From 2947fa2c8776679968f372848f42e4d876bad3c4 Mon Sep 17 00:00:00 2001 From: Gregory Colpart Date: Sun, 20 Aug 2017 04:31:00 +0200 Subject: [PATCH] =?UTF-8?q?NO=20CODE=20IN=C2=A0THIS=C2=A0COMMIT.=20ONLY=20?= =?UTF-8?q?:retab=20replacement=20aka=20remove-all-tabs-from-code=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/add_server.php | 10 +- bin/init_cache.php | 6 +- bin/list_domains.php | 10 +- htdocs/inc/js/ftpadmin.js | 18 +- inc/accounts.php | 72 +-- inc/ftpadmin.php | 4 +- inc/webadmin.php | 80 +-- lib/bdd.php | 12 +- scripts/check_cron_state.sh | 72 +-- scripts/ftpadmin.sh | 46 +- scripts/stats.sh | 32 +- scripts/sync-master-to-slave.sh | 6 +- scripts/web-add-cluster.sh | 408 +++++++-------- scripts/web-add.sh | 844 ++++++++++++++++---------------- tpl/webadmin.tpl.php | 26 +- 15 files changed, 823 insertions(+), 823 deletions(-) diff --git a/bin/add_server.php b/bin/add_server.php index c1bc90e..4b005ac 100644 --- a/bin/add_server.php +++ b/bin/add_server.php @@ -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] \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] \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); diff --git a/bin/init_cache.php b/bin/init_cache.php index 2c15389..d289f8f 100644 --- a/bin/init_cache.php +++ b/bin/init_cache.php @@ -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; } } diff --git a/bin/list_domains.php b/bin/list_domains.php index e9a1624..81f4ce8 100644 --- a/bin/list_domains.php +++ b/bin/list_domains.php @@ -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] \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(); diff --git a/htdocs/inc/js/ftpadmin.js b/htdocs/inc/js/ftpadmin.js index df4ff7c..37ff0ca 100644 --- a/htdocs/inc/js/ftpadmin.js +++ b/htdocs/inc/js/ftpadmin.js @@ -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() { diff --git a/inc/accounts.php b/inc/accounts.php index f6b4474..fdea281 100644 --- a/inc/accounts.php +++ b/inc/accounts.php @@ -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(); + $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); - } + /* 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); + /* 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); - } - } + /* 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']); - } + /* 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'; diff --git a/inc/ftpadmin.php b/inc/ftpadmin.php index bf87b40..f528318 100644 --- a/inc/ftpadmin.php +++ b/inc/ftpadmin.php @@ -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++; diff --git a/inc/webadmin.php b/inc/webadmin.php index bc0794d..e41cc19 100644 --- a/inc/webadmin.php +++ b/inc/webadmin.php @@ -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); + $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]) - ); - } + /* 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(); + $vhost_list = array(); - /* parcours de la table account */ - $bdd=new bdd(); - $bdd->open($cache); + /* parcours de la table account */ + $bdd=new bdd(); + $bdd->open($cache); - $accounts = $bdd->list_accounts(); + $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'], + 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) + ); - } - } + } + } } diff --git a/lib/bdd.php b/lib/bdd.php index 2132580..6784650 100644 --- a/lib/bdd.php +++ b/lib/bdd.php @@ -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; diff --git a/scripts/check_cron_state.sh b/scripts/check_cron_state.sh index 9e68154..b60d2e7 100755 --- a/scripts/check_cron_state.sh +++ b/scripts/check_cron_state.sh @@ -9,7 +9,7 @@ LOGFILE=~/log/evocluster.log MAIL="jdoe@example.com" mail_error() { - echo "From: John Doe + echo "From: John Doe 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 - ### + # 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 + # 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 + . $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 + if [ "$REMOTE_STATE" = "master" ]; then + error "Remote server $IP is master too. (incoherent state)..." + exit 1 + fi fi # Remote server is slave diff --git a/scripts/ftpadmin.sh b/scripts/ftpadmin.sh index 6e0df38..02c4dcf 100755 --- a/scripts/ftpadmin.sh +++ b/scripts/ftpadmin.sh @@ -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 diff --git a/scripts/stats.sh b/scripts/stats.sh index 36f7bcd..ed9f480 100755 --- a/scripts/stats.sh +++ b/scripts/stats.sh @@ -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 diff --git a/scripts/sync-master-to-slave.sh b/scripts/sync-master-to-slave.sh index 8eb6212..b5f1735 100755 --- a/scripts/sync-master-to-slave.sh +++ b/scripts/sync-master-to-slave.sh @@ -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 diff --git a/scripts/web-add-cluster.sh b/scripts/web-add-cluster.sh index cf32d99..02552de 100755 --- a/scripts/web-add-cluster.sh +++ b/scripts/web-add-cluster.sh @@ -40,7 +40,7 @@ config_file="/etc/evolinux/web-add.conf" [ -r $config_file ] && . $config_file usage() { - cat <&2 + cat <&2 Usage: $0 COMMAND [ARG] @@ -97,8 +97,8 @@ EOT # Affiche un message d'erreur de validation # in_error() { - msg=$1 - cat >&2 <&2 </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 <> /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 + 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 + 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 + 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 + 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_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"; + # 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 + 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 + 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_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() { diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 58e949d..afc1570 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -34,7 +34,7 @@ config_file="/etc/evolinux/web-add.conf" [ -r $config_file ] && . $config_file usage() { - cat <&2 + cat <&2 Usage: $0 COMMAND [ARG] @@ -97,8 +97,8 @@ EOT # Affiche un message d'erreur de validation # in_error() { - msg=$1 - cat >&2 <&2 </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 + # 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 + if [ -f $PRE_LOCAL_SCRIPT ]; then + source $PRE_LOCAL_SCRIPT + 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 - HOME_DIR_USER="$HOME_DIR/$in_login" - fi + 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 - - ############################################################################ + 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 + # 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" + [ -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 --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 + /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 + sed -i "s/^AllowUsers .*/& $in_login/" /etc/ssh/sshd_config + /etc/init.d/ssh reload - step_ok "Création des utilisateurs" + step_ok "Création des utilisateurs" - ############################################################################ + ############################################################################ - echo "www-$login: $login" >> /etc/aliases - echo "$login: $WWWBOUNCE_MAIL" >> /etc/aliases - newaliases + echo "www-$login: $login" >> /etc/aliases + echo "$login: $WWWBOUNCE_MAIL" >> /etc/aliases + newaliases - step_ok "Alias mail" + 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 + 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" + 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" + ############################################################################ + + 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 - + 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 + 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 + 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 - 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 + ############################################################################ + + 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 + 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 + 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" + ############################################################################ + + 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" + step_ok "Envoi du mail récapitulatif" - ############################################################################ + ############################################################################ - if [ -f $LOCAL_SCRIPT ]; then - source $LOCAL_SCRIPT - fi + if [ -f $LOCAL_SCRIPT ]; then + source $LOCAL_SCRIPT + fi - step_ok "Exécution du script spécifique" + step_ok "Exécution du script spécifique" - ############################################################################ - - 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 - step_ok "Rechargement d'Apache" + step_ok "Rechargement d'Apache" - ############################################################################ - - DATE=$(date +"%Y-%m-%d") - echo "$DATE [web-add.sh] Ajout $in_login" >> /var/log/evolix.log + ############################################################################ + + 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 + if [ $# -lt 1 ]; then + usage + exit 1 + else + login=$1 + if [ $# -eq 2 ]; then + dbname=$2 + fi + fi - echo "Deleting account $login. Continue ?" - read + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 - ;; - U) - in_wwwuid=$OPTARG - ;; - h) - usage - exit 1 - ;; - ?) - usage - exit 1 - ;; - esac - done - - shift $(($OPTIND - 1)) - if [ $# -ne 2 ]; then - usage - exit 1 - else - in_login=$1 - in_wwwdomain=$2 - validate_login $in_login || exit 1 - [ -z "$in_passwd" ] && [ -z "$in_sshkey" ] && in_passwd=`gen_random_passwd` - [ -z "$in_sshkey" ] && ( validate_passwd $in_passwd || exit 1 ) - [ -n "$in_dbname" ] && ( validate_dbname $in_dbname || exit 1 ) - [ -z "$in_dbpasswd" ] && [ -n "$in_dbname" ] && in_dbpasswd=`gen_random_passwd` - [ -n "$in_dbname" ] && ( validate_passwd $in_dbpasswd || exit 1 ) - validate_wwwdomain $in_wwwdomain || exit 1 - [ -z "$in_mail" ] && in_mail=$CONTACT_MAIL - validate_mail $in_mail || exit 1 - fi - fi - - echo - echo "----------------------------------------------" - echo "Nom du compte : $in_login" - echo "Mot de passe : $in_passwd" - if [ "$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 "Envoi du mail récapitulatif à : $in_mail" - echo "----------------------------------------------" - echo - - if [ -z "$force_confirm" ]; then - echo -n "Confirmer la création ? [y/N] : " - read tmp - echo - if [ "$tmp" != "y" ] && [ "$tmp" != "Y" ]; then - echo "Annulation..." - echo - exit 1 - fi - fi - - create_www_account - echo - echo " => Compte $in_login créé avec succès" - echo + # + # 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 + ;; + U) + in_wwwuid=$OPTARG + ;; + h) + usage + exit 1 + ;; + ?) + usage + exit 1 + ;; + esac + done + + shift $(($OPTIND - 1)) + if [ $# -ne 2 ]; then + usage + exit 1 + else + in_login=$1 + in_wwwdomain=$2 + validate_login $in_login || exit 1 + [ -z "$in_passwd" ] && [ -z "$in_sshkey" ] && in_passwd=`gen_random_passwd` + [ -z "$in_sshkey" ] && ( validate_passwd $in_passwd || exit 1 ) + [ -n "$in_dbname" ] && ( validate_dbname $in_dbname || exit 1 ) + [ -z "$in_dbpasswd" ] && [ -n "$in_dbname" ] && in_dbpasswd=`gen_random_passwd` + [ -n "$in_dbname" ] && ( validate_passwd $in_dbpasswd || exit 1 ) + validate_wwwdomain $in_wwwdomain || exit 1 + [ -z "$in_mail" ] && in_mail=$CONTACT_MAIL + validate_mail $in_mail || exit 1 + fi + fi + + echo + echo "----------------------------------------------" + echo "Nom du compte : $in_login" + echo "Mot de passe : $in_passwd" + if [ "$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 "Envoi du mail récapitulatif à : $in_mail" + echo "----------------------------------------------" + echo + + if [ -z "$force_confirm" ]; then + echo -n "Confirmer la création ? [y/N] : " + read tmp + echo + if [ "$tmp" != "y" ] && [ "$tmp" != "Y" ]; then + echo "Annulation..." + echo + exit 1 + fi + fi + + create_www_account + echo + echo " => Compte $in_login créé avec succès" + echo } # Point d'entrée diff --git a/tpl/webadmin.tpl.php b/tpl/webadmin.tpl.php index 94c74bb..13b0847 100755 --- a/tpl/webadmin.tpl.php +++ b/tpl/webadmin.tpl.php @@ -47,10 +47,10 @@ $vhost_info['server_name'], $vhost_info['server_name']); if ($conf['cluster']) { - if (empty($vhost_info['bdd'])) - printf(''); - else - printf('%s', $vhost_info['bdd']); + if (empty($vhost_info['bdd'])) + printf(''); + else + printf('%s', $vhost_info['bdd']); if (empty($vhost_info['mail'])) printf(''); @@ -61,16 +61,16 @@ if (empty($vhost_info['replication'])) printf(''); else - printf('%s', $vhost_info['replication']); - printf('%s', $vhost_info['master']); - if (empty($vhost_info['slave'])) - printf(''); - else - printf('%s', $vhost_info['slave']); - } - else { + printf('%s', $vhost_info['replication']); + printf('%s', $vhost_info['master']); + if (empty($vhost_info['slave'])) + printf(''); + else + printf('%s', $vhost_info['slave']); + } + else { printf('%s', $vhost_info['server_alias']); - } + } if (is_superadmin()) { printf('Lister/Modifier', $vhost_info['owner']);