Browse Source

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

web-add-support-nginx-and-apache
Gregory Colpart 3 years ago
parent
commit
2947fa2c87
15 changed files with 888 additions and 888 deletions
  1. +5
    -5
      bin/add_server.php
  2. +3
    -3
      bin/init_cache.php
  3. +5
    -5
      bin/list_domains.php
  4. +9
    -9
      htdocs/inc/js/ftpadmin.js
  5. +40
    -40
      inc/accounts.php
  6. +2
    -2
      inc/ftpadmin.php
  7. +44
    -44
      inc/webadmin.php
  8. +6
    -6
      lib/bdd.php
  9. +39
    -39
      scripts/check_cron_state.sh
  10. +23
    -23
      scripts/ftpadmin.sh
  11. +16
    -16
      scripts/stats.sh
  12. +3
    -3
      scripts/sync-master-to-slave.sh
  13. +213
    -213
      scripts/web-add-cluster.sh
  14. +467
    -467
      scripts/web-add.sh
  15. +13
    -13
      tpl/webadmin.tpl.php

+ 5
- 5
bin/add_server.php View File

@@ -9,9 +9,9 @@ $file = '';
$server = '';
if (is_mcluster_mode()) {
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";
exit(1);
exit(1);
}
$file = str_replace('%cluster_name%', $argv[1], $conf['cache']);
$server = $argv[2];
@@ -19,7 +19,7 @@ if (is_mcluster_mode()) {
else {
if ($argc != 2) {
echo "Usage: $argv[0] <server>\n";
exit(1);
exit(1);
}
$file = $conf['cache'];
$server = $argv[1];
@@ -27,8 +27,8 @@ else {


if (!file_exists($file)) {
echo "$file doesn't exist\n";
exit(1);
echo "$file doesn't exist\n";
exit(1);
}

$bdd->open($file);


+ 3
- 3
bin/init_cache.php View File

@@ -18,12 +18,12 @@ foreach ($files as $file) {
$bdd = new bdd();

if (!file_exists($file)) {
$bdd->create($file);
$bdd->create($file);
echo "$file created.\n";
}
else {
echo "$file is already created.\n";
continue;
echo "$file is already created.\n";
continue;
}
}



+ 5
- 5
bin/list_domains.php View File

@@ -7,23 +7,23 @@ $file = '';
$server = '';
if (is_mcluster_mode()) {
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";
exit(1);
exit(1);
}
$file = str_replace('%cluster_name%', $argv[1], $conf['cache']);
}
else {
if ($argc != 1) {
echo "Usage: $argv[0]\n";
exit(1);
exit(1);
}
$file = $conf['cache'];
}

if (!file_exists($file)) {
echo "$file is not created\n";
exit(1);
echo "$file is not created\n";
exit(1);
}

$bdd = new bdd();


+ 9
- 9
htdocs/inc/js/ftpadmin.js View File

@@ -2,18 +2,18 @@
// vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2

function fill_directory_field(value) {
if(document.forms['addftp'].path.value == '') {
document.forms['addftp'].path.value = value;
}
if(document.forms['addftp'].path.value == '') {
document.forms['addftp'].path.value = value;
}
}

function check_form_ftp_add() {
field_passwd = document.getElementById('passwd').value;
if(field_passwd.length < 6) {
alert('Le mot de passe doit contenir au moins 6 caractères ');
return false;
}
return true;
field_passwd = document.getElementById('passwd').value;
if(field_passwd.length < 6) {
alert('Le mot de passe doit contenir au moins 6 caractères ');
return false;
}
return true;
}

document.observe("dom:loaded", function() {


+ 40
- 40
inc/accounts.php View File

@@ -83,7 +83,7 @@ function web_add_cluster($form, $admin_mail) {
$exec_cmd = 'web-add-cluster.sh add';

$realtime=0;
/* array account with infos for sqlite cache */
$account = array();

@@ -194,21 +194,21 @@ function web_add_cluster($form, $admin_mail) {
/* insertion des infos dans le cache sqlite */
if ($exec_return == 0) {

$bdd=new bdd();
$bdd->open($cache);
$bdd=new bdd();
$bdd->open($cache);

$account['name'] = $form->getField('username')->getValue();
$account['domain'] = $form->getField('domain')->getValue();
$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);
$bdd->add_account($account);

$bdd->add_role($account['name'], $master, 'master');
if ($slave != "null");
$bdd->add_role($account['name'], $slave, 'slave');
$bdd->add_role($account['name'], $master, 'master');
if ($slave != "null");
$bdd->add_role($account['name'], $slave, 'slave');

if (substr_compare($account['domain'], 'www.', 0, strlen('www.')) == 0) {
$wwwalias = ltrim($account['domain'], 'www.');
@@ -337,37 +337,37 @@ $form->addField('use_gmail_mxs', new CheckboxInputFormField("Utilisation des ser

/* Traitement du formulaire */
if(!empty($_POST)) {
$form->isCurrentPage(TRUE);
$form->initFields();
/* Le champ password devient obligatoire si le champ password_random est
* décoché */
if(!$form->getField('password_random')->getValue()) {
$form->getField('password')->setMandatory(TRUE);
$form->getField('password')->setDisabled(FALSE);
}
/* Erreur si mysql_db est coché */
if($form->getField('mysql_db')->getValue()) {
$form->getField('mysql_dbname')->setMandatory(TRUE);
$form->getField('mysql_dbname')->setDisabled(FALSE);
$form->getField('mysql_password_random')->setDisabled(FALSE);
/* Le champ mysql_passwd devient obligatoire si le champ
* mysql_password_random est coché */
if(!$form->getField('mysql_password_random')->getValue()) {
$form->getField('mysql_password')->setMandatory(TRUE);
$form->getField('mysql_password')->setDisabled(FALSE);
}
}
/* Test de validation du formulaire */
if($form->verify(TRUE)) {
if ($conf['cluster'])
$exec_info = web_add_cluster($form, $conf['admin']['mail']);
else
$exec_info = web_add($form, $conf['admin']['mail']);
}
$form->isCurrentPage(TRUE);
$form->initFields();
/* Le champ password devient obligatoire si le champ password_random est
* décoché */
if(!$form->getField('password_random')->getValue()) {
$form->getField('password')->setMandatory(TRUE);
$form->getField('password')->setDisabled(FALSE);
}
/* Erreur si mysql_db est coché */
if($form->getField('mysql_db')->getValue()) {
$form->getField('mysql_dbname')->setMandatory(TRUE);
$form->getField('mysql_dbname')->setDisabled(FALSE);
$form->getField('mysql_password_random')->setDisabled(FALSE);
/* Le champ mysql_passwd devient obligatoire si le champ
* mysql_password_random est coché */
if(!$form->getField('mysql_password_random')->getValue()) {
$form->getField('mysql_password')->setMandatory(TRUE);
$form->getField('mysql_password')->setDisabled(FALSE);
}
}
/* Test de validation du formulaire */
if($form->verify(TRUE)) {
if ($conf['cluster'])
$exec_info = web_add_cluster($form, $conf['admin']['mail']);
else
$exec_info = web_add($form, $conf['admin']['mail']);
}
}

include_once EVOADMIN_BASE . '../tpl/header.tpl.php';


+ 2
- 2
inc/ftpadmin.php View File

@@ -200,13 +200,13 @@ if ($action=="add") {
$size_total += $infos[3];
$table[$num_line]['size'] = formatBytes($infos[3]);
} else {
$table[$num_line]['size'] = 0;
$table[$num_line]['size'] = 0;
}

if ($infos[4]>0) {
$table[$num_line]['date'] = date("d/m/Y h:i:s", $infos[4]);
} else {
$table[$num_line]['date'] = "01/01/1970";
$table[$num_line]['date'] = "01/01/1970";
}

$num_line++;


+ 44
- 44
inc/webadmin.php View File

@@ -21,23 +21,23 @@ global $conf;

if (!$conf['cluster']) {

$cmd = 'web-add.sh list-vhost';
if(!is_superadmin()) {
$cmd = sprintf('%s %s', $cmd, $_SESSION['user']);
}
sudoexec($cmd, $data_output, $exec_return);
/* Récupération de cette liste dans le tableau $vhost_list */
$vhost_list = array();
foreach($data_output as $data_line) {
$data_split = explode(':', $data_line);
array_push($vhost_list, array(
'owner' => $data_split[0],
'configid' => $data_split[1],
'server_name' => $data_split[2],
'server_alias' => $data_split[3])
);
}
$cmd = 'web-add.sh list-vhost';
if(!is_superadmin()) {
$cmd = sprintf('%s %s', $cmd, $_SESSION['user']);
}
sudoexec($cmd, $data_output, $exec_return);
/* Récupération de cette liste dans le tableau $vhost_list */
$vhost_list = array();
foreach($data_output as $data_line) {
$data_split = explode(':', $data_line);
array_push($vhost_list, array(
'owner' => $data_split[0],
'configid' => $data_split[1],
'server_name' => $data_split[2],
'server_alias' => $data_split[3])
);
}

}
else {
@@ -53,35 +53,35 @@ else {
$cache = $conf['cache'];
}

$vhost_list = array();
/* parcours de la table account */
$bdd=new bdd();
$bdd->open($cache);
$accounts = $bdd->list_accounts();
if (!empty($accounts)) {
foreach($accounts as $account) {
$master = $bdd->get_server_from_roleid($account['id_master']);
$slave = '';
if (!empty($account['id_slave']))
$slave = $bdd->get_server_from_roleid($account['id_slave']);
array_push($vhost_list, array(
'owner' => $account['name'],
'server_name'=> $account['domain'],
'bdd' => $account['bdd'],
$vhost_list = array();
/* parcours de la table account */
$bdd=new bdd();
$bdd->open($cache);
$accounts = $bdd->list_accounts();
if (!empty($accounts)) {
foreach($accounts as $account) {
$master = $bdd->get_server_from_roleid($account['id_master']);
$slave = '';
if (!empty($account['id_slave']))
$slave = $bdd->get_server_from_roleid($account['id_slave']);
array_push($vhost_list, array(
'owner' => $account['name'],
'server_name'=> $account['domain'],
'bdd' => $account['bdd'],
'mail' => $account['mail'],
'replication' => $account['replication'],
'master' => $master,
'slave' => $slave)
);
'replication' => $account['replication'],
'master' => $master,
'slave' => $slave)
);

}
}
}
}

}



+ 6
- 6
lib/bdd.php View File

@@ -132,7 +132,7 @@ class bdd {
return $row['name'];
}

return 0;
return 0;
}

/**
@@ -450,9 +450,9 @@ class bdd {

public function list_accounts()
{
$database = $this->db;
$database = $this->db;

$query = "SELECT * FROM Accounts";
$query = "SELECT * FROM Accounts";

$result = $database->query($query);
if ($result != FALSE)
@@ -474,12 +474,12 @@ class bdd {

public function list_serveralias($domain)
{
$database = $this->db;
$database = $this->db;
if ($domain == NULL)
return NULL;

$query = "SELECT * FROM Serveralias WHERE domain = '$domain'";
$query = "SELECT * FROM Serveralias WHERE domain = '$domain'";
$result = $database->query($query);
if ($result != FALSE)
@@ -501,7 +501,7 @@ class bdd {

public function is_serveralias($domain, $alias)
{
$database = $this->db;
$database = $this->db;
if ($domain == NULL)
return 0;


+ 39
- 39
scripts/check_cron_state.sh View File

@@ -9,7 +9,7 @@ LOGFILE=~/log/evocluster.log
MAIL="jdoe@example.com"

mail_error() {
echo "From: John Doe <jdoe@example.com>
echo "From: John Doe <jdoe@example.com>
To: $MAIL
Subject: [evocluster] check_cron_state.sh

@@ -52,45 +52,45 @@ fi


if [ "$STATE" = "slave" ]; then
info 'Account is in state slave, execution of cron is disabled'
exit 1
info 'Account is in state slave, execution of cron is disabled'
exit 1
else
# env var $FORCE_CRON is set to yes, execute the cron
[ "$FORCE_CRON" = "yes" ] && exit 0;
###  rajouter une règle sudo pour pouvoir exécuter ping ?
# test if the remote server is alive
#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"
# exit 1
#fi
###
# try to connect to the remote server and check if it isn't a master
REMOTE_STATE=$(mktemp)
if ssh $REMOTE_IP [ -e ~/state ]; then
ssh $REMOTE_IP cat ~/state >$REMOTE_STATE
elif [ $? -eq 255 ]; then
error "Failed to connect to slave ($REMOTE_IP)! I don't know what to do.."
exit 1
else
error "State file does not exist on slave !"
exit 1
fi
. $REMOTE_STATE
rm -rf $REMOTE_STATE
if [ -n "$STATE" ]; then
REMOTE_STATE=$STATE
else
error '$STATE not set in remote state file!'
exit 1
fi
if [ "$REMOTE_STATE" = "master" ]; then
error "Remote server $IP is master too. (incoherent state)..."
exit 1
fi
# env var $FORCE_CRON is set to yes, execute the cron
[ "$FORCE_CRON" = "yes" ] && exit 0;
###  rajouter une règle sudo pour pouvoir exécuter ping ?
# test if the remote server is alive
#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"
# exit 1
#fi
###
# try to connect to the remote server and check if it isn't a master
REMOTE_STATE=$(mktemp)
if ssh $REMOTE_IP [ -e ~/state ]; then
ssh $REMOTE_IP cat ~/state >$REMOTE_STATE
elif [ $? -eq 255 ]; then
error "Failed to connect to slave ($REMOTE_IP)! I don't know what to do.."
exit 1
else
error "State file does not exist on slave !"
exit 1
fi
. $REMOTE_STATE
rm -rf $REMOTE_STATE
if [ -n "$STATE" ]; then
REMOTE_STATE=$STATE
else
error '$STATE not set in remote state file!'
exit 1
fi
if [ "$REMOTE_STATE" = "master" ]; then
error "Remote server $IP is master too. (incoherent state)..."
exit 1
fi
fi

# Remote server is slave


+ 23
- 23
scripts/ftpadmin.sh View File

@@ -135,40 +135,40 @@ delete_account() {
while getopts a:u:n:f:p: opt; do
case "$opt" in
a)
in_action=$OPTARG
;;
in_action=$OPTARG
;;
u)
in_userid=$OPTARG
;;
in_userid=$OPTARG
;;
n)
in_accountname=$OPTARG
;;
in_accountname=$OPTARG
;;
f)
in_workpath=$OPTARG
;;
in_workpath=$OPTARG
;;
p)
in_password=$OPTARG
;;
in_password=$OPTARG
;;
esac
done

case "$in_action" in
l)
account_list=`list_accounts_by_UID $in_userid`
echo -e -n $account_list
exit 1
;;
account_list=`list_accounts_by_UID $in_userid`
echo -e -n $account_list
exit 1
;;
a)
echo -e -n `add_account $in_userid $in_accountname $in_workpath $in_password`
exit 1
;;
echo -e -n `add_account $in_userid $in_accountname $in_workpath $in_password`
exit 1
;;
m)
echo -e -n `edit_password $in_accountname $in_password`
exit 1;
;;
echo -e -n `edit_password $in_accountname $in_password`
exit 1;
;;
d)
echo -e -n `delete_account $in_accountname`
exit 1;
;;
echo -e -n `delete_account $in_accountname`
exit 1;
;;
esac


+ 16
- 16
scripts/stats.sh View File

@@ -2,22 +2,22 @@

for dir in `cat /etc/proftpd/vpasswd | cut -d : -f 6`; do
#for dir in /home/dalleFTP/reynaud_mila; do
if [ -d $dir ]; then
du -s $dir | cut -f 1 >$dir/.size
chmod 644 $dir/.size
if [ -d $dir ]; then
du -s $dir | cut -f 1 >$dir/.size
chmod 644 $dir/.size

#mtime=0
#export IFS=$'\n'
#for file in `find $dir -type f -not -name .size -not -name .last-modified`; do
# timestamp=`stat -c %Y $file`
# if [ $timestamp -gt $mtime ]; then
# mtime=$timestamp
# fi
#done
#unset IFS
#echo $mtime >$dir/.lastmodified
#chmod 644 $dir/.lastmodified
fi
#mtime=0
#export IFS=$'\n'
#for file in `find $dir -type f -not -name .size -not -name .last-modified`; do
# timestamp=`stat -c %Y $file`
# if [ $timestamp -gt $mtime ]; then
# mtime=$timestamp
# fi
#done
#unset IFS
#echo $mtime >$dir/.lastmodified
#chmod 644 $dir/.lastmodified
fi
done


+ 3
- 3
scripts/sync-master-to-slave.sh 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
REMOTE_STATE=$(mktemp)
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
error "failed to connect to slave ($REMOTE_IP)!"
exit 2
error "failed to connect to slave ($REMOTE_IP)!"
exit 2
else
error "state file does not exist on slave!"
exit 2


+ 213
- 213
scripts/web-add-cluster.sh View File

@@ -40,7 +40,7 @@ config_file="/etc/evolinux/web-add.conf"
[ -r $config_file ] && . $config_file

usage() {
cat <<EOT >&2
cat <<EOT >&2

Usage: $0 COMMAND [ARG]

@@ -97,8 +97,8 @@ EOT
# Affiche un message d'erreur de validation
#
in_error() {
msg=$1
cat >&2 <<EOT
msg=$1
cat >&2 <<EOT
***
Erreur : $msg
***
@@ -106,55 +106,55 @@ EOT
}

gen_random_passwd() {
apg -c /dev/urandom -n1 -E oOlL10\&\\\/\"\'
apg -c /dev/urandom -n1 -E oOlL10\&\\\/\"\'
}

validate_login() {
login=$1
length=${#login}
if [ $length -lt 3 ]; then
in_error "Le login doit contenir plus de 2 caracteres"
return 1
fi
if [ $length -gt $MAX_LOGIN_CHAR ]; then
in_error "Le login ne doit pas contenir plus de $MAX_LOGIN_CHAR caracteres"
return 1
fi
login=$1
length=${#login}
if [ $length -lt 3 ]; then
in_error "Le login doit contenir plus de 2 caracteres"
return 1
fi
if [ $length -gt $MAX_LOGIN_CHAR ]; then
in_error "Le login ne doit pas contenir plus de $MAX_LOGIN_CHAR caracteres"
return 1
fi
}

validate_passwd() {
passwd=$1
length=${#passwd}
passwd=$1
length=${#passwd}

if [ $length -lt 6 ] && [ $length -gt 0 ]; then
in_error "Le mot de passe doit avoir au moins 6 caracteres"
return 1
fi
if [ $length -lt 6 ] && [ $length -gt 0 ]; then
in_error "Le mot de passe doit avoir au moins 6 caracteres"
return 1
fi
}

validate_dbname() {
dbname=$1
dbname=$1
# aandre 18/06
# if mysql -ss -e "show databases" | grep "^$dbname$" >/dev/null; then
# in_error "Base de données déjà existante"
# return 1
# fi
# if mysql -ss -e "show databases" | grep "^$dbname$" >/dev/null; then
# in_error "Base de données déjà existante"
# return 1
# fi
}

validate_wwwdomain() {
wwwdomain=$1
if [ -z "$wwwdomain" ]; then
in_error "Le nom de domaine est obligatoire"
return 1
fi
return 0
wwwdomain=$1
if [ -z "$wwwdomain" ]; then
in_error "Le nom de domaine est obligatoire"
return 1
fi
return 0
}

validate_mail() {
return 0
return 0
}

validate_replmode() {
@@ -191,23 +191,23 @@ validate_replinterval() {
}

step_ok() {
msg=$1
echo "[OK] $msg"
msg=$1
echo "[OK] $msg"
}

create_www_accounts() {

CMD_MASTER="$SSH -T $SSH_USER@$in_master"
CMD_SLAVE="$SSH -T $SSH_USER@$in_slave"
CMD_MASTER="$SSH -T $SSH_USER@$in_master"
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
in_error "Le compte $in_login existe sur $in_master";
exit 1;
fi
if [ -n "$($CMD_MASTER cut -d: -f1 /etc/passwd| grep ^$in_login$)" ]; then
in_error "Le compte $in_login existe sur $in_master";
exit 1;
fi

if [ $in_slave != "null" ]; then
if [ -n "$($CMD_SLAVE cut -d: -f1 /etc/passwd| grep ^$in_login$)" ]; then
@@ -217,13 +217,13 @@ create_www_accounts() {
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)
if [ -z "$last_uid_master" ]; then
echo "error while fetching uid in master";
return 1
fi
last_uid_master=$($CMD_MASTER $LAST_UID)
if [ -z "$last_uid_master" ]; then
echo "error while fetching uid in master";
return 1
fi

if [ $in_slave != "null" ]; then
last_uid_slave=$($CMD_SLAVE $LAST_UID)
@@ -247,19 +247,19 @@ create_www_accounts() {
uid=$(($last_uid_master + 1))
fi

echo "UID libre: $uid"
echo "UID libre: $uid"

# options mysql
opts_mysql='';
[ -n "$in_dbname" ] && opts_mysql="-m $in_dbname -P '$in_dbpasswd'"
# options mysql
opts_mysql='';
[ -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
@@ -334,10 +334,10 @@ ENDSSH
sudo -u $in_login lsyncd ~$in_login/www $in_slave:www
ENDSSH
# Pour les mails
# La réplication se fait au niveau du domaine (réplication de tout
# /home/vmail/example.com/).
# La réplication se fait au niveau du domaine (réplication de tout
# /home/vmail/example.com/).
domain=$(remove_subdomain $wwwdomain)
$CMD_MASTER <<ENDSSH
$CMD_MASTER <<ENDSSH
if [ ! -d ~$VMAIL_USER/$domain ]; then
mkdir ~$VMAIL_USER/$domain
chown $VMAIL_USER:$VMAIL_USER ~$VMAIL_USER/$domain
@@ -400,18 +400,18 @@ ENDSSH
}

op_del() {
if [ $# -lt 3 ]; then
usage
exit 1
else
login=$1
master=$2
slave=$3
if [ $# -eq 4 ]; then
dbname=$4
fi
fi
if [ $# -lt 3 ]; then
usage
exit 1
else
login=$1
master=$2
slave=$3
if [ $# -eq 4 ]; then
dbname=$4
fi
fi

if [ $slave != "null" ]; then
echo "Deleting account $login on $master and $slave. Continue ?"
@@ -420,14 +420,14 @@ op_del() {
fi
read

CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave"
CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave"

# check account exist on master and slave
if [ -z "$($CMD_MASTER cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then
echo "Account $login doesn't exist on $master";
exit 1;
fi
# check account exist on master and slave
if [ -z "$($CMD_MASTER cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then
echo "Account $login doesn't exist on $master";
exit 1;
fi
if [ $slave != "null" ]; then
if [ -z "$($CMD_SLAVE cut -d: -f1 /etc/passwd| grep ^$login$)" ]; then
@@ -436,12 +436,12 @@ op_del() {
fi
fi

yes | $CMD_MASTER $WEBADD del $login $dbname
yes | $CMD_MASTER $WEBADD del $login $dbname
if [ $slave != "null" ]; then
yes | $CMD_SLAVE $WEBADD del $login $dbname
fi

DATE=$(date +"%Y-%m-%d")
DATE=$(date +"%Y-%m-%d")
if [ $slave != "null" ]; then
echo "$DATE [web-add-cluster.sh] $login deleted from $master and $slave" >> /var/log/evolix.log
else
@@ -460,8 +460,8 @@ op_aliasadd() {
master=$3
slave=$4

CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave"
CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave"
$CMD_MASTER $WEBADD add-alias $vhost $alias

@@ -469,7 +469,7 @@ op_aliasadd() {
$CMD_SLAVE $WEBADD add-alias $vhost $alias
fi

DATE=$(date +"%Y-%m-%d")
DATE=$(date +"%Y-%m-%d")
if [ $slave != "null" ]; then
echo "$DATE [web-add-cluster.sh] $alias added to $vhost on $master and $slave" >> /var/log/evolix.log
else
@@ -488,8 +488,8 @@ op_aliasdel() {
master=$3
slave=$4

CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave"
CMD_MASTER="$SSH $SSH_USER@$master"
CMD_SLAVE="$SSH $SSH_USER@$slave"
$CMD_MASTER $WEBADD del-alias $vhost $alias

@@ -497,7 +497,7 @@ op_aliasdel() {
$CMD_SLAVE $WEBADD del-alias $vhost $alias
fi

DATE=$(date +"%Y-%m-%d")
DATE=$(date +"%Y-%m-%d")
if [ $slave != "null" ]; then
echo "$DATE [web-add-cluster.sh] $alias deleted from $vhost on $master and $slave" >> /var/log/evolix.log
else
@@ -509,148 +509,148 @@ op_aliasdel() {

arg_processing() {

# Détermination de la commande
if [ $# -lt 1 ]; then
usage
else
commandname=$1
shift
case "$commandname" in
add)
op_add $*
;;
del)
op_del $*
;;
list-vhost)
op_listvhost $*
;;
# Détermination de la commande
if [ $# -lt 1 ]; then
usage
else
commandname=$1
shift
case "$commandname" in
add)
op_add $*
;;
del)
op_del $*
;;
list-vhost)
op_listvhost $*
;;
add-alias)
op_aliasadd $*
;;
del-alias)
op_aliasdel $*
;;
*)
usage
;;
esac
fi
*)
usage
;;
esac
fi
}

op_listvhost() {
if [ $# -eq 1 ]; then
configlist="$VHOST_PATH/$1";
else
configlist="$VHOST_PATH/*";
fi
for configfile in $configlist; do
if [ -r "$configfile" ]; then
servername=`awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' $configfile | head -n 1`
serveraliases=`perl -ne 'print $1 if /^[[:space:]]*ServerAlias (.*)/' $configfile | head -n 1`
serveraliases=`echo $serveraliases | sed 's/ \+/, /g'`
userid=`awk '/^[[:space:]]*AssignUserID.*/ { print $3 }' $configfile | head -n 1`
if [ "$servername" ] && [ "$userid" ]; then
configid=`basename $configfile`
echo "$userid:$configid:$servername:$serveraliases"
fi
fi
done
if [ $# -eq 1 ]; then
configlist="$VHOST_PATH/$1";
else
configlist="$VHOST_PATH/*";
fi
for configfile in $configlist; do
if [ -r "$configfile" ]; then
servername=`awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' $configfile | head -n 1`
serveraliases=`perl -ne 'print $1 if /^[[:space:]]*ServerAlias (.*)/' $configfile | head -n 1`
serveraliases=`echo $serveraliases | sed 's/ \+/, /g'`
userid=`awk '/^[[:space:]]*AssignUserID.*/ { print $3 }' $configfile | head -n 1`
if [ "$servername" ] && [ "$userid" ]; then
configid=`basename $configfile`
echo "$userid:$configid:$servername:$serveraliases"
fi
fi
done
}

op_add() {
while getopts hyp:m:P:s:l:f:c: opt; do
case "$opt" in
p)
in_passwd=$OPTARG
;;
m)
in_dbname=$OPTARG
;;
P)
in_dbpasswd=$OPTARG
;;
l)
in_mail=$OPTARG
;;
f)
in_replinterval=$OPTARG
;;
c)
in_replunit=$OPTARG
;;
h)
usage
exit 1
;;
?)
usage
exit 1
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -ne 5 ]; then
usage
exit 1
fi
in_login=$1
in_wwwdomain=$2
in_master=$3
in_slave=$4
in_replmode=$5
# in_master doit etre different d'in_slave
[ "$in_master" = "$in_slave" ] && in_slave="null";
validate_login $in_login || exit 1
[ -z "$in_passwd" ] && in_passwd=`gen_random_passwd`
validate_passwd $in_passwd || exit 1
if [ -n "$in_dbname" ]; then
validate_dbname $in_dbname || exit 1
if [ -z "$in_dbpasswd" ]; then
in_dbpasswd=`gen_random_passwd`
validate_passwd $in_dbpasswd || exit 1
echo "validate mysql passwd $in_dbpasswd";
fi
echo " ? validate mysql passwd $in_dbpasswd";
fi
validate_wwwdomain $in_wwwdomain || exit 1
[ -z "$in_mail" ] && in_mail=$CONTACT_MAIL
validate_mail $in_mail || exit 1
while getopts hyp:m:P:s:l:f:c: opt; do
case "$opt" in
p)
in_passwd=$OPTARG
;;
m)
in_dbname=$OPTARG
;;
P)
in_dbpasswd=$OPTARG
;;
l)
in_mail=$OPTARG
;;
f)
in_replinterval=$OPTARG
;;
c)
in_replunit=$OPTARG
;;
h)
usage
exit 1
;;
?)
usage
exit 1
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -ne 5 ]; then
usage
exit 1
fi
in_login=$1
in_wwwdomain=$2
in_master=$3
in_slave=$4
in_replmode=$5
# in_master doit etre different d'in_slave
[ "$in_master" = "$in_slave" ] && in_slave="null";
validate_login $in_login || exit 1
[ -z "$in_passwd" ] && in_passwd=`gen_random_passwd`
validate_passwd $in_passwd || exit 1
if [ -n "$in_dbname" ]; then
validate_dbname $in_dbname || exit 1
if [ -z "$in_dbpasswd" ]; then
in_dbpasswd=`gen_random_passwd`
validate_passwd $in_dbpasswd || exit 1
echo "validate mysql passwd $in_dbpasswd";
fi
echo " ? validate mysql passwd $in_dbpasswd";
fi
validate_wwwdomain $in_wwwdomain || exit 1
[ -z "$in_mail" ] && in_mail=$CONTACT_MAIL
validate_mail $in_mail || exit 1
validate_replmode $in_replmode || exit 1
if [ $in_replmode = "deferred" ]; then
validate_replinterval $in_replinterval $in_replunit || exit 1
fi

echo
echo "----------------------------------------------"
echo "Nom du compte : $in_login"
echo "Mot de passe : $in_passwd"
if [ -n "$in_dbname" ]; then
echo "Base de données MySQL : $in_dbname"
echo "Mot de passe MySQL : $in_dbpasswd"
fi
echo "Nom de domaine : $in_wwwdomain"
echo "IP compte master : $in_master"
echo "IP compte slave : $in_slave"
echo "Mode de replication : $in_replmode"
echo "Envoi du mail récapitulatif à : $in_mail"
echo "----------------------------------------------"
echo
create_www_accounts
echo
echo " => Compte $in_login créé avec succès"
echo
echo
echo "----------------------------------------------"
echo "Nom du compte : $in_login"
echo "Mot de passe : $in_passwd"
if [ -n "$in_dbname" ]; then
echo "Base de données MySQL : $in_dbname"
echo "Mot de passe MySQL : $in_dbpasswd"
fi
echo "Nom de domaine : $in_wwwdomain"
echo "IP compte master : $in_master"
echo "IP compte slave : $in_slave"
echo "Mode de replication : $in_replmode"
echo "Envoi du mail récapitulatif à : $in_mail"
echo "----------------------------------------------"
echo
create_www_accounts
echo
echo " => Compte $in_login créé avec succès"
echo
}

remove_subdomain() {


+ 467
- 467
scripts/web-add.sh View File

@@ -34,7 +34,7 @@ config_file="/etc/evolinux/web-add.conf"
[ -r $config_file ] && . $config_file

usage() {
cat <<EOT >&2
cat <<EOT >&2

Usage: $0 COMMAND [ARG]

@@ -97,8 +97,8 @@ EOT
# Affiche un message d'erreur de validation
#
in_error() {
msg=$1
cat >&2 <<EOT
msg=$1
cat >&2 <<EOT
***
Erreur : $msg
***
@@ -106,334 +106,334 @@ EOT
}

gen_random_passwd() {
apg -c /dev/urandom -n1 -E oOlL10\&\\\/\"\'
apg -c /dev/urandom -n1 -E oOlL10\&\\\/\"\'
}

validate_login() {
login=$1
length=${#login}
if [ $length -lt 3 ]; then
in_error "Le login doit contenir plus de 2 caracteres"
return 1
fi
if [ $length -gt $MAX_LOGIN_CHAR ]; then
in_error "Le login ne doit pas contenir plus de $MAX_LOGIN_CHAR caracteres"
return 1
fi
login=$1
length=${#login}
if [ $length -lt 3 ]; then
in_error "Le login doit contenir plus de 2 caracteres"
return 1
fi
if [ $length -gt $MAX_LOGIN_CHAR ]; then
in_error "Le login ne doit pas contenir plus de $MAX_LOGIN_CHAR caracteres"
return 1
fi
}

validate_passwd() {
passwd=$1
length=${#passwd}
passwd=$1
length=${#passwd}

if [ $length -lt 6 ] && [ $length -gt 0 ]; then
in_error "Le mot de passe doit avoir au moins 6 caracteres"
return 1
fi
if [ $length -lt 6 ] && [ $length -gt 0 ]; then
in_error "Le mot de passe doit avoir au moins 6 caracteres"
return 1
fi
}

validate_dbname() {
dbname=$1
if mysql -ss -e "show databases" | grep "^$dbname$" >/dev/null; then
in_error "Base de données déjà existante"
return 1
fi
dbname=$1
if mysql -ss -e "show databases" | grep "^$dbname$" >/dev/null; then
in_error "Base de données déjà existante"
return 1
fi
}

validate_wwwdomain() {
wwwdomain=$1
if [ -z "$wwwdomain" ]; then
in_error "Le nom de domaine est obligatoire"
return 1
fi
return 0
wwwdomain=$1
if [ -z "$wwwdomain" ]; then
in_error "Le nom de domaine est obligatoire"
return 1
fi
return 0
}

validate_mail() {
return 0
return 0
}

step_ok() {
msg=$1
echo "[OK] $msg"
msg=$1
echo "[OK] $msg"
}

create_www_account() {

# Vérifications
for filetocheck in $TPL_VHOST $TPL_AWSTATS $TPL_MAIL; do
if [ ! -f $filetocheck ]; then
in_error "Fichier inexistant : $filetocheck"
exit 1
fi
done
############################################################################
if [ -f $PRE_LOCAL_SCRIPT ]; then
source $PRE_LOCAL_SCRIPT
fi
step_ok "Exécution du pre-script spécifique"
############################################################################
if [ -z "$HOME_DIR_USER" ]; then
HOME_DIR_USER="$HOME_DIR/$in_login"
fi
############################################################################
if [ -d "$HOME_DIR_USER" ]; then
in_error "Ce compte existe deja (ou il a mal été effacé)"
return 1
fi
############################################################################
# Force UID GID if specified
[ -n "$in_uid" ] && OPT_UID="--uid" && OPT_UID_ARG="$in_uid"
[ -n "$in_gid" ] && OPT_GID="--gid" && OPT_GID_ARG="$in_gid"
[ -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
[ -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" \
&& 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 \
--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
/etc/init.d/ssh reload
step_ok "Création des utilisateurs"
############################################################################
echo "www-$login: $login" >> /etc/aliases
echo "$login: $WWWBOUNCE_MAIL" >> /etc/aliases
newaliases
step_ok "Alias mail"
############################################################################
chmod 750 $HOME_DIR_USER/
# Répertoires par défaut
mkdir -p $HOME_DIR_USER/{log,www,awstats}
chown $in_login:$in_login $HOME_DIR_USER/www
chgrp $in_login $HOME_DIR_USER/{log,awstats}
chmod 750 $HOME_DIR_USER/{log,www,awstats}
# Ajout des logs par defaut
touch $HOME_DIR_USER/log/access.log
touch $HOME_DIR_USER/log/error.log
touch $HOME_DIR_USER/log/php.log
chgrp $in_login $HOME_DIR_USER/log/access.log
chgrp $in_login $HOME_DIR_USER/log/error.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/error.log
chmod 640 $HOME_DIR_USER/log/php.log
step_ok "Création du répertoire personnel"
############################################################################
random=$RANDOM
vhostfile="/etc/apache2/sites-available/${in_login}.conf"
cat $TPL_VHOST | \
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
if echo $in_wwwdomain | grep '^www.' > /dev/null; then
subweb=`echo $in_wwwdomain | sed -e "s/www.//"`
sed -i -e "s/^\(.*\)#\(ServerAlias\).*$/\1\2 $subweb/" $vhostfile
fi
a2ensite $in_login >/dev/null
step_ok "Configuration d'Apache"
############################################################################
cat $TPL_AWSTATS | \
sed -e "s/XXX/$in_login/ ; s/SERVERNAME/$in_wwwdomain/ ; s#HOME_DIR#$HOME_DIR#" \
> /etc/awstats/awstats.$in_login.conf
chmod 644 /etc/awstats/awstats.$in_login.conf
# Vérifications
for filetocheck in $TPL_VHOST $TPL_AWSTATS $TPL_MAIL; do
if [ ! -f $filetocheck ]; then
in_error "Fichier inexistant : $filetocheck"
exit 1
fi
done
############################################################################
if [ -f $PRE_LOCAL_SCRIPT ]; then
source $PRE_LOCAL_SCRIPT
fi
step_ok "Exécution du pre-script spécifique"
############################################################################
if [ -z "$HOME_DIR_USER" ]; then
HOME_DIR_USER="$HOME_DIR/$in_login"
fi
############################################################################
if [ -d "$HOME_DIR_USER" ]; then
in_error "Ce compte existe deja (ou il a mal été effacé)"
return 1
fi
############################################################################
# Force UID GID if specified
[ -n "$in_uid" ] && OPT_UID="--uid" && OPT_UID_ARG="$in_uid"
[ -n "$in_gid" ] && OPT_GID="--gid" && OPT_GID_ARG="$in_gid"
[ -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
[ -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" \
&& 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 \
--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
/etc/init.d/ssh reload
step_ok "Création des utilisateurs"
############################################################################
echo "www-$login: $login" >> /etc/aliases
echo "$login: $WWWBOUNCE_MAIL" >> /etc/aliases
newaliases
step_ok "Alias mail"
############################################################################
chmod 750 $HOME_DIR_USER/
# Répertoires par défaut
mkdir -p $HOME_DIR_USER/{log,www,awstats}
chown $in_login:$in_login $HOME_DIR_USER/www
chgrp $in_login $HOME_DIR_USER/{log,awstats}
chmod 750 $HOME_DIR_USER/{log,www,awstats}
# Ajout des logs par defaut
touch $HOME_DIR_USER/log/access.log
touch $HOME_DIR_USER/log/error.log
touch $HOME_DIR_USER/log/php.log
chgrp $in_login $HOME_DIR_USER/log/access.log
chgrp $in_login $HOME_DIR_USER/log/error.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/error.log
chmod 640 $HOME_DIR_USER/log/php.log
step_ok "Création du répertoire personnel"
############################################################################
random=$RANDOM
vhostfile="/etc/apache2/sites-available/${in_login}.conf"
cat $TPL_VHOST | \
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
if echo $in_wwwdomain | grep '^www.' > /dev/null; then
subweb=`echo $in_wwwdomain | sed -e "s/www.//"`
sed -i -e "s/^\(.*\)#\(ServerAlias\).*$/\1\2 $subweb/" $vhostfile
fi
a2ensite $in_login >/dev/null
step_ok "Configuration d'Apache"
############################################################################
cat $TPL_AWSTATS | \
sed -e "s/XXX/$in_login/ ; s/SERVERNAME/$in_wwwdomain/ ; s#HOME_DIR#$HOME_DIR#" \
> /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`
if [ "$VAR" = "" ] || [ $VAR -ge 59 ]; then
VAR=1
else
VAR=$(($VAR +1))
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
step_ok "Activation d'Awstats"
############################################################################
if [ "$in_dbname" ]; then
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 "FLUSH PRIVILEGES;" | mysql
my_cnf_file="$HOME_DIR_USER/.my.cnf"
cat >$my_cnf_file <<-EOT
[client]
user = $in_login
password = "$in_dbpasswd"
[mysql]
database = $in_dbname
EOT
chown $in_login $my_cnf_file
chmod 600 $my_cnf_file
step_ok "Création base de données et compte MySQL"
fi
############################################################################
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#"| \
/usr/lib/sendmail -oi -t -f "$CONTACT_MAIL"
step_ok "Envoi du mail récapitulatif"
############################################################################
if [ -f $LOCAL_SCRIPT ]; then
source $LOCAL_SCRIPT
fi
step_ok "Exécution du script spécifique"
############################################################################
apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null
step_ok "Rechargement d'Apache"
############################################################################
DATE=$(date +"%Y-%m-%d")
echo "$DATE [web-add.sh] Ajout $in_login" >> /var/log/evolix.log
if [ "$VAR" = "" ] || [ $VAR -ge 59 ]; then
VAR=1
else
VAR=$(($VAR +1))
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
step_ok "Activation d'Awstats"
############################################################################
if [ "$in_dbname" ]; then
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 "FLUSH PRIVILEGES;" | mysql
my_cnf_file="$HOME_DIR_USER/.my.cnf"
cat >$my_cnf_file <<-EOT
[client]
user = $in_login
password = "$in_dbpasswd"
[mysql]
database = $in_dbname
EOT
chown $in_login $my_cnf_file
chmod 600 $my_cnf_file
step_ok "Création base de données et compte MySQL"
fi
############################################################################
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#"| \
/usr/lib/sendmail -oi -t -f "$CONTACT_MAIL"
step_ok "Envoi du mail récapitulatif"
############################################################################
if [ -f $LOCAL_SCRIPT ]; then
source $LOCAL_SCRIPT
fi
step_ok "Exécution du script spécifique"
############################################################################
apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null
step_ok "Rechargement d'Apache"
############################################################################
DATE=$(date +"%Y-%m-%d")
echo "$DATE [web-add.sh] Ajout $in_login" >> /var/log/evolix.log
}

op_del() {
if [ $# -lt 1 ]; then
usage
exit 1
else
login=$1
if [ $# -eq 2 ]; then
dbname=$2
fi
fi
echo "Deleting account $login. Continue ?"
read
set -x
userdel $login
userdel www-$login
groupdel $login
sed -i.bak "/^$login:/d" /etc/aliases
sed -i.bak "/^www-$login:/d" /etc/aliases
sed -i "s/^\(AllowUsers .*\)$login/\1/" /etc/ssh/sshd_config
/etc/init.d/ssh reload
if [ -d "$HOME_DIR/$login" ]; then
mv -i $HOME_DIR/$login $HOME_DIR/$login.`date '+%Y%m%d-%H%M%S'`.bak
else
echo "warning : $HOME_DIR/$login does not exist"
fi
a2dissite $login
rm /etc/apache2/sites-available/$login.conf
rm /etc/awstats/awstats.$login.conf
sed -i.bak "/-config=$login /d" /etc/cron.d/awstats
apache2ctl configtest
set +x
if [ -n "$dbname" ]; then
echo "Deleting mysql DATABASE $dbname and mysql user $login. Continue ?"
read
set -x
echo "DROP DATABASE $dbname; delete from mysql.user where user='$login' ; FLUSH PRIVILEGES;" | mysql
set +x
fi
if [ $# -lt 1 ]; then
usage
exit 1
else
login=$1
if [ $# -eq 2 ]; then
dbname=$2
fi
fi
echo "Deleting account $login. Continue ?"
read
set -x
userdel $login
userdel www-$login
groupdel $login
sed -i.bak "/^$login:/d" /etc/aliases
sed -i.bak "/^www-$login:/d" /etc/aliases
sed -i "s/^\(AllowUsers .*\)$login/\1/" /etc/ssh/sshd_config
/etc/init.d/ssh reload
if [ -d "$HOME_DIR/$login" ]; then
mv -i $HOME_DIR/$login $HOME_DIR/$login.`date '+%Y%m%d-%H%M%S'`.bak
else
echo "warning : $HOME_DIR/$login does not exist"
fi
a2dissite $login
rm /etc/apache2/sites-available/$login.conf
rm /etc/awstats/awstats.$login.conf
sed -i.bak "/-config=$login /d" /etc/cron.d/awstats
apache2ctl configtest
set +x
if [ -n "$dbname" ]; then
echo "Deleting mysql DATABASE $dbname and mysql user $login. Continue ?"
read
set -x
echo "DROP DATABASE $dbname; delete from mysql.user where user='$login' ; FLUSH PRIVILEGES;" | mysql
set +x
fi
}

arg_processing() {

# Détermination de la commande
if [ $# -lt 1 ]; then
usage
else
commandname=$1
shift
case "$commandname" in
add)
op_add $*
;;
del)
op_del $*
;;
list-vhost)
op_listvhost $*
;;
# Détermination de la commande
if [ $# -lt 1 ]; then
usage
else
commandname=$1
shift
case "$commandname" in
add)
op_add $*
;;
del)
op_del $*
;;
list-vhost)
op_listvhost $*
;;
add-alias)
op_aliasadd $*
;;
del-alias)
op_aliasdel $*
;;
*)
usage
;;
esac
fi
*)
usage
;;
esac
fi
}

op_listvhost() {
if [ $# -eq 1 ]; then
configlist="$VHOST_PATH/$1";
else
configlist="$VHOST_PATH/*";
fi
for configfile in $configlist; do
if [ -r "$configfile" ]; then
servername=`awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' $configfile | head -n 1`
serveraliases=`perl -ne 'print $1 if /^[[:space:]]*ServerAlias (.*)/' $configfile | head -n 1`
serveraliases=`echo $serveraliases | sed 's/ \+/, /g'`
userid=`awk '/^[[:space:]]*AssignUserID.*/ { print $3 }' $configfile | head -n 1`
if [ "$servername" ] && [ "$userid" ]; then
configid=`basename $configfile`
echo "$userid:$configid:$servername:$serveraliases"
fi
fi
done
if [ $# -eq 1 ]; then
configlist="$VHOST_PATH/$1";
else
configlist="$VHOST_PATH/*";
fi
for configfile in $configlist; do
if [ -r "$configfile" ]; then
servername=`awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' $configfile | head -n 1`
serveraliases=`perl -ne 'print $1 if /^[[:space:]]*ServerAlias (.*)/' $configfile | head -n 1`
serveraliases=`echo $serveraliases | sed 's/ \+/, /g'`
userid=`awk '/^[[:space:]]*AssignUserID.*/ { print $3 }' $configfile | head -n 1`
if [ "$servername" ] && [ "$userid" ]; then
configid=`basename $configfile`
echo "$userid:$configid:$servername:$serveraliases"
fi
fi
done
}

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

apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null
apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null

else usage
fi
@@ -457,8 +457,8 @@ op_aliasdel() {

[ -f $VHOST_PATH/$vhost ] && sed -i -e "/ServerAlias $alias/d" $VHOST_PATH/$vhost --follow-symlinks

apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null
apache2ctl configtest 2>/dev/null
/etc/init.d/apache2 force-reload >/dev/null

else usage
fi
@@ -466,178 +466,178 @@ op_aliasdel() {

op_add() {

#
# Mode interactif
#
if [ $# -eq 0 ]; then
echo
echo "Ajout d'un compte WEB"
echo
until [ "$in_login" ]; do
echo -n "Entrez le login du nouveau compte : "
read tmp
if validate_login "$tmp"; then
in_login="$tmp"
fi
done
until [ "$in_passwd" ]; do
echo -n "Entrez le mot de passe FTP/SFTP/SSH (ou vide pour aleatoire) : "
read -s tmp
echo
if [ -z "$tmp" ]; then
tmp=`gen_random_passwd`
fi
if validate_passwd "$tmp"; then
in_passwd="$tmp"
fi
done
echo -n "Voulez-vous aussi un compte/base MySQL ? [Y|n] "
read confirm
if [ "$confirm" != "n" ] && [ "$confirm" != "N" ]; then
until [ "$in_dbname" ]; do
echo -n "Entrez le nom de la base de donnees ($in_login par defaut) : "
read tmp
if [ -z "$tmp" ]; then
tmp=$in_login
fi
if validate_dbname "$tmp"; then
in_dbname="$tmp"
fi
done
until [ "$in_dbpasswd" ]; do
echo -n "Entrez le mot de passe MySQL (ou vide pour aleatoire) : "
read -s tmp
echo
if [ -z "$tmp" ]; then
tmp=`gen_random_passwd`
fi
if validate_passwd "$tmp"; then
in_dbpasswd="$tmp"
fi
done
fi
until [ "$in_wwwdomain" ]; do
echo -n "Entrez le nom de domaine web (ex: foo.example.com) : "
read tmp
if validate_wwwdomain "$tmp"; then
in_wwwdomain="$tmp"
fi
done
until [ "$in_mail" ]; do
echo -n "Entrez votre adresse mail pour recevoir le mail de creation ($CONTACT_MAIL par défaut) : "
read tmp
if [ -z "$tmp" ]; then
tmp="$CONTACT_MAIL"
fi
if validate_mail "$tmp"; then
in_mail="$tmp"
fi
done
#
# Mode non interactif
#
else
while getopts hyp:m:P:w:l:k:u:g:U: opt; do
case "$opt" in
p)
in_passwd=$OPTARG
;;
m)
in_dbname=$OPTARG
;;
P)
in_dbpasswd=$OPTARG
;;
l)
in_mail=$OPTARG
;;
k)
in_sshkey=$OPTARG
;;
y)
force_confirm=1
;;
u)
in_uid=$OPTARG
;;
g)
in_gid=$OPTARG