Pavel Loginov 4 years ago
parent 79275a6360
commit a26482623f

@ -16,7 +16,7 @@ exgrep = form.getvalue('exgrep') if form.getvalue('exgrep') else ''
if form.getvalue('rows') is None: if form.getvalue('rows') is None:
rows = 10 rows = 10
else: else:
if form.getvalue('rows1') not is None: if form.getvalue('rows1') is not None:
rows = form.getvalue('rows1') rows = form.getvalue('rows1')
else: else:
rows = form.getvalue('rows') rows = form.getvalue('rows')
@ -46,7 +46,6 @@ template = template.render(h2 = 1,
title = title, title = title,
role = role, role = role,
user = user, user = user,
onclick = "showLog()",
select_id = "serv", select_id = "serv",
selects = servers, selects = servers,
serv = form.getvalue('serv'), serv = form.getvalue('serv'),

@ -6,7 +6,7 @@
<table class="overview"> <table class="overview">
<tr class="overviewHead"> <tr class="overviewHead">
<td class="padding10 first-collumn" style="width: 10%;"> <td class="padding10 first-collumn" style="width: 10%;">
{% if onclick == 'viewLogs()' %} {% if select_id == 'viewlogs' %}
Log Log
{% else %} {% else %}
Server Server
@ -15,20 +15,21 @@
{% if onclick != 'viewLogs()' and service != 'nginx' %} {% if onclick != 'viewLogs()' and service != 'nginx' %}
<td style="width: 5%;">WAF logs</td> <td style="width: 5%;">WAF logs</td>
{% endif %} {% endif %}
<td style="width: 10%;">Number rows</td> <td>Number rows</td>
<td class="padding10" style="width: 10%;">Ex for grep</td> <td class="padding10"><span title="Find in log file(supports regular expressions)">Find (?)<span></td>
<td class="padding10"><span title="Exclude from search in log file(supports regular expressions)">Exclude (?)<span></td>
<td style="width: 10%;"> <td style="width: 10%;">
<label for="time_range_out_hour" style="padding: 0">Time range:</label> <label for="time_range_out_hour" style="padding: 0">Time range:</label>
{{ input('time_range_out_hour', value=hour, class='time-range', readonly='readonly') }}:{{ input('time_range_out_minut', value=minut, class='time-range', readonly='readonly') }} {{ input('time_range_out_hour', value=hour, class='time-range', readonly='readonly') }}:{{ input('time_range_out_minut', value=minut, class='time-range', readonly='readonly') }}
{{ input('time_range_out_hour1', value=hour1, class='time-range', readonly='readonly') }}:{{ input('time_range_out_minut1', value=minut1, class='time-range', readonly='readonly') }} {{ input('time_range_out_hour1', value=hour1, class='time-range', readonly='readonly') }}:{{ input('time_range_out_minut1', value=minut1, class='time-range', readonly='readonly') }}
</td> </td>
<td style="width: 10%;"> </td> <td></td>
</tr> </tr>
<tr> <tr>
<td class="padding10 first-collumn" style="width: 10%;"> <td class="padding10 first-collumn" style="width: 10%;">
<form action="" method="post"> <form action="" method="post" id="show_log_form">
{% if onclick == 'viewLogs()' %} {% if select_id == 'viewlogs' %}
<select autofocus required name="serv" id="{{ select_id }}"> <select autofocus required name="serv" id="{{ select_id }}">
<option disabled selected>Choose log</option> <option disabled selected>Choose log</option>
{% for select in selects %} {% for select in selects %}
{% if select.0|int() == serv|int() %} {% if select.0|int() == serv|int() %}
@ -42,29 +43,32 @@
{% include 'include/select.html' %} {% include 'include/select.html' %}
{% endif %} {% endif %}
</td> </td>
{% if onclick != 'viewLogs()' and service != 'nginx' %} {% if select_id == 'viewlogs' and service != 'nginx' %}
<td> <td>
{{ checkbox('waf') }} {{ checkbox('waf') }}
</td> </td>
{% endif %} {% endif %}
<td class="padding10" style="width: 10%;"> <td class="padding10" style="width: 10%;">
{{ input('rows', type='number', value=rows, required='required') }} {{ input('rows', type='number', value=rows, required='required', size='5') }}
</td> </td>
<td class="padding10" style="width: 10%;"> <td class="padding10" style="width: 10%;">
{{ input('grep', value=grep) }} {{ input('grep', value=grep) }}
</td> </td>
<td class="padding10" style="width: 10%;">
{{ input('exgrep', value=exgrep) }}
</td>
<td class="padding10" style="width: 10%;"> <td class="padding10" style="width: 10%;">
<div id="time-range"></div> <div id="time-range"></div>
</td> </td>
<td class="padding10 first-collumn" style="width: 10%;"> <td class="padding10 first-collumn" style="width: 10%;">
<a class="ui-button ui-widget ui-corner-all" id="show" title="Show logs" onclick="{{ onclick }}">Show</a> <button type="submit" name="Show log" value="Show" id="show_log_button">Show</button>
</form> </form>
</td> </td>
</tr> </tr>
</table> </table>
<div id="ajax"> <div id="ajax">
</div> </div>
{% if onclick == 'viewLogs()' and serv != '' and viewlogs != '' and viewlogs != 'haproxy-wi.error.log' and viewlogs != 'haproxy-wi.access.log' %} {% if select_id == 'viewlogs' and serv != '' and viewlogs != '' and viewlogs != 'haproxy-wi.error.log' and viewlogs != 'haproxy-wi.access.log' %}
<script> <script>
viewLogs() viewLogs()
if (window.matchMedia('(max-width: 786px)').matches || window.matchMedia('(max-width: 1024px)').matches || window.matchMedia('(max-width: 667px)').matches) { if (window.matchMedia('(max-width: 786px)').matches || window.matchMedia('(max-width: 1024px)').matches || window.matchMedia('(max-width: 667px)').matches) {

@ -4,6 +4,7 @@ import datetime
import funct import funct
import sql import sql
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) env = Environment(loader=FileSystemLoader('templates/'), autoescape=True)
template = env.get_template('logs.html') template = env.get_template('logs.html')
form = funct.form form = funct.form
@ -12,17 +13,17 @@ if form.getvalue('grep') is None:
grep = "" grep = ""
else: else:
grep = form.getvalue('grep') grep = form.getvalue('grep')
if form.getvalue('rows') is None: if form.getvalue('rows') is None:
rows = 10 rows = 10
else: else:
rows = form.getvalue('rows') rows = form.getvalue('rows')
if form.getvalue('viewlogs') is None: if form.getvalue('viewlogs') is None:
serv = form.getvalue('serv') serv = form.getvalue('serv')
else: else:
serv = form.getvalue('viewlogs') serv = form.getvalue('viewlogs')
hour = form.getvalue('hour') hour = form.getvalue('hour')
hour1 = form.getvalue('hour1') hour1 = form.getvalue('hour1')
minut = form.getvalue('minut') minut = form.getvalue('minut')
@ -42,41 +43,40 @@ try:
for file in filenames: for file in filenames:
curpath = os.path.join(dirpath, file) curpath = os.path.join(dirpath, file)
try: try:
funct.subprocess_execute('sudo chown apache:apache '+curpath) funct.subprocess_execute('sudo chown apache:apache ' + curpath)
except: except:
pass pass
file_modified = datetime.datetime.fromtimestamp(os.path.getmtime(curpath)) file_modified = datetime.datetime.fromtimestamp(os.path.getmtime(curpath))
if datetime.datetime.now() - file_modified > datetime.timedelta(hours=time_storage_hours): if datetime.datetime.now() - file_modified > datetime.timedelta(hours=time_storage_hours):
os.remove(curpath) os.remove(curpath)
except: except:
print('<center><div class="alert alert-danger" style="margin: 0; margin-bottom: 10px;">Can\'t delete old logs file. <br> Please check "log_time_storage" in config and <br>exist directory </div></center>') print(
'<center><div class="alert alert-danger" style="margin: 0; margin-bottom: 10px;">Can\'t delete old logs file. <br> Please check "log_time_storage" in config and <br>exist directory </div></center>')
pass pass
try: try:
user, user_id, role, token, servers = funct.get_users_params() user, user_id, role, token, servers = funct.get_users_params()
except: except:
pass pass
selects = funct.get_files(log_path, format="log") selects = funct.get_files(log_path, format="log")
selects.append(['fail2ban.log','fail2ban.log']) selects.append(['fail2ban.log', 'fail2ban.log'])
selects.append(['haproxy-wi.error.log','error.log']) selects.append(['haproxy-wi.error.log', 'error.log'])
selects.append(['haproxy-wi.access.log','access.log']) selects.append(['haproxy-wi.access.log', 'access.log'])
output_from_parsed_template = template.render(h2 = 1, output_from_parsed_template = template.render(h2=1,
autorefresh = 1, autorefresh=1,
title = "View internal logs", title="View internal logs",
role = role, role=role,
user = user, user=user,
onclick = "viewLogs()", serv=serv,
serv = serv, select_id="viewlogs",
select_id = "viewlogs", selects=selects,
selects = selects, rows=rows,
rows = rows, grep=grep,
grep = grep, hour=hour,
hour = hour, hour1=hour1,
hour1 = hour1, minut=minut,
minut = minut, minut1=minut1,
minut1 = minut1, versions=funct.versions(),
versions = funct.versions(), token=token)
token = token)
print(output_from_parsed_template) print(output_from_parsed_template)

@ -718,6 +718,14 @@ $( function() {
} ); } );
return false; return false;
}); });
$('#show_log_form').submit(function() {
if(cur_url[0] == '/app/logs.py') {
showLog();
} else {
viewLogs();
}
return false;
});
var showUpdates = $( "#show-updates" ).dialog({ var showUpdates = $( "#show-updates" ).dialog({
autoOpen: false, autoOpen: false,
resizable: false, resizable: false,

Loading…
Cancel
Save