2015-12-13 13:49:48 +00:00
< ? php
require_once $config [ 'install_dir' ] . '/lib/pure_php_radius/radius.class.php' ;
$radius = new Radius ( $config [ 'radius' ][ 'hostname' ], $config [ 'radius' ][ 'secret' ], $config [ 'radius' ][ 'suffix' ], $config [ 'radius' ][ 'timeout' ], $config [ 'radius' ][ 'port' ]);
2016-08-18 20:28:22 -05:00
function authenticate ( $username , $password )
{
2015-12-13 13:49:48 +00:00
global $config , $radius , $debug ;
if ( empty ( $username )) {
return 0 ;
2016-08-18 20:28:22 -05:00
} else {
2015-12-13 13:49:48 +00:00
if ( $debug ) {
2016-08-18 20:28:22 -05:00
$radius -> SetDebugMode ( true );
2015-12-13 13:49:48 +00:00
}
2016-08-18 20:28:22 -05:00
$rad = $radius -> AccessRequest ( $username , $password );
if ( $rad === true ) {
2015-12-13 13:49:48 +00:00
adduser ( $username );
return 1 ;
2016-08-18 20:28:22 -05:00
} else {
2015-12-13 13:49:48 +00:00
return 0 ;
}
}
}
2016-08-18 20:28:22 -05:00
function reauthenticate ()
{
2015-12-13 13:49:48 +00:00
return 0 ;
}
2016-08-18 20:28:22 -05:00
function passwordscanchange ()
{
2015-12-13 13:49:48 +00:00
// not supported so return 0
return 0 ;
}
2016-08-18 20:28:22 -05:00
function changepassword ()
{
2015-12-13 13:49:48 +00:00
// not supported so return 0
return 0 ;
}
2016-08-18 20:28:22 -05:00
function auth_usermanagement ()
{
2015-12-13 13:49:48 +00:00
// not supported so return 0
return 1 ;
}
2016-08-18 20:28:22 -05:00
function adduser ( $username , $password , $level = 1 , $email = '' , $realname = '' , $can_modify_passwd = 0 , $description = '' , $twofactor = 0 )
{
2015-12-13 13:49:48 +00:00
// Check to see if user is already added in the database
2015-12-14 21:52:15 +00:00
global $config ;
2015-12-13 13:49:48 +00:00
if ( ! user_exists ( $username )) {
2015-12-13 16:54:40 +00:00
$hasher = new PasswordHash ( 8 , false );
$encrypted = $hasher -> HashPassword ( $password );
2015-12-14 21:52:15 +00:00
if ( $config [ 'radius' ][ 'default_level' ] > 0 ) {
$level = $config [ 'radius' ][ 'default_level' ];
}
2015-12-13 16:54:40 +00:00
$userid = dbInsert ( array ( 'username' => $username , 'password' => $encrypted , 'realname' => $realname , 'email' => $email , 'descr' => $description , 'level' => $level , 'can_modify_passwd' => $can_modify_passwd , 'twofactor' => $twofactor ), 'users' );
2015-12-13 13:49:48 +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-12-13 13:49:48 +00:00
}
}
return $userid ;
2016-08-18 20:28:22 -05:00
} else {
2015-12-13 13:49:48 +00:00
return false ;
}
}
2016-08-18 20:28:22 -05:00
function user_exists ( $username )
{
2015-12-13 13:49:48 +00:00
return dbFetchCell ( 'SELECT COUNT(*) FROM users WHERE username = ?' , array ( $username ), true );
}
2016-08-18 20:28:22 -05:00
function get_userlevel ( $username )
{
2015-12-13 13:49:48 +00:00
return dbFetchCell ( 'SELECT `level` FROM `users` WHERE `username` = ?' , array ( $username ), true );
}
2016-08-18 20:28:22 -05:00
function get_userid ( $username )
{
2015-12-13 13:49:48 +00:00
return dbFetchCell ( 'SELECT `user_id` FROM `users` WHERE `username` = ?' , array ( $username ), true );
}
2016-08-18 20:28:22 -05:00
function deluser ( $username )
{
2015-12-13 13:49:48 +00:00
dbDelete ( 'bill_perms' , '`user_name` = ?' , array ( $username ));
dbDelete ( 'devices_perms' , '`user_name` = ?' , array ( $username ));
dbDelete ( 'ports_perms' , '`user_name` = ?' , array ( $username ));
dbDelete ( 'users_prefs' , '`user_name` = ?' , array ( $username ));
dbDelete ( 'users' , '`user_name` = ?' , array ( $username ));
return dbDelete ( 'users' , '`username` = ?' , array ( $username ));
}
2016-08-18 20:28:22 -05:00
function get_userlist ()
{
2015-12-13 13:49:48 +00:00
return dbFetchRows ( 'SELECT * FROM `users`' );
}
2016-08-18 20:28:22 -05:00
function can_update_users ()
{
2015-12-13 13:49:48 +00:00
// supported so return 1
return 1 ;
}
2016-08-18 20:28:22 -05:00
function get_user ( $user_id )
{
2015-12-13 13:49:48 +00:00
return dbFetchRow ( 'SELECT * FROM `users` WHERE `user_id` = ?' , array ( $user_id ), true );
}
2016-08-18 20:28:22 -05:00
function update_user ( $user_id , $realname , $level , $can_modify_passwd , $email )
{
2015-12-13 13:49:48 +00:00
dbUpdate ( array ( 'realname' => $realname , 'level' => $level , 'can_modify_passwd' => $can_modify_passwd , 'email' => $email ), 'users' , '`user_id` = ?' , array ( $user_id ));
}