summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Burschka2014-01-16 04:25:51 +0100
committerChristoph Burschka2014-01-16 04:25:51 +0100
commit86a4fd69d53b61a624dfc332c7a0e70b9a79218a (patch)
tree4f9c652f7ea30737b29a0864ac1806919cbc1314
parentFormatting of README headings. (diff)
downloadejabberd-auth-php-86a4fd69d53b61a624dfc332c7a0e70b9a79218a.tar.gz
Implement smf2_session and finish RPC code. (#1)
This patch should be ready for testing with SMF. (cburschka/cadence/#31)
-rw-r--r--README.md6
-rw-r--r--plugins/session/main.php21
-rw-r--r--plugins/session/www/rpc.php31
-rw-r--r--plugins/smf2/smf2.module12
4 files changed, 49 insertions, 21 deletions
diff --git a/README.md b/README.md
index adff0ee..5637636 100644
--- a/README.md
+++ b/README.md
@@ -31,6 +31,12 @@ The class methods must return boolean values indicating success or failure.
It is generally recommended NOT to allow account creation, account deletion or
password changes, and instead to simply return FALSE in these methods.
+If you wish to use the `session` plugin with your bridge, you will also need to
+implement a function named {xyz}_session(). This function takes no arguments.
+It is called in a non-CLI context, and should return the username of the
+currently logged-in user who made the web request, or `FALSE` if no user
+is logged in.
+
License
-------
diff --git a/plugins/session/main.php b/plugins/session/main.php
new file mode 100644
index 0000000..814bfc5
--- /dev/null
+++ b/plugins/session/main.php
@@ -0,0 +1,21 @@
+<?php
+
+define('ROOT', __DIR__ . '/../../');
+
+function create_key($salt) {
+ require_once ROOT . 'config.php';
+ require_once ROOT . 'plugins/session/session.module';
+ $bridge = session_init($config['session']);
+ $plugin = $config['session']['plugin'];
+ $plugin_conf = $config[$plugin_conf];
+ $plugin_id = $plugin_conf['file'];
+ require_once ROOT . 'plugins/' . $plugin_id . '/' . $plugin_id . '.module';
+ $function = $plugin_id . '_session';
+ $username = function_exists($function) ? $function($plugin_conf) : NULL;
+ if ($username) {
+ $entry = ['user' => $username, 'secret' => sha1($salt . time() . mt_rand()), 'time' => time()];
+ $bridge->create($entry);
+ return $entry;
+ }
+ return FALSE;
+}
diff --git a/plugins/session/www/rpc.php b/plugins/session/www/rpc.php
index 58f3634..fca85a0 100644
--- a/plugins/session/www/rpc.php
+++ b/plugins/session/www/rpc.php
@@ -1,25 +1,16 @@
<?php
-define('ROOT', __DIR__ . '/../../../');
-define('SESS_ROOT' , __DIR__ . '/../');
+define('SESS_ROOT', __DIR__ . '/../');
-main();
+require_once SESS_ROOT . 'main.php';
-function main() {
- require_once ROOT . 'config.php';
- require_once SESS_ROOT . 'session.module';
- $bridge = session_init($config['session']);
- $plugin = $config['session']['plugin'];
- $plugin_conf = $config['session']['plugins'][$plugin_conf];
- $plugin_id = $plugin_conf['file'];
- require_once SESS_ROOT . 'plugins/' . $plugin_id . '/' . $plugin_id . '.module';
- $function = $plugin_id . '_authenticate';
- $username = $function($plugin_conf);
- if ($username) {
- $entry = ['user' => $username, 'secret' => sha1($_POST['salt'] . time() . mt_rand()), 'time' => time()];
- $bridge->create($entry);
- header('Content-type: text/plain; charset=UTF-8');
- print json_encode($entry);
- }
- else header('HTTP/1.1 403 Forbidden');
+$entry = (!empty($_POST['salt']) && strlen($_POST['salt']) >= 16) ?
+ create_key($_POST['salt']) : FALSE;
+
+if ($entry) {
+ header('Content-type: text/plain; charset=UTF-8');
+ print json_encode($entry);
+}
+else {
+ header('HTTP/1.1 403 Forbidden');
}
diff --git a/plugins/smf2/smf2.module b/plugins/smf2/smf2.module
index 8274318..066780e 100644
--- a/plugins/smf2/smf2.module
+++ b/plugins/smf2/smf2.module
@@ -1,6 +1,6 @@
<?php
-function smf2_init($config) {
+function smf2_bootstrap($config) {
$smf_root_path = $config['root_path'];
if (file_exists($smf_root_path . 'SSI.php')) {
include_once $smf_root_path . 'SSI.php';
@@ -9,10 +9,20 @@ function smf2_init($config) {
file_put_contents('php://stderr', "SMF not found at <{$smf_root_path}>.\n");
exit;
}
+}
+
+function smf2_init($config) {
+ smf2_bootstap($config);
require_once __DIR__ . '/BridgeSMF2.php';
return new BridgeSMF2();
}
+function smf2_session($config) {
+ smf2_bootstap($config);
+ $user = smf_ssi('welcome', NULL);
+ return (empty($user['is_guest']) && !empty($user['name'])) ? $user['name'] : FALSE;
+}
+
function smf_ssi($function) {
$args = func_get_args();
array_shift($args);