From 1a1ec38c95a25143bea1e3da38c65a60437d7883 Mon Sep 17 00:00:00 2001 From: Christoph Burschka Date: Thu, 1 Nov 2012 00:01:08 +0100 Subject: Huge overhaul to deal with the global variables more cleanly. Avoid globals wherever possible, to avoid collisions with CMS systems. --- core/EjabberdAuth.php | 30 +++++++++++++---------------- main.php | 35 +++++++++++++++++++--------------- plugins/phpbb3/BridgePhpBB3.php | 36 +++++++++++++++++++++++++++++++++++ plugins/phpbb3/JabberAuthPhpBB3.php | 38 ------------------------------------- plugins/phpbb3/phpbb3.module | 5 +++-- plugins/phpbb3/phpbb3_bootstrap.php | 7 ++++++- plugins/phpbb4/phpbb4_bootstrap.php | 5 +++++ 7 files changed, 83 insertions(+), 73 deletions(-) mode change 100644 => 100755 main.php create mode 100644 plugins/phpbb3/BridgePhpBB3.php delete mode 100644 plugins/phpbb3/JabberAuthPhpBB3.php diff --git a/core/EjabberdAuth.php b/core/EjabberdAuth.php index 3e9d4df..d9b9776 100644 --- a/core/EjabberdAuth.php +++ b/core/EjabberdAuth.php @@ -1,20 +1,16 @@ stdin = fopen('php://stdin', 'r'); $this->stdout = fopen('php://stdout', 'w'); + $this->bridge = $bridge; if (!empty($config['log_path']) && is_dir($config['log_path']) && is_writable($config['log_path'])) { $this->logfile = fopen($config['log_path'] . 'activity-' . date('Y-m-d') . '.log', 'a'); } @@ -74,22 +70,22 @@ abstract class JabberAuth { switch ($command) { case 'isuser': list($username, $server) = $args; - return $this->isuser($username, $server); + return $this->bridge->isuser($username, $server); case 'auth': list($username, $server, $password) = $args; - return $this->auth($username, $server, $password); + return $this->bridge->auth($username, $server, $password); case 'setpass': list($username, $server, $password) = $args; - return $this->setpass($username, $server, $password); + return $this->bridge->setpass($username, $server, $password); case 'tryregister': list($username, $server, $password) = $args; - return $this->tryregister($username, $server, $password); + return $this->bridge->tryregister($username, $server, $password); case 'removeuser': list($username, $server) = $args; - return $this->removeuser($username, $server); + return $this->bridge->removeuser($username, $server); case 'removeuser3': list($username, $server, $password) = $args; - return $this->auth($username, $server, $password) && $this->removeuser($username, $password); + return $this->bridge->auth($username, $server, $password) && $this->bridge->removeuser($username, $password); default: $this->stop(); } diff --git a/main.php b/main.php old mode 100644 new mode 100755 index 2388e8f..5d6c9dd --- a/main.php +++ b/main.php @@ -1,23 +1,28 @@ #!/usr/bin/php run(); +function main() { + require_once ROOT . 'config.php'; + $err = fopen('php://stderr', 'w'); + if (!empty($config['plugin']) && !empty($config[$config['plugin']])) { + $plugin_file = 'plugins/' . $config['plugin'] . '/' . $config['plugin'] . '.module'; + if (file_exists(ROOT . $plugin_file)) { + require_once ROOT . $plugin_file; + $function = $config['plugin'] . '_init'; + $auth = new EjabberdAuth($config, $function($config[$config['plugin']])); + $auth->run(); + } + else { + fwrite($err, "Plugin <{$plugin_file}> not found.\n"); + } } else { - fwrite($err, "Plugin <{$plugin_file}> not found.\n"); + fwrite($err, 'Incomplete configuration: $config[\'plugin\'] must be set to , and $config[] populated.' . "\n"); } -} -else { - fwrite($err, 'Incomplete configuration: $config[\'plugin\'] must be set to , and $config[] populated.' . "\n"); -} +} \ No newline at end of file diff --git a/plugins/phpbb3/BridgePhpBB3.php b/plugins/phpbb3/BridgePhpBB3.php new file mode 100644 index 0000000..bc7d8c8 --- /dev/null +++ b/plugins/phpbb3/BridgePhpBB3.php @@ -0,0 +1,36 @@ +auth = $auth; + $this->db = $db; + } + + function isuser($username, $server) { + $username_clean = utf8_clean_string($username); + $row = $this->db->sql_fetchrow($this->db->sql_query('SELECT username FROM ' . USERS_TABLE . ' WHERE username_clean = ' . "'" . $this->db->sql_escape($username_clean) . "'" . ';')); + return !empty($row); + } + + function auth($username, $server, $password) { + $result = $this->auth->login($username, $password); + return $result['status'] == LOGIN_SUCCESS; + } + + // The following functions are disabled. This script will not change the phpBB user database. + + function setpass($username, $server, $password) { + return FALSE; + } + + function tryregister($username, $server, $password) { + return FALSE; + } + + function removeuser($username, $server) { + return FALSE; + } +} diff --git a/plugins/phpbb3/JabberAuthPhpBB3.php b/plugins/phpbb3/JabberAuthPhpBB3.php deleted file mode 100644 index e60cbae..0000000 --- a/plugins/phpbb3/JabberAuthPhpBB3.php +++ /dev/null @@ -1,38 +0,0 @@ -logpath = $logpath; - parent::init(); - $this->auth = $auth; - $this->db = $db; - } - - function isuser($username, $server) { - $username_clean = utf8_clean_string($username); - $row = $this->db->sql_fetchrow($this->db->sql_query('SELECT username FROM ' . USERS_TABLE . ' WHERE username_clean = ' . "'" . $this->db->sql_escape($username_clean) . "'" . ';')); - return !empty($row); - } - - function auth($username, $server, $password) { - $result = $this->auth->login($username, $password); - return $result['status'] == LOGIN_SUCCESS; - } - - // The following functions are disabled. This script will not change the phpBB user database. - - function setpass($username, $server, $password) { - return FALSE; - } - - function tryregister($username, $server, $password) { - return FALSE; - } - - function removeuser($username, $server) { - return FALSE; - } -} diff --git a/plugins/phpbb3/phpbb3.module b/plugins/phpbb3/phpbb3.module index 4c58762..7502094 100644 --- a/plugins/phpbb3/phpbb3.module +++ b/plugins/phpbb3/phpbb3.module @@ -1,10 +1,11 @@ .\n"); + exit; +} require($phpbb_root_path . 'includes/startup.' . $phpEx); if (file_exists($phpbb_root_path . 'config.' . $phpEx)) @@ -30,7 +35,7 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); // Instantiate some basic classes $user = new noweb_user(); $auth = new auth(); -$db = new $sql_db(); +$db = new $sql_db(); $cache = new cache(); // Connect to DB diff --git a/plugins/phpbb4/phpbb4_bootstrap.php b/plugins/phpbb4/phpbb4_bootstrap.php index 3f7dee5..740f230 100644 --- a/plugins/phpbb4/phpbb4_bootstrap.php +++ b/plugins/phpbb4/phpbb4_bootstrap.php @@ -6,6 +6,11 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +if (!file_exists($phpbb_root_path . 'includes/startup.' . $phpEx)) { + file_put_contents('php://stderr', "phpBB not found at <{$phpbb_root_path}>.\n"); + exit; +} + require($phpbb_root_path . 'includes/startup.' . $phpEx); require_once __DIR__ . '/noweb_user.php'; -- cgit v1.1