From e6edffd820b8b5e66496c8f652f138f27eedd3d2 Mon Sep 17 00:00:00 2001 From: Romain Dessort Date: Mon, 31 Aug 2015 15:17:10 +0200 Subject: [PATCH] Merge untracked code into evoadmin-web. --- bin/add_server.php | 41 ++++---- bin/init_cache.php | 39 +++---- bin/list_domains.php | 30 ++++-- conf/config.cluster1.php | 31 ++++++ conf/config.cluster2.php | 21 ++++ conf/config.php | 20 +--- evolibs/Form.php | 4 +- htdocs/common.php | 32 +++++- htdocs/img/evolix.gif | Bin 0 -> 170 bytes htdocs/img/gmail.gif | Bin 0 -> 112 bytes htdocs/index.php | 4 + inc/accounts.php | 66 ++++++------ inc/auth.php | 2 +- inc/ftpadmin.php | 4 +- inc/home.php | 16 +++ inc/webadmin-edit.php | 121 ++++++++++++++------- inc/webadmin-suppr.php | 198 ++++++++++++++++++++++++++++++++++ inc/webadmin.php | 15 ++- lib/bdd.php | 118 +++++++++++++-------- lib/domain.php | 29 +++++ scripts/bind-add-ng.sh | 210 +++++++++++++++++++++++++++++++++++++ scripts/vhost | 1 + scripts/vhost-default | 1 + scripts/web-add-cluster.sh | 25 +++-- scripts/web-add.sh | 4 +- tpl/header.tpl.php | 15 ++- tpl/home.tpl.php | 20 +++- tpl/webadmin.tpl.php | 53 +++++----- 28 files changed, 893 insertions(+), 227 deletions(-) create mode 100644 conf/config.cluster1.php create mode 100644 conf/config.cluster2.php create mode 100644 htdocs/img/evolix.gif create mode 100644 htdocs/img/gmail.gif create mode 100755 inc/webadmin-suppr.php create mode 100644 lib/domain.php create mode 100755 scripts/bind-add-ng.sh diff --git a/bin/add_server.php b/bin/add_server.php index f579b02..c1bc90e 100644 --- a/bin/add_server.php +++ b/bin/add_server.php @@ -1,20 +1,30 @@ +#!/usr/bin/php \n"; + exit(1); + } + $file = str_replace('%cluster_name%', $argv[1], $conf['cache']); + $server = $argv[2]; +} +else { + if ($argc != 2) { + echo "Usage: $argv[0] \n"; + exit(1); + } + $file = $conf['cache']; + $server = $argv[1]; +} + if (!file_exists($file)) { echo "$file doesn't exist\n"; @@ -22,13 +32,8 @@ if (!file_exists($file)) { } $bdd->open($file); - -$server = array("name" => $argv[1]); - $bdd->add_server(array("name" => "$server")); -exec('ssh -o "UserKnownHostsFile '.$conf['known_host'].'" '.$argv[1].' /bin/true'); +echo "$server added in $file\n"; -echo "$server added in cache\n"; exit(0); ?> - diff --git a/bin/init_cache.php b/bin/init_cache.php index 613ce0b..2c15389 100644 --- a/bin/init_cache.php +++ b/bin/init_cache.php @@ -1,28 +1,31 @@ +#!/usr/bin/php create($file); +$files = array(); +if (is_mcluster_mode()) { + foreach ($conf['clusters'] as $cluster) { + array_push($files, str_replace('%cluster_name%', $cluster, $conf['cache'])); + } +} else { - echo "$file is already created"; - exit(1); + array_push($files, $conf['cache']); } -foreach ($conf['servers'] as $server) { - echo "$server added in cache\n"; - $bdd->add_server(array("name" => "$server")); +foreach ($files as $file) { + + $bdd = new bdd(); + + if (!file_exists($file)) { + $bdd->create($file); + echo "$file created.\n"; + } + else { + echo "$file is already created.\n"; + continue; + } } -echo "Cache initialisé\n"; exit(0); ?> diff --git a/bin/list_domains.php b/bin/list_domains.php index 096fad4..e9a1624 100644 --- a/bin/list_domains.php +++ b/bin/list_domains.php @@ -1,23 +1,33 @@ +#!/usr/bin/php \n"; + exit(1); + } + $file = str_replace('%cluster_name%', $argv[1], $conf['cache']); +} +else { + if ($argc != 1) { + echo "Usage: $argv[0]\n"; + exit(1); + } + $file = $conf['cache']; +} if (!file_exists($file)) { echo "$file is not created\n"; exit(1); } +$bdd = new bdd(); $bdd->open($file); - $domains = $bdd->list_domains(); print_r($domains); diff --git a/conf/config.cluster1.php b/conf/config.cluster1.php new file mode 100644 index 0000000..4bc5ae4 --- /dev/null +++ b/conf/config.cluster1.php @@ -0,0 +1,31 @@ + + * @author Thomas Martin + * @author Sebastien Palma + * @version 1.0 + */ + +$clusterconf['noreplication'] = array('srv00'); +$clusterconf['postponedreplication'] = array('srv00', 'srv01', 'srv04'); +$clusterconf['immediatereplication'] = array('srv00', 'srv01'); +$clusterconf['postponedreplication_mode'] = array('3 fois/jour', '1 fois/jour', '1 fois/heure'); +// On specifie des serveurs pour certains modes de replication différés +//$clusterconf['1 fois/jour'] = array('srv03', 'srv01'); +$clusterconf['1 fois/heure'] = array('srv01', 'srv00'); + +/* opcodes + * type indice array mode + +noreplication 1 x +postponedrepl 2 x y m +immediaterepl 3 x y +*/ diff --git a/conf/config.cluster2.php b/conf/config.cluster2.php new file mode 100644 index 0000000..68dc63f --- /dev/null +++ b/conf/config.cluster2.php @@ -0,0 +1,21 @@ + + * @author Thomas Martin + * @author Sebastien Palma + * @version 1.0 + */ + +$clusterconf['noreplication'] = array('srv10'); +$clusterconf['postponedreplication'] = array('srv10', 'srv11'); +$clusterconf['immediatereplication'] = array('srv10', 'srv11'); +$clusterconf['postponedreplication_mode'] = array('3 fois/jour', '1 fois/jour', '1 fois/heure'); +$clusterconf['1 fois/heure'] = array('srv10', 'srv11'); diff --git a/conf/config.php b/conf/config.php index 0076cae..c4228c0 100644 --- a/conf/config.php +++ b/conf/config.php @@ -27,19 +27,7 @@ $oriconf['cache'] = '/home/evoadmin/www/cache.sqlite'; $localconf['known_host'] = '/home/evoadmin/www/known_host'; $oriconf['ftpadmin'] = TRUE; -/* cluster mode - * $oriconf['noreplication'] = array('www00'); - * $oriconf['postponedreplication'] = array('www00', 'www01'); - * $oriconf['immediatereplication'] = array('www00', 'www01'); - * $oriconf['postponedreplication_mode'] = array('3 fois/jour', '1 fois/jour', '1 fois/heure'); - */ - -/* Il est possible de définir pour chaque mode de - * postponedreplication_mode une liste de serveurs, - * qui seront utilisés à la place des serveurs du - * tableau postponedreplication. - * - * $localconf['1 fois/jour'] = array('www00', 'www01'); - * $localconf['1 fois/heure'] = array('www01', 'www00'); - */ - +$oriconf['noreplication'] = array('srv00.example.com', 'srv01.example.com', 'srv02.example.com'); +$oriconf['postponedreplication'] = array('srv00.example.com', 'srv01.example.com', 'srv02.example.com'); +$oriconf['immediatereplication'] = array('srv00.example.com', 'srv01.example.com'); +$oriconf['postponedreplication_mode'] = array('1 fois/jour', '3 fois/jour', '1 fois/jour'); diff --git a/evolibs/Form.php b/evolibs/Form.php index 8c3bd2c..6748031 100644 --- a/evolibs/Form.php +++ b/evolibs/Form.php @@ -373,7 +373,7 @@ class TextInputFormField extends FormField { protected $mandatory = NULL; protected $textsize = NULL; - public function __construct($label, $mandatory=TRUE, $textsize=array(20, 40)) { + public function __construct($label, $mandatory=TRUE, $textsize=array(20, 80)) { parent::__construct($label); $this->mandatory = $mandatory; $this->textsize = $textsize; @@ -422,7 +422,7 @@ class DateInputFormField extends TextInputFormField { if($set_error) $this->error = 'Format de date non valide'; return FALSE; } - $arr_date = split('/', $this->value); + $arr_date = explode('/', $this->value); if(!empty($this->value) && !checkdate($arr_date[1],$arr_date[0],$arr_date[2])) { if($set_error) $this->error = "La date saisie n'existe pas"; diff --git a/htdocs/common.php b/htdocs/common.php index 923d9f8..c59e84b 100644 --- a/htdocs/common.php +++ b/htdocs/common.php @@ -34,7 +34,7 @@ function http_redirect($path) { function findexts ($filename) { $filename = strtolower($filename) ; - $exts = split("[/\\.]", $filename) ; + $exts = explode("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; @@ -49,7 +49,7 @@ function is_superadmin() { } } -function sudoexec($cmd, &$output, &$return_var) { +function sudoexec($cmd, $output, $return_var) { global $conf; /* -H The -H (HOME) option sets the HOME environment variable to the @@ -60,6 +60,33 @@ function sudoexec($cmd, &$output, &$return_var) { exec($cmd, $output, $return_var); } +/** + * Return TRUE is Evoadmin is installed in cluster mode. + */ +function is_cluster_mode() { + global $conf; + return $conf['cluster']; +} + +/** + * Return TRUE is Evoadmin is installed in multi-cluster mode. + */ +function is_mcluster_mode() { + global $conf; + return is_cluster_mode() && array_key_exists('clusters', $conf) && is_array($conf['clusters']); +} + +/** + * Load config file for the specified cluster. + */ +function load_config_cluster($cluster) { + global $conf; + $configfile = '../conf/config.'.$cluster.'.php'; + test_exist($configfile); + require_once($configfile); + $conf = array_merge($conf, $clusterconf); +} + /** * Includes */ @@ -84,4 +111,3 @@ if (!(ini_set('include_path', ini_get('include_path')))) { test_exist('/etc/shadow'); $conf = array_merge($oriconf, $localconf); } - diff --git a/htdocs/img/evolix.gif b/htdocs/img/evolix.gif new file mode 100644 index 0000000000000000000000000000000000000000..7e5a2c09d0e04d2206fea9fe4a40da12c8a19b4c GIT binary patch literal 170 zcmZ?wbhEHb6krfwc+AU?yZ1rSfk)+s9@iXwvg^tD1J6$%e12-*s}uWPo!tHQ_|Eso zwtqab_0y66FrfHP(77lzu_QG`p**uBL&4qCH-JI$CkrDN13!Zf0}y}=W?*sJaME-2 z-qIJmO*am+^ff2W>Mfg_E)|ykaoZKo6}+c?IJ%ZEZ+((5;ZKN~E7Mb3Qlx!^qTju4`EWx*8SPh8G+?cvz>ph^rjrIl}qjkPDyM(Pv8+ M)I>;ku`pNz04@J4D*ylh literal 0 HcmV?d00001 diff --git a/htdocs/index.php b/htdocs/index.php index 4e8c10d..2f8af52 100755 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -52,6 +52,10 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) { include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; +} elseif (preg_match('#^/webadmin/suppr/(.*)/?$#', $uri, $params)) { + + include_once EVOADMIN_BASE . '../inc/webadmin-suppr.php'; + } elseif (is_superadmin() && preg_match('#^/accounts/?#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/accounts.php'; diff --git a/inc/accounts.php b/inc/accounts.php index bb224a1..683258a 100644 --- a/inc/accounts.php +++ b/inc/accounts.php @@ -15,41 +15,20 @@ require_once EVOADMIN_BASE . '../evolibs/Form.php'; require_once EVOADMIN_BASE . '../lib/bdd.php'; +require_once EVOADMIN_BASE . '../lib/domain.php'; global $conf; -$servers=$conf['servers']; -$servers_slave=$conf['servers']; - -$servers_slave[]='Aucun'; -$cache=$conf['cache']; - - -function domain_add($name, $IP, $with_mxs, $gmail=false) { - - $exec_cmd = 'bind-add-ng.sh'; - - if ( $with_mxs == true ) { - /* Quai13 specific: use Gmail MXs if wanted */ - if ( $gmail ) { - $exec_cmd .= ' -m ASPMX.L.GOOGLE.com.,10'; - $exec_cmd .= ' -m ALT1.ASPMX.L.GOOGLE.com.,20'; - $exec_cmd .= ' -m ALT2.ASPMX.L.GOOGLE.com.,20'; - $exec_cmd .= ' -m ASPMX2.GOOGLEMAIL.com.,30'; - $exec_cmd .= ' -m ASPMX3.GOOGLEMAIL.com.,30'; - } - else { - $exec_cmd .= ' -m mail,10'; - $exec_cmd .= ' -m backup.quai13.net.,20'; - } - mail($conf['techmail'], '[TAF] Ajouter '.$name.' sur le serveur de mail', wordwrap('Ajouter le domaine '.$name.' à la directive relay_domains dans le fichier /etc/postfix/main.cf sur le serveur mail, pour mettre en place le MX secondaire du domaine.', 70)); +if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); } - - $exec_cmd .= " -a $IP $name"; - - //echo $exec_cmd."\n"; - sudoexec($exec_cmd, $exec_output, $exec_return); - return array($exec_cmd, $exec_return, $exec_output); + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + load_config_cluster($_SESSION['cluster']); +} +else { + $cache = $conf['cache']; } function web_add($form, $admin_mail) { @@ -77,7 +56,22 @@ function web_add($form, $admin_mail) { $form->getField('username')->getValue(), $form->getField('domain')->getValue()); - sudoexec($exec_cmd, $exec_output, $exec_return); + //domain_add($form, $_SERVER['SERVER_ADDR'], true); + //sudoexec($exec_cmd, $exec_output, $exec_return); + + /* Gestion des noms de domaines supplementaires */ + if ( $form->getField('domain_alias')->getValue() ) { + $domain_alias = preg_split('/,/', $form->getField('domain_alias')->getValue()); + foreach ( $domain_alias as $domain ) { + $exec_cmd = 'web-add.sh add-alias '.$form->getField('domain')->getValue().' '; + $domain = trim($domain); + $exec_cmd .= $domain.' '.$master.' '.$slave; + sudoexec($exec_cmd, $exec_output, $exec_return); + //domain_add($form, gethostbyname($master), false); + } + $exec_return |= $exec_return2; // $exec_return == 0 if $exec_return == 0 && $exec_return2 == 0 + array_push($exec_output, $exec_output2); + } return array($exec_cmd, $exec_return, $exec_output); } @@ -205,6 +199,10 @@ function web_add_cluster($form, $admin_mail) { $account['name'] = $form->getField('username')->getValue(); $account['domain'] = $form->getField('domain')->getValue(); + if ($form->getField('use_gmail_mxs')->getValue()) + $account['mail'] = 'gmail'; + else + $account['mail'] = 'evolix'; $bdd->add_account($account); @@ -242,7 +240,7 @@ function web_add_cluster($form, $admin_mail) { /* Construction du formulaire d'ajout */ $form = new FormPage("Ajout d'un compte web", FALSE); -$form->addField('username', new TextInputFormField("Nom d'utilisateur", TRUE)); +$form->addField('username', new TextInputFormField("Nom d'utilisateur", TRUE, array(20,16))); $form->addField('domain', new TextInputFormField("Nom de domaine", TRUE)); $form->addField('domain_alias', new TextInputFormField("Alias (séparés par une virgule)", FALSE)); $form->addField('password_random', @@ -255,7 +253,7 @@ $form->addField('mysql_db', FALSE)); $form->getField('mysql_db')->setValue(TRUE); $form->addField('mysql_dbname', - new TextInputFormField("Nom de la base MySQL", FALSE)); + new TextInputFormField("Nom de la base MySQL", FALSE, array(20,16))); //$form->getField('mysql_dbname')->setDisabled(); $form->addField('mysql_password_random', new CheckboxInputFormField("Mot de passe MySQL aléatoire ?", diff --git a/inc/auth.php b/inc/auth.php index 80a6bb9..b72d5d1 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -30,7 +30,7 @@ if ((empty($_GET['form']) || $_GET['form']!=1) && !empty($_POST)) { $user = posix_getpwnam($username); // On nettoie le nom complet - $gecos = split(',',$user['gecos']); + $gecos = explode(',',$user['gecos']); $user['gecos'] = $gecos[0]; $_SESSION['user_id'] = $user['uid']; $_SESSION['user_gid'] = $user['gid']; diff --git a/inc/ftpadmin.php b/inc/ftpadmin.php index 7566d84..bf87b40 100644 --- a/inc/ftpadmin.php +++ b/inc/ftpadmin.php @@ -182,14 +182,14 @@ if ($action=="add") { foreach ($account_list as $account) { - $infos = split(':', $account); + $infos = explode(':', $account); if (!empty($infos[0])) { $table[$num_line]['owner'] = $infos[0]; $table[$num_line]['name'] = $infos[1]; - $path = split("/", $infos[2]); + $path = explode("/", $infos[2]); $rel_path=''; foreach($path as $id => $folder) { if ($id>2) $rel_path.='/'.$folder; diff --git a/inc/home.php b/inc/home.php index ed5b12a..cd29ed6 100644 --- a/inc/home.php +++ b/inc/home.php @@ -13,6 +13,22 @@ * @version 1.0 */ +require_once EVOADMIN_BASE . '../evolibs/Form.php'; + +if (is_mcluster_mode()) { + $form = new FormPage("Sélection du cluster", FALSE); + $form->addField('cluster_name', new SelectFormField('cluster', FALSE, $conf['clusters'])); + + if (!empty($_POST)) { + $form->isCurrentPage(TRUE); + $form->initFields(); + + if ($form->verify(TRUE)) { + $_SESSION['cluster'] = $form->getField('cluster_name')->getReadableValue(); + } + } +} + include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; include_once EVOADMIN_BASE . '../tpl/home.tpl.php'; diff --git a/inc/webadmin-edit.php b/inc/webadmin-edit.php index f5f7f46..a3308a6 100644 --- a/inc/webadmin-edit.php +++ b/inc/webadmin-edit.php @@ -14,6 +14,7 @@ */ require_once EVOADMIN_BASE . '../lib/bdd.php'; +require_once EVOADMIN_BASE . '../lib/domain.php'; global $conf; @@ -31,28 +32,55 @@ if (isset($_GET['del']) ) { $serveralias = array ( - 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_SCRIPT_URL'])), + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), 'alias' => $alias ); if ($conf['cluster']) { - $cache = $conf['cache']; + if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); + } + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + } + else { + $cache = $conf['cache']; + } $bdd = new bdd(); $bdd->open($cache); - if (! $bdd->del_serveralias($serveralias)) + $account_name=$serveralias['domain']; + $account = $bdd->get_account($account_name); + + if (sizeof($account) == 0) + die("Anomalie... Contactez votre administrateur."); + + $master = $bdd->get_server_from_roleid($account['id_master']); + $slave = $bdd->get_server_from_roleid($account['id_slave']); + + /* web-add-cluster addalias */ + $exec_cmd = 'web-add-cluster.sh del-alias '.$serveralias['domain'].' '.$serveralias['alias'].' '.$master.' '.$slave; + sudoexec($exec_cmd, $exec_output, $exec_return); + + if ($exec_return == 0) { + if (! $bdd->del_serveralias($serveralias)) + print "

La suppression a échouée. Veuillez contacter votre administrateur.

"; + printf ('

Alias %s est supprimé.

', $serveralias['alias']); + } else print "

La suppression a échouée. Veuillez contacter votre administrateur.

"; + } - printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); print ""; } else if ( ! isset($_GET['modif']) ) { print "
"; print "

Confirmez vous la suppression de $alias ?

"; - printf ('

Confirmer la suppression

', $_SERVER['REDIRECT_SCRIPT_URL'], $alias); - printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); + printf ('

Confirmer la suppression

', $_SERVER['REDIRECT_URL'], $alias); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); print "
"; } @@ -75,57 +103,72 @@ if (isset($_GET['del']) ) { if ($form->verify(TRUE)) { if ($conf['cluster']) { - $cache = $conf['cache']; + if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); + } + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + } + else { + $cache = $conf['cache']; + } $bdd = new bdd(); $bdd->open($cache); $serveralias = array ( - 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_SCRIPT_URL'])), + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), 'alias' => $form->getField('domain_alias')->getValue(), ); $account_name=$serveralias['domain']; $account = $bdd->get_account($account_name); + if (sizeof($account) == 0) die("Anomalie... Contactez votre administrateur."); $master = $bdd->get_server_from_roleid($account['id_master']); $slave = $bdd->get_server_from_roleid($account['id_slave']); - /* web-add-cluster addalias */ - $exec_cmd = 'web-add-cluster.sh add-alias '.$serveralias['domain'].' '.$serveralias['alias'].' '.$master.' '.$slave; - sudoexec($exec_cmd, $exec_output, $exec_return); - /* bind add */ - $exec_cmd = 'bind-add-ng.sh'; - $exec_cmd .= ' -a '. gethostbyname($master) .' '.$serveralias['alias']; - sudoexec($exec_cmd, $exec_output, $exec_return2); - - $exec_return |= $exec_return2; + if ( $bdd->is_serveralias( $account_name, $serveralias['alias'] ) == 0 ) { - if ($exec_return == 0) { - /* Ajout BDD */ - $bdd->add_serveralias($serveralias); + /* web-add-cluster addalias */ + $exec_cmd = 'web-add-cluster.sh add-alias '.$serveralias['domain'].' '.$serveralias['alias'].' '.$master.' '.$slave; + sudoexec($exec_cmd, $exec_output, $exec_return); - domain_add($serveralias['alias'], gethostbyname($master) , false); - # Si le compte en question est en replication temps - # reel, il faut faire un restart manuel de lsyncd - # pour prendre en compte le nouveau domaine. - if ($account['replication'] == "realtime") { - mail('tech@evolix.fr', "[TAF] Redemarrer lsyncd sur $master", wordwrap('killer tous les processus lsyncd lancé par vmail pour le compte '.$account['name'].' et les relancer (cf. la ligne correspondante à ce compte dans la crontab de vmail).\n', 70)); + + if ($exec_return == 0) { + /* Ajout BDD */ + $bdd->add_serveralias($serveralias); + + domain_add($serveralias['alias'], gethostbyname($master) , false); + + # Si le compte en question est en replication temps + # reel, il faut faire un restart manuel de lsyncd + # pour prendre en compte le nouveau domaine. + if ($account['replication'] == "realtime") { + mail('tech@evolix.fr', "[TAF] Redemarrer lsyncd sur $master", wordwrap('killer tous les processus lsyncd lancé par vmail pour le compte '.$account['name'].' et les relancer (cf. la ligne correspondante à ce compte dans la crontab de vmail).\n', 70)); + } + + print "
"; + printf ('

L\'alias %s du domaine %s a bien été créé

', $serveralias['alias'], $serveralias['domain']); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); + print "
"; + } else { + print "
"; + printf ('

Echec dans la creation de l\'alias %s du domaine %s

', $serveralias['alias'], $serveralias['domain']); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); + print "
"; } - - print "
"; - printf ('

L\'alias %s du domaine %s a bien été créé

', $serveralias['alias'], $serveralias['domain']); - printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); - print "
"; } else { print "
"; - printf ('

Echec dans la creation de l\'alias %s du domaine %s

', $serveralias['alias'], $serveralias['domain']); - printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); + printf ('

Alias %s du domaine %s deja existant !

', $serveralias['alias'], $serveralias['domain']); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); print "
"; + } } } @@ -150,8 +193,16 @@ if (isset($_GET['del']) ) { $alias_list = array(); if ($conf['cluster']) { - - $cache = $conf['cache']; + if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); + } + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + } + else { + $cache = $conf['cache']; + } $alias_list = array(); diff --git a/inc/webadmin-suppr.php b/inc/webadmin-suppr.php new file mode 100755 index 0000000..4854b62 --- /dev/null +++ b/inc/webadmin-suppr.php @@ -0,0 +1,198 @@ + + * @author Thomas Martin + * @author Sebastien Palma + * @version 1.0 + */ + +require_once EVOADMIN_BASE . '../lib/bdd.php'; +require_once EVOADMIN_BASE . '../lib/domain.php'; + +global $conf; + +if (isset($_GET['del']) ) { + + include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; + + $alias = htmlspecialchars($_GET['del']); + + if (isset($_GET['modif']) && ($_GET['modif'] == 'yes')) { + + print "
"; + print "

Suppression de $alias...

"; + + + $serveralias = array ( + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_SCRIPT_URL'])), + 'alias' => $alias + ); + + if ($conf['cluster']) { + + if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); + } + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + } + else { + $cache = $conf['cache']; + } + $bdd = new bdd(); + $bdd->open($cache); + + $account_name=$serveralias['domain']; + $account = $bdd->get_account($account_name); + + if (sizeof($account) == 0) + die("Anomalie... Contactez votre administrateur."); + + $master = $bdd->get_server_from_roleid($account['id_master']); + $slave = $bdd->get_server_from_roleid($account['id_slave']); + + /* web-add-cluster addalias */ + $exec_cmd = 'web-add-cluster.sh del-alias '.$serveralias['domain'].' '.$serveralias['alias'].' '.$master.' '.$slave; + sudoexec($exec_cmd, $exec_output, $exec_return); + + if ($exec_return == 0) { + if (! $bdd->del_serveralias($serveralias)) + print "

La suppression a échouée. Veuillez contacter votre administrateur.

"; + printf ('

Alias %s est supprimé.

', $serveralias['alias']); + } else + print "

La suppression a échouée. Veuillez contacter votre administrateur.

"; + + } + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); + print "
"; + + } else if ( ! isset($_GET['modif']) ) { + + print "
"; + print "

Confirmez vous la suppression de $alias ?

"; + printf ('

Confirmer la suppression

', $_SERVER['REDIRECT_SCRIPT_URL'], $alias); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); + print "
"; + } + + + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; + +} else if (isset($_GET['add']) ) { + + require_once EVOADMIN_BASE . '../evolibs/Form.php'; + + include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; + + $form = new FormPage("Ajout d'un alias", FALSE); + $form->addField('domain_alias', new TextInputFormField("Alias", FALSE)); + + if (!empty($_POST)) { + $form->isCurrentPage(TRUE); + $form->initFields(); + + if ($form->verify(TRUE)) { + if ($conf['cluster']) { + $cache = $conf['cache']; + $bdd = new bdd(); + $bdd->open($cache); + + $serveralias = array ( + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_SCRIPT_URL'])), + 'alias' => $form->getField('domain_alias')->getValue(), + ); + + $account_name=$serveralias['domain']; + $account = $bdd->get_account($account_name); + + if (sizeof($account) == 0) + die("Anomalie... Contactez votre administrateur."); + + $master = $bdd->get_server_from_roleid($account['id_master']); + $slave = $bdd->get_server_from_roleid($account['id_slave']); + + + if ( $bdd->is_serveralias( $account_name, $serveralias['alias'] ) == 0 ) { + + /* web-add-cluster addalias */ + $exec_cmd = 'web-add-cluster.sh add-alias '.$serveralias['domain'].' '.$serveralias['alias'].' '.$master.' '.$slave; + sudoexec($exec_cmd, $exec_output, $exec_return); + + + + if ($exec_return == 0) { + /* Ajout BDD */ + $bdd->add_serveralias($serveralias); + + domain_add($serveralias['alias'], gethostbyname($master) , false); + + print "
"; + printf ('

L\'alias %s du domaine %s a bien été créé

', $serveralias['alias'], $serveralias['domain']); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); + print "
"; + } else { + print "
"; + printf ('

Echec dans la creation de l\'alias %s du domaine %s

', $serveralias['alias'], $serveralias['domain']); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); + print "
"; + } + } else { + print "
"; + printf ('

Alias %s du domaine %s deja existant !

', $serveralias['alias'], $serveralias['domain']); + printf ('

Retour à la liste des alias

', $_SERVER['REDIRECT_SCRIPT_URL']); + print "
"; + + } + } + } + } else { + + print "
"; + print "
"; + print " Ajout d'un serveralias"; + print $form; + print "

"; + print "
"; + print "
"; + + } + + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; + + +} else { + + $domain = $params[1]; + $alias_list = array(); + + if ($conf['cluster']) { + + $cache = $conf['cache']; + + $alias_list = array(); + + /* parcours de la table Serveralias */ + $bdd = new bdd(); + $bdd->open($cache); + + $alias_list = $bdd->list_serveralias($domain); + } + + include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/webadmin-edit.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; + +} + +?> diff --git a/inc/webadmin.php b/inc/webadmin.php index a2d9bfb..bc0794d 100644 --- a/inc/webadmin.php +++ b/inc/webadmin.php @@ -30,7 +30,7 @@ if (!$conf['cluster']) { /* Récupération de cette liste dans le tableau $vhost_list */ $vhost_list = array(); foreach($data_output as $data_line) { - $data_split = split(':', $data_line); + $data_split = explode(':', $data_line); array_push($vhost_list, array( 'owner' => $data_split[0], 'configid' => $data_split[1], @@ -42,7 +42,16 @@ if (!$conf['cluster']) { } else { - $cache=$conf['cache']; + if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); + } + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + } + else { + $cache = $conf['cache']; + } $vhost_list = array(); @@ -65,6 +74,7 @@ else { 'owner' => $account['name'], 'server_name'=> $account['domain'], 'bdd' => $account['bdd'], + 'mail' => $account['mail'], 'replication' => $account['replication'], 'master' => $master, 'slave' => $slave) @@ -75,6 +85,7 @@ else { } + include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; include_once EVOADMIN_BASE . '../tpl/webadmin.tpl.php'; diff --git a/lib/bdd.php b/lib/bdd.php index 8666035..2132580 100644 --- a/lib/bdd.php +++ b/lib/bdd.php @@ -43,17 +43,17 @@ class bdd { private $db; /* resource of a created database */ /** - * @desc Open a sqlite database. Create it if it doesn't exist. + * @desc Open a sqlite database in rw mode. Create it if it doesn't exist. * @param string $db_name Name of the sqlite database */ public function open($db_name) { try { - $this->db = new SQLiteDatabase($db_name, 0666, $error); + $this->db = new SQLite3($db_name); } catch(Exception $e) { - die ($error); + die ($e); } } @@ -83,38 +83,38 @@ class bdd { /* Table Accounts */ $query = 'CREATE Table Accounts ' . - '(id INTEGER PRIMARY KEY , name TEXT, domain TEXT, bdd TEXT, replication TEXT, id_master INTEGER, id_slave INTEGER)'; + '(id INTEGER PRIMARY KEY , name TEXT, domain TEXT, bdd TEXT, replication TEXT, id_master INTEGER, id_slave INTEGER, mail TEXT)'; - if (!$database->queryExec($query, $error)) + if (!$database->exec($query)) { - die($error); + die($database->lastErrorMsg()); } /* Table Servers */ $query = 'CREATE Table Servers ' . '(id INTEGER PRIMARY KEY , name TEXT, ip TEXT)'; - if (!$database->queryExec($query, $error)) + if (!$database->exec($query)) { - die($error); + die($database->lastErrorMsg()); } /* Table ServersAlias */ $query = 'CREATE Table Serveralias ' . '(id INTEGER PRIMARY KEY , domain TEXT, alias TEXT)'; - if (!$database->queryExec($query, $error)) + if (!$database->exec($query)) { - die($error); + die($database->lastErrorMsg()); } /* Table Roles */ $query = 'CREATE Table Roles ' . '(id INTEGER PRIMARY KEY , name TEXT, id_account INTEGER, id_server INTEGER)'; - if (!$database->queryExec($query, $error)) + if (!$database->exec($query)) { - die($error); + die($database->lastErrorMsg()); } } @@ -124,11 +124,12 @@ class bdd { $query = "SELECT Servers.name FROM Servers, Roles where Roles.id = '$roleid' and Roles.id_server = Servers.id"; - if ($result = $database->query($query, SQLITE_ASSOC, $error)) + $result = $database->query($query); + if ($result != FALSE) { - $row = $result->fetch(); + $row = $result->fetchArray(); if (isset($row)) - return $row['Servers.name']; + return $row['name']; } return 0; @@ -146,9 +147,10 @@ class bdd { $query = "SELECT id FROM Accounts where name = '$account_name'"; - if ($result = $database->query($query, SQLITE_ASSOC, $error)) + $result = $database->query($query); + if ($result != FALSE) { - $row = $result->fetch(); + $row = $result->fetchArray(); if (isset($row)) return $row['id']; } @@ -167,9 +169,10 @@ class bdd { $query = "SELECT * FROM Accounts where name = '$account_name'"; - if ($result = $database->query($query, SQLITE_ASSOC, $error)) + $result = $database->query($query); + if ($result != FALSE) { - $row = $result->fetch(); + $row = $result->fetchArray(); if (isset($row)) return $row; else @@ -197,6 +200,7 @@ class bdd { * 'domain' => "$domain", * 'bdd' => "bdd", * 'replication' => "replication" + * 'mail' => "gmail|evolix" * } * @return 1 on success, * 0 else @@ -209,21 +213,23 @@ class bdd { $domain = $account["domain"]; $bdd = $account["bdd"]; $replication = $account["replication"]; + $mail = $account["mail"]; /* check if account exists */ if ($this->is_account($name)) return 0; - $query = "INSERT INTO Accounts (name, domain, bdd, replication) + $query = "INSERT INTO Accounts (name, domain, bdd, replication, mail) VALUES ( '$name', '$domain', '$bdd', - '$replication');"; + '$replication', + '$mail');"; - if (!$database->queryExec($query, $error)) + if (!$database->exec($query)) { - die($error); + die($database->lastErrorMsg()); } return 1; } @@ -250,9 +256,9 @@ class bdd { '$domain', '$alias');"; - if (!$database->queryExec($query, $error)) + if (!$database->exec($query)) { - die($error); + die($database->lastErrorMsg()); } return 1; } @@ -276,8 +282,8 @@ class bdd { $query = "DELETE FROM Serveralias WHERE domain='$domain' AND alias='$alias';"; - if (!$database->queryExec($query, $error)) - die($error); + if (!$database->exec($query)) + die($database->lastErrorMsg()); return 1; } @@ -294,9 +300,10 @@ class bdd { $query = "SELECT id FROM Servers where name = '$server_name'"; - if ($result = $database->query($query, SQLITE_ASSOC, $error)) + $result = $database->query($query); + if ($result != FALSE) { - $row = $result->fetch(); + $row = $result->fetchArray(); if (isset($row)) return $row['id']; } @@ -339,8 +346,8 @@ class bdd { '$name' );"; - if (!$database->queryExec($query, $error)) - die($error); + if (!$database->exec($query)) + die($database->lastErrorMsg()); return 1; } @@ -373,8 +380,8 @@ class bdd { '$id_account', '$id_server')"; - if (!$database->queryExec($query, $error)) - die($error); + if (!$database->exec($query)) + die($database->lastErrorMsg()); $id = $database->lastInsertRowid(); @@ -382,8 +389,8 @@ class bdd { if (($role === 'master') || ($role === 'slave')) $query = "UPDATE Accounts SET id_$role = '$id' WHERE id = '$id_account'"; - if (!$database->queryExec($query, $error)) - die($error); + if (!$database->exec($query)) + die($database->lastErrorMsg()); return 1; } @@ -423,12 +430,13 @@ class bdd { $database = $this->db; $query = "SELECT * FROM Accounts, Roles, Servers WHERE Accounts.id = Roles.id_account AND Roles.id_server = Servers.id"; - if($result = $database->query($query, SQLITE_ASSOC, $error)) + $result = $database->query($query); + if($result != FALSE) { $domains = array(); $i = 0; - while($row = $result->fetch()) + while($row = $result->fetchArray()) { $domains[$i] = $row; ++$i; @@ -442,16 +450,17 @@ class bdd { public function list_accounts() { - $database = $this->db; + $database = $this->db; - $query = "SELECT * FROM Accounts"; + $query = "SELECT * FROM Accounts"; - if($result = $database->query($query, SQLITE_ASSOC, $error)) + $result = $database->query($query); + if ($result != FALSE) { $accounts = array(); $i = 0; - while($row = $result->fetch()) + while($row = $result->fetchArray()) { $accounts[$i] = $row; ++$i; @@ -472,12 +481,13 @@ class bdd { $query = "SELECT * FROM Serveralias WHERE domain = '$domain'"; - if ($result = $database->query($query, SQLITE_ASSOC, $error)) + $result = $database->query($query); + if ($result != FALSE) { $serveralias = array(); $i = 0; - while($row = $result->fetch()) + while($row = $result->fetchArray()) { $serveralias[$i] = $row; ++$i; @@ -488,4 +498,26 @@ class bdd { return $serveralias; } + + public function is_serveralias($domain, $alias) + { + $database = $this->db; + + if ($domain == NULL) + return 0; + if ($alias == NULL) + return 0; + + $query = "SELECT id FROM Serveralias WHERE domain = '$domain' and alias = '$alias'"; + + $result = $database->query($query); + if ($result != FALSE) + { + $row = $result->fetchArray(); + return !!($row['id']); + } + + return 0; + } + } diff --git a/lib/domain.php b/lib/domain.php new file mode 100644 index 0000000..a63df20 --- /dev/null +++ b/lib/domain.php @@ -0,0 +1,29 @@ +>$LOGFILE +# Duplicate stderr on $LOGFILE (bashism) +exec 2> >(tee -a $LOGFILE >&2) + +# Create zone file for a new domain. +create_domain () { + domain="$1" + ip="$2" + + zonefile="$BINDROOT/db.$domain" + + # Create new zone file + cp -p $DBTEMPLATE $zonefile + sed -i "s/_IP_/$ip/" $zonefile + + # Add domain to bind conf + sed "s/__DATE__/`date "+%d.%m.%Y"`/; s/example.com/$domain/" \ + $BINDROOT/named.conf.single >> $BINDROOT/named.conf.evolix +} + +# Add a MX record to an existing domain. +add_mx () { + domain="$1" + mx="$2" + mx_priority="$3" + mx_subdomain="$4" + + zonefile="$BINDROOT/db.$domain" + + # Quai13 specific. See #8053. + if [ "$mx_subdomain" != "@" ]; then + log INFO "Not adding MX record for subdomain $mx_subdomain." + return 0 + fi + + if ! grep -q -E "^$mx_subdomain[ \t]+IN[ \t]+MX[ \t]+[[:digit:]]+[ \t]+$mx$" $zonefile; then + echo "$mx_subdomain IN MX $mx_priority $mx" >>$zonefile + else + log ERR "MX Record $mx already exists." + return 1 + fi +} + +# Add a subdomain (CNAME) to an existing domain. +add_subdomain () { + domain="$1" + subdomain="$2" + + zonefile="$BINDROOT/db.$domain" + + if ! grep -q -E "^$subdomain[ \t]+IN[ \t]+(CNAME|A)[ \t]+" $zonefile; then + echo "$subdomain IN CNAME @" >>$zonefile + else + log ERR "CNAME or A record for $subdomain already exists." + return 1 + fi +} + +# Incremente serial number for a domain, check zone, and reload rndc daemon. +inc_and_reload () { + domain="$1" + + zonefile="$BINDROOT/db.$domain" + + sed -i "s/^\([ \t]*\)[0-9]\{10\}\([ \t]*; serial\)/\1`date "+%Y%m%d%H"`\2/" \ + $zonefile + if stderr=$(named-checkzone $domain $zonefile 2>&1); then + rndc reload + else + log ERR "named-checkzone returns non zero exit code: $stderr" + return 1 + fi +} + +# Send mail to staff to create domain on the slave server. +send_mail () { + #addr_master=$(ifconfig eth0 |perl -ne 'print "$1" if /addr:([\d\.]+)/') + echo "IP du serveur maitre : 46.105.42.13" | + mail -s "[TAF] Ajouter le domaine $domain sur $SLAVE" tech@evolix.fr +} + +usage () { + cat >&2 < [-m ,] [-s subdomain] domain +E.g.: $0 -a 192.0.2.12 -m mail,10 -s foo example.net + +Notes: + - -m and -s options can be specified multiple times to add multiple MX + records and/or subdomains + - you can also create a subdomain "foo" with this syntax (even if example.net + is not yet created): + $0 foo.example.net +EOT +} + +log () { + level="$1" + message="$2" + + if [ "$level" = "ERR" ]; then + echo -n "$(date +"%b %d %T") " >>$LOGFILE + echo "ERROR: $message" |tee -a $LOGFILE >&2 + elif [ "$level" = "INFO" ]; then + echo -n "$(date +"%b %d %T") " >>$LOGFILE + echo "INFO: $message" |tee -a $LOGFILE + fi +} + + +log INFO "$0 $*" + +# Options parsing. + +while getopts 'a:s:m:' opt; do + case $opt in + a) + ip=$OPTARG + ;; + s) + subdomains="$subdomains $OPTARG" + ;; + m) + mxs="$mxs $OPTARG" + ;; + \?) + log ERR "Invalid option -$OPTARG." + usage + exit 1 + ;; + esac +done + +shift $((OPTIND-1)) + +if [ $# -eq 1 ]; then + fqdn=$(echo $1 |tr '[:upper:]' '[:lower:]') +else + usage + exit 1 +fi + +# If the domain contains a subdomain, extracts it. +if [ $(echo "$fqdn" |grep -oF '.' |wc -l) -gt 1 ]; then + domain=$(echo $fqdn |grep -o '[^\.]\+\.[^\.]\+$') + if [ ${fqdn%.$domain} != "www" ]; then # www is already present in the zone template, so skip it. + subdomains="$subdomains ${fqdn%.$domain}" + fi +else + domain="$fqdn" +fi + +if [ ! -f $BINDROOT/db.$domain ]; then + log INFO "Creating domain $domain." + if [ -n "$ip" ]; then + create_domain $domain $ip + #send_mail $domain + $ADD_DOMAIN_SLAVE $domain + $ADD_RELAY_DOMAIN $domain + else + log ERR "Domain $domain does not exist and -a option is not set." + log "Could not create domain." + exit 1 + fi + log INFO "domain $domain created successfully." +fi + +if [ -n "$mxs" ]; then + for mx in $mxs; do + log INFO "Adding MX record $mx to domain $domain." + mx_domain=$(echo $mx |cut -d ',' -f '1') + mx_priority=$(echo $mx |cut -d ',' -f '2') + mx_subdomain="${fqdn%.$domain}" + if [ "$mx_subdomain" = "$domain" ] || [ "$mx_subdomain" = "www" ]; then + mx_subdomain="@" + fi + if ! add_mx $domain $mx_domain $mx_priority "$mx_subdomain"; then + log ERR "Error: adding MX record failed." + exit 1 + fi + log INFO "MX record $mx added successfully to domain $domain." + done +fi + +if [ -n "$subdomains" ]; then + for subdomain in $subdomains; do + log INFO "Adding CNAME record $subdomain to domain $domain." + if ! add_subdomain $domain $subdomain; then + log ERR "Error: adding CNAME record failed." + exit 1 + fi + log INFO "CNAME record $subdomain added successfully to domain $domain." + done +fi + +log INFO "Reloading rndc." +if ! inc_and_reload $domain; then + log ERR "Error: zone not loaded due to errors." + exit 1 +fi +log INFO "rndc reloaded successfully." diff --git a/scripts/vhost b/scripts/vhost index aa89314..88ac77a 100644 --- a/scripts/vhost +++ b/scripts/vhost @@ -28,6 +28,7 @@ Order Deny,Allow Deny from all + #Allow from YYY.YYY.YYY.YYY Satisfy any diff --git a/scripts/vhost-default b/scripts/vhost-default index e4fe719..891d25f 100755 --- a/scripts/vhost-default +++ b/scripts/vhost-default @@ -8,6 +8,7 @@ AllowOverride None Deny from all + #Allow from XXX.XXX.XXX.XXX diff --git a/scripts/web-add-cluster.sh b/scripts/web-add-cluster.sh index 4e0e039..9443f54 100755 --- a/scripts/web-add-cluster.sh +++ b/scripts/web-add-cluster.sh @@ -16,8 +16,8 @@ set -e HOME="/root" -CONTACT_MAIL="" -WWWBOUNCE_MAIL="" +CONTACT_MAIL="jdoe@example.org" +WWWBOUNCE_MAIL="jdoe@example.org" LOCAL_SCRIPT="/usr/share/scripts/web-add.local.sh" PRE_LOCAL_SCRIPT="/usr/share/scripts/web-add.pre-local.sh" TPL_VHOST="/usr/share/scripts/vhost" @@ -265,15 +265,20 @@ create_www_accounts() { if [ "$in_replmode" != "realtime" ]; then - echo "SLAVE: $CMD_SLAVE $WEBADD add -p '$in_passwd' $opts_mysql -l $in_mail -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain" - $CMD_SLAVE $WEBADD add -p \'$in_passwd\' $opts_mysql -l $in_mail -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain || (in_error "creation du compte slave sur $in_slave: $?" && exit 1) + echo "SLAVE: $CMD_SLAVE $WEBADD add -p '$in_passwd' $opts_mysql -l null@example.org -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain" + $CMD_SLAVE $WEBADD add -p \'$in_passwd\' $opts_mysql -l null@example.org -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain || (in_error "creation du compte slave sur $in_slave: $?" && exit 1) else - echo "SLAVE: $CMD_SLAVE $WEBADD add -p '$in_passwd' -l $in_mail -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain" - $CMD_SLAVE $WEBADD add -p \'$in_passwd\' -l $in_mail -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain || (in_error "creation du compte slave sur $in_slave: $?" && exit 1) + echo "SLAVE: $CMD_SLAVE $WEBADD add -p '$in_passwd' -l null@example.org -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain" + $CMD_SLAVE $WEBADD add -p \'$in_passwd\' -l null@example.org -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain || (in_error "creation du compte slave sur $in_slave: $?" && exit 1) fi + + # On ne veut pas que le site soit actif sur le serveur slave + $CMD_SLAVE a2dissite $in_login + $CMD_SLAVE /etc/init.d/apache2 reload + fi # Les operation suivantes sont faites uniquement si une replication doit @@ -375,12 +380,12 @@ ENDSSH cron_line="*/$in_replinterval * * * * /opt/evocluster/sync-master-to-slave.sh" cron_line2="*/$in_replinterval * * * * /opt/evocluster/get-domains.sh $in_login |while read domain; do /opt/evocluster/sync-master-to-slave_mail.sh \$domain $in_login; done" elif [ $in_replunit = "hour" ]; then - minute=$(($RANDOM % 60)) + minute=$(($RANDOM % 54)) offset=5 cron_line="$minute */$in_replinterval * * * /opt/evocluster/sync-master-to-slave.sh" cron_line2="$(($minute+$offset)) */$in_replinterval * * * /opt/evocluster/get-domains.sh $in_login |while read domain; do /opt/evocluster/sync-master-to-slave_mail.sh \$domain $in_login; done" fi - $CMD_MASTER "(crontab -lu $in_login; echo \"$cron_line\") |crontab -u $in_login -" + $CMD_MASTER "(crontab -lu $in_login; echo -e \"$cron_line\") |crontab -u $in_login -" $CMD_MASTER "(crontab -lu $VMAIL_USER; echo '$cron_line2') |crontab -u $VMAIL_USER -" fi @@ -420,13 +425,13 @@ op_del() { # check account exist on master and slave if [ -z "$($CMD_MASTER cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then - error "Account $login doesn't exist on $master"; + echo "Account $login doesn't exist on $master"; exit 1; fi if [ $slave != "null" ]; then if [ -z "$($CMD_SLAVE cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then - error "Account $login doesn't exist on $slave"; + echo "Account $login doesn't exist on $slave"; exit 1; fi fi diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 4dbecd2..ceb9f8c 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -16,8 +16,8 @@ set -e HOME="/root" -CONTACT_MAIL="" -WWWBOUNCE_MAIL="" +CONTACT_MAIL="jdoe@example.org" +WWWBOUNCE_MAIL="jdoe@example.org" LOCAL_SCRIPT="/usr/share/scripts/web-add.local.sh" PRE_LOCAL_SCRIPT="/usr/share/scripts/web-add.pre-local.sh" TPL_VHOST="/usr/share/scripts/vhost" diff --git a/tpl/header.tpl.php b/tpl/header.tpl.php index f2c3a1d..85a81f7 100644 --- a/tpl/header.tpl.php +++ b/tpl/header.tpl.php @@ -35,9 +35,18 @@ diff --git a/tpl/home.tpl.php b/tpl/home.tpl.php index 8dd894e..5d10005 100644 --- a/tpl/home.tpl.php +++ b/tpl/home.tpl.php @@ -13,9 +13,23 @@ * @version 1.0 */ +require_once EVOADMIN_BASE . '../evolibs/Form.php'; + +if (is_mcluster_mode()) { + echo '

Bienvenue, sélectionnez le cluster que vous voulez administrer, +puis utilisez le menu ci-dessus pour administrer votre compte.

'; + + print "
"; + print "
"; + print " Choisissez un cluster"; + print $form; + print "

"; + print "
"; + print "
"; +} +else { + echo '

Bienvenue, utilisez le menu ci-dessus pour administrer votre compte.

'; +} ?> -

-Bienvenue, utilisez le menu ci-dessus pour administrer votre compte. -

diff --git a/tpl/webadmin.tpl.php b/tpl/webadmin.tpl.php index 864c08c..94c74bb 100755 --- a/tpl/webadmin.tpl.php +++ b/tpl/webadmin.tpl.php @@ -28,12 +28,13 @@ Bdd + Mail Replication Master Slave - Alias'); - ?> + Alias'; + }} ?> @@ -46,36 +47,38 @@ $vhost_info['server_name'], $vhost_info['server_name']); if ($conf['cluster']) { + if (empty($vhost_info['bdd'])) + printf(''); + else + printf('%s', $vhost_info['bdd']); - if (empty($vhost_info['bdd'])) - printf(''); - else - printf('%s', $vhost_info['bdd']); + if (empty($vhost_info['mail'])) + printf(''); + else if ($vhost_info['mail'] == 'gmail') + printf('Gmail'); + else printf('Evolix'); if (empty($vhost_info['replication'])) - printf(''); - else - printf('%s', $vhost_info['replication']); - - printf('%s', $vhost_info['master']); - - if (empty($vhost_info['slave'])) printf(''); else - printf('%s', $vhost_info['slave']); + printf('%s', $vhost_info['replication']); + printf('%s', $vhost_info['master']); + if (empty($vhost_info['slave'])) + printf(''); + else + printf('%s', $vhost_info['slave']); + } + else { + printf('%s', $vhost_info['server_alias']); + } + if (is_superadmin()) { + printf('Lister/Modifier', + $vhost_info['owner']); + } - if (is_superadmin()) { - printf('Lister/Modifier', - $vhost_info['owner']); - } - } else { - if (empty($vhost_info['server_alias'])) - printf(''); - else - printf('%s', $vhost_info['server_alias']); - } print ''; + } ?>