pull/30/head
Aidaho12 2018-08-01 14:06:09 +06:00
parent 01fc3c49be
commit 7bec23f837
7 changed files with 133 additions and 54 deletions

View File

@ -186,13 +186,13 @@ def ssh_connect(serv, **kwargs):
return 'Unable to verify server\'s host key: %s ' % badHostKeyException return 'Unable to verify server\'s host key: %s ' % badHostKeyException
pass pass
except Exception as e: except Exception as e:
if e.args[1] == "No such file or directory": if e == "No such file or directory":
if kwargs.get('check'): 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: else:
return '{}. Check ssh key'.format(e.args[1]) return '{}. Check ssh key'.format(e)
pass pass
elif e.args[1] == "Invalid argument": elif e == "Invalid argument":
if kwargs.get('check'): if kwargs.get('check'):
print('<div class="alert alert-danger">Check the IP of the new server</div>') print('<div class="alert alert-danger">Check the IP of the new server</div>')
else: else:
@ -200,9 +200,9 @@ def ssh_connect(serv, **kwargs):
pass pass
else: else:
if kwargs.get('check'): 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: else:
error = e.args[1] error = e
pass pass
if kwargs.get('check'): if kwargs.get('check'):
return False return False
@ -462,15 +462,9 @@ def server_status(stdout):
if "Ncat: Connection refused." not in line: if "Ncat: Connection refused." not in line:
for k in line: for k in line:
proc_count = k.split(":")[1] proc_count = k.split(":")[1]
err = 1
else: else:
err = 0
proc_count = 0 proc_count = 0
return proc_count
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)
def ssh_command(serv, commands, **kwargs): def ssh_command(serv, commands, **kwargs):
ssh = ssh_connect(serv) ssh = ssh_connect(serv)
@ -490,7 +484,7 @@ def ssh_command(serv, commands, **kwargs):
elif kwargs.get("server_status") == "1": elif kwargs.get("server_status") == "1":
server_status(stdout) server_status(stdout)
else: else:
print(stdout.read().decode(encoding='UTF-8')) return stdout.read().decode(encoding='UTF-8')
print(stderr.read().decode(encoding='UTF-8')) print(stderr.read().decode(encoding='UTF-8'))
try: try:
@ -510,17 +504,24 @@ def subprocess_execute(cmd):
return output, stderr return output, stderr
def show_backends(serv): def show_backends(serv, **kwargs):
import json import json
cmd='echo "show backend" |nc %s 1999' % serv cmd='echo "show backend" |nc %s 1999' % serv
output, stderr = subprocess_execute(cmd) output, stderr = subprocess_execute(cmd)
ret = ""
for line in output: for line in output:
if "#" in line or "stats" in line: if "#" in line or "stats" in line:
continue continue
if line != "": if line != "":
back = json.dumps(line).split("\"") back = json.dumps(line).split("\"")
print(back[1]+"<br>") if kwargs.get('ret'):
ret += back[1]
ret += "<br />"
else:
print(back[1]+"<br>")
if kwargs.get('ret'):
return ret
def get_files(): def get_files():
import glob import glob

View File

@ -23,12 +23,12 @@ try:
except: except:
pass pass
output_from_parsed_template = template.render(h2 = 1, template = template.render(h2 = 1,
autorefresh = 1, autorefresh = 1,
title = "Overview", title = "Overview",
role = sql.get_user_role_by_uuid(user_id.value), role = sql.get_user_role_by_uuid(user_id.value),
user = user, user = user,
users = users, users = users,
groups = groups, groups = groups,
token = token) token = token)
print(output_from_parsed_template) print(template)

View File

@ -12,49 +12,57 @@ hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
form = cgi.FieldStorage() form = cgi.FieldStorage()
def get_overview(): def get_overview():
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() listhap = sql.get_dick_permit()
commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ] commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ]
servers = []
for server in listhap: 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] cmd = 'echo "show info" |nc %s 1999 |grep -e "Process_num"' % server[2]
funct.server_status(funct.subprocess_execute(cmd)) server_status = (server[1],server[2], funct.server_status(funct.subprocess_execute(cmd)), funct.ssh_command(server[2], commands))
print('</td><td>') servers.append(server_status)
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>')
template = template.render(service_status = servers, role = sql.get_user_role_by_uuid(user_id.value))
print(template)
def get_overviewServers(): 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() listhap = sql.get_dick_permit()
commands = [ "top -u haproxy -b -n 1" ] commands = [ "top -u haproxy -b -n 1" ]
servers = []
for server in sorted(listhap): 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>') server_status = ()
print('<td class="overviewTd" style="padding-top: 10px;"><pre style="font-size: 12px;">')
cmd = 'echo "show info" |nc %s 1999 |grep -e "Ver\|CurrConns\|SessRate\|Maxco\|MB\|Uptime:"' % server[2] cmd = 'echo "show info" |nc %s 1999 |grep -e "Ver\|CurrConns\|SessRate\|Maxco\|MB\|Uptime:"' % server[2]
out = funct.subprocess_execute(cmd) out = funct.subprocess_execute(cmd)
out1 = ""
for k in out: for k in out:
if "Ncat: Connection refused." not in k: if "Ncat: Connection refused." not in k:
for r in k: for r in k:
print(r) out1 += r
out1 += "<br />"
else: else:
print("Can\'t connect to HAproxy") out1 = "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) server_status = (server[1],server[2], out1, funct.ssh_command(server[2], commands),funct.show_backends(server[2], ret=1))
print('</td><td style="padding: 10px;font-size: 12px;">') servers.append(server_status)
funct.show_backends(server[2])
print('</pre></td><td></td></tr>') #print(servers)
template = template.render(service_status = servers, role = sql.get_user_role_by_uuid(user_id.value))
print(template)
def get_map(serv): def get_map(serv):
from datetime import datetime from datetime import datetime

View File

@ -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 %}

View File

@ -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 %}

View File

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<center> <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_log}}
{{error}} {{error}}
{{db_create}} {{db_create}}

View File

@ -309,7 +309,7 @@
</div> </div>
<div id="group_error" style="display: none;"> <div id="group_error" style="display: none;">
<div class="alert alert-danger"> <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>
</div> </div>
<script> <script>
@ -324,6 +324,7 @@
$("input[type=checkbox]").checkboxradio( "disable" ); $("input[type=checkbox]").checkboxradio( "disable" );
$("select").selectmenu( "disable" ); $("select").selectmenu( "disable" );
$("input").attr( "readonly", "readonly" ); $("input").attr( "readonly", "readonly" );
$('.delete').remove()
}, 500 ); }, 500 );
} }