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.logging(serv, "config.py open config")
funct.get_config(serv, cfg) funct.get_config(serv, cfg)
conf = open(cfg, "r") 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("<center><h3>Config from %s</h3>" % serv)
print('<form action="config.py" method="get">') 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) 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/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") os.system("/bin/rm -f " + hap_configs_dir + "*.old")

View File

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

View File

@ -28,7 +28,7 @@ restart_command = config.get('haproxy', 'restart_command')
def check_config(): def check_config():
for section in [ 'main', 'configs', 'ssh', 'logs', 'haproxy' ]: for section in [ 'main', 'configs', 'ssh', 'logs', 'haproxy' ]:
if not config.has_section(section): 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): def get_data(type):
now_utc = datetime.now(timezone(time_zone)) 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')) ssh.connect(hostname = serv, username = ssh_user_name, password = config.get('ssh', 'ssh_pass'))
return ssh return ssh
except paramiko.AuthenticationException: 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: 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: 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: except Exception as e:
print(e.args) print('<div class="alert alert-danger">{}</div>'.format(e.args))
def get_config(serv, cfg): def get_config(serv, cfg):
os.chdir(hap_configs_dir) os.chdir(hap_configs_dir)
@ -318,11 +318,14 @@ def get_config(serv, cfg):
sftp.close() sftp.close()
ssh.close() ssh.close()
except Exception as e: 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): def show_config(cfg):
print('<div style="margin-left: 16%" class="configShow">') print('<div style="margin-left: 16%" class="configShow">')
conf = open(cfg, "r") try:
conf = open(cfg, "r")
except IOError:
print('<div class="alert alert-danger">Can\'t read import config file</div>')
i = 0 i = 0
for line in conf: for line in conf:
i = i + 1 i = i + 1
@ -363,9 +366,12 @@ def show_config(cfg):
def upload_and_restart(serv, cfg, **kwargs): def upload_and_restart(serv, cfg, **kwargs):
tmp_file = tmp_config_path + "/" + get_data('config') + ".cfg" tmp_file = tmp_config_path + "/" + get_data('config') + ".cfg"
ssh = ssh_connect(serv) try:
print("<center>connected<br />") ssh = ssh_connect(serv)
print("<center>connected to %s<br />" % serv)
except:
print("Connect fail")
sftp = ssh.open_sftp() sftp = ssh.open_sftp()
sftp.put(cfg, tmp_file) sftp.put(cfg, tmp_file)
sftp.close() sftp.close()

View File

@ -173,7 +173,11 @@ if serv is not None and act == "configShow":
if form.getvalue('viewlogs') is not None: if form.getvalue('viewlogs') is not None:
viewlog = form.getvalue('viewlogs') viewlog = form.getvalue('viewlogs')
log_path = config.get('main', 'log_path') log_path = config.get('main', 'log_path')
log = open(log_path + viewlog, "r") 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) print('<center><h3>Shows log: %s</h3></center><br />' % viewlog)
i = 0 i = 0
for line in log: for line in log:

View File

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

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import html import html
import cgi import cgi
import os import os, sys
import funct import funct
from configparser import ConfigParser, ExtendedInterpolation from configparser import ConfigParser, ExtendedInterpolation
import glob import glob
@ -21,12 +21,17 @@ log_path = config.get('main', 'log_path')
funct.page_for_admin() funct.page_for_admin()
funct.get_auto_refresh("View logs") funct.get_auto_refresh("View logs")
try:
os.chdir(log_path) 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()
print('<script src="/inc/users.js"></script>' print('<script src="/inc/users.js"></script>'
'<a name="top"></a>' '<a name="top"></a>'
'<center><h3>Choose log file</h3><br />' '<center><h3>Choose log file</h3><br />')
'<select id="viewlogs">'
print('<select id="viewlogs">'
'<option disabled selected>Choose log</option>') '<option disabled selected>Choose log</option>')
for files in sorted(glob.glob('*.log'), reverse=True): for files in sorted(glob.glob('*.log'), reverse=True):