2010-02-28 13:04:07 +00:00
< ? php
2015-07-13 20:10:26 +02:00
if ( ! isset ( $_SESSION [ 'username' ])) {
$_SESSION [ 'username' ] = '' ;
2011-05-03 14:10:21 +00:00
}
2010-02-28 13:04:07 +00:00
2016-08-18 20:28:22 -05:00
function authenticate ( $username , $password )
{
2015-07-13 20:10:26 +02:00
global $config ;
2011-03-12 08:50:47 +00:00
2015-07-13 20:10:26 +02:00
if ( isset ( $_SERVER [ 'REMOTE_USER' ])) {
$_SESSION [ 'username' ] = mres ( $_SERVER [ 'REMOTE_USER' ]);
$row = @ dbFetchRow ( 'SELECT username FROM `users` WHERE `username`=?' , array ( $_SESSION [ 'username' ]));
if ( isset ( $row [ 'username' ]) && $row [ 'username' ] == $_SESSION [ 'username' ]) {
return 1 ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$_SESSION [ 'username' ] = $config [ 'http_auth_guest' ];
return 1 ;
}
2010-02-28 13:04:07 +00:00
}
2015-07-13 20:10:26 +02:00
return 0 ;
2010-02-28 13:04:07 +00:00
}
2016-09-13 15:10:42 +01:00
function reauthenticate ( $sess_id = '' , $token = '' )
{
return 0 ;
}
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
2016-08-18 20:28:22 -05:00
function adduser ( $username , $password , $level , $email = '' , $realname = '' , $can_modify_passwd = 1 , $description = '' , $twofactor = 0 )
{
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 );
2015-11-21 12:25:34 +00:00
$userid = dbInsert ( array ( 'username' => $username , 'password' => $encrypted , 'level' => $level , 'email' => $email , 'realname' => $realname , 'can_modify_passwd' => $can_modify_passwd , 'descr' => $description , 'twofactor' => $twofactor ), 'users' );
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 )
{
2015-07-13 20:10:26 +02:00
// FIXME this doesn't seem right? (adama)
return dbFetchCell ( 'SELECT * FROM `users` WHERE `username` = ?' , array ( $username ));
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 )
{
2015-07-13 20:10:26 +02:00
return dbFetchCell ( 'SELECT `level` FROM `users` WHERE `username`= ?' , array ( $username ));
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 )
{
2015-07-13 20:10:26 +02:00
return dbFetchCell ( 'SELECT `user_id` FROM `users` WHERE `username`= ?' , array ( $username ));
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 ));
}