diff --git a/app/apachelogs.py b/app/apachelogs.py new file mode 100644 index 00000000..8bbb88ef --- /dev/null +++ b/app/apachelogs.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +import html +import cgi +import funct +import sql +import os, http +from jinja2 import Environment, FileSystemLoader +env = Environment(loader=FileSystemLoader('templates/')) +template = env.get_template('logs.html') +form = cgi.FieldStorage() + +if form.getvalue('grep') is None: + grep = "" +else: + grep = form.getvalue('grep') + +if form.getvalue('rows') is None: + rows = 10 +else: + rows = form.getvalue('rows') + +print('Content-type: text/html\n') +funct.check_login() +funct.page_for_admin() + +try: + cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) + user_id = cookie.get('uuid') + user = sql.get_user_name_by_uuid(user_id.value) + servers = [('haproxy-wi.error.log','error.log'), ('haproxy-wi.access.log','access.log')] +except: + pass + +#print(sql.get_dick_permit()) + +output_from_parsed_template = template.render(h2 = 1, + autorefresh = 1, + title = "Show Apache logs", + role = sql.get_user_role_by_uuid(user_id.value), + user = user, + onclick = "showApacheLog()", + select_id = "serv", + selects = servers, + serv = form.getvalue('serv'), + rows = rows, + grep = grep) +print(output_from_parsed_template) + + + diff --git a/app/options.py b/app/options.py index cc66d4e7..1edf6a7e 100644 --- a/app/options.py +++ b/app/options.py @@ -158,10 +158,28 @@ if serv is not None and form.getvalue('rows') is not None: else: commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ] syslog_server = config.get('logs', 'syslog_server') - print('
') + print('
') funct.ssh_command(syslog_server, commands, show_log="1") print('
') +if serv is not None and form.getvalue('rows1') is not None: + rows = form.getvalue('rows1') + grep = form.getvalue('grep') + + if grep is not None: + grep_act = '|grep' + else: + grep_act = '' + grep = '' + + cmd='tail -%s %s %s %s' % (rows, '/var/log/httpd/'+serv, grep_act, grep) + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True) + stdout, stderr = p.communicate() + output = stdout.splitlines() + + funct.show_log(output) + print(stderr) + if serv is not None and act == "showMap": ovw.get_map(serv) diff --git a/app/ovw.py b/app/ovw.py index a44e7857..847bb703 100644 --- a/app/ovw.py +++ b/app/ovw.py @@ -151,13 +151,16 @@ def get_map(serv): G.add_node(node,pos=(k,i),label_pos=(k,i+150)) if "bind" in line: - bind = line.split(":") - if stats_port not in bind[1]: - bind[1] = bind[1].strip(' ') - bind = bind[1].split("crt") - node = node.strip(' \t\n\r') - node = node + ":" + bind[0] - G.add_node(node,pos=(k,i),label_pos=(k,i+150)) + try: + bind = line.split(":") + if stats_port not in bind[1]: + bind[1] = bind[1].strip(' ') + bind = bind[1].split("crt") + node = node.strip(' \t\n\r') + node = node + ":" + bind[0] + G.add_node(node,pos=(k,i),label_pos=(k,i+150)) + except: + pass if "server " in line or "use_backend" in line or "default_backend" in line and "stats" not in line: if "timeout" not in line and "default-server" not in line and "#" not in line and "stats" not in line: diff --git a/app/templates/admin.html b/app/templates/admin.html index 653c5456..5e9ce9c7 100644 --- a/app/templates/admin.html +++ b/app/templates/admin.html @@ -289,10 +289,16 @@ {% if ssh_enable == 1 %} -
diff --git a/app/templates/logs.html b/app/templates/logs.html index 0a0bf9f6..02eee2fe 100644 --- a/app/templates/logs.html +++ b/app/templates/logs.html @@ -1,9 +1,17 @@ {% extends "base.html" %} {% block content %} - +{% if onclick == 'showApacheLog()' %} + +{% endif %} - + @@ -13,6 +21,15 @@
Server + {% if onclick == 'showApacheLog()' %} + Log + {% else %} + Server + {% endif %} + Number rows Ex for grep
@@ -37,7 +55,11 @@
{% endblock %} \ No newline at end of file diff --git a/inc/script.js b/inc/script.js index 09f97a85..51b4f54f 100644 --- a/inc/script.js +++ b/inc/script.js @@ -67,6 +67,9 @@ function startSetInterval(interval) { } else if (cur_url[0] == "viewlogs.py") { intervalId = setInterval('viewLogs()', interval); viewLogs(); + } else if (cur_url[0] == "apachelogs.py") { + intervalId = setInterval('showApacheLog()', interval); + showApacheLog(); } } function pauseAutoRefresh() { @@ -275,6 +278,10 @@ $( function() { theme:"minimal-dark", scrollInertia:30 }); + $(".top-link").mCustomScrollbar({ + theme:"minimal-dark", + scrollInertia:30 + }); $(".diff").mCustomScrollbar({ theme:"minimal-dark", scrollInertia:30 diff --git a/inc/users.js b/inc/users.js index e4f625c1..f68fd82a 100644 --- a/inc/users.js +++ b/inc/users.js @@ -464,4 +464,19 @@ function updateSSH() { } } } ); +} +function showApacheLog() { + $.ajax( { + url: "options.py", + data: { + rows1: $('#rows').val(), + serv: $("#serv").val(), + grep: $("#grep").val(), + }, + type: "GET", + success: function( data ) { + $("#ajax").html(data); + window.history.pushState("Logs", "Logs", cur_url[0]+"?serv="+$("#serv").val()+"&rows1="+$('#rows').val()+"&grep="+$("#grep").val()); + } + } ); } \ No newline at end of file diff --git a/update.sh b/update.sh index fdfd4485..5030a15e 100644 --- a/update.sh +++ b/update.sh @@ -15,7 +15,7 @@ pip3 install -r ../requirements.txt echo "" echo "#################" echo "Change in config:" -diff --expand-tabs -W 100 -y /tmp/haproxy-webintarface.config haproxy-webintarface.config |grep "|" +diff --expand-tabs -W 100 -y /tmp/haproxy-webintarface.config haproxy-webintarface.config echo "" echo "Please set your config" echo ""