From b6fcb25b3b3823c9ae1874573821eea38b15e0e4 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Tue, 19 Mar 2019 11:46:41 +0100 Subject: [PATCH 01/29] added servernameupdate function --- scripts/web-add.sh | 63 ++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 80ab7aa..94ac4e7 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -109,7 +109,7 @@ del LOGIN [DBNAME] list-vhost LOGIN List Apache vhost for user LOGIN - + check-vhosts -f List suggested changes to vhosts, apply fixes with -f @@ -121,6 +121,10 @@ del-alias VHOST ALIAS Del a ServerAlias from an Apache vhost +update-servername VHOST SERVERNAME + + Update the ServerName from an Apache vhost + setphpversion LOGIN VERSION Change PHP version for LOGIN @@ -261,7 +265,7 @@ create_www_account() { ${in_gid:+'--gid' "$in_gid"} \ --force-badname \ --home "$HOME_DIR_USER" >/dev/null - + [ -z "$in_sshkey" ] \ && echo "$in_login:$in_passwd" | chpasswd @@ -272,7 +276,7 @@ create_www_account() { && chmod -R u=rwX,g=,o= "$HOME_DIR_USER/.ssh/authorized_keys" \ && chown -R "$in_login":"$in_login" "$HOME_DIR_USER/.ssh" - if [ "$WEB_SERVER" == "apache" ]; then + if [ "$WEB_SERVER" == "apache" ]; then # Create www user and force UID if specified /usr/sbin/adduser \ --gecos "WWW $in_login" \ @@ -486,25 +490,25 @@ EOT if [ "$in_dbname" ]; then 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/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#" \ < $TPL_MAIL | /usr/lib/sendmail -oi -t -f "$CONTACT_MAIL" else sed -e " - s/LOGIN/$in_login/g ; - s/SERVERNAME/$in_wwwdomain/ ; - s/PASSE1/$in_passwd/ ; - s/RANDOM/$random/ ; - s/QUOTA/$quota/ ; - s/RCPTTO/$in_mail/ ; - s#HOME_DIR#$HOME_DIR# ; + s/LOGIN/$in_login/g ; + s/SERVERNAME/$in_wwwdomain/ ; + s/PASSE1/$in_passwd/ ; + s/RANDOM/$random/ ; + s/QUOTA/$quota/ ; + s/RCPTTO/$in_mail/ ; + s#HOME_DIR#$HOME_DIR# ; 39,58d" \ < $TPL_MAIL | /usr/lib/sendmail -oi -t -f "$CONTACT_MAIL" fi @@ -719,7 +723,7 @@ arg_processing() { ;; list-vhost) op_listvhost "$@" - ;; + ;; check-vhosts) op_checkvhosts "$@" ;; @@ -729,6 +733,9 @@ arg_processing() { del-alias) op_aliasdel "$@" ;; + update-servername) + op_servernameupdate "$@" + ;; setphpversion) op_setphpversion "$@" ;; @@ -803,6 +810,20 @@ op_aliasdel() { fi } +op_servernameupdate() { + if [ $# -eq 2 ]; then + vhost="${1}.conf" + servername=$2 + + [ -f $VHOST_PATH/"$vhost" ] && sed -i "s/ServerName .*/ServerName $servername/" $VHOST_PATH/"$vhost" --follow-symlinks + + apache2ctl configtest 2>/dev/null + /etc/init.d/apache2 force-reload >/dev/null + + else usage + fi +} + op_add() { # @@ -1006,7 +1027,7 @@ op_add() { op_checkvhosts() { ln_vhosts_dir="$(sed 's/available/enabled/' <<< "$VHOST_PATH")" non_ln_vhosts="$(find "$ln_vhosts_dir"/* ! -type l)" - + while getopts f opt; do case "$opt" in f) @@ -1018,7 +1039,7 @@ op_checkvhosts() { ;; esac done - + for ln_path in $non_ln_vhosts do vhost_name=$(basename "$ln_path") -- 2.39.2 From 6e8ea737de17dfacd5ef2ee06544e40664f6006a Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Tue, 19 Mar 2019 15:37:32 +0100 Subject: [PATCH 02/29] replace ServerName inside Rewrite rules --- scripts/web-add.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 94ac4e7..6a817e7 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -814,8 +814,10 @@ op_servernameupdate() { if [ $# -eq 2 ]; then vhost="${1}.conf" servername=$2 + old_servername=$(grep ServerName $VHOST_PATH/"$vhost" | awk '{print $2;}') - [ -f $VHOST_PATH/"$vhost" ] && sed -i "s/ServerName .*/ServerName $servername/" $VHOST_PATH/"$vhost" --follow-symlinks + [ -f $VHOST_PATH/"$vhost" ] && sed -i "s/ServerName .*/ServerName $servername/" $VHOST_PATH/"$vhost" --follow-symlinks \ + && sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" $VHOST_PATH/"$vhost" --follow-symlinks apache2ctl configtest 2>/dev/null /etc/init.d/apache2 force-reload >/dev/null -- 2.39.2 From fdce16652aac0dddbfa7b30d49f1b10dec108bee Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Thu, 21 Mar 2019 09:52:40 +0100 Subject: [PATCH 03/29] allow default value for field --- evolibs/Form.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/evolibs/Form.php b/evolibs/Form.php index 3df9cfe..1e23ccd 100644 --- a/evolibs/Form.php +++ b/evolibs/Form.php @@ -187,8 +187,9 @@ class FormPage { } } - public function addField($name, $obj) { + public function addField($name, $obj, $default_value="") { $obj->setName($name); + if ($default_value != "") $obj->setValue($default_value); array_push($this->fields, array($name, $obj)); } -- 2.39.2 From 794defa907820e2bac768a2d2b16b3ddc6a3ab6e Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Thu, 21 Mar 2019 10:01:58 +0100 Subject: [PATCH 04/29] retrieve first ServerName and change it with the new one in all the conf file --- scripts/web-add.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 6a817e7..57ef87a 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -814,9 +814,9 @@ op_servernameupdate() { if [ $# -eq 2 ]; then vhost="${1}.conf" servername=$2 - old_servername=$(grep ServerName $VHOST_PATH/"$vhost" | awk '{print $2;}') - - [ -f $VHOST_PATH/"$vhost" ] && sed -i "s/ServerName .*/ServerName $servername/" $VHOST_PATH/"$vhost" --follow-symlinks \ + old_servername=$(grep ServerName $VHOST_PATH/"$vhost" | awk '{print $2;}' | head -n1) + # Remplacement de toutes les directives ServerName, on assume qu'il s'agit du même pour chaque vhost du fichier + [ -f $VHOST_PATH/"$vhost" ] && sed -i "s/ServerName .*/ServerName $servername/g" $VHOST_PATH/"$vhost" --follow-symlinks \ && sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" $VHOST_PATH/"$vhost" --follow-symlinks apache2ctl configtest 2>/dev/null -- 2.39.2 From 7e02e5004739e524a2407f87c7b366599869fa0a Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Thu, 21 Mar 2019 10:02:23 +0100 Subject: [PATCH 05/29] update ServerName from web interface --- htdocs/index.php | 4 + inc/webadmin-servername.php | 193 ++++++++++++++++++++++++++++++++ tpl/webadmin-servername.tpl.php | 55 +++++++++ 3 files changed, 252 insertions(+) create mode 100644 inc/webadmin-servername.php create mode 100644 tpl/webadmin-servername.tpl.php diff --git a/htdocs/index.php b/htdocs/index.php index 47fe6f4..f1aacd9 100755 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -48,6 +48,10 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) { include_once EVOADMIN_BASE . '../inc/webadmin.php'; +} elseif (preg_match('#^/webadmin/servername/(.*)/?$#', $uri, $params)) { + + include_once EVOADMIN_BASE . '../inc/webadmin-servername.php'; + } elseif (preg_match('#^/webadmin/edit/(.*)/?$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php new file mode 100644 index 0000000..f577b67 --- /dev/null +++ b/inc/webadmin-servername.php @@ -0,0 +1,193 @@ + + * @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; + +if (isset($_GET['edit']) ) { + require_once EVOADMIN_BASE . '../evolibs/Form.php'; + + include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; + + $form = new FormPage("Modification du Server Name", FALSE); + $form->addField('domain_servername', new TextInputFormField("Server Name", FALSE), $_GET['edit']); + + if (!empty($_POST)) { + $form->isCurrentPage(TRUE); + $form->initFields(); + + if ($form->verify(TRUE)) { + if ($conf['cluster']) { + if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); + } + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + } + else { + $cache = $conf['cache']; + } + $bdd = new bdd(); + $bdd->open($cache); + + $serveralias = array ( + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), + 'alias' => $form->getField('domain_alias')->getValue(), + ); + + $account_name=$serveralias['domain']; + $account = $bdd->get_account($account_name); + + + if (sizeof($account) == 0) + die("Anomalie... Contactez votre administrateur."); + + $master = $bdd->get_server_from_roleid($account['id_master']); + $slave = $bdd->get_server_from_roleid($account['id_slave']); + + + if ( $bdd->is_serveralias( $account_name, $serveralias['alias'] ) == 0 ) { + + /* web-add-cluster addalias */ + $exec_cmd = 'web-add-cluster.sh add-alias '.$serveralias['domain'].' '.$serveralias['alias'].' '.$master.' '.$slave; + sudoexec($exec_cmd, $exec_output, $exec_return); + + + + if ($exec_return == 0) { + /* Ajout BDD */ + $bdd->add_serveralias($serveralias); + + domain_add($serveralias['alias'], gethostbyname($master) , false); + + # Si le compte en question est en replication temps + # reel, il faut faire un restart manuel de lsyncd + # pour prendre en compte le nouveau domaine. + if ($account['replication'] == "realtime") { + mail('tech@evolix.fr', "[TAF] Redemarrer lsyncd sur $master", wordwrap('killer tous les processus lsyncd lancé par vmail pour le compte '.$account['name'].' et les relancer (cf. la ligne correspondante à ce compte dans la crontab de vmail).\n', 70)); + } + + print "
"; + printf ('

L\'alias %s du domaine %s a bien été créé

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

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); + print "
"; + } else { + print "
"; + printf ('

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

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

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); + print "
"; + } + } else { + print "
"; + printf ('

Alias %s du domaine %s deja existant !

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

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); + print "
"; + + } + } + else { + $servername = array ( + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), + 'servername' => $form->getField('domain_servername')->getValue(), + ); + + $account_name=$servername['domain']; + + $exec_cmd = 'web-add.sh update-servername ' . $servername['domain'] . ' ' . $servername['servername']; + sudoexec($exec_cmd, $exec_output, $exec_return); + if ($exec_return == 0) { + //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer + print "
"; + printf ('

Le Server Name %s du domaine %s a bien été modifié

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

Retour à la liste des Server Names

', $_SERVER['REDIRECT_URL']); + print "
"; + } + else { + print "
"; + printf ('

Echec dans la modification du Server Name %s du domaine %s

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

Retour à la liste des Server Names

', $_SERVER['REDIRECT_URL']); + print "
"; + } + } + } + } else { + print "

Modification du ServerName


"; + print "
"; + print "
"; + print " Modification du Server Name"; + print $form; + print "

"; + print "
"; + print "
"; + + } + + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; + + +} else { + + $domain = $params[1]; + $servername_list = array(); + + // TODO: adapt for cluster mode + if ($conf['cluster']) { + if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); + } + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + } + else { + $cache = $conf['cache']; + } + + $alias_list = array(); + + /* parcours de la table Serveralias */ + $bdd = new bdd(); + $bdd->open($cache); + + $alias_list = $bdd->list_serveralias($domain); + } + else { + $cmd = 'web-add.sh list-vhost'; + if(!is_superadmin()) { + $cmd = sprintf('%s %s', $cmd, $_SESSION['user']); + } + sudoexec($cmd, $data_output, $exec_return); + + foreach($data_output as $data_line) { + $data_split = explode(':', $data_line); + if ($data_split[0] == $domain && $data_split[2] != '') { + // Fonctionne uniquement pour un seul et même servername par conf + array_push($servername_list, $data_split[2]); + } + } + } + + include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/webadmin-servername.tpl.php'; + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; + +} + +?> diff --git a/tpl/webadmin-servername.tpl.php b/tpl/webadmin-servername.tpl.php new file mode 100644 index 0000000..70cdc2f --- /dev/null +++ b/tpl/webadmin-servername.tpl.php @@ -0,0 +1,55 @@ + + * @version 1.0 + */ + +?> + +

Server Name

+ + 0) { ?> + + + + + + Action'; + } ?> + + + + '; + printf('', + $servername_list[$i]); + if (is_superadmin()) + printf('', + $domain, $servername_list[$i]); + print ''; + } ?> + +
Server Name
%sModifier
+Aucun alias existant pour le domaine $domain !

"; + if (is_superadmin()) { + print "
"; + printf('

Ajouter un alias

', $domain); + print "
"; + } + } + + +?> -- 2.39.2 From 20aeb60cda10b4136f77a766c2c47add84f6ce2d Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Thu, 21 Mar 2019 10:12:32 +0100 Subject: [PATCH 06/29] using DomainInputFormField for ServerName update field --- inc/webadmin-servername.php | 14 +++++++------- tpl/webadmin-servername.tpl.php | 11 +++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index f577b67..68d9db2 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -24,8 +24,8 @@ if (isset($_GET['edit']) ) { include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; - $form = new FormPage("Modification du Server Name", FALSE); - $form->addField('domain_servername', new TextInputFormField("Server Name", FALSE), $_GET['edit']); + $form = new FormPage("Modification du ServerName", FALSE); + $form->addField('domain_servername', new DomainInputFormField("ServerName", FALSE), $_GET['edit']); if (!empty($_POST)) { $form->isCurrentPage(TRUE); @@ -114,14 +114,14 @@ if (isset($_GET['edit']) ) { if ($exec_return == 0) { //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer print "
"; - printf ('

Le Server Name %s du domaine %s a bien été modifié

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

Retour à la liste des Server Names

', $_SERVER['REDIRECT_URL']); + printf ('

Le ServerName %s du domaine %s a bien été modifié

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

Retour à la liste des ServerNames

', $_SERVER['REDIRECT_URL']); print "
"; } else { print "
"; - printf ('

Echec dans la modification du Server Name %s du domaine %s

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

Retour à la liste des Server Names

', $_SERVER['REDIRECT_URL']); + printf ('

Echec dans la modification du ServerName %s du domaine %s

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

Retour à la liste des ServerNames

', $_SERVER['REDIRECT_URL']); print "
"; } } @@ -130,7 +130,7 @@ if (isset($_GET['edit']) ) { print "

Modification du ServerName


"; print "
"; print "
"; - print " Modification du Server Name"; + print " Modification du ServerName"; print $form; print "

"; print "
"; diff --git a/tpl/webadmin-servername.tpl.php b/tpl/webadmin-servername.tpl.php index 70cdc2f..5e218cb 100644 --- a/tpl/webadmin-servername.tpl.php +++ b/tpl/webadmin-servername.tpl.php @@ -13,7 +13,7 @@ ?> -

Server Name

+

ServerNames

- Server Name + ServerName Action'; } ?> @@ -43,12 +43,7 @@ Aucun alias existant pour le domaine $domain !

"; - if (is_superadmin()) { - print "
"; - printf('

Ajouter un alias

', $domain); - print "
"; - } + print "

Aucun ServerName existant pour le domaine $domain !

"; } -- 2.39.2 From f90b127a950700b4567c5852542d0b89ffcfc38a Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Fri, 22 Mar 2019 10:52:04 +0100 Subject: [PATCH 07/29] list servername linked to file conf --- inc/webadmin-servername.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index 68d9db2..75e4ef0 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -109,6 +109,10 @@ if (isset($_GET['edit']) ) { $account_name=$servername['domain']; + // $exec_cmd_check_occurence = 'web-add.sh'; + // grep -RE "^.*(ServerName|ServerAlias)[[:space:]]wutang[[:space:]]" + // faire un if else + $exec_cmd = 'web-add.sh update-servername ' . $servername['domain'] . ' ' . $servername['servername']; sudoexec($exec_cmd, $exec_output, $exec_return); if ($exec_return == 0) { @@ -168,7 +172,9 @@ if (isset($_GET['edit']) ) { $alias_list = $bdd->list_serveralias($domain); } else { - $cmd = 'web-add.sh list-vhost'; + + $cmd = 'web-add.sh list-vhost ' . $domain; + if(!is_superadmin()) { $cmd = sprintf('%s %s', $cmd, $_SESSION['user']); } -- 2.39.2 From d5f4e27840fa6612ad3d9d95cd472d1d42d26163 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Fri, 22 Mar 2019 14:56:51 +0100 Subject: [PATCH 08/29] option for hidden input in DomainInputFormField class --- evolibs/Form.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/evolibs/Form.php b/evolibs/Form.php index 1e23ccd..97b6921 100644 --- a/evolibs/Form.php +++ b/evolibs/Form.php @@ -463,9 +463,10 @@ class DomainInputFormField extends FormField { protected $mandatory = NULL; protected $textsize = NULL; - public function __construct($label, $mandatory=TRUE) { + public function __construct($label, $mandatory=TRUE, $hidden=FALSE) { parent::__construct($label); $this->mandatory = $mandatory; + $this->hidden = $hidden; $this->textsize = $textsize; } @@ -485,7 +486,10 @@ class DomainInputFormField extends FormField { public function getInputHTML() { $input = ''; - $input .= 'hidden) + $input .= 'name.'"'; $input .= ' name="'.$this->name.'" value="'.htmlspecialchars($this->value,ENT_QUOTES).'"'; $input .= ' maxlength="'.$this->textsize[1].'" size="'.$this->textsize[0].'" '; if($this->read_only) { $input .= 'readonly="readonly="'; } @@ -497,9 +501,13 @@ class DomainInputFormField extends FormField { public function __toString() { $out = ''; $out .= "

\n"; - $out .= $this->getLabelHTML(); - $out .= $this->getInputHTML(); - $out .= $this->getErrorHTML(); + if ($this->hidden) { + $out .= $this->getInputHTML(); + } else { + $out .= $this->getLabelHTML(); + $out .= $this->getInputHTML(); + $out .= $this->getErrorHTML(); + } $out .= "

\n\n"; return $out; } -- 2.39.2 From 38308afcf793ea925b0c9cd725931de9b019ae64 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Fri, 22 Mar 2019 15:00:44 +0100 Subject: [PATCH 09/29] list servername and relace previous servername with new one --- scripts/web-add.sh | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 57ef87a..532f634 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -111,6 +111,7 @@ list-vhost LOGIN List Apache vhost for user LOGIN check-vhosts -f + List suggested changes to vhosts, apply fixes with -f add-alias VHOST ALIAS @@ -121,9 +122,14 @@ del-alias VHOST ALIAS Del a ServerAlias from an Apache vhost -update-servername VHOST SERVERNAME +list-servername LOGIN - Update the ServerName from an Apache vhost + 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 setphpversion LOGIN VERSION @@ -733,6 +739,9 @@ arg_processing() { del-alias) op_aliasdel "$@" ;; + list-servername) + op_listservername "$@" + ;; update-servername) op_servernameupdate "$@" ;; @@ -810,13 +819,26 @@ op_aliasdel() { fi } +op_listservername() { + if [ $# -eq 1 ]; then + configfile="$VHOST_PATH/${1}.conf"; + + for servername in $(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq); do + echo "$servername"; + done + + else usage + fi +} + op_servernameupdate() { - if [ $# -eq 2 ]; then + if [ $# -eq 3 ]; then vhost="${1}.conf" servername=$2 - old_servername=$(grep ServerName $VHOST_PATH/"$vhost" | awk '{print $2;}' | head -n1) + old_servername=$3 + # Remplacement de toutes les directives ServerName, on assume qu'il s'agit du même pour chaque vhost du fichier - [ -f $VHOST_PATH/"$vhost" ] && sed -i "s/ServerName .*/ServerName $servername/g" $VHOST_PATH/"$vhost" --follow-symlinks \ + [ -f $VHOST_PATH/"$vhost" ] && sed -i "/^ *ServerName/ s/$old_servername/$servername/g" $VHOST_PATH/"$vhost" --follow-symlinks \ && sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" $VHOST_PATH/"$vhost" --follow-symlinks apache2ctl configtest 2>/dev/null -- 2.39.2 From 28149ed2298213b955c084d6139e459e04eb10ed Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Fri, 22 Mar 2019 15:22:22 +0100 Subject: [PATCH 10/29] change ServerName for a specific vhost --- inc/webadmin-servername.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index 75e4ef0..a3b7523 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -26,6 +26,7 @@ if (isset($_GET['edit']) ) { $form = new FormPage("Modification du ServerName", FALSE); $form->addField('domain_servername', new DomainInputFormField("ServerName", FALSE), $_GET['edit']); + $form->addField('previous_servername', new DomainInputFormField("", FALSE, TRUE), $_GET['edit']); if (!empty($_POST)) { $form->isCurrentPage(TRUE); @@ -33,6 +34,7 @@ if (isset($_GET['edit']) ) { if ($form->verify(TRUE)) { if ($conf['cluster']) { + // TODO: Adapt the script for cluster mode if (is_mcluster_mode()) { // If the user has not yet selected a cluster, redirect-it to home page. if (empty($_SESSION['cluster'])) { @@ -46,12 +48,13 @@ if (isset($_GET['edit']) ) { $bdd = new bdd(); $bdd->open($cache); - $serveralias = array ( + $servername = array ( 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), - 'alias' => $form->getField('domain_alias')->getValue(), + 'servername' => $form->getField('domain_servername')->getValue(), + 'previous_servername' => $form->getField('previous_servername')->getValue(), ); - $account_name=$serveralias['domain']; + $account_name=$servername['domain']; $account = $bdd->get_account($account_name); @@ -105,6 +108,7 @@ if (isset($_GET['edit']) ) { $servername = array ( 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), 'servername' => $form->getField('domain_servername')->getValue(), + 'previous_servername' => $form->getField('previous_servername')->getValue(), ); $account_name=$servername['domain']; @@ -113,7 +117,7 @@ if (isset($_GET['edit']) ) { // grep -RE "^.*(ServerName|ServerAlias)[[:space:]]wutang[[:space:]]" // faire un if else - $exec_cmd = 'web-add.sh update-servername ' . $servername['domain'] . ' ' . $servername['servername']; + $exec_cmd = 'web-add.sh update-servername ' . $servername['domain'] . ' ' . $servername['servername'] . ' ' . $servername['previous_servername']; sudoexec($exec_cmd, $exec_output, $exec_return); if ($exec_return == 0) { //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer @@ -173,7 +177,7 @@ if (isset($_GET['edit']) ) { } else { - $cmd = 'web-add.sh list-vhost ' . $domain; + $cmd = 'web-add.sh list-servername ' . $domain; if(!is_superadmin()) { $cmd = sprintf('%s %s', $cmd, $_SESSION['user']); @@ -181,11 +185,7 @@ if (isset($_GET['edit']) ) { sudoexec($cmd, $data_output, $exec_return); foreach($data_output as $data_line) { - $data_split = explode(':', $data_line); - if ($data_split[0] == $domain && $data_split[2] != '') { - // Fonctionne uniquement pour un seul et même servername par conf - array_push($servername_list, $data_split[2]); - } + array_push($servername_list, $data_line); } } -- 2.39.2 From ce66f0b9b89f8df2dd0a893ed95aa2051d0599eb Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 10:43:24 +0100 Subject: [PATCH 11/29] enabled field verification for ServerName --- inc/webadmin-servername.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index a3b7523..69bd426 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -25,8 +25,8 @@ if (isset($_GET['edit']) ) { include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; $form = new FormPage("Modification du ServerName", FALSE); - $form->addField('domain_servername', new DomainInputFormField("ServerName", FALSE), $_GET['edit']); - $form->addField('previous_servername', new DomainInputFormField("", FALSE, TRUE), $_GET['edit']); + $form->addField('domain_servername', new DomainInputFormField("ServerName", TRUE), $_GET['edit']); + $form->addField('previous_servername', new DomainInputFormField("", TRUE, TRUE), $_GET['edit']); if (!empty($_POST)) { $form->isCurrentPage(TRUE); @@ -133,16 +133,25 @@ if (isset($_GET['edit']) ) { print ""; } } + } else { + print "

Modification du ServerName


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

"; + print "
"; + print ""; } } else { - print "

Modification du ServerName


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

"; - print "
"; - print "
"; + print "

Modification du ServerName


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

"; + print "
"; + print "
"; } -- 2.39.2 From fed8a1fc84f002ca17993de3308756a36ca2d27b Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 11:34:03 +0100 Subject: [PATCH 12/29] Added function to search occurence of given name in vhosts --- scripts/web-add.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 532f634..b421326 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -131,6 +131,10 @@ update-servername VHOST SERVERNAME OLD_SERVERNAME Replace the OLD_SERVERNAME with the SERVERNAME for an Apache vhost Also apply to rules +check-occurence NAME + + List all occurences of NAME in vhosts + setphpversion LOGIN VERSION Change PHP version for LOGIN @@ -745,6 +749,9 @@ arg_processing() { update-servername) op_servernameupdate "$@" ;; + check-occurence) + op_checkoccurencename "$@" + ;; setphpversion) op_setphpversion "$@" ;; @@ -848,6 +855,26 @@ op_servernameupdate() { fi } +op_checkoccurencename() { + if [ $# -eq 1 ]; then + name=${1} + configlist="$VHOST_PATH/*"; + servernames='' + aliases='' + + for configfile in $configlist; do + if [ -r "$configfile" ]; then + aliases="$aliases $(perl -ne 'print "$1 " if /^[[:space:]]*ServerAlias (.*)/' "$configfile" | head -n 1)" + servernames="$servernames $(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq)" + fi + done + + echo "$servernames" "$aliases" | grep -w "$name" + + else usage + fi +} + op_add() { # -- 2.39.2 From 4153145c5d661cd0ba08047193fdd3450a41613a Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 11:57:55 +0100 Subject: [PATCH 13/29] Added check-occurence for servername update --- inc/webadmin-servername.php | 42 +++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index 69bd426..36cfd56 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -33,8 +33,8 @@ if (isset($_GET['edit']) ) { $form->initFields(); if ($form->verify(TRUE)) { + // TODO: Adapt the script for cluster mode if ($conf['cluster']) { - // TODO: Adapt the script for cluster mode if (is_mcluster_mode()) { // If the user has not yet selected a cluster, redirect-it to home page. if (empty($_SESSION['cluster'])) { @@ -113,24 +113,34 @@ if (isset($_GET['edit']) ) { $account_name=$servername['domain']; - // $exec_cmd_check_occurence = 'web-add.sh'; - // grep -RE "^.*(ServerName|ServerAlias)[[:space:]]wutang[[:space:]]" - // faire un if else + $check_occurence_cmd = 'web-add.sh check-occurence ' . $servername['servername']; + sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); - $exec_cmd = 'web-add.sh update-servername ' . $servername['domain'] . ' ' . $servername['servername'] . ' ' . $servername['previous_servername']; - sudoexec($exec_cmd, $exec_output, $exec_return); - if ($exec_return == 0) { - //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer - print "
"; - printf ('

Le ServerName %s du domaine %s a bien été modifié

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

Retour à la liste des ServerNames

', $_SERVER['REDIRECT_URL']); - print "
"; + // Check if the name is present in vhosts already, returns 1 if no + if ($check_occurence_return == 1) { + $exec_cmd = 'web-add.sh update-servername ' . $servername['domain'] . ' ' . $servername['servername'] . ' ' . $servername['previous_servername']; + sudoexec($exec_cmd, $exec_output, $exec_return); + + 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

', $_SERVER['REDIRECT_URL']); + print "
"; + } + else { + print "
"; + printf ('

Echec dans la modification du ServerName %s

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

Retour à la liste des ServerNames

', $_SERVER['REDIRECT_URL']); + print "
"; + } } else { - print "
"; - printf ('

Echec dans la modification du ServerName %s du domaine %s

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

Retour à la liste des ServerNames

', $_SERVER['REDIRECT_URL']); - print "
"; + print "
"; + 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

', $_SERVER['REDIRECT_URL']); + print "
"; } } } else { -- 2.39.2 From bbada41dd565f0ef14b5339634908cce51093531 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 12:04:55 +0100 Subject: [PATCH 14/29] Added check-occurence for alias creation --- inc/webadmin-edit.php | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/inc/webadmin-edit.php b/inc/webadmin-edit.php index 910a771..0606e27 100644 --- a/inc/webadmin-edit.php +++ b/inc/webadmin-edit.php @@ -185,23 +185,36 @@ if (isset($_GET['del']) ) { 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), 'alias' => $form->getField('domain_alias')->getValue(), ); - + $account_name=$serveralias['domain']; - $exec_cmd = 'web-add.sh add-alias ' . $serveralias['domain'] . ' ' . $serveralias['alias']; - sudoexec($exec_cmd, $exec_output, $exec_return); - if ($exec_return == 0) { - //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer - print "
"; - printf ('

L\'alias %s du domaine %s a bien été créé

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

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); - print "
"; + $check_occurence_cmd = 'web-add.sh check-occurence ' . $serveralias['alias']; + sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); + + // Check if the name is present in vhosts already, returns 1 if no + if ($check_occurence_return == 1) { + $exec_cmd = 'web-add.sh add-alias ' . $serveralias['domain'] . ' ' . $serveralias['alias']; + sudoexec($exec_cmd, $exec_output, $exec_return); + if ($exec_return == 0) { + //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer + print "
"; + printf ('

L\'alias %s du domaine %s a bien été créé

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

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); + print "
"; + } + else { + print "
"; + printf ('

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

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

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); + print "
"; + } } else { - print "
"; - printf ('

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

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

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); - print "
"; + print "
"; + printf ('

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

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

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

Retour à la liste des alias

', $_SERVER['REDIRECT_URL']); + print "
"; } } } -- 2.39.2 From 24c4e4236d8f46ec4d7f5f62525118225f09bd15 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 13:09:02 +0100 Subject: [PATCH 15/29] move the check-occurence logic to a function --- lib/domain.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/domain.php b/lib/domain.php index a63df20..94d4c20 100644 --- a/lib/domain.php +++ b/lib/domain.php @@ -27,3 +27,10 @@ function domain_add($name, $IP, $with_mxs, $gmail=false) { return array($exec_cmd, $exec_return, $exec_output); } +// Check if the name is present in vhosts already, returns 1 if no +function check_occurence_name($name) { + $check_occurence_cmd = 'web-add.sh check-occurence ' . $name; + sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); + + return $check_occurence_return; +} -- 2.39.2 From cf4d066f0ef3f56a4c9d271a2422de5a5c309145 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 13:10:09 +0100 Subject: [PATCH 16/29] call function check_occurence for alias and servername --- inc/webadmin-edit.php | 4 +--- inc/webadmin-servername.php | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/inc/webadmin-edit.php b/inc/webadmin-edit.php index 0606e27..469eb2a 100644 --- a/inc/webadmin-edit.php +++ b/inc/webadmin-edit.php @@ -188,10 +188,8 @@ if (isset($_GET['del']) ) { $account_name=$serveralias['domain']; - $check_occurence_cmd = 'web-add.sh check-occurence ' . $serveralias['alias']; - sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); + $check_occurence_return = check_occurence_name($serveralias['alias']); - // Check if the name is present in vhosts already, returns 1 if no if ($check_occurence_return == 1) { $exec_cmd = 'web-add.sh add-alias ' . $serveralias['domain'] . ' ' . $serveralias['alias']; sudoexec($exec_cmd, $exec_output, $exec_return); diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index 36cfd56..b2ec9c8 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -113,14 +113,12 @@ if (isset($_GET['edit']) ) { $account_name=$servername['domain']; - $check_occurence_cmd = 'web-add.sh check-occurence ' . $servername['servername']; - sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); - - // Check if the name is present in vhosts already, returns 1 if no + $check_occurence_return = check_occurence_name($servername['servername']); + if ($check_occurence_return == 1) { $exec_cmd = 'web-add.sh update-servername ' . $servername['domain'] . ' ' . $servername['servername'] . ' ' . $servername['previous_servername']; sudoexec($exec_cmd, $exec_output, $exec_return); - + if ($exec_return == 0) { //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer print "
"; -- 2.39.2 From 2f25655038388787a46ef0c6115e2b3ccf9c0999 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 14:36:43 +0100 Subject: [PATCH 17/29] using better var names for check occurence return code --- inc/webadmin-edit.php | 4 ++-- inc/webadmin-servername.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/inc/webadmin-edit.php b/inc/webadmin-edit.php index 469eb2a..c8a579f 100644 --- a/inc/webadmin-edit.php +++ b/inc/webadmin-edit.php @@ -188,9 +188,9 @@ if (isset($_GET['del']) ) { $account_name=$serveralias['domain']; - $check_occurence_return = check_occurence_name($serveralias['alias']); + $is_alias_present = check_occurence_name($serveralias['alias']); - if ($check_occurence_return == 1) { + if (!$is_alias_present) { $exec_cmd = 'web-add.sh add-alias ' . $serveralias['domain'] . ' ' . $serveralias['alias']; sudoexec($exec_cmd, $exec_output, $exec_return); if ($exec_return == 0) { diff --git a/inc/webadmin-servername.php b/inc/webadmin-servername.php index b2ec9c8..a68d7c2 100644 --- a/inc/webadmin-servername.php +++ b/inc/webadmin-servername.php @@ -113,9 +113,9 @@ if (isset($_GET['edit']) ) { $account_name=$servername['domain']; - $check_occurence_return = check_occurence_name($servername['servername']); - - if ($check_occurence_return == 1) { + $is_servername_present = check_occurence_name($servername['servername']); + + if (!$is_servername_present) { $exec_cmd = 'web-add.sh update-servername ' . $servername['domain'] . ' ' . $servername['servername'] . ' ' . $servername['previous_servername']; sudoexec($exec_cmd, $exec_output, $exec_return); -- 2.39.2 From 0bfe7a2aac1f25bb172eb3898e42a213532da8cb Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 14:37:17 +0100 Subject: [PATCH 18/29] update check_occurence_name function to work with multiple aliases --- lib/domain.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/domain.php b/lib/domain.php index 94d4c20..0e33f93 100644 --- a/lib/domain.php +++ b/lib/domain.php @@ -27,10 +27,15 @@ function domain_add($name, $IP, $with_mxs, $gmail=false) { return array($exec_cmd, $exec_return, $exec_output); } -// Check if the name is present in vhosts already, returns 1 if no function check_occurence_name($name) { - $check_occurence_cmd = 'web-add.sh check-occurence ' . $name; - sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); - return $check_occurence_return; + $exploded_names = explode(',', $name); + + foreach ($exploded_names as $current_name) { + $check_occurence_cmd = 'web-add.sh check-occurence ' . $current_name; + sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); + if ($check_occurence_return == 0) return true; + } + + return false; } -- 2.39.2 From 6f0106d4d0fc9417d9e65ff5f4d35324e005f5c2 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 14:37:44 +0100 Subject: [PATCH 19/29] implement check_occurence_name on account creation --- inc/accounts.php | 12 +++++++++++- tpl/accounts.tpl.php | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/inc/accounts.php b/inc/accounts.php index e790701..a223167 100644 --- a/inc/accounts.php +++ b/inc/accounts.php @@ -388,11 +388,21 @@ if(!empty($_POST)) { /* Test de validation du formulaire */ if($form->verify(TRUE)) { + $is_domain_present = check_occurence_name($form->getField('domain')->getValue()); + $is_alias_present = check_occurence_name($form->getField('domain_alias')->getValue()); + + if (!$is_domain_present && !$is_alias_present) { if ($conf['cluster']) $exec_info = web_add_cluster($form, $conf['admin']['mail']); else $exec_info = web_add($form, $conf['admin']['mail']); - } + } + else { + $errors_check = array(); + if ($is_domain_present) array_push($errors_check, "Domaine déjà présent dans d'autres vhosts."); + if ($is_alias_present) array_push($errors_check, "Alias déjà présent(s) dans d'autres vhosts."); + } + } } include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; diff --git a/tpl/accounts.tpl.php b/tpl/accounts.tpl.php index 34cc35c..859b442 100644 --- a/tpl/accounts.tpl.php +++ b/tpl/accounts.tpl.php @@ -34,8 +34,15 @@ print ''; } else { -?> + if (isset($errors_check)) { + print '

Erreur(s) :
'; + foreach ($errors_check as $error) { + printf('%s
', $error); + } + print '

'; + } +?>
Ajout d'un compte -- 2.39.2 From 89858a6bbde022a2d28452d10c0016952958b938 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 18:05:37 +0100 Subject: [PATCH 20/29] first draft itk mgmt --- htdocs/index.php | 4 ++ inc/webadmin-itk.php | 130 +++++++++++++++++++++++++++++++++++++++ scripts/web-add.sh | 55 +++++++++++++++++ tpl/webadmin-itk.tpl.php | 61 ++++++++++++++++++ 4 files changed, 250 insertions(+) create mode 100644 inc/webadmin-itk.php create mode 100644 tpl/webadmin-itk.tpl.php diff --git a/htdocs/index.php b/htdocs/index.php index f1aacd9..7e78c11 100755 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -52,6 +52,10 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) { include_once EVOADMIN_BASE . '../inc/webadmin-servername.php'; +} elseif (preg_match('#^/webadmin/itk/(.*)/?$#', $uri, $params)) { + + include_once EVOADMIN_BASE . '../inc/webadmin-itk.php'; + } elseif (preg_match('#^/webadmin/edit/(.*)/?$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; diff --git a/inc/webadmin-itk.php b/inc/webadmin-itk.php new file mode 100644 index 0000000..51ea1d0 --- /dev/null +++ b/inc/webadmin-itk.php @@ -0,0 +1,130 @@ + + * @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; + +var_dump($_SESSION); +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'; + + + # TODO: sanitize $_GET + $servername = array ( + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), + 'servername' => $_GET['enable'] + ); + + $enable_cmd = 'web-add.sh enable-user-itk ' . $servername['servername'] . ' ' . $servername['domain']; + + 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

', $_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'; + + + # TODO: sanitize $_GET + $servername = array ( + 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), + 'servername' => $_GET['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

', $_SERVER['REDIRECT_URL']); + } + + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; + + +} +else { + + $domain = $params[1]; + $data_list = array(); + + // TODO: adapt for cluster mode + if ($conf['cluster']) { + if (is_mcluster_mode()) { + // If the user has not yet selected a cluster, redirect-it to home page. + if (empty($_SESSION['cluster'])) { + http_redirect('/'); + } + $cache = str_replace('%cluster_name%', $_SESSION['cluster'], $conf['cache']); + } + else { + $cache = $conf['cache']; + } + + $alias_list = array(); + + /* parcours de la table Serveralias */ + $bdd = new bdd(); + $bdd->open($cache); + + $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; + + 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 + } + } + } + + 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 b421326..a40ed95 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -135,6 +135,18 @@ check-occurence NAME List all occurences of NAME in vhosts +list-user-itk DOMAIN LOGIN + + List the assigned ITK user for the DOMAIN specified + +enable-user-itk DOMAIN LOGIN + + Enable the assigned ITK user for the DOMAIN specified + +disable-user-itk DOMAIN LOGIN + + Disable the assigned ITK user for the DOMAIN specified + setphpversion LOGIN VERSION Change PHP version for LOGIN @@ -752,6 +764,15 @@ arg_processing() { check-occurence) op_checkoccurencename "$@" ;; + list-user-itk) + op_listuseritk "$@" + ;; + enable-user-itk) + op_enableuseritk "$@" + ;; + disable-user-itk) + op_disableuseritk "$@" + ;; setphpversion) op_setphpversion "$@" ;; @@ -766,6 +787,7 @@ arg_processing() { } op_listvhost() { + # cas pour afficher usage à faire if [ $# -eq 1 ]; then configlist="$VHOST_PATH/${1}.conf"; else @@ -875,6 +897,39 @@ op_checkoccurencename() { fi } +op_listuseritk() { + if [ $# -eq 2 ]; then + domain=${1} + configfile="$VHOST_PATH"/"${2}".conf + + sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $2}' + else usage + fi +} + +op_enableuseritk() { + if [ $# -eq 2 ]; then + domain=${1} + configfile="$VHOST_PATH"/"${2}".conf + user=$(op_listuseritk "${1}" "${2}") + echo $user + + sed -i "/^ *AssignUserID ${user}/ s/${user}/www-${user}/" $VHOST_PATH/"${2}".conf --follow-symlinks + else usage + fi +} + +op_disableuseritk() { + if [ $# -eq 2 ]; then + domain=${1} + configfile="$VHOST_PATH"/"${2}".conf + user=$(op_listuseritk "${1}" "${2}") + echo $user + sed -i "/^ *AssignUserID ${user}/ s/${user}/${user:4}/" $VHOST_PATH/"${2}".conf --follow-symlinks + else usage + fi +} + op_add() { # diff --git a/tpl/webadmin-itk.tpl.php b/tpl/webadmin-itk.tpl.php new file mode 100644 index 0000000..70d54f8 --- /dev/null +++ b/tpl/webadmin-itk.tpl.php @@ -0,0 +1,61 @@ + + * @version 1.0 + */ + +?> + +

Sécurité ITK

+ + 0) { ?> + + + + + + + Action'; + } ?> + + + + '; + 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']; + } + + printf('', + $domain, $action[0], $data_list[$i]['servername']); + } + print ''; + } ?> + +
ServerNameUtilisateur
%s%s'.$action[1].'
+Aucun ServerName existant pour le domaine $domain !

"; + } + + +?> -- 2.39.2 From fc3fe6bd152d1dfc1df97feb3e3b955372f53fab Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Tue, 26 Mar 2019 10:41:17 +0100 Subject: [PATCH 21/29] cleaning code + add links to navigate to new pages --- inc/webadmin-itk.php | 1 - tpl/webadmin-itk.tpl.php | 2 +- tpl/webadmin.tpl.php | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/inc/webadmin-itk.php b/inc/webadmin-itk.php index 51ea1d0..680c653 100644 --- a/inc/webadmin-itk.php +++ b/inc/webadmin-itk.php @@ -18,7 +18,6 @@ require_once EVOADMIN_BASE . '../lib/domain.php'; global $conf; -var_dump($_SESSION); if (isset($_GET['enable']) ) { require_once EVOADMIN_BASE . '../evolibs/Form.php'; diff --git a/tpl/webadmin-itk.tpl.php b/tpl/webadmin-itk.tpl.php index 70d54f8..7d1f596 100644 --- a/tpl/webadmin-itk.tpl.php +++ b/tpl/webadmin-itk.tpl.php @@ -54,7 +54,7 @@ Aucun ServerName existant pour le domaine $domain !

"; + print "

La sécurité ITK ne semble pas en place pour le domaine $domain

"; } diff --git a/tpl/webadmin.tpl.php b/tpl/webadmin.tpl.php index 1fad772..6a7cbfb 100755 --- a/tpl/webadmin.tpl.php +++ b/tpl/webadmin.tpl.php @@ -39,7 +39,14 @@ } ?>  Actif ?  -  Action  + +  Alias '; + print ' ServerName '; + print ' Sécurité '; + } + ?> + Bdd @@ -95,7 +102,11 @@ } printf('%s', ($vhost_info['is_enabled'] ? 'Activé' : 'Désactivé' )); if (is_superadmin()) { - printf('Lister/Modifier les alias', + printf('Gérer', + $vhost_info['owner']); + printf('Modifier', + $vhost_info['owner']); + printf('Gérer', $vhost_info['owner']); } -- 2.39.2 From e15e03c36b7d3654b77c35dbe4454dac77428264 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Tue, 26 Mar 2019 12:06:07 +0100 Subject: [PATCH 22/29] enhance enable/disable for itk --- scripts/web-add.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index a40ed95..f842275 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -787,7 +787,6 @@ arg_processing() { } op_listvhost() { - # cas pour afficher usage à faire if [ $# -eq 1 ]; then configlist="$VHOST_PATH/${1}.conf"; else @@ -902,7 +901,7 @@ op_listuseritk() { domain=${1} configfile="$VHOST_PATH"/"${2}".conf - sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $2}' + sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $2}' | uniq else usage fi } @@ -912,9 +911,12 @@ op_enableuseritk() { domain=${1} configfile="$VHOST_PATH"/"${2}".conf user=$(op_listuseritk "${1}" "${2}") - echo $user - sed -i "/^ *AssignUserID ${user}/ s/${user}/www-${user}/" $VHOST_PATH/"${2}".conf --follow-symlinks + sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $user/ AssignUserID www-$user/" $configfile --follow-symlinks + + apache2ctl configtest 2>/dev/null + /etc/init.d/apache2 force-reload >/dev/null + else usage fi } @@ -924,8 +926,12 @@ op_disableuseritk() { domain=${1} configfile="$VHOST_PATH"/"${2}".conf user=$(op_listuseritk "${1}" "${2}") - echo $user - sed -i "/^ *AssignUserID ${user}/ s/${user}/${user:4}/" $VHOST_PATH/"${2}".conf --follow-symlinks + + sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $user/ AssignUserID ${user:4}/" $configfile --follow-symlinks + + apache2ctl configtest 2>/dev/null + /etc/init.d/apache2 force-reload >/dev/null + else usage fi } -- 2.39.2 From b3ec773c64fe3abc29445ca7093f819f1577ede0 Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Tue, 26 Mar 2019 16:37:26 +0100 Subject: [PATCH 23/29] Ensure that check_occurence_name say false if an empty string is given Also add some comments & fix code indent --- lib/domain.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/domain.php b/lib/domain.php index 0e33f93..1e6dea7 100644 --- a/lib/domain.php +++ b/lib/domain.php @@ -17,25 +17,37 @@ function domain_add($name, $IP, $with_mxs, $gmail=false) { $exec_cmd .= ' -m mail,10'; $exec_cmd .= ' -m backup.quai13.net.,20'; } -# mail('tech@evolix.fr', '[TAF] Ajouter '.$name.' sur quai13-backup', wordwrap('Ajouter le domaine '.$name.' à la directive relay_domains dans le fichier /etc/postfix/main.cf sur quai13-backup, pour mettre en place le MX secondaire du domaine.', 70)); } $exec_cmd .= " -a $IP $name"; - //echo $exec_cmd."\n"; sudoexec($exec_cmd, $exec_output, $exec_return); return array($exec_cmd, $exec_return, $exec_output); } +/** + * Ensure that the domain (or list of domains) do no exists in any other + * apache config file. Either as a ServerName or ServerAlias + * + * @param string $name Domain (or list of domains separated by commas) + * + * @return boolean True if one occurence is found. Else otherwise + */ function check_occurence_name($name) { - $exploded_names = explode(',', $name); + // If no domain are given, that should be okay + if(strlen($name) === 0){ + return false; + } - foreach ($exploded_names as $current_name) { - $check_occurence_cmd = 'web-add.sh check-occurence ' . $current_name; - sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); - if ($check_occurence_return == 0) return true; - } + $exploded_names = explode(',', $name); - return false; + foreach ($exploded_names as $current_name) { + $check_occurence_cmd = 'web-add.sh check-occurence ' . escapeshellarg($current_name); + + sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); + if ($check_occurence_return == 0) return true; + } + + return false; } -- 2.39.2 From 29b92647a72b1ee97a99de7e411f0e24865fd69c Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Tue, 26 Mar 2019 16:59:12 +0100 Subject: [PATCH 24/29] Refactor the domain and alias checks done at account creation --- inc/accounts.php | 17 +++++++++-------- tpl/accounts.tpl.php | 18 +++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/inc/accounts.php b/inc/accounts.php index a223167..0513670 100644 --- a/inc/accounts.php +++ b/inc/accounts.php @@ -388,20 +388,21 @@ if(!empty($_POST)) { /* Test de validation du formulaire */ if($form->verify(TRUE)) { - $is_domain_present = check_occurence_name($form->getField('domain')->getValue()); - $is_alias_present = check_occurence_name($form->getField('domain_alias')->getValue()); + $errors_check = array(); - if (!$is_domain_present && !$is_alias_present) { + if(check_occurence_name($form->getField('domain')->getValue())){ + array_push($errors_check, "Domaine déjà présent dans d'autres vhosts."); + } + if(check_occurence_name($form->getField('domain_alias')->getValue())){ + array_push($errors_check, "Alias déjà présent(s) dans d'autres vhosts."); + } + + if (count($errors_check) === 0) { if ($conf['cluster']) $exec_info = web_add_cluster($form, $conf['admin']['mail']); else $exec_info = web_add($form, $conf['admin']['mail']); } - else { - $errors_check = array(); - if ($is_domain_present) array_push($errors_check, "Domaine déjà présent dans d'autres vhosts."); - if ($is_alias_present) array_push($errors_check, "Alias déjà présent(s) dans d'autres vhosts."); - } } } diff --git a/tpl/accounts.tpl.php b/tpl/accounts.tpl.php index 859b442..89e4c84 100644 --- a/tpl/accounts.tpl.php +++ b/tpl/accounts.tpl.php @@ -13,9 +13,7 @@ * @version 1.0 */ -?> -'; if ($conf['debug'] == TRUE) @@ -23,7 +21,7 @@ if ($exec_info[1]) { print "La commande a échoué\n"; - print_r($exec_info); + print_r($exec_info); } else print "Le compte a été créé avec succès\n"; @@ -35,18 +33,20 @@ print ''; } else { + // If there is validation errors, display them if (isset($errors_check)) { - print '

Erreur(s) :
'; - foreach ($errors_check as $error) { - printf('%s
', $error); - } - print '

'; + print '

Erreur(s) :
'; + foreach ($errors_check as $error) { + printf('%s
', $error); + } + print '

'; } ?> +
Ajout d'un compte - +

-- 2.39.2 From d3e5cc7b4cf09c76aec2fa3bf02366c912a3762a Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Tue, 26 Mar 2019 17:46:31 +0100 Subject: [PATCH 25/29] fix case when using multiple time disable-user-itk and enable-user-itk --- scripts/web-add.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index f842275..5b243f5 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -910,9 +910,9 @@ op_enableuseritk() { if [ $# -eq 2 ]; then domain=${1} configfile="$VHOST_PATH"/"${2}".conf - user=$(op_listuseritk "${1}" "${2}") + group=$(sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $3}' | uniq) - sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $user/ AssignUserID www-$user/" $configfile --follow-symlinks + sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $group/ AssignUserID www-$group/" $configfile --follow-symlinks apache2ctl configtest 2>/dev/null /etc/init.d/apache2 force-reload >/dev/null @@ -925,9 +925,9 @@ op_disableuseritk() { if [ $# -eq 2 ]; then domain=${1} configfile="$VHOST_PATH"/"${2}".conf - user=$(op_listuseritk "${1}" "${2}") + group=$(sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $3}' | uniq) - sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $user/ AssignUserID ${user:4}/" $configfile --follow-symlinks + sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID www-$group/ AssignUserID ${group}/" $configfile --follow-symlinks apache2ctl configtest 2>/dev/null /etc/init.d/apache2 force-reload >/dev/null -- 2.39.2 From 369415b5f5d0bdb028070f178357059e4c7634c1 Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Wed, 27 Mar 2019 11:09:02 +0100 Subject: [PATCH 26/29] Ensure SelectFormField behave properly in some edge cases --- evolibs/Form.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evolibs/Form.php b/evolibs/Form.php index 97b6921..f1cdba9 100644 --- a/evolibs/Form.php +++ b/evolibs/Form.php @@ -879,7 +879,7 @@ class SelectFormField extends FormField { } public function verify($set_error) { - if($this->mandatory && empty($this->value)) { + if($this->mandatory && strlen($this->value) === 0) { if($set_error) $this->error = 'Champ obligatoire'; return FALSE; } @@ -894,7 +894,7 @@ class SelectFormField extends FormField { $input .= ' '."\n"; foreach ($this->list as $value => $label) { $input .= ' '."\n"; } $input .= "\n"; -- 2.39.2 From 256baadb853006a5a5a3287ac7e4231aa09d7113 Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Wed, 27 Mar 2019 14:07:47 +0100 Subject: [PATCH 27/29] Add PHP version update interface when running in multiphp mode --- htdocs/common.php | 10 +++++ htdocs/index.php | 9 ++-- inc/webadmin-php.php | 94 ++++++++++++++++++++++++++++++++++++++++ tpl/webadmin-php.tpl.php | 26 +++++++++++ tpl/webadmin.tpl.php | 24 +++++----- 5 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 inc/webadmin-php.php create mode 100644 tpl/webadmin-php.tpl.php diff --git a/htdocs/common.php b/htdocs/common.php index 1c4acba..1e2532f 100644 --- a/htdocs/common.php +++ b/htdocs/common.php @@ -87,6 +87,16 @@ function load_config_cluster($cluster) { $conf = array_merge($conf, $clusterconf); } +/** + * Return wether or not this evoadmin install is a multi PHP install + * + * @return boolean - True when it's a multi PHP system + */ +function is_multiphp() +{ + return array_key_exists('php_versions', $conf) && count($conf['php_versions']) > 1; +} + /** * Includes */ diff --git a/htdocs/index.php b/htdocs/index.php index 7e78c11..62d2a65 100755 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -4,7 +4,7 @@ * common DirectoryIndex page * * Copyright (c) 2009 Evolix - Tous droits reserves - * + * * vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2 * * @author Gregory Colpart @@ -24,7 +24,7 @@ define('EVOADMIN_BASE','./'); session_name('EVOADMINWEB_SESS'); session_start(); -error_reporting(E_ALL | E_NOTICE); +error_reporting(E_ALL); header('Content-Type: text/html; charset=utf-8'); /** @@ -56,6 +56,10 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) { include_once EVOADMIN_BASE . '../inc/webadmin-itk.php'; +} elseif (preg_match('#^/webadmin/php/(.*)/?$#', $uri, $params)) { + + include_once EVOADMIN_BASE . '../inc/webadmin-php.php'; + } elseif (preg_match('#^/webadmin/edit/(.*)/?$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; @@ -83,4 +87,3 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) { } else { die ("Cette page n'existe pas !!!"); } - diff --git a/inc/webadmin-php.php b/inc/webadmin-php.php new file mode 100644 index 0000000..6afba03 --- /dev/null +++ b/inc/webadmin-php.php @@ -0,0 +1,94 @@ + + * @author Thomas Martin + * @author Sebastien Palma + * @version 1.0 + */ + +require_once EVOADMIN_BASE . '../lib/bdd.php'; +require_once EVOADMIN_BASE . '../lib/domain.php'; +require_once EVOADMIN_BASE . '../evolibs/Form.php'; + +global $conf; + +$form = new FormPage("Modification de la version de PHP", FALSE); +$form->addField('php_version', new SelectFormField("Nouvelle version de PHP", True, $conf['php_versions'])); + +include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; +include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; + +$domain = $params[1]; + +// TODO: adapt for cluster mode +if ($conf['cluster']) { + print "
"; + printf ('

ERREUR

'); + printf ('

Cette action n\'est pas encore supportée en mode cluster

'); + printf ('

Retour à liste des comptes

'); + print "
"; +} +else { + $cmd = 'web-add.sh list-vhost ' . escapeshellarg($domain); + sudoexec($cmd, $data_output, $exec_return); + + $data_split = explode(':', $data_output[0]); + $current_PHP_version = $data_split[7]; + + if (!empty($_POST)) { + $form->isCurrentPage(TRUE); + $form->initFields(); + + if ($form->verify(TRUE)) { + if (isset($conf['php_versions'][$form->getField('php_version')->getValue()])) + { + $selected_php_version = $conf['php_versions'][$form->getField('php_version')->getValue()]; + $exec_cmd = 'web-add.sh setphpversion '.escapeshellarg($domain).' '.escapeshellarg($selected_php_version); + sudoexec($exec_cmd, $exec_output, $exec_return); + + if ($exec_return == 0) { + + print "
"; + printf ('

La version de PHP bien été modifié

'); + printf ('

Retour à liste des comptes

'); + print "
"; + + } + else { + print "
"; + printf ('

ERREUR

'); + printf ('

Une erreur innatendue s\'est produite

'); + + if ($conf['debug'] == TRUE) { + print '
';
+                            foreach($exec_output as $exec_line) {
+                                printf("%s\n", $exec_line);
+                            }
+                            print '
'; + } + + printf ('

Retour à liste des comptes

'); + print "
"; + } + } + else { + include_once EVOADMIN_BASE . '../tpl/webadmin-php.tpl.php'; + } + } + else { + include_once EVOADMIN_BASE . '../tpl/webadmin-php.tpl.php'; + } + } + else { + include_once EVOADMIN_BASE . '../tpl/webadmin-php.tpl.php'; + } + + include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; +} diff --git a/tpl/webadmin-php.tpl.php b/tpl/webadmin-php.tpl.php new file mode 100644 index 0000000..34f590b --- /dev/null +++ b/tpl/webadmin-php.tpl.php @@ -0,0 +1,26 @@ + + * @version 1.0 + */ + +?> + +

Version PHP

+ +

Version actuelle de PHP :

+ +
+
+ Changement de version de PHP + +

+
+
diff --git a/tpl/webadmin.tpl.php b/tpl/webadmin.tpl.php index 6a7cbfb..3ae37f0 100755 --- a/tpl/webadmin.tpl.php +++ b/tpl/webadmin.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 Gregory Colpart * @author Thomas Martin @@ -15,7 +15,7 @@ ?> -

Domaines

+

Liste des comptes web

0) { ?> @@ -41,9 +41,7 @@  Alias '; - print ''; - print ''; + print ''; } ?> @@ -65,7 +63,7 @@ } printf('', $vhost_info['server_name'], $vhost_info['server_name']); - + if ($conf['cluster']) { if (empty($vhost_info['bdd'])) printf('', preg_replace("/^(\d)(\d)$/", '\1.\2', $vhost_info['php_version'])); } printf('', ($vhost_info['is_enabled'] ? 'Activé' : 'Désactivé' )); + if (is_superadmin()) { - printf('', - $vhost_info['owner']); - printf('', - $vhost_info['owner']); - printf('', - $vhost_info['owner']); + printf(''); + } print ''; -- 2.39.2 From 128db077008c8b6ecf722fcf87127f3622b8403f Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Wed, 27 Mar 2019 14:58:56 +0100 Subject: [PATCH 28/29] The php version field should be mandatory --- inc/accounts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/accounts.php b/inc/accounts.php index 0513670..5c57119 100644 --- a/inc/accounts.php +++ b/inc/accounts.php @@ -348,7 +348,7 @@ if ($conf['bindadmin']) { } if (array_key_exists('php_versions', $conf) && count($conf['php_versions']) > 1) { - $form->addField('php_version', new SelectFormField("Version de PHP", FALSE, $conf['php_versions'])); + $form->addField('php_version', new SelectFormField("Version de PHP", TRUE, $conf['php_versions'])); } if ($conf['quota']) { -- 2.39.2 From 7faf647185529ccede2a641f7c7b5a06f7ed120d Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Wed, 27 Mar 2019 15:33:57 +0100 Subject: [PATCH 29/29] replace chained conditionals by regular if/else + configtest before reload --- scripts/web-add.sh | 156 +++++++++++++++++++++++++++++---------------- 1 file changed, 100 insertions(+), 56 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 5b243f5..df0306e 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -837,26 +837,45 @@ op_aliasdel() { if [ $# -eq 2 ]; then vhost="${1}.conf" alias=$2 + vhost_file="${VHOST_PATH}/${vhost}" - [ -f $VHOST_PATH/"$vhost" ] && sed -i -e "/ServerAlias $alias/d" $VHOST_PATH/"$vhost" --follow-symlinks + if [ -f "${vhost_file}" ]; then + sed -i -e "/ServerAlias $alias/d" "${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=$? - else usage + if [ "$configtest_rc" = "0" ]; then + /etc/init.d/apache2 force-reload >/dev/null + else + echo $configtest_out >&2 + fi + else + usage fi } op_listservername() { - if [ $# -eq 1 ]; then - configfile="$VHOST_PATH/${1}.conf"; + if [ $# -eq 1 ]; then + vhost_file="$VHOST_PATH/${1}.conf"; - for servername in $(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq); do - echo "$servername"; - done + if [ -f "${vhost_file}" ]; then + servernames=$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$vhost_file" | uniq) - else usage - fi + 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() { @@ -864,76 +883,101 @@ op_servernameupdate() { vhost="${1}.conf" servername=$2 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 - [ -f $VHOST_PATH/"$vhost" ] && sed -i "/^ *ServerName/ s/$old_servername/$servername/g" $VHOST_PATH/"$vhost" --follow-symlinks \ - && sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" $VHOST_PATH/"$vhost" --follow-symlinks + 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 + fi - apache2ctl configtest 2>/dev/null - /etc/init.d/apache2 force-reload >/dev/null + configtest_out=$(apache2ctl configtest) + configtest_rc=$? - else usage + if [ "$configtest_rc" = "0" ]; then + /etc/init.d/apache2 force-reload >/dev/null + else + echo $configtest_out >&2 + fi + else + usage fi } op_checkoccurencename() { - if [ $# -eq 1 ]; then - name=${1} - configlist="$VHOST_PATH/*"; - servernames='' - aliases='' + if [ $# -eq 1 ]; then + name=${1} + configlist="$VHOST_PATH/*"; + servernames='' + aliases='' - for configfile in $configlist; do - if [ -r "$configfile" ]; then - aliases="$aliases $(perl -ne 'print "$1 " if /^[[:space:]]*ServerAlias (.*)/' "$configfile" | head -n 1)" - servernames="$servernames $(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq)" - fi - done + for configfile in $configlist; do + 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 + done - echo "$servernames" "$aliases" | grep -w "$name" - - else usage - fi + echo "$servernames" "$aliases" | grep -w "$name" + else + usage + fi } 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 - fi + if [ $# -eq 2 ]; then + domain=${1} + configfile="$VHOST_PATH/${2}.conf" + + sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $2}' | 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 2 ]; then + domain=${1} + configfile="$VHOST_PATH/${2}.conf" + group=$(sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $3}' | uniq) - sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $group/ AssignUserID www-$group/" $configfile --follow-symlinks + sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $group/ AssignUserID www-$group/" "$configfile" --follow-symlinks - apache2ctl configtest 2>/dev/null - /etc/init.d/apache2 force-reload >/dev/null + configtest_out=$(apache2ctl configtest) + configtest_rc=$? - else usage - fi + if [ "$configtest_rc" = "0" ]; then + /etc/init.d/apache2 force-reload >/dev/null + else + echo $configtest_out >&2 + fi + else + usage + fi } 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 2 ]; then + domain=${1} + configfile="$VHOST_PATH"/"${2}".conf + group=$(sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $3}' | uniq) - sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID www-$group/ AssignUserID ${group}/" $configfile --follow-symlinks + sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID www-$group/ AssignUserID ${group}/" "$configfile" --follow-symlinks - apache2ctl configtest 2>/dev/null - /etc/init.d/apache2 force-reload >/dev/null + configtest_out=$(apache2ctl configtest) + configtest_rc=$? - else usage - fi + if [ "$configtest_rc" = "0" ]; then + /etc/init.d/apache2 force-reload >/dev/null + else + echo $configtest_out >&2 + fi + else + usage + fi } op_add() { -- 2.39.2
 Actif ?   ServerName  Sécurité Administrationhttp://%s'); @@ -101,13 +99,15 @@ printf('%s%sGérerModifierGérer'); + printf('Alias - ', $vhost_info['owner']); + printf('Servername - ', $vhost_info['owner']); + printf('ITK - ', $vhost_info['owner']); + printf('PHP', $vhost_info['owner']); + printf('