Merge DefaultController into index.php

This commit is contained in:
Victor LABORIE 2018-10-09 14:31:34 +02:00
parent 24fabced51
commit bc29c91ca9
5 changed files with 73 additions and 75 deletions

View file

@ -4,6 +4,38 @@ spl_autoload_register(function ($class) {
if (file_exists("lib/$class.php")) { require_once("lib/$class.php"); }
});
DefaultController::init();
Config::load('../config/config.ini');
?>
Logger::init();
MailNotify::init();
session_name('EVOADMIN_SESS');
session_start();
// Get content from LDAP
$server = NULL;
if (!empty($_SESSION['login'])) {
try {
$server = new LdapServer($_SESSION['login']);
} catch (Exception $e) {
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
FormController::init($server);
} else {
if (!empty($_POST['login'])) {
try {
$input = filter_input_array(INPUT_POST, array(
'login' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH)
,'password' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH)
));
$server = new LdapServer($input['login']);
$server->login($input['password']);
$_SESSION['login'] = $server->getLogin();
} catch (Exception $e) {
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
$server = NULL;
}
}
}
PageController::init($server);

View file

@ -1,39 +0,0 @@
<?php
class DefaultController {
protected static $alerts=array(),$server;
public static function init() {
Config::load('../config/config.ini');
Logger::init();
MailNotify::init();
session_name('EVOADMIN_SESS');
session_start();
// Get content from LDAP
if (!empty($_SESSION['login'])) {
try {
self::$server = new LdapServer($_SESSION['login']);
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
FormController::init();
} else {
if (!empty($_POST['login'])) {
try {
$input = filter_input_array(INPUT_POST, array(
'login' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH)
,'password' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH)
));
self::$server = new LdapServer($input['login']);
self::$server->login($input['password']);
$_SESSION['login'] = self::$server->getLogin();
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
}
PageController::init();
}
}

View file

@ -1,8 +1,10 @@
<?php
class FormController extends DefaultController {
private static $form=array(), $domain, $account, $alias;
public static function init() {
class FormController {
private static $server, $form=array(), $domain, $account, $alias;
public static function init(LdapServer $server) {
self::$server = $server;
self::filterPost();
// Get content from LDAP
try {
@ -16,7 +18,7 @@ class FormController extends DefaultController {
}
}
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
if (!empty(self::$form['delete'])) {
@ -60,7 +62,7 @@ class FormController extends DefaultController {
private static function filterPassword() {
if (count(self::$form['password']) != 2 || self::$form['password'][0] != self::$form['password'][1]) {
self::$alerts[] = array('type' => 2, 'message' => "Confirmation du mot de passe inccorrecte !");
PageController::$alerts[] = array('type' => 2, 'message' => "Confirmation du mot de passe inccorrecte !");
return false;
}
@ -106,11 +108,11 @@ class FormController extends DefaultController {
if (self::$server->isSuperAdmin()) {
if (!empty(self::$form['cn'])) {
try {
self::$alerts[] = array('type' => 1, 'message' => 'Ajout en cours du domaine '.self::$form['cn'].' ...');
PageController::$alerts[] = array('type' => 1, 'message' => 'Ajout en cours du domaine '.self::$form['cn'].' ...');
self::$server->addDomain(self::$form['cn'], self::$form['isactive']);
self::$alerts[] = array('type' => 0, 'message' => "Ajout effectué.");
PageController::$alerts[] = array('type' => 0, 'message' => "Ajout effectué.");
} catch (Exception $e_ad) {
self::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
}
}
}
@ -121,46 +123,46 @@ class FormController extends DefaultController {
try {
self::$domain->update(self::$form['isactive']);
} catch (Exception $e_ad) {
self::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
}
}
}
private static function delDomain() {
if (self::$server->isSuperAdmin()) {
self::$alerts[] = array('type' => 1, 'message' => 'Suppression du domaine '.self::$form['cn'].' ...');
PageController::$alerts[] = array('type' => 1, 'message' => 'Suppression du domaine '.self::$form['cn'].' ...');
try {
self::$server->delDomain(self::$form['cn']);
self::$alerts[] = array('type' => 0, 'message' => 'Suppression effectué.');
PageController::$alerts[] = array('type' => 0, 'message' => 'Suppression effectué.');
} catch (Exception $e_ad) {
self::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
}
}
}
private static function delAccount() {
self::$alerts[] = array('type' => 1, 'message' => 'Suppression du compte '.self::$form['uid'].'...');
PageController::$alerts[] = array('type' => 1, 'message' => 'Suppression du compte '.self::$form['uid'].'...');
try {
self::$domain->delAccount(self::$form['uid']);
self::$alerts[] = array('type' => 0, 'message' => "Suppression effectué.");
PageController::$alerts[] = array('type' => 0, 'message' => "Suppression effectué.");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function delAlias() {
self::$alerts[] = array('type' => 1, 'message' => 'Suppression de l\'alias '.self::$form['cn'].'...');
PageController::$alerts[] = array('type' => 1, 'message' => 'Suppression de l\'alias '.self::$form['cn'].'...');
try {
self::$domain->delAlias(self::$form['cn']);
self::$alerts[] = array('type' => 0, 'message' => "Suppression effectué.");
PageController::$alerts[] = array('type' => 0, 'message' => "Suppression effectué.");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function addAccount() {
try {
self::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
PageController::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
self::$domain->addAccount(
self::$form['uid']
,self::$form['cn']
@ -172,15 +174,15 @@ class FormController extends DefaultController {
,self::$form['webmailactive']
,self::$form['authsmtpactive']
);
self::$alerts[] = array('type' => 0, 'message' => 'Ajout effectué');
PageController::$alerts[] = array('type' => 0, 'message' => 'Ajout effectué');
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function updateAccount() {
try {
self::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
PageController::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
self::$account->update(
self::$form['cn']
,self::$form['password']
@ -191,38 +193,38 @@ class FormController extends DefaultController {
,self::$form['webmailactive']
,self::$form['authsmtpactive']
);
self::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
PageController::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function addAlias() {
try {
self::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
PageController::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
self::$domain->addAlias(
self::$form['cn']
,self::$form['isactive']
,self::$form['mailaccept']
,self::$form['maildrop']
);
self::$alerts[] = array('type' => 0, 'message' => "Ajout effectué");
PageController::$alerts[] = array('type' => 0, 'message' => "Ajout effectué");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function updateAlias() {
try {
self::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
PageController::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
self::$alias->update(
self::$form['isactive']
,self::$form['mailaccept']
,self::$form['maildrop']
);
self::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
PageController::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}

View file

@ -71,7 +71,7 @@ class LdapServer {
$this->base = Config::getLdapBase();
} else {
$mydomain = preg_replace('/.*@/', '', $login);
$this->base = LdapDomain::$dn.'='.$mydomain.','.Config::getBaseDN();
$this->base = LdapDomain::$dn.'='.$mydomain.','.Config::getLdapBase();
}
}

View file

@ -2,10 +2,13 @@
require_once 'Twig/autoload.php';
class PageController extends DefaultController {
private static $twig, $params=array(), $domain, $account, $alias;
class PageController {
public static $alerts=array();
private static $server, $twig, $params=array(), $domain, $account, $alias;
public static function init(LdapServer $server=NULL) {
self::$server = $server;
public static function init() {
$loader = new Twig_Loader_Filesystem('tpl/page');
self::$twig = new Twig_Environment($loader, array(
'cache' => false