From a648d5cfcc887b21a539647f41abb674826f2ea2 Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Thu, 26 Apr 2018 10:24:23 +0600 Subject: [PATCH] v2.0.6 --- cgi-bin/config.py | 6 +++++- cgi-bin/edit.py | 2 +- cgi-bin/funct.py | 26 ++++++++++++++++---------- cgi-bin/options.py | 6 +++++- cgi-bin/ovw.py | 9 ++++++--- cgi-bin/viewlogs.py | 15 ++++++++++----- 6 files changed, 43 insertions(+), 21 deletions(-) diff --git a/cgi-bin/config.py b/cgi-bin/config.py index 40c511a1..6d567918 100644 --- a/cgi-bin/config.py +++ b/cgi-bin/config.py @@ -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) - conf = open(cfg, "r") + try: + conf = open(cfg, "r") + except IOError: + print('
Can\'t read import config file
') print("

Config from %s

" % serv) print('
') @@ -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") diff --git a/cgi-bin/edit.py b/cgi-bin/edit.py index d43d1435..eff77d00 100644 --- a/cgi-bin/edit.py +++ b/cgi-bin/edit.py @@ -41,7 +41,7 @@ print('' '' '' '' - '' + '' '' 'Enter' '
' diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 02ac2676..90aa77c7 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -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('Check config file, no %s section' % section) + print('
Check config file, no %s section
' % 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('
Authentication failed, please verify your credentials
') except paramiko.SSHException as sshException: - print("Unable to establish SSH connection: %s" % sshException) + print('
Unable to establish SSH connection: %s
' % sshException) except paramiko.BadHostKeyException as badHostKeyException: - print("Unable to verify server's host key: %s" % badHostKeyException) + print('
Unable to verify server\'s host key: %s
' % badHostKeyException) except Exception as e: - print(e.args) + print('
{}
'.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('
' + str(e) + ' Please check IP, and SSH settings
') def show_config(cfg): print('
') - conf = open(cfg, "r") + try: + conf = open(cfg, "r") + except IOError: + print('
Can\'t read import config file
') i = 0 for line in conf: i = i + 1 @@ -363,9 +366,12 @@ def show_config(cfg): def upload_and_restart(serv, cfg, **kwargs): tmp_file = tmp_config_path + "/" + get_data('config') + ".cfg" - - ssh = ssh_connect(serv) - print("
connected
") + + try: + ssh = ssh_connect(serv) + print("
connected to %s
" % serv) + except: + print("Connect fail") sftp = ssh.open_sftp() sftp.put(cfg, tmp_file) sftp.close() diff --git a/cgi-bin/options.py b/cgi-bin/options.py index 200a91b8..7cdf4778 100644 --- a/cgi-bin/options.py +++ b/cgi-bin/options.py @@ -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') - log = open(log_path + viewlog, "r") + try: + log = open(log_path + viewlog, "r") + except IOError: + print('
Can\'t read import config file
') + print('

Shows log: %s


' % viewlog) i = 0 for line in log: diff --git a/cgi-bin/ovw.py b/cgi-bin/ovw.py index 5236fc94..650fcfb7 100644 --- a/cgi-bin/ovw.py +++ b/cgi-bin/ovw.py @@ -131,7 +131,10 @@ def get_map(serv): G = nx.DiGraph() funct.get_config(serv, cfg) - conf = open(cfg, "r") + try: + conf = open(cfg, "r") + except IOError: + print('
Can\'t read import config file
') 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('
' + str(e) + '
') commands = [ "rm -f "+fullpath+"/map*.png", "mv %s/map.png %s/map%s.png" % (cgi_path, fullpath, date) ] funct.ssh_command("localhost", commands) diff --git a/cgi-bin/viewlogs.py b/cgi-bin/viewlogs.py index 4df90384..88b73820 100644 --- a/cgi-bin/viewlogs.py +++ b/cgi-bin/viewlogs.py @@ -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") - -os.chdir(log_path) +try: + os.chdir(log_path) +except IOError: + print('
No such file or directory: "%s". Please check log_path in config and exist directory
' % log_path) + sys.exit() + print('' '' - '

Choose log file


' - '' '') for files in sorted(glob.glob('*.log'), reverse=True):