diff --git a/cgi-bin/config.py b/cgi-bin/config.py index e1f319e8..a5495aea 100644 --- a/cgi-bin/config.py +++ b/cgi-bin/config.py @@ -26,13 +26,14 @@ config.read(path_config) fullpath = config.get('main', 'fullpath') hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') +time_zone = config.get('main', 'time_zone') if login is None: print('') if serv is not None: fmt = "%Y-%m-%d.%H:%M:%S" - now_utc = datetime.now(timezone('Asia/Almaty')) + now_utc = datetime.now(timezone(time_zone)) cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg" funct.chooseServer("config.py#conf", "Edit HAproxy config", "y") @@ -49,7 +50,6 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None : print('' % cfg) print('' % conf.read()) print('

') - print('

UP

') conf.close os.system("/bin/sudo /bin/mv %s %s.old" % (cfg, cfg)) diff --git a/cgi-bin/configshow.py b/cgi-bin/configshow.py index 8c2f3b22..7a261024 100644 --- a/cgi-bin/configshow.py +++ b/cgi-bin/configshow.py @@ -24,10 +24,11 @@ ssh_keys = config.get('ssh', 'ssh_keys') ssh_user_name = config.get('ssh', 'ssh_user_name') hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') haproxy_config_path = config.get('haproxy', 'haproxy_config_path') +time_zone = config.get('main', 'time_zone') if serv is not None: fmt = "%Y-%m-%d.%H:%M:%S" - now_utc = datetime.now(timezone('Asia/Almaty')) + now_utc = datetime.now(timezone(time_zone)) cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg" funct.chooseServer("configshow.py#conf", "Show HAproxy config", "n") @@ -35,12 +36,10 @@ funct.chooseServer("configshow.py#conf", "Show HAproxy config", "n") if form.getvalue('serv') is not None and form.getvalue('open') is not None : funct.get_config(serv, cfg) - conf = open(cfg, "r") print('') print("

Config from %s

" % serv) - print('' % conf.read()) - print('

UP

') - conf.close + + funct.show_config(cfg) os.system("/bin/sudo /bin/rm -f " + cfg) diff --git a/cgi-bin/configver.py b/cgi-bin/configver.py index 300a12cf..d455111f 100644 --- a/cgi-bin/configver.py +++ b/cgi-bin/configver.py @@ -63,16 +63,14 @@ if serv is not None and form.getvalue('open') is not None: configver = form.getvalue('configver') funct.logging(serv, "open old config %s" % configver) - conf = open(configver, "r") print("

Config from %s, and version is: %s

" % (serv, configver)) print('
') print('' % serv) print('' % configver) - print('') - print('' % conf.read()) - print('

') - print('

UP

') - conf.close + print('') + funct.show_config(configver) + print('

') + if form.getvalue('serv') is not None and form.getvalue('config') is not None: configver = form.getvalue('configver') @@ -84,4 +82,6 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None: funct.upload_and_restart(serv, configver) - print('
Go to view stats
') + print('

Go to view stats
') + +funct.footer() diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 5a07e3bc..3712a361 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -30,10 +30,11 @@ haproxy_configs_server = config.get('configs', 'haproxy_configs_server') hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') haproxy_config_path = config.get('haproxy', 'haproxy_config_path') restart_command = config.get('haproxy', 'restart_command') +time_zone = config.get('main', 'time_zone') def logging(serv, action): dateFormat = "%b %d %H:%M:%S" - now_utc = datetime.now(timezone('Asia/Almaty')) + now_utc = datetime.now(timezone(time_zone)) IP = cgi.escape(os.environ["REMOTE_ADDR"]) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) firstName = cookie.get('FirstName') @@ -43,6 +44,18 @@ def logging(serv, action): log.write(mess) log.close +def links(): + print('Home Page ') + print('Stats ') + print('Monitoring ') + print('Logs') + print('Edit settings ') + print(' | Configs: ') + print('Show ') + print('Compare ') + print('Edit ') + print('Upload old') + def head(title): print("Content-type: text/html\n") print('%s' % title) @@ -50,28 +63,13 @@ def head(title): print('') print('') print('
') def footer(): + print('

UP

') print('
') def get_config(serv, cfg): @@ -87,6 +85,43 @@ def get_config(serv, cfg): sftp.close() ssh.close() +def show_config(cfg): + print('
') + conf = open(cfg, "r") + i = 0 + for line in conf: + i = i + 1 + if not line.find("global"): + print('
' + line + '
') + continue + if not line.find("defaults"): + print('
' + line + '
') + continue + if not line.find("listen"): + print('
' + line + '
') + continue + if not line.find("frontend"): + print('
' + line + '
') + continue + if not line.find("backend"): + print('
' + line + '
') + continue + if "acl" in line or "option" in line or "server" in line: + print('
') + print(i) + print('' + line + '
') + continue + if "#" in line: + print('
') + print(i) + print(line + '
') + continue + print('
') + print(i) + print('' + line + '
') + print('
') + conf.close + def upload_and_restart(serv, cfg): ssh = SSHClient() ssh.load_system_host_keys() @@ -119,9 +154,15 @@ def ssh_command(serv, commands): ssh.connect( hostname = serv, username = ssh_user_name, pkey = k ) for command in commands: stdin , stdout, stderr = ssh.exec_command(command) - print('
')
-		print(stdout.read().decode(encoding='UTF-8'))
-		print('
') + print('
') + i = 1 + for line in stdout: + i = i + 1 + if i % 2 == 0: + print('
' + line + '
') + else: + print('
' + line + '
') + print('
') ssh.close() def chooseServer(formName, title, note): @@ -156,7 +197,7 @@ def choose_server_with_vip(serv): selected = 'selected' else: selected = '' - print('' % (listhap.listhap.get(i), selected, i)) + print('' % (listhap.listhap.get(i), selected, i)) def merge_two_dicts(x, y): z = x.copy() diff --git a/cgi-bin/logs.py b/cgi-bin/logs.py index f60f5be9..d21c0bcc 100644 --- a/cgi-bin/logs.py +++ b/cgi-bin/logs.py @@ -72,6 +72,4 @@ if form.getvalue('serv') is not None: funct.ssh_command(syslog_server, commands) - print('

UP

') - funct.footer() \ No newline at end of file diff --git a/cgi-bin/viewsttats.py b/cgi-bin/viewsttats.py index 89446a28..f606868c 100644 --- a/cgi-bin/viewsttats.py +++ b/cgi-bin/viewsttats.py @@ -22,7 +22,7 @@ form = cgi.FieldStorage() serv = form.getvalue('serv') if serv is None: - serv = '172.28.9.161' + serv = '172.28.5.17' try: response = requests.get('http://%s:%s/stats' % (serv, stats_port), auth=(haproxy_user, haproxy_pass))