php lint + code standard PSR-2

This commit is contained in:
Nikita Tarasov 2018-05-20 22:17:29 +03:00
parent ebd12ebeb2
commit 73f290e896
15 changed files with 796 additions and 531 deletions

View file

@ -1,18 +1,18 @@
<?php
include_once('includes/config.inc.php');
include_once('includes/session.inc.php');
include_once('includes/misc.inc.php');
include_once 'includes/config.inc.php';
include_once 'includes/session.inc.php';
include_once 'includes/misc.inc.php';
if (!is_csrf_safe()) {
header('Status: 403');
header('Location: ./index.php');
jtable_respond(null, 'error', "Authentication required");
jtable_respond(null, 'error', 'Authentication required');
}
if (!is_adminuser()) {
header('Status: 403');
jtable_respond(null, 'error', "You need adminprivileges to get here");
jtable_respond(null, 'error', 'You need adminprivileges to get here');
}
if (!isset($_GET['action'])) {
@ -20,15 +20,15 @@ if (!isset($_GET['action'])) {
jtable_respond(null, 'error', 'No action given');
}
if ($logging !== TRUE) {
if ($logging !== true) {
jtable_respond(null, 'error', 'Logging is disabled');
} else {
switch ($_GET['action']) {
case "list":
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);
case 'list':
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;
@ -37,29 +37,31 @@ if ($logging !== TRUE) {
$entries=getlogs();
}
if(!empty($_POST['user'])) {
$entries=array_filter($entries,
if (!empty($_POST['user'])) {
$entries=array_filter(
$entries,
function ($val) {
return(stripos($val['user'], $_POST['user']) !== FALSE);
return(stripos($val['user'], $_POST['user']) !== false);
}
);
}
if(!empty($_POST['entry'])) {
$entries=array_filter($entries,
if (!empty($_POST['entry'])) {
$entries=array_filter(
$entries,
function ($val) {
return(stripos($val['log'], $_POST['entry']) !== FALSE);
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);
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;
@ -68,22 +70,22 @@ if ($logging !== TRUE) {
$entries=getlogs();
}
if(defined('JSON_PRETTY_PRINT')) {
print json_encode($entries,JSON_PRETTY_PRINT);
if (defined('JSON_PRETTY_PRINT')) {
print json_encode($entries, JSON_PRETTY_PRINT);
} else {
print json_encode($entries);
}
break;
case "clear":
if($allowclearlogs === TRUE) {
case 'clear':
if ($allowclearlogs === true) {
clearlogs();
} else {
jtable_respond(null, 'error', 'Invalid action');
}
break;
case "rotate":
if($allowrotatelogs === TRUE) {
case 'rotate':
if ($allowrotatelogs === true) {
rotatelogs();
} else {
jtable_respond(null, 'error', 'Invalid action');