Browse Source

Merge untracked code into evoadmin-web.

jessie
Romain Dessort 6 years ago
parent
commit
e6edffd820
  1. 39
      bin/add_server.php
  2. 39
      bin/init_cache.php
  3. 32
      bin/list_domains.php
  4. 31
      conf/config.cluster1.php
  5. 21
      conf/config.cluster2.php
  6. 20
      conf/config.php
  7. 4
      evolibs/Form.php
  8. 32
      htdocs/common.php
  9. BIN
      htdocs/img/evolix.gif
  10. BIN
      htdocs/img/gmail.gif
  11. 4
      htdocs/index.php
  12. 66
      inc/accounts.php
  13. 2
      inc/auth.php
  14. 4
      inc/ftpadmin.php
  15. 16
      inc/home.php
  16. 121
      inc/webadmin-edit.php
  17. 198
      inc/webadmin-suppr.php
  18. 15
      inc/webadmin.php
  19. 118
      lib/bdd.php
  20. 29
      lib/domain.php
  21. 210
      scripts/bind-add-ng.sh
  22. 1
      scripts/vhost
  23. 1
      scripts/vhost-default
  24. 25
      scripts/web-add-cluster.sh
  25. 4
      scripts/web-add.sh
  26. 15
      tpl/header.tpl.php
  27. 20
      tpl/home.tpl.php
  28. 53
      tpl/webadmin.tpl.php

39
bin/add_server.php

@ -1,20 +1,30 @@
#!/usr/bin/php
<?php
require '../lib/bdd.php';
require_once '../conf/config.php';
require_once '../conf/config.local.php';
require_once '../htdocs/common.php';
$bdd = new bdd();
if ($argc==1) {
echo "Specify a server name";
exit(1);
$file = '';
$server = '';
if (is_mcluster_mode()) {
if ($argc != 3) {
echo "Multi-cluster mode is enabled in your config file.\n";
echo "Usage: $argv[0] <cluster> <server>\n";
exit(1);
}
$file = str_replace('%cluster_name%', $argv[1], $conf['cache']);
$server = $argv[2];
}
else {
if ($argc != 2) {
echo "Usage: $argv[0] <server>\n";
exit(1);
}
$file = $conf['cache'];
$server = $argv[1];
}
$conf = array_merge($oriconf, $localconf);
$bdd = new bdd();
$file=$conf['cache'];
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);
?>

39
bin/init_cache.php

@ -1,28 +1,31 @@
#!/usr/bin/php
<?php
require '../lib/bdd.php';
require_once '../conf/config.php';
require_once '../conf/config.local.php';
$conf = array_merge($oriconf, $localconf);
$bdd = new bdd();
require_once '../htdocs/common.php';
$file=$conf['cache'];
if (!file_exists($file))
$bdd->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);
?>

32
bin/list_domains.php

@ -1,23 +1,33 @@
#!/usr/bin/php
<?php
require '../lib/bdd.php';
require_once '../conf/config.php';
require_once '../conf/config.local.php';
$conf = array_merge($oriconf, $localconf);
$bdd = new bdd();
$file=$conf['cache'];
require_once '../htdocs/common.php';
$file = '';
$server = '';
if (is_mcluster_mode()) {
if ($argc != 2) {
echo "Multi-cluster mode is enabled in your config file.\n";
echo "Usage: $argv[0] <cluster>\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);

31
conf/config.cluster1.php

@ -0,0 +1,31 @@
<?php
/*
* Configuration page
*
* Copyright (c) 2009 Evolix - Tous droits reserves
*
* $Id: config.php 273 2009-05-12 13:54:50Z tmartin $
* vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
*
* @author Gregory Colpart <reg@evolix.fr>
* @author Thomas Martin <tmartin@evolix.fr>
* @author Sebastien Palma <spalma@evolix.fr>
* @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
*/

21
conf/config.cluster2.php

@ -0,0 +1,21 @@
<?php
/*
* Configuration page
*
* Copyright (c) 2009 Evolix - Tous droits reserves
*
* $Id: config.php 273 2009-05-12 13:54:50Z tmartin $
* vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
*
* @author Gregory Colpart <reg@evolix.fr>
* @author Thomas Martin <tmartin@evolix.fr>
* @author Sebastien Palma <spalma@evolix.fr>
* @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');

20
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');

4
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";

32
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);
}

BIN
htdocs/img/evolix.gif

After

Width: 16  |  Height: 16  |  Size: 170 B

BIN
htdocs/img/gmail.gif

After

Width: 16  |  Height: 11  |  Size: 112 B

4
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';

66
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 ?",

2
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'];

4
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;

16
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';

121
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 "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
printf ('<p>Alias %s est supprimé.</p>', $serveralias['alias']);
} else
print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
}
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
} else if ( ! isset($_GET['modif']) ) {
print "<center>";
print "<p>Confirmez vous la suppression de $alias ?</p>";
printf ('<p><a href="%s?del=%s&modif=yes">Confirmer la suppression</a></p>', $_SERVER['REDIRECT_SCRIPT_URL'], $alias);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
printf ('<p><a href="%s?del=%s&modif=yes">Confirmer la suppression</a></p>', $_SERVER['REDIRECT_URL'], $alias);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
}
@ -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));
}
print "<center>";
printf ('<p>L\'alias %s du domaine %s a bien été créé</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
print "</center>";
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 "<center>";
printf ('<p>L\'alias %s du domaine %s a bien été créé</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
} else {
print "<center>";
printf ('<p>Echec dans la creation de l\'alias %s du domaine %s</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
}
} else {
print "<center>";
printf ('<p>Echec dans la creation de l\'alias %s du domaine %s</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
printf ('<p>Alias %s du domaine %s deja existant !</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
}
}
}
@ -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();

198
inc/webadmin-suppr.php

@ -0,0 +1,198 @@
<?php
/**
* Apache VirtualHost Management Page
*
* Copyright (c) 2009 Evolix - Tous droits reserves
*
* vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
*
* @author Gregory Colpart <reg@evolix.fr>
* @author Thomas Martin <tmartin@evolix.fr>
* @author Sebastien Palma <spalma@evolix.fr>
* @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 "<center>";
print "<p>Suppression de $alias...</p>";
$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 "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
printf ('<p>Alias %s est supprimé.</p>', $serveralias['alias']);
} else
print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
}
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
print "</center>";
} else if ( ! isset($_GET['modif']) ) {
print "<center>";
print "<p>Confirmez vous la suppression de $alias ?</p>";
printf ('<p><a href="%s?del=%s&modif=yes">Confirmer la suppression</a></p>', $_SERVER['REDIRECT_SCRIPT_URL'], $alias);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
print "</center>";
}
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 "<center>";
printf ('<p>L\'alias %s du domaine %s a bien été créé</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
print "</center>";
} else {
print "<center>";
printf ('<p>Echec dans la creation de l\'alias %s du domaine %s</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
print "</center>";
}
} else {
print "<center>";
printf ('<p>Alias %s du domaine %s deja existant !</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_SCRIPT_URL']);
print "</center>";
}
}
}
} else {
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
print " <fieldset>";
print " <legend>Ajout d'un serveralias</legend>";
print $form;
print " <p><input type=\"submit\" value=\"Créer\"/></p>";
print " </fieldset>";
print "</form>";
}
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';
}
?>

15
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';

118
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;
}
}

29
lib/domain.php

@ -0,0 +1,29 @@
<?php
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('tech@evolix.fr', '[TAF] Ajouter '.$name.' sur quai13-backup', wordwrap('Ajouter le domaine '.$name.' à la directive relay_domains dans le fichier /etc/postfix/main.cf sur quai13-backup, pour mettre en place le MX secondaire du domaine.', 70));
}
$exec_cmd .= " -a $IP $name";
//echo $exec_cmd."\n";
sudoexec($exec_cmd, $exec_output, $exec_return);
return array($exec_cmd, $exec_return, $exec_output);
}

210
scripts/bind-add-ng.sh

@ -0,0 +1,210 @@
#!/bin/bash
BINDROOT="/etc/bind"
DBTEMPLATE="$BINDROOT/db.example.com"
SLAVE="ns4.evolix.net"
LOGFILE="/var/log/bind-add.log"
ADD_DOMAIN_SLAVE="/usr/share/scripts/add_domain_slave_ns4.sh"
ADD_RELAY_DOMAIN="/usr/share/scripts/add_relay_domains.sh"
# Redirect stderr to $LOGFILE since Evoadmin don't catch stderr correctly.
#exec 2>>$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 <<EOT
Usage: $0 -a <A record> [-m <MX record>,<priority>] [-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."

1
scripts/vhost

@ -28,6 +28,7 @@
Order Deny,Allow
Deny from all
#Allow from YYY.YYY.YYY.YYY
Satisfy any

1
scripts/vhost-default