summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Burschka2016-04-04 18:35:21 +0000
committerChristoph Burschka2016-04-04 18:35:21 +0000
commit8cd148bdb2be52b16cc4dc57a501f194c1ffb58b (patch)
treee3a500052cc560834e02c5f5befe46ebf4adb036
parentTest with domain argument. (diff)
downloadejabberd-auth-php-8cd148bdb2be52b16cc4dc57a501f194c1ffb58b.tar.gz
Add multi-domain support to htpasswd plugin.
Each domain can now use its own htpasswd file.
-rw-r--r--plugins/htpasswd/BridgeHtpasswd.php8
-rw-r--r--plugins/htpasswd/README.md9
-rw-r--r--plugins/htpasswd/htpasswd.module25
3 files changed, 33 insertions, 9 deletions
diff --git a/plugins/htpasswd/BridgeHtpasswd.php b/plugins/htpasswd/BridgeHtpasswd.php
index 51b6a94..62ac1f4 100644
--- a/plugins/htpasswd/BridgeHtpasswd.php
+++ b/plugins/htpasswd/BridgeHtpasswd.php
@@ -9,11 +9,15 @@ class BridgeHtpasswd extends EjabberdAuthBridge {
$this->config = $config;
}
+ function getData($server) {
+ return array_key_exists($server, $this->data) ? $this->data[$server] : $this->data[NULL];
+ }
+
function isuser($username, $server) {
- return array_key_exists($username, $this->data);
+ return array_key_exists($username, $this->getData($server));
}
function auth($username, $server, $password) {
- return $this->isuser($username, $server) && htpasswd_check($password, $this->data[$username], $this->config);
+ return $this->isuser($username, $server) && htpasswd_check($password, $this->getData($server)[$username], $this->config);
}
}
diff --git a/plugins/htpasswd/README.md b/plugins/htpasswd/README.md
index b7b8bcb..66f46ca 100644
--- a/plugins/htpasswd/README.md
+++ b/plugins/htpasswd/README.md
@@ -26,3 +26,12 @@ This configuration must be entered into plugin_conf in config.php:
'htpasswd_file' => '</path/to/htpasswd/file>',
'plain' => FALSE, // optional
]
+
+Each domain can use a separate file, as in:
+
+ 'plugin_conf' => [
+ 'htpasswd_file' => [
+ 'example.com' => '<com.htpasswd>',
+ 'example.org' => '<org.htpasswd>',
+ ]
+ ]
diff --git a/plugins/htpasswd/htpasswd.module b/plugins/htpasswd/htpasswd.module
index b97de52..6e1c9d2 100644
--- a/plugins/htpasswd/htpasswd.module
+++ b/plugins/htpasswd/htpasswd.module
@@ -1,8 +1,23 @@
<?php
function htpasswd_init($config) {
- $data = array();
- $file = $config['htpasswd_file'];
+ $data = [NULL => []];
+ $file = $config['file'];
+ if (!is_array($file)) {
+ $file = [NULL => $file];
+ }
+ foreach ($file as $d => $f) {
+ $data[$d] = htpasswd_load($f);
+ }
+
+ // Load the plugin.
+ require_once __DIR__ . '/BridgeHtpasswd.php';
+ require_once __DIR__ . '/htpasswd.inc';
+ return new BridgeHtpasswd($data, $config);
+}
+
+function htpasswd_load($file) {
+ $data = [];
if (file_exists($file) && is_readable($file)) {
$lines = explode("\n", trim(file_get_contents($file)));
foreach ($lines as $line) {
@@ -10,9 +25,5 @@ function htpasswd_init($config) {
$data[$user] = $password;
}
}
-
- // Load the plugin.
- require_once __DIR__ . '/BridgeHtpasswd.php';
- require_once __DIR__ . '/htpasswd.inc';
- return new BridgeHtpasswd($data, $config);
+ return $data;
}