aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/config/ConfigManager.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/config/ConfigManager.php')
-rw-r--r--application/config/ConfigManager.php77
1 files changed, 64 insertions, 13 deletions
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php
index 32aaea48..99efc156 100644
--- a/application/config/ConfigManager.php
+++ b/application/config/ConfigManager.php
@@ -22,6 +22,11 @@ class ConfigManager
22 public static $DEFAULT_PLUGINS = array('qrcode'); 22 public static $DEFAULT_PLUGINS = array('qrcode');
23 23
24 /** 24 /**
25 * @var string User space.
26 */
27 protected $userSpace;
28
29 /**
25 * @var string Config folder. 30 * @var string Config folder.
26 */ 31 */
27 protected $configFile; 32 protected $configFile;
@@ -41,12 +46,36 @@ class ConfigManager
41 * 46 *
42 * @param string $configFile Configuration file path without extension. 47 * @param string $configFile Configuration file path without extension.
43 */ 48 */
44 public function __construct($configFile = 'data/config') 49 public function __construct($configFile = null, $userSpace = null)
45 { 50 {
46 $this->configFile = $configFile; 51 $this->userSpace = $this->findLDAPUser($userSpace);
52 if ($configFile !== null) {
53 $this->configFile = $configFile;
54 } else {
55 $this->configFile = ($this->userSpace === null) ? 'data/config' : 'data/' . $this->userSpace . '/config';
56 }
47 $this->initialize(); 57 $this->initialize();
48 } 58 }
49 59
60 public function findLDAPUser($login, $password = null) {
61 $connect = ldap_connect(getenv('SHAARLI_LDAP_HOST'));
62 ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
63 if (!$connect || !ldap_bind($connect, getenv('SHAARLI_LDAP_DN'), getenv('SHAARLI_LDAP_PASSWORD'))) {
64 return false;
65 }
66
67 $search_query = str_replace('%login%', ldap_escape($login), getenv('SHAARLI_LDAP_FILTER'));
68
69 $search = ldap_search($connect, getenv('SHAARLI_LDAP_BASE'), $search_query);
70 $info = ldap_get_entries($connect, $search);
71
72 if (ldap_count_entries($connect, $search) == 1 && (is_null($password) || ldap_bind($connect, $info[0]["dn"], $password))) {
73 return $login;
74 } else {
75 return null;
76 }
77 }
78
50 /** 79 /**
51 * Reset the ConfigManager instance. 80 * Reset the ConfigManager instance.
52 */ 81 */
@@ -270,6 +299,16 @@ class ConfigManager
270 } 299 }
271 300
272 /** 301 /**
302 * Get the current userspace.
303 *
304 * @return mixed User space.
305 */
306 public function getUserSpace()
307 {
308 return $this->userSpace;
309 }
310
311 /**
273 * Recursive function which find asked setting in the loaded config. 312 * Recursive function which find asked setting in the loaded config.
274 * 313 *
275 * @param array $settings Ordered array which contains keys to find. 314 * @param array $settings Ordered array which contains keys to find.
@@ -342,19 +381,31 @@ class ConfigManager
342 */ 381 */
343 protected function setDefaultValues() 382 protected function setDefaultValues()
344 { 383 {
345 $this->setEmpty('resource.data_dir', 'data'); 384 if ($this->userSpace === null) {
346 $this->setEmpty('resource.config', 'data/config.php'); 385 $data = 'data';
347 $this->setEmpty('resource.datastore', 'data/datastore.php'); 386 $tmp = 'tmp';
348 $this->setEmpty('resource.ban_file', 'data/ipbans.php'); 387 $cache = 'cache';
349 $this->setEmpty('resource.updates', 'data/updates.txt'); 388 $pagecache = 'pagecache';
350 $this->setEmpty('resource.log', 'data/log.txt'); 389 } else {
351 $this->setEmpty('resource.update_check', 'data/lastupdatecheck.txt'); 390 $data = 'data/' . ($this->userSpace);
352 $this->setEmpty('resource.history', 'data/history.php'); 391 $tmp = 'tmp/' . ($this->userSpace);
392 $cache = 'cache/' . ($this->userSpace);
393 $pagecache = 'pagecache/' . ($this->userSpace);
394 }
395
396 $this->setEmpty('resource.data_dir', $data);
397 $this->setEmpty('resource.config', $data . '/config.php');
398 $this->setEmpty('resource.datastore', $data . '/datastore.php');
399 $this->setEmpty('resource.ban_file', $data . '/ipbans.php');
400 $this->setEmpty('resource.updates', $data . '/updates.txt');
401 $this->setEmpty('resource.log', $data . '/log.txt');
402 $this->setEmpty('resource.update_check', $data . '/lastupdatecheck.txt');
403 $this->setEmpty('resource.history', $data . '/history.php');
353 $this->setEmpty('resource.raintpl_tpl', 'tpl/'); 404 $this->setEmpty('resource.raintpl_tpl', 'tpl/');
354 $this->setEmpty('resource.theme', 'default'); 405 $this->setEmpty('resource.theme', 'default');
355 $this->setEmpty('resource.raintpl_tmp', 'tmp/'); 406 $this->setEmpty('resource.raintpl_tmp', $tmp);
356 $this->setEmpty('resource.thumbnails_cache', 'cache'); 407 $this->setEmpty('resource.thumbnails_cache', $cache);
357 $this->setEmpty('resource.page_cache', 'pagecache'); 408 $this->setEmpty('resource.page_cache', $pagecache);
358 409
359 $this->setEmpty('security.ban_after', 4); 410 $this->setEmpty('security.ban_after', 4);
360 $this->setEmpty('security.ban_duration', 1800); 411 $this->setEmpty('security.ban_duration', 1800);