mirror of https://github.com/Aidaho12/haproxy-wi
v2.7.3
parent
01fc3c49be
commit
7bec23f837
33
app/funct.py
33
app/funct.py
|
@ -186,13 +186,13 @@ def ssh_connect(serv, **kwargs):
|
|||
return 'Unable to verify server\'s host key: %s ' % badHostKeyException
|
||||
pass
|
||||
except Exception as e:
|
||||
if e.args[1] == "No such file or directory":
|
||||
if e == "No such file or directory":
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">{}. Check ssh key</div>'.format(e.args[1]))
|
||||
print('<div class="alert alert-danger">{}. Check ssh key</div>'.format(e))
|
||||
else:
|
||||
return '{}. Check ssh key'.format(e.args[1])
|
||||
return '{}. Check ssh key'.format(e)
|
||||
pass
|
||||
elif e.args[1] == "Invalid argument":
|
||||
elif e == "Invalid argument":
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">Check the IP of the new server</div>')
|
||||
else:
|
||||
|
@ -200,9 +200,9 @@ def ssh_connect(serv, **kwargs):
|
|||
pass
|
||||
else:
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">{}</div>'.format(e.args[1]))
|
||||
print('<div class="alert alert-danger">{}</div>'.format(e))
|
||||
else:
|
||||
error = e.args[1]
|
||||
error = e
|
||||
pass
|
||||
if kwargs.get('check'):
|
||||
return False
|
||||
|
@ -462,15 +462,9 @@ def server_status(stdout):
|
|||
if "Ncat: Connection refused." not in line:
|
||||
for k in line:
|
||||
proc_count = k.split(":")[1]
|
||||
err = 1
|
||||
else:
|
||||
err = 0
|
||||
proc_count = 0
|
||||
|
||||
if err != 0:
|
||||
print('<span class="serverUp"> UP</span> running %s processes' % proc_count)
|
||||
else:
|
||||
print('<span class="serverDown"> DOWN</span> running %s processes' % proc_count)
|
||||
return proc_count
|
||||
|
||||
def ssh_command(serv, commands, **kwargs):
|
||||
ssh = ssh_connect(serv)
|
||||
|
@ -490,7 +484,7 @@ def ssh_command(serv, commands, **kwargs):
|
|||
elif kwargs.get("server_status") == "1":
|
||||
server_status(stdout)
|
||||
else:
|
||||
print(stdout.read().decode(encoding='UTF-8'))
|
||||
return stdout.read().decode(encoding='UTF-8')
|
||||
|
||||
print(stderr.read().decode(encoding='UTF-8'))
|
||||
try:
|
||||
|
@ -510,18 +504,25 @@ def subprocess_execute(cmd):
|
|||
|
||||
return output, stderr
|
||||
|
||||
def show_backends(serv):
|
||||
def show_backends(serv, **kwargs):
|
||||
import json
|
||||
cmd='echo "show backend" |nc %s 1999' % serv
|
||||
output, stderr = subprocess_execute(cmd)
|
||||
|
||||
ret = ""
|
||||
for line in output:
|
||||
if "#" in line or "stats" in line:
|
||||
continue
|
||||
if line != "":
|
||||
back = json.dumps(line).split("\"")
|
||||
if kwargs.get('ret'):
|
||||
ret += back[1]
|
||||
ret += "<br />"
|
||||
else:
|
||||
print(back[1]+"<br>")
|
||||
|
||||
if kwargs.get('ret'):
|
||||
return ret
|
||||
|
||||
def get_files():
|
||||
import glob
|
||||
file = set()
|
||||
|
|
|
@ -23,7 +23,7 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
output_from_parsed_template = template.render(h2 = 1,
|
||||
template = template.render(h2 = 1,
|
||||
autorefresh = 1,
|
||||
title = "Overview",
|
||||
role = sql.get_user_role_by_uuid(user_id.value),
|
||||
|
@ -31,4 +31,4 @@ output_from_parsed_template = template.render(h2 = 1,
|
|||
users = users,
|
||||
groups = groups,
|
||||
token = token)
|
||||
print(output_from_parsed_template)
|
||||
print(template)
|
60
app/ovw.py
60
app/ovw.py
|
@ -12,49 +12,57 @@ hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
|||
form = cgi.FieldStorage()
|
||||
|
||||
def get_overview():
|
||||
listhap = sql.get_dick_permit()
|
||||
import os, http.cookies
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
env = Environment(loader=FileSystemLoader('templates/ajax'))
|
||||
template = env.get_template('overview.html')
|
||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||
user_id = cookie.get('uuid')
|
||||
|
||||
listhap = sql.get_dick_permit()
|
||||
commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ]
|
||||
servers = []
|
||||
|
||||
for server in listhap:
|
||||
print('<tr><td class="padding10 first-collumn"><a href="#%s" title="Go to %s status" style="color: #000">%s</a></td><td class="second-collumn">' % (server[1], server[1], server[1]))
|
||||
server_status = ()
|
||||
cmd = 'echo "show info" |nc %s 1999 |grep -e "Process_num"' % server[2]
|
||||
funct.server_status(funct.subprocess_execute(cmd))
|
||||
print('</td><td>')
|
||||
if funct.is_admin():
|
||||
print('<a id="%s" class="start" title="Start HAproxy service"><img src=/image/pic/start.png alt="start" class="icon"></a>' % server[2])
|
||||
print('<a id="%s" class="stop" title="Stop HAproxy service"><img src=/image/pic/stop.png alt="start" class="icon"></a>' % server[2])
|
||||
print('<a id="%s" class="restart" title="Restart HAproxy service"><img src=/image/pic/update.png alt="restart" class="icon"></a>' % server[2])
|
||||
if funct.is_admin(level = 2):
|
||||
print('<a href="/app/configshow.py?serv=%s&open=open#conf" title="Show config"><img src=/image/pic/show.png alt="show" class="icon"></a>' % server[2])
|
||||
print('<a href="/app/config.py?serv=%s&open=open#conf" title="Edit config"><img src=/image/pic/edit.png alt="edit" class="icon"></a>' % server[2])
|
||||
print('<a href="/app/diff.py?serv=%s&open=open#diff" title="Compare config"><img src=/image/pic/compare.png alt="compare" class="icon"></a>' % server[2])
|
||||
print('<a href="/app/map.py?serv=%s&open=open#map" title="Map listen/frontend/backend"><img src=/image/pic/map.png alt="map" class="icon"></a>' % server[2])
|
||||
print('</td><td>')
|
||||
funct.ssh_command(server[2], commands)
|
||||
print('</td><td></td></tr>')
|
||||
server_status = (server[1],server[2], funct.server_status(funct.subprocess_execute(cmd)), funct.ssh_command(server[2], commands))
|
||||
servers.append(server_status)
|
||||
|
||||
template = template.render(service_status = servers, role = sql.get_user_role_by_uuid(user_id.value))
|
||||
print(template)
|
||||
|
||||
def get_overviewServers():
|
||||
import os, http.cookies
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
env = Environment(loader=FileSystemLoader('templates/ajax'))
|
||||
template = env.get_template('overviewServers.html')
|
||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||
user_id = cookie.get('uuid')
|
||||
|
||||
listhap = sql.get_dick_permit()
|
||||
commands = [ "top -u haproxy -b -n 1" ]
|
||||
servers = []
|
||||
|
||||
for server in sorted(listhap):
|
||||
print('<tr><td class="overviewTr first-collumn"><a name="'+server[1]+'"></a><h3 title="IP ' + server[2] + '">' + server[1] + ':</h3></td>')
|
||||
print('<td class="overviewTd" style="padding-top: 10px;"><pre style="font-size: 12px;">')
|
||||
server_status = ()
|
||||
cmd = 'echo "show info" |nc %s 1999 |grep -e "Ver\|CurrConns\|SessRate\|Maxco\|MB\|Uptime:"' % server[2]
|
||||
out = funct.subprocess_execute(cmd)
|
||||
|
||||
out1 = ""
|
||||
for k in out:
|
||||
if "Ncat: Connection refused." not in k:
|
||||
for r in k:
|
||||
print(r)
|
||||
out1 += r
|
||||
out1 += "<br />"
|
||||
else:
|
||||
print("Can\'t connect to HAproxy")
|
||||
print('</pre></td><td style="padding-top: 10px;"><pre style="font-size: 12px; padding-left: 0px;">')
|
||||
funct.ssh_command(server[2], commands)
|
||||
print('</td><td style="padding: 10px;font-size: 12px;">')
|
||||
funct.show_backends(server[2])
|
||||
print('</pre></td><td></td></tr>')
|
||||
out1 = "Can\'t connect to HAproxy"
|
||||
|
||||
server_status = (server[1],server[2], out1, funct.ssh_command(server[2], commands),funct.show_backends(server[2], ret=1))
|
||||
servers.append(server_status)
|
||||
|
||||
#print(servers)
|
||||
template = template.render(service_status = servers, role = sql.get_user_role_by_uuid(user_id.value))
|
||||
print(template)
|
||||
|
||||
def get_map(serv):
|
||||
from datetime import datetime
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
{% for service in service_status %}
|
||||
<tr>
|
||||
<td class="padding10 first-collumn">
|
||||
<a href="#{{ service.0 }}" title="Go to {{ service.0 }} status" style="color: #000">{{ service.0 }}</a>
|
||||
</td>
|
||||
<td class="second-collumn">
|
||||
{% if service.2|int() >= 1 %}
|
||||
<span class="serverUp"> UP</span> running {{service.2 }} processes
|
||||
{% else %}
|
||||
<span class="serverDown"> DOWN</span> running {{service.2 }} processes
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if role <= 1 %}
|
||||
<a id="{{ service.1 }}" class="start" title="Start HAproxy service">
|
||||
<img src=/image/pic/start.png alt="start" class="icon">
|
||||
</a>
|
||||
<a id="{{ service.1 }}" class="stop" title="Stop HAproxy service">
|
||||
<img src=/image/pic/stop.png alt="start" class="icon">
|
||||
</a>
|
||||
<a id="{{ service.1 }}" class="restart" title="Restart HAproxy service">
|
||||
<img src=/image/pic/update.png alt="restart" class="icon">
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if role <= 2 %}
|
||||
<a href="/app/configshow.py?serv={{ service.1 }}&open=open#conf" title="Show config">
|
||||
<img src="/image/pic/show.png" alt="show" class="icon">
|
||||
</a>
|
||||
<a href="/app/config.py?serv={{ service.1 }}&open=open#conf" title="Edit config">
|
||||
<img src="/image/pic/edit.png" alt="edit" class="icon">
|
||||
</a>
|
||||
<a href="/app/diff.py?serv={{ service.1 }}&open=open#diff" title="Compare config">
|
||||
<img src="/image/pic/compare.png" alt="compare" class="icon">
|
||||
</a>
|
||||
<a href="/app/map.py?serv={{ service.1 }}&open=open#map" title="Map listen/frontend/backend">
|
||||
<img src="/image/pic/map.png" alt="map" class="icon">
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ service.3 }}
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endfor %}
|
|
@ -0,0 +1,24 @@
|
|||
{% for service in service_status %}
|
||||
<tr>
|
||||
<td class="overviewTr first-collumn">
|
||||
<a name="{{ service.0 }}"></a>
|
||||
<h3 title="IP {{ service.1 }}"> {{ service.0 }} :</h3>
|
||||
</td>
|
||||
<td class="overviewTd" style="padding-top: 10px;">
|
||||
<pre style="font-size: 12px;">
|
||||
{{ service.2 }}
|
||||
</pre>
|
||||
</td>
|
||||
<td style="padding-top: 10px;">
|
||||
<pre style="font-size: 12px; padding-left: 0px;">
|
||||
{{ service.3 }}
|
||||
</pre>
|
||||
</td>
|
||||
<td style="padding: 10px;font-size: 12px;">
|
||||
<pre>
|
||||
{{ service.4 }}
|
||||
</pre>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endfor %}
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<center>
|
||||
<form name="auth" id="auth" action="login.py" class="form-horizontal" method="get">
|
||||
<form name="auth" id="auth" action="login.py" class="form-horizontal" method="post">
|
||||
{{error_log}}
|
||||
{{error}}
|
||||
{{db_create}}
|
||||
|
|
|
@ -309,7 +309,7 @@
|
|||
</div>
|
||||
<div id="group_error" style="display: none;">
|
||||
<div class="alert alert-danger">
|
||||
<b>Do not edit this section if your group is "ALL"!</b> Add first<a href="app/users.py#groups" title="Admin Area: Groups">group</a> or edit your own group at<a href="app/users.py#users" title="Admin Area: Users">users</a> page
|
||||
<b>Do not edit this section if your group is "ALL"!</b> Add first<a href="users.py#groups" title="Admin Area: Groups">group</a> or edit your own group at<a href="users.py#users" title="Admin Area: Users">users</a> page
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
@ -324,6 +324,7 @@
|
|||
$("input[type=checkbox]").checkboxradio( "disable" );
|
||||
$("select").selectmenu( "disable" );
|
||||
$("input").attr( "readonly", "readonly" );
|
||||
$('.delete').remove()
|
||||
}, 500 );
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue