Browse Source

v2.5.4.5

Logs time range
pull/19/head
Aidaho12 7 years ago
parent
commit
fe7b682cba
  1. 73
      app/options.py
  2. 4
      app/templates/base.html
  3. 32
      app/templates/logs.html
  4. 67
      app/templates/overview.html
  5. 30
      app/templates/viewlogs.html
  6. 21
      app/viewlogs.py
  7. BIN
      image/haproxy-wi-logs.jpeg
  8. 41
      inc/script.js
  9. 8
      inc/style.css
  10. 4
      inc/users.js

73
app/options.py

@ -163,6 +163,12 @@ if serv is not None and act == "stats":
if serv is not None and form.getvalue('rows') is not None:
rows = form.getvalue('rows')
grep = form.getvalue('grep')
hour = form.getvalue('hour')
minut = form.getvalue('minut')
hour1 = form.getvalue('hour1')
minut1 = form.getvalue('minut1')
date = hour+':'+minut
date1 = hour1+':'+minut1
if grep is not None:
grep_act = '|grep'
@ -174,25 +180,57 @@ if serv is not None and form.getvalue('rows') is not None:
if syslog_server_enable is None or syslog_server_enable == "0":
local_path_logs = funct.get_config_var('logs', 'local_path_logs')
syslog_server = serv
commands = [ 'sudo tail -%s %s %s %s' % (rows, local_path_logs, grep_act, grep) ]
commands = [ "sudo cat %s| awk '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % (local_path_logs, date, date1, rows, grep_act, grep) ]
else:
commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ]
commands = [ "sudo cat /var/log/%s/syslog.log | sed '/ %s:00/,/ %s:00/! d' |tail -%s %s %s" % (serv, date, date1, rows, grep_act, grep) ]
syslog_server = funct.get_config_var('logs', 'syslog_server')
print('<div id="logs">')
funct.ssh_command(syslog_server, commands, show_log="1")
print('</div>')
funct.ssh_command(syslog_server, commands, show_log="1")
if serv is not None and form.getvalue('rows1') is not None:
rows = form.getvalue('rows1')
grep = form.getvalue('grep')
grep = form.getvalue('grep')
hour = form.getvalue('hour')
minut = form.getvalue('minut')
hour1 = form.getvalue('hour1')
minut1 = form.getvalue('minut1')
date = hour+':'+minut
date1 = hour1+':'+minut1
if grep is not None:
grep_act = '|grep'
grep_act = '|grep'
else:
grep_act = ''
grep = ''
cmd='tail -%s %s %s %s' % (rows, '/var/log/httpd/'+serv, grep_act, grep)
cmd="cat %s| awk -F\"/|:\" '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % ('/var/log/httpd/'+serv, date, date1, rows, 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 form.getvalue('viewlogs') is not None:
viewlog = form.getvalue('viewlogs')
log_path = funct.get_config_var('main', 'log_path')
rows = form.getvalue('rows2')
grep = form.getvalue('grep')
hour = form.getvalue('hour')
minut = form.getvalue('minut')
hour1 = form.getvalue('hour1')
minut1 = form.getvalue('minut1')
date = hour+':'+minut
date1 = hour1+':'+minut1
if grep is not None:
grep_act = '|grep'
else:
grep_act = ''
grep = ''
cmd="cat %s| awk '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % (log_path + viewlog, date, date1, rows, 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()
@ -262,26 +300,7 @@ if serv is not None and act == "configShow":
funct.get_button("Just save", value="save")
funct.get_button("Upload and restart")
print('</form></center>')
if form.getvalue('viewlogs') is not None:
viewlog = form.getvalue('viewlogs')
log_path = funct.get_config_var('main', 'log_path')
try:
log = open(log_path + viewlog, "r",encoding='utf-8', errors='ignore')
except IOError:
print('<div class="alert alert-danger">Can\'t read import log file</div>')
sys.exit()
print('<center><h3>Shows log: %s</h3></center><br />' % viewlog)
i = 0
for line in log:
i = i + 1
if i % 2 == 0:
print('<div class="line3">' + line + '</div>')
else:
print('<div class="line">' + line + '</div>')
if form.getvalue('master'):
master = form.getvalue('master')
slave = form.getvalue('slave')

4
app/templates/base.html

@ -99,9 +99,9 @@
</ul>
</nav>
<div class="copyright-menu">
HAproxy-WI v2.5.4.4
HAproxy-WI v2.5.4.5
<br>
<a href="https://www.patreon.com/haproxy_wi" title="Donate" style="color: #fff; margin-left: 40px;">Patreon</a>
<a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 40px;">Patreon</a>
</div>
</div>
</div>

32
app/templates/logs.html

@ -5,22 +5,27 @@
{% endif %}
<table class="overview">
<tr class="overviewHead">
<td class="padding10 first-collumn">
<td class="padding10 first-collumn" style="width: 10%;">
{% if onclick == 'showApacheLog()' %}
Log
{% else %}
Server
{% endif %}
</td>
<td>Number rows</td>
<td class="padding10">Ex for grep</td>
<td> </td>
<td style="width: 10%;">Number rows</td>
<td class="padding10" style="width: 10%;">Ex for grep</td>
<td style="width: 10%;">
<label for="time_range_out_hour">Time range:</label>
<input type="text" id="time_range_out_hour" readonly class="time-range">:<input type="text" id="time_range_out_minut" readonly class="time-range"> -
<input type="text" id="time_range_out_hour1" readonly class="time-range">:<input type="text" id="time_range_out_minut1" readonly class="time-range">
</td>
<td style="width: 10%;"> </td>
</tr>
<tr>
<td class="padding10 first-collumn">
<td class="padding10 first-collumn" style="width: 10%;">
<form action="logs.py" method="get">
<select autofocus required name="serv" id="serv">
{% if onclick == 'showApacheLog()' %}
<select autofocus required name="serv" id="{{ select_id }}">
{% if onclick == 'showApacheLog()' or onclick == 'viewLogs()' %}
<option disabled selected>Choose log</option>
{% for select in selects %}
{% if select.2 == serv %}
@ -41,16 +46,19 @@
{% endif %}
</select>
</td>
<td>
<td class="padding10" style="width: 10%;">
<input type="number" name="rows" id="rows" value="{{ rows }}" class="form-control" required>
</td>
<td class="padding10 first-collumn">
<td class="padding10" style="width: 10%;">
<input type="text" name="grep" id="grep" class="form-control" value="{{ grep }}" >
</td>
<td class="padding10 first-collumn">
<td class="padding10" style="width: 10%;">
<div id="time-range"></div>
</td>
<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>
</form>
</td>
</td>
</tr>
</table>
<div id="ajax">
@ -60,7 +68,7 @@
window.onload = showApacheLog()
{% else %}
window.onload = showLog()
{% endif %}
{% endif %}
</script>
{% endblock %}

67
app/templates/overview.html

@ -1,67 +0,0 @@
{% extends "base.html" %}
{% block content %}
{% if role <= 1 %}
<table class="overview">
<tr class="overviewHead">
<td class="padding10">Login</td>
<td class="padding10">Email</td>
<td>Group</td>
<td class="padding10">Role</td>
<td style="width: 200px;">
<span class="add-button">
<a href="#" title="Show all users" id="show-all-users" style="color: #fff">
Show all
</a>
</span>
</td>
</tr>
{% set counter = 0 -%}
{% for user in users %}
{% set counter = counter + 1 %}
{% if counter < 4 %}
<tr>
<td class="padding10 first-collumn"> {{ user.1 }}</td>
<td class="padding10"> {{ user.2 }}</td>
<td class="second-collumn">{{ user.5 }}</td>
<td>{{ user.4 }}</td>
<td></td>
</tr>
{% else %}
<tr style="display: none;" class="show-users">
<td class="padding10 first-collumn"> {{ user.1 }}</td>
<td class="padding10"> {{ user.2 }}</td>
<td class="second-collumn">{{ user.5 }}</td>
<td>{{ user.4 }}</td>
<td></td>
</tr>
{% endif %}
{% endfor %}
</table>
{% endif %}
<table class="overview">
<tr class="overviewHead">
<td class="padding10">Server</td>
<td class="padding10">
HAproxy status
</td>
<td class="padding10">
Action
</td>
<td>
Last edit
</td>
</tr>
{% for server in servers %}
<tr>
<td class="padding10 first-collumn"><a title={{ server.1 }} style="color: #000">{{ server.1 }}</a></td>
<td class="second-collumn">{{ server.7 }}</td>
<td class="padding10">
<a href="/app/configshow.py?serv={{ server.2 }}&open=open#conf" title="Show config"><img src="/image/pic/show.png" alt="show" class="icon"></a>
<a href="/app/configshow.py?serv={{ server.2 }}&open=open#conf" title="Edit config"><img src="/image/pic/edit.png" alt="edit" class="icon"></a>
<a href="/app/configshow.py?serv={{ server.2 }}&open=open#conf" title="Compare config"><img src="/image/pic/compare.png" alt="compare" class="icon"></a>
<a href="/app/configshow.py?serv={{ server.2 }}&open=open#conf" title="Map listen/frontend/backend"><img src="/image/pic/map.png" alt="map" class="icon"></a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}

30
app/templates/viewlogs.html

@ -1,30 +0,0 @@
{% extends "base.html" %}
{% block content %}
<center>
<h3>Choose server</h3>
<p>
<form action="{{ action }}" method="get">
<select autofocus required name="serv" id="{{ select_id }}">
<option disabled>Choose server</option>
{% for select in selects %}
{% if select == serv %}
<option value="{{ select }}" selected>{{ select }}</option>
{% else %}
<option value="{{ select }}">{{ select }}</option>
{% endif %}
{% endfor %}
</select>
{% if onclick %}
<a class="ui-button ui-widget ui-corner-all" id="show" title="Show config" onclick="{{ onclick }}">Show</a>
{% else %}
<button type="submit" value="open" name="open" class="btn btn-default">Open</button>
{% endif %}
</form>
</p>
</center>
<div id="ajax">
</div>
<script>
window.onload = viewLogs()
</script>
{% endblock %}

21
app/viewlogs.py

@ -8,9 +8,19 @@ import glob
import datetime
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('viewlogs.html')
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()
@ -35,14 +45,13 @@ 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 = sql.get_dick_permit()
except:
pass
def get_files():
file = set()
file = []
for files in glob.glob(os.path.join(log_path,'*.log')):
file.add(files.split('/')[5])
file += [(files.split('/')[5], files.split('/')[5])]
return sorted(file, reverse=True)
output_from_parsed_template = template.render(h2 = 1,
@ -53,5 +62,7 @@ output_from_parsed_template = template.render(h2 = 1,
onclick = "viewLogs()",
serv = form.getvalue('viewlogs'),
select_id = "viewlogs",
selects = get_files())
selects = get_files(),
rows = rows,
grep = grep)
print(output_from_parsed_template)

BIN
image/haproxy-wi-logs.jpeg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 KiB

After

Width:  |  Height:  |  Size: 456 KiB

41
inc/script.js

@ -148,6 +148,10 @@ function showLog() {
rows: $('#rows').val(),
serv: $("#serv").val(),
grep: $("#grep").val(),
hour: $('#time_range_out_hour').val(),
minut: $('#time_range_out_minut').val(),
hour1: $('#time_range_out_hour1').val(),
minut1: $('#time_range_out_minut1').val(),
},
type: "GET",
success: function( data ) {
@ -258,6 +262,12 @@ function viewLogs() {
url: "options.py",
data: {
viewlogs: $('#viewlogs').val(),
rows2: $('#rows').val(),
grep: $("#grep").val(),
hour: $('#time_range_out_hour').val(),
minut: $('#time_range_out_minut').val(),
hour1: $('#time_range_out_hour1').val(),
minut1: $('#time_range_out_minut1').val(),
},
type: "GET",
success: function( data ) {
@ -321,7 +331,38 @@ $( function() {
$(this).addClass('current');
}
});
var now = new Date(Date.now());
var date1 = now.getHours() * 60 - 1 * 60;
var date2 = now.getHours() * 60;
$("#time-range").slider({
range: true,
min: 0,
max: 1440,
step: 15,
values: [ date1, date2 ],
slide: function(e, ui) {
var hours = Math.floor(ui.values[0] / 60);
var minutes = ui.values[0] - (hours * 60);
if(hours.toString().length == 1) hours = '0' + hours;
if(minutes.toString().length == 1) minutes = '0' + minutes;
var hours1 = Math.floor(ui.values[1] / 60);
var minutes1 = ui.values[1] - (hours1 * 60);
if(hours1.toString().length == 1) hours1 = '0' + hours1;
if(minutes1.toString().length == 1) minutes1 = '0' + minutes1;
$('#time_range_out_hour').val(hours);
$('#time_range_out_minut').val(minutes);
$('#time_range_out_hour1').val(hours1);
$('#time_range_out_minut1').val(minutes1);
}
});
$('#time_range_out_hour').val(date1/60);
$('#time_range_out_minut').val('00');
$('#time_range_out_hour1').val(date2/60);
$('#time_range_out_minut1').val('00');
$('#0').click(function() {
$('.auto-refresh-div').show("blind", "fast");
$('#0').css("display", "none");

8
inc/style.css

@ -209,6 +209,14 @@ pre {
.line:hover, .line3:hover, tr:hover {
background-color: #f6f8fa;
}
.time-range {
border: 0;
background-color: #f5faf4;
font-weight: bold;
width: 18px;
padding-left: 0;
padding-right: 0;
}
.overviewHead:hover {
background-color: #f4f9f3e6;
}

4
inc/users.js

@ -527,6 +527,10 @@ function showApacheLog() {
rows1: $('#rows').val(),
serv: $("#serv").val(),
grep: $("#grep").val(),
hour: $('#time_range_out_hour').val(),
minut: $('#time_range_out_minut').val(),
hour1: $('#time_range_out_hour1').val(),
minut1: $('#time_range_out_minut1').val(),
},
type: "GET",
success: function( data ) {

Loading…
Cancel
Save