Browse Source

Add new config style and Config class for better configuration.

ohartl 9 years ago
parent
commit
25f08f5e76
2 changed files with 306 additions and 0 deletions
  1. 195 0
      config/config.php.example
  2. 111 0
      include/php/classes/Config.php

+ 195 - 0
config/config.php.example

@@ -0,0 +1,195 @@
+<?php
+
+//////////////////////////////////////////////////////////////////////////
+//                                                                      //
+//  DO NOT EDIT THIS FILE!                                              //
+//                                                                      //
+//  Instead, copy this config file to config.php and make your changes  //
+//  in the copied version. This is just a template!                     //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+return array(
+
+	/******************************************************
+	 * URL to your WebMUM installation.
+	 */
+
+	'base_url' => 'http://localhost/webmum',
+
+
+	/******************************************************
+	 * MySQL database connection settings
+	 */
+
+	'mysql' => array(
+		'host' => 'localhost',
+		'user' => 'vmail',
+		'password' => 'vmail',
+		'database' => 'vmail',
+	),
+
+
+	/******************************************************
+	 * Database schema mapping
+	 */
+
+	'schema' => array(
+		// Table names
+		'tables' => array(
+			// Example:
+			// 'table-keyword' => 'actual-table-name',
+
+			'users' => 'users',
+			'domains' => 'domains',
+			'aliases' => 'aliases',
+		),
+
+		'attributes' => array(
+			// Example:
+			// 'table-keyword' => array(
+			//     'attribute-keyword' => 'actual-attribute-name',
+			//     ...
+			// ),
+
+			// Users table columns
+			'users' => array(
+				'id' => 'id',
+				'username' => 'username',
+				'domain' => 'domain',
+				'password' => 'password',
+				'mailbox_limit' => 'mailbox_limit', // (Optional see 'options.enable_mailbox_limits')
+			),
+
+			// Domains table columns
+			'domains' => array(
+				'id' => 'id',
+				'domain' => 'domain',
+			),
+
+			// Aliases table columns
+			'aliases' => array(
+				'id' => 'id',
+				'source' => 'source',
+				'destination' => 'destination',
+				'multi_source' => 'multi_source', // (Optional see 'options.enable_multi_source_redirects')
+			),
+		),
+	),
+
+
+	/******************************************************
+	 * General options
+	 */
+
+	'options' => array(
+
+		/**
+		 * Enable mailbox limits. (Default false == off)
+		 *
+		 * Needs a new db attribute in users table with INT(10)
+		 */
+
+		'enable_mailbox_limits' => false,
+
+
+		/**
+		 * Enable validating that the source addresses are ending with domain from domains. (Default true == on)
+		 */
+
+		'enable_validate_aliases_source_domain' => true,
+
+
+		/**
+		 * Enable multi source redirects. (Default false == off)
+		 *
+		 * Needs a new db attribute in aliases table with VARCHAR(32)
+		 */
+
+		'enable_multi_source_redirects' => false,
+
+
+		/**
+		 * Enable limited admin domain access. (Default false == off)
+		 *
+		 * Limitations can be configured under 'admin_domain_limits'
+		 */
+
+		'enable_admin_domain_limits' => false,
+
+
+		/**
+		 * Enable logging for failed login attempts. (Default false == off)
+		 *
+		 * You can mointor the logfile with fail2ban and ban attackers' IP-addresses.
+		 * Path to logfile can be configured under 'log_path'
+		 */
+
+		'enable_logging' => false,
+
+	),
+
+
+	/******************************************************
+	 * Admin e-mail addresses
+	 *
+	 * Users with these e-mail addresses will have admin access,
+	 * you can limit their access with the 'options.enable_admin_domain_limits' feature
+	 */
+
+	'admins' => array(
+		'admin@domain.tld',
+	),
+
+
+	/******************************************************
+	 * Limited admin domain access (only used if 'options.enable_admin_domain_limits' is true)
+	 *
+	 * Unlisted admins have access to every domain, the admin is limited to listed domains only!
+	 * Unlisted domains are not accessible by that admin.
+	 * Note that listed admins cannot create new domains!
+	 */
+
+	'admin_domain_limits' => array(
+		// Example:
+		// 'low_rank_admin@domain.tld' => array('his-domain.tld', 'shared-domain.tld'),
+	),
+
+
+	/******************************************************
+	 * Password
+	 */
+
+	'password' => array(
+
+		// Algorithm used for password encryption
+		'hash_algorithm' => 'SHA-512', // Supported algorithms: SHA-512, SHA-256, BLOWFISH
+
+		// Minimum length for passwords
+		'min_length' => 8,
+
+	),
+
+
+	/******************************************************
+	 * Log file path (only used if 'options.enable_logging' is true)
+	 *
+	 * Make sure that PHP has permission to create the log directory and webmum.log (write permissions for php user)
+	 */
+
+	'log_path' => '/var/www/webmum/log/',
+
+
+	/******************************************************
+	 * Frontend options
+	 */
+
+	'frontend_options' => array(
+
+		// Separator for email lists
+		'email_separator_text' => ', ', // possible values: ', ' (default), '; ', PHP_EOL (newline)
+		'email_separator_form' => ',', // possible values: ',' (default), ';', PHP_EOL (newline)
+
+	),
+
+);

+ 111 - 0
include/php/classes/Config.php

@@ -0,0 +1,111 @@
+<?php
+
+class Config
+{
+
+	/**
+	 * @var array
+	 */
+	protected static $config = array();
+
+
+	private function __construct()
+	{
+	}
+
+
+	private function __clone()
+	{
+	}
+
+
+	/**
+	 * @param array $configArray
+	 */
+	public static function init($configArray)
+	{
+		static::set(null, $configArray);
+	}
+
+
+	/**
+	 * Set a config value using "dot" notation.
+	 *
+	 * @param string $key
+	 * @param mixed $value
+	 * @return array
+	 */
+	public static function set($key, $value)
+	{
+		if(is_null($key)) return static::$config = $value;
+
+		$keys = explode('.', $key);
+
+		$array =& static::$config;
+		while(count($keys) > 1){
+			$key = array_shift($keys);
+
+			if(!isset($array[$key]) || !is_array($array[$key])){
+				$array[$key] = array();
+			}
+
+			$array =& $array[$key];
+		}
+
+		$array[array_shift($keys)] = $value;
+
+		return $array;
+	}
+
+
+	/**
+	 * Get a config value using "dot" notation.
+	 *
+	 * @param string $key
+	 * @param mixed $default
+	 * @return mixed
+	 */
+	public static function get($key, $default = null)
+	{
+		if(is_null($key)) return static::$config;
+
+		if(isset(static::$config[$key])) return static::$config[$key];
+
+		$pointer = static::$config;
+		foreach(explode('.', $key) as $segment){
+			if(!is_array($pointer) || !array_key_exists($segment, $pointer)){
+				return $default;
+			}
+
+			$pointer = $pointer[$segment];
+		}
+
+		return $pointer;
+	}
+
+
+	/**
+	 * Check if a config value exists using "dot" notation.
+	 *
+	 * @param string $key
+	 * @return bool
+	 */
+	public static function has($key)
+	{
+		if(empty(static::$config) || is_null($key)) return false;
+
+		if(array_key_exists($key, static::$config)) return true;
+
+		$pointer = static::$config;
+		foreach(explode('.', $key) as $segment){
+			if(!is_array($pointer) || !array_key_exists($segment, $pointer)){
+				return false;
+			}
+
+			$pointer = $pointer[$segment];
+		}
+
+		return true;
+	}
+
+}