diff options
author | Christoph Burschka | 2012-11-01 00:01:08 +0100 |
---|---|---|
committer | Christoph Burschka | 2012-11-01 00:01:08 +0100 |
commit | 1a1ec38c95a25143bea1e3da38c65a60437d7883 (patch) | |
tree | 4784357112e6fce315bef1fc21848df7a1b50154 | |
parent | Huge overhaul to deal with the global variables more cleanly. Avoid globals w... (diff) | |
download | ejabberd-auth-php-1a1ec38c95a25143bea1e3da38c65a60437d7883.tar.gz |
Huge overhaul to deal with the global variables more cleanly. Avoid globals wherever possible, to avoid collisions with CMS systems.
-rw-r--r-- | core/EjabberdAuth.php | 30 | ||||
-rwxr-xr-x[-rw-r--r--] | main.php | 35 | ||||
-rw-r--r-- | plugins/phpbb3/BridgePhpBB3.php (renamed from plugins/phpbb3/JabberAuthPhpBB3.php) | 6 | ||||
-rw-r--r-- | plugins/phpbb3/phpbb3.module | 5 | ||||
-rw-r--r-- | plugins/phpbb3/phpbb3_bootstrap.php | 7 | ||||
-rw-r--r-- | plugins/phpbb4/phpbb4_bootstrap.php | 5 |
6 files changed, 49 insertions, 39 deletions
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 @@ <?php -// Arancaytar, October 2012 -// This is a general PHP implementation of the ejabberd auth protocol. -abstract class JabberAuth { +/** + * Runs constantly and takes requests from an input stream + * as specified in the ejabberd auth protocol. + */ +class EjabberdAuth { var $running; - abstract function isuser($username, $server); - abstract function auth($username, $server, $password); - abstract function setpass($username, $server, $password); - abstract function tryregister($username, $server, $password); - abstract function removeuser($username, $server); - - function init() { - global $config; + function __construct($config, EjabberdAuthBridge $bridge) { $this->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(); } @@ -1,23 +1,28 @@ #!/usr/bin/php <?php -// by Aran, October 2012 - define('ROOT', __DIR__ . '/'); -require_once ROOT . 'config.php'; -$err = fopen('php://stderr', 'w'); +require_once ROOT . 'core/EjabberdAuth.php'; +require_once ROOT . 'core/EjabberdAuthBridge.php'; + +main(); -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'; - $function($config[$config['plugin']])->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 <name>, and $config[<name>] populated.' . "\n"); } -} -else { - fwrite($err, 'Incomplete configuration: $config[\'plugin\'] must be set to <name>, and $config[<name>] populated.' . "\n"); -} +}
\ No newline at end of file diff --git a/plugins/phpbb3/JabberAuthPhpBB3.php b/plugins/phpbb3/BridgePhpBB3.php index e60cbae..bc7d8c8 100644 --- a/plugins/phpbb3/JabberAuthPhpBB3.php +++ b/plugins/phpbb3/BridgePhpBB3.php @@ -1,12 +1,10 @@ <?php -class JabberAuthPhpBB extends JabberAuth { +class BridgePhpBB3 extends EjabberdAuthBridge { var $auth; var $db; - function __construct($auth, $db, $logpath) { - $this->logpath = $logpath; - parent::init(); + function __construct($auth, $db) { $this->auth = $auth; $this->db = $db; } 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 @@ <?php function phpbb3_init($config) { + global $phpbb_root_path; $phpbb_root_path = $config['root_path']; // Bootstrap the phpBB system. require_once __DIR__ . '/phpbb3_bootstrap.php'; // Load the plugin. - require_once __DIR__ . '/JabberAuthPhpBB3.php'; - return new JabberAuthPhpBB3($config['auth'], $config['db']); + require_once __DIR__ . '/BridgePhpBB3.php'; + return new BridgePhpBB3($auth, $db); } diff --git a/plugins/phpbb3/phpbb3_bootstrap.php b/plugins/phpbb3/phpbb3_bootstrap.php index 4ede950..55c973f 100644 --- a/plugins/phpbb3/phpbb3_bootstrap.php +++ b/plugins/phpbb3/phpbb3_bootstrap.php @@ -1,7 +1,12 @@ <?php define('IN_PHPBB', TRUE); +global $phpEx, $db, $cache, $user, $config; $phpEx = 'php'; +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); 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'; |