mirror of https://github.com/Aidaho12/haproxy-wi
v1.8.1
parent
eb0f59d6ca
commit
6854bcda33
|
@ -55,11 +55,11 @@ else:
|
|||
print('</select></td>')
|
||||
print('<td style="width: 35%;"><select autofocus required name="servaction">')
|
||||
print('<option disabled selected>Choose action</option>')
|
||||
print('<option value=1 %s>Disable server</option>' % selected1)
|
||||
print('<option value=2 %s>Enable server</option>' % selected2)
|
||||
print('<option value=1 %s>Disable</option>' % selected1)
|
||||
print('<option value=2 %s>Enable</option>' % selected2)
|
||||
print('<option value=3 %s>Show</option>' % selected3)
|
||||
print('</select></td>')
|
||||
print('<td><input type="text" name="servbackend" size=40 placeholder="Backend/Server, show info, pools or help" required class="form-control">')
|
||||
print('<td><input type="text" name="servbackend" size=35 title="Frontend, backend/server, show: info, pools or help" required class="form-control">')
|
||||
|
||||
print('</td></tr>'
|
||||
'<tr style="border:none;">'
|
||||
|
@ -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'
|
||||
|
||||
|
|
107
cgi-bin/funct.py
107
cgi-bin/funct.py
|
@ -72,8 +72,21 @@ def show_login_links():
|
|||
if login is None:
|
||||
print('<li><a href=/cgi-bin/login.py? title="Login">Login</a></li>')
|
||||
else:
|
||||
print('<li><a href=/cgi-bin/login.py?logout=logout title="Logout">Logout</a></li>')
|
||||
print('<li><a href=/cgi-bin/login.py?logout=logout title="Logout, user name: %s">Logout</a></li>' % 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 type="submit">%s</button>' % button)
|
||||
print('<button type="submit" class="btn btn-default">%s</button>' % button)
|
||||
elif role.value == "admin" or role.value == "editor" and level == "editor":
|
||||
print('<button type="submit">%s</button>' % button)
|
||||
print('<button type="submit" class="btn btn-default">%s</button>' % button)
|
||||
|
||||
def links():
|
||||
print('<nav class="menu">'
|
||||
|
@ -113,10 +126,11 @@ def links():
|
|||
'</li>'
|
||||
'<li><a href="#">Versions</a>'
|
||||
'<ul>'
|
||||
'<li><a href=/cgi-bin/configver.py title="Upload old versions configs" style="size:5">Upload</a></li>'
|
||||
'<li><a href=/cgi-bin/delver.py title="Delete old versions configs" style="size:5">Delete</a></li>'
|
||||
'</ul>'
|
||||
'</li>')
|
||||
'<li><a href=/cgi-bin/configver.py title="Upload old versions configs">Upload</a></li>')
|
||||
if is_admin():
|
||||
print('<li><a href=/cgi-bin/delver.py title="Delete old versions configs">Delete</a></li>')
|
||||
print('</ul>'
|
||||
'</li>')
|
||||
show_login_links()
|
||||
print('</ul>'
|
||||
'</nav>')
|
||||
|
@ -334,7 +348,71 @@ def ssh_command(serv, commands, **kwargs):
|
|||
print('<div style="margin: -10px;">'+stdout.read().decode(encoding='UTF-8')+'</div>')
|
||||
|
||||
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('<option value="%s" %s>%s</option>' % (listhap.get(i), selected, i))
|
||||
|
||||
def chooseServer(formName, title, note):
|
||||
print('<center><h2>' + title + '</h2>')
|
||||
print('<h3>Choose server</h3>')
|
||||
|
@ -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('<option value="%s" %s>%s</option>' % (listhap.listhap.get(i), selected, i))
|
||||
|
||||
choose_only_select(serv, servNew=servNew)
|
||||
|
||||
print('</select>')
|
||||
print('<button type="submit" value="open" name="open">Open</button></p></form>')
|
||||
print('<button type="submit" value="open" name="open" class="btn btn-default">Open</button></p></form>')
|
||||
if note == "y":
|
||||
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p>')
|
||||
|
||||
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'
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{ "name": "admin", "lists": "all" }
|
||||
{ "name": "mysql", "lists": "mysql" }
|
||||
{ "name": "web", "lists": "web" }
|
|
@ -26,6 +26,7 @@ print('<center>'
|
|||
'<td class="padding10">Server</td>'
|
||||
'<td>Number rows</td>'
|
||||
'<td class="padding10">Ex for grep</td>'
|
||||
'<td> </td>'
|
||||
'</tr>'
|
||||
'<tr>'
|
||||
'<td class="padding10">'
|
||||
|
@ -33,16 +34,7 @@ print('<center>'
|
|||
'<select autofocus required name="serv" id="serv">'
|
||||
'<option disabled>Choose server</option>')
|
||||
|
||||
for i in sorted(listhap.listhap):
|
||||
if listhap.listhap.get(i) == serv:
|
||||
selected = 'selected'
|
||||
else:
|
||||
selected = ''
|
||||
|
||||
if listhap.listhap.get(i) == '172.28.5.17' or listhap.listhap.get(i) == '172.28.9.161':
|
||||
continue
|
||||
|
||||
print('<option value="%s" %s>%s</option>' % (listhap.listhap.get(i), selected, i))
|
||||
funct.choose_only_select(serv)
|
||||
|
||||
print('</select>')
|
||||
|
||||
|
@ -58,13 +50,11 @@ else:
|
|||
|
||||
print('</td><td><input type="number" name="rows" %s class="form-control" required></td>' % rows)
|
||||
print('<td><input type="text" name="grep" class="form-control" %s >' % grep)
|
||||
print('</td></tr>'
|
||||
'<tr style="border:none;">'
|
||||
'<th style="border:none;">'
|
||||
'<td class="padding10" >'
|
||||
'<button type="submit">Show</button>'
|
||||
'</td>'
|
||||
'</th></form>'
|
||||
print('</td>'
|
||||
'<td class="padding10" >'
|
||||
'<button type="submit">Show</button>'
|
||||
'</td>'
|
||||
'</form>'
|
||||
'</tr></table>')
|
||||
|
||||
if form.getvalue('serv') is not None:
|
||||
|
|
|
@ -24,33 +24,33 @@ except IOError:
|
|||
print('<h2>Quick Status </h2>'
|
||||
'<table class="overview">')
|
||||
|
||||
commands = [ "ps -Af |grep [h]aproxy |wc -l" ]
|
||||
if funct.is_admin():
|
||||
|
||||
print('<tr class="overviewHead">'
|
||||
'<td class="padding10">User name</td>'
|
||||
'<td>Login name</td>'
|
||||
'<td class="padding10">'
|
||||
'Role'
|
||||
'<!--<span class="add-button" title="Just a button, do nothing )">+ Add </span>-->'
|
||||
'<span class="add-button">'
|
||||
'<a href="#" title="Show all users" id="show-all-users" style="color: #fff">'
|
||||
'Show all'
|
||||
'</a>'
|
||||
'</span>'
|
||||
'</td>'
|
||||
'</tr>')
|
||||
print('<tr class="overviewHead">'
|
||||
'<td class="padding10">User name</td>'
|
||||
'<td>Group</td>'
|
||||
'<td class="padding10">'
|
||||
'Role'
|
||||
'<!--<span class="add-button" title="Just a button, do nothing )">+ Add </span>-->'
|
||||
'<span class="add-button">'
|
||||
'<a href="#" title="Show all users" id="show-all-users" style="color: #fff">'
|
||||
'Show all'
|
||||
'</a>'
|
||||
'</span>'
|
||||
'</td>'
|
||||
'</tr>')
|
||||
|
||||
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('<tr ' + style + '><td class="padding10">' + users['firstName'] + ' ' + users['lastName'] +'</td><td>')
|
||||
print(users['login']+'</td><td>')
|
||||
print(users['role'])
|
||||
print('</td></tr>')
|
||||
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('<tr ' + style + '><td class="padding10">' + users['firstName'] + ' ' + users['lastName'] +'</td><td>')
|
||||
print(users['group']+'</td><td>')
|
||||
print(users['role'])
|
||||
print('</td></tr>')
|
||||
|
||||
print('<tr class="overviewHead">'
|
||||
'<td class="padding10">Server</td>'
|
||||
|
@ -65,15 +65,20 @@ print('<tr class="overviewHead">'
|
|||
'</a></span>'
|
||||
'</td>'
|
||||
'</tr>')
|
||||
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('<tr><td class="padding10">' + i + '</td><td>')
|
||||
funct.ssh_command(listhap.listhap.get(i), commands, server_status="1")
|
||||
funct.ssh_command(listhap.get(i), commands, server_status="1")
|
||||
print('</td><td>')
|
||||
print('<a href="/cgi-bin/configshow.py?serv=%s&open=open#conf" title="Show config"><img src=/image/pic/show.png alt="show" class="icon"></a>' % listhap.listhap.get(i))
|
||||
print('<a href="/cgi-bin/config.py?serv=%s&open=open#conf" title="Edit config"><img src=/image/pic/edit.png alt="edit" class="icon"></a>' % listhap.listhap.get(i))
|
||||
print('<a href="/cgi-bin/diff.py?serv=%s&open=open#diff" title="Compare config"><img src=/image/pic/compare.png alt="compare" class="icon"></a>' % listhap.listhap.get(i))
|
||||
print('<a href="/cgi-bin/map.py?serv=%s&open=open#map" title="Map listen/frontend/backend"><img src=/image/pic/map.png alt="map" class="icon"></a>' % listhap.listhap.get(i))
|
||||
print('<a href="/cgi-bin/configshow.py?serv=%s&open=open#conf" title="Show config"><img src=/image/pic/show.png alt="show" class="icon"></a>' % listhap.get(i))
|
||||
print('<a href="/cgi-bin/config.py?serv=%s&open=open#conf" title="Edit config"><img src=/image/pic/edit.png alt="edit" class="icon"></a>' % listhap.get(i))
|
||||
print('<a href="/cgi-bin/diff.py?serv=%s&open=open#diff" title="Compare config"><img src=/image/pic/compare.png alt="compare" class="icon"></a>' % listhap.get(i))
|
||||
print('<a href="/cgi-bin/map.py?serv=%s&open=open#map" title="Map listen/frontend/backend"><img src=/image/pic/map.png alt="map" class="icon"></a>' % listhap.get(i))
|
||||
print('</td></tr>')
|
||||
|
||||
print('</table><table><tr class="overviewHead">'
|
||||
'<td class="padding10">Server</td>'
|
||||
'<td class="padding10">'
|
||||
|
@ -86,10 +91,10 @@ print('</table><table><tr class="overviewHead">'
|
|||
'</tr>')
|
||||
print('</td></tr>')
|
||||
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('<tr><td class="overviewTr"><h3 title="IP ' + listhap.listhap.get(i) + '">' + i + ':</h3></td>')
|
||||
for i in sorted(listhap):
|
||||
print('<tr><td class="overviewTr"><h3 title="IP ' + listhap.get(i) + '">' + i + ':</h3></td>')
|
||||
print('<td class="overviewTd"><span style="margin-left: -10px;">Total listen/frontend/backend:</span><pre>')
|
||||
funct.ssh_command(listhap.listhap.get(i), commands)
|
||||
funct.ssh_command(listhap.get(i), commands)
|
||||
print('</pre></td></tr>')
|
||||
|
||||
print('<tr></table>')
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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')
|
||||
|
|
13
style.css
13
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue