summaryrefslogtreecommitdiff
path: root/core/JabberAuth.php
diff options
context:
space:
mode:
authorChristoph Burschka2012-10-31 23:57:55 +0100
committerChristoph Burschka2012-10-31 23:57:55 +0100
commit82059dd246f979b783bd5b14972595d1660b91e3 (patch)
tree6ca9cfcdf7d46b448a5f31b1f5b4fb18c4663f66 /core/JabberAuth.php
parentAdd phpbb4 plugin (for trunk of phpBB) (diff)
downloadejabberd-auth-php-82059dd246f979b783bd5b14972595d1660b91e3.tar.gz
Huge overhaul to deal with the global variables more cleanly. Avoid globals wherever possible, to avoid collisions with CMS systems.
Diffstat (limited to 'core/JabberAuth.php')
-rw-r--r--core/JabberAuth.php97
1 files changed, 0 insertions, 97 deletions
diff --git a/core/JabberAuth.php b/core/JabberAuth.php
deleted file mode 100644
index 3e9d4df..0000000
--- a/core/JabberAuth.php
+++ /dev/null
@@ -1,97 +0,0 @@
-<?php
-// Arancaytar, October 2012
-// This is a general PHP implementation of the ejabberd auth protocol.
-
-abstract class JabberAuth {
- 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;
- $this->stdin = fopen('php://stdin', 'r');
- $this->stdout = fopen('php://stdout', 'w');
- 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');
- }
- else {
- $this->logfile = fopen('php://stderr', 'w');
- }
- $this->log('Starting...');
- $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();
- }
- }
-}