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;
if (isset($params[2]) && $params[2] != "") {
$redirect_url = "/webadmin/" . $params[1] . "/itk/";
if (isset($_GET['enable']) ) {
require_once EVOADMIN_BASE . '../evolibs/Form.php';
include_once EVOADMIN_BASE . '../tpl/header.tpl.php';
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';
$servername = array (
'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])),
);
$enable_cmd = 'web-add.sh enable-user-itk ' . $servername['domain'];
if (isset($params[3]) && $params[3] == "") http_redirect($redirect_url);
if ($enable_cmd_return == 0) {
print 'Sécurité ITK activée.';
printf ('<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';
include_once EVOADMIN_BASE . '../tpl/header.tpl.php';
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';
$servername = array (
'domain' => $params[1],
'servername' => $params[3]
'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])),
);
if ($params[2] == "enable") {
$enable_cmd = 'web-add.sh enable-user-itk ' . $servername['servername'] . ' ' . $servername['domain'];
$disable_cmd = 'web-add.sh disable-user-itk ' . $servername['domain'];
sudoexec($enable_cmd, $enable_cmd_output, $enable_cmd_return);
@ -46,20 +62,10 @@ if (isset($params[2]) && $params[2] != "") {
elseif ($params[2] == "disable") {
$disable_cmd = 'web-add.sh disable-user-itk ' . $servername['servername'] . ' ' . $servername['domain'];
sudoexec($disable_cmd, $disable_cmd_output, $disable_cmd_return);
if ($disable_cmd_return == 0) {
print 'Sécurité ITK désactivée';
printf ('<p><a href="%s">Retour à la gestion ITK</a></p>', $redirect_url);
}
}
include_once EVOADMIN_BASE . '../tpl/footer.tpl.php';
}
else {
} else {
$domain = $params[1];
$data_list = array();
// TODO: adapt for cluster mode
if ($conf['cluster']) {
@ -83,33 +89,17 @@ else {
$alias_list = $bdd->list_serveralias($domain);
}
else {
$cmd = 'web-add.sh list-servername ' . $domain;
if(!is_superadmin()) {
$cmd = sprintf('%s %s', $cmd, $_SESSION['user']);
}
sudoexec($cmd, $data_output, $exec_return);
# à revérifier (notamment gestion erreurs)
if ($exec_return == 0) {
foreach($data_output as $data_line) {
$cmd_itk = 'web-add.sh list-user-itk ' . $data_line . ' ' . $domain;
$cmd_itk = 'web-add.sh list-user-itk ' . $domain;
sudoexec($cmd_itk, $data_output_itk, $exec_return_itk);
# on prend le premier résultat du tableau, ne fonctionne pas s'il y a plusieurs la même ligne ou des commentaires etc.
array_push($data_list, ['servername' => $data_line, 'user' => $data_output_itk[0]]);
unset($data_output_itk); # reset variable pour éviter conflits
}
}
$user_itk = $data_output_itk[0];
}
include_once EVOADMIN_BASE . '../tpl/header.tpl.php';
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';
include_once EVOADMIN_BASE . '../tpl/webadmin-itk.tpl.php';
include_once EVOADMIN_BASE . '../tpl/footer.tpl.php';
}
?>

View file

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

View file

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