parent
63a2f16b27
commit
e6edffd820
@ -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);
|
||||
?>
|
||||
|
@ -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
|
||||
*/
|
@ -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');
|
After Width: | Height: | Size: 170 B |
After Width: | Height: | Size: 112 B |
@ -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';
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -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);
|
||||
}
|
||||
|
@ -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."
|