2018-09-25 15:56:22 +02:00
|
|
|
<?php
|
|
|
|
|
2018-10-09 14:31:34 +02:00
|
|
|
class FormController {
|
|
|
|
private static $server, $form=array(), $domain, $account, $alias;
|
|
|
|
public static function init(LdapServer $server) {
|
|
|
|
self::$server = $server;
|
|
|
|
|
2018-10-09 13:26:53 +02:00
|
|
|
self::filterPost();
|
|
|
|
// Get content from LDAP
|
|
|
|
try {
|
|
|
|
if (!empty(self::$form['domain'])) {
|
|
|
|
self::$domain = new LdapDomain(self::$server, self::$form['domain']);
|
|
|
|
if (!empty(self::$form['account'])) {
|
|
|
|
self::$account = new LdapAccount(self::$domain, self::$form['account']);
|
|
|
|
}
|
|
|
|
if (!empty(self::$form['alias'])) {
|
|
|
|
self::$alias = new LdapAlias(self::$domain, self::$form['alias']);
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-09 13:26:53 +02:00
|
|
|
} catch (Exception $e) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
2018-10-09 13:26:53 +02:00
|
|
|
}
|
2018-09-25 15:56:22 +02:00
|
|
|
|
2018-10-09 13:26:53 +02:00
|
|
|
if (!empty(self::$form['delete'])) {
|
|
|
|
switch(self::$form['delete']) {
|
|
|
|
case 'domain':
|
|
|
|
FormController::delDomain();
|
|
|
|
break;
|
|
|
|
case 'account':
|
|
|
|
FormController::delAccount();
|
|
|
|
break;
|
|
|
|
case 'alias':
|
|
|
|
FormController::delAlias();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (!empty(self::$form['add'])) {
|
|
|
|
switch(self::$form['add']) {
|
|
|
|
case 'domain':
|
|
|
|
FormController::addDomain();
|
|
|
|
break;
|
|
|
|
case 'account':
|
|
|
|
FormController::addAccount();
|
|
|
|
break;
|
|
|
|
case 'alias':
|
|
|
|
FormController::addAlias();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (!empty(self::$form['update'])) {
|
|
|
|
switch(self::$form['update']) {
|
|
|
|
case 'domain':
|
|
|
|
FormController::updateDomain();
|
|
|
|
break;
|
|
|
|
case 'account':
|
|
|
|
FormController::updateAccount();
|
|
|
|
break;
|
|
|
|
case 'alias':
|
|
|
|
FormController::updateAlias();
|
|
|
|
break;
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
2018-10-09 13:26:53 +02:00
|
|
|
}
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static function filterPassword() {
|
|
|
|
if (count(self::$form['password']) != 2 || self::$form['password'][0] != self::$form['password'][1]) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => "Confirmation du mot de passe inccorrecte !");
|
2018-09-25 15:56:22 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
self::$form['password'] = self::$form['password'][0];
|
|
|
|
self::$form['password'] = filter_var(self::$form['password'], FILTER_CALLBACK, array('options' => function($value) {
|
|
|
|
return trim($value);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function filterType($type) {
|
|
|
|
if (in_array($type, array('domain', 'account', 'alias'))) {
|
|
|
|
return $type;
|
|
|
|
} else { return NULL; }
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function filterPost() {
|
|
|
|
self::$form = filter_input_array(INPUT_POST, array(
|
|
|
|
'add' => array('filter' => FILTER_CALLBACK, 'options' => 'self::filterType')
|
|
|
|
,'delete' => array('filter' => FILTER_CALLBACK, 'options' => 'self::filterType')
|
|
|
|
,'update' => array('filter' => FILTER_CALLBACK, 'options' => 'self::filterType')
|
|
|
|
,'domain' => FILTER_SANITIZE_URL
|
|
|
|
,'account' => FILTER_SANITIZE_EMAIL
|
|
|
|
,'alias' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH)
|
|
|
|
,'uid' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH)
|
|
|
|
,'cn' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH)
|
|
|
|
,'password' => array('filter' => FILTER_DEFAULT, 'flags' => FILTER_FORCE_ARRAY)
|
|
|
|
,'isactive' => FILTER_VALIDATE_BOOLEAN
|
|
|
|
,'isadmin' => FILTER_VALIDATE_BOOLEAN
|
|
|
|
,'courieractive' => FILTER_VALIDATE_BOOLEAN
|
|
|
|
,'webmailactive' => FILTER_VALIDATE_BOOLEAN
|
|
|
|
,'authsmtpactive' => FILTER_VALIDATE_BOOLEAN
|
|
|
|
,'maildrop' => array('filter' => FILTER_DEFAULT, 'flags' => FILTER_FORCE_ARRAY)
|
|
|
|
,'mailaccept' => array('filter' => FILTER_DEFAULT, 'flags' => FILTER_FORCE_ARRAY)
|
|
|
|
), true);
|
|
|
|
|
2019-01-10 14:32:34 +01:00
|
|
|
self::$form['mailaccept'] = array_map(function($value) {
|
|
|
|
if (!empty($value)) {
|
|
|
|
return $value.'@'.self::$form['domain'];
|
|
|
|
}
|
|
|
|
}, self::$form['mailaccept']);
|
|
|
|
|
2018-09-25 15:56:22 +02:00
|
|
|
if (!empty(self::$form['password'])) { self::filterPassword(); }
|
|
|
|
|
|
|
|
unset($_POST);
|
|
|
|
//die(var_dump(self::$form));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function addDomain() {
|
2018-09-27 13:34:55 +02:00
|
|
|
if (self::$server->isSuperAdmin()) {
|
2018-09-25 15:56:22 +02:00
|
|
|
if (!empty(self::$form['cn'])) {
|
|
|
|
try {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 1, 'message' => 'Ajout en cours du domaine '.self::$form['cn'].' ...');
|
2018-09-25 15:56:22 +02:00
|
|
|
self::$server->addDomain(self::$form['cn'], self::$form['isactive']);
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 0, 'message' => "Ajout effectué.");
|
2018-09-25 15:56:22 +02:00
|
|
|
} catch (Exception $e_ad) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function updateDomain() {
|
2018-09-27 13:34:55 +02:00
|
|
|
if (self::$server->isSuperAdmin()) {
|
2018-09-25 15:56:22 +02:00
|
|
|
try {
|
|
|
|
self::$domain->update(self::$form['isactive']);
|
|
|
|
} catch (Exception $e_ad) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function delDomain() {
|
2018-09-27 13:34:55 +02:00
|
|
|
if (self::$server->isSuperAdmin()) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 1, 'message' => 'Suppression du domaine '.self::$form['cn'].' ...');
|
2018-09-25 15:56:22 +02:00
|
|
|
try {
|
|
|
|
self::$server->delDomain(self::$form['cn']);
|
2023-07-24 17:51:03 +02:00
|
|
|
PageController::$alerts[] = array('type' => 0, 'message' => 'Suppression effectuée.');
|
2018-09-25 15:56:22 +02:00
|
|
|
} catch (Exception $e_ad) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function delAccount() {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 1, 'message' => 'Suppression du compte '.self::$form['uid'].'...');
|
2018-09-25 15:56:22 +02:00
|
|
|
try {
|
2023-07-24 17:58:22 +02:00
|
|
|
self::$domain->delAccount(self::$form['uid'],self::$form['domain']);
|
2023-07-26 16:52:39 +02:00
|
|
|
PageController::$alerts[] = array('type' => 0, 'message' => "Suppression effectuée.");
|
2018-09-25 15:56:22 +02:00
|
|
|
} catch (Exception $e) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function delAlias() {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 1, 'message' => 'Suppression de l\'alias '.self::$form['cn'].'...');
|
2018-09-25 15:56:22 +02:00
|
|
|
try {
|
|
|
|
self::$domain->delAlias(self::$form['cn']);
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 0, 'message' => "Suppression effectué.");
|
2018-09-25 15:56:22 +02:00
|
|
|
} catch (Exception $e) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function addAccount() {
|
|
|
|
try {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
|
2018-09-25 15:56:22 +02:00
|
|
|
self::$domain->addAccount(
|
|
|
|
self::$form['uid']
|
|
|
|
,self::$form['cn']
|
|
|
|
,self::$form['password']
|
|
|
|
,self::$form['isactive']
|
|
|
|
,self::$form['isadmin']
|
|
|
|
,self::$form['isactive']
|
|
|
|
,self::$form['courieractive']
|
|
|
|
,self::$form['webmailactive']
|
|
|
|
,self::$form['authsmtpactive']
|
|
|
|
);
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 0, 'message' => 'Ajout effectué');
|
2018-09-25 15:56:22 +02:00
|
|
|
} catch (Exception $e) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function updateAccount() {
|
|
|
|
try {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
|
2018-09-25 15:56:22 +02:00
|
|
|
self::$account->update(
|
|
|
|
self::$form['cn']
|
|
|
|
,self::$form['password']
|
|
|
|
,self::$form['isactive']
|
|
|
|
,self::$form['isadmin']
|
|
|
|
,self::$form['isactive']
|
|
|
|
,self::$form['courieractive']
|
|
|
|
,self::$form['webmailactive']
|
|
|
|
,self::$form['authsmtpactive']
|
2019-01-09 17:09:17 +01:00
|
|
|
,self::$form['mailaccept']
|
|
|
|
,self::$form['maildrop']
|
2018-09-25 15:56:22 +02:00
|
|
|
);
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
|
2018-09-25 15:56:22 +02:00
|
|
|
} catch (Exception $e) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function addAlias() {
|
|
|
|
try {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
|
2018-09-25 15:56:22 +02:00
|
|
|
self::$domain->addAlias(
|
|
|
|
self::$form['cn']
|
|
|
|
,self::$form['isactive']
|
|
|
|
,self::$form['mailaccept']
|
|
|
|
,self::$form['maildrop']
|
|
|
|
);
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 0, 'message' => "Ajout effectué");
|
2018-09-25 15:56:22 +02:00
|
|
|
} catch (Exception $e) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function updateAlias() {
|
|
|
|
try {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
|
2018-09-25 15:56:22 +02:00
|
|
|
self::$alias->update(
|
|
|
|
self::$form['isactive']
|
|
|
|
,self::$form['mailaccept']
|
|
|
|
,self::$form['maildrop']
|
|
|
|
);
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
|
2018-09-25 15:56:22 +02:00
|
|
|
} catch (Exception $e) {
|
2018-10-09 14:31:34 +02:00
|
|
|
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
|
2018-09-25 15:56:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|