3
require('version.php');
5
require('functions.php');
9
$query = @$_REQUEST['query'];
11
//check query type and decide what to do
15
//the most important case, handled after the switch
19
//the server wants a list of supported methods, comma seperated
20
conclude('methods '.implode(',', $validMethods), 200);
24
// the md5 method would support parameters, the prefix and
25
// suffix that is added to the password before it is hashed.
27
if (isset($_REQUEST['method']))
29
$realDbDetails = get_db_details($host, @$_REQUEST['method']);
30
foreach ($realDbDetails['params'] as $var => $key)
31
$msg .= $var." ".$key."\n";
36
foreach ($dbdetails['params'] as $var => $key)
37
$msg .= $var." ".$key."\n";
46
//return "supported" versions
48
foreach ($versionTable as $version => $details)
51
conclude(substr($msg, 1), 200);
55
conclude('UNKNOWN_QUERY', 404);
58
//get request variables
59
$user = @$_REQUEST['user'];
60
$hash = @$_REQUEST['hash'] . '';
61
$salt = @$_REQUEST['salt'] . '';
62
$packedSalt = @pack("H*", $salt); //pack salt
64
if (in_array($_REQUEST['method'], $validMethods))
66
$hashMethod = $_REQUEST['method'];
70
if (!isset($hashMethod))
71
conclude('METHOD_NOT_IMPLEMENTED', 501);
73
if (in_array($hashMethod, $validMethods)) //make sure it's supported method
75
$realDbDetails = get_db_details ($host, $hashMethod);
76
$db = mysql_connect($realDbDetails['host'], $realDbDetails['user'], $realDbDetails['passwd']);
77
mysql_select_db($realDbDetails['name'], $db);
79
if ( $hashMethod === 'webform' )
81
if ( in_array('md5', $validMethods) ) $method = 'md5';
82
else if ( in_array('bmd5', $validMethods) ) $method = 'bmd5';
83
else die("METHOD_NOT_IMPLEMENTED"); // TODO: nice message
85
$result = mysql_query('SELECT `'.$realDbDetails['row'].'`, `'.$realDbDetails['user_row'].'`,`' . $realDbDetails['username_row'].'`, `'.$realDbDetails['user_rank'].'` FROM `'.$realDbDetails['table'].'` WHERE `'.$realDbDetails['user_row'].'` = \''.addslashes($user).'\'', $db);
86
$del_result = mysql_query('DELETE FROM `' . $realDbDetails['table'] . '`
87
WHERE `'.$realDbDetails['user_row'].'` = \''.addslashes($user).'\'');
91
$method = $hashMethod;
92
$result = mysql_query('SELECT `'.$realDbDetails['row'].'`, `'.$realDbDetails['user_row'].'`,`'.$realDbDetails['user_rank'].'` FROM `'.$realDbDetails['table'].'` WHERE `'.$realDbDetails['user_row'].'` = \''.addslashes($user).'\'', $db);
95
if (mysql_num_rows($result) == 1) //if there's the user
97
$row = mysql_fetch_row($result);
98
if (strlen($row[0]) == 0) //make sure hash row isn't empty
102
if ( $hashMethod == 'webform')
104
$correctUserName = $row[2];
109
$correctUserName = $row[1];
112
$correctHash = $method(pack('H*',$row[0]).$packedSalt); //calculate the correct hash
113
if (strcasecmp($hash, $correctHash) == 0) //and then compare it
120
mysql_close($db); //close the database connection
123
conclude('USER_NOT_FOUND', 404);
125
conclude('PRECONDITION_FAILED: Login again at the authority.', 412);
126
else if ($passwordOK) //if a valid password return ok
127
conclude('PASSWORD_OK ' . $correctUserName . '@' . $host . $rank, 200);
131
conclude('PASSWORD_FAIL', 401);