mirror of https://github.com/Aidaho12/haproxy-wi
v1.6
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
parent
7c0b4b2d59
commit
aab03e46fc
|
@ -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()
|
|
@ -70,15 +70,21 @@ def show_login_links():
|
|||
login = cookie.get('login')
|
||||
|
||||
if login is None:
|
||||
print('<a href=/cgi-bin/login.py? title="Login" style="size:5">Login</a>')
|
||||
print('<a style="margin-left: 40px;" href=/cgi-bin/login.py? title="Login" style="size:5">Login</a>')
|
||||
else:
|
||||
print('<a href=/cgi-bin/login.py?logout=logout title="Logout" style="size:5">Logout</a>')
|
||||
print('<a style="margin-left: 40px;" href=/cgi-bin/login.py?logout=logout title="Logout" style="size:5">Logout</a>')
|
||||
|
||||
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 type="submit">%s</button>' % button)
|
||||
elif role.value == "admin" or role.value == "editor" and level == "editor":
|
||||
print('<button type="submit">%s</button>' % button)
|
||||
|
||||
def links():
|
||||
|
@ -92,7 +98,9 @@ def links():
|
|||
print('<a href=/cgi-bin/diff.py title="Compare Configs">Compare</a> ')
|
||||
print('<a href=/cgi-bin/add.py title="Add single listen/frontend/backend" style="size:5">Add</a> ')
|
||||
print('<a href=/cgi-bin/config.py title="Edit Config" style="size:5">Edit</a> ')
|
||||
print('<a href=/cgi-bin/configver.py title="Upload old config" style="size:5">Upload old</a>')
|
||||
print('<span style="color: #fff"> | Versions: </span>')
|
||||
print('<a href=/cgi-bin/configver.py title="Upload old versions configs" style="size:5">Upload</a>')
|
||||
print('<a href=/cgi-bin/delver.py title="Delete old versions configs" style="size:5">Delete</a>')
|
||||
show_login_links()
|
||||
|
||||
def head(title):
|
||||
|
@ -257,8 +265,6 @@ def show_log(stdout):
|
|||
print('<div class="line3">' + line + '</div>')
|
||||
else:
|
||||
print('<div class="line">' + line + '</div>')
|
||||
|
||||
print('</div></div>')
|
||||
|
||||
def show_ip(stdout):
|
||||
for line in stdout:
|
||||
|
|
|
@ -66,7 +66,6 @@ if login is not None and password is not None:
|
|||
print('<html><head><title>Redirecting</title><meta charset="UTF-8">')
|
||||
print('<link href="/style.css" rel="stylesheet">')
|
||||
print('<meta http-equiv="refresh" content="0; url=%s">' % ref)
|
||||
funct.logging("localhost", "login now")
|
||||
break
|
||||
login_page("error")
|
||||
|
||||
|
|
|
@ -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) ]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" }
|
||||
|
|
16
index.html
16
index.html
|
@ -20,22 +20,10 @@
|
|||
<a href=/cgi-bin/add.py title="Add single listen/frontend/backend">Add</a> <br />
|
||||
<a href="cgi-bin/config.py" title="Edit settings">Edit config</a> <br />
|
||||
<a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br />
|
||||
<a href="cgi-bin/delver.py" title="Upload old config">Delete old config</a> <br />
|
||||
<div class="copyright">
|
||||
HAproxy Web Interface v1.3
|
||||
HAproxy Web Interface v1.6
|
||||
</div>
|
||||
</div>
|
||||
</center>
|
||||
<center>
|
||||
<h2>Welcome! HAproxy Web intarface</h2>
|
||||
<h3>Choose your destiny!</h3>
|
||||
<a href="cgi-bin/viewsttats.py" title="View stats">View stats</a> <br />
|
||||
<a href="cgi-bin/edit.py" title="Edit settings">Edit settings</a> <br />
|
||||
<a href="cgi-bin/logs.py" title="View logs">Logs</a> <br />
|
||||
<a href="cgi-bin/diff.py" title="Compare Configs">Compare</a> <br />
|
||||
<a href="cgi-bin/configshow.py" title="Show Config">Show</a> <br />
|
||||
<a href="cgi-bin/config.py" title="Edit settings">Edit config</a> <br />
|
||||
<a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br />
|
||||
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue