Merge all pages in index.php with Controller class

This commit is contained in:
Victor LABORIE 2018-09-25 15:56:22 +02:00
parent 833fe2bcda
commit 75595ed201
23 changed files with 538 additions and 407 deletions

View File

@ -1,84 +0,0 @@
<?php
// Load config and autoload class
require_once("lib/config.php");
// Force authentication on this page
require_once("lib/auth.php");
if (empty($_GET['domain'])) {
header("location: superadmin.php\n\n");
exit(1);
}
if (!empty($_POST['account'])) {
$account = htmlentities(strip_tags($_POST['account']),ENT_NOQUOTES);
$alerts[] = array('type' => 1, 'message' => "Voulez vous vraiment supprimer le compte $account ?");
$alerts[] = array('type' => 1, 'message' => "<form name=\"del\" method=\"post\" action=\"admin.php?domain=".$domain->getName()."&viewonly=1\"><button type=\"submit\" name=\"delete\" value=\"$account\">Confirmer</button> / <a href=\"admin.php?domain=".$domain->getName()."&viewonly=1\">Annuler</a></form>");
}
if (!empty($_POST['alias'])) {
$alias = htmlentities(strip_tags($_POST['alias']),ENT_NOQUOTES);
$alerts[] = array('type' => 1, 'message' => "Voulez vous vraiment supprimer l'alias $alias ?");
$alerts[] = array('type' => 1, 'message' => "<form name=\"del\" method=\"post\" action=\"admin.php?domain=".$domain->getName()."&viewonly=2\"><button type=\"submit\" name=\"delalias\" value=\"$alias\">Confirmer</button> / <a href=\"admin.php?domain=".$domain->getName()."&viewonly=2\">Annuler</a></form>");
}
if (!empty($_POST['delete'])) {
$account = htmlentities(strip_tags($_POST['delete']),ENT_NOQUOTES);
$alerts[] = array('type' => 1, 'message' => "Suppression du compte $account...");
try {
$domain->delAccount($account);
$alerts[] = array('type' => 0, 'message' => "Suppression effectué.");
} catch (Exception $e) {
$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
if (!empty($_POST['delalias'])) {
$alias = htmlentities(strip_tags($_POST['delalias']),ENT_NOQUOTES);
$alerts[] = array('type' => 1, 'message' => "Suppression de l'alias $alias...");
try {
$domain->delAlias($alias);
$alerts[] = array('type' => 0, 'message' => "Suppression effectué.");
} catch (Exception $e) {
$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
if (!empty($_POST['isactive']) && $server->isSuperAdmin()) {
$active = ($_POST['isactive'] == "TRUE") ? true : false;
try {
$domain->update($active);
header('Location: admin.php?domain='.$domain->getName());
} catch (Exception $e) {
$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
if ( (!isset($_GET['viewonly'])) || ($_GET['viewonly']==1) ) {
print $twig->render('list_account.html', array(
'page_name' => $config['global']['name']
,'alerts' => $alerts
,'login' => $server->getLogin()
,'isSuperAdmin' => $server->isSuperAdmin()
,'domain' => $domain->getName()
,'active' => $domain->isActive()
,'accounts' => $domain->getAccounts()
,'view' => 'account'
));
} elseif ( (isset($_GET['viewonly'])) && ($_GET['viewonly']==2) ) {
print $twig->render('list_alias.html', array(
'page_name' => $config['global']['name']
,'alerts' => $alerts
,'login' => $server->getLogin()
,'isSuperAdmin' => $server->isSuperAdmin()
,'domain' => $domain->getName()
,'active' => $domain->isActive()
,'aliases' => $domain->getAlias()
,'view' => 'alias'
));
}

View File

@ -1,54 +0,0 @@
<?php
// Load config and autoload class
require_once("lib/config.php");
// Force authentication on this page
require_once("lib/auth.php");
if (!empty($_POST['cn'])) {
$cn = (!empty($_GET['alias'])) ? $alias->getName() : htmlentities(strip_tags($_POST['cn']),ENT_NOQUOTES);
$actif = (!empty($_POST['isactive'])) ? true : false;
$mailaccept = array_filter($_POST['mailaccept'], function($value) {
if (!empty($value)) {
return true;
} else {
return false;
}
});
array_walk($mailaccept, function(&$item,$key) {
if (!empty($item)) {
global $domain;
$item = "$item". "@".$domain->getName();
}
});
$maildrop = $_POST['maildrop'];
try {
if (!empty($_GET['alias'])) {
$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
$alias->update($actif,$mailaccept,$maildrop);
header('Location: alias.php?domain='.$domain->getName().'&alias='.$alias->getName());
} else {
$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
$domain->addAlias($cn,$actif,$mailaccept,$maildrop);
$alerts[] = array('type' => 0, 'message' => "Ajout effectué");
$alerts[] = array('type' => 0, 'message' => '<a href="alias.php?domain='.$domain->getName().'&alias='.$cn.'"><button class="btn btn-primary">Voir l\'alias cr&eacute;&eacute;</button></a>');
}
} catch (Exception $e) {
$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
print $twig->render('alias.html', array(
'page_name' => $config['global']['name']
,'alerts' => $alerts
,'login' => $server->getLogin()
,'isSuperAdmin' => $server->isSuperAdmin()
,'domain' => $domain->getName()
,'name' => !empty($alias) ? $alias->getName() : NULL
,'active' => !empty($alias) ? $alias->isActive() : true
,'aliases' => !empty($alias) ? $alias->getAliases() : NULL
,'maildrops' => !empty($alias) ? $alias->getRedirections() : NULL
));

View File

@ -1,38 +0,0 @@
<?php
// Load config and autoload class
require_once("lib/config.php");
session_name('EVOADMIN_SESS');
session_start();
ob_start();
$logout = isset($_SESSION['login']) ? true : false;
if ($logout) {
session_unset('EVOADMIN_SESS');
session_destroy();
}
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, $config['ldap']);
$server->login($password);
$_SESSION['login'] = $server->getLogin();
header("location: superadmin.php\n\n");
exit(0);
} catch (Exception $e) {
$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
print $twig->render('login.html', array(
'page_name' => $config['global']['name'].' - Login'
,'alerts' => $alerts
,'logout' => $logout
));
ob_end_flush();

View File

@ -1,55 +0,0 @@
<?php
// Load config and autoload class
require_once("lib/config.php");
// Force authentication on this page
require_once("lib/auth.php");
if (!empty($_POST['cn'])) {
// Verification coherence des mots de passe
if ( $_POST['pass1'] != $_POST['pass2'] ) {
$alerts[] = array('type' => 2, 'message' => "Erreur, vous avez tape deux mots de passe differents");
exit(1);
}
$uid = (!empty($_GET['account'])) ? $account->getUid() : htmlentities(strip_tags($_POST['uid']),ENT_NOQUOTES);
$cn = htmlentities(strip_tags($_POST['cn']),ENT_NOQUOTES);
$password = (!empty($_POST['pass1'])) ? $_POST['pass1'] : NULL;
$actif = (!empty($_POST['isactive'])) ? true : false;
$admin = (!empty($_POST['isadmin'])) ? true : false;
$courier = (!empty($_POST['courieractive'])) ? true : false;
$webmail = (!empty($_POST['webmailactive'])) ? true : false;
$authsmtp = (!empty($_POST['authsmtpactive'])) ? true : false;
try {
if (!empty($_GET['account'])) {
$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
$account->update($cn,$password,$actif,$admin,$actif,$courier,$webmail,$authsmtp);
header('Location: compte.php?domain='.$domain->getName().'&account='.$account->getUid());
} else {
$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
$domain->addAccount($uid,$cn,$password,$actif,$admin,$actif,$courier,$webmail,$authsmtp);
$alerts[] = array('type' => 0, 'message' => 'Ajout effectué <a href="compte.php?domain='.$domain->getName().'&account='.$uid.'@'.$domain->getName().'"><button class="btn btn-primary">Voir le compte créé</button></a>');
}
} catch (Exception $e) {
$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
print $twig->render('account.html', array(
'page_name' => $config['global']['name']
,'alerts' => $alerts
,'login' => $server->getLogin()
,'isSuperAdmin' => $server->isSuperAdmin()
,'domain' => $domain->getName()
,'uid' => !empty($account) ? $account->getUid() : NULL
,'name' => !empty($account) ? $account->getName() : NULL
,'aliases' => !empty($account) ? $account->getAliases() : array()
,'maildrops' => !empty($account) ? $account->getRedirections() : array()
,'active' => !empty($account) ? $account->isActive() : true
,'admin' => !empty($account) ? $account->isAdmin() : false
,'courier' => !empty($account) ? $account->isCourier() : true
,'webmail' => !empty($account) ? $account->isWebmail() : true
,'authsmtp' => !empty($account) ? $account->isAuthSmtp() : true
));

View File

@ -1,36 +0,0 @@
<?php
// Load config and autoload class
require_once("lib/config.php");
// Force authentication on this page
require_once("lib/auth.php");
if (!$server->isSuperAdmin()) {
$alerts[] = array('type' => 2, 'message' => "Vous n'avez pas les droits pour cette page");
# EvoLog::log("Access denied on domaine.php");
exit(1);
}
$domain = NULL;
if (!empty($_POST['domain'])) {
$domain = htmlentities(strip_tags($_POST['domain']),ENT_NOQUOTES);
$alerts[] = array('type' => 1, 'message' => "Ajout en cours du domaine $domain ...");
try {
$active = (!empty($_POST['isactive'])) ? true : false;
$server->addDomain($domain, $active);
$alerts[] = array('type' => 0, 'message' => "Ajout effectué.");
} catch (Exception $e_ad) {
$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
}
}
print $twig->render('add_domain.html', array(
'page_name' => $config['global']['name']
,'alerts' => $alerts
,'login' => $server->getLogin()
,'isSuperAdmin' => $server->isSuperAdmin()
));

View File

@ -1,15 +0,0 @@
<?php
// Load config and autoload class
require_once("lib/config.php");
// Force authentication on this page
require_once("lib/auth.php");
print $twig->render('help.html', array(
'page_name' => $config['global']['name']
,'alerts' => $alerts
,'login' => $server->getLogin()
,'isSuperAdmin' => $server->isSuperAdmin()
,'notif_mail' => $config['global']['mail']
));

View File

@ -3,11 +3,18 @@
session_name('EVOADMIN_SESS');
session_start();
if (isset($_SESSION['login'])) {
header("Location: superadmin.php\n\n");
exit(0);
} else {
header("Location: auth.php\n\n");
exit(0);
}
spl_autoload_register(function ($class) {
if (file_exists("lib/$class.php")) {
require_once("lib/$class.php");
}
$class = strtolower($class);
if (file_exists("lib/class.$class.php")) {
require_once("lib/class.$class.php");
}
});
DefaultController::init();
FormController::init();
PageController::init();
?>

View File

@ -0,0 +1,43 @@
<?php
class DefaultController {
protected static $logged=false, $config=array(), $alerts=array(),$server;
public static function init() {
self::$config = parse_ini_file('../config/config.ini', true);
Logger::configure(self::$config['global']['log_level']);
MailNotify::configure(self::$config['global']);
// Get content from LDAP
if (!empty($_SESSION['login'])) {
self::$logged = true;
try {
self::$server = new LdapServer($_SESSION['login'], self::$config['ldap']);
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
} 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::$config['ldap']);
self::$server->login($input['password']);
self::$logged = true;
$_SESSION['login'] = self::$server->getLogin();
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
}
}
protected static function needSuperAdmin() {
if (!self::$server->isSuperAdmin()) {
self::$alerts[] = array('type' => 2, 'message' => "Super Adminsitrateur seulement !");
return false;
} else { return true; }
}
}

View File

@ -0,0 +1,231 @@
<?php
class FormController extends DefaultController {
private static $form=array(), $domain, $account, $alias;
public static function init() {
if (self::$logged) {
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']);
}
}
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
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;
}
}
}
}
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 !");
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);
if (!empty(self::$form['password'])) { self::filterPassword(); }
unset($_POST);
//die(var_dump(self::$form));
}
private static function addDomain() {
if (self::needSuperAdmin()) {
if (!empty(self::$form['cn'])) {
try {
self::$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é.");
} catch (Exception $e_ad) {
self::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
}
}
}
}
private static function updateDomain() {
if (self::needSuperAdmin()) {
try {
self::$domain->update(self::$form['isactive']);
} catch (Exception $e_ad) {
self::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
}
}
}
private static function delDomain() {
if (self::needSuperAdmin()) {
self::$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é.');
} catch (Exception $e_ad) {
self::$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
}
}
}
private static function delAccount() {
self::$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é.");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function delAlias() {
self::$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é.");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function addAccount() {
try {
self::$alerts[] = array('type' => 1, 'message' => "Ajout en cours...");
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']
);
self::$alerts[] = array('type' => 0, 'message' => 'Ajout effectué');
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function updateAccount() {
try {
self::$alerts[] = array('type' => 1, 'message' => "Modification en cours...");
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']
);
self::$alerts[] = array('type' => 0, 'message' => "Modification effectué.");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function addAlias() {
try {
self::$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é");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function updateAlias() {
try {
self::$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é.");
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
}

View File

@ -0,0 +1,206 @@
<?php
require_once 'Twig/autoload.php';
class PageController extends DefaultController {
private static $twig, $params=array(), $domain, $account, $alias;
public static function init() {
$loader = new Twig_Loader_Filesystem('tpl/page');
self::$twig = new Twig_Environment($loader, array(
'cache' => false
));
ob_start();
if (self::$logged) {
PageController::filterGet();
PageController::ldap();
if (!empty(self::$params['page'])) {
switch(self::$params['page']) {
case 'logout':
PageController::logout();
break;
case 'help':
PageController::help();
break;
}
} else {
PageController::choosePage();
}
} else {
PageController::login();
}
ob_end_flush();
}
private static function filterGet() {
$allowed_params = array('_all', '_add');
$static_pages = array('logout', 'help');
self::$params['page'] = !empty($_GET['page']) && in_array($_GET['page'], $static_pages) ? $_GET['page'] : NULL;
if (!empty($_GET['domain']) && in_array($_GET['domain'], $allowed_params)) { self::$params['domain'] = $_GET['domain']; }
if (!empty($_GET['account']) && in_array($_GET['account'], $allowed_params)) { self::$params['account'] = $_GET['account']; }
if (!empty($_GET['alias']) && in_array($_GET['alias'], $allowed_params)) { self::$params['alias'] = $_GET['alias']; }
self::$params = array_merge(filter_input_array(INPUT_GET, array(
'domain' => FILTER_SANITIZE_URL
,'account' => FILTER_SANITIZE_EMAIL
,'alias' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH)
), true)
, self::$params);
unset($_GET);
//die(var_dump(self::$params));
}
private static function ldap() {
// Get content from LDAP
try {
if (!empty(self::$params['domain']) && self::$params['domain'] != '_all' && self::$params['domain'] != '_add') {
self::$domain = new LdapDomain(self::$server, self::$params['domain']);
if (!empty(self::$params['account']) && self::$params['account'] != '_all' && self::$params['account'] != '_add') {
self::$account = new LdapAccount(self::$domain, self::$params['account']);
}
if (!empty(self::$params['alias']) && self::$params['alias'] != '_all' && self::$params['alias'] != '_add') {
self::$alias = new LdapAlias(self::$domain, self::$params['alias']);
}
}
} catch (Exception $e) {
self::$alerts[] = array('type' => 2, 'message' => $e->getMessage());
}
}
private static function login() {
print self::$twig->render('login.html', array(
'page_name' => self::$config['global']['name'].' - Login'
,'alerts' => self::$alerts
,'logout' => false
));
}
private static function logout() {
session_unset('EVOADMIN_SESS');
session_destroy();
print self::$twig->render('login.html', array(
'page_name' => self::$config['global']['name'].' - Login'
,'alerts' => self::$alerts
,'logout' => true
));
}
private static function help() {
print self::$twig->render('help.html', array(
'page_name' => self::$config['global']['name']
,'alerts' => self::$alerts
,'login' => self::$server->getLogin()
,'isSuperAdmin' => self::$server->isSuperAdmin()
,'notif_mail' => self::$config['global']['mail']
));
}
private static function choosePage() {
if (empty(self::$params['domain'])) {
self::$params['domain'] = '_all';
}
if (self::$params['domain'] == '_all') {
PageController::listDomains();
} else if (self::$params['domain'] == '_add') {
PageController::addDomain();
} else {
if (empty(self::$params['account']) && empty(self::$params['alias'])) { self::$params['account'] = '_all'; }
if (!empty(self::$params['account'])) {
if (self::$params['account'] == '_all') {
PageController::listAccounts();
} else {
PageController::Account();
}
} else if (!empty(self::$params['alias']) && empty(self::$params['account'])) {
if (self::$params['alias'] == '_all') {
PageController::listAlias();
} else {
PageController::Alias();
}
}
}
}
private static function addDomain() {
if (self::needSuperAdmin("Vous n'avez pas le droit d'ajouter un domaine !")) {
print self::$twig->render('add_domain.html', array(
'page_name' => self::$config['global']['name']
,'alerts' => self::$alerts
,'login' => self::$server->getLogin()
,'isSuperAdmin' => self::$server->isSuperAdmin()
));
}
}
private static function listDomains() {
print self::$twig->render('list_domain.html', array(
'page_name' => self::$config['global']['name']
,'alerts' => self::$alerts
,'login' => self::$server->getLogin()
,'isSuperAdmin' => self::$server->isSuperAdmin()
,'domains' => self::$server->getDomains()
));
}
private static function listAccounts() {
print self::$twig->render('list_account.html', array(
'page_name' => self::$config['global']['name']
,'alerts' => self::$alerts
,'login' => self::$server->getLogin()
,'isSuperAdmin' => self::$server->isSuperAdmin()
,'domain' => self::$domain->getName()
,'active' => self::$domain->isActive()
,'accounts' => self::$domain->getAccounts()
,'view' => 'account'
));
}
private static function listAlias() {
print self::$twig->render('list_alias.html', array(
'page_name' => self::$config['global']['name']
,'alerts' => self::$alerts
,'login' => self::$server->getLogin()
,'isSuperAdmin' => self::$server->isSuperAdmin()
,'domain' => self::$domain->getName()
,'active' => self::$domain->isActive()
,'aliases' => self::$domain->getAlias()
,'view' => 'alias'
));
}
private static function Account() {
print self::$twig->render('account.html', array(
'page_name' => self::$config['global']['name']
,'alerts' => self::$alerts
,'login' => self::$server->getLogin()
,'isSuperAdmin' => self::$server->isSuperAdmin()
,'domain' => self::$domain->getName()
,'uid' => !empty(self::$account) ? self::$account->getUid() : NULL
,'name' => !empty(self::$account) ? self::$account->getName() : NULL
,'aliases' => !empty(self::$account) ? self::$account->getAliases() : array()
,'maildrops' => !empty(self::$account) ? self::$account->getRedirections() : array()
,'active' => !empty(self::$account) ? self::$account->isActive() : true
,'admin' => !empty(self::$account) ? self::$account->isAdmin() : false
,'courier' => !empty(self::$account) ? self::$account->isCourier() : true
,'webmail' => !empty(self::$account) ? self::$account->isWebmail() : true
,'authsmtp' => !empty(self::$account) ? self::$account->isAuthSmtp() : true
));
}
private static function Alias() {
print self::$twig->render('alias.html', array(
'page_name' => self::$config['global']['name']
,'alerts' => self::$alerts
,'login' => self::$server->getLogin()
,'isSuperAdmin' => self::$server->isSuperAdmin()
,'domain' => self::$domain->getName()
,'name' => !empty(self::$alias) ? self::$alias->getName() : NULL
,'active' => !empty(self::$alias) ? self::$alias->isActive() : true
,'aliases' => !empty(self::$alias) ? self::$alias->getAliases() : NULL
,'maildrops' => !empty(self::$alias) ? self::$alias->getRedirections() : NULL
));
}
}

View File

@ -1,28 +0,0 @@
<?php
session_name('EVOADMIN_SESS');
session_start();
if (empty($_SESSION['login'])) {
header("location: auth.php\n\n");
exit(0);
} else {
try {
$server = new LdapServer($_SESSION['login'], $config['ldap']);
if (!empty($_GET['domain'])) {
$domain = htmlentities(strip_tags($_GET['domain']),ENT_NOQUOTES);
$domain = new LdapDomain($server, $domain);
if (!empty($_GET['account'])) {
$account = htmlentities(strip_tags($_GET['account']),ENT_NOQUOTES);
$account = new LdapAccount($domain, $account);
}
if (!empty($_GET['alias'])) {
$alias = htmlentities(strip_tags($_GET['alias']),ENT_NOQUOTES);
$alias = new LdapAlias($domain, $alias);
}
}
} catch (Exception $e) {
print '<div class="alert alert-danger" role="alert">'.$e->getMessage().'</div>';
exit(1);
}
}

View File

@ -1,5 +1,7 @@
<?php
require_once 'Twig/autoload.php';
class MailNotify {
private static $twig, $adminmail;

View File

@ -1,22 +0,0 @@
<?php
spl_autoload_register(function ($class) {
$class = strtolower($class);
if (file_exists("lib/class.$class.php")) {
require_once("lib/class.$class.php");
}
});
require_once 'Twig/autoload.php';
$config = parse_ini_file('../config/config.ini', true);
Logger::configure($config['global']['log_level']);
MailNotify::configure($config['global']);
$loader = new Twig_Loader_Filesystem('tpl/page');
$twig = new Twig_Environment($loader, array(
'cache' => false
));
$alerts = array();

View File

@ -1,33 +0,0 @@
<?php
// Load config and autoload class
require_once("lib/config.php");
// Force authentication on this page
require_once("lib/auth.php");
if (!empty($_POST['domain'])) {
$domain = htmlentities(strip_tags($_POST['domain']),ENT_NOQUOTES);
$alerts[] = array('type' => 1, 'message' => "Voulez vous vraiment supprimer le domaine $domain ?");
$alerts[] = array('type' => 1, 'message' => "<form name=\"del\" method=\"post\" action=\"superadmin.php\"><button type=\"submit\" name=\"delete\" value=\"$domain\">Confirmer</button> / <a href=\"superadmin.php\">Annuler</a></form>");
}
if (!empty($_POST['delete'])) {
$domain = htmlentities(strip_tags($_POST['delete']),ENT_NOQUOTES);
$alerts[] = array('type' => 1, 'message' => "Suppression du domaine $domain ...");
try {
$server->delDomain($domain);
$alerts[] = array('type' => 0, 'message' => 'Suppression effectué.');
} catch (Exception $e_ad) {
$alerts[] = array('type' => 2, 'message' => $e_ad->getMessage());
}
}
print $twig->render('list_domain.html', array(
'page_name' => $config['global']['name']
,'alerts' => $alerts
,'login' => $server->getLogin()
,'isSuperAdmin' => $server->isSuperAdmin()
,'domains' => $server->getDomains()
));

View File

@ -8,16 +8,21 @@
<h2>{% if uid is null %}Ajout d'un compte{% else %}Modification du compte {{ uid }}{% endif %}</h2>
<form name="add" action="compte.php?domain={{ domain }}{% if uid is not null %}&account={{ uid }}{% endif %}" method="post" class="form-horizontal">
<form action="/?domain={{ domain }}&account={% if uid is not null %}{{ uid }}{% else %}_all{% endif %}" method="post" class="form-horizontal">
<input type="hidden" name="domain" value="{{ domain }}"/>
<hr><div class="alert alert-info" role="alert">Remplissez lez champs, ceux contenant [*] sont obligatoires.</div>
{% if uid is null %}
<input type="hidden" name="add" value="account"/>
<div class="form-group">
<label for="uid" class="col-sm-3 control-label">Login [*] :</label>
<div class="col-sm-7"><input type="text" name="uid" class="form-control"/></div>
<div class="col-sm-2 control-label">@{{ domain }}</div>
</div>
{% else %}
<input type="hidden" name="update" value="account"/>
<input type="hidden" name="account" value="{{ uid }}"/>
{% endif %}
<div class="form-group">
@ -28,13 +33,13 @@
<div class="form-group">
<label for="pass1" class="col-sm-3 control-label">Mot de passe [*] :</label>
<div class="col-sm-7"><input type="password" name="pass1" class="form-control" /></div>
<div class="col-sm-7"><input type="password" name="password[]" class="form-control" /></div>
<div class="col-sm-2 control-label"></div>
</div>
<div class="form-group">
<label for="pass2" class="col-sm-3 control-label">Confirmation du mot de passe [*] :</label>
<div class="col-sm-7"><input type="password" name="pass2" class="form-control" /></div>
<div class="col-sm-7"><input type="password" name="password[]" class="form-control" /></div>
<div class="col-sm-2 control-label"></div>
</div>

View File

@ -6,11 +6,12 @@
<div class="container">
{% include 'notif.html' %}
<h2>Ajout d'un domaine</h2>
<form name="add" action="domaine.php" method="post" class="form-horizontal">
<form action="/?domain=_add" method="post" class="form-horizontal">
<input type="hidden" name="add" value="domain"/>
<hr><div class="alert alert-info" role="alert">Remplissez lez champs, ceux contenant [*] sont obligatoires.</div>
<div class="form-group">
<label for="domain" class="col-sm-3 control-label">Domaine [*] :</label>
<div class="col-sm-9"><input type="text" name="domain" class="form-control" /></div>
<div class="col-sm-9"><input type="text" name="cn" class="form-control" /></div>
</div>
<div class="form-group">
<label for="isactive" class="col-sm-3 control-label">Activation globale :</label>

View File

@ -8,16 +8,21 @@
<h2>{% if name is null %}Ajout d'un alias{% else %}Modification de l'alias {{ name }}{% endif %}</h2>
<form name="add" action="alias.php?domain={{ domain }}{% if name is not null %}&alias={{ name }}{% endif %}" method="post" class="form-horizontal">
<form action="/?domain={{ domain }}&alias={% if uid is not null %}{{ uid }}{% else %}_all{% endif %}" method="post" class="form-horizontal">
<input type="hidden" name="domain" value="{{ domain }}"/>
<hr><div class="alert alert-info" role="alert">Remplissez lez champs, ceux contenant [*] sont obligatoires.</div>
{% if name is null %}
<input type="hidden" name="add" value="alias"/>
<div class="form-group">
<label for="cn" class="col-sm-3 control-label">Nom (unique) de l'alias [*] :</label>
<div class="col-sm-7"><input type="text" name="cn" class="form-control" /></div>
<div class="col-sm-2 control-label"></div>
</div>
{% else %}
<input type="hidden" name="update" value="alias"/>
<input type="hidden" name="alias" value="{{ name }}"/>
{% endif %}
{% for alias in aliases %}

View File

@ -7,7 +7,9 @@
{% include 'notif.html' %}
<div class="text-center">
<form name="update" method="post" action="admin.php?domain={{ domain }}">
<form method="post" action="/?domain={{ domain }}">
<input type="hidden" name="update" value="domain"/>
<input type="hidden" name="domain" value="{{ domain }}"/>
{% if isSuperAdmin %}
{% if active %}
<button type="submit" name="isactive" value="FALSE" class="btn btn-primary">Désactiver le domaine</button>&nbsp;&nbsp;&nbsp;
@ -15,21 +17,12 @@
<button type="submit" name="isactive" value="TRUE" class="btn btn-primary">Activer le domaine</button>&nbsp;&nbsp;&nbsp;
{% endif %}
{% endif %}
<a href="compte.php?domain={{ domain }}"><button type="button" class="btn btn-primary">Ajouter un nouveau compte</button></a>&nbsp;&nbsp;&nbsp;
<a href="alias.php?domain={{ domain }}"><button type="button" class="btn btn-primary">Ajouter un nouvel alias/groupe de diffusion</button></a>
<a href="?domain={{ domain }}&account=_all"><button type="button" class="btn btn-primary">Liste des comptes</button></a>&nbsp;&nbsp;&nbsp;
<a href="/?domain={{ domain }}&account=_add"><button type="button" class="btn btn-primary">Ajouter un nouveau compte</button></a>&nbsp;&nbsp;&nbsp;
<a href="?domain={{ domain }}&alias=_all"><button type="button" class="btn btn-primary">Liste des alias/groupe de diffusion</button></a>&nbsp;&nbsp;&nbsp;
<a href="/?domain={{ domain }}&alias=_add"><button type="button" class="btn btn-primary">Ajouter un nouvel alias/groupe de diffusion</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
<hr>
<form class='center' action='admin.php' method='GET' name='listing'>
<div class="form-group">
<input type="hidden" name="domain" value="{{ domain }}"/>
<select class="form-control" name='viewonly' onchange="document.listing.submit()">
<option value='1' {% if view == 'account' %}selected="selected"{% endif %}>Liste des comptes</option>
<option value='2' {% if view == 'alias' %}selected="selected"{% endif %}>Liste des alias/groupe de diffusion</option>
</select>
</div>
</form>
{% block list %}{% endblock %}

View File

@ -4,7 +4,8 @@
<h2>Liste des comptes :</h2><hr>
<form name="del" method="post" action="admin.php?domain={{ domain }}">
<form method="post" action="/?domain={{ domain }}&account=_all">
<input type="hidden" name="delete" value="account"/>
<table class="table table-striped table-condensed">
<thead>
<tr>
@ -22,7 +23,7 @@
{% for account in accounts %}
<tr>
<td style="text-align:left;"><a href="compte.php?domain={{ domain }}&account={{ account.uid }}">{{ account.name }} <{{account.uid }}></a></td>
<td style="text-align:left;"><a href="/?domain={{ domain }}&account={{ account.uid }}">{{ account.name }} <{{account.uid }}></a></td>
{% if account.active %}
<td><span class="glyphicon glyphicon-ok"></span></td>
{% else %}
@ -50,7 +51,7 @@
{% endif %}
<td>{{ account.quota }}</td>
<td>
<button type="submit" name="account" value="{{ account.uid }}"><span class="glyphicon glyphicon-trash"></span></button>
<button type="submit" name="uid" value="{{ account.uid }}"><span class="glyphicon glyphicon-trash"></span></button>
</td>
</tr>
{% endfor %}

View File

@ -4,7 +4,8 @@
<h2>Liste des alias/groupe de diffusion :</h2><hr>
<form name="del" method="post" action="admin.php?domain={{ domain }}&viewonly=2">
<form method="post" action="?domain={{ domain }}&alias=_all">
<input type="hidden" name="delete" value="alias"/>
<table class="table table-striped table-condensed">
<thead>
<tr>
@ -16,13 +17,13 @@
<tbody>
{% for alias in aliases %}
<tr><td style="text-align:left;"><a href="alias.php?domain={{ domain }}&alias={{ alias.name }}">{{ alias.name }}</a></td>
<tr><td style="text-align:left;"><a href="/?domain={{ domain }}&alias={{ alias.name }}">{{ alias.name }}</a></td>
{% if alias.active %}
<td><span class="glyphicon glyphicon-ok"></span></td>
{% else %}
<td><span class="glyphicon glyphicon-remove"></span></td>
{% endif %}
<td><button type="submit" name="alias" value="{{ alias.name }}"><span class="glyphicon glyphicon-trash"></span></button></td>
<td><button type="submit" name="cn" value="{{ alias.name }}"><span class="glyphicon glyphicon-trash"></span></button></td>
</tr>
{% endfor %}
</tbody></table></form>

View File

@ -7,7 +7,8 @@
{% include 'notif.html' %}
<h2>Liste des domaines administrables :</h2><hr>
<form name="del" method="post" action="superadmin.php">
<form method="post" action="/?domain=_all">
<input type="hidden" name="delete" value="domain"/>
<table class="table table-striped table-condensed">
<thead>
<tr>
@ -23,7 +24,7 @@
<tbody>
<?php
{% for domain in domains %}
<tr><td style="text-align:left;"><a href="admin.php?domain={{ domain.name }}">{{ domain.name }}</a></td>
<tr><td style="text-align:left;"><a href="/?domain={{ domain.name }}">{{ domain.name }}</a></td>
{% if domain.active %}
<td><span class="glyphicon glyphicon-ok"></span></td>
{% else %}
@ -33,7 +34,7 @@
<td><b>{{ domain.NbMailAccounts }}</b></td>
<td><b>{{ domain.NbMailAlias }}</b></td>
<td>{{ domain.getQuota }}</td>
<td><button type="submit" name="domain" value="{{ domain.name }}"><span class="glyphicon glyphicon-trash"></span></button></td>
<td><button type="submit" name="cn" value="{{ domain.name }}"><span class="glyphicon glyphicon-trash"></span></button></td>
</tr>
{% endfor %}
</tbody>

View File

@ -11,7 +11,7 @@
<div class="illustration">
<img src="assets/logo.png" class="img-responsive" alt="Responsive image">
</div>
<form method="POST" action="auth.php" method="post" name="auth">
<form method="POST" action="/" method="post" name="auth">
<div class="form-group has-feedback has-feedback-left">
<input type="text" name="login" class="form-control" placeholder="Utilisateur" autofocus="autofocus"/>
<i class="glyphicon glyphicon-user form-control-feedback"></i>

View File

@ -6,17 +6,17 @@
</a>
</div>
<ul class="nav navbar-nav">
<li><a href="superadmin.php">Accueil</a></li>
<li><a href="help.php">Aide</a></li>
<li><a href="/?domain=_all">Accueil</a></li>
<li><a href="/?page=help">Aide</a></li>
{% if isSuperAdmin %}
<li><a href="domaine.php">Ajout Domaine</a></li>
<li><a href="/?domain=_add">Ajout Domaine</a></li>
{% endif %}
<li><a href="auth.php">Déconnexion</a></li>
<li><a href="/?page=logout">Déconnexion</a></li>
</ul>
<p class="navbar-text navbar-right">
<em>{{ login }}</em>
{% if domain is not null %}
- Domaine : <a href="admin.php?domain={{ domain }}">{{ domain }}</a>
- Domaine : <a href="/?domain={{ domain }}">{{ domain }}</a>
{% endif %}
</p>
</div>