revert multiple virtualhosts mgmt for ITK

This commit is contained in:
Nicolas Roman 2019-05-16 11:55:52 +02:00
parent 1ee7221b19
commit 5a738c4e2e
3 changed files with 52 additions and 72 deletions

View file

@ -18,23 +18,39 @@ require_once EVOADMIN_BASE . '../lib/domain.php';
global $conf; global $conf;
if (isset($params[2]) && $params[2] != "") { if (isset($_GET['enable']) ) {
$redirect_url = "/webadmin/" . $params[1] . "/itk/"; 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 (isset($params[3]) && $params[3] == "") http_redirect($redirect_url);
if ($enable_cmd_return == 0) {
print 'Sécurité ITK activée.';
printf ('<p><a href="%s">Retour à la gestion ITK</a></p>', $_SERVER['REDIRECT_URL']);
}
include_once EVOADMIN_BASE . '../tpl/footer.tpl.php';
} elseif (isset($_GET['disable']) ) {
require_once EVOADMIN_BASE . '../evolibs/Form.php'; require_once EVOADMIN_BASE . '../evolibs/Form.php';
include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/header.tpl.php';
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';
$servername = array ( $servername = array (
'domain' => $params[1], 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])),
'servername' => $params[3]
); );
if ($params[2] == "enable") { $disable_cmd = 'web-add.sh disable-user-itk ' . $servername['domain'];
$enable_cmd = 'web-add.sh enable-user-itk ' . $servername['servername'] . ' ' . $servername['domain'];
sudoexec($enable_cmd, $enable_cmd_output, $enable_cmd_return); sudoexec($enable_cmd, $enable_cmd_output, $enable_cmd_return);
@ -46,20 +62,10 @@ if (isset($params[2]) && $params[2] != "") {
elseif ($params[2] == "disable") { 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['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 ('<p><a href="%s">Retour à la gestion ITK</a></p>', $redirect_url);
}
}
include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; include_once EVOADMIN_BASE . '../tpl/footer.tpl.php';
}
else {
} else {
$domain = $params[1]; $domain = $params[1];
$data_list = array();
// TODO: adapt for cluster mode // TODO: adapt for cluster mode
if ($conf['cluster']) { if ($conf['cluster']) {
@ -83,33 +89,17 @@ else {
$alias_list = $bdd->list_serveralias($domain); $alias_list = $bdd->list_serveralias($domain);
} }
else { else {
$cmd_itk = 'web-add.sh list-user-itk ' . $domain;
$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); 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. $user_itk = $data_output_itk[0];
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/header.tpl.php';
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php'; include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';
include_once EVOADMIN_BASE . '../tpl/webadmin-itk.tpl.php'; include_once EVOADMIN_BASE . '../tpl/webadmin-itk.tpl.php';
include_once EVOADMIN_BASE . '../tpl/footer.tpl.php'; include_once EVOADMIN_BASE . '../tpl/footer.tpl.php';
} }
?> ?>

View file

@ -1001,23 +1001,21 @@ op_checkoccurencename() {
} }
op_listuseritk() { op_listuseritk() {
if [ $# -eq 2 ]; then if [ $# -eq 1 ]; then
domain=${1} configfile="$VHOST_PATH/${1}.conf"
configfile="$VHOST_PATH/${2}.conf"
sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $2}' | uniq awk '/AssignUserID/ {print $2}' "$configfile" | uniq
else else
usage usage
fi fi
} }
op_enableuseritk() { op_enableuseritk() {
if [ $# -eq 2 ]; then if [ $# -eq 1 ]; then
domain=${1} configfile="$VHOST_PATH/${1}.conf"
configfile="$VHOST_PATH/${2}.conf" group=$(awk '/AssignUserID/ {print $3}' "$configfile" | uniq)
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 "s/^ *AssignUserID $group/ AssignUserID www-$group/" "$configfile" --follow-symlinks
configtest_out=$(apache2ctl configtest) configtest_out=$(apache2ctl configtest)
configtest_rc=$? configtest_rc=$?
@ -1033,12 +1031,11 @@ op_enableuseritk() {
} }
op_disableuseritk() { op_disableuseritk() {
if [ $# -eq 2 ]; then if [ $# -eq 1 ]; then
domain=${1} configfile="$VHOST_PATH"/"${1}".conf
configfile="$VHOST_PATH"/"${2}".conf group=$(awk '/AssignUserID/ {print $3}' "$configfile" | uniq)
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 "s/^ *AssignUserID www-$group/ AssignUserID ${group}/" "$configfile" --follow-symlinks
configtest_out=$(apache2ctl configtest) configtest_out=$(apache2ctl configtest)
configtest_rc=$? configtest_rc=$?

View file

@ -17,12 +17,11 @@
<?php <?php
if(count($data_list) > 0) { ?> if(!empty($user_itk)) { ?>
<table id="tab-list"> <table id="tab-list">
<thead> <thead>
<tr> <tr>
<th>Servername</th>
<th>Utilisateur</th> <th>Utilisateur</th>
<?php if (is_superadmin()) { <?php if (is_superadmin()) {
print '<th>Action</th>'; print '<th>Action</th>';
@ -31,29 +30,23 @@
</thead> </thead>
<tbody> <tbody>
<?php <?php
for ( $i=0; $i < count($data_list); ++$i ) {
print '<tr>';
printf('<td>%s</td>',
$data_list[$i]['servername']);
printf('<td>%s</td>',
$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 print '<tr>';
if (empty($data_list[$i]['user'])) { printf('<td>%s</td>',
$action = ["", ""]; $user_itk);
} if (is_superadmin()) {
printf('<td><a href="/webadmin/%s/itk/%s/%s/">'.$action[1].'</a></td>', if (strpos($user_itk, 'www') !== false) {
$domain, $action[0], $data_list[$i]['servername']); $action = ['disable', 'Désactiver'];
} } else {
print '</tr>'; $action = ['enable', 'Activer'];
} ?> }
printf('<td><a href="/webadmin/itk/%s?%s">'.$action[1].'</a></td>',
$domain, $action[0]);
}
print '</tr>';
?>
</tbody> </tbody>
</table> </table>
<?php <?php