View Apache logs, bugs fix
pull/19/head
Aidaho12 7 years ago
parent 02d5f9ab6b
commit 9b76d5e21e

@ -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)

@ -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('<div id"logs">')
print('<div id="logs">')
funct.ssh_command(syslog_server, commands, show_log="1")
print('</div>')
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)

@ -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:

@ -289,10 +289,16 @@
<tr style="width: 50%;">
<td class="first-collumn" valign="top" style="padding-top: 15px;">
{% if ssh_enable == 1 %}
<label for="ssh_enable">Enable SSH<input type="checkbox" id="ssh_enable" checked>
<label for="ssh_enable">Enable SSH key</label><input type="checkbox" id="ssh_enable" checked>
{% else %}
<label for="ssh_enable">Enable SSH<input type="checkbox" id="ssh_enable">
<label for="ssh_enable">Enable SSH key</label><input type="checkbox" id="ssh_enable">
{% endif %}
<div class="tooltip tooltipTop">
<b>Note:</b> If enabled, the key will be used, if turned off - the password.
<br>Do not forget to download the keys to all servers or install the sudo without a password
<br>
<br>
</div>
</td>
<td style="padding-top: 15px;">
<p>

@ -50,37 +50,34 @@
</li>
<li><a href=/app/edit.py title="Runtime API" class="runtime">Runtime API</a> </li>
<li><a title="Actions with Haproxy configs" class="config-show">Haproxy</a>
<li><a href=/app/configshow.py title="Show Haproxy Config" class="config-show head-submenu">Show config</a></li>
<li><a href=/app/diff.py title="Compare Haproxy Configs" class="compare head-submenu">Compare configs</a></li>
<li><a href=/app/configshow.py title="Show Haproxy Config" class="config-show head-submenu">Show config</a></li>
<li><a href=/app/diff.py title="Compare Haproxy Configs" class="compare head-submenu">Compare configs</a></li>
{% if user %}
{% if role <= 2 %}
<li><a href=/app/add.py#listner title="Add single listen" class="add head-submenu">Add listen</a></li>
<li><a href=/app/add.py#frontend title="Add single frontend" class="add head-submenu">Add frontend</a></li>
<li><a href=/app/add.py#backend title="Add single backend" class="add head-submenu">Add backend</a></li>
<li><a href=/app/add.py#ssl title="Upload SSL cert" class="cert head-submenu">SSL</a></li>
<li><a href=/app/config.py title="Edit Haproxy Config" class="edit head-submenu">Edit config</a> </li>
{% endif %}
{% if role <= 1 %}
<li><a href=/app/ihap.py title="Installation HAProxy" class="hap head-submenu">Installation</a> </li>
{% endif %}
</li>
{% if role <= 2 %}
<li><a href=/app/add.py#listner title="Add single listen" class="add head-submenu">Add listen</a></li>
<li><a href=/app/add.py#frontend title="Add single frontend" class="add head-submenu">Add frontend</a></li>
<li><a href=/app/add.py#backend title="Add single backend" class="add head-submenu">Add backend</a></li>
<li><a href=/app/add.py#ssl title="Upload SSL cert" class="cert head-submenu">SSL</a></li>
<li><a href=/app/config.py title="Edit Haproxy Config" class="edit head-submenu">Edit config</a> </li>
{% endif %}
{% if role <= 1 %}
<li><a href=/app/ihap.py title="Installation HAProxy" class="hap head-submenu">Installation</a> </li>
{% endif %}
</li>
{% if role <= 2 %}
<li><a title="Actions with configs" class="version">Versions</a>
<li><a href=/app/configver.py title="Upload old versions configs" class="upload head-submenu">Upload</a></li>
{% endif %}
{% if role <= 1 %}
<li><a href=/app/delver.py title="Delete old versions configs" class="delete head-submenu">Delete</a></li>
{% endif %}
</li>
{% if role <= 1 %}
<li><a title="Keepalived" class="ha">Keepalived</a>
<li><a href=/app/ha.py title="Create HA cluster" class="keepalived head-submenu">HA</a></li>
<li><a href=/app/keepalivedconfig.py title="Edit keepalived config" class="edit head-submenu">Edit config</a></li>
</li>
{% endif %}
<li><a title="Actions with configs" class="version">Versions</a>
<li><a href=/app/configver.py title="Upload old versions configs" class="upload head-submenu">Upload</a></li>
{% if role <= 1 %}
<li><a href=/app/delver.py title="Delete old versions configs" class="delete head-submenu">Delete</a></li>
{% endif %}
</li>
{% if user %}
<li><a href=/app/login.py?logout=logout title="Logout, user name: {{ user }}" class="login">Logout</a></li>
{% else %}
<li><a href=/app/login.py title="Login" class="login">Login</a></li>
{% endif %}
{% if role <= 1 %}
<li><a title="Admin area" class="admin">Admin area</a>
<li><a href=/app/users.py#users title="Actions with users" class="users head-submenu">Users</a></li>
@ -89,13 +86,19 @@
<li><a href=/app/users.py#roles title="Users roles" class="role head-submenu">Roles</a></li>
<li><a href=/app/users.py#ssh title="Users roles" class="admin head-submenu">SSH credentials</a></li>
<li><a href=/app/settings.py title="View settings" class="settings head-submenu">View settings</a></li>
<li><a href=/app/viewlogs.py title="View users actions logs" class="logs head-submenu">View logs</a></li>
<li><a href=/app/viewlogs.py title="View users actions logs" class="logs head-submenu">Users logs</a></li>
<li><a href=/app/apachelogs.py title="View Apache logs" class="logs head-submenu">Apache logs</a></li>
</li>
{% endif %}
{% endif %}
{% if user %}
<li><a href=/app/login.py?logout=logout title="Logout, user name: {{ user }}" class="login">Logout</a></li>
{% else %}
<li><a href=/app/login.py title="Login" class="login">Login</a></li>
{% endif %}
</ul>
</nav>
<div class="copyright-menu">HAproxy-WI v2.5.3</div>
<div class="copyright-menu">HAproxy-WI v2.5.4</div>
</div>
</div>
<div class="container">

@ -1,9 +1,17 @@
{% extends "base.html" %}
{% block content %}
{% if onclick == 'showApacheLog()' %}
<script src="/inc/users.js"></script>
{% endif %}
<table class="overview">
<tr class="overviewHead">
<td class="padding10 first-collumn">Server</td>
<td class="padding10 first-collumn">
{% if onclick == 'showApacheLog()' %}
Log
{% else %}
Server
{% endif %}
</td>
<td>Number rows</td>
<td class="padding10">Ex for grep</td>
<td> </td>
@ -13,6 +21,15 @@
<form action="logs.py" method="get">
<select autofocus required name="serv" id="serv">
<option disabled selected>Choose server</option>
{% if onclick == 'showApacheLog()' %}
{% for select in selects %}
{% if select.2 == serv %}
<option value="{{ select.0 }}" selected>{{ select.1 }}</option>
{% else %}
<option value="{{ select.0 }}">{{ select.1 }}</option>
{% endif %}
{% endfor %}
{% else %}
{% for select in selects %}
{% if select.2 == serv %}
<option value="{{ select.2 }}" selected>{{ select.1 }}</option>
@ -20,6 +37,7 @@
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endif %}
{% endfor %}
{% endif %}
</select>
</td>
<td>
@ -37,7 +55,11 @@
<div id="ajax">
</div>
<script>
window.onload = showLog()
{% if onclick == 'showApacheLog()' %}
window.onload = showApacheLog()
{% else %}
window.onload = showLog()
{% endif %}
</script>
{% endblock %}

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

@ -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());
}
} );
}

@ -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 ""

Loading…
Cancel
Save