2010-02-28 13:04:07 +00:00
< ? php
2017-05-15 22:18:23 -05:00
use LibreNMS\Exceptions\AuthenticationException ;
2017-01-01 03:37:15 -06:00
use Phpass\PasswordHash ;
2017-07-03 15:38:58 -05:00
function init_auth ()
{
}
2016-08-18 20:28:22 -05:00
function authenticate ( $username , $password )
{
2017-05-23 08:40:57 +01:00
if ( user_exists ( $username )) {
return true ;
2010-02-28 13:04:07 +00:00
}
2017-05-23 08:40:57 +01:00
throw new AuthenticationException ( 'No matching user found and http_auth_guest is not set' );
2010-02-28 13:04:07 +00:00
}
2016-09-13 15:10:42 +01:00
2017-05-15 22:18:23 -05:00
function reauthenticate ( $sess_id , $token )
2016-09-13 15:10:42 +01:00
{
2017-05-15 22:18:23 -05:00
return false ;
2016-09-13 15:10:42 +01:00
}
2016-08-18 20:28:22 -05:00
function passwordscanchange ( $username = '' )
{
2015-07-13 20:10:26 +02:00
return 0 ;
2010-03-06 00:00:05 +00:00
}
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function changepassword ( $username , $newpassword )
{
2015-07-13 20:10:26 +02:00
// Not supported
2010-03-06 00:00:05 +00:00
}
2011-03-12 08:50:47 +00:00
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function auth_usermanagement ()
{
2015-07-13 20:10:26 +02:00
return 1 ;
2010-03-06 01:10:05 +00:00
}
2011-03-12 08:50:47 +00:00
2015-07-13 20:10:26 +02:00
2017-04-01 16:18:00 -05:00
function adduser ( $username , $password , $level , $email = '' , $realname = '' , $can_modify_passwd = 1 , $description = '' )
2016-08-18 20:28:22 -05:00
{
2014-10-06 18:39:48 +01:00
if ( ! user_exists ( $username )) {
2015-07-13 20:10:26 +02:00
$hasher = new PasswordHash ( 8 , false );
2014-10-06 18:39:48 +01:00
$encrypted = $hasher -> HashPassword ( $password );
2017-04-01 16:18:00 -05:00
$userid = dbInsert ( array ( 'username' => $username , 'password' => $encrypted , 'level' => $level , 'email' => $email , 'realname' => $realname , 'can_modify_passwd' => $can_modify_passwd , 'descr' => $description ), 'users' );
2015-11-21 12:25:34 +00:00
if ( $userid == false ) {
return false ;
2016-08-18 20:28:22 -05:00
} else {
foreach ( dbFetchRows ( 'select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc' , array ( $userid )) as $notif ) {
dbInsert ( array ( 'notifications_id' => $notif [ 'notifications_id' ], 'user_id' => $userid , 'key' => 'read' , 'value' => 1 ), 'notifications_attribs' );
2015-11-21 12:25:34 +00:00
}
}
return $userid ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
return false ;
2014-10-06 18:39:48 +01:00
}
2010-03-06 01:10:05 +00:00
}
2011-03-12 08:50:47 +00:00
2010-03-06 01:10:05 +00:00
2016-08-18 20:28:22 -05:00
function user_exists ( $username )
{
2017-05-23 08:40:57 +01:00
global $config ;
2017-07-10 15:48:24 -05:00
$query = 'SELECT COUNT(*) FROM `users` WHERE `username`=?' ;
$params = array ( $username );
if ( isset ( $config [ 'http_auth_guest' ])) {
$query .= ' OR `username`=?' ;
$params [] = $config [ 'http_auth_guest' ];
}
return dbFetchCell ( $query , $params ) > 0 ;
2010-03-06 01:15:52 +00:00
}
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function get_userlevel ( $username )
{
2017-05-23 08:40:57 +01:00
global $config ;
2017-07-10 15:48:24 -05:00
$user_level = dbFetchCell ( 'SELECT `level` FROM `users` WHERE `username`=?' , array ( $username ));
if ( $user_level ) {
return $user_level ;
}
if ( isset ( $config [ 'http_auth_guest' ])) {
return dbFetchCell ( 'SELECT `level` FROM `users` WHERE `username`=?' , array ( $config [ 'http_auth_guest' ]));
}
return 0 ;
2010-03-06 01:22:09 +00:00
}
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function get_userid ( $username )
{
2017-05-23 08:40:57 +01:00
global $config ;
2017-07-10 15:48:24 -05:00
$user_id = dbFetchCell ( 'SELECT `user_id` FROM `users` WHERE `username`=?' , array ( $username ));
if ( $user_id ) {
return $user_id ;
}
if ( isset ( $config [ 'http_auth_guest' ])) {
return dbFetchCell ( 'SELECT `user_id` FROM `users` WHERE `username`=?' , array ( $config [ 'http_auth_guest' ]));
}
return - 1 ;
2011-03-28 10:48:43 +00:00
}
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function deluser ( $username )
{
2015-07-13 20:10:26 +02:00
// Not supported
return 0 ;
2011-09-22 16:46:30 +00:00
}
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function get_userlist ()
{
2015-07-13 20:10:26 +02:00
return dbFetchRows ( 'SELECT * FROM `users`' );
2014-03-10 23:50:16 +00:00
}
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function can_update_users ()
{
2015-07-13 20:10:26 +02:00
// supported so return 1
return 1 ;
2014-03-10 23:50:16 +00:00
}
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function get_user ( $user_id )
{
2015-07-13 20:10:26 +02:00
return dbFetchRow ( 'SELECT * FROM `users` WHERE `user_id` = ?' , array ( $user_id ));
2014-03-10 23:50:16 +00:00
}
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function update_user ( $user_id , $realname , $level , $can_modify_passwd , $email )
{
2015-07-13 20:10:26 +02:00
dbUpdate ( array ( 'realname' => $realname , 'level' => $level , 'can_modify_passwd' => $can_modify_passwd , 'email' => $email ), 'users' , '`user_id` = ?' , array ( $user_id ));
}