diff --git a/cgi-bin/diff.py b/cgi-bin/diff.py index ea7420a4..93d165ab 100644 --- a/cgi-bin/diff.py +++ b/cgi-bin/diff.py @@ -69,6 +69,6 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None : if form.getvalue('serv') is not None and form.getvalue('right') is not None: commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ] - funct.ssh_command(haproxy_configs_server, commands, compare="compare") + funct.ssh_command(haproxy_configs_server, commands, compare="1") funct.footer() \ No newline at end of file diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index b53e62cf..d5119cea 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -301,38 +301,33 @@ def show_ip(stdout): for line in stdout: print(line) +def server_status(stdout): + if " " not in stdout.read().decode(encoding='UTF-8'): + print(' UP running 3 processes') + else: + print(' DOWN running 0 processes') + def ssh_command(serv, commands, **kwargs): ssh = ssh_connect(serv) - - ip = 0 - compare_funct = 0 - show_log_funct = 0 - - for k in kwargs: - if "ip" in kwargs[k]: - ip = 1 - if "compare" in kwargs[k]: - compare_funct = 1 - if "show_log" in kwargs[k]: - show_log_funct = 1 - + for command in commands: try: stdin, stdout, stderr = ssh.exec_command(command) except: continue - if ip is 1: + if kwargs.get("ip") == "1": show_ip(stdout) - if compare_funct is 1: + if kwargs.get("compare") == "1": compare(stdout) - if show_log_funct is 1: + if kwargs.get("show_log") == "1": show_log(stdout) + if kwargs.get("server_status") == "1": + server_status(stdout) else: print(stdout.read().decode(encoding='UTF-8')) print(stderr.read().decode(encoding='UTF-8')) - #ssh.close() def chooseServer(formName, title, note): print('

' + title + '

') diff --git a/cgi-bin/haproxy-webintarface.config b/cgi-bin/haproxy-webintarface.config new file mode 100644 index 00000000..41282f18 --- /dev/null +++ b/cgi-bin/haproxy-webintarface.config @@ -0,0 +1,54 @@ +[main] +#Path to files destination +fullpath = /var/www/haproxy-wi/ +server_bind_ip = 0.0.0.0 +server_port = 8000 +log_path = %(fullpath)s/log/ +time_zone = UTC +#Enable logo on top menu. Default disable +logo_enable = 0 +logo_path = /logo.png + +[configs] +#Server for save configs from HAproxy servers +haproxy_configs_server = localhost +#Dir where configs will be save +haproxy_save_configs_dir = /var/www/haproxy-wi/cgi-bin/hap_config/ + +[ssh] +#If ssh connect disable entare password for ssh connect. Default enable +ssh_keys_enable = 1 +#SSH keys to connect without password to HAproxy servers +ssh_keys = /var/www/haproxy-wi/cgi-bin/id_rsa.pem +#Username for connect ssh +ssh_user_name = root +ssh_pass = + +[logs] +#Logs save locally, disable by default +local_path_logs = /var/log/haproxy.log +#If exist syslog server for HAproxy logs +syslog_server_enable = 0 +syslog_server = + +[telegram] +#Send log message to telegram channel +#Default bot send message disable +enable = 0 +token = +channel_name = +proxy = + +[haproxy] +#Command for restart HAproxy service +restart_command = service haproxy restart +#Username and password for Stats web page HAproxy +user = admin +password = password +stats_port = 8085 +stats_page = stats +haproxy_config_path = /etc/haproxy/haproxy.cfg +#Temp store configs, for haproxy check +tmp_config_path = /tmp +#Time in seconds for auto refresh view stats_port +refresh_time = 120 diff --git a/cgi-bin/logs.py b/cgi-bin/logs.py index 1afea9a1..14e6718d 100644 --- a/cgi-bin/logs.py +++ b/cgi-bin/logs.py @@ -71,6 +71,6 @@ if form.getvalue('serv') is not None: commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ] syslog_server = config.get('logs', 'syslog_server') - funct.ssh_command(syslog_server, commands, show_log="show_log") + funct.ssh_command(syslog_server, commands, show_log="1") funct.footer() \ No newline at end of file diff --git a/cgi-bin/options.py b/cgi-bin/options.py index a87003dd..80e045e7 100644 --- a/cgi-bin/options.py +++ b/cgi-bin/options.py @@ -10,7 +10,6 @@ form = cgi.FieldStorage() req = form.getvalue('req') serv = form.getvalue('serv') print('Content-type: text/html\n') -#print('Content-type: application/json\n') if req is not None: if req is 1: @@ -43,7 +42,7 @@ if backend is not None: if form.getvalue('ip') is not None and serv is not None: commands = [ "ip a |grep inet |egrep -v '::1' |awk '{ print $2 }' |awk -F'/' '{ print $1 }'" ] - funct.ssh_command(serv, commands, ip="ip") + funct.ssh_command(serv, commands, ip="1") if form.getvalue('name') is not None: name = form.getvalue('name') diff --git a/cgi-bin/overview.py b/cgi-bin/overview.py index 00903d36..ffe79c5f 100644 --- a/cgi-bin/overview.py +++ b/cgi-bin/overview.py @@ -13,11 +13,20 @@ path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() config.read(path_config) -commands = [ "cat /etc/haproxy/haproxy.cfg |grep -E '^listen|^backend|^frontend' |wc -l", "haproxy -v |head -1", "top -u haproxy -b -n 1" ] print('

Quick Status

') +commands = [ "ps -Af |grep [h]aproxy |wc -l" ] + +print('') for i in sorted(listhap.listhap): - print('') + print('') +print('') +print('') +commands = [ "cat /etc/haproxy/haproxy.cfg |grep -E '^listen|^backend|^frontend' |grep -v stats |wc -l", "haproxy -v |head -1", "top -u haproxy -b -n 1" ] +for i in sorted(listhap.listhap): + print('') print('') diff --git a/cgi-bin/viewsttats.py b/cgi-bin/viewsttats.py index 4d71ad4d..b3432918 100644 --- a/cgi-bin/viewsttats.py +++ b/cgi-bin/viewsttats.py @@ -7,8 +7,8 @@ import listserv as listhap import configparser from requests_toolbelt.utils import dump +print("Content-type: text/html\n") funct.check_config() -funct.check_login() path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() @@ -16,6 +16,7 @@ config.read(path_config) haproxy_user = config.get('haproxy', 'user') haproxy_pass = config.get('haproxy', 'password') stats_port = config.get('haproxy', 'stats_port') +stats_page = config.get('haproxy', 'stats_page') listhap.listhap = funct.merge_two_dicts(listhap.listhap, listhap.list_hap_vip) @@ -27,32 +28,37 @@ if serv is None: serv = first_serv[0] try: - response = requests.get('http://%s:%s/stats' % (serv, stats_port), auth=(haproxy_user, haproxy_pass)) + response = requests.get('http://%s:%s/%s' % (serv, stats_port, stats_page), auth=(haproxy_user, haproxy_pass)) except requests.exceptions.ConnectTimeout: print('Oops. Connection timeout occured!') except requests.exceptions.ReadTimeout: print('Oops. Read timeout occured') +except requests.exceptions.HTTPError as errh: + print ("Http Error:",errh) +except requests.exceptions.ConnectionError as errc: + print ("Error Connecting:",errc) +except requests.exceptions.Timeout as errt: + print ("Timeout Error:",errt) +except requests.exceptions.RequestException as err: + print ("OOps: Something Else",err) -print("Content-type: text/html\n") print('' % (config.get('haproxy', 'refresh_time') ,serv)) for i in listhap.listhap: if listhap.listhap.get(i) == serv: servname = i -print('

Curent server IP - %s, name - %s


' % (serv, servname)) -print('Home Page

') - -print('

Choose server!


') -print('') -print('

' + '') funct.choose_server_with_vip(serv) -print('

') +print('') -data = dump.dump_all(response) +data = response.content print('') print(data.decode('utf-8')) - +funct.head("Stats HAproxy configs") +print('') diff --git a/haproxy-webintarface.config b/haproxy-webintarface.config index eb7636db..ca4bad26 100644 --- a/haproxy-webintarface.config +++ b/haproxy-webintarface.config @@ -25,9 +25,9 @@ ssh_user_name = root ssh_pass = [logs] -#Logs save locally +#Logs save locally, disable by default local_path_logs = /var/log/haproxy.log -#If exist syslog server for HAproxy logs, disable by default +#If exist syslog server for HAproxy logs syslog_server_enable = 0 syslog_server = @@ -46,6 +46,7 @@ restart_command = service haproxy restart user = admin password = password stats_port = 8085 +stats_page = stats haproxy_config_path = /etc/haproxy/haproxy.cfg #Temp store configs, for haproxy check tmp_config_path = /tmp diff --git a/index.html b/index.html index 7a18b730..93eb3d54 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@
-

Welcome! HAproxy Web Interface

+

Welcome to HAproxy-WI!

Choose your destiny!

Overview
View stats
@@ -23,7 +23,7 @@ Upload old config
Delete old config
diff --git a/script.js b/script.js index 7a2c894e..daec1b90 100644 --- a/script.js +++ b/script.js @@ -4,9 +4,9 @@ $( function() { $( "#tabs" ).tabs( "option", "active", 2 ); } ); $( "select" ).selectmenu(); - $( document ).tooltip(); + //$( document ).tooltip(); $( "input[type=submit], button" ).button(); - $( "input" ).checkboxradio(); + $( "input[type=checkbox]" ).checkboxradio(); } ); $( function() { diff --git a/style.css b/style.css index 78a2081c..803b5a79 100644 --- a/style.css +++ b/style.css @@ -11,11 +11,17 @@ body { padding: 0; } h2 { - border: 1px solid #aaa; + border: 1px solid #5D9CEB; padding: 10px; border-radius: 5px; - background: #aaa; + background: #5D9CEB; padding-left: 3%; + color: #fff; + margin-bottom: 0px; +} +h3 { + margin-top: 10px; + margin-bottom: 0px; } .top-menu { background-color: #222; @@ -47,7 +53,6 @@ h2 { padding-left: 7px; padding-right: 7px; } - .top-link { margin-top: 15px; } @@ -121,8 +126,8 @@ h2 { margin-left: 15px; } .line { - background-color: #eee; - border: 1px solid #000; + background-color: #EBF1F1; + border: 1px solid #ddd; } .line, .line3 { padding-top:5px; @@ -134,7 +139,7 @@ h2 { color: #aaa; } .addName { - background-color: #eee; + background-color: #f6f6f6; width: 120px; } .addOption, .addName { @@ -167,6 +172,11 @@ h2 { .overview { width: 100%; } +.overviewHead { + border-radius: 5px; + background-color: #EBF1F1; + font-weight: bold; +} .overview tr{ border: 1px solid #ddd; border-radius: 5px; @@ -179,10 +189,26 @@ h2 { } .overviewTr { margin: 0; - background-color: #eee; + background-color: #f6f6f6; padding-left: 15px; font-size: 15px; } +.serverUp, .serverDown { + padding: 3px; + border-radius: 3px; + color: #fff; + font-weight: bold; +} +.serverUp { + background-color: green; +} +.serverDown { + background-color: red; +} +.padding10 { + padding: 10px; + border: none; +} .ro { border: none; } @@ -193,7 +219,7 @@ h2 { margin-top: -10px; } .menu ul li{ - padding: 10px; + padding: 10px; } .menu ul > li:hover{ background-color: #333; @@ -203,6 +229,7 @@ h2 { } .menu ul li, .menu ul{ display: inline-block; + border-radius: 3px; } .menu ul{ position: relative; @@ -223,12 +250,11 @@ h2 { } .menu ul ul a{ color: #fff; - text-decoration: none; + text-decoration: none; } .menu li:hover ul{ display: block; } - .menu li:hover li{ display: block; } @@ -322,20 +348,9 @@ a, a:visited { text-decoration: underline; } -#a[href]:after { -# content: " (" attr(href) ")"; -# } -#abbr[title]:after { -# content: " (" attr(title) ")"; -# } -#a[href^="#"]:after, -#a[href^="javascript:"]:after { -# content: ""; -# } a { - #color: #337ab7; - color: #9d9d9d; - text-decoration: none; + color: #9d9d9d; + text-decoration: none; } a:hover, a:focus {
ServerHAproxy status

Server ' + i + ':

' + i + '') + funct.ssh_command(listhap.listhap.get(i), commands, server_status="1") + print('
ServerServer status

' + i + ':

Total listen/frontend/backend:
')
 	funct.ssh_command(listhap.listhap.get(i), commands)
 	print('