From 5d12901a5bf1c5477c1248e9ac616ff423632cbd Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Tue, 6 Feb 2018 10:39:43 +0600 Subject: [PATCH] v1.6.1 Add overview, change menu style --- cgi-bin/config.py | 4 +- cgi-bin/configver.py | 4 +- cgi-bin/delver.py | 8 ++-- cgi-bin/funct.py | 52 +++++++++++++------- cgi-bin/overview.py | 26 ++++++++++ index.html | 5 +- style.css | 110 ++++++++++++++++++++++++++++++++++--------- 7 files changed, 161 insertions(+), 48 deletions(-) create mode 100644 cgi-bin/overview.py diff --git a/cgi-bin/config.py b/cgi-bin/config.py index 7319ad81..d82192b5 100644 --- a/cgi-bin/config.py +++ b/cgi-bin/config.py @@ -41,7 +41,7 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None : conf = open(cfg, "r") print('') print("

Config from %s

" % serv) - print('
') + print('') print('' % serv) print('' % cfg) print('' % conf.read()) @@ -70,6 +70,6 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None : os.system("/bin/diff -ub %s %s >> %slog/config_edit.log" % (oldcfg, cfg, fullpath)) os.system("/bin/sudo /bin/rm -f " + hap_configs_dir + "*.old") - print('
Go to view stats
') + print('
Go to view stats
' % serv) funct.footer() \ No newline at end of file diff --git a/cgi-bin/configver.py b/cgi-bin/configver.py index 97b9dc13..721cb8be 100644 --- a/cgi-bin/configver.py +++ b/cgi-bin/configver.py @@ -60,7 +60,7 @@ if serv is not None and form.getvalue('open') is not None: funct.logging(serv, "open old config %s" % configver) print("

Config from %s, and version is: %s

" % (serv, configver)) - print('') + print('') print('' % serv) print('' % configver) print('') @@ -81,6 +81,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
' % serv) funct.footer() diff --git a/cgi-bin/delver.py b/cgi-bin/delver.py index 442e9e0c..cea041de 100644 --- a/cgi-bin/delver.py +++ b/cgi-bin/delver.py @@ -23,7 +23,7 @@ funct.chooseServer("delver.py#conf", "Delete Versions HAproxy config", "n") if serv is not None and form.getvalue('open') is not None: print('

Choose old version

') - print('') + print('') import glob @@ -51,9 +51,9 @@ if serv is not None and form.getvalue('open') is not None: try: os.remove(form.getvalue(get)) print(form.getvalue(get) + "
") - funct.logging(serv, "delver.py deleted config: %s" % form.getvalue(get)) - + funct.logging(serv, "delver.py deleted config: %s" % form.getvalue(get)) except OSError: print ("Error: %s - %s." % (e.filename,e.strerror)) - print('' % form.getvalue('serv')) + print('' % form.getvalue('serv')) + funct.footer() \ No newline at end of file diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 4794e27d..8b1a7ed6 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -70,9 +70,9 @@ def show_login_links(): login = cookie.get('login') if login is None: - print('Login') + print('
  • Login
  • ') else: - print('Logout') + print('
  • Logout
  • ') def mode_admin(button, **kwargs): cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) @@ -88,20 +88,38 @@ def mode_admin(button, **kwargs): print('' % button) def links(): - print('Home Page ') - print('Stats ') - print('Monitoring ') - print('Logs') - print('Edit settings ') - print(' | Configs: ') - print('Show ') - print('Compare ') - print('Add ') - print('Edit ') - print(' | Versions: ') - print('Upload') - print('Delete') + print('') + def head(title): print('Content-type: text/html\n') @@ -132,7 +150,7 @@ def footer(): '
    ' '') def ssh_connect(serv): @@ -295,6 +313,8 @@ def ssh_command(serv, commands, **kwargs): compare(stdout) if show_log_funct is 1: show_log(stdout) + else: + print(stdout.read().decode(encoding='UTF-8')) print(stderr.read().decode(encoding='UTF-8')) ssh.close() diff --git a/cgi-bin/overview.py b/cgi-bin/overview.py new file mode 100644 index 00000000..54734b42 --- /dev/null +++ b/cgi-bin/overview.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import html +import cgi +import funct +import configparser +import listserv as listhap + +funct.head("Overview") +funct.check_config() +funct.check_login() + +path_config = "haproxy-webintarface.config" +config = configparser.ConfigParser() +config.read(path_config) + +commands = [ "top -u haproxy -b -n 1" ] +print('

    Quick Status

    ') + +for i in sorted(listhap.listhap): + print('') + print('') + +print("

    Server ' + i + ':

    ')
    +	funct.ssh_command(listhap.listhap.get(i), commands)
    +	print('
    ") +funct.footer() \ No newline at end of file diff --git a/index.html b/index.html index c8ad7e11..1c23e779 100644 --- a/index.html +++ b/index.html @@ -12,9 +12,10 @@

    Welcome! HAproxy Web Interface

    Choose your destiny!

    + Overview
    View stats
    - Edit settings
    Logs
    + Edit settings
    Compare
    Show
    Add
    @@ -22,7 +23,7 @@ Upload old config
    Delete old config
    diff --git a/style.css b/style.css index bbe83c18..0a356272 100644 --- a/style.css +++ b/style.css @@ -10,15 +10,22 @@ body { margin: 0; padding: 0; } +h2 { + border: 1px solid #aaa; + padding: 10px; + border-radius: 5px; + background: #aaa; + padding-left: 3%; +} .top-menu { - background-color: #222; - min-height: 50px; - margin-bottom: 20px; - top: 0; - position: fixed; - right: 0; - left: 0; - z-index: 1000; + background-color: #222; + min-height: 50px; + margin-bottom: 20px; + top: 0; + position: fixed; + right: 0; + left: 0; + z-index: 1000; } .logoText { color: #fff; @@ -40,26 +47,21 @@ body { padding-left: 7px; padding-right: 7px; } -.top-menu a:focus, .footer a:focus { - color: #000; -} -.top-menu a:hover, .footer a:hover { - color: #fff; -} -.top-menu span, .footer span { - padding-left: 20px; -} + .top-link { - margin-top: 15px; - margin-left: 35%; + margin-top: 15px; +} +.top-link, .footer-link { + margin-left: 30%; } .conteiner { clear: both; margin-top: 65px; min-height: calc(100vh - 115px); - width: 45%; + max-width: 50%; + min-width: 40%; background-color: #fff; - margin-left: 27%; + margin-left: 25%; } .configShow, .diff { margin-left: 16%; @@ -159,13 +161,77 @@ body { right: 0; left: 0; } +.overview { + width: 100%; +} +.overview tr{ + border: 1px solid #ddd; + border-radius: 5px; +} + +.overviewTd { + padding-left: 5%; + padding-top: 20px; + border-color: #ddd; +} +.overviewTr { + margin: 0; + background-color: #eee; + padding-left: 15px; + font-size: 15px; +} .footer-link { padding-top: 15px; - margin-left: 35%; } .ro { border: none; } +.menu { + margin-left: 13%; + font-weight: bold; + font-style: italic; + margin-top: -10px; +} +.menu ul li{ + padding: 10px; +} +.menu ul > li:hover{ + background-color: #333; +} +.menu ul ul > li:hover{ + background-color: #69e; +} +.menu ul li, .menu ul{ + display: inline-block; +} +.menu ul{ + position: relative; + margin: 0; + padding: 0; + background-color: #222222; +} +.menu ul ul{ + display: none; + position: absolute; + background-color: #007FFF; + margin-top: 10px; + margin-left: -10px; +} +.menu ul a{ + color: #fff; + text-decoration: none; +} +.menu ul ul a{ + color: #fff; + text-decoration: none; +} +.menu li:hover ul{ + display: block; +} + +.menu li:hover li{ + display: block; +} a { background-color: transparent; }