Browse Source

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 configs
pull/19/head
Aidaho12 7 years ago
parent
commit
aab03e46fc
  1. 58
      cgi-bin/delver.py
  2. 20
      cgi-bin/funct.py
  3. 1
      cgi-bin/login.py
  4. 2
      cgi-bin/logs.py
  5. 3
      cgi-bin/options.py
  6. 1
      cgi-bin/users
  7. 16
      index.html

58
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('<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()

20
cgi-bin/funct.py

@ -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')
level = kwargs.get("level")
if role.value == "admin":
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):
@ -258,8 +266,6 @@ def show_log(stdout):
else:
print('<div class="line">' + line + '</div>')
print('</div></div>')
def show_ip(stdout):
for line in stdout:
print(line)

1
cgi-bin/login.py

@ -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")

2
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) ]

3
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

1
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" }

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…
Cancel
Save