From 8c4447864312626c848e13be5d088f85cb36e857 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Wed, 17 Apr 2019 18:11:33 +0200 Subject: [PATCH] first draft to get aliases linked to the servername --- inc/webadmin-edit.php | 26 ++++++++++++++++++++++++++ scripts/web-add.sh | 24 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/inc/webadmin-edit.php b/inc/webadmin-edit.php index f0f1ba6..4e2a3c4 100644 --- a/inc/webadmin-edit.php +++ b/inc/webadmin-edit.php @@ -257,6 +257,7 @@ else { $domain = $params[1]; $alias_list = array(); + $alias_list2 = array(); if ($conf['cluster']) { if (is_mcluster_mode()) { @@ -285,6 +286,31 @@ else { } sudoexec($cmd, $data_output, $exec_return); + $cmd2 = 'web-add.sh list-alias ' . $domain; + sudoexec($cmd2, $data_output2, $exec_return2); + + $vhost_detail = array(); + foreach($data_output2 as $data_line2) { + $data_split2 = explode(' ', $data_line2); + // var_dump($data_split2); + $vhost_detail['servername'] = $data_split2[0]; + unset($data_split2[0]); + + # si des aliases sont présents + if (count($data_split2) > 0) { + $vhost_detail['aliases'] = array(); + foreach($data_split2 as $alias_split2) { + array_push($vhost_detail['aliases'], $alias_split2); + } + } + array_push($alias_list2, $vhost_detail); + } + + echo '
';
+        var_dump($alias_list2);
+        echo '
'; + // var_dump($vhost_detail); + /* Récupération de cette liste dans le tableau $vhost_list */ $vhost_list = array(); foreach($data_output as $data_line) { diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 8cdffbe..f6b2cd7 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -756,6 +756,9 @@ arg_processing() { del-alias) op_aliasdel "$@" ;; + list-alias) + op_listalias "$@" + ;; list-servername) op_listservername "$@" ;; @@ -861,6 +864,27 @@ op_aliasdel() { fi } +# The Holy Grail, do not touch, even if you're Indiana Jones +# TODO: ne pas prendre en compte les lignes commentées +# ajouter la fonction dans le usage +# awk '/^/{if(/^<\/VirtualHost>/)p=1;if(/ServerName|ServerAlias/)out = out (out?OFS:"") ($2)}p{print out;p=0;out=""}' /etc/apache2/sites-enabled/test.conf +op_listalias() { + if [ $# -eq 1 ]; then + vhost_file="$VHOST_PATH/${1}.conf"; + + if [ -f "${vhost_file}" ]; then + + aliases=$(awk '/^/{if(/^<\/VirtualHost>/)p=1;if(/ServerName|ServerAlias/)out = out (out?OFS:"") ($2)}p{print out;p=0;out=""}' "$vhost_file") + echo "$aliases"; + else + echo "VHost file \`${vhost_file}' not found'" >&2 + return 1 + fi + else + usage + fi +} + op_listservername() { if [ $# -eq 1 ]; then vhost_file="$VHOST_PATH/${1}.conf";