mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
fix: Fixed http-auth not honouring http_auth_guest (#6699)
* fix: Fixed http-auth not honouring http_auth_guest * Always fall back to http_auth_guest. Make sure $username is set, otherwise, we won't try to authenticate. * reverted elseif to default to http-auth-guest * Update authenticate.inc.php simplify logic
This commit is contained in:
@@ -56,9 +56,9 @@ try {
|
||||
$username = clean($_REQUEST['username']);
|
||||
$password = $_REQUEST['password'];
|
||||
} elseif (isset($_SERVER['REMOTE_USER'])) {
|
||||
$username = $_SERVER['REMOTE_USER'];
|
||||
$username = clean($_SERVER['REMOTE_USER']);
|
||||
} elseif (isset($_SERVER['PHP_AUTH_USER']) && $config['auth_mechanism'] === 'http-auth') {
|
||||
$username = $_SERVER['PHP_AUTH_USER'];
|
||||
$username = clean($_SERVER['PHP_AUTH_USER']);
|
||||
}
|
||||
|
||||
// form authentication
|
||||
|
||||
@@ -3,27 +3,13 @@
|
||||
use LibreNMS\Exceptions\AuthenticationException;
|
||||
use Phpass\PasswordHash;
|
||||
|
||||
if (!isset($_SESSION['username'])) {
|
||||
$_SESSION['username'] = '';
|
||||
}
|
||||
|
||||
|
||||
function authenticate($username, $password)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (isset($_SERVER['REMOTE_USER']) || isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
$_SESSION['username'] = mres($_SERVER['REMOTE_USER']) ?: mres($_SERVER['PHP_AUTH_USER']);
|
||||
|
||||
$row = @dbFetchRow('SELECT username FROM `users` WHERE `username`=?', array($_SESSION['username']));
|
||||
if (isset($row['username']) && $row['username'] == $_SESSION['username']) {
|
||||
return true;
|
||||
} else {
|
||||
$_SESSION['username'] = $config['http_auth_guest'];
|
||||
if (user_exists($username)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
throw new AuthenticationException();
|
||||
|
||||
throw new AuthenticationException('No matching user found and http_auth_guest is not set');
|
||||
}
|
||||
|
||||
|
||||
@@ -73,20 +59,34 @@ function adduser($username, $password, $level, $email = '', $realname = '', $can
|
||||
|
||||
function user_exists($username)
|
||||
{
|
||||
// FIXME this doesn't seem right? (adama)
|
||||
return dbFetchCell('SELECT * FROM `users` WHERE `username` = ?', array($username));
|
||||
global $config;
|
||||
|
||||
return dbFetchCell(
|
||||
'SELECT COUNT(*) FROM `users` WHERE `username`=? OR `username`=?',
|
||||
array($username, $config['http_auth_guest'])
|
||||
) > 0;
|
||||
}
|
||||
|
||||
|
||||
function get_userlevel($username)
|
||||
{
|
||||
return dbFetchCell('SELECT `level` FROM `users` WHERE `username`= ?', array($username));
|
||||
global $config;
|
||||
|
||||
return dbFetchCell(
|
||||
'SELECT `level` FROM `users` WHERE `username`=? OR `username`=?',
|
||||
array($username, $config['http_auth_guest'])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function get_userid($username)
|
||||
{
|
||||
return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username`= ?', array($username));
|
||||
global $config;
|
||||
|
||||
return dbFetchCell(
|
||||
'SELECT `user_id` FROM `users` WHERE `username`=? OR `username`=?',
|
||||
array($username, $config['http_auth_guest'])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user