From d7e7a368b15d84763b802dface998b32ae4995d6 Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Sat, 27 Jan 2018 18:11:57 +0100 Subject: [PATCH] Refactoring of configuration loading Use one INI file instead of multiple PHP files --- .gitignore | 4 +-- config/config-sample.ini | 21 +++++++++++++ htdocs/admin.php | 4 --- htdocs/alias.php | 18 ----------- htdocs/auth.php | 2 +- htdocs/compte.php | 16 ++++------ htdocs/config/conf-dist.php | 56 --------------------------------- htdocs/config/connect-dist.php | 30 ------------------ htdocs/help.php | 2 +- htdocs/inc/haut.php | 2 +- htdocs/lib/auth.php | 2 +- htdocs/lib/class.ldapdomain.php | 3 +- htdocs/lib/class.ldapserver.php | 14 ++++----- htdocs/lib/config.php | 19 +---------- htdocs/lib/hook-dist.php | 54 ------------------------------- 15 files changed, 41 insertions(+), 206 deletions(-) create mode 100644 config/config-sample.ini delete mode 100644 htdocs/config/conf-dist.php delete mode 100644 htdocs/config/connect-dist.php delete mode 100644 htdocs/lib/hook-dist.php diff --git a/.gitignore b/.gitignore index 6a222a8..5046a38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ *.swp -htdocs/config/conf.php -htdocs/config/connect.php -htdocs/lib/hook.php +config/config.ini diff --git a/config/config-sample.ini b/config/config-sample.ini new file mode 100644 index 0000000..7ccfc5c --- /dev/null +++ b/config/config-sample.ini @@ -0,0 +1,21 @@ +; The configuration for evoadmin-mail +; +; You need to copy and edit config-sample.ini to config.ini. +; This INI file is loaded by evoadmin-mail and contains the +; following configurations : +; +; * Global settings +; * LDAP settings +; + +[global] +name = "Evoadmin Mail XXX"; +mail = "evoadmin-mail@example.com" + +[ldap] +host = "127.0.0.1" +port = 389 +base = "dc=example,dc=com" +admin_dn = "cn=admin,dc=example,dc=com" +admin_pass = "xxxxxxx" +superadmin[] = "evoadmin" diff --git a/htdocs/admin.php b/htdocs/admin.php index 94bcf41..ed2da78 100644 --- a/htdocs/admin.php +++ b/htdocs/admin.php @@ -84,9 +84,6 @@ if (!empty($_POST['isactive']) && $server->isSuperAdmin()) {     @@ -105,7 +102,6 @@ if (!empty($_POST['isactive']) && $server->isSuperAdmin()) { getAliases() as $mailaccept) { print "Mail accepté en entrée : "; - if (!$conf['domaines']['onlyone']) { print "@" .$domain->getName(); - } print ""; } @@ -78,25 +76,19 @@ if (isset($_GET['alias'])) { print "Création d'un nouveau mail accepté en entrée : "; - if (!$conf['domaines']['onlyone']) { print "@" .$domain->getName(); - } print ""; print "Création d'un nouveau mail accepté en entrée : "; - if (!$conf['domaines']['onlyone']) { print "@" .$domain->getName(); - } print ""; print "Création d'un nouveau mail accepté en entrée : "; - if (!$conf['domaines']['onlyone']) { print "@" .$domain->getName(); - } print ""; foreach($alias->getRedirections() as $red) { @@ -152,45 +144,35 @@ if (isset($_GET['alias'])) { Alias : getName(); - } ?> Alias : getName(); - } ?> Alias : getName(); - } ?> Alias : getName(); - } ?> Alias : getName(); - } ?> diff --git a/htdocs/auth.php b/htdocs/auth.php index 104f5a2..f01e5a3 100644 --- a/htdocs/auth.php +++ b/htdocs/auth.php @@ -19,7 +19,7 @@ if (!empty($_POST['login'])) { try { $login = htmlentities(strip_tags($_POST['login']),ENT_NOQUOTES); $password = htmlentities(strip_tags($_POST['password']),ENT_NOQUOTES); - $server = new LdapServer($login, LDAP_BASE, LDAP_ADMIN_DN, LDAP_ADMIN_PASS, LDAP_URI); + $server = new LdapServer($login, $config['ldap']); $server->login($password); $_SESSION['login'] = $server->getLogin(); header("location: superadmin.php\n\n"); diff --git a/htdocs/compte.php b/htdocs/compte.php index 3fdbaff..0805624 100644 --- a/htdocs/compte.php +++ b/htdocs/compte.php @@ -76,9 +76,7 @@ if (isset($_GET['account'])) { print ""; print "
"; print "
"; - if (!$conf['domaines']['onlyone']) { print "@" .$domain->getName(); - } print "
"; print ""; @@ -88,9 +86,7 @@ if (isset($_GET['account'])) { print ""; print "
"; print "
"; - if (!$conf['domaines']['onlyone']) { print "@" .$domain->getName(); - } print "
"; print ""; @@ -165,7 +161,7 @@ if (isset($_GET['account'])) {
-
getName(); } ?>
+
getName(); ?>
@@ -190,19 +186,19 @@ if (isset($_GET['account'])) {
-
getName(); } ?>
+
getName(); ?>
-
getName(); } ?>
+
getName(); ?>
-
getName(); } ?>
+
getName(); ?>

Cochez les cases pour choisir les autorisations du compte.
@@ -227,7 +223,7 @@ if (isset($_GET['account'])) {
-
class="form-control move-left" />
+
@@ -235,7 +231,7 @@ if (isset($_GET['account'])) { diff --git a/htdocs/config/conf-dist.php b/htdocs/config/conf-dist.php deleted file mode 100644 index 40bfa75..0000000 --- a/htdocs/config/conf-dist.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @version 1.0 - */ - -#define("LDAP_URI","ldap://127.0.0.1"); -$ldap_servers = array('ldap://127.0.0.1', 'ldap://12'); -define("LDAP_BASE","dc=example,dc=com"); -define("LDAP_ADMIN_DN","cn=admin,dc=example,dc=com"); -define("LDAP_ADMIN_PASS","xxxxx"); - -define("SUDOBIN","/usr/bin/sudo"); -define("SUDOSCRIPT","/usr/share/scripts/evoadmin.sh"); -define("SUDOPASS","xxxxxx"); - -define ('SERVEUR', "localhost"); - -define('SERVEUR','localhost'); -define('SERVEURPORT',3306); -define('BASE','horde'); -define('NOM', 'horde'); -define('PASSE', 'xxxx'); - -?> diff --git a/htdocs/help.php b/htdocs/help.php index 26c670a..502b222 100644 --- a/htdocs/help.php +++ b/htdocs/help.php @@ -30,7 +30,7 @@ include('inc/debut.php');

FAQ

- Cette Foire-Aux-Questions (FAQ) devrait répondre à vos questions. Au fil du temps, de nouvelles questions/réponses seront ajoutées. Posez vos questions à . + Cette Foire-Aux-Questions (FAQ) devrait répondre à vos questions. Au fil du temps, de nouvelles questions/réponses seront ajoutées. Posez vos questions à .

Qu'est-ce qu'une syntaxe valide pour un compte mail ?

diff --git a/htdocs/inc/haut.php b/htdocs/inc/haut.php index e43ed75..2b39e8a 100644 --- a/htdocs/inc/haut.php +++ b/htdocs/inc/haut.php @@ -4,7 +4,7 @@ - <?php print $conf['html']['title']; ?> + <?php print $config['global']['name']; ?> diff --git a/htdocs/lib/auth.php b/htdocs/lib/auth.php index 569a076..5c00015 100644 --- a/htdocs/lib/auth.php +++ b/htdocs/lib/auth.php @@ -8,7 +8,7 @@ if (empty($_SESSION['login'])) { exit(0); } else { try { - $server = new LdapServer($_SESSION['login'], LDAP_BASE, LDAP_ADMIN_DN, LDAP_ADMIN_PASS, LDAP_URI); + $server = new LdapServer($_SESSION['login'], $config['ldap']); if (!empty($_GET['domain'])) { $domain = htmlentities(strip_tags($_GET['domain']),ENT_NOQUOTES); $domain = new LdapDomain($server, $domain); diff --git a/htdocs/lib/class.ldapdomain.php b/htdocs/lib/class.ldapdomain.php index 83cce8c..5d7026c 100644 --- a/htdocs/lib/class.ldapdomain.php +++ b/htdocs/lib/class.ldapdomain.php @@ -70,7 +70,6 @@ class LdapDomain extends LdapServer { } public function addAccount($uid,$name,$password,$active=false,$admin=false,$accountactive=false,$courieractive=false,$webmailactive=false,$authsmtpactive=false,$amavisBypassSpamChecks=false) { - global $conf; if (!preg_match('/^([a-z0-9][a-z0-9\-\.\_]{0,28}[a-z0-9])$/', $uid)) { throw new Exception("Erreur, $name est un nom invalide."); } @@ -78,7 +77,7 @@ class LdapDomain extends LdapServer { $info[LdapAccount::$dn] = $mail; $info["cn"] = $name; $info["homeDirectory"] = "/home/vmail/" .$this->getName(). "/" .$uid. "/"; - $info["uidNumber"] = $conf['unix']['uid']; + $info["uidNumber"] = 2022; $info["gidNumber"] = $this->getGid(); $info["isActive"] = ($active) ? 'TRUE' : 'FALSE'; $info["isAdmin"] = ($admin) ? 'TRUE' : 'FALSE'; diff --git a/htdocs/lib/class.ldapserver.php b/htdocs/lib/class.ldapserver.php index f557fb2..96681a2 100644 --- a/htdocs/lib/class.ldapserver.php +++ b/htdocs/lib/class.ldapserver.php @@ -54,24 +54,24 @@ class LdapServer { return '{SSHA}'.base64_encode(mhash(MHASH_SHA1, $pass.$salt).$salt); } - public function __construct($login, $base, $adminDN, $adminPass, $uri='ldap://127.0.0.1') { - global $conf; + public function __construct($login, $config) { + $uri = 'ldap://'.$config['host'].':'.$config['port']; $this->login = $login; if (!$this->conn = ldap_connect($uri)) { - throw new Exception("Impossible de se connecter au serveur LDAP $uri"); + throw new Exception("Impossible de se connecter au serveur LDAP ".$config['host']); } if (!ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3)) { throw new Exception("Impossible de modifier la version du protocole LDAP à 3"); } - if (!ldap_bind($this->conn, $adminDN, $adminPass)) { + if (!ldap_bind($this->conn, $config['admin_dn'], $config['admin_pass'])) { throw new Exception("Authentification LDAP échoué !"); } - if (in_array($this->login, $conf['admin']['logins'])) { + if (in_array($this->login, $config['superadmin'])) { $this->superadmin = true; - $this->base = $base; + $this->base = $config['base']; } else { $mydomain = preg_replace('/.*@/', '', $login); - $this->base = LdapDomain::$dn.'='.$mydomain.','.$base; + $this->base = LdapDomain::$dn.'='.$mydomain.','.$config['base']; } } diff --git a/htdocs/lib/config.php b/htdocs/lib/config.php index af745db..efb2089 100644 --- a/htdocs/lib/config.php +++ b/htdocs/lib/config.php @@ -1,25 +1,8 @@