From 6854bcda33572f17df0ef9866436bc869effcaf6 Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Fri, 23 Feb 2018 23:37:59 +0600 Subject: [PATCH] v1.8.1 --- cgi-bin/edit.py | 10 ++-- cgi-bin/funct.py | 107 +++++++++++++++++++++++++++++++++++------- cgi-bin/groups | 3 ++ cgi-bin/logs.py | 24 +++------- cgi-bin/overview.py | 73 ++++++++++++++-------------- cgi-bin/users | 6 +-- cgi-bin/viewsttats.py | 2 +- style.css | 13 ++++- 8 files changed, 159 insertions(+), 79 deletions(-) create mode 100644 cgi-bin/groups diff --git a/cgi-bin/edit.py b/cgi-bin/edit.py index c9874149..e780a183 100644 --- a/cgi-bin/edit.py +++ b/cgi-bin/edit.py @@ -55,11 +55,11 @@ else: print('') print('') -print('') +print('') print('' '' @@ -73,9 +73,9 @@ if form.getvalue('servaction') is not None: backend = form.getvalue('servbackend') if action == '1': - enable = 'disable server' + enable = 'disable' elif action == '2': - enable = 'enable server' + enable = 'enable' elif action == '3': enable = 'show' diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 4231a091..6ed402d9 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -72,8 +72,21 @@ def show_login_links(): if login is None: print('
  • Login
  • ') else: - print('
  • Logout
  • ') + print('
  • Logout
  • ' % login.value) +def is_admin(): + cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) + role = cookie.get('role') + + try: + if role.value == "admin": + return True + else: + return False + except: + return False + pass + def mode_admin(button, **kwargs): cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) role = cookie.get('role') @@ -83,9 +96,9 @@ def mode_admin(button, **kwargs): level = "editor" if role.value == "admin" and level == "admin": - print('' % button) + print('' % button) elif role.value == "admin" or role.value == "editor" and level == "editor": - print('' % button) + print('' % button) def links(): print('') @@ -334,7 +348,71 @@ def ssh_command(serv, commands, **kwargs): print('
    '+stdout.read().decode(encoding='UTF-8')+'
    ') print(stderr.read().decode(encoding='UTF-8')) + +def get_group_permit(): + import json + cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) + login = cookie.get('login') + USERS = fullpath + '/cgi-bin/users' + + try: + with open(USERS, "r") as user: + pass + except IOError: + print("Can't load users DB") + + for f in open(USERS, 'r'): + users = json.loads(f) + if login.value in users['login']: + group = users['group'] + GROUPS = fullpath + '/cgi-bin/groups' + try: + with open(GROUPS, "r") as user: + pass + except IOError: + print("Can't load groups DB") + + for f in open(GROUPS, 'r'): + groups = json.loads(f) + if group in groups['name']: + list = groups['lists'] + break + else: + list = "" + + return list + +def get_dick_after_permit(): + list_serv = get_group_permit() + + if list_serv == "all": + from listserv import listhap as listhap + elif list_serv == "web": + from listserv import web as listhap + elif list_serv == "mysql": + from listserv import mysql as listhap + else: + from listserv import no_group as listhap + + return listhap + +def choose_only_select(serv, **kwargs): + listhap = get_dick_after_permit() + + if kwargs.get("servNew"): + servNew = kwargs.get("servNew") + else: + servNew = "" + + for i in sorted(listhap): + if listhap.get(i) == serv or listhap.get(i) == servNew: + selected = 'selected' + else: + selected = '' + + print('' % (listhap.get(i), selected, i)) + def chooseServer(formName, title, note): print('

    ' + title + '

    ') print('

    Choose server

    ') @@ -345,23 +423,16 @@ def chooseServer(formName, title, note): form = cgi.FieldStorage() serv = form.getvalue('serv') servNew = form.getvalue('serNew') - - for i in sorted(listhap.listhap): - if listhap.listhap.get(i) == serv or listhap.listhap.get(i) == servNew: - selected = 'selected' - else: - selected = '' - - print('' % (listhap.listhap.get(i), selected, i)) + + choose_only_select(serv, servNew=servNew) print('') - print('

    ') + print('

    ') if note == "y": print('

    Note: If you reconfigure First server, second will reconfigured automatically

    ') def choose_server_with_vip(serv): - import listserv as listhap - listhap.listhap = merge_two_dicts(listhap.listhap, listhap.list_hap_vip) + listhap.listhap = merge_two_dicts(listhap.listhap, listhap.listhap_vip) for i in sorted(listhap.listhap): if listhap.listhap.get(i) == serv: selected = 'selected' diff --git a/cgi-bin/groups b/cgi-bin/groups new file mode 100644 index 00000000..5b20e841 --- /dev/null +++ b/cgi-bin/groups @@ -0,0 +1,3 @@ +{ "name": "admin", "lists": "all" } +{ "name": "mysql", "lists": "mysql" } +{ "name": "web", "lists": "web" } \ No newline at end of file diff --git a/cgi-bin/logs.py b/cgi-bin/logs.py index 60d118f9..d4480f56 100644 --- a/cgi-bin/logs.py +++ b/cgi-bin/logs.py @@ -26,6 +26,7 @@ print('
    ' 'Server' 'Number rows' 'Ex for grep' + ' ' '' '' '' @@ -33,16 +34,7 @@ print('
    ' '') @@ -58,13 +50,11 @@ else: print('' % rows) print('' % grep) -print('' - '' - '' - '' - '' - '' - '' +print('' + '' + '' + '' + '' '') if form.getvalue('serv') is not None: diff --git a/cgi-bin/overview.py b/cgi-bin/overview.py index 485ea1e5..19406768 100644 --- a/cgi-bin/overview.py +++ b/cgi-bin/overview.py @@ -24,33 +24,33 @@ except IOError: print('

    Quick Status

    ' '') -commands = [ "ps -Af |grep [h]aproxy |wc -l" ] +if funct.is_admin(): -print('' - '' - '' - '' - '') + print('' + '' + '' + '' + '') -i = 0 -style = "" -for f in open(USERS, 'r'): - i = i + 1 - users = json.loads(f) - if i is 4: - style = 'style="display: none;" class="show-users"' - print('') + i = 0 + style = "" + for f in open(USERS, 'r'): + i = i + 1 + users = json.loads(f) + if i is 4: + style = 'style="display: none;" class="show-users"' + print('') print('' '' @@ -65,15 +65,20 @@ print('' '' '' '') -for i in sorted(listhap.listhap): + +listhap = funct.get_dick_after_permit() + +commands = [ "ps -Af |grep [h]aproxy |wc -l" ] +for i in sorted(listhap): print('') + print('
    User nameLogin name' - 'Role' - '' - '' - '' - 'Show all' - '' - '' - '
    User nameGroup' + 'Role' + '' + '' + '' + 'Show all' + '' + '' + '
    ' + users['firstName'] + ' ' + users['lastName'] +'') - print(users['login']+'') - print(users['role']) - print('
    ' + users['firstName'] + ' ' + users['lastName'] +'') + print(users['group']+'') + print(users['role']) + print('
    Server
    ' + i + '') - funct.ssh_command(listhap.listhap.get(i), commands, server_status="1") + funct.ssh_command(listhap.get(i), commands, server_status="1") print('') - print('show' % listhap.listhap.get(i)) - print('edit' % listhap.listhap.get(i)) - print('compare' % listhap.listhap.get(i)) - print('map' % listhap.listhap.get(i)) + print('show' % listhap.get(i)) + print('edit' % listhap.get(i)) + print('compare' % listhap.get(i)) + print('map' % listhap.get(i)) print('
    ' '' '
    Server' @@ -86,10 +91,10 @@ print('
    ' '') print('') commands = [ "cat /etc/haproxy/haproxy.cfg |grep -E '^listen|^backend|^frontend' |grep -v stats |wc -l", "uname -smor", "haproxy -v |head -1", "top -u haproxy -b -n 1" ] -for i in sorted(listhap.listhap): - print('') +for i in sorted(listhap): + print('') print('') print('

    ' + i + ':

    ' + i + ':

    Total listen/frontend/backend:
    ')
    -	funct.ssh_command(listhap.listhap.get(i), commands)
    +	funct.ssh_command(listhap.get(i), commands)
     	print('
    ') diff --git a/cgi-bin/users b/cgi-bin/users index 5b5ed9a6..aed30cbe 100644 --- a/cgi-bin/users +++ b/cgi-bin/users @@ -1,3 +1,3 @@ -{ "firstName": "admin", "lastName": "admin", "login": "admin", "password": "admin", "role": "admin" } -{ "firstName": "Editor", "lastName": "Editor", "login": "Editor", "password": "Editor@123", "role": "editor" } -{ "firstName": "Guest", "lastName": "Guest", "login": "Guest", "password": "Guest@123", "role": "guest" } +{ "firstName": "admin", "lastName": "admin", "login": "admin", "password": "admin", "role": "admin", "group": "admin" } +{ "firstName": "Editor", "lastName": "Editor", "login": "Editor", "password": "Editor@123", "role": "editor", "group": "admin" } +{ "firstName": "Guest", "lastName": "Guest", "login": "Guest", "password": "Guest@123", "role": "guest", "group": "admin" } diff --git a/cgi-bin/viewsttats.py b/cgi-bin/viewsttats.py index b3432918..f8d47c4d 100644 --- a/cgi-bin/viewsttats.py +++ b/cgi-bin/viewsttats.py @@ -18,7 +18,7 @@ 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) +listhap.listhap = funct.merge_two_dicts(listhap.listhap, listhap.listhap_vip) form = cgi.FieldStorage() serv = form.getvalue('serv') diff --git a/style.css b/style.css index d1736aed..84eca285 100644 --- a/style.css +++ b/style.css @@ -78,6 +78,7 @@ iframe { } .conteiner { box-shadow: 1px 1px 5px grey; + border-radius: 5px; clear: both; margin-top: 65px; min-height: calc(100vh - 115px); @@ -312,8 +313,18 @@ iframe { padding-right: 0; } .ui-state-default { - background-color: #EBF1F1; + background-color: #EBF1F1 !important; } +.ui-state-active { + background-color: #5D9CEB !important; + border-color: #5D9CEB !important; +} +.ui-tooltip, .arrow:after { + background: #33414E !important; + border: 1px solid #33414E !important; + border-radius: 5px !important; + color: #fff !important; + } a { background-color: transparent; }