mirror of https://github.com/Aidaho12/haproxy-wi
Browse Source
Add section "Delete old configs". Add new role - editor, can do the same thing as the admin, but do not delete the old versions of the configspull/19/head
Aidaho12
7 years ago
7 changed files with 78 additions and 27 deletions
@ -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('<center><h3>Choose old version</h3>') |
||||
print('<form action="delver.py#conf" method="get">') |
||||
|
||||
import glob |
||||
|
||||
os.chdir(hap_configs_dir) |
||||
|
||||
for files in sorted(glob.glob('*.cfg')): |
||||
ip = files.split("-") |
||||
if serv == ip[0]: |
||||
print('<label for="%s"> %s </label><input type="checkbox" value="%s" name="%s" id="%s"><br />' % (files, files, files, files, files)) |
||||
|
||||
print('<input type="hidden" value="%s" name="serv">' % serv) |
||||
print('<input type="hidden" value="open" name="open">') |
||||
print('<input type="hidden" value="del" name="del">') |
||||
print('<p>') |
||||
funct.mode_admin("Delete", level="admin") |
||||
print('</p></form>') |
||||
|
||||
Select = form.getvalue('del') |
||||
|
||||
if Select is not None: |
||||
os.chdir(hap_configs_dir) |
||||
print("<b>The following files were deleted:</b><br />") |
||||
for get in form: |
||||
if "cfg" in get: |
||||
try: |
||||
os.remove(form.getvalue(get)) |
||||
print(form.getvalue(get) + "<br />") |
||||
funct.logging(serv, "delver.py deleted config: %s" % form.getvalue(get)) |
||||
except OSError: |
||||
print ("Error: %s - %s." % (e.filename,e.strerror)) |
||||
|
||||
funct.footer() |
@ -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" } |
||||
|
Loading…
Reference in new issue