NO CODE IN THIS COMMIT. ONLY :retab replacement aka remove-all-tabs-from-code commit

This commit is contained in:
Gregory Colpart 2017-08-20 04:31:00 +02:00
parent d16fe6fd70
commit 2947fa2c87
15 changed files with 823 additions and 823 deletions

View File

@ -9,9 +9,9 @@ $file = '';
$server = ''; $server = '';
if (is_mcluster_mode()) { if (is_mcluster_mode()) {
if ($argc != 3) { if ($argc != 3) {
echo "Multi-cluster mode is enabled in your config file.\n"; echo "Multi-cluster mode is enabled in your config file.\n";
echo "Usage: $argv[0] <cluster> <server>\n"; echo "Usage: $argv[0] <cluster> <server>\n";
exit(1); exit(1);
} }
$file = str_replace('%cluster_name%', $argv[1], $conf['cache']); $file = str_replace('%cluster_name%', $argv[1], $conf['cache']);
$server = $argv[2]; $server = $argv[2];
@ -19,7 +19,7 @@ if (is_mcluster_mode()) {
else { else {
if ($argc != 2) { if ($argc != 2) {
echo "Usage: $argv[0] <server>\n"; echo "Usage: $argv[0] <server>\n";
exit(1); exit(1);
} }
$file = $conf['cache']; $file = $conf['cache'];
$server = $argv[1]; $server = $argv[1];
@ -27,8 +27,8 @@ else {
if (!file_exists($file)) { if (!file_exists($file)) {
echo "$file doesn't exist\n"; echo "$file doesn't exist\n";
exit(1); exit(1);
} }
$bdd->open($file); $bdd->open($file);

View File

@ -18,12 +18,12 @@ foreach ($files as $file) {
$bdd = new bdd(); $bdd = new bdd();
if (!file_exists($file)) { if (!file_exists($file)) {
$bdd->create($file); $bdd->create($file);
echo "$file created.\n"; echo "$file created.\n";
} }
else { else {
echo "$file is already created.\n"; echo "$file is already created.\n";
continue; continue;
} }
} }

View File

@ -7,23 +7,23 @@ $file = '';
$server = ''; $server = '';
if (is_mcluster_mode()) { if (is_mcluster_mode()) {
if ($argc != 2) { if ($argc != 2) {
echo "Multi-cluster mode is enabled in your config file.\n"; echo "Multi-cluster mode is enabled in your config file.\n";
echo "Usage: $argv[0] <cluster>\n"; echo "Usage: $argv[0] <cluster>\n";
exit(1); exit(1);
} }
$file = str_replace('%cluster_name%', $argv[1], $conf['cache']); $file = str_replace('%cluster_name%', $argv[1], $conf['cache']);
} }
else { else {
if ($argc != 1) { if ($argc != 1) {
echo "Usage: $argv[0]\n"; echo "Usage: $argv[0]\n";
exit(1); exit(1);
} }
$file = $conf['cache']; $file = $conf['cache'];
} }
if (!file_exists($file)) { if (!file_exists($file)) {
echo "$file is not created\n"; echo "$file is not created\n";
exit(1); exit(1);
} }
$bdd = new bdd(); $bdd = new bdd();

View File

@ -2,18 +2,18 @@
// vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2 // vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
function fill_directory_field(value) { function fill_directory_field(value) {
if(document.forms['addftp'].path.value == '') { if(document.forms['addftp'].path.value == '') {
document.forms['addftp'].path.value = value; document.forms['addftp'].path.value = value;
} }
} }
function check_form_ftp_add() { function check_form_ftp_add() {
field_passwd = document.getElementById('passwd').value; field_passwd = document.getElementById('passwd').value;
if(field_passwd.length < 6) { if(field_passwd.length < 6) {
alert('Le mot de passe doit contenir au moins 6 caractères '); alert('Le mot de passe doit contenir au moins 6 caractères ');
return false; return false;
} }
return true; return true;
} }
document.observe("dom:loaded", function() { document.observe("dom:loaded", function() {

View File

@ -83,7 +83,7 @@ function web_add_cluster($form, $admin_mail) {
$exec_cmd = 'web-add-cluster.sh add'; $exec_cmd = 'web-add-cluster.sh add';
$realtime=0; $realtime=0;
/* array account with infos for sqlite cache */ /* array account with infos for sqlite cache */
$account = array(); $account = array();
@ -194,21 +194,21 @@ function web_add_cluster($form, $admin_mail) {
/* insertion des infos dans le cache sqlite */ /* insertion des infos dans le cache sqlite */
if ($exec_return == 0) { if ($exec_return == 0) {
$bdd=new bdd(); $bdd=new bdd();
$bdd->open($cache); $bdd->open($cache);
$account['name'] = $form->getField('username')->getValue(); $account['name'] = $form->getField('username')->getValue();
$account['domain'] = $form->getField('domain')->getValue(); $account['domain'] = $form->getField('domain')->getValue();
if ($form->getField('use_gmail_mxs')->getValue()) if ($form->getField('use_gmail_mxs')->getValue())
$account['mail'] = 'gmail'; $account['mail'] = 'gmail';
else else
$account['mail'] = 'evolix'; $account['mail'] = 'evolix';
$bdd->add_account($account); $bdd->add_account($account);
$bdd->add_role($account['name'], $master, 'master'); $bdd->add_role($account['name'], $master, 'master');
if ($slave != "null"); if ($slave != "null");
$bdd->add_role($account['name'], $slave, 'slave'); $bdd->add_role($account['name'], $slave, 'slave');
if (substr_compare($account['domain'], 'www.', 0, strlen('www.')) == 0) { if (substr_compare($account['domain'], 'www.', 0, strlen('www.')) == 0) {
$wwwalias = ltrim($account['domain'], 'www.'); $wwwalias = ltrim($account['domain'], 'www.');
@ -337,37 +337,37 @@ $form->addField('use_gmail_mxs', new CheckboxInputFormField("Utilisation des ser
/* Traitement du formulaire */ /* Traitement du formulaire */
if(!empty($_POST)) { if(!empty($_POST)) {
$form->isCurrentPage(TRUE); $form->isCurrentPage(TRUE);
$form->initFields(); $form->initFields();
/* Le champ password devient obligatoire si le champ password_random est /* Le champ password devient obligatoire si le champ password_random est
* décoché */ * décoché */
if(!$form->getField('password_random')->getValue()) { if(!$form->getField('password_random')->getValue()) {
$form->getField('password')->setMandatory(TRUE); $form->getField('password')->setMandatory(TRUE);
$form->getField('password')->setDisabled(FALSE); $form->getField('password')->setDisabled(FALSE);
} }
/* Erreur si mysql_db est coché */ /* Erreur si mysql_db est coché */
if($form->getField('mysql_db')->getValue()) { if($form->getField('mysql_db')->getValue()) {
$form->getField('mysql_dbname')->setMandatory(TRUE); $form->getField('mysql_dbname')->setMandatory(TRUE);
$form->getField('mysql_dbname')->setDisabled(FALSE); $form->getField('mysql_dbname')->setDisabled(FALSE);
$form->getField('mysql_password_random')->setDisabled(FALSE); $form->getField('mysql_password_random')->setDisabled(FALSE);
/* Le champ mysql_passwd devient obligatoire si le champ /* Le champ mysql_passwd devient obligatoire si le champ
* mysql_password_random est coché */ * mysql_password_random est coché */
if(!$form->getField('mysql_password_random')->getValue()) { if(!$form->getField('mysql_password_random')->getValue()) {
$form->getField('mysql_password')->setMandatory(TRUE); $form->getField('mysql_password')->setMandatory(TRUE);
$form->getField('mysql_password')->setDisabled(FALSE); $form->getField('mysql_password')->setDisabled(FALSE);
} }
} }
/* Test de validation du formulaire */ /* Test de validation du formulaire */
if($form->verify(TRUE)) { if($form->verify(TRUE)) {
if ($conf['cluster']) if ($conf['cluster'])
$exec_info = web_add_cluster($form, $conf['admin']['mail']); $exec_info = web_add_cluster($form, $conf['admin']['mail']);
else else
$exec_info = web_add($form, $conf['admin']['mail']); $exec_info = web_add($form, $conf['admin']['mail']);
} }
} }
include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/header.tpl.php';

View File

@ -200,13 +200,13 @@ if ($action=="add") {
$size_total += $infos[3]; $size_total += $infos[3];
$table[$num_line]['size'] = formatBytes($infos[3]); $table[$num_line]['size'] = formatBytes($infos[3]);
} else { } else {
$table[$num_line]['size'] = 0; $table[$num_line]['size'] = 0;
} }
if ($infos[4]>0) { if ($infos[4]>0) {
$table[$num_line]['date'] = date("d/m/Y h:i:s", $infos[4]); $table[$num_line]['date'] = date("d/m/Y h:i:s", $infos[4]);
} else { } else {
$table[$num_line]['date'] = "01/01/1970"; $table[$num_line]['date'] = "01/01/1970";
} }
$num_line++; $num_line++;

View File

@ -21,23 +21,23 @@ global $conf;
if (!$conf['cluster']) { if (!$conf['cluster']) {
$cmd = 'web-add.sh list-vhost'; $cmd = 'web-add.sh list-vhost';
if(!is_superadmin()) { if(!is_superadmin()) {
$cmd = sprintf('%s %s', $cmd, $_SESSION['user']); $cmd = sprintf('%s %s', $cmd, $_SESSION['user']);
} }
sudoexec($cmd, $data_output, $exec_return); sudoexec($cmd, $data_output, $exec_return);
/* Récupération de cette liste dans le tableau $vhost_list */ /* Récupération de cette liste dans le tableau $vhost_list */
$vhost_list = array(); $vhost_list = array();
foreach($data_output as $data_line) { foreach($data_output as $data_line) {
$data_split = explode(':', $data_line); $data_split = explode(':', $data_line);
array_push($vhost_list, array( array_push($vhost_list, array(
'owner' => $data_split[0], 'owner' => $data_split[0],
'configid' => $data_split[1], 'configid' => $data_split[1],
'server_name' => $data_split[2], 'server_name' => $data_split[2],
'server_alias' => $data_split[3]) 'server_alias' => $data_split[3])
); );
} }
} }
else { else {
@ -53,35 +53,35 @@ else {
$cache = $conf['cache']; $cache = $conf['cache'];
} }
$vhost_list = array(); $vhost_list = array();
/* parcours de la table account */ /* parcours de la table account */
$bdd=new bdd(); $bdd=new bdd();
$bdd->open($cache); $bdd->open($cache);
$accounts = $bdd->list_accounts(); $accounts = $bdd->list_accounts();
if (!empty($accounts)) { if (!empty($accounts)) {
foreach($accounts as $account) { foreach($accounts as $account) {
$master = $bdd->get_server_from_roleid($account['id_master']); $master = $bdd->get_server_from_roleid($account['id_master']);
$slave = ''; $slave = '';
if (!empty($account['id_slave'])) if (!empty($account['id_slave']))
$slave = $bdd->get_server_from_roleid($account['id_slave']); $slave = $bdd->get_server_from_roleid($account['id_slave']);
array_push($vhost_list, array( array_push($vhost_list, array(
'owner' => $account['name'], 'owner' => $account['name'],
'server_name'=> $account['domain'], 'server_name'=> $account['domain'],
'bdd' => $account['bdd'], 'bdd' => $account['bdd'],
'mail' => $account['mail'], 'mail' => $account['mail'],
'replication' => $account['replication'], 'replication' => $account['replication'],
'master' => $master, 'master' => $master,
'slave' => $slave) 'slave' => $slave)
); );
} }
} }
} }

View File

@ -132,7 +132,7 @@ class bdd {
return $row['name']; return $row['name'];
} }
return 0; return 0;
} }
/** /**
@ -450,9 +450,9 @@ class bdd {
public function list_accounts() public function list_accounts()
{ {
$database = $this->db; $database = $this->db;
$query = "SELECT * FROM Accounts"; $query = "SELECT * FROM Accounts";
$result = $database->query($query); $result = $database->query($query);
if ($result != FALSE) if ($result != FALSE)
@ -474,12 +474,12 @@ class bdd {
public function list_serveralias($domain) public function list_serveralias($domain)
{ {
$database = $this->db; $database = $this->db;
if ($domain == NULL) if ($domain == NULL)
return NULL; return NULL;
$query = "SELECT * FROM Serveralias WHERE domain = '$domain'"; $query = "SELECT * FROM Serveralias WHERE domain = '$domain'";
$result = $database->query($query); $result = $database->query($query);
if ($result != FALSE) if ($result != FALSE)
@ -501,7 +501,7 @@ class bdd {
public function is_serveralias($domain, $alias) public function is_serveralias($domain, $alias)
{ {
$database = $this->db; $database = $this->db;
if ($domain == NULL) if ($domain == NULL)
return 0; return 0;

View File

@ -9,7 +9,7 @@ LOGFILE=~/log/evocluster.log
MAIL="jdoe@example.com" MAIL="jdoe@example.com"
mail_error() { mail_error() {
echo "From: John Doe <jdoe@example.com> echo "From: John Doe <jdoe@example.com>
To: $MAIL To: $MAIL
Subject: [evocluster] check_cron_state.sh Subject: [evocluster] check_cron_state.sh
@ -52,45 +52,45 @@ fi
if [ "$STATE" = "slave" ]; then if [ "$STATE" = "slave" ]; then
info 'Account is in state slave, execution of cron is disabled' info 'Account is in state slave, execution of cron is disabled'
exit 1 exit 1
else else
# env var $FORCE_CRON is set to yes, execute the cron # env var $FORCE_CRON is set to yes, execute the cron
[ "$FORCE_CRON" = "yes" ] && exit 0; [ "$FORCE_CRON" = "yes" ] && exit 0;
###  rajouter une règle sudo pour pouvoir exécuter ping ? ###  rajouter une règle sudo pour pouvoir exécuter ping ?
# test if the remote server is alive # test if the remote server is alive
#if ! ping -c1 -w1 $REMOTE_IP; then #if ! ping -c1 -w1 $REMOTE_IP; then
# error "Remote server $IP doesn't seem to be up, I don't know what to do...Add 'FORCE_CRON=yes' in ~/state file to execute user cron" # error "Remote server $IP doesn't seem to be up, I don't know what to do...Add 'FORCE_CRON=yes' in ~/state file to execute user cron"
# exit 1 # exit 1
#fi #fi
### ###
# try to connect to the remote server and check if it isn't a master # try to connect to the remote server and check if it isn't a master
REMOTE_STATE=$(mktemp) REMOTE_STATE=$(mktemp)
if ssh $REMOTE_IP [ -e ~/state ]; then if ssh $REMOTE_IP [ -e ~/state ]; then
ssh $REMOTE_IP cat ~/state >$REMOTE_STATE ssh $REMOTE_IP cat ~/state >$REMOTE_STATE
elif [ $? -eq 255 ]; then elif [ $? -eq 255 ]; then
error "Failed to connect to slave ($REMOTE_IP)! I don't know what to do.." error "Failed to connect to slave ($REMOTE_IP)! I don't know what to do.."
exit 1 exit 1
else else
error "State file does not exist on slave !" error "State file does not exist on slave !"
exit 1 exit 1
fi fi
. $REMOTE_STATE . $REMOTE_STATE
rm -rf $REMOTE_STATE rm -rf $REMOTE_STATE
if [ -n "$STATE" ]; then if [ -n "$STATE" ]; then
REMOTE_STATE=$STATE REMOTE_STATE=$STATE
else else
error '$STATE not set in remote state file!' error '$STATE not set in remote state file!'
exit 1 exit 1
fi fi
if [ "$REMOTE_STATE" = "master" ]; then if [ "$REMOTE_STATE" = "master" ]; then
error "Remote server $IP is master too. (incoherent state)..." error "Remote server $IP is master too. (incoherent state)..."
exit 1 exit 1
fi fi
fi fi
# Remote server is slave # Remote server is slave

View File

@ -135,40 +135,40 @@ delete_account() {
while getopts a:u:n:f:p: opt; do while getopts a:u:n:f:p: opt; do
case "$opt" in case "$opt" in
a) a)
in_action=$OPTARG in_action=$OPTARG
;; ;;
u) u)
in_userid=$OPTARG in_userid=$OPTARG
;; ;;
n) n)
in_accountname=$OPTARG in_accountname=$OPTARG
;; ;;
f) f)
in_workpath=$OPTARG in_workpath=$OPTARG
;; ;;
p) p)
in_password=$OPTARG in_password=$OPTARG
;; ;;
esac esac
done done
case "$in_action" in case "$in_action" in
l) l)
account_list=`list_accounts_by_UID $in_userid` account_list=`list_accounts_by_UID $in_userid`
echo -e -n $account_list echo -e -n $account_list
exit 1 exit 1
;; ;;
a) a)
echo -e -n `add_account $in_userid $in_accountname $in_workpath $in_password` echo -e -n `add_account $in_userid $in_accountname $in_workpath $in_password`
exit 1 exit 1
;; ;;
m) m)
echo -e -n `edit_password $in_accountname $in_password` echo -e -n `edit_password $in_accountname $in_password`
exit 1; exit 1;
;; ;;
d) d)
echo -e -n `delete_account $in_accountname` echo -e -n `delete_account $in_accountname`
exit 1; exit 1;
;; ;;
esac esac

View File

@ -2,22 +2,22 @@
for dir in `cat /etc/proftpd/vpasswd | cut -d : -f 6`; do for dir in `cat /etc/proftpd/vpasswd | cut -d : -f 6`; do
#for dir in /home/dalleFTP/reynaud_mila; do #for dir in /home/dalleFTP/reynaud_mila; do
if [ -d $dir ]; then if [ -d $dir ]; then
du -s $dir | cut -f 1 >$dir/.size du -s $dir | cut -f 1 >$dir/.size
chmod 644 $dir/.size chmod 644 $dir/.size
#mtime=0 #mtime=0
#export IFS=$'\n' #export IFS=$'\n'
#for file in `find $dir -type f -not -name .size -not -name .last-modified`; do #for file in `find $dir -type f -not -name .size -not -name .last-modified`; do
# timestamp=`stat -c %Y $file` # timestamp=`stat -c %Y $file`
# if [ $timestamp -gt $mtime ]; then # if [ $timestamp -gt $mtime ]; then
# mtime=$timestamp # mtime=$timestamp
# fi # fi
#done #done
#unset IFS #unset IFS
#echo $mtime >$dir/.lastmodified #echo $mtime >$dir/.lastmodified
#chmod 644 $dir/.lastmodified #chmod 644 $dir/.lastmodified
fi fi
done done

View File

@ -59,10 +59,10 @@ if [ $LOCAL_STATE = 'master' ]; then
# Try to connect to the remote server and check if it is a slave # Try to connect to the remote server and check if it is a slave
REMOTE_STATE=$(mktemp) REMOTE_STATE=$(mktemp)
if ssh $REMOTE_IP [ -e ~/state ]; then if ssh $REMOTE_IP [ -e ~/state ]; then
ssh $REMOTE_IP cat ~/state >$REMOTE_STATE ssh $REMOTE_IP cat ~/state >$REMOTE_STATE
elif [ $? -eq 255 ]; then elif [ $? -eq 255 ]; then
error "failed to connect to slave ($REMOTE_IP)!" error "failed to connect to slave ($REMOTE_IP)!"
exit 2 exit 2
else else
error "state file does not exist on slave!" error "state file does not exist on slave!"
exit 2 exit 2

View File

@ -40,7 +40,7 @@ config_file="/etc/evolinux/web-add.conf"
[ -r $config_file ] && . $config_file [ -r $config_file ] && . $config_file
usage() { usage() {
cat <<EOT >&2 cat <<EOT >&2
Usage: $0 COMMAND [ARG] Usage: $0 COMMAND [ARG]
@ -97,8 +97,8 @@ EOT
# Affiche un message d'erreur de validation # Affiche un message d'erreur de validation
# #
in_error() { in_error() {
msg=$1 msg=$1
cat >&2 <<EOT cat >&2 <<EOT
*** ***
Erreur : $msg Erreur : $msg
*** ***
@ -106,55 +106,55 @@ EOT
} }
gen_random_passwd() { gen_random_passwd() {
apg -c /dev/urandom -n1 -E oOlL10\&\\\/\"\' apg -c /dev/urandom -n1 -E oOlL10\&\\\/\"\'
} }
validate_login() { validate_login() {
login=$1 login=$1
length=${#login} length=${#login}
if [ $length -lt 3 ]; then if [ $length -lt 3 ]; then
in_error "Le login doit contenir plus de 2 caracteres" in_error "Le login doit contenir plus de 2 caracteres"
return 1 return 1
fi fi
if [ $length -gt $MAX_LOGIN_CHAR ]; then if [ $length -gt $MAX_LOGIN_CHAR ]; then
in_error "Le login ne doit pas contenir plus de $MAX_LOGIN_CHAR caracteres" in_error "Le login ne doit pas contenir plus de $MAX_LOGIN_CHAR caracteres"
return 1 return 1
fi fi
} }
validate_passwd() { validate_passwd() {
passwd=$1 passwd=$1
length=${#passwd} length=${#passwd}
if [ $length -lt 6 ] && [ $length -gt 0 ]; then if [ $length -lt 6 ] && [ $length -gt 0 ]; then
in_error "Le mot de passe doit avoir au moins 6 caracteres" in_error "Le mot de passe doit avoir au moins 6 caracteres"
return 1 return 1
fi fi
} }
validate_dbname() { validate_dbname() {
dbname=$1 dbname=$1
# aandre 18/06 # aandre 18/06
# if mysql -ss -e "show databases" | grep "^$dbname$" >/dev/null; then # if mysql -ss -e "show databases" | grep "^$dbname$" >/dev/null; then
# in_error "Base de données déjà existante" # in_error "Base de données déjà existante"
# return 1 # return 1
# fi # fi
} }
validate_wwwdomain() { validate_wwwdomain() {
wwwdomain=$1 wwwdomain=$1
if [ -z "$wwwdomain" ]; then if [ -z "$wwwdomain" ]; then
in_error "Le nom de domaine est obligatoire" in_error "Le nom de domaine est obligatoire"
return 1 return 1
fi fi
return 0 return 0
} }
validate_mail() { validate_mail() {
return 0 return 0
} }
validate_replmode() { validate_replmode() {
@ -191,23 +191,23 @@ validate_replinterval() {
} }
step_ok() { step_ok() {
msg=$1 msg=$1
echo "[OK] $msg" echo "[OK] $msg"
} }
create_www_accounts() { create_www_accounts() {
CMD_MASTER="$SSH -T $SSH_USER@$in_master" CMD_MASTER="$SSH -T $SSH_USER@$in_master"
CMD_SLAVE="$SSH -T $SSH_USER@$in_slave" CMD_SLAVE="$SSH -T $SSH_USER@$in_slave"
# On verifie que le compte n'existe pas sur master et slave # On verifie que le compte n'existe pas sur master et slave
if [ -n "$($CMD_MASTER cut -d: -f1 /etc/passwd| grep ^$in_login$)" ]; then if [ -n "$($CMD_MASTER cut -d: -f1 /etc/passwd| grep ^$in_login$)" ]; then
in_error "Le compte $in_login existe sur $in_master"; in_error "Le compte $in_login existe sur $in_master";
exit 1; exit 1;
fi fi
if [ $in_slave != "null" ]; then if [ $in_slave != "null" ]; then
if [ -n "$($CMD_SLAVE cut -d: -f1 /etc/passwd| grep ^$in_login$)" ]; then if [ -n "$($CMD_SLAVE cut -d: -f1 /etc/passwd| grep ^$in_login$)" ]; then
@ -217,13 +217,13 @@ create_www_accounts() {
fi fi
# Trouver un UID valide et commun pour le compte cree sur Master et Slave # Trouver un UID valide et commun pour le compte cree sur Master et Slave
last_uid_master=$($CMD_MASTER $LAST_UID) last_uid_master=$($CMD_MASTER $LAST_UID)
if [ -z "$last_uid_master" ]; then if [ -z "$last_uid_master" ]; then
echo "error while fetching uid in master"; echo "error while fetching uid in master";
return 1 return 1
fi fi
if [ $in_slave != "null" ]; then if [ $in_slave != "null" ]; then
last_uid_slave=$($CMD_SLAVE $LAST_UID) last_uid_slave=$($CMD_SLAVE $LAST_UID)
@ -247,19 +247,19 @@ create_www_accounts() {
uid=$(($last_uid_master + 1)) uid=$(($last_uid_master + 1))
fi fi
echo "UID libre: $uid" echo "UID libre: $uid"
# options mysql # options mysql
opts_mysql=''; opts_mysql='';
[ -n "$in_dbname" ] && opts_mysql="-m $in_dbname -P '$in_dbpasswd'" [ -n "$in_dbname" ] && opts_mysql="-m $in_dbname -P '$in_dbpasswd'"
# Creation web account on Master # Creation web account on Master
echo "MASTER: $CMD_MASTER $WEBADD add -p '$in_passwd' $opts_mysql -l $in_mail -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain" echo "MASTER: $CMD_MASTER $WEBADD add -p '$in_passwd' $opts_mysql -l $in_mail -y -u $uid -g $uid -U $(($uid + 1)) $in_login $in_wwwdomain"
$CMD_MASTER $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 master sur $in_master: $?" && exit 1) $CMD_MASTER $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 master sur $in_master: $?" && exit 1)
# Creation web account on Slave # Creation web account on Slave
if [ $in_slave != "null" ]; then if [ $in_slave != "null" ]; then
@ -334,10 +334,10 @@ ENDSSH
sudo -u $in_login lsyncd ~$in_login/www $in_slave:www sudo -u $in_login lsyncd ~$in_login/www $in_slave:www
ENDSSH ENDSSH
# Pour les mails # Pour les mails
# La réplication se fait au niveau du domaine (réplication de tout # La réplication se fait au niveau du domaine (réplication de tout
# /home/vmail/example.com/). # /home/vmail/example.com/).
domain=$(remove_subdomain $wwwdomain) domain=$(remove_subdomain $wwwdomain)
$CMD_MASTER <<ENDSSH $CMD_MASTER <<ENDSSH
if [ ! -d ~$VMAIL_USER/$domain ]; then if [ ! -d ~$VMAIL_USER/$domain ]; then
mkdir ~$VMAIL_USER/$domain mkdir ~$VMAIL_USER/$domain
chown $VMAIL_USER:$VMAIL_USER ~$VMAIL_USER/$domain chown $VMAIL_USER:$VMAIL_USER ~$VMAIL_USER/$domain
@ -400,18 +400,18 @@ ENDSSH
} }
op_del() { op_del() {
if [ $# -lt 3 ]; then if [ $# -lt 3 ]; then
usage usage
exit 1 exit 1
else else
login=$1 login=$1
master=$2 master=$2
slave=$3 slave=$3
if [ $# -eq 4 ]; then if [ $# -eq 4 ]; then
dbname=$4 dbname=$4
fi fi
fi fi
if [ $slave != "null" ]; then if [ $slave != "null" ]; then
echo "Deleting account $login on $master and $slave. Continue ?" echo "Deleting account $login on $master and $slave. Continue ?"
@ -420,14 +420,14 @@ op_del() {
fi fi
read read
CMD_MASTER="$SSH $SSH_USER@$master" CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave" CMD_SLAVE="$SSH $SSH_USER@$slave"
# check account exist on master and slave # check account exist on master and slave
if [ -z "$($CMD_MASTER cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then if [ -z "$($CMD_MASTER cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then
echo "Account $login doesn't exist on $master"; echo "Account $login doesn't exist on $master";
exit 1; exit 1;
fi fi
if [ $slave != "null" ]; then if [ $slave != "null" ]; then
if [ -z "$($CMD_SLAVE cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then if [ -z "$($CMD_SLAVE cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then
@ -436,12 +436,12 @@ op_del() {
fi fi
fi fi
yes | $CMD_MASTER $WEBADD del $login $dbname yes | $CMD_MASTER $WEBADD del $login $dbname
if [ $slave != "null" ]; then if [ $slave != "null" ]; then
yes | $CMD_SLAVE $WEBADD del $login $dbname yes | $CMD_SLAVE $WEBADD del $login $dbname
fi fi
DATE=$(date +"%Y-%m-%d") DATE=$(date +"%Y-%m-%d")
if [ $slave != "null" ]; then if [ $slave != "null" ]; then
echo "$DATE [web-add-cluster.sh] $login deleted from $master and $slave" >> /var/log/evolix.log echo "$DATE [web-add-cluster.sh] $login deleted from $master and $slave" >> /var/log/evolix.log
else else
@ -460,8 +460,8 @@ op_aliasadd() {
master=$3 master=$3
slave=$4 slave=$4
CMD_MASTER="$SSH $SSH_USER@$master" CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave" CMD_SLAVE="$SSH $SSH_USER@$slave"
$CMD_MASTER $WEBADD add-alias $vhost $alias $CMD_MASTER $WEBADD add-alias $vhost $alias
@ -469,7 +469,7 @@ op_aliasadd() {
$CMD_SLAVE $WEBADD add-alias $vhost $alias $CMD_SLAVE $WEBADD add-alias $vhost $alias
fi fi
DATE=$(date +"%Y-%m-%d") DATE=$(date +"%Y-%m-%d")
if [ $slave != "null" ]; then if [ $slave != "null" ]; then
echo "$DATE [web-add-cluster.sh] $alias added to $vhost on $master and $slave" >> /var/log/evolix.log echo "$DATE [web-add-cluster.sh] $alias added to $vhost on $master and $slave" >> /var/log/evolix.log
else else
@ -488,8 +488,8 @@ op_aliasdel() {
master=$3 master=$3
slave=$4 slave=$4
CMD_MASTER="$SSH $SSH_USER@$master" CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave" CMD_SLAVE="$SSH $SSH_USER@$slave"
$CMD_MASTER $WEBADD del-alias $vhost $alias $CMD_MASTER $WEBADD del-alias $vhost $alias
@ -497,7 +497,7 @@ op_aliasdel() {
$CMD_SLAVE $WEBADD del-alias $vhost $alias $CMD_SLAVE $WEBADD del-alias $vhost $alias
fi fi
DATE=$(date +"%Y-%m-%d") DATE=$(date +"%Y-%m-%d")
if [ $slave != "null" ]; then if [ $slave != "null" ]; then
echo "$DATE [web-add-cluster.sh] $alias deleted from $vhost on $master and $slave" >> /var/log/evolix.log echo "$DATE [web-add-cluster.sh] $alias deleted from $vhost on $master and $slave" >> /var/log/evolix.log
else else
@ -509,148 +509,148 @@ op_aliasdel() {
arg_processing() { arg_processing() {
# Détermination de la commande # Détermination de la commande
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
usage usage
else else
commandname=$1 commandname=$1
shift shift
case "$commandname" in case "$commandname" in
add) add)
op_add $* op_add $*
;; ;;
del) del)
op_del $* op_del $*
;; ;;
list-vhost) list-vhost)
op_listvhost $* op_listvhost $*
;; ;;
add-alias) add-alias)
op_aliasadd $* op_aliasadd $*
;; ;;
del-alias) del-alias)
op_aliasdel $* op_aliasdel $*
;; ;;
*) *)
usage usage
;; ;;
esac esac
fi fi
} }
op_listvhost() { op_listvhost() {
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
configlist="$VHOST_PATH/$1"; configlist="$VHOST_PATH/$1";
else else
configlist="$VHOST_PATH/*"; configlist="$VHOST_PATH/*";
fi fi
for configfile in $configlist; do for configfile in $configlist; do
if [ -r "$configfile" ]; then if [ -r "$configfile" ]; then
servername=`awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' $configfile | head -n 1` servername=`awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' $configfile | head -n 1`
serveraliases=`perl -ne 'print $1 if /^[[:space:]]*ServerAlias (.*)/' $configfile | head -n 1` serveraliases=`perl -ne 'print $1 if /^[[:space:]]*ServerAlias (.*)/' $configfile | head -n 1`
serveraliases=`echo $serveraliases | sed 's/ \+/, /g'` serveraliases=`echo $serveraliases | sed 's/ \+/, /g'`
userid=`awk '/^[[:space:]]*AssignUserID.*/ { print $3 }' $configfile | head -n 1` userid=`awk '/^[[:space:]]*AssignUserID.*/ { print $3 }' $configfile | head -n 1`
if [ "$servername" ] && [ "$userid" ]; then if [ "$servername" ] && [ "$userid" ]; then
configid=`basename $configfile` configid=`basename $configfile`
echo "$userid:$configid:$servername:$serveraliases" echo "$userid:$configid:$servername:$serveraliases"
fi fi
fi fi
done done
} }
op_add() { op_add() {
while getopts hyp:m:P:s:l:f:c: opt; do while getopts hyp:m:P:s:l:f:c: opt; do
case "$opt" in case "$opt" in
p) p)
in_passwd=$OPTARG in_passwd=$OPTARG
;; ;;
m) m)
in_dbname=$OPTARG in_dbname=$OPTARG
;; ;;
P) P)
in_dbpasswd=$OPTARG in_dbpasswd=$OPTARG
;; ;;
l) l)
in_mail=$OPTARG in_mail=$OPTARG
;; ;;
f) f)
in_replinterval=$OPTARG in_replinterval=$OPTARG
;; ;;
c) c)
in_replunit=$OPTARG in_replunit=$OPTARG
;; ;;
h) h)
usage usage
exit 1 exit 1
;; ;;
?) ?)
usage usage
exit 1 exit 1
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -ne 5 ]; then if [ $# -ne 5 ]; then
usage usage
exit 1 exit 1
fi fi
in_login=$1 in_login=$1
in_wwwdomain=$2 in_wwwdomain=$2
in_master=$3 in_master=$3
in_slave=$4 in_slave=$4
in_replmode=$5 in_replmode=$5
# in_master doit etre different d'in_slave # in_master doit etre different d'in_slave
[ "$in_master" = "$in_slave" ] && in_slave="null"; [ "$in_master" = "$in_slave" ] && in_slave="null";
validate_login $in_login || exit 1 validate_login $in_login || exit 1
[ -z "$in_passwd" ] && in_passwd=`gen_random_passwd` [ -z "$in_passwd" ] && in_passwd=`gen_random_passwd`
validate_passwd $in_passwd || exit 1 validate_passwd $in_passwd || exit 1
if [ -n "$in_dbname" ]; then if [ -n "$in_dbname" ]; then
validate_dbname $in_dbname || exit 1 validate_dbname $in_dbname || exit 1
if [ -z "$in_dbpasswd" ]; then if [ -z "$in_dbpasswd" ]; then
in_dbpasswd=`gen_random_passwd` in_dbpasswd=`gen_random_passwd`
validate_passwd $in_dbpasswd || exit 1 validate_passwd $in_dbpasswd || exit 1
echo "validate mysql passwd $in_dbpasswd"; echo "validate mysql passwd $in_dbpasswd";
fi fi
echo " ? validate mysql passwd $in_dbpasswd"; echo " ? validate mysql passwd $in_dbpasswd";
fi fi
validate_wwwdomain $in_wwwdomain || exit 1 validate_wwwdomain $in_wwwdomain || exit 1
[ -z "$in_mail" ] && in_mail=$CONTACT_MAIL [ -z "$in_mail" ] && in_mail=$CONTACT_MAIL
validate_mail $in_mail || exit 1 validate_mail $in_mail || exit 1
validate_replmode $in_replmode || exit 1 validate_replmode $in_replmode || exit 1
if [ $in_replmode = "deferred" ]; then if [ $in_replmode = "deferred" ]; then
validate_replinterval $in_replinterval $in_replunit || exit 1 validate_replinterval $in_replinterval $in_replunit || exit 1
fi fi
echo echo
echo "----------------------------------------------" echo "----------------------------------------------"
echo "Nom du compte : $in_login" echo "Nom du compte : $in_login"
echo "Mot de passe : $in_passwd" echo "Mot de passe : $in_passwd"
if [ -n "$in_dbname" ]; then if [ -n "$in_dbname" ]; then
echo "Base de données MySQL : $in_dbname" echo "Base de données MySQL : $in_dbname"
echo "Mot de passe MySQL : $in_dbpasswd" echo "Mot de passe MySQL : $in_dbpasswd"
fi fi
echo "Nom de domaine : $in_wwwdomain" echo "Nom de domaine : $in_wwwdomain"
echo "IP compte master : $in_master" echo "IP compte master : $in_master"
echo "IP compte slave : $in_slave" echo "IP compte slave : $in_slave"
echo "Mode de replication : $in_replmode" echo "Mode de replication : $in_replmode"
echo "Envoi du mail récapitulatif à : $in_mail" echo "Envoi du mail récapitulatif à : $in_mail"
echo "----------------------------------------------" echo "----------------------------------------------"
echo echo
create_www_accounts create_www_accounts
echo echo
echo " => Compte $in_login créé avec succès" echo " => Compte $in_login créé avec succès"
echo echo
} }
remove_subdomain() { remove_subdomain() {

View File

@ -34,7 +34,7 @@ config_file="/etc/evolinux/web-add.conf"
[ -r $config_file ] && . $config_file [ -r $config_file ] && . $config_file
usage() { usage() {
cat <<EOT >&2 cat <<EOT >&2
Usage: $0 COMMAND [ARG] Usage: $0 COMMAND [ARG]
@ -97,8 +97,8 @@ EOT
# Affiche un message d'erreur de validation # Affiche un message d'erreur de validation
# #
in_error() { in_error() {
msg=$1 msg=$1
cat >&2 <<EOT cat >&2 <<EOT
*** ***
Erreur : $msg Erreur : $msg
*** ***
@ -106,334 +106,334 @@ EOT
} }
gen_random_passwd() { gen_random_passwd() {
apg -c /dev/urandom -n1 -E oOlL10\&\\\/\"\' apg -c /dev/urandom -n1 -E oOlL10\&\\\/\"\'
} }
validate_login() { validate_login() {
login=$1 login=$1
length=${#login} length=${#login}
if [ $length -lt 3 ]; then if [ $length -lt 3 ]; then
in_error "Le login doit contenir plus de 2 caracteres" in_error "Le login doit contenir plus de 2 caracteres"
return 1 return 1
fi fi
if [ $length -gt $MAX_LOGIN_CHAR ]; then if [ $length -gt $MAX_LOGIN_CHAR ]; then
in_error "Le login ne doit pas contenir plus de $MAX_LOGIN_CHAR caracteres" in_error "Le login ne doit pas contenir plus de $MAX_LOGIN_CHAR caracteres"
return 1 return 1
fi fi
} }
validate_passwd() { validate_passwd() {
passwd=$1 passwd=$1
length=${#passwd} length=${#passwd}
if [ $length -lt 6 ] && [ $length -gt 0 ]; then if [ $length -lt 6 ] && [ $length -gt 0 ]; then
in_error "Le mot de passe doit avoir au moins 6 caracteres" in_error "Le mot de passe doit avoir au moins 6 caracteres"
return 1 return 1
fi fi
} }
validate_dbname() { validate_dbname() {
dbname=$1 dbname=$1
if mysql -ss -e "show databases" | grep "^$dbname$" >/dev/null; then if mysql -ss -e "show databases" | grep "^$dbname$" >/dev/null; then
in_error "Base de données déjà existante" in_error "Base de données déjà existante"
return 1 return 1
fi fi
} }
validate_wwwdomain() { validate_wwwdomain() {
wwwdomain=$1 wwwdomain=$1
if [ -z "$wwwdomain" ]; then if [ -z "$wwwdomain" ]; then
in_error "Le nom de domaine est obligatoire" in_error "Le nom de domaine est obligatoire"
return 1 return 1
fi fi
return 0 return 0
} }
validate_mail() { validate_mail() {
return 0 return 0
} }
step_ok() { step_ok() {
msg=$1 msg=$1
echo "[OK] $msg" echo "[OK] $msg"
} }
create_www_account() { create_www_account() {
# Vérifications # Vérifications
for filetocheck in $TPL_VHOST $TPL_AWSTATS $TPL_MAIL; do for filetocheck in $TPL_VHOST $TPL_AWSTATS $TPL_MAIL; do
if [ ! -f $filetocheck ]; then if [ ! -f $filetocheck ]; then
in_error "Fichier inexistant : $filetocheck" in_error "Fichier inexistant : $filetocheck"
exit 1 exit 1
fi fi
done done
############################################################################ ############################################################################
if [ -f $PRE_LOCAL_SCRIPT ]; then if [ -f $PRE_LOCAL_SCRIPT ]; then
source $PRE_LOCAL_SCRIPT source $PRE_LOCAL_SCRIPT
fi fi
step_ok "Exécution du pre-script spécifique" step_ok "Exécution du pre-script spécifique"
############################################################################ ############################################################################
if [ -z "$HOME_DIR_USER" ]; then if [ -z "$HOME_DIR_USER" ]; then
HOME_DIR_USER="$HOME_DIR/$in_login" HOME_DIR_USER="$HOME_DIR/$in_login"
fi fi
############################################################################ ############################################################################
if [ -d "$HOME_DIR_USER" ]; then if [ -d "$HOME_DIR_USER" ]; then
in_error "Ce compte existe deja (ou il a mal été effacé)" in_error "Ce compte existe deja (ou il a mal été effacé)"
return 1 return 1
fi fi
############################################################################ ############################################################################
# Force UID GID if specified # Force UID GID if specified
[ -n "$in_uid" ] && OPT_UID="--uid" && OPT_UID_ARG="$in_uid" [ -n "$in_uid" ] && OPT_UID="--uid" && OPT_UID_ARG="$in_uid"
[ -n "$in_gid" ] && OPT_GID="--gid" && OPT_GID_ARG="$in_gid" [ -n "$in_gid" ] && OPT_GID="--gid" && OPT_GID_ARG="$in_gid"
[ -n "$in_wwwuid" ] && OPT_WWWUID="--uid" && OPT_WWWUID_ARG="$in_wwwuid" [ -n "$in_wwwuid" ] && OPT_WWWUID="--uid" && OPT_WWWUID_ARG="$in_wwwuid"
############################################################################ ############################################################################
/usr/sbin/adduser --gecos "User $in_login" --disabled-password "$in_login" --shell /bin/bash $OPT_UID $OPT_UID_ARG --force-badname --home "$HOME_DIR_USER" >/dev/null /usr/sbin/adduser --gecos "User $in_login" --disabled-password "$in_login" --shell /bin/bash $OPT_UID $OPT_UID_ARG --force-badname --home "$HOME_DIR_USER" >/dev/null
[ -z "$in_sshkey" ] && echo "$in_login:$in_passwd" | chpasswd --md5 [ -z "$in_sshkey" ] && echo "$in_login:$in_passwd" | chpasswd --md5
[ -z "$in_sshkey" ] || [ -n "$HOME_DIR_USER" ] && mkdir "$HOME_DIR_USER/.ssh" && echo "$in_sshkey" > "$HOME_DIR_USER/.ssh/authorized_keys" \ [ -z "$in_sshkey" ] || [ -n "$HOME_DIR_USER" ] && mkdir "$HOME_DIR_USER/.ssh" && echo "$in_sshkey" > "$HOME_DIR_USER/.ssh/authorized_keys" \
&& chmod -R u=rwX,g=,o= "$HOME_DIR_USER/.ssh/authorized_keys" && chown -R "$in_login":"$in_login" "$HOME_DIR_USER/.ssh" && chmod -R u=rwX,g=,o= "$HOME_DIR_USER/.ssh/authorized_keys" && chown -R "$in_login":"$in_login" "$HOME_DIR_USER/.ssh"
/usr/sbin/adduser --disabled-password --home $HOME_DIR_USER/www \ /usr/sbin/adduser --disabled-password --home $HOME_DIR_USER/www \
--no-create-home --shell /bin/false --gecos "WWW $in_login" www-$in_login $OPT_WWWUID $OPT_WWWUID_ARG --ingroup $in_login --force-badname >/dev/null --no-create-home --shell /bin/false --gecos "WWW $in_login" www-$in_login $OPT_WWWUID $OPT_WWWUID_ARG --ingroup $in_login --force-badname >/dev/null
sed -i "s/^AllowUsers .*/& $in_login/" /etc/ssh/sshd_config sed -i "s/^AllowUsers .*/& $in_login/" /etc/ssh/sshd_config
/etc/init.d/ssh reload /etc/init.d/ssh reload
step_ok "Création des utilisateurs" step_ok "Création des utilisateurs"
############################################################################ ############################################################################
echo "www-$login: $login" >> /etc/aliases echo "www-$login: $login" >> /etc/aliases
echo "$login: $WWWBOUNCE_MAIL" >> /etc/aliases echo "$login: $WWWBOUNCE_MAIL" >> /etc/aliases
newaliases newaliases
step_ok "Alias mail" step_ok "Alias mail"
############################################################################ ############################################################################
chmod 750 $HOME_DIR_USER/ chmod 750 $HOME_DIR_USER/
# Répertoires par défaut # Répertoires par défaut
mkdir -p $HOME_DIR_USER/{log,www,awstats} mkdir -p $HOME_DIR_USER/{log,www,awstats}
chown $in_login:$in_login $HOME_DIR_USER/www chown $in_login:$in_login $HOME_DIR_USER/www
chgrp $in_login $HOME_DIR_USER/{log,awstats} chgrp $in_login $HOME_DIR_USER/{log,awstats}
chmod 750 $HOME_DIR_USER/{log,www,awstats} chmod 750 $HOME_DIR_USER/{log,www,awstats}
# Ajout des logs par defaut # Ajout des logs par defaut
touch $HOME_DIR_USER/log/access.log touch $HOME_DIR_USER/log/access.log
touch $HOME_DIR_USER/log/error.log touch $HOME_DIR_USER/log/error.log
touch $HOME_DIR_USER/log/php.log touch $HOME_DIR_USER/log/php.log
chgrp $in_login $HOME_DIR_USER/log/access.log chgrp $in_login $HOME_DIR_USER/log/access.log
chgrp $in_login $HOME_DIR_USER/log/error.log chgrp $in_login $HOME_DIR_USER/log/error.log
chown www-$in_login:$in_login $HOME_DIR_USER/log/php.log chown www-$in_login:$in_login $HOME_DIR_USER/log/php.log
chmod 640 $HOME_DIR_USER/log/access.log chmod 640 $HOME_DIR_USER/log/access.log
chmod 640 $HOME_DIR_USER/log/error.log chmod 640 $HOME_DIR_USER/log/error.log
chmod 640 $HOME_DIR_USER/log/php.log chmod 640 $HOME_DIR_USER/log/php.log
step_ok "Création du répertoire personnel" step_ok "Création du répertoire personnel"
############################################################################ ############################################################################
random=$RANDOM random=$RANDOM
vhostfile="/etc/apache2/sites-available/${in_login}.conf" vhostfile="/etc/apache2/sites-available/${in_login}.conf"
cat $TPL_VHOST | \ cat $TPL_VHOST | \
sed -e "s/XXX/$in_login/g ; s/SERVERNAME/$in_wwwdomain/ ; s/RANDOM/$random/ ; s#HOME_DIR#$HOME_DIR#" >$vhostfile sed -e "s/XXX/$in_login/g ; s/SERVERNAME/$in_wwwdomain/ ; s/RANDOM/$random/ ; s#HOME_DIR#$HOME_DIR#" >$vhostfile
# On active aussi example.com si domaine commence par "www." comme www.example # On active aussi example.com si domaine commence par "www." comme www.example
if echo $in_wwwdomain | grep '^www.' > /dev/null; then if echo $in_wwwdomain | grep '^www.' > /dev/null; then
subweb=`echo $in_wwwdomain | sed -e "s/www.//"` subweb=`echo $in_wwwdomain | sed -e "s/www.//"`
sed -i -e "s/^\(.*\)#\(ServerAlias\).*$/\1\2 $subweb/" $vhostfile sed -i -e "s/^\(.*\)#\(ServerAlias\).*$/\1\2 $subweb/" $vhostfile
fi fi
a2ensite $in_login >/dev/null a2ensite $in_login >/dev/null
step_ok "Configuration d'Apache" step_ok "Configuration d'Apache"
############################################################################ ############################################################################
cat $TPL_AWSTATS | \ cat $TPL_AWSTATS | \
sed -e "s/XXX/$in_login/ ; s/SERVERNAME/$in_wwwdomain/ ; s#HOME_DIR#$HOME_DIR#" \ sed -e "s/XXX/$in_login/ ; s/SERVERNAME/$in_wwwdomain/ ; s#HOME_DIR#$HOME_DIR#" \
> /etc/awstats/awstats.$in_login.conf > /etc/awstats/awstats.$in_login.conf
chmod 644 /etc/awstats/awstats.$in_login.conf chmod 644 /etc/awstats/awstats.$in_login.conf
VAR=`grep -v "^#" /etc/cron.d/awstats |tail -1 | cut -d " " -f1` VAR=`grep -v "^#" /etc/cron.d/awstats |tail -1 | cut -d " " -f1`
if [ "$VAR" = "" ] || [ $VAR -ge 59 ]; then if [ "$VAR" = "" ] || [ $VAR -ge 59 ]; then
VAR=1 VAR=1
else else
VAR=$(($VAR +1)) VAR=$(($VAR +1))
fi fi
echo "$VAR * * * * root umask 033; [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.$in_login.conf -a -r $HOME_DIR_USER/log/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=$in_login -update >/dev/null" >> /etc/cron.d/awstats echo "$VAR * * * * root umask 033; [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.$in_login.conf -a -r $HOME_DIR_USER/log/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=$in_login -update >/dev/null" >> /etc/cron.d/awstats
step_ok "Activation d'Awstats" step_ok "Activation d'Awstats"
############################################################################ ############################################################################
if [ "$in_dbname" ]; then if [ "$in_dbname" ]; then
echo "CREATE DATABASE \`$in_dbname\` $MYSQL_CREATE_DB_OPTS;" | mysql echo "CREATE DATABASE \`$in_dbname\` $MYSQL_CREATE_DB_OPTS;" | mysql
echo "GRANT ALL PRIVILEGES ON \`$in_dbname\`.* TO \`$in_login\`@localhost IDENTIFIED BY '$in_dbpasswd';" | mysql echo "GRANT ALL PRIVILEGES ON \`$in_dbname\`.* TO \`$in_login\`@localhost IDENTIFIED BY '$in_dbpasswd';" | mysql
echo "FLUSH PRIVILEGES;" | mysql echo "FLUSH PRIVILEGES;" | mysql
my_cnf_file="$HOME_DIR_USER/.my.cnf" my_cnf_file="$HOME_DIR_USER/.my.cnf"
cat >$my_cnf_file <<-EOT cat >$my_cnf_file <<-EOT
[client] [client]
user = $in_login user = $in_login
password = "$in_dbpasswd" password = "$in_dbpasswd"
[mysql] [mysql]
database = $in_dbname database = $in_dbname
EOT EOT
chown $in_login $my_cnf_file chown $in_login $my_cnf_file
chmod 600 $my_cnf_file chmod 600 $my_cnf_file
step_ok "Création base de données et compte MySQL" step_ok "Création base de données et compte MySQL"
fi fi
############################################################################ ############################################################################
cat $TPL_MAIL | \ cat $TPL_MAIL | \
sed -e "s/LOGIN/$in_login/g ; s/SERVERNAME/$in_wwwdomain/ ; s/PASSE1/$in_passwd/ ; s/PASSE2/$in_dbpasswd/ ; s/RANDOM/$random/ ; s/QUOTA/$quota/ ; s/RCPTTO/$in_mail/ ; s/DBNAME/$in_dbname/ ; s#HOME_DIR#$HOME_DIR#"| \ sed -e "s/LOGIN/$in_login/g ; s/SERVERNAME/$in_wwwdomain/ ; s/PASSE1/$in_passwd/ ; s/PASSE2/$in_dbpasswd/ ; s/RANDOM/$random/ ; s/QUOTA/$quota/ ; s/RCPTTO/$in_mail/ ; s/DBNAME/$in_dbname/ ; s#HOME_DIR#$HOME_DIR#"| \
/usr/lib/sendmail -oi -t -f "$CONTACT_MAIL" /usr/lib/sendmail -oi -t -f "$CONTACT_MAIL"
step_ok "Envoi du mail récapitulatif" step_ok "Envoi du mail récapitulatif"
############################################################################ ############################################################################
if [ -f $LOCAL_SCRIPT ]; then if [ -f $LOCAL_SCRIPT ]; then
source $LOCAL_SCRIPT source $LOCAL_SCRIPT
fi fi
step_ok "Exécution du script spécifique" step_ok "Exécution du script spécifique"
############################################################################ ############################################################################
apache2ctl configtest 2>/dev/null apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null /etc/init.d/apache2 force-reload >/dev/null
step_ok "Rechargement d'Apache" step_ok "Rechargement d'Apache"
############################################################################ ############################################################################
DATE=$(date +"%Y-%m-%d") DATE=$(date +"%Y-%m-%d")
echo "$DATE [web-add.sh] Ajout $in_login" >> /var/log/evolix.log echo "$DATE [web-add.sh] Ajout $in_login" >> /var/log/evolix.log
} }
op_del() { op_del() {
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
usage usage
exit 1 exit 1
else else
login=$1 login=$1
if [ $# -eq 2 ]; then if [ $# -eq 2 ]; then
dbname=$2 dbname=$2
fi fi
fi fi
echo "Deleting account $login. Continue ?" echo "Deleting account $login. Continue ?"
read read
set -x set -x
userdel $login userdel $login
userdel www-$login userdel www-$login
groupdel $login groupdel $login
sed -i.bak "/^$login:/d" /etc/aliases sed -i.bak "/^$login:/d" /etc/aliases
sed -i.bak "/^www-$login:/d" /etc/aliases sed -i.bak "/^www-$login:/d" /etc/aliases
sed -i "s/^\(AllowUsers .*\)$login/\1/" /etc/ssh/sshd_config sed -i "s/^\(AllowUsers .*\)$login/\1/" /etc/ssh/sshd_config
/etc/init.d/ssh reload /etc/init.d/ssh reload
if [ -d "$HOME_DIR/$login" ]; then if [ -d "$HOME_DIR/$login" ]; then
mv -i $HOME_DIR/$login $HOME_DIR/$login.`date '+%Y%m%d-%H%M%S'`.bak mv -i $HOME_DIR/$login $HOME_DIR/$login.`date '+%Y%m%d-%H%M%S'`.bak
else else
echo "warning : $HOME_DIR/$login does not exist" echo "warning : $HOME_DIR/$login does not exist"
fi fi
a2dissite $login a2dissite $login
rm /etc/apache2/sites-available/$login.conf rm /etc/apache2/sites-available/$login.conf
rm /etc/awstats/awstats.$login.conf rm /etc/awstats/awstats.$login.conf
sed -i.bak "/-config=$login /d" /etc/cron.d/awstats sed -i.bak "/-config=$login /d" /etc/cron.d/awstats
apache2ctl configtest apache2ctl configtest
set +x set +x
if [ -n "$dbname" ]; then if [ -n "$dbname" ]; then
echo "Deleting mysql DATABASE $dbname and mysql user $login. Continue ?" echo "Deleting mysql DATABASE $dbname and mysql user $login. Continue ?"
read read
set -x set -x
echo "DROP DATABASE $dbname; delete from mysql.user where user='$login' ; FLUSH PRIVILEGES;" | mysql echo "DROP DATABASE $dbname; delete from mysql.user where user='$login' ; FLUSH PRIVILEGES;" | mysql
set +x set +x
fi fi
} }
arg_processing() { arg_processing() {
# Détermination de la commande # Détermination de la commande
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
usage usage
else else
commandname=$1 commandname=$1
shift shift
case "$commandname" in case "$commandname" in
add) add)
op_add $* op_add $*
;; ;;
del) del)
op_del $* op_del $*
;; ;;
list-vhost) list-vhost)
op_listvhost $* op_listvhost $*
;; ;;
add-alias) add-alias)
op_aliasadd $* op_aliasadd $*
;; ;;
del-alias) del-alias)
op_aliasdel $* op_aliasdel $*
;; ;;
*) *)
usage usage
;; ;;
esac esac
fi fi
} }
op_listvhost() { op_listvhost() {
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
configlist="$VHOST_PATH/$1"; configlist="$VHOST_PATH/$1";
else else
configlist="$VHOST_PATH/*"; configlist="$VHOST_PATH/*";
fi fi
for configfile in $configlist; do for configfile in $configlist; do
if [ -r "$configfile" ]; then if [ -r "$configfile" ]; then
servername=`awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' $configfile | head -n 1` servername=`awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' $configfile | head -n 1`
serveraliases=`perl -ne 'print $1 if /^[[:space:]]*ServerAlias (.*)/' $configfile | head -n 1` serveraliases=`perl -ne 'print $1 if /^[[:space:]]*ServerAlias (.*)/' $configfile | head -n 1`
serveraliases=`echo $serveraliases | sed 's/ \+/, /g'` serveraliases=`echo $serveraliases | sed 's/ \+/, /g'`
userid=`awk '/^[[:space:]]*AssignUserID.*/ { print $3 }' $configfile | head -n 1` userid=`awk '/^[[:space:]]*AssignUserID.*/ { print $3 }' $configfile | head -n 1`
if [ "$servername" ] && [ "$userid" ]; then if [ "$servername" ] && [ "$userid" ]; then
configid=`basename $configfile` configid=`basename $configfile`
echo "$userid:$configid:$servername:$serveraliases" echo "$userid:$configid:$servername:$serveraliases"
fi fi
fi fi
done done
} }
op_aliasadd() { op_aliasadd() {
@ -443,8 +443,8 @@ op_aliasadd() {
[ -f $VHOST_PATH/$vhost ] && sed -i -e "s/\(ServerName .*\)/\1\n\tServerAlias $alias/" $VHOST_PATH/$vhost --follow-symlinks [ -f $VHOST_PATH/$vhost ] && sed -i -e "s/\(ServerName .*\)/\1\n\tServerAlias $alias/" $VHOST_PATH/$vhost --follow-symlinks
apache2ctl configtest 2>/dev/null apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null /etc/init.d/apache2 force-reload >/dev/null
else usage else usage
fi fi
@ -457,8 +457,8 @@ op_aliasdel() {
[ -f $VHOST_PATH/$vhost ] && sed -i -e "/ServerAlias $alias/d" $VHOST_PATH/$vhost --follow-symlinks [ -f $VHOST_PATH/$vhost ] && sed -i -e "/ServerAlias $alias/d" $VHOST_PATH/$vhost --follow-symlinks
apache2ctl configtest 2>/dev/null apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null /etc/init.d/apache2 force-reload >/dev/null
else usage else usage
fi fi
@ -466,178 +466,178 @@ op_aliasdel() {
op_add() { op_add() {
# #
# Mode interactif # Mode interactif
# #
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
echo echo
echo "Ajout d'un compte WEB" echo "Ajout d'un compte WEB"
echo echo
until [ "$in_login" ]; do until [ "$in_login" ]; do
echo -n "Entrez le login du nouveau compte : " echo -n "Entrez le login du nouveau compte : "
read tmp read tmp
if validate_login "$tmp"; then if validate_login "$tmp"; then
in_login="$tmp" in_login="$tmp"
fi fi
done done
until [ "$in_passwd" ]; do until [ "$in_passwd" ]; do
echo -n "Entrez le mot de passe FTP/SFTP/SSH (ou vide pour aleatoire) : " echo -n "Entrez le mot de passe FTP/SFTP/SSH (ou vide pour aleatoire) : "
read -s tmp read -s tmp
echo echo
if [ -z "$tmp" ]; then if [ -z "$tmp" ]; then
tmp=`gen_random_passwd` tmp=`gen_random_passwd`
fi fi
if validate_passwd "$tmp"; then if validate_passwd "$tmp"; then
in_passwd="$tmp" in_passwd="$tmp"
fi fi
done done
echo -n "Voulez-vous aussi un compte/base MySQL ? [Y|n] " echo -n "Voulez-vous aussi un compte/base MySQL ? [Y|n] "
read confirm read confirm
if [ "$confirm" != "n" ] && [ "$confirm" != "N" ]; then if [ "$confirm" != "n" ] && [ "$confirm" != "N" ]; then
until [ "$in_dbname" ]; do until [ "$in_dbname" ]; do
echo -n "Entrez le nom de la base de donnees ($in_login par defaut) : " echo -n "Entrez le nom de la base de donnees ($in_login par defaut) : "
read tmp read tmp
if [ -z "$tmp" ]; then if [ -z "$tmp" ]; then
tmp=$in_login tmp=$in_login
fi fi
if validate_dbname "$tmp"; then if validate_dbname "$tmp"; then
in_dbname="$tmp" in_dbname="$tmp"
fi fi
done done
until [ "$in_dbpasswd" ]; do until [ "$in_dbpasswd" ]; do
echo -n "Entrez le mot de passe MySQL (ou vide pour aleatoire) : " echo -n "Entrez le mot de passe MySQL (ou vide pour aleatoire) : "
read -s tmp read -s tmp
echo echo
if [ -z "$tmp" ]; then if [ -z "$tmp" ]; then
tmp=`gen_random_passwd` tmp=`gen_random_passwd`
fi fi
if validate_passwd "$tmp"; then if validate_passwd "$tmp"; then
in_dbpasswd="$tmp" in_dbpasswd="$tmp"
fi fi
done done
fi fi
until [ "$in_wwwdomain" ]; do until [ "$in_wwwdomain" ]; do
echo -n "Entrez le nom de domaine web (ex: foo.example.com) : " echo -n "Entrez le nom de domaine web (ex: foo.example.com) : "
read tmp read tmp
if validate_wwwdomain "$tmp"; then if validate_wwwdomain "$tmp"; then
in_wwwdomain="$tmp" in_wwwdomain="$tmp"
fi fi
done done
until [ "$in_mail" ]; do until [ "$in_mail" ]; do
echo -n "Entrez votre adresse mail pour recevoir le mail de creation ($CONTACT_MAIL par défaut) : " echo -n "Entrez votre adresse mail pour recevoir le mail de creation ($CONTACT_MAIL par défaut) : "
read tmp read tmp
if [ -z "$tmp" ]; then if [ -z "$tmp" ]; then
tmp="$CONTACT_MAIL" tmp="$CONTACT_MAIL"
fi fi
if validate_mail "$tmp"; then if validate_mail "$tmp"; then
in_mail="$tmp" in_mail="$tmp"
fi fi
done done
# #
# Mode non interactif # Mode non interactif
# #
else else
while getopts hyp:m:P:w:l:k:u:g:U: opt; do while getopts hyp:m:P:w:l:k:u:g:U: opt; do
case "$opt" in case "$opt" in
p) p)
in_passwd=$OPTARG in_passwd=$OPTARG
;; ;;
m) m)
in_dbname=$OPTARG in_dbname=$OPTARG
;; ;;
P) P)
in_dbpasswd=$OPTARG in_dbpasswd=$OPTARG
;; ;;
l) l)
in_mail=$OPTARG in_mail=$OPTARG
;; ;;
k) k)
in_sshkey=$OPTARG in_sshkey=$OPTARG
;; ;;
y) y)
force_confirm=1 force_confirm=1
;; ;;
u) u)
in_uid=$OPTARG in_uid=$OPTARG
;; ;;
g) g)
in_gid=$OPTARG in_gid=$OPTARG
;; ;;
U) U)
in_wwwuid=$OPTARG in_wwwuid=$OPTARG
;; ;;
h) h)
usage usage
exit 1 exit 1
;; ;;
?) ?)
usage usage
exit 1 exit 1
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
usage usage
exit 1 exit 1
else else
in_login=$1 in_login=$1
in_wwwdomain=$2 in_wwwdomain=$2
validate_login $in_login || exit 1 validate_login $in_login || exit 1
[ -z "$in_passwd" ] && [ -z "$in_sshkey" ] && in_passwd=`gen_random_passwd` [ -z "$in_passwd" ] && [ -z "$in_sshkey" ] && in_passwd=`gen_random_passwd`
[ -z "$in_sshkey" ] && ( validate_passwd $in_passwd || exit 1 ) [ -z "$in_sshkey" ] && ( validate_passwd $in_passwd || exit 1 )
[ -n "$in_dbname" ] && ( validate_dbname $in_dbname || exit 1 ) [ -n "$in_dbname" ] && ( validate_dbname $in_dbname || exit 1 )
[ -z "$in_dbpasswd" ] && [ -n "$in_dbname" ] && in_dbpasswd=`gen_random_passwd` [ -z "$in_dbpasswd" ] && [ -n "$in_dbname" ] && in_dbpasswd=`gen_random_passwd`
[ -n "$in_dbname" ] && ( validate_passwd $in_dbpasswd || exit 1 ) [ -n "$in_dbname" ] && ( validate_passwd $in_dbpasswd || exit 1 )
validate_wwwdomain $in_wwwdomain || exit 1 validate_wwwdomain $in_wwwdomain || exit 1
[ -z "$in_mail" ] && in_mail=$CONTACT_MAIL [ -z "$in_mail" ] && in_mail=$CONTACT_MAIL
validate_mail $in_mail || exit 1 validate_mail $in_mail || exit 1
fi fi
fi fi
echo echo
echo "----------------------------------------------" echo "----------------------------------------------"
echo "Nom du compte : $in_login" echo "Nom du compte : $in_login"
echo "Mot de passe : $in_passwd" echo "Mot de passe : $in_passwd"
if [ "$in_dbname" ]; then if [ "$in_dbname" ]; then
echo "Base de données MySQL : $in_dbname" echo "Base de données MySQL : $in_dbname"
echo "Mot de passe MySQL : $in_dbpasswd" echo "Mot de passe MySQL : $in_dbpasswd"
fi fi
echo "Nom de domaine : $in_wwwdomain" echo "Nom de domaine : $in_wwwdomain"
echo "Envoi du mail récapitulatif à : $in_mail" echo "Envoi du mail récapitulatif à : $in_mail"
echo "----------------------------------------------" echo "----------------------------------------------"
echo echo
if [ -z "$force_confirm" ]; then if [ -z "$force_confirm" ]; then
echo -n "Confirmer la création ? [y/N] : " echo -n "Confirmer la création ? [y/N] : "
read tmp read tmp
echo echo
if [ "$tmp" != "y" ] && [ "$tmp" != "Y" ]; then if [ "$tmp" != "y" ] && [ "$tmp" != "Y" ]; then
echo "Annulation..." echo "Annulation..."
echo echo
exit 1 exit 1
fi fi
fi fi
create_www_account create_www_account
echo echo
echo " => Compte $in_login créé avec succès" echo " => Compte $in_login créé avec succès"
echo echo
} }
# Point d'entrée # Point d'entrée

View File

@ -47,10 +47,10 @@
$vhost_info['server_name'], $vhost_info['server_name']); $vhost_info['server_name'], $vhost_info['server_name']);
if ($conf['cluster']) { if ($conf['cluster']) {
if (empty($vhost_info['bdd'])) if (empty($vhost_info['bdd']))
printf('<td bgcolor="#696969"/>'); printf('<td bgcolor="#696969"/>');
else else
printf('<td>%s</td>', $vhost_info['bdd']); printf('<td>%s</td>', $vhost_info['bdd']);
if (empty($vhost_info['mail'])) if (empty($vhost_info['mail']))
printf('<td bgcolor="#696969" />'); printf('<td bgcolor="#696969" />');
@ -61,16 +61,16 @@
if (empty($vhost_info['replication'])) if (empty($vhost_info['replication']))
printf('<td bgcolor="#696969"/>'); printf('<td bgcolor="#696969"/>');
else else
printf('<td>%s</td>', $vhost_info['replication']); printf('<td>%s</td>', $vhost_info['replication']);
printf('<td>%s</td>', $vhost_info['master']); printf('<td>%s</td>', $vhost_info['master']);
if (empty($vhost_info['slave'])) if (empty($vhost_info['slave']))
printf('<td bgcolor="#696969"/>'); printf('<td bgcolor="#696969"/>');
else else
printf('<td>%s</td>', $vhost_info['slave']); printf('<td>%s</td>', $vhost_info['slave']);
} }
else { else {
printf('<td>%s</td>', $vhost_info['server_alias']); printf('<td>%s</td>', $vhost_info['server_alias']);
} }
if (is_superadmin()) { if (is_superadmin()) {
printf('<td><a href="/webadmin/edit/%s">Lister/Modifier</a></td>', printf('<td><a href="/webadmin/edit/%s">Lister/Modifier</a></td>',
$vhost_info['owner']); $vhost_info['owner']);