mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-04-18 19:59:30 +03:00
Merge remote-tracking branch 'origin/master' into issue-107
Add test for pre-PHP 5.4 for pretty-printing logs Conflicts: includes/misc.inc.php
This commit is contained in:
commit
7c767b7769
3 changed files with 15 additions and 4 deletions
|
@ -128,7 +128,6 @@ function do_db_auth($u, $p) {
|
|||
$db->close();
|
||||
|
||||
if ($userinfo and $userinfo['password'] and (crypt($p, $userinfo['password']) === $userinfo['password'])) {
|
||||
writelog('Succesful login.');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -329,11 +328,15 @@ function listrotatedlogs() {
|
|||
return $list;
|
||||
}
|
||||
|
||||
function writelog($line) {
|
||||
function writelog($line, $user=False) {
|
||||
global $logging;
|
||||
if ($logging !== TRUE)
|
||||
return;
|
||||
|
||||
if ($user === False) {
|
||||
$user = get_sess_user();
|
||||
}
|
||||
|
||||
try {
|
||||
$db = get_db();
|
||||
$q = $db->prepare('CREATE TABLE IF NOT EXISTS logs (
|
||||
|
@ -344,7 +347,7 @@ function writelog($line) {
|
|||
$ret = $q->execute();
|
||||
|
||||
$q = $db->prepare('INSERT INTO logs (user, log) VALUES (:user, :log)');
|
||||
$q->bindValue(':user', get_sess_user(), SQLITE3_TEXT);
|
||||
$q->bindValue(':user', $user, SQLITE3_TEXT);
|
||||
$q->bindValue(':log', $line, SQLITE3_TEXT);
|
||||
$q->execute();
|
||||
$db->close();
|
||||
|
|
|
@ -150,6 +150,7 @@ function _try_login($username, $password) {
|
|||
global $wefactapiurl, $wefactapikey;
|
||||
|
||||
if (!valid_user($username)) {
|
||||
writelog("Illegal username at login!", $username);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -158,6 +159,7 @@ function _try_login($username, $password) {
|
|||
if (isset($wefactapiurl) && isset($wefactapikey)) {
|
||||
$wefact = do_wefact_auth($username, $password);
|
||||
if (false === $wefact ) {
|
||||
writelog("Failed Wefact login!", $username);
|
||||
return false;
|
||||
}
|
||||
if (-1 !== $wefact) {
|
||||
|
@ -166,11 +168,13 @@ function _try_login($username, $password) {
|
|||
}
|
||||
|
||||
if ($do_local_auth && !do_db_auth($username, $password)) {
|
||||
writelog("Failed login!", $username);
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = get_user_info($username);
|
||||
if (!$user) {
|
||||
writelog("Failed to find user!", $username);
|
||||
return false;
|
||||
} else {
|
||||
_set_current_user($username, (bool) $user['isadmin']);
|
||||
|
|
6
logs.php
6
logs.php
|
@ -68,7 +68,11 @@ if ($logging !== TRUE) {
|
|||
$entries=getlogs();
|
||||
}
|
||||
|
||||
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":
|
||||
|
|
Loading…
Add table
Reference in a new issue