From cc202c462f34fff212d3e51a095c63008c20b050 Mon Sep 17 00:00:00 2001 From: Christoph Burschka Date: Sun, 25 Sep 2016 15:25:59 +0200 Subject: Fix #16 Accept command-line arguments. If main.php is called with commandline arguments, these will be passed to the bridge as a single request, instead of running the bridge as a daemon. The arguments are, in order: The result will be printed to stdout (1 for success, 0 for failure), and will be set as the exit status (0 for success, 1 for failure). --- core/EjabberdAuth.php | 2 +- main.php | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/EjabberdAuth.php b/core/EjabberdAuth.php index c9b5ec4..d2465ce 100644 --- a/core/EjabberdAuth.php +++ b/core/EjabberdAuth.php @@ -61,7 +61,7 @@ class EjabberdAuth { } function execute($data) { - $args = explode(':', $data . ':::'); + $args = is_array($data) ? array_merge($data, [NULL,NULL,NULL]) : explode(':', $data . ':::'); list($command, $username, $server, $password) = $args; $username = xmpp_unescape_node($username); diff --git a/main.php b/main.php index ba63f7d..4df895e 100755 --- a/main.php +++ b/main.php @@ -10,18 +10,25 @@ main(); function main() { require_once ROOT . 'config.php'; $plugin_file = 'plugins/' . $config['plugin'] . '/' . $config['plugin'] . '.module'; - if (file_exists(ROOT . $plugin_file)) { - require_once ROOT . $plugin_file; - $function = $config['plugin'] . '_init'; - $bridge = $function($config['plugin_conf']); - } - else { + if (!file_exists(ROOT . $plugin_file)) { return fwrite(STDERR, "Plugin <{$plugin_file}> not found.\n"); } + + require_once ROOT . $plugin_file; + $function = $config['plugin'] . '_init'; + $bridge = $function($config['plugin_conf']); + if (!empty($config['session'])) { require_once 'plugins/session/session.module'; $session = session_init($config['session']); } else $session = NULL; - (new EjabberdAuth($config, $bridge, $session))->run(); + + $main = new EjabberdAuth($config, $bridge, $session); + if ($_SERVER['argc'] > 1) { + $result = $main->execute(array_slice($_SERVER['argv'], 1)); + print(($result ? 1 : 0) . "\n"); + exit($result ? 0 : 1); + } + $main->run(); } -- cgit v1.1