def get_overview(): import http.cookies from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/ajax')) template = env.get_template('overview.html') haproxy_config_path = sql.get_setting('haproxy_config_path') cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) user_id = cookie.get('uuid') haproxy_sock_port = sql.get_setting('haproxy_sock_port') listhap = sql.get_dick_permit() commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ] servers = [] for server in listhap: server_status = () cmd = 'echo "show info" |nc %s %s |grep -e "Process_num"' % ( server[2], haproxy_sock_port) 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)
async def async_get_overview(serv1, serv2): server_status = () commands2 = [ "ps ax |grep waf/bin/modsecurity |grep -v grep |wc -l" ] cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Process_num"' % (serv2, sql.get_setting('haproxy_sock_port')) keepalived = sql.select_keealived(serv2) if keepalived == 1: command = [ "ps ax |grep keepalived|grep -v grep|wc -l" ] keepalived_process = funct.ssh_command(serv2, command) else: keepalived_process = '' nginx = sql.select_nginx(serv2) if nginx == 1: command = [ "ps ax |grep nginx:|grep -v grep|wc -l" ] nginx_process = funct.ssh_command(serv2, command) else: nginx_process = '' server_status = (serv1, serv2, funct.server_status(funct.subprocess_execute(cmd)), sql.select_servers(server=serv2, keep_alive=1), funct.ssh_command(serv2, commands2), sql.select_waf_servers(serv2), keepalived, keepalived_process, nginx, nginx_process) return server_status
async def async_get_overview(serv1, serv2): haproxy_config_path = sql.get_setting('haproxy_config_path') commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ] commands1 = [ "ps ax |grep waf/bin/modsecurity |grep -v grep |wc -l" ] cmd = 'echo "show info" |nc %s %s |grep -e "Process_num"' % (serv2, haproxy_sock_port) server_status = (serv1, serv2, funct.server_status(funct.subprocess_execute(cmd)), funct.ssh_command(serv2, commands), funct.ssh_command(serv2, commands1)) return server_status
async def async_get_overview(serv1, serv2): server_status = () commands2 = ["ps ax |grep waf/bin/modsecurity |grep -v grep |wc -l"] cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Process_num"' % ( serv2, sql.get_setting('haproxy_sock_port')) server_status = (serv1, serv2, funct.server_status(funct.subprocess_execute(cmd)), sql.select_servers(server=serv2, keep_alive=1), funct.ssh_command(serv2, commands2), sql.select_waf_servers(serv2)) return server_status
def get_overview(): listhap = sql.get_dick_permit() commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ] 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])) 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>')
async def async_get_overview(serv1, serv2): haproxy_config_path = sql.get_setting('haproxy_config_path') commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ] commands2 = "ps ax |grep keep_alive.py |grep -v grep |wc -l" cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Process_num"' % (serv2, haproxy_sock_port) server_status = (serv1, serv2, funct.server_status(funct.subprocess_execute(cmd)), funct.ssh_command(serv2, commands), sql.select_servers(server=serv2, keep_alive=1), funct.subprocess_execute(commands2)) return server_status
def get_overview(): template = env.get_template('overview.html') haproxy_config_path = sql.get_setting('haproxy_config_path') commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ] commands1 = ["ps ax |grep waf/bin/modsecurity |grep -v grep |wc -l"] for server in listhap: cmd = 'echo "show info" |nc %s %s |grep -e "Process_num"' % ( server[2], haproxy_sock_port) server_status = (server[1], server[2], funct.server_status(funct.subprocess_execute(cmd)), funct.ssh_command(server[2], commands), funct.ssh_command(server[2], commands1)) servers.append(server_status) template = template.render(service_status=servers, role=sql.get_user_role_by_uuid(user_id.value)) print(template)