Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #862 from f0o/issue-851
Updates syslog-page
- Loading branch information
Showing
2 changed files
with
173 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
$where = "1"; | ||
|
||
if (!empty($_POST['searchPhrase'])) | ||
{ | ||
$where .= ' AND S.msg LIKE "%'.mres($_POST['searchPhrase']).'%"'; | ||
} | ||
|
||
if ($_POST['program']) | ||
{ | ||
$where .= " AND S.program = ?"; | ||
$param[] = $_POST['program']; | ||
} | ||
|
||
if (is_numeric($_POST['device'])) | ||
{ | ||
$where .= " AND S.device_id = ?"; | ||
$param[] = $_POST['device']; | ||
} | ||
|
||
if( !empty($_POST['from']) ) { | ||
$where .= " AND timestamp >= ?"; | ||
$param[] = $_POST['from']; | ||
} | ||
if( !empty($_POST['to']) ) { | ||
$where .= " AND timestamp <= ?"; | ||
$param[] = $_POST['to']; | ||
} | ||
|
||
if ($_SESSION['userlevel'] >= '5') | ||
{ | ||
$sql = "FROM syslog AS S"; | ||
$sql .= " WHERE ".$where; | ||
} else { | ||
$sql = "FROM syslog AS S, devices_perms AS P"; | ||
$sql .= "WHERE S.device_id = P.device_id AND P.user_id = ?"; | ||
$sql .= $where; | ||
$param = array_merge(array($_SESSION['user_id']), $param); | ||
} | ||
|
||
$count_sql = "SELECT COUNT(timestamp) $sql"; | ||
$total = dbFetchCell($count_sql,$param); | ||
if (empty($total)) { | ||
$total = 0; | ||
} | ||
|
||
if (!isset($sort) || empty($sort)) { | ||
$sort = 'timestamp DESC'; | ||
} | ||
|
||
$sql .= " ORDER BY $sort"; | ||
|
||
if (isset($current)) { | ||
$limit_low = ($current * $rowCount) - ($rowCount); | ||
$limit_high = $rowCount; | ||
} | ||
|
||
if ($rowCount != -1) { | ||
$sql .= " LIMIT $limit_low,$limit_high"; | ||
} | ||
|
||
$sql = "SELECT S.*, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date $sql"; | ||
|
||
foreach (dbFetchRows($sql,$param) as $syslog) { | ||
$dev = device_by_id_cache($syslog['device_id']); | ||
$response[] = array('timestamp'=>$syslog['date'], | ||
'device_id'=>generate_device_link($dev, shorthost($dev['hostname'])), | ||
'program'=>$syslog['program'], | ||
'msg'=>htmlspecialchars($syslog['msg'])); | ||
} | ||
|
||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); | ||
echo _json_encode($output); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,106 @@ | ||
<?php | ||
|
||
if ($_vars['action'] == "expunge" && $_SESSION['userlevel'] >= '10') { dbFetchCell("TRUNCATE TABLE `syslog`"); } | ||
$no_refresh = TRUE; | ||
|
||
print_optionbar_start('25'); | ||
$param = array(); | ||
|
||
$pagetitle[] = "Syslog"; | ||
|
||
?> | ||
|
||
<form method="post" action=""> | ||
<span style="font-weight: bold;">Syslog</span> » | ||
<label><strong>Search</strong> | ||
<input type="text" name="string" id="string" value="<?php echo($_POST['string']); ?>" /> | ||
</label> | ||
<label> | ||
<strong>Program</strong> | ||
<select name="program" id="program"> | ||
<option value="">All Programs</option> | ||
<?php | ||
foreach (dbFetchRows("SELECT DISTINCT `program` FROM `syslog` ORDER BY `program`") as $data) | ||
{ | ||
echo("<option value='".$data['program']."'"); | ||
if ($data['program'] == $_POST['program']) { echo("selected"); } | ||
echo(">".$data['program']."</option>"); | ||
} | ||
?> | ||
</select> | ||
</label> | ||
<label> | ||
<strong>Device</strong> | ||
<select name="device" id="device"> | ||
<option value="">All Devices</option> | ||
<?php | ||
foreach (get_all_devices() as $hostname) | ||
{ | ||
echo("<option value='".getidbyname($hostname)."'"); | ||
|
||
if (getidbyname($hostname) == $_POST['device']) { echo("selected"); } | ||
|
||
echo(">".$hostname."</option>"); | ||
} | ||
?> | ||
</select> | ||
</label> | ||
<input type=submit class=submit value=Search> | ||
|
||
</form> | ||
|
||
<?php | ||
|
||
print_optionbar_end(); | ||
|
||
if ($_POST['string']) | ||
if ($vars['action'] == "expunge" && $_SESSION['userlevel'] >= '10') | ||
{ | ||
$where = " AND S.msg LIKE ?"; | ||
$array[] = "%".$_POST['string']."%"; | ||
dbQuery("TRUNCATE TABLE `syslog`"); | ||
print_message("syslog truncated"); | ||
} | ||
|
||
if ($_POST['program']) | ||
{ | ||
$where .= " AND S.program = ?"; | ||
$array[] = $_POST['program']; | ||
} | ||
|
||
if (is_numeric($_POST['device'])) | ||
{ | ||
$where .= " AND S.device_id = ?"; | ||
$array[] = $_POST['device']; | ||
} | ||
|
||
if ($_SESSION['userlevel'] >= '5') | ||
{ | ||
$sql = "SELECT *, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date from syslog AS S"; | ||
if (count($array)) | ||
{ | ||
$sql .= " WHERE 1 ".$where; | ||
} | ||
$sql .= " ORDER BY timestamp DESC LIMIT 1000"; | ||
} else { | ||
$sql = "SELECT *, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date from syslog AS S, devices_perms AS P"; | ||
$sql .= "WHERE S.device_id = P.device_id AND P.user_id = ?"; | ||
if (count($array)) | ||
{ | ||
$sql .= " WHERE 1 ".$where; | ||
} | ||
$sql .= " ORDER BY timestamp DESC LIMIT 1000"; | ||
|
||
$array = array_merge(array($_SESSION['user_id']), $array); | ||
} | ||
|
||
echo('<div class="panel panel-default panel-condensed"> | ||
<div class="panel-heading"> | ||
<strong>Eventlog entries</strong> | ||
</div> | ||
<table class="table table-hover table-condensed table-striped">'); | ||
|
||
foreach (dbFetchRows($sql, $array) as $entry) | ||
{ | ||
$entry = array_merge($entry, device_by_id_cache($entry['device_id'])); | ||
|
||
include("includes/print-syslog.inc.php"); | ||
} | ||
|
||
echo("</table> | ||
</div>"); | ||
|
||
$pagetitle[] = "Syslog"; | ||
?> | ||
|
||
<div class="table-responsive"> | ||
<table id="syslog" class="table table-hover table-condensed table-striped"> | ||
<thead> | ||
<tr> | ||
<th data-column-id="timestamp" data-order="desc">Datetime</th> | ||
<th data-column-id="device_id">Hostname</th> | ||
<th data-column-id="program">Program</th> | ||
<th data-column-id="msg">Message</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
</div> | ||
|
||
<script> | ||
|
||
var grid = $("#syslog").bootgrid({ | ||
ajax: true, | ||
templates: { | ||
header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+ | ||
"<div class=\"col-sm-9 actionBar\"><span class=\"pull-left\">"+ | ||
"<form method=\"post\" action=\"\" class=\"form-inline\" role=\"form\" id=\"result_form\">"+ | ||
"<div class=\"form-group\">"+ | ||
"<select name=\"device\" id=\"device\" class=\"form-control input-sm\">"+ | ||
"<option value=\"\">All Devices</option>"+ | ||
<?php | ||
foreach( get_all_devices() as $hostname ) { | ||
$device_id = getidbyname($hostname); | ||
if (device_permitted($device_id)) { | ||
echo('"<option value=\"'.$device_id.'\"'); | ||
if ($device_id == $vars['device']) { echo(' selected'); } | ||
echo('>'.$hostname.'</option>"+'); | ||
} | ||
} | ||
?> | ||
"</select>"+ | ||
"</div>"+ | ||
"<div class=\"form-group\">"+ | ||
"<select name=\"program\" id=\"program\" class=\"form-control input-sm\">"+ | ||
"<option value=\"\">All Programs</option>"+ | ||
<?php | ||
foreach( dbFetchRows("SELECT DISTINCT `program` FROM `syslog` ORDER BY `program`") as $data ) { | ||
echo('"<option value=\"'.$data['program'].'\"'); | ||
if ($data['program'] == $vars['program']) { echo(' selected'); } | ||
echo('>'.$data['program'].'</option>"+'); | ||
} | ||
?> | ||
"</select>"+ | ||
"</div>"+ | ||
"<div class=\"form-group\">"+ | ||
"<input name=\"from\" type=\"text\" class=\"form-control\" id=\"dtpickerfrom\" maxlength=\"16\" value=\"<?php echo $vars['from']; ?>\" placeholder=\"From\" data-date-format=\"YYYY-MM-DD HH:mm\">"+ | ||
"</div>"+ | ||
"<div class=\"form-group\">"+ | ||
"<input name=\"to\" type=\"text\" class=\"form-control\" id=\"dtpickerto\" maxlength=\"16\" value=\"<?php echo $vars['to']; ?>\" placeholder=\"To\" data-date-format=\"YYYY-MM-DD HH:mm\">"+ | ||
"</div>"+ | ||
"<button type=\"submit\" class=\"btn btn-default input-sm\">Filter</button>"+ | ||
"</form></span></div>"+ | ||
"<div class=\"col-sm-3 actionBar\"><p class=\"{{css.actions}}\"></p></div></div></div>" | ||
|
||
}, | ||
post: function () | ||
{ | ||
return { | ||
id: "syslog", | ||
device: '<?php echo htmlspecialchars($vars['device']); ?>', | ||
program: '<?php echo htmlspecialchars($vars['program']); ?>', | ||
to: '<?php echo htmlspecialchars($vars['to']); ?>', | ||
from: '<?php echo htmlspecialchars($vars['from']); ?>', | ||
}; | ||
}, | ||
url: "/ajax_table.php" | ||
}); | ||
|
||
$(function () { | ||
$("#dtpickerfrom").datetimepicker(); | ||
$("#dtpickerfrom").on("dp.change", function (e) { | ||
$("#dtpickerto").data("DateTimePicker").minDate(e.date); | ||
}); | ||
$("#dtpickerto").datetimepicker(); | ||
$("#dtpickerto").on("dp.change", function (e) { | ||
$("#dtpickerfrom").data("DateTimePicker").maxDate(e.date); | ||
}); | ||
if( $("#dtpickerfrom").val() != "" ) { | ||
$("#dtpickerto").data("DateTimePicker").minDate($("#dtpickerfrom").val()); | ||
} | ||
if( $("#dtpickerto").val() != "" ) { | ||
$("#dtpickerfrom").data("DateTimePicker").maxDate($("#dtpickerto").val()); | ||
} else { | ||
$("#dtpickerto").data("DateTimePicker").maxDate('<?php echo date('Y-m-d H:i'); ?>'); | ||
} | ||
}); | ||
</script> |