From 7a0d307f23d9fdbc3bccbbb9f62a380316e549f9 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Thu, 4 Apr 2019 11:52:18 +0200 Subject: [PATCH 01/12] first draft --- scripts/web-add.sh | 61 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index dc0528f..c1c5c62 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -612,19 +612,59 @@ EOT } op_del() { - if [ $# -lt 1 ]; then - usage - exit 1 - else + + # + # Mode interactif + # + + if [ $# -eq 0 ]; then + echo + echo "Suppression d'un compte WEB" + echo + + until [ "$login" ]; do + echo -n "Entrez le login du compte à supprimer : " + read -r tmp + login="$tmp" + done + + echo -n "Voulez-vous aussi supprimer un compte/base MySQL ? [y|N]" + read -r confirm + + if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then + echo -n "Entrez le nom de la base de donnees ($login par defaut) : " + read -r tmp + + if [ -z "$tmp" ]; then + dbname=$login + else + dbname="$tmp" + fi + fi + + echo -n "Continuer la suppression du compte $login ? [y/N] : " + read -r tmp + echo + if [ "$tmp" != "y" ] && [ "$tmp" != "Y" ]; then + echo "Annulation..." + echo + exit 1 + fi + + # + # Mode non interactif + # + + elif [ $# -gt 0 ] && [ $# -le 2 ]; then login=$1 if [ $# -eq 2 ]; then dbname=$2 fi + else + usage + exit 1 fi - echo "Deleting account $login. Continue ?" - read -r - set -x if [ "$WEB_SERVER" == "apache" ]; then userdel www-"$login" @@ -681,9 +721,6 @@ op_del() { set +x if [ -n "$dbname" ]; then - echo "Deleting mysql DATABASE $dbname and mysql user $login. Continue ?" - read -r - set -x echo "DROP DATABASE $dbname; delete from mysql.user where user='$login' ; FLUSH PRIVILEGES;" | mysql $MYSQL_OPTS set +x @@ -915,7 +952,7 @@ op_checkoccurencename() { if [ -r "$configfile" ]; then alias=$(perl -ne 'print "$1 " if /^[[:space:]]*ServerAlias (.*)/' "$configfile" | head -n 1) aliases="$aliases $alias" - + servername=$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq) servernames="$servernames $servername" fi @@ -931,7 +968,7 @@ op_listuseritk() { if [ $# -eq 2 ]; then domain=${1} configfile="$VHOST_PATH/${2}.conf" - + sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $2}' | uniq else usage From ad3c31fb96deb6f2a8a225472c3e56951969784b Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Fri, 5 Apr 2019 10:49:23 +0200 Subject: [PATCH 02/12] added force-confirm option for del script --- scripts/web-add.sh | 66 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index c1c5c62..37d1948 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -100,12 +100,18 @@ add [ [OPTIONS] LOGIN WWWDOMAIN ] Example : web-add.sh add -m testdb -r 56 testlogin testdomain.com -del LOGIN [DBNAME] +del [ [OPTIONS] LOGIN [DBNAME] ] Delete account and all files related (Apache, Awstats, etc) Archive home directory. Remove MySQL database only if DBNAME is specified. + -y + Don't ask for confirmation + + Example : web-add.sh del -y testlogin testdatabase + + list-vhost LOGIN List Apache vhost for user LOGIN @@ -642,7 +648,50 @@ op_del() { fi fi - echo -n "Continuer la suppression du compte $login ? [y/N] : " + # + # Mode non interactif + # + + else + while getopts hy opt; do + case "$opt" in + y) + force_confirm=1 + ;; + h) + usage + exit 1 + ;; + ?) + usage + exit 1 + ;; + esac + done + + shift $((OPTIND - 1)) + if [ $# -gt 0 ] && [ $# -le 2 ]; then + login=$1 + if [ $# -eq 2 ]; then + dbname=$2 + fi + else + usage + exit 1 + fi + fi + + echo + echo "----------------------------------------------" + echo "Nom du compte : $login" + if [ "$dbname" ]; then + echo "Base de données MySQL : $dbname" + fi + echo "----------------------------------------------" + echo + + if [ -z "$force_confirm" ]; then + echo -n "Confirmer la suppression ? [y/N] : " read -r tmp echo if [ "$tmp" != "y" ] && [ "$tmp" != "Y" ]; then @@ -650,19 +699,6 @@ op_del() { echo exit 1 fi - - # - # Mode non interactif - # - - elif [ $# -gt 0 ] && [ $# -le 2 ]; then - login=$1 - if [ $# -eq 2 ]; then - dbname=$2 - fi - else - usage - exit 1 fi set -x From 6f7fe190462bd25d881f49f9aeeac19714cbfd23 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Fri, 5 Apr 2019 15:07:01 +0200 Subject: [PATCH 03/12] added delete webpage --- htdocs/inc/js/webadmin.js | 6 ++++ htdocs/index.php | 4 +++ inc/webadmin-delete.php | 72 +++++++++++++++++++++++++++++++++++++ tpl/webadmin-delete.tpl.php | 36 +++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 inc/webadmin-delete.php create mode 100644 tpl/webadmin-delete.tpl.php diff --git a/htdocs/inc/js/webadmin.js b/htdocs/inc/js/webadmin.js index 77bb78f..4a78df5 100644 --- a/htdocs/inc/js/webadmin.js +++ b/htdocs/inc/js/webadmin.js @@ -21,6 +21,12 @@ function switch_disabled(name) { } document.observe("dom:loaded", function() { + if (document.getElementById('vhost-delete-db') != null) { + document.getElementById('vhost-delete-db').onclick = function() { + console.log("clicked box"); + switch_disabled('vhost-dbname'); + } + } document.getElementById('password_random').onclick = function() { switch_disabled('password'); } diff --git a/htdocs/index.php b/htdocs/index.php index b1010bb..a801e52 100755 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -64,6 +64,10 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) { include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; +} elseif (preg_match('#^/webadmin/(.*)/delete/$#', $uri, $params)) { + + include_once EVOADMIN_BASE . '../inc/webadmin-delete.php'; + } elseif (preg_match('#^/webadmin/suppr/(.*)/?$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-suppr.php'; diff --git a/inc/webadmin-delete.php b/inc/webadmin-delete.php new file mode 100644 index 0000000..85b9e03 --- /dev/null +++ b/inc/webadmin-delete.php @@ -0,0 +1,72 @@ + + * @author Thomas Martin + * @author Sebastien Palma + * @version 1.0 + */ + +require_once EVOADMIN_BASE . '../lib/bdd.php'; +require_once EVOADMIN_BASE . '../lib/domain.php'; + +global $conf; + +include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; +include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; + +if (isset($_POST['delete-vhost'])) { + $domain = $params[1]; + + while(true) { + // Errors handling + if (empty($_POST['vhost-name'])) { + print "

Veuillez entrer le nom du compte web à supprimer.

"; + printf ('

Retour

', $_SERVER['REDIRECT_URL']); + break; + } + + if ($_POST['vhost-name'] !== $domain) { + print "Le nom de compte ne correspond pas."; + printf ('

Retour

', $_SERVER['REDIRECT_URL']); + break; + } + + if (isset($_POST['vhost-delete-db']) && empty($_POST['vhost-dbname'])) { + print "Veuillez spécifier un nom de base de données."; + printf ('

Retour

', $_SERVER['REDIRECT_URL']); + break; + } + + // Shell arguments + if (!empty($_POST['vhost-dbname'])) + $exec_cmd = "web-add.sh del -y " . $domain . " " . $_POST['vhost-dbname']; + else + $exec_cmd = "web-add.sh del -y " . $domain; + + // Execute script + sudoexec($exec_cmd, $exec_output, $exec_return); + + // Deal with response code + if ($exec_return == 0) + print "

Compte supprimé.

"; + else + print "

La suppression a échouée. Veuillez contacter votre administrateur.

"; + + break; + } + + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; + +} else { + include_once EVOADMIN_BASE . '../tpl/webadmin-delete.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; +} + +?> diff --git a/tpl/webadmin-delete.tpl.php b/tpl/webadmin-delete.tpl.php new file mode 100644 index 0000000..58338bc --- /dev/null +++ b/tpl/webadmin-delete.tpl.php @@ -0,0 +1,36 @@ + + * @version 1.0 + */ + +?> + +

Suppression du compte web

+ +
+
+

+ + +

+

+ + +

+

+ + +

+

+ +

+
+
From bb17afd5fc3bf10e95eca7073773e880f64ec3a2 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Fri, 5 Apr 2019 15:25:01 +0200 Subject: [PATCH 04/12] added delete link --- tpl/webadmin-delete.tpl.php | 2 +- tpl/webadmin.tpl.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tpl/webadmin-delete.tpl.php b/tpl/webadmin-delete.tpl.php index 58338bc..9a0081d 100644 --- a/tpl/webadmin-delete.tpl.php +++ b/tpl/webadmin-delete.tpl.php @@ -1,7 +1,7 @@ ITK', $vhost_info['owner']); } + printf(' - Supprimer', $vhost_info['owner']); printf(''); } From 1ffa0ef4e78ec725c7c579e56fb610535f915792 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Thu, 16 May 2019 10:57:05 +0200 Subject: [PATCH 05/12] normalize title names --- inc/webadmin-edit.php | 8 ++++---- inc/webadmin-servername.php | 4 ++-- tpl/webadmin-edit.tpl.php | 4 ++-- tpl/webadmin-itk.tpl.php | 2 +- tpl/webadmin-servername.tpl.php | 6 +++--- tpl/webadmin.tpl.php | 10 +++++----- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/inc/webadmin-edit.php b/inc/webadmin-edit.php index b52a528..7e63681 100644 --- a/inc/webadmin-edit.php +++ b/inc/webadmin-edit.php @@ -222,10 +222,10 @@ elseif (isset($params[2]) && $params[2] == "add") { } } else { - print "

Ajout d'un serveralias


"; + print "

Ajout d'un alias


"; print "
"; print "
"; - print " Ajout d'un serveralias"; + print " Ajout d'un alias"; print $form; print "

"; print "
"; @@ -233,10 +233,10 @@ elseif (isset($params[2]) && $params[2] == "add") { } } else { - print "

Ajout d'un serveralias


"; + print "

Ajout d'un alias


"; print ""; print "
"; - print " Ajout d'un serveralias"; + print " Ajout d'un alias"; print $form; print "

"; print "
"; diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index 7779c43..db5b862 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -146,10 +146,10 @@ if (isset($params[2]) && $params[2] == "edit") { } } } else { - print "

Modification du ServerName


"; + print "

Modification du Servername


"; print ""; print "
"; - print " Modification du ServerName"; + print " Modification du Servername"; print $form; print "

"; print "
"; diff --git a/tpl/webadmin-edit.tpl.php b/tpl/webadmin-edit.tpl.php index 09826c2..4c57bd3 100644 --- a/tpl/webadmin-edit.tpl.php +++ b/tpl/webadmin-edit.tpl.php @@ -5,7 +5,7 @@ * * Copyright (c) 2009 Evolix - Tous droits reserves * - * vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2 + * vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2 * * @author Thomas Martin * @version 1.0 @@ -38,7 +38,7 @@ '; - printf('http://%s', + printf('%s', $alias_list[$i]['alias'], $alias_list[$i]['alias']); if (is_superadmin()) printf('Supprimer', diff --git a/tpl/webadmin-itk.tpl.php b/tpl/webadmin-itk.tpl.php index 313f947..c856703 100644 --- a/tpl/webadmin-itk.tpl.php +++ b/tpl/webadmin-itk.tpl.php @@ -22,7 +22,7 @@ - + Action'; diff --git a/tpl/webadmin-servername.tpl.php b/tpl/webadmin-servername.tpl.php index 9766b99..ac53cdd 100644 --- a/tpl/webadmin-servername.tpl.php +++ b/tpl/webadmin-servername.tpl.php @@ -13,7 +13,7 @@ ?> -

ServerNames

+

Servernames

- + Action'; } ?> @@ -43,7 +43,7 @@
ServerNameServername Utilisateur
ServerNameServername
Aucun ServerName existant pour le domaine $domain !

"; + print "

Aucun Servername existant pour le domaine $domain !

"; } diff --git a/tpl/webadmin.tpl.php b/tpl/webadmin.tpl.php index 0fd15c6..5ccba08 100755 --- a/tpl/webadmin.tpl.php +++ b/tpl/webadmin.tpl.php @@ -22,9 +22,9 @@ Propriétaire'; + print 'Virtual Host'; } ?> - Domaine + Servername Alias'; } @@ -61,7 +61,7 @@ if(is_superadmin()) { printf('%s', $vhost_info['owner']); } - printf('http://%s', + printf('%s', $vhost_info['server_name'], $vhost_info['server_name']); if ($conf['cluster']) { @@ -87,7 +87,7 @@ printf('%s', $vhost_info['slave']); } - printf('%s', preg_replace('/,/','
',$vhost_info['server_alias'])); + printf('%s', preg_replace('/,/','
',$vhost_info['server_alias'])); if ($conf['quota']) { printf('%s', $vhost_info['size']); @@ -110,7 +110,7 @@ } else { printf('ITK', $vhost_info['owner']); } - printf(' - Supprimer', $vhost_info['owner']); + printf('Supprimer', $vhost_info['owner']); printf(''); } From 1ee7221b19ace00688a1f192f87974cebce0bdbc Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Thu, 16 May 2019 11:19:43 +0200 Subject: [PATCH 06/12] normalize text --- inc/webadmin-edit.php | 12 ++++++------ tpl/webadmin-servername.tpl.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/inc/webadmin-edit.php b/inc/webadmin-edit.php index 7e63681..7b0d99b 100644 --- a/inc/webadmin-edit.php +++ b/inc/webadmin-edit.php @@ -1,11 +1,11 @@ * @author Thomas Martin @@ -68,10 +68,10 @@ if (isset($params[2]) && $params[2] == "delete") { sudoexec($exec_cmd, $exec_output, $exec_return); if ($exec_return == 0) { - if (! $bdd->del_serveralias($serveralias)) + if (! $bdd->del_serveralias($serveralias)) print "

La suppression a échouée. Veuillez contacter votre administrateur.

"; printf ('

Alias %s est supprimé.

', $serveralias['alias']); - } else + } else print "

La suppression a échouée. Veuillez contacter votre administrateur.

"; } @@ -134,7 +134,7 @@ elseif (isset($params[2]) && $params[2] == "add") { 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), 'alias' => $form->getField('domain_alias')->getValue(), ); - + $account_name=$serveralias['domain']; $account = $bdd->get_account($account_name); @@ -214,7 +214,7 @@ elseif (isset($params[2]) && $params[2] == "add") { } else { print "
"; - printf ('

Echec dans la creation de l\'alias %s du domaine %s

', $serveralias['alias'], $serveralias['domain']); + printf ('

Echec dans la creation de l\'alias %s

', $serveralias['alias']); print ('

L\'alias existe dans d\'autres vhosts.'); printf ('

Retour à la liste des alias

', $redirect_url); print "
"; diff --git a/tpl/webadmin-servername.tpl.php b/tpl/webadmin-servername.tpl.php index ac53cdd..ccd1911 100644 --- a/tpl/webadmin-servername.tpl.php +++ b/tpl/webadmin-servername.tpl.php @@ -13,7 +13,7 @@ ?> -

Servernames

+

Servername

Date: Thu, 16 May 2019 11:55:52 +0200 Subject: [PATCH 07/12] revert multiple virtualhosts mgmt for ITK --- inc/webadmin-itk.php | 60 +++++++++++++++++----------------------- scripts/web-add.sh | 25 ++++++++--------- tpl/webadmin-itk.tpl.php | 39 +++++++++++--------------- 3 files changed, 52 insertions(+), 72 deletions(-) diff --git a/inc/webadmin-itk.php b/inc/webadmin-itk.php index 673d46b..d47a972 100644 --- a/inc/webadmin-itk.php +++ b/inc/webadmin-itk.php @@ -18,23 +18,39 @@ require_once EVOADMIN_BASE . '../lib/domain.php'; global $conf; -if (isset($params[2]) && $params[2] != "") { - $redirect_url = "/webadmin/" . $params[1] . "/itk/"; +if (isset($_GET['enable']) ) { + require_once EVOADMIN_BASE . '../evolibs/Form.php'; + + include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; + + $servername = array ( + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), + ); + + $enable_cmd = 'web-add.sh enable-user-itk ' . $servername['domain']; if (isset($params[3]) && $params[3] == "") http_redirect($redirect_url); + if ($enable_cmd_return == 0) { + print 'Sécurité ITK activée.'; + printf ('

Retour à la gestion ITK

', $_SERVER['REDIRECT_URL']); + } + + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; + +} elseif (isset($_GET['disable']) ) { + require_once EVOADMIN_BASE . '../evolibs/Form.php'; include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; $servername = array ( - 'domain' => $params[1], - 'servername' => $params[3] + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), ); - if ($params[2] == "enable") { - $enable_cmd = 'web-add.sh enable-user-itk ' . $servername['servername'] . ' ' . $servername['domain']; + $disable_cmd = 'web-add.sh disable-user-itk ' . $servername['domain']; sudoexec($enable_cmd, $enable_cmd_output, $enable_cmd_return); @@ -46,20 +62,10 @@ if (isset($params[2]) && $params[2] != "") { elseif ($params[2] == "disable") { $disable_cmd = 'web-add.sh disable-user-itk ' . $servername['servername'] . ' ' . $servername['domain']; - sudoexec($disable_cmd, $disable_cmd_output, $disable_cmd_return); - - if ($disable_cmd_return == 0) { - print 'Sécurité ITK désactivée'; - printf ('

Retour à la gestion ITK

', $redirect_url); - } - } include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; -} - -else { +} else { $domain = $params[1]; - $data_list = array(); // TODO: adapt for cluster mode if ($conf['cluster']) { @@ -83,33 +89,17 @@ else { $alias_list = $bdd->list_serveralias($domain); } else { - - $cmd = 'web-add.sh list-servername ' . $domain; - - if(!is_superadmin()) { - $cmd = sprintf('%s %s', $cmd, $_SESSION['user']); - } - sudoexec($cmd, $data_output, $exec_return); - - # à revérifier (notamment gestion erreurs) - if ($exec_return == 0) { - foreach($data_output as $data_line) { - $cmd_itk = 'web-add.sh list-user-itk ' . $data_line . ' ' . $domain; + $cmd_itk = 'web-add.sh list-user-itk ' . $domain; sudoexec($cmd_itk, $data_output_itk, $exec_return_itk); - # on prend le premier résultat du tableau, ne fonctionne pas s'il y a plusieurs la même ligne ou des commentaires etc. - array_push($data_list, ['servername' => $data_line, 'user' => $data_output_itk[0]]); - unset($data_output_itk); # reset variable pour éviter conflits - } - } + $user_itk = $data_output_itk[0]; } include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; include_once EVOADMIN_BASE . '../tpl/webadmin-itk.tpl.php'; include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; - } ?> diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 37d1948..5a560c8 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -1001,23 +1001,21 @@ op_checkoccurencename() { } op_listuseritk() { - if [ $# -eq 2 ]; then - domain=${1} - configfile="$VHOST_PATH/${2}.conf" + if [ $# -eq 1 ]; then + configfile="$VHOST_PATH/${1}.conf" - sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $2}' | uniq + awk '/AssignUserID/ {print $2}' "$configfile" | uniq else usage fi } op_enableuseritk() { - if [ $# -eq 2 ]; then - domain=${1} - configfile="$VHOST_PATH/${2}.conf" - group=$(sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $3}' | uniq) + if [ $# -eq 1 ]; then + configfile="$VHOST_PATH/${1}.conf" + group=$(awk '/AssignUserID/ {print $3}' "$configfile" | uniq) - sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $group/ AssignUserID www-$group/" "$configfile" --follow-symlinks + sed -i "s/^ *AssignUserID $group/ AssignUserID www-$group/" "$configfile" --follow-symlinks configtest_out=$(apache2ctl configtest) configtest_rc=$? @@ -1033,12 +1031,11 @@ op_enableuseritk() { } op_disableuseritk() { - if [ $# -eq 2 ]; then - domain=${1} - configfile="$VHOST_PATH"/"${2}".conf - group=$(sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $3}' | uniq) + if [ $# -eq 1 ]; then + configfile="$VHOST_PATH"/"${1}".conf + group=$(awk '/AssignUserID/ {print $3}' "$configfile" | uniq) - sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID www-$group/ AssignUserID ${group}/" "$configfile" --follow-symlinks + sed -i "s/^ *AssignUserID www-$group/ AssignUserID ${group}/" "$configfile" --follow-symlinks configtest_out=$(apache2ctl configtest) configtest_rc=$? diff --git a/tpl/webadmin-itk.tpl.php b/tpl/webadmin-itk.tpl.php index c856703..e5ca180 100644 --- a/tpl/webadmin-itk.tpl.php +++ b/tpl/webadmin-itk.tpl.php @@ -17,12 +17,11 @@ 0) { ?> + if(!empty($user_itk)) { ?> - Action'; @@ -31,29 +30,23 @@ '; - printf('', - $data_list[$i]['servername']); - printf('', - $data_list[$i]['user']); - if (is_superadmin()) { - if (strpos($data_list[$i]['user'], 'www') !== false) { - $action = ['disable', 'Désactiver']; - } else { - $action = ['enable', 'Activer']; - } - // AssignUserID not set in the vhost, override previous action - if (empty($data_list[$i]['user'])) { - $action = ["", ""]; - } + print ''; + printf('', + $user_itk); + if (is_superadmin()) { - printf('', - $domain, $action[0], $data_list[$i]['servername']); - } - print ''; - } ?> + if (strpos($user_itk, 'www') !== false) { + $action = ['disable', 'Désactiver']; + } else { + $action = ['enable', 'Activer']; + } + + printf('', + $domain, $action[0]); + } + print ''; + ?>
Servername Utilisateur
%s%s
%s'.$action[1].'
'.$action[1].'
Date: Thu, 16 May 2019 12:06:35 +0200 Subject: [PATCH 08/12] normalize add-alias with del-alias --- scripts/web-add.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 5a560c8..3229072 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -866,7 +866,6 @@ op_listvhost() { configlist="$VHOST_PATH/*"; fi - for configfile in $configlist; do if [ -r "$configfile" ] && echo "$configfile" |grep -qvE "/(000-default|default-ssl|evoadmin)\\.conf$"; then servername="$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | head -n 1)" @@ -896,12 +895,23 @@ op_aliasadd() { if [ $# -eq 2 ]; then vhost="${1}.conf" alias=$2 + vhost_file="${VHOST_PATH}/${vhost}" - [ -f $VHOST_PATH/"$vhost" ] && sed -i "/ServerName .*/a \\\tServerAlias $alias" "$VHOST_PATH"/"$vhost" --follow-symlinks + if [ -f "${vhost_file}" ]; then + sed -i "/ServerName .*/a \\\tServerAlias $alias" "${vhost_file}" --follow-symlinks + else + echo "VHost file \`${vhost_file}' not found'" >&2 + return 1 + fi - apache2ctl configtest 2>/dev/null - /etc/init.d/apache2 force-reload >/dev/null + configtest_out=$(apache2ctl configtest) + configtest_rc=$? + if [ "$configtest_rc" = "0" ]; then + /etc/init.d/apache2 force-reload >/dev/null + else + echo $configtest_out >&2 + fi else usage fi } From ad452aad6ad30dd851c7bb1654f1e2b7859af649 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Thu, 16 May 2019 14:40:30 +0200 Subject: [PATCH 09/12] delete list-servername function --- inc/webadmin-servername.php | 8 +++---- scripts/web-add.sh | 41 ++++++--------------------------- tpl/webadmin-servername.tpl.php | 19 ++++++++------- 3 files changed, 19 insertions(+), 49 deletions(-) diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index db5b862..7141acc 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -197,17 +197,15 @@ if (isset($params[2]) && $params[2] == "edit") { $alias_list = $bdd->list_serveralias($domain); } else { - - $cmd = 'web-add.sh list-servername ' . $domain; + $cmd = 'web-add.sh list-vhost ' . $domain; if(!is_superadmin()) { $cmd = sprintf('%s %s', $cmd, $_SESSION['user']); } sudoexec($cmd, $data_output, $exec_return); - foreach($data_output as $data_line) { - array_push($servername_list, $data_line); - } + $data_vhost = explode(':', $data_output[0]); + $servername = $data_vhost[2]; } include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 3229072..e3d5df9 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -128,30 +128,26 @@ del-alias VHOST ALIAS Del a ServerAlias from an Apache vhost -list-servername LOGIN - - List ServerName(s) for user LOGIN - update-servername VHOST SERVERNAME OLD_SERVERNAME Replace the OLD_SERVERNAME with the SERVERNAME for an Apache vhost - Also apply to rules + Also apply to rewrite rules check-occurence NAME List all occurences of NAME in vhosts -list-user-itk DOMAIN LOGIN +list-user-itk LOGIN - List the assigned ITK user for the DOMAIN specified + List the assigned ITK user for the LOGIN specified -enable-user-itk DOMAIN LOGIN +enable-user-itk LOGIN - Enable the assigned ITK user for the DOMAIN specified + Enable the assigned ITK user for the LOGIN specified -disable-user-itk DOMAIN LOGIN +disable-user-itk LOGIN - Disable the assigned ITK user for the DOMAIN specified + Disable the assigned ITK user for the LOGIN specified setphpversion LOGIN VERSION @@ -828,9 +824,6 @@ arg_processing() { del-alias) op_aliasdel "$@" ;; - list-servername) - op_listservername "$@" - ;; update-servername) op_servernameupdate "$@" ;; @@ -942,25 +935,6 @@ op_aliasdel() { fi } -op_listservername() { - if [ $# -eq 1 ]; then - vhost_file="$VHOST_PATH/${1}.conf"; - - if [ -f "${vhost_file}" ]; then - servernames=$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$vhost_file" | uniq) - - for servername in $servernames; do - echo "$servername"; - done - else - echo "VHost file \`${vhost_file}' not found'" >&2 - return 1 - fi - else - usage - fi -} - op_servernameupdate() { if [ $# -eq 3 ]; then vhost="${1}.conf" @@ -968,7 +942,6 @@ op_servernameupdate() { old_servername=$3 vhost_file="${VHOST_PATH}/${vhost}" - # Remplacement de toutes les directives ServerName, on assume qu'il s'agit du même pour chaque vhost du fichier if [ -f "${vhost_file}" ]; then sed -i "/^ *ServerName/ s/$old_servername/$servername/g" "${vhost_file}" --follow-symlinks sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" "${vhost_file}" --follow-symlinks diff --git a/tpl/webadmin-servername.tpl.php b/tpl/webadmin-servername.tpl.php index ccd1911..50b87d3 100644 --- a/tpl/webadmin-servername.tpl.php +++ b/tpl/webadmin-servername.tpl.php @@ -17,7 +17,7 @@ 0) { ?> + if(!empty($servername)) { ?> @@ -30,15 +30,14 @@ '; - printf('', - $servername_list[$i]); - if (is_superadmin()) - printf('', - $domain, $servername_list[$i]); - print ''; - } ?> + print ''; + printf('', + $servername); + if (is_superadmin()) + printf('', + $domain, $servername); + print ''; + ?>
%sModifier
%sModifier
Date: Fri, 17 May 2019 11:53:21 +0200 Subject: [PATCH 10/12] block non-standard vhost modification --- htdocs/index.php | 35 +++++++++++++++++++++++------------ inc/webadmin.php | 11 +++++++++++ scripts/web-add.sh | 10 +++++++++- tpl/webadmin.tpl.php | 16 ++++++++++------ 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/htdocs/index.php b/htdocs/index.php index a801e52..8e951b3 100755 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -48,30 +48,41 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) { include_once EVOADMIN_BASE . '../inc/webadmin.php'; -} elseif (preg_match('#^/webadmin/(.*)/domain/?(edit)?/?(.*)?/$#', $uri, $params)) { +} elseif (preg_match('#^/webadmin?#', $uri)) { - include_once EVOADMIN_BASE . '../inc/webadmin-servername.php'; + // Redirect to /webadmin in order to set $_SESSION['non_stanard'] + if (!isset($_SESSION['non_standard'])) + http_redirect('/webadmin'); -} elseif (preg_match('#^/webadmin/(.*)/itk/?(enable|disable)?/?(.*)?/$#', $uri, $params)) { + // block the non-standard vhost modification + if (in_array(htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), $_SESSION['non_standard'])) + http_redirect('/webadmin'); - include_once EVOADMIN_BASE . '../inc/webadmin-itk.php'; + if (preg_match('#^/webadmin/servername/(.*)/?$#', $uri, $params)) { -} elseif (preg_match('#^/webadmin/(.*)/php/$#', $uri, $params)) { + include_once EVOADMIN_BASE . '../inc/webadmin-servername.php'; - include_once EVOADMIN_BASE . '../inc/webadmin-php.php'; + } elseif (preg_match('#^/webadmin/itk/(.*)/?$#', $uri, $params)) { -} elseif (preg_match('#^/webadmin/(.*)/alias/?(add|delete)?/?(.*)?/$#', $uri, $params)) { + include_once EVOADMIN_BASE . '../inc/webadmin-itk.php'; - include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; + } elseif (preg_match('#^/webadmin/php/(.*)/?$#', $uri, $params)) { -} elseif (preg_match('#^/webadmin/(.*)/delete/$#', $uri, $params)) { + include_once EVOADMIN_BASE . '../inc/webadmin-php.php'; - include_once EVOADMIN_BASE . '../inc/webadmin-delete.php'; + } elseif (preg_match('#^/webadmin/edit/(.*)/?$#', $uri, $params)) { -} elseif (preg_match('#^/webadmin/suppr/(.*)/?$#', $uri, $params)) { + include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; - include_once EVOADMIN_BASE . '../inc/webadmin-suppr.php'; + } elseif (preg_match('#^/webadmin/delete/(.*)/?$#', $uri, $params)) { + include_once EVOADMIN_BASE . '../inc/webadmin-delete.php'; + + } elseif (preg_match('#^/webadmin/suppr/(.*)/?$#', $uri, $params)) { + + include_once EVOADMIN_BASE . '../inc/webadmin-suppr.php'; + + } } elseif (is_superadmin() && preg_match('#^/accounts/?#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/accounts.php'; diff --git a/inc/webadmin.php b/inc/webadmin.php index ad3ec23..bc61a7b 100644 --- a/inc/webadmin.php +++ b/inc/webadmin.php @@ -30,6 +30,12 @@ if (!$conf['cluster']) { /* Récupération de cette liste dans le tableau $vhost_list */ $vhost_list = array(); + + if (!isset($_SESSION['non_standard'])) { + $_SESSION['non_standard'] = array(); + } + + foreach($data_output as $data_line) { $data_split = explode(':', $data_line); @@ -72,6 +78,11 @@ if (!$conf['cluster']) { $occupation = ""; } + // current vhost isn't standard and thus not manageable by evoadmin-web + if (!$data_split[9]) { + array_push($_SESSION['non_standard'], $data_split[0]); + } + array_push($vhost_list, array( 'owner' => $data_split[0], 'configid' => $data_split[1], diff --git a/scripts/web-add.sh b/scripts/web-add.sh index e3d5df9..b4ca350 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -876,9 +876,17 @@ op_listvhost() { else is_enabled=0 fi + + count_virtualhosts="$(grep "'); - printf('Alias - ', $vhost_info['owner']); - printf('Servername - ', $vhost_info['owner']); - if(is_multiphp()) { - printf('PHP', $vhost_info['owner']); + if (!in_array($vhost_info['owner'], $_SESSION['non_standard'])) { + printf('Alias - ', $vhost_info['owner']); + printf('Servername - ', $vhost_info['owner']); + if(is_multiphp()) { + printf('PHP - ', $vhost_info['owner']); + } else { + printf('ITK - ', $vhost_info['owner']); + } + printf('Supprimer', $vhost_info['owner']); } else { - printf('ITK', $vhost_info['owner']); + print 'VirtualHost non standard'; } - printf('Supprimer', $vhost_info['owner']); printf(''); } From 44b4ac2f5e5ae6993ac25373840cee0a927b9f62 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 3 Jun 2019 16:44:14 +0200 Subject: [PATCH 11/12] add .idea folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6e9dadb..7d7f61e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ conf/config.local.php .vagrant +.idea From 634a18d1cb80e8d950c9b1cc3039e41ddafdea9b Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Wed, 5 Jun 2019 17:20:34 +0200 Subject: [PATCH 12/12] rebase master --- htdocs/index.php | 8 +++--- inc/webadmin-itk.php | 49 +++++++++++++-------------------- inc/webadmin-servername.php | 20 +++++++------- tpl/webadmin-itk.tpl.php | 2 +- tpl/webadmin-servername.tpl.php | 2 +- tpl/webadmin.tpl.php | 8 +++--- 6 files changed, 39 insertions(+), 50 deletions(-) diff --git a/htdocs/index.php b/htdocs/index.php index 8e951b3..c2f5ff0 100755 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -58,19 +58,19 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) { if (in_array(htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), $_SESSION['non_standard'])) http_redirect('/webadmin'); - if (preg_match('#^/webadmin/servername/(.*)/?$#', $uri, $params)) { + if (preg_match('#^/webadmin/(.*)/domain/?(edit)?/?(.*)?/$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-servername.php'; - } elseif (preg_match('#^/webadmin/itk/(.*)/?$#', $uri, $params)) { + } elseif (preg_match('#^/webadmin/(.*)/itk/?(enable|disable)?/?(.*)?/$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-itk.php'; - } elseif (preg_match('#^/webadmin/php/(.*)/?$#', $uri, $params)) { + } elseif (preg_match('#^/webadmin/(.*)/php/$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-php.php'; - } elseif (preg_match('#^/webadmin/edit/(.*)/?$#', $uri, $params)) { + } elseif (preg_match('#^/webadmin/(.*)/alias/?(add|delete)?/?(.*)?/$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; diff --git a/inc/webadmin-itk.php b/inc/webadmin-itk.php index d47a972..44a106d 100644 --- a/inc/webadmin-itk.php +++ b/inc/webadmin-itk.php @@ -18,28 +18,9 @@ require_once EVOADMIN_BASE . '../lib/domain.php'; global $conf; -if (isset($_GET['enable']) ) { - require_once EVOADMIN_BASE . '../evolibs/Form.php'; +if (isset($params[2]) && $params[2] != "") { - include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; - include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; - - $servername = array ( - 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), - ); - - $enable_cmd = 'web-add.sh enable-user-itk ' . $servername['domain']; - - if (isset($params[3]) && $params[3] == "") http_redirect($redirect_url); - - if ($enable_cmd_return == 0) { - print 'Sécurité ITK activée.'; - printf ('

Retour à la gestion ITK

', $_SERVER['REDIRECT_URL']); - } - - include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; - -} elseif (isset($_GET['disable']) ) { + $redirect_url = "/webadmin/" . $params[1] . "/itk/"; require_once EVOADMIN_BASE . '../evolibs/Form.php'; @@ -47,23 +28,31 @@ if (isset($_GET['enable']) ) { include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; $servername = array ( - 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), + 'domain' => $params[1], ); - $disable_cmd = 'web-add.sh disable-user-itk ' . $servername['domain']; + if ($params[2] == "enable") { + $enable_cmd = 'web-add.sh enable-user-itk ' . $servername['domain']; - sudoexec($enable_cmd, $enable_cmd_output, $enable_cmd_return); + sudoexec($enable_cmd, $enable_cmd_output, $enable_cmd_return); - if ($enable_cmd_return == 0) { - print 'Sécurité ITK activée.'; - printf ('

Retour à la gestion ITK

', $redirect_url); - } + if ($enable_cmd_return == 0) { + print 'Sécurité ITK activée.'; + printf ('

Retour à la gestion ITK

', $redirect_url); + } } elseif ($params[2] == "disable") { - $disable_cmd = 'web-add.sh disable-user-itk ' . $servername['servername'] . ' ' . $servername['domain']; + $disable_cmd = 'web-add.sh disable-user-itk ' . $servername['domain']; + + sudoexec($disable_cmd, $disable_cmd_output, $disable_cmd_return); + + if ($disable_cmd_return == 0) { + print 'Sécurité ITK désactivée'; + printf ('

Retour à la gestion ITK

', $redirect_url); + } + } include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; - } else { $domain = $params[1]; diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index 7141acc..8b58619 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -28,8 +28,8 @@ if (isset($params[2]) && $params[2] == "edit") { include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; - $form = new FormPage("Modification du ServerName", FALSE); - $form->addField('domain_servername', new DomainInputFormField("ServerName", TRUE), $params[3]); + $form = new FormPage("Modification du Servername", FALSE); + $form->addField('domain_servername', new DomainInputFormField("Servername", TRUE), $params[3]); $form->addField('previous_servername', new DomainInputFormField("", TRUE, TRUE), $params[3]); if (!empty($_POST)) { @@ -126,22 +126,22 @@ if (isset($params[2]) && $params[2] == "edit") { if ($exec_return == 0) { //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer print "
"; - printf ('

Le ServerName %s a bien été modifié

', $servername['servername']); - printf ('

Retour à la liste des ServerNames

', $redirect_url); + printf ('

Le Servername %s a bien été modifié

', $servername['servername']); + printf ('

Retour à la liste des Servernames

', $redirect_url); print "
"; } else { print "
"; - printf ('

Echec dans la modification du ServerName %s

', $servername['servername']); - printf ('

Retour à la liste des ServerNames

', $redirect_url); + printf ('

Echec dans la modification du Servername %s

', $servername['servername']); + printf ('

Retour à la liste des Servernames

', $redirect_url); print "
"; } } else { print "
"; - printf ('

Echec dans la modification du ServerName %s

', $servername['servername']); + printf ('

Echec dans la modification du Servername %s

', $servername['servername']); print ('

Le domaine existe déjà dans d\'autres vhosts.'); - printf ('

Retour à la liste des ServerNames

', $redirect_url); + printf ('

Retour à la liste des Servernames

', $redirect_url); print "
"; } } @@ -156,10 +156,10 @@ if (isset($params[2]) && $params[2] == "edit") { print ""; } } else { - print "

Modification du ServerName


"; + print "

Modification du Servername


"; print "
"; print "
"; - print " Modification du ServerName"; + print " Modification du Servername"; print $form; print "

"; print "
"; diff --git a/tpl/webadmin-itk.tpl.php b/tpl/webadmin-itk.tpl.php index e5ca180..5819a3c 100644 --- a/tpl/webadmin-itk.tpl.php +++ b/tpl/webadmin-itk.tpl.php @@ -42,7 +42,7 @@ $action = ['enable', 'Activer']; } - printf(''.$action[1].'', + printf(''.$action[1].'', $domain, $action[0]); } print ''; diff --git a/tpl/webadmin-servername.tpl.php b/tpl/webadmin-servername.tpl.php index 50b87d3..f712236 100644 --- a/tpl/webadmin-servername.tpl.php +++ b/tpl/webadmin-servername.tpl.php @@ -34,7 +34,7 @@ printf('%s', $servername); if (is_superadmin()) - printf('Modifier', + printf('Modifier', $domain, $servername); print ''; ?> diff --git a/tpl/webadmin.tpl.php b/tpl/webadmin.tpl.php index b138e19..280b6e9 100755 --- a/tpl/webadmin.tpl.php +++ b/tpl/webadmin.tpl.php @@ -104,12 +104,12 @@ if (is_superadmin()) { printf(''); if (!in_array($vhost_info['owner'], $_SESSION['non_standard'])) { - printf('Alias - ', $vhost_info['owner']); - printf('Servername - ', $vhost_info['owner']); + printf('Alias - ', $vhost_info['owner']); + printf('Servername - ', $vhost_info['owner']); if(is_multiphp()) { - printf('PHP - ', $vhost_info['owner']); + printf('PHP - ', $vhost_info['owner']); } else { - printf('ITK - ', $vhost_info['owner']); + printf('ITK - ', $vhost_info['owner']); } printf('Supprimer', $vhost_info['owner']); } else {