pull/19/head
Aidaho12 2018-04-26 10:24:23 +06:00
parent 95105c68a6
commit a648d5cfcc
6 changed files with 43 additions and 21 deletions

View File

@ -33,7 +33,10 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
funct.logging(serv, "config.py open config")
funct.get_config(serv, cfg)
try:
conf = open(cfg, "r")
except IOError:
print('<div class="alert alert-danger">Can\'t read import config file</div>')
print("<center><h3>Config from %s</h3>" % serv)
print('<form action="config.py" method="get">')
@ -69,6 +72,7 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
funct.upload_and_restart(serv, cfg, just_save=save)
os.system("/bin/diff -ub %s %s >> %s/config_edit-%s.log" % (oldcfg, cfg, log_path, funct.get_data('logs')))
os.system("/bin/rm -f " + hap_configs_dir + "*.old")

View File

@ -41,7 +41,7 @@ print('<option value="show">Show</option>'
'<td>'
'<input type="text" name="servbackend" id="servbackend" size=35 title="Frontend, backend/server, show: info, pools or help" required class="form-control">'
'</td><td>'
'<input type="checkbox" name="save" id="save" value="123">'
'<label for="save"></label><input type="checkbox" name="save" id="save" value="123">'
'</td><td>'
'<a class="ui-button ui-widget ui-corner-all" id="show" title="Enter" onclick="showRuntime()">Enter</a>'
'</td></form>'

View File

@ -28,7 +28,7 @@ restart_command = config.get('haproxy', 'restart_command')
def check_config():
for section in [ 'main', 'configs', 'ssh', 'logs', 'haproxy' ]:
if not config.has_section(section):
print('<b style="color: red">Check config file, no %s section</b>' % section)
print('<center><div class="alert alert-danger">Check config file, no %s section</div>' % section)
def get_data(type):
now_utc = datetime.now(timezone(time_zone))
@ -301,13 +301,13 @@ def ssh_connect(serv):
ssh.connect(hostname = serv, username = ssh_user_name, password = config.get('ssh', 'ssh_pass'))
return ssh
except paramiko.AuthenticationException:
print("Authentication failed, please verify your credentials: %s")
print('<div class="alert alert-danger">Authentication failed, please verify your credentials</div>')
except paramiko.SSHException as sshException:
print("Unable to establish SSH connection: %s" % sshException)
print('<div class="alert alert-danger">Unable to establish SSH connection: %s </div>' % sshException)
except paramiko.BadHostKeyException as badHostKeyException:
print("Unable to verify server's host key: %s" % badHostKeyException)
print('<div class="alert alert-danger">Unable to verify server\'s host key: %s </div>' % badHostKeyException)
except Exception as e:
print(e.args)
print('<div class="alert alert-danger">{}</div>'.format(e.args))
def get_config(serv, cfg):
os.chdir(hap_configs_dir)
@ -318,11 +318,14 @@ def get_config(serv, cfg):
sftp.close()
ssh.close()
except Exception as e:
print("!!! There was an issue, " + str(e))
print('<div class="alert alert-danger">' + str(e) + ' Please check IP, and SSH settings</div>')
def show_config(cfg):
print('<div style="margin-left: 16%" class="configShow">')
try:
conf = open(cfg, "r")
except IOError:
print('<div class="alert alert-danger">Can\'t read import config file</div>')
i = 0
for line in conf:
i = i + 1
@ -364,8 +367,11 @@ def show_config(cfg):
def upload_and_restart(serv, cfg, **kwargs):
tmp_file = tmp_config_path + "/" + get_data('config') + ".cfg"
try:
ssh = ssh_connect(serv)
print("<center>connected<br />")
print("<center>connected to %s<br />" % serv)
except:
print("Connect fail")
sftp = ssh.open_sftp()
sftp.put(cfg, tmp_file)
sftp.close()

View File

@ -173,7 +173,11 @@ if serv is not None and act == "configShow":
if form.getvalue('viewlogs') is not None:
viewlog = form.getvalue('viewlogs')
log_path = config.get('main', 'log_path')
try:
log = open(log_path + viewlog, "r")
except IOError:
print('<div class="alert alert-danger">Can\'t read import config file</div>')
print('<center><h3>Shows log: %s</h3></center><br />' % viewlog)
i = 0
for line in log:

View File

@ -131,7 +131,10 @@ def get_map(serv):
G = nx.DiGraph()
funct.get_config(serv, cfg)
try:
conf = open(cfg, "r")
except IOError:
print('<div class="alert alert-danger">Can\'t read import config file</div>')
node = ""
line_new2 = [1,""]
@ -159,7 +162,7 @@ def get_map(serv):
G.add_node(node,pos=(k,i),label_pos=(k,i+150))
if "server " in line or "use_backend" in line or "default_backend" in line and "stats" not in line:
if "timeout" not in line and "default-server" not in line and "#use_backend" not in line and "stats" not in line:
if "timeout" not in line and "default-server" not in line and "#" not in line and "stats" not in line:
i = i - 300
j = j + 1
if "check" in line:
@ -203,7 +206,7 @@ def get_map(serv):
plt.savefig("map.png")
plt.show()
except Exception as e:
print("!!! There was an issue, " + str(e))
print('<div class="alert alert-danger">' + str(e) + '</div>')
commands = [ "rm -f "+fullpath+"/map*.png", "mv %s/map.png %s/map%s.png" % (cgi_path, fullpath, date) ]
funct.ssh_command("localhost", commands)

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
import html
import cgi
import os
import os, sys
import funct
from configparser import ConfigParser, ExtendedInterpolation
import glob
@ -21,12 +21,17 @@ log_path = config.get('main', 'log_path')
funct.page_for_admin()
funct.get_auto_refresh("View logs")
try:
os.chdir(log_path)
except IOError:
print('<center><div class="alert alert-danger">No such file or directory: "%s". Please check log_path in config and exist directory</div>' % log_path)
sys.exit()
os.chdir(log_path)
print('<script src="/inc/users.js"></script>'
'<a name="top"></a>'
'<center><h3>Choose log file</h3><br />'
'<select id="viewlogs">'
'<center><h3>Choose log file</h3><br />')
print('<select id="viewlogs">'
'<option disabled selected>Choose log</option>')
for files in sorted(glob.glob('*.log'), reverse=True):