diff --git a/phpBB/adm/admin_jabber.php b/phpBB/adm/admin_jabber.php index 8a693a2a23..2d33676a73 100644 --- a/phpBB/adm/admin_jabber.php +++ b/phpBB/adm/admin_jabber.php @@ -12,13 +12,8 @@ // ------------------------------------------------------------- // TODO -// Server name -// Username -// Password -// Resource // Create new user on server // Advise what transports on server -// Set cruise control time // Register transport usernames/passwords (links to online reg systems) if (!empty($setmodules)) @@ -38,6 +33,7 @@ define('IN_PHPBB', 1); $phpbb_root_path = '../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); require('pagestart.' . $phpEx); +include($phpbb_root_path . 'includes/functions_jabber.'.$phpEx); // Do we have general permissions? if (!$auth->acl_get('a_server')) @@ -48,21 +44,86 @@ if (!$auth->acl_get('a_server')) // Grab some basic parameters $submit = (isset($_POST['submit'])) ? true : false; -/* - if ($result = $this->jabber->AccountRegistration($config['contact_email'], str_replace('.', '_', $config['server_name']))) - { - break; - } - } - if (!$result) - { - trigger_error('Could not create new user on Jabber server', E_USER_ERROR); - } -*/ +$jab_enable = request_var('jab_enable', $config['jab_enable']); +$jab_host = request_var('jab_host', $config['jab_host']); +$jab_port = request_var('jab_port', $config['jab_port']); +$jab_username = request_var('jab_username', $config['jab_username']); +$jab_password = request_var('jab_password', $config['jab_password']); +$jab_resource = request_var('jab_resource', $config['jab_resource']); -// Pull all config data -$sql = "SELECT * - FROM " . CONFIG_TABLE; +$jabber = new jabber(); +$error = array(); + +// Setup the basis vars for jabber connection +$jabber->server = $jab_host; +$jabber->port = ($jab_port) ? $jab_port : 5222; +$jabber->username = $jab_username; +$jabber->password = $jab_password; +$jabber->resource = $jab_resource; + +// Are changing (or initialising) a new host or username? If so run some checks and +// try to create account if it doesn't exist +if ($jab_enable && ($jab_host != $config['jab_host'] || $jab_username != $config['jab_username'])) +{ + if (!$jabber->Connect()) + { + trigger_error('Could not connect to Jabber server', E_USER_ERROR); + } + + // First we'll try to authorise using this account, if that fails we'll + // try to create it. + if (!($result = $jabber->SendAuth())) + { + echo " >> $result"; + + if (($result = $jabber->AccountRegistration($config['board_email'], $config['sitename'])) <> 2) + { + + $error[] = ($result == 1) ? $user->lang['ERR_JAB_USERNAME'] : sprintf($user->lang['ERR_JAB_REGISTER'], $result); + } + else + { + $message = $user->lang['JAB_REGISTERED']; + $log = 'JAB_REGISTER'; + } + } + else + { + $message = $user->lang['JAB_CHANGED']; + $log = 'JAB_CHANGED'; + } +} +else if ($jab_password != $config['jab_password']) +{ + if (!$jabber->Connect()) + { + trigger_error('Could not connect to Jabber server', E_USER_ERROR); + } + + if (!$jabber->SendAuth()) + { + trigger_error('Could not authorise on Jabber server', E_USER_ERROR); + } + $jabber->SendPresence(NULL, NULL, 'online'); + + if (($result = $jabber->ChangePassword($jab_password)) <> 2) + { + $error[] = ($result == 1) ? $user->lang['ERR_JAB_PASSCHG'] : sprintf($user->lang['ERR_JAB_PASSFAIL'], $result); + } + else + { + $message = $user->lang['JAB_PASS_CHANGED']; + $log = 'JAB_PASSCHG'; + } + + sleep(1); + $jabber->Disconnect(); +} + +// Pull relevant config data +$sql = 'SELECT * + FROM ' . CONFIG_TABLE . " + WHERE config_name LIKE 'jab_%'"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -71,18 +132,18 @@ while ($row = $db->sql_fetchrow($result)) $config_value = $row['config_value']; $default_config[$config_name] = $config_value; - $new[$config_name] = (isset($_POST[$config_name])) ? $_POST[$config_name] : $default_config[$config_name]; + $new[$config_name] = (isset($_POST[$config_name])) ? request_var($config_name, '') : $default_config[$config_name]; - if ($submit) + if ($submit && !sizeof($error)) { set_config($config_name, $new[$config_name]); } } -if ($submit) +if ($submit && !sizeof($error)) { - add_log('admin', 'LOG_' . strtoupper($mode) . '_CONFIG'); - trigger_error($user->lang['CONFIG_UPDATED']); + add_log('admin', 'LOG_' . $log); + trigger_error($message); } @@ -110,6 +171,20 @@ $jab_yim_enable_no = (!$new['jab_yim_enable']) ? 'checked="checked"' : ''; lang['IM']; ?> + + + ', $error); ?> + + lang['JAB_ENABLE']; ?>:
lang['JAB_ENABLE_EXPLAIN']; ?> />lang['ENABLED']; ?>    />lang['DISABLED']; ?> @@ -192,6 +267,6 @@ $jab_yim_enable_no = (!$new['jab_yim_enable']) ? 'checked="checked"' : ''; \ No newline at end of file diff --git a/phpBB/includes/functions_jabber.php b/phpBB/includes/functions_jabber.php index 30e628f66f..fdc76c03da 100644 --- a/phpBB/includes/functions_jabber.php +++ b/phpBB/includes/functions_jabber.php @@ -250,7 +250,46 @@ class Jabber } return $return_code; + } + else + { + return 3; + } + } + function ChangePassword($new_password) + { + $packet = $this->SendIq($this->server, 'get', 'A0', 'jabber:iq:register'); + + if ($packet) + { + $key = $this->GetInfoFromIqKey($packet); // just in case a key was passed back from the server + unset($packet); + + $payload = "{$this->username} + {$new_password}\n"; + $payload .= ($key) ? "$key\n" : ''; + + $packet = $this->SendIq($this->server, 'set', 'A0', 'jabber:iq:register', $payload); + + if ($this->GetInfoFromIqType($packet) == 'result') + { + $return_code = (isset($packet['iq']['#']['query'][0]['#']['registered'][0]['#'])) ? 1 : 2; + } + elseif ($this->GetInfoFromIqType($packet) == 'error' && isset($packet['iq']['#']['error'][0]['#'])) + { + // "conflict" error, i.e. already registered + if ($packet['iq']['#']['error'][0]['@']['code'] == '409') + { + $return_code = 1; + } + else + { + $return_code = 'Error ' . $packet['iq']['#']['error'][0]['@']['code'] . ': ' . $packet['iq']['#']['error'][0]['#']; + } + } + + return $return_code; } else { diff --git a/phpBB/language/en/lang_admin.php b/phpBB/language/en/lang_admin.php index bc6b3e9bcf..d38e62ae36 100644 --- a/phpBB/language/en/lang_admin.php +++ b/phpBB/language/en/lang_admin.php @@ -211,9 +211,13 @@ $lang += array( 'LOG_EXPORT_IMAGESET' => 'Exported imageset
» %s', 'LOG_DELETE_IMAGESET' => 'Deleted imageset
» %s', - 'LOG_BBCODE_ADD' => 'Added new BBCode
» %s', - 'LOG_BBCODE_EDIT' => 'Edited BBCode
» %s', - 'LOG_BBCODE_DELETE' => 'Deleted BBCode
» %s', + 'LOG_BBCODE_ADD' => 'Added new BBCode
» %s', + 'LOG_BBCODE_EDIT' => 'Edited BBCode
» %s', + 'LOG_BBCODE_DELETE' => 'Deleted BBCode
» %s', + + 'LOG_JAB_PASSCHG' => 'Jabber password changed', + 'LOG_JAB_REGISTER' => 'Jabber account registered', + 'LOG_JAB_CHANGED' => 'Jabber account changed', 'LOG_EMAIL_ERROR' => '%s', 'LOG_JABBER_ERROR' => '%s', @@ -509,7 +513,7 @@ $lang += array( // Jabber settings $lang += array( - 'IM_EXPLAIN' => 'Here you can enable and control the use Jabber for instant messaging and board notices. Jabber is an opensource protocol and therefore available for use by anyone. Some Jabber servers include gateways or transports which allow you to contact users on other networks. Please note that not all servers offer all transports and changes in protocols can prevent transports from operating.', + 'IM_EXPLAIN' => 'Here you can enable and control the use Jabber for instant messaging and board notices. Jabber is an opensource protocol and therefore available for use by anyone. Some Jabber servers include gateways or transports which allow you to contact users on other networks. Not all servers offer all transports and changes in protocols can prevent transports from operating. Note that it may take several seconds to update Jabber account details, do not stop the script till completed!', 'JAB_ENABLE' => 'Enable Jabber', 'JAB_ENABLE_EXPLAIN' => 'Enables use of jabber messaging and notifications', @@ -540,6 +544,15 @@ $lang += array( 'YIM_USERNAME' => 'YIM Username', 'YIM_USERNAME_EXPLAIN' => 'A valid username on %sYIM%s', 'YIM_PASSWORD' => 'YIM Password', + + 'JAB_PASS_CHANGED' => 'Jabber password changed successfully', + 'JAB_REGISTERED' => 'New account registered successfully', + 'JAB_CHANGED' => 'Jabber account changed successfully', + + 'ERR_JAB_USERNAME' => 'The username specified already exists, please choose an alternative.', + 'ERR_JAB_REGISTER' => 'An error occured trying to register this account, %s', + 'ERR_JAB_PASSCHG' => 'Could not change password', + 'ERR_JAB_PASSFAIL' => 'Password update failed, %s', ); // Cookie settings