1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-10 16:46:50 +02:00

Tidy up alt_auth; first cut of radius support (thanks to Cameron K for testing)

This commit is contained in:
e107steved
2008-09-02 19:39:13 +00:00
parent 61ec94fa25
commit 231e2c055f
19 changed files with 512 additions and 146 deletions

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/alt_auth/e107db_auth.php,v $
| $Revision: 1.1 $
| $Date: 2008-07-25 19:33:03 $
| $Revision: 1.2 $
| $Date: 2008-09-02 19:39:12 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
@@ -29,66 +29,47 @@
class auth_login
{
var $od;
var $Available;
var $ErrorText;
var $conf; // Configuration parameters
function auth_login()
{
// global $otherdb_conf, $sql;
global $sql;
$this->conf = array();
$this->ErrorText = '';
$sql -> db_Select("alt_auth", "*", "auth_type = 'e107db' ");
while($row = $sql -> db_Fetch())
{
$e107db_conf[$row['auth_parmname']] = base64_decode(base64_decode($row['auth_parmval']));
}
$class_name = "e107db_mysql_class";
if(class_exists($class_name))
{
$this->od = new $class_name($e107db_conf);
$this->Available = TRUE;
}
else
{
$this->Available = FALSE;
return AUTH_NOCONNECT;
$this->conf[$row['auth_parmname']] = base64_decode(base64_decode($row['auth_parmval']));
}
$this->Available = TRUE;
}
function login($uname, $pword, &$newvals, $connect_only = FALSE)
// Add the reconnect function in here - might be needed
function makeErrorText($extra = '')
{
$this->ErrorText = $extra;
global $mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb, $sql;
$ret = $this->od->login($uname, $pword, $newvals, $connect_only);
$sql->db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);
return $ret;
}
}
class e107db_mysql_class
{
var $conf;
function e107db_mysql_class($otherdb_conf)
{
$this->conf = $otherdb_conf;
// print_a($this->conf);
}
function login($uname, $pword, &$newvals, $connect_only = FALSE)
{
//Attempt to open connection to sql database
if(!$res = mysql_connect($this->conf['e107db_server'], $this->conf['e107db_username'], $this->conf['e107db_password']))
{
$this->makeErrorText('Cannot connect to remote server');
return AUTH_NOCONNECT;
}
//Select correct db
if(!mysql_select_db($this->conf['e107db_database'], $res))
{
mysql_close($res);
$this->makeErrorText('Cannot connect to remote DB');
return AUTH_NOCONNECT;
}
if ($connect_only) return AUTH_SUCCESS; // Test mode may just want to connect to the DB
@@ -107,16 +88,18 @@ class e107db_mysql_class
//Get record containing supplied login name
$qry = "SELECT ".implode(',',$sel_fields)." FROM ".MPREFIX."user WHERE {$user_field} = '{$uname}'";
$qry = "SELECT ".implode(',',$sel_fields)." FROM ".$this->conf['e107db_prefix']."user WHERE {$user_field} = '{$uname}'";
// echo "Query: {$qry}<br />";
if(!$r1 = mysql_query($qry))
{
mysql_close($res);
$this->makeErrorText('Lookup query failed');
return AUTH_NOCONNECT;
}
if(!$row = mysql_fetch_array($r1))
{
mysql_close($res);
$this->makeErrorText('User not found');
return AUTH_NOUSER;
}
@@ -127,12 +110,17 @@ class e107db_mysql_class
$pass_check = new ExtendedPasswordHandler();
$passMethod = $pass_check->passwordMapping($this->conf['e107db_password_method']);
if ($passMethod === FALSE) return AUTH_BADPASSWORD;
if ($passMethod === FALSE)
{
$this->makeErrorText('Password error - invalid method');
return AUTH_BADPASSWORD;
}
$pwFromDB = $row['user_password']; // Password stored in DB
if ($pass_check->checkPassword($pword, $uname, $pwFromDB, $passMethod) !== PASSWORD_VALID)
{
$this->makeErrorText('Password incorrect');
return AUTH_BADPASSWORD;
}
@@ -145,6 +133,7 @@ class e107db_mysql_class
if (isset($row[$f])) $newvals[$f] = $row[$f];
}
}
$this->makeErrorText(''); // Success - just reconnect to E107 DB if needed
return AUTH_SUCCESS;
}
}