Created
February 11, 2010 13:40
-
-
Save cs278/301510 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* POP3 authentication plugin for phpBB | |
* | |
* @package login | |
* @version $Id$ | |
* @copyright (c) 2005 phpBB Group | |
* @copyright (c) 2009 Chris Smith | |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License | |
* | |
*/ | |
/** | |
* @ignore | |
*/ | |
if (!defined('IN_PHPBB')) | |
{ | |
exit; | |
} | |
/** | |
* Login function | |
*/ | |
function login_pop3(&$username, &$password) | |
{ | |
global $db, $config; | |
// do not allow empty password | |
if (!$password) | |
{ | |
return array( | |
'status' => LOGIN_ERROR_PASSWORD, | |
'error_msg' => 'NO_PASSWORD_SUPPLIED', | |
'user_row' => array('user_id' => ANONYMOUS), | |
); | |
} | |
if (!$username) | |
{ | |
return array( | |
'status' => LOGIN_ERROR_USERNAME, | |
'error_msg' => 'LOGIN_ERROR_USERNAME', | |
'user_row' => array('user_id' => ANONYMOUS), | |
); | |
} | |
$host = $config['pop3_server']; | |
$port = ((int) $config['pop3_port'] <= 0) ? 110 : (int) $config['pop3_port']; | |
// Very rudimentary check to see if the username is an email address | |
$email = $username . ((strpos($username, '@') === false) ? '@' . $config['pop3_domain'] : ''); | |
if (@extension_loaded('imap')) | |
{ | |
// $handle = imap_open("{". "$host:$port/service=pop3}", $username, $password); | |
$handle = imap_open('{pop.ex.ac.uk/pop3}', $email, $password); | |
if ($handle) | |
{ | |
// Successful connection | |
@imap_close($handle); | |
$sql ='SELECT user_id, username, user_password, user_passchg, user_email, user_type | |
FROM ' . USERS_TABLE . " | |
WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; | |
$result = $db->sql_query($sql); | |
$row = $db->sql_fetchrow($result); | |
$db->sql_freeresult($result); | |
echo $sql; die; | |
if ($row) | |
{ | |
// Successful login... set user_login_attempts to zero... | |
return array( | |
'status' => LOGIN_SUCCESS, | |
'error_msg' => false, | |
'user_row' => $row, | |
); | |
} | |
else | |
{ | |
// retrieve default group id | |
$sql = 'SELECT group_id | |
FROM ' . GROUPS_TABLE . " | |
WHERE group_name = '" . $db->sql_escape('REGISTERED') . "' | |
AND group_type = " . GROUP_SPECIAL; | |
$result = $db->sql_query($sql); | |
$row = $db->sql_fetchrow($result); | |
$db->sql_freeresult($result); | |
if (!$row) | |
{ | |
trigger_error('NO_GROUP'); | |
} | |
global $user; | |
// generate user account data | |
$user_row = array( | |
'username' => $username, | |
'user_password' => '', | |
'user_email' => $email, | |
'group_id' => (int) $row['group_id'], | |
'user_type' => USER_NORMAL, | |
'user_ip' => $user->ip, | |
); | |
// this is the user's first login so create an empty profile | |
return array( | |
'status' => LOGIN_SUCCESS_CREATE_PROFILE, | |
'error_msg' => false, | |
'user_row' => $user_row, | |
); | |
} | |
} | |
else | |
{ | |
return array( | |
'status' => LOGIN_ERROR_PASSWORD, | |
'error_msg' => 'LOGIN_ERROR_PASSWORD', | |
'user_row' => array('user_id' => ANONYMOUS), | |
); | |
} | |
} | |
else | |
{ | |
// PHP Implementation | |
} | |
return array( | |
'status' => LOGIN_ERROR_EXTERNAL_AUTH, | |
'error_msg' => 'POP3_', | |
'user_row' => array('user_id' => ANONYMOUS), | |
); | |
} | |
/** | |
* This function is used to output any required fields in the authentication | |
* admin panel. It also defines any required configuration table fields. | |
*/ | |
function acp_pop3(&$new) | |
{ | |
global $user; | |
$user->lang['POP3_SERVER'] = 'Server'; | |
$user->lang['POP3_PORT'] = 'Port'; | |
$user->lang['POP3_DOMAIN'] = 'Domain'; | |
$user->lang['POP3_SERVER_EXPLAIN'] = $user->lang['POP3_PORT_EXPLAIN'] = $user->lang['POP3_DOMAIN_EXPLAIN'] = ''; | |
$tpl = ' | |
<dl> | |
<dt><label for="pop3_server">' . $user->lang['POP3_SERVER'] . ':</label><br /><span>' . $user->lang['POP3_SERVER_EXPLAIN'] . '</span></dt> | |
<dd><input type="text" id="pop3_server" size="40" name="config[pop3_server]" value="' . $new['pop3_server'] . '" /></dd> | |
</dl> | |
<dl> | |
<dt><label for="pop3_port">' . $user->lang['POP3_PORT'] . ':</label><br /><span>' . $user->lang['POP3_PORT_EXPLAIN'] . '</span></dt> | |
<dd><input type="text" id="pop3_port" size="40" name="config[pop3_port]" value="' . $new['pop3_port'] . '" /></dd> | |
</dl> | |
<dl> | |
<dt><label for="pop3_domain">' . $user->lang['POP3_DOMAIN'] . ':</label><br /><span>' . $user->lang['POP3_DOMAIN_EXPLAIN'] . '</span></dt> | |
<dd><input type="text" id="pop3_domain" size="40" name="config[pop3_domain]" value="' . $new['pop3_domain'] . '" /></dd> | |
</dl> | |
'; | |
// These are fields required in the config table | |
return array( | |
'tpl' => $tpl, | |
'config' => array('pop3_server', 'pop3_port', 'pop3_domain') | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment