Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into issue-107
Browse files Browse the repository at this point in the history
Add test for pre-PHP 5.4 for pretty-printing logs

Conflicts:
	includes/misc.inc.php
  • Loading branch information
richard-underwood committed Aug 26, 2016
2 parents 2cb95a6 + 6833f59 commit 7c767b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions includes/misc.inc.php
Expand Up @@ -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;
}

Expand Down Expand Up @@ -329,11 +328,15 @@ function ($val) {
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 (
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions includes/session.inc.php
Expand Up @@ -150,6 +150,7 @@ function _try_login($username, $password) {
global $wefactapiurl, $wefactapikey;

if (!valid_user($username)) {
writelog("Illegal username at login!", $username);
return false;
}

Expand All @@ -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) {
Expand All @@ -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']);
Expand Down
6 changes: 5 additions & 1 deletion logs.php
Expand Up @@ -68,7 +68,11 @@ function ($val) {
$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":
Expand Down

0 comments on commit 7c767b7

Please sign in to comment.