From 7fc3addf1b2796998fe0350cd4c5d7513612b1ba Mon Sep 17 00:00:00 2001 From: Christoph Burschka Date: Tue, 30 Oct 2012 02:45:21 +0100 Subject: Initial checkin --- classes/JabberAuth.php | 90 +++++++++++++++++++++++++++++++++++++++ classes/JabberAuthPhpBB.php | 38 +++++++++++++++++ config.php | 4 ++ main.php | 16 +++++++ phpbb-bridge/noweb_user.php | 17 ++++++++ phpbb-bridge/phpbb_bootstrap.php | 51 ++++++++++++++++++++++ tests/test | 10 +++++ tests/test.php | 26 +++++++++++ tests/test.successful | Bin 0 -> 32 bytes 9 files changed, 252 insertions(+) create mode 100644 classes/JabberAuth.php create mode 100644 classes/JabberAuthPhpBB.php create mode 100644 config.php create mode 100644 main.php create mode 100644 phpbb-bridge/noweb_user.php create mode 100644 phpbb-bridge/phpbb_bootstrap.php create mode 100755 tests/test create mode 100644 tests/test.php create mode 100644 tests/test.successful diff --git a/classes/JabberAuth.php b/classes/JabberAuth.php new file mode 100644 index 0000000..f649889 --- /dev/null +++ b/classes/JabberAuth.php @@ -0,0 +1,90 @@ +stdin = fopen('php://stdin', 'r'); + $this->stdout = fopen('php://stdout', 'w'); + $this->logfile = fopen($this->logpath . 'activity-' . date('Y-m-d') . '.log', 'a'); + $this->running = TRUE; + } + + function stop() { + $this->log("Stopping..."); + $this->running = FALSE; + } + + function run() { + while ($this->running) { + $data = $this->read(); + if ($data) { + $result = $this->execute($data); + $this->write((int)$result); + } + } + $this->log("Stopped"); + } + + function read() { + $input = fread($this->stdin, 2); + if (!$input) { + return $this->stop(); + } + + $input = unpack('n', $input); + $length = $input[1]; + if($length > 0) { + $this->log("Reading $length bytes..."); + $data = fread($this->stdin, $length); + return $data; + } + } + + function write($data) { + $this->log("OUT: $data"); + fwrite($this->stdout, pack("nn", 2, $data)); + } + + function log($data) { + fwrite($this->logfile, sprintf("%s [%d] - %s\n", date('Y-m-d H:i:s'), getmypid(), $data)); + } + + function execute($data) { + $args = explode(':', $data); + $command = array_shift($args); + // Only log the username for security. + $this->log("Executing $command on {$args[0]}"); + + switch ($command) { + case 'isuser': + list($username, $server) = $args; + return $this->isuser($username, $server); + case 'auth': + list($username, $server, $password) = $args; + return $this->auth($username, $server, $password); + case 'setpass': + list($username, $server, $password) = $args; + return $this->setpass($username, $server, $password); + case 'tryregister': + list($username, $server, $password) = $args; + return $this->tryregister($username, $server, $password); + case 'removeuser': + list($username, $server) = $args; + return $this->removeuser($username, $server); + case 'removeuser3': + list($username, $server, $password) = $args; + return $this->auth($username, $server, $password) && $this->removeuser($username, $password); + default: + $this->stop(); + } + } +} diff --git a/classes/JabberAuthPhpBB.php b/classes/JabberAuthPhpBB.php new file mode 100644 index 0000000..e60cbae --- /dev/null +++ b/classes/JabberAuthPhpBB.php @@ -0,0 +1,38 @@ +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/config.php b/config.php new file mode 100644 index 0000000..dd5f8f1 --- /dev/null +++ b/config.php @@ -0,0 +1,4 @@ +run(); diff --git a/phpbb-bridge/noweb_user.php b/phpbb-bridge/noweb_user.php new file mode 100644 index 0000000..3291222 --- /dev/null +++ b/phpbb-bridge/noweb_user.php @@ -0,0 +1,17 @@ +load('services.yml'); + +$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); +$processor->process($phpbb_container); + +// Setup class loader first +$phpbb_class_loader = $phpbb_container->get('class_loader'); +$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); + +// Instantiate some basic classes +$user = new noweb_user; +$auth = $phpbb_container->get('auth'); +$db = $phpbb_container->get('dbal.conn'); + +// Grab global variables, re-cache if necessary +$config = $phpbb_container->get('config'); +set_config(null, null, null, $config); +set_config_count(null, null, null, $config); diff --git a/tests/test b/tests/test new file mode 100755 index 0000000..4d68705 --- /dev/null +++ b/tests/test @@ -0,0 +1,10 @@ +php test.php > test.in +php ../main.php test.out +if [ -z "$(diff test.out test.successful)" ] +then + echo "Test successful." +else + echo "Test unsuccessful. Check activity logs." +fi + +rm test.in test.out \ No newline at end of file diff --git a/tests/test.php b/tests/test.php new file mode 100644 index 0000000..a6d6c16 --- /dev/null +++ b/tests/test.php @@ -0,0 +1,26 @@ +