mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-04-19 20:09:14 +03:00
Changed Download logs to download the logs currently being shown, not always the current logs - note, doesn't filter first.
Removed "delete" case in logs.php Moved logging check out of case statements to avoid duplication. Changed wording of clear logs warning. Pretty-print the JSON on log export - requires PHP 5.4.
This commit is contained in:
parent
ff8df5e5b2
commit
befb891174
2 changed files with 69 additions and 68 deletions
|
@ -114,7 +114,7 @@ if ($blocklogin === TRUE) {
|
||||||
<div id="dnssecinfo">
|
<div id="dnssecinfo">
|
||||||
</div>
|
</div>
|
||||||
<div id="clearlogs" style="display: none;">
|
<div id="clearlogs" style="display: none;">
|
||||||
Are you sure you want to clear all the logs? Maybe download them
|
Are you sure you want to clear the current logs? Maybe download them
|
||||||
first<?php if($allowrotatelogs) { ?>, or use "Rotate logs" to save
|
first<?php if($allowrotatelogs) { ?>, or use "Rotate logs" to save
|
||||||
them on the server<?php } ?>?
|
them on the server<?php } ?>?
|
||||||
</div>
|
</div>
|
||||||
|
@ -1121,13 +1121,13 @@ $(document).ready(function () {
|
||||||
icon: 'img/export.png',
|
icon: 'img/export.png',
|
||||||
text: 'Download logs',
|
text: 'Download logs',
|
||||||
click: function () {
|
click: function () {
|
||||||
var $zexport = $.get("logs.php?action=export", function(data) {
|
var $zexport = $.get("logs.php?action=export&logfile=" + $('#logfile').val(), function(data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
blob = new Blob([data], { type: 'text/plain' });
|
blob = new Blob([data], { type: 'text/plain' });
|
||||||
var dl = document.createElement('a');
|
var dl = document.createElement('a');
|
||||||
dl.addEventListener('click', function(ev) {
|
dl.addEventListener('click', function(ev) {
|
||||||
dl.href = URL.createObjectURL(blob);
|
dl.href = URL.createObjectURL(blob);
|
||||||
dl.download = 'nseditlogs.txt';
|
dl.download = $('#logfile').val() == "" ? 'nseditlogs.txt':$('#logfile').val() + ".txt";
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
if (document.createEvent) {
|
if (document.createEvent) {
|
||||||
|
|
131
logs.php
131
logs.php
|
@ -20,72 +20,73 @@ if (!isset($_GET['action'])) {
|
||||||
jtable_respond(null, 'error', 'No action given');
|
jtable_respond(null, 'error', 'No action given');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($_GET['action']) {
|
if ($logging !== TRUE) {
|
||||||
|
jtable_respond(null, 'error', 'Logging is disabled');
|
||||||
|
} else {
|
||||||
|
switch ($_GET['action']) {
|
||||||
|
|
||||||
case "list":
|
case "list":
|
||||||
global $logging;
|
if(!empty($_POST['logfile'])) {
|
||||||
if ($logging !== TRUE) {
|
if(preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}\.json/',$_POST['logfile']) == 1) {
|
||||||
jtable_respond(null, 'error', 'Logging is disabled');
|
$entries=json_decode(file_get_contents($logsdirectory . "/" . $_POST['logfile']),true);
|
||||||
|
} else {
|
||||||
|
jtable_respond(null, 'error', "Can't find log file");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$entries=getlogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($_POST['user'])) {
|
||||||
|
$entries=array_filter($entries,
|
||||||
|
function ($val) {
|
||||||
|
return(stripos($val['user'], $_POST['user']) !== FALSE);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($_POST['entry'])) {
|
||||||
|
$entries=array_filter($entries,
|
||||||
|
function ($val) {
|
||||||
|
return(stripos($val['log'], $_POST['entry']) !== FALSE);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
jtable_respond($entries);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "export":
|
||||||
|
if(!empty($_GET['logfile'])) {
|
||||||
|
if(preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}\.json/',$_GET['logfile']) == 1) {
|
||||||
|
$entries=json_decode(file_get_contents($logsdirectory . "/" . $_GET['logfile']),true);
|
||||||
|
} else {
|
||||||
|
jtable_respond(null, 'error', "Can't find log file");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$entries=getlogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
print json_encode($entries,JSON_PRETTY_PRINT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "clear":
|
||||||
|
if($allowclearlogs === TRUE) {
|
||||||
|
clearlogs();
|
||||||
|
} else {
|
||||||
|
jtable_respond(null, 'error', 'Invalid action');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "rotate":
|
||||||
|
if($allowrotatelogs === TRUE) {
|
||||||
|
rotatelogs();
|
||||||
|
} else {
|
||||||
|
jtable_respond(null, 'error', 'Invalid action');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jtable_respond(null, 'error', 'Invalid action');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($_POST['logfile'])) {
|
|
||||||
if(preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}\.json/',$_POST['logfile']) == 1) {
|
|
||||||
$entries=json_decode(file_get_contents($logsdirectory . "/" . $_POST['logfile']),true);
|
|
||||||
} else {
|
|
||||||
jtable_respond(null, 'error', "Can't find log file");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$entries=getlogs();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($_POST['user'])) {
|
|
||||||
$entries=array_filter($entries,
|
|
||||||
function ($val) {
|
|
||||||
return(stripos($val['user'], $_POST['user']) !== FALSE);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($_POST['entry'])) {
|
|
||||||
$entries=array_filter($entries,
|
|
||||||
function ($val) {
|
|
||||||
return(stripos($val['log'], $_POST['entry']) !== FALSE);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
jtable_respond($entries);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "delete":
|
|
||||||
if ($emailaddress != '' and delete_user($emailaddress) !== FALSE) {
|
|
||||||
jtable_respond(null, 'delete');
|
|
||||||
} else {
|
|
||||||
jtable_respond(null, 'error', 'Could not delete user');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "export":
|
|
||||||
print json_encode(getlogs());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "clear":
|
|
||||||
if($allowclearlogs === TRUE) {
|
|
||||||
clearlogs();
|
|
||||||
} else {
|
|
||||||
jtable_respond(null, 'error', 'Invalid action');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "rotate":
|
|
||||||
if($allowrotatelogs === TRUE) {
|
|
||||||
rotatelogs();
|
|
||||||
} else {
|
|
||||||
jtable_respond(null, 'error', 'Invalid action');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jtable_respond(null, 'error', 'Invalid action');
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue