diff --git a/cgi-bin/delver.py b/cgi-bin/delver.py new file mode 100644 index 00000000..131ca851 --- /dev/null +++ b/cgi-bin/delver.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +import html +import cgi +import os +import funct +import configparser + +form = cgi.FieldStorage() +serv = form.getvalue('serv') + +funct.head("Old Versions HAproxy config") +funct.check_config() +funct.check_login() + +path_config = "haproxy-webintarface.config" +config = configparser.ConfigParser() +config.read(path_config) + +hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') + +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('
') + + import glob + + os.chdir(hap_configs_dir) + + for files in sorted(glob.glob('*.cfg')): + ip = files.split("-") + if serv == ip[0]: + print('
' % (files, files, files, files, files)) + + print('' % serv) + print('') + print('') + print('

') + funct.mode_admin("Delete", level="admin") + print('

') + + Select = form.getvalue('del') + + if Select is not None: + os.chdir(hap_configs_dir) + print("The following files were deleted:
") + for get in form: + if "cfg" in get: + try: + os.remove(form.getvalue(get)) + print(form.getvalue(get) + "
") + funct.logging(serv, "delver.py deleted config: %s" % form.getvalue(get)) + except OSError: + print ("Error: %s - %s." % (e.filename,e.strerror)) + +funct.footer() \ No newline at end of file diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index c4b712a1..9cf5cbd0 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -70,15 +70,21 @@ 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): +def mode_admin(button, **kwargs): cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) - role = cookie.get('role') - - if role.value == "admin": + role = cookie.get('role') + level = kwargs.get("level") + + if level is None: + level = "editor" + + if role.value == "admin" and level == "admin": + print('' % button) + elif role.value == "admin" or role.value == "editor" and level == "editor": print('' % button) def links(): @@ -92,7 +98,9 @@ def links(): print('Compare ') print('Add ') print('Edit ') - print('Upload old') + print(' | Versions: ') + print('Upload') + print('Delete') show_login_links() def head(title): @@ -257,8 +265,6 @@ def show_log(stdout): print('
' + line + '
') else: print('
' + line + '
') - - print('') def show_ip(stdout): for line in stdout: diff --git a/cgi-bin/login.py b/cgi-bin/login.py index 02c31506..5e9ca01d 100644 --- a/cgi-bin/login.py +++ b/cgi-bin/login.py @@ -66,7 +66,6 @@ if login is not None and password is not None: print('Redirecting') print('') print('' % ref) - funct.logging("localhost", "login now") break login_page("error") diff --git a/cgi-bin/logs.py b/cgi-bin/logs.py index 22f6f136..1afea9a1 100644 --- a/cgi-bin/logs.py +++ b/cgi-bin/logs.py @@ -63,7 +63,7 @@ if form.getvalue('serv') is not None: grep = '' syslog_server_enable = config.get('logs', 'syslog_server_enable') - if syslog_server_enable is None or syslog_server_enable == "disable": + if syslog_server_enable is None or syslog_server_enable == "0": local_path_logs = config.get('logs', 'local_path_logs') syslog_server = serv commands = [ 'sudo tail -%s %s %s %s' % (rows, local_path_logs, grep_act, grep) ] diff --git a/cgi-bin/options.py b/cgi-bin/options.py index 9998c951..a87003dd 100644 --- a/cgi-bin/options.py +++ b/cgi-bin/options.py @@ -50,8 +50,7 @@ if form.getvalue('name') is not None: conf = open("/home/ploginov/haproxy/cgi-bin/hap_config/test.cfg", "r") s = form.getvalue('s') for line in conf: - #print(line) + if s in line and name in line: -# print(line) print("yes") break diff --git a/cgi-bin/users b/cgi-bin/users index a0502589..5b5ed9a6 100644 --- a/cgi-bin/users +++ b/cgi-bin/users @@ -1,2 +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" } diff --git a/index.html b/index.html index 39c10f47..c8ad7e11 100644 --- a/index.html +++ b/index.html @@ -20,22 +20,10 @@ Add
Edit config
Upload old config
+ Delete old config
-
-
-

Welcome! HAproxy Web intarface

-

Choose your destiny!

- View stats
- Edit settings
- Logs
- Compare
- Show
- Edit config
- Upload old config
- -