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 "";
+
+ }
+
+ 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) { ?>
+
+
+
+
+ Server Name |
+ Action';
+ } ?>
+
+
+
+ ';
+ printf('%s | ',
+ $servername_list[$i]);
+ if (is_superadmin())
+ printf('Modifier | ',
+ $domain, $servername_list[$i]);
+ print '';
+ } ?>
+
+
+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 "