Merge DefaultController into index.php
This commit is contained in:
parent
24fabced51
commit
bc29c91ca9
|
@ -4,6 +4,38 @@ spl_autoload_register(function ($class) {
|
||||||
if (file_exists("lib/$class.php")) { require_once("lib/$class.php"); }
|
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);
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class FormController extends DefaultController {
|
class FormController {
|
||||||
private static $form=array(), $domain, $account, $alias;
|
private static $server, $form=array(), $domain, $account, $alias;
|
||||||
public static function init() {
|
public static function init(LdapServer $server) {
|
||||||
|
self::$server = $server;
|
||||||
|
|
||||||
self::filterPost();
|
self::filterPost();
|
||||||
// Get content from LDAP
|
// Get content from LDAP
|
||||||
try {
|
try {
|
||||||
|
@ -16,7 +18,7 @@ class FormController extends DefaultController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty(self::$form['delete'])) {
|
if (!empty(self::$form['delete'])) {
|
||||||
|
@ -60,7 +62,7 @@ class FormController extends DefaultController {
|
||||||
|
|
||||||
private static function filterPassword() {
|
private static function filterPassword() {
|
||||||
if (count(self::$form['password']) != 2 || self::$form['password'][0] != self::$form['password'][1]) {
|
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;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -106,11 +108,11 @@ class FormController extends DefaultController {
|
||||||
if (self::$server->isSuperAdmin()) {
|
if (self::$server->isSuperAdmin()) {
|
||||||
if (!empty(self::$form['cn'])) {
|
if (!empty(self::$form['cn'])) {
|
||||||
try {
|
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::$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) {
|
} 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 {
|
try {
|
||||||
self::$domain->update(self::$form['isactive']);
|
self::$domain->update(self::$form['isactive']);
|
||||||
} catch (Exception $e_ad) {
|
} 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() {
|
private static function delDomain() {
|
||||||
if (self::$server->isSuperAdmin()) {
|
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 {
|
try {
|
||||||
self::$server->delDomain(self::$form['cn']);
|
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) {
|
} 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() {
|
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 {
|
try {
|
||||||
self::$domain->delAccount(self::$form['uid']);
|
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) {
|
} catch (Exception $e) {
|
||||||
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function delAlias() {
|
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 {
|
try {
|
||||||
self::$domain->delAlias(self::$form['cn']);
|
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) {
|
} catch (Exception $e) {
|
||||||
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function addAccount() {
|
private static function addAccount() {
|
||||||
try {
|
try {
|
||||||
self::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
|
PageController::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
|
||||||
self::$domain->addAccount(
|
self::$domain->addAccount(
|
||||||
self::$form['uid']
|
self::$form['uid']
|
||||||
,self::$form['cn']
|
,self::$form['cn']
|
||||||
|
@ -172,15 +174,15 @@ class FormController extends DefaultController {
|
||||||
,self::$form['webmailactive']
|
,self::$form['webmailactive']
|
||||||
,self::$form['authsmtpactive']
|
,self::$form['authsmtpactive']
|
||||||
);
|
);
|
||||||
self::$alerts[] = array('type' => 0, 'message' => 'Ajout effectué');
|
PageController::$alerts[] = array('type' => 0, 'message' => 'Ajout effectué');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function updateAccount() {
|
private static function updateAccount() {
|
||||||
try {
|
try {
|
||||||
self::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
|
PageController::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
|
||||||
self::$account->update(
|
self::$account->update(
|
||||||
self::$form['cn']
|
self::$form['cn']
|
||||||
,self::$form['password']
|
,self::$form['password']
|
||||||
|
@ -191,38 +193,38 @@ class FormController extends DefaultController {
|
||||||
,self::$form['webmailactive']
|
,self::$form['webmailactive']
|
||||||
,self::$form['authsmtpactive']
|
,self::$form['authsmtpactive']
|
||||||
);
|
);
|
||||||
self::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
|
PageController::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function addAlias() {
|
private static function addAlias() {
|
||||||
try {
|
try {
|
||||||
self::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
|
PageController::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
|
||||||
self::$domain->addAlias(
|
self::$domain->addAlias(
|
||||||
self::$form['cn']
|
self::$form['cn']
|
||||||
,self::$form['isactive']
|
,self::$form['isactive']
|
||||||
,self::$form['mailaccept']
|
,self::$form['mailaccept']
|
||||||
,self::$form['maildrop']
|
,self::$form['maildrop']
|
||||||
);
|
);
|
||||||
self::$alerts[] = array('type' => 0, 'message' => "Ajout effectué");
|
PageController::$alerts[] = array('type' => 0, 'message' => "Ajout effectué");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function updateAlias() {
|
private static function updateAlias() {
|
||||||
try {
|
try {
|
||||||
self::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
|
PageController::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
|
||||||
self::$alias->update(
|
self::$alias->update(
|
||||||
self::$form['isactive']
|
self::$form['isactive']
|
||||||
,self::$form['mailaccept']
|
,self::$form['mailaccept']
|
||||||
,self::$form['maildrop']
|
,self::$form['maildrop']
|
||||||
);
|
);
|
||||||
self::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
|
PageController::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ class LdapServer {
|
||||||
$this->base = Config::getLdapBase();
|
$this->base = Config::getLdapBase();
|
||||||
} else {
|
} else {
|
||||||
$mydomain = preg_replace('/.*@/', '', $login);
|
$mydomain = preg_replace('/.*@/', '', $login);
|
||||||
$this->base = LdapDomain::$dn.'='.$mydomain.','.Config::getBaseDN();
|
$this->base = LdapDomain::$dn.'='.$mydomain.','.Config::getLdapBase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,13 @@
|
||||||
|
|
||||||
require_once 'Twig/autoload.php';
|
require_once 'Twig/autoload.php';
|
||||||
|
|
||||||
class PageController extends DefaultController {
|
class PageController {
|
||||||
private static $twig, $params=array(), $domain, $account, $alias;
|
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');
|
$loader = new Twig_Loader_Filesystem('tpl/page');
|
||||||
self::$twig = new Twig_Environment($loader, array(
|
self::$twig = new Twig_Environment($loader, array(
|
||||||
'cache' => false
|
'cache' => false
|
||||||
|
|
Loading…
Reference in a new issue