Merge branch 'vhost-delete' of evolix/evoadmin-web into master

This commit is contained in:
Nicolas Roman 2019-06-05 17:24:28 +02:00 committed by Gitea
commit 84a821d58c
14 changed files with 365 additions and 189 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
conf/config.local.php conf/config.local.php
.vagrant .vagrant
.idea

View File

@ -21,6 +21,12 @@ function switch_disabled(name) {
} }
document.observe("dom:loaded", function() { document.observe("dom:loaded", function() {
if (document.getElementById('vhost-delete-db') != null) {
document.getElementById('vhost-delete-db').onclick = function() {
console.log("clicked box");
switch_disabled('vhost-dbname');
}
}
document.getElementById('password_random').onclick = function() { document.getElementById('password_random').onclick = function() {
switch_disabled('password'); switch_disabled('password');
} }

View File

@ -48,26 +48,41 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) {
include_once EVOADMIN_BASE . '../inc/webadmin.php'; include_once EVOADMIN_BASE . '../inc/webadmin.php';
} elseif (preg_match('#^/webadmin/(.*)/domain/?(edit)?/?(.*)?/$#', $uri, $params)) { } elseif (preg_match('#^/webadmin?#', $uri)) {
include_once EVOADMIN_BASE . '../inc/webadmin-servername.php'; // Redirect to /webadmin in order to set $_SESSION['non_stanard']
if (!isset($_SESSION['non_standard']))
http_redirect('/webadmin');
} elseif (preg_match('#^/webadmin/(.*)/itk/?(enable|disable)?/?(.*)?/$#', $uri, $params)) { // block the non-standard vhost modification
if (in_array(htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), $_SESSION['non_standard']))
http_redirect('/webadmin');
include_once EVOADMIN_BASE . '../inc/webadmin-itk.php'; if (preg_match('#^/webadmin/(.*)/domain/?(edit)?/?(.*)?/$#', $uri, $params)) {
} elseif (preg_match('#^/webadmin/(.*)/php/$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-servername.php';
include_once EVOADMIN_BASE . '../inc/webadmin-php.php'; } elseif (preg_match('#^/webadmin/(.*)/itk/?(enable|disable)?/?(.*)?/$#', $uri, $params)) {
} elseif (preg_match('#^/webadmin/(.*)/alias/?(add|delete)?/?(.*)?/$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-itk.php';
include_once EVOADMIN_BASE . '../inc/webadmin-edit.php'; } elseif (preg_match('#^/webadmin/(.*)/php/$#', $uri, $params)) {
} elseif (preg_match('#^/webadmin/suppr/(.*)/?$#', $uri, $params)) { include_once EVOADMIN_BASE . '../inc/webadmin-php.php';
include_once EVOADMIN_BASE . '../inc/webadmin-suppr.php'; } elseif (preg_match('#^/webadmin/(.*)/alias/?(add|delete)?/?(.*)?/$#', $uri, $params)) {
include_once EVOADMIN_BASE . '../inc/webadmin-edit.php';
} elseif (preg_match('#^/webadmin/delete/(.*)/?$#', $uri, $params)) {
include_once EVOADMIN_BASE . '../inc/webadmin-delete.php';
} elseif (preg_match('#^/webadmin/suppr/(.*)/?$#', $uri, $params)) {
include_once EVOADMIN_BASE . '../inc/webadmin-suppr.php';
}
} elseif (is_superadmin() && preg_match('#^/accounts/?#', $uri, $params)) { } elseif (is_superadmin() && preg_match('#^/accounts/?#', $uri, $params)) {
include_once EVOADMIN_BASE . '../inc/accounts.php'; include_once EVOADMIN_BASE . '../inc/accounts.php';

72
inc/webadmin-delete.php Normal file
View File

@ -0,0 +1,72 @@
<?php
/**
* Apache VirtualHost Management Page
*
* Copyright (c) 2009 Evolix - Tous droits reserves
*
* vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
*
* @author Gregory Colpart <reg@evolix.fr>
* @author Thomas Martin <tmartin@evolix.fr>
* @author Sebastien Palma <spalma@evolix.fr>
* @version 1.0
*/
require_once EVOADMIN_BASE . '../lib/bdd.php';
require_once EVOADMIN_BASE . '../lib/domain.php';
global $conf;
include_once EVOADMIN_BASE . '../tpl/header.tpl.php';
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';
if (isset($_POST['delete-vhost'])) {
$domain = $params[1];
while(true) {
// Errors handling
if (empty($_POST['vhost-name'])) {
print "<p>Veuillez entrer le nom du compte web à supprimer.</p>";
printf ('<p><a href="%s">Retour</a></p>', $_SERVER['REDIRECT_URL']);
break;
}
if ($_POST['vhost-name'] !== $domain) {
print "Le nom de compte ne correspond pas.";
printf ('<p><a href="%s">Retour</a></p>', $_SERVER['REDIRECT_URL']);
break;
}
if (isset($_POST['vhost-delete-db']) && empty($_POST['vhost-dbname'])) {
print "Veuillez spécifier un nom de base de données.";
printf ('<p><a href="%s">Retour</a></p>', $_SERVER['REDIRECT_URL']);
break;
}
// Shell arguments
if (!empty($_POST['vhost-dbname']))
$exec_cmd = "web-add.sh del -y " . $domain . " " . $_POST['vhost-dbname'];
else
$exec_cmd = "web-add.sh del -y " . $domain;
// Execute script
sudoexec($exec_cmd, $exec_output, $exec_return);
// Deal with response code
if ($exec_return == 0)
print "<p>Compte supprimé.</p>";
else
print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
break;
}
include_once EVOADMIN_BASE . '../tpl/footer.tpl.php';
} else {
include_once EVOADMIN_BASE . '../tpl/webadmin-delete.tpl.php';
include_once EVOADMIN_BASE . '../tpl/footer.tpl.php';
}
?>

View File

@ -1,11 +1,11 @@
<?php <?php
/** /**
* Apache VirtualHost Management Page * Apache VirtualHost Management Page
* *
* Copyright (c) 2009 Evolix - Tous droits reserves * 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 <reg@evolix.fr> * @author Gregory Colpart <reg@evolix.fr>
* @author Thomas Martin <tmartin@evolix.fr> * @author Thomas Martin <tmartin@evolix.fr>
@ -68,10 +68,10 @@ if (isset($params[2]) && $params[2] == "delete") {
sudoexec($exec_cmd, $exec_output, $exec_return); sudoexec($exec_cmd, $exec_output, $exec_return);
if ($exec_return == 0) { if ($exec_return == 0) {
if (! $bdd->del_serveralias($serveralias)) if (! $bdd->del_serveralias($serveralias))
print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>"; print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
printf ('<p>Alias %s est supprimé.</p>', $serveralias['alias']); printf ('<p>Alias %s est supprimé.</p>', $serveralias['alias']);
} else } else
print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>"; print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
} }
@ -134,7 +134,7 @@ elseif (isset($params[2]) && $params[2] == "add") {
'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])), 'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])),
'alias' => $form->getField('domain_alias')->getValue(), 'alias' => $form->getField('domain_alias')->getValue(),
); );
$account_name=$serveralias['domain']; $account_name=$serveralias['domain'];
$account = $bdd->get_account($account_name); $account = $bdd->get_account($account_name);
@ -214,7 +214,7 @@ elseif (isset($params[2]) && $params[2] == "add") {
} }
else { else {
print "<center>"; print "<center>";
printf ('<p>Echec dans la creation de l\'alias %s du domaine %s</p>', $serveralias['alias'], $serveralias['domain']); printf ('<p>Echec dans la creation de l\'alias %s</p>', $serveralias['alias']);
print ('<p>L\'alias existe dans d\'autres vhosts.'); print ('<p>L\'alias existe dans d\'autres vhosts.');
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $redirect_url); printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $redirect_url);
print "</center>"; print "</center>";
@ -222,10 +222,10 @@ elseif (isset($params[2]) && $params[2] == "add") {
} }
} }
else { else {
print "<h2>Ajout d'un serveralias</h2><hr>"; print "<h2>Ajout d'un alias</h2><hr>";
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">"; print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
print " <fieldset>"; print " <fieldset>";
print " <legend>Ajout d'un serveralias</legend>"; print " <legend>Ajout d'un alias</legend>";
print $form; print $form;
print " <p><input type=\"submit\" value=\"Créer\"/></p>"; print " <p><input type=\"submit\" value=\"Créer\"/></p>";
print " </fieldset>"; print " </fieldset>";
@ -233,10 +233,10 @@ elseif (isset($params[2]) && $params[2] == "add") {
} }
} else { } else {
print "<h2>Ajout d'un serveralias</h2><hr>"; print "<h2>Ajout d'un alias</h2><hr>";
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">"; print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
print " <fieldset>"; print " <fieldset>";
print " <legend>Ajout d'un serveralias</legend>"; print " <legend>Ajout d'un alias</legend>";
print $form; print $form;
print " <p><input type=\"submit\" value=\"Créer\"/></p>"; print " <p><input type=\"submit\" value=\"Créer\"/></p>";
print " </fieldset>"; print " </fieldset>";

View File

@ -19,9 +19,8 @@ require_once EVOADMIN_BASE . '../lib/domain.php';
global $conf; global $conf;
if (isset($params[2]) && $params[2] != "") { if (isset($params[2]) && $params[2] != "") {
$redirect_url = "/webadmin/" . $params[1] . "/itk/";
if (isset($params[3]) && $params[3] == "") http_redirect($redirect_url); $redirect_url = "/webadmin/" . $params[1] . "/itk/";
require_once EVOADMIN_BASE . '../evolibs/Form.php'; require_once EVOADMIN_BASE . '../evolibs/Form.php';
@ -30,36 +29,32 @@ if (isset($params[2]) && $params[2] != "") {
$servername = array ( $servername = array (
'domain' => $params[1], 'domain' => $params[1],
'servername' => $params[3]
); );
if ($params[2] == "enable") { if ($params[2] == "enable") {
$enable_cmd = 'web-add.sh enable-user-itk ' . $servername['servername'] . ' ' . $servername['domain']; $enable_cmd = 'web-add.sh enable-user-itk ' . $servername['domain'];
sudoexec($enable_cmd, $enable_cmd_output, $enable_cmd_return); sudoexec($enable_cmd, $enable_cmd_output, $enable_cmd_return);
if ($enable_cmd_return == 0) { if ($enable_cmd_return == 0) {
print 'Sécurité ITK activée.'; print 'Sécurité ITK activée.';
printf ('<p><a href="%s">Retour à la gestion ITK</a></p>', $redirect_url); printf ('<p><a href="%s">Retour à la gestion ITK</a></p>', $redirect_url);
} }
} }
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['domain'];
sudoexec($disable_cmd, $disable_cmd_output, $disable_cmd_return); sudoexec($disable_cmd, $disable_cmd_output, $disable_cmd_return);
if ($disable_cmd_return == 0) { if ($disable_cmd_return == 0) {
print 'Sécurité ITK désactivée'; print 'Sécurité ITK désactivée';
printf ('<p><a href="%s">Retour à la gestion ITK</a></p>', $redirect_url); 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 +78,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

@ -28,8 +28,8 @@ if (isset($params[2]) && $params[2] == "edit") {
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';
$form = new FormPage("Modification du ServerName", FALSE); $form = new FormPage("Modification du Servername", FALSE);
$form->addField('domain_servername', new DomainInputFormField("ServerName", TRUE), $params[3]); $form->addField('domain_servername', new DomainInputFormField("Servername", TRUE), $params[3]);
$form->addField('previous_servername', new DomainInputFormField("", TRUE, TRUE), $params[3]); $form->addField('previous_servername', new DomainInputFormField("", TRUE, TRUE), $params[3]);
if (!empty($_POST)) { if (!empty($_POST)) {
@ -126,40 +126,40 @@ if (isset($params[2]) && $params[2] == "edit") {
if ($exec_return == 0) { if ($exec_return == 0) {
//domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer //domain_add($serveralias['alias'], gethostbyname($master) , false); TODO avec l'IP du load balancer
print "<center>"; print "<center>";
printf ('<p>Le ServerName %s a bien été modifié</p>', $servername['servername']); printf ('<p>Le Servername %s a bien été modifié</p>', $servername['servername']);
printf ('<p><a href="%s">Retour à la liste des ServerNames</a></p>', $redirect_url); printf ('<p><a href="%s">Retour à la liste des Servernames</a></p>', $redirect_url);
print "</center>"; print "</center>";
} }
else { else {
print "<center>"; print "<center>";
printf ('<p>Echec dans la modification du ServerName %s</p>', $servername['servername']); printf ('<p>Echec dans la modification du Servername %s</p>', $servername['servername']);
printf ('<p><a href="%s">Retour à la liste des ServerNames</a></p>', $redirect_url); printf ('<p><a href="%s">Retour à la liste des Servernames</a></p>', $redirect_url);
print "</center>"; print "</center>";
} }
} }
else { else {
print "<center>"; print "<center>";
printf ('<p>Echec dans la modification du ServerName %s</p>', $servername['servername']); printf ('<p>Echec dans la modification du Servername %s</p>', $servername['servername']);
print ('<p>Le domaine existe déjà dans d\'autres vhosts.'); print ('<p>Le domaine existe déjà dans d\'autres vhosts.');
printf ('<p><a href="%s">Retour à la liste des ServerNames</a></p>', $redirect_url); printf ('<p><a href="%s">Retour à la liste des Servernames</a></p>', $redirect_url);
print "</center>"; print "</center>";
} }
} }
} else { } else {
print "<h2>Modification du ServerName</h2><hr>"; print "<h2>Modification du Servername</h2><hr>";
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">"; print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
print " <fieldset>"; print " <fieldset>";
print " <legend>Modification du ServerName</legend>"; print " <legend>Modification du Servername</legend>";
print $form; print $form;
print " <p><input type=\"submit\" value=\"Modifier\"/></p>"; print " <p><input type=\"submit\" value=\"Modifier\"/></p>";
print " </fieldset>"; print " </fieldset>";
print "</form>"; print "</form>";
} }
} else { } else {
print "<h2>Modification du ServerName</h2><hr>"; print "<h2>Modification du Servername</h2><hr>";
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">"; print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
print " <fieldset>"; print " <fieldset>";
print " <legend>Modification du ServerName</legend>"; print " <legend>Modification du Servername</legend>";
print $form; print $form;
print " <p><input type=\"submit\" value=\"Modifier\"/></p>"; print " <p><input type=\"submit\" value=\"Modifier\"/></p>";
print " </fieldset>"; print " </fieldset>";
@ -197,17 +197,15 @@ if (isset($params[2]) && $params[2] == "edit") {
$alias_list = $bdd->list_serveralias($domain); $alias_list = $bdd->list_serveralias($domain);
} }
else { else {
$cmd = 'web-add.sh list-vhost ' . $domain;
$cmd = 'web-add.sh list-servername ' . $domain;
if(!is_superadmin()) { if(!is_superadmin()) {
$cmd = sprintf('%s %s', $cmd, $_SESSION['user']); $cmd = sprintf('%s %s', $cmd, $_SESSION['user']);
} }
sudoexec($cmd, $data_output, $exec_return); sudoexec($cmd, $data_output, $exec_return);
foreach($data_output as $data_line) { $data_vhost = explode(':', $data_output[0]);
array_push($servername_list, $data_line); $servername = $data_vhost[2];
}
} }
include_once EVOADMIN_BASE . '../tpl/header.tpl.php'; include_once EVOADMIN_BASE . '../tpl/header.tpl.php';

View File

@ -30,6 +30,12 @@ if (!$conf['cluster']) {
/* Récupération de cette liste dans le tableau $vhost_list */ /* Récupération de cette liste dans le tableau $vhost_list */
$vhost_list = array(); $vhost_list = array();
if (!isset($_SESSION['non_standard'])) {
$_SESSION['non_standard'] = array();
}
foreach($data_output as $data_line) { foreach($data_output as $data_line) {
$data_split = explode(':', $data_line); $data_split = explode(':', $data_line);
@ -72,6 +78,11 @@ if (!$conf['cluster']) {
$occupation = ""; $occupation = "";
} }
// current vhost isn't standard and thus not manageable by evoadmin-web
if (!$data_split[9]) {
array_push($_SESSION['non_standard'], $data_split[0]);
}
array_push($vhost_list, array( array_push($vhost_list, array(
'owner' => $data_split[0], 'owner' => $data_split[0],
'configid' => $data_split[1], 'configid' => $data_split[1],

View File

@ -100,12 +100,18 @@ add [ [OPTIONS] LOGIN WWWDOMAIN ]
Example : web-add.sh add -m testdb -r 56 testlogin testdomain.com Example : web-add.sh add -m testdb -r 56 testlogin testdomain.com
del LOGIN [DBNAME] del [ [OPTIONS] LOGIN [DBNAME] ]
Delete account and all files related (Apache, Awstats, etc) Delete account and all files related (Apache, Awstats, etc)
Archive home directory. Archive home directory.
Remove MySQL database only if DBNAME is specified. Remove MySQL database only if DBNAME is specified.
-y
Don't ask for confirmation
Example : web-add.sh del -y testlogin testdatabase
list-vhost LOGIN list-vhost LOGIN
List Apache vhost for user LOGIN List Apache vhost for user LOGIN
@ -122,30 +128,26 @@ del-alias VHOST ALIAS
Del a ServerAlias from an Apache vhost Del a ServerAlias from an Apache vhost
list-servername LOGIN
List ServerName(s) for user LOGIN
update-servername VHOST SERVERNAME OLD_SERVERNAME update-servername VHOST SERVERNAME OLD_SERVERNAME
Replace the OLD_SERVERNAME with the SERVERNAME for an Apache vhost Replace the OLD_SERVERNAME with the SERVERNAME for an Apache vhost
Also apply to rules Also apply to rewrite rules
check-occurence NAME check-occurence NAME
List all occurences of NAME in vhosts List all occurences of NAME in vhosts
list-user-itk DOMAIN LOGIN list-user-itk LOGIN
List the assigned ITK user for the DOMAIN specified List the assigned ITK user for the LOGIN specified
enable-user-itk DOMAIN LOGIN enable-user-itk LOGIN
Enable the assigned ITK user for the DOMAIN specified Enable the assigned ITK user for the LOGIN specified
disable-user-itk DOMAIN LOGIN disable-user-itk LOGIN
Disable the assigned ITK user for the DOMAIN specified Disable the assigned ITK user for the LOGIN specified
setphpversion LOGIN VERSION setphpversion LOGIN VERSION
@ -612,18 +614,88 @@ EOT
} }
op_del() { op_del() {
if [ $# -lt 1 ]; then
usage #
exit 1 # Mode interactif
#
if [ $# -eq 0 ]; then
echo
echo "Suppression d'un compte WEB"
echo
until [ "$login" ]; do
echo -n "Entrez le login du compte à supprimer : "
read -r tmp
login="$tmp"
done
echo -n "Voulez-vous aussi supprimer un compte/base MySQL ? [y|N]"
read -r confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
echo -n "Entrez le nom de la base de donnees ($login par defaut) : "
read -r tmp
if [ -z "$tmp" ]; then
dbname=$login
else
dbname="$tmp"
fi
fi
#
# Mode non interactif
#
else else
login=$1 while getopts hy opt; do
if [ $# -eq 2 ]; then case "$opt" in
dbname=$2 y)
force_confirm=1
;;
h)
usage
exit 1
;;
?)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [ $# -gt 0 ] && [ $# -le 2 ]; then
login=$1
if [ $# -eq 2 ]; then
dbname=$2
fi
else
usage
exit 1
fi fi
fi fi
echo "Deleting account $login. Continue ?" echo
read -r echo "----------------------------------------------"
echo "Nom du compte : $login"
if [ "$dbname" ]; then
echo "Base de données MySQL : $dbname"
fi
echo "----------------------------------------------"
echo
if [ -z "$force_confirm" ]; then
echo -n "Confirmer la suppression ? [y/N] : "
read -r tmp
echo
if [ "$tmp" != "y" ] && [ "$tmp" != "Y" ]; then
echo "Annulation..."
echo
exit 1
fi
fi
set -x set -x
if [ "$WEB_SERVER" == "apache" ]; then if [ "$WEB_SERVER" == "apache" ]; then
@ -681,9 +753,6 @@ op_del() {
set +x set +x
if [ -n "$dbname" ]; then if [ -n "$dbname" ]; then
echo "Deleting mysql DATABASE $dbname and mysql user $login. Continue ?"
read -r
set -x set -x
echo "DROP DATABASE $dbname; delete from mysql.user where user='$login' ; FLUSH PRIVILEGES;" | mysql $MYSQL_OPTS echo "DROP DATABASE $dbname; delete from mysql.user where user='$login' ; FLUSH PRIVILEGES;" | mysql $MYSQL_OPTS
set +x set +x
@ -755,9 +824,6 @@ arg_processing() {
del-alias) del-alias)
op_aliasdel "$@" op_aliasdel "$@"
;; ;;
list-servername)
op_listservername "$@"
;;
update-servername) update-servername)
op_servernameupdate "$@" op_servernameupdate "$@"
;; ;;
@ -793,7 +859,6 @@ op_listvhost() {
configlist="$VHOST_PATH/*"; configlist="$VHOST_PATH/*";
fi fi
for configfile in $configlist; do for configfile in $configlist; do
if [ -r "$configfile" ] && echo "$configfile" |grep -qvE "/(000-default|default-ssl|evoadmin)\\.conf$"; then if [ -r "$configfile" ] && echo "$configfile" |grep -qvE "/(000-default|default-ssl|evoadmin)\\.conf$"; then
servername="$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | head -n 1)" servername="$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | head -n 1)"
@ -811,9 +876,17 @@ op_listvhost() {
else else
is_enabled=0 is_enabled=0
fi fi
count_virtualhosts="$(grep "<VirtualHost" "$configfile" | wc -l)"
if [ "$count_virtualhosts" -eq 1 ]; then
is_standard=1
else
is_standard=0
fi
if [ "$servername" ] && [ "$userid" ]; then if [ "$servername" ] && [ "$userid" ]; then
configid=$(basename "$configfile") configid=$(basename "$configfile")
echo "$userid:$configid:$servername:$serveraliases:$size:$quota_soft:$quota_hard:$phpversion:$is_enabled" echo "$userid:$configid:$servername:$serveraliases:$size:$quota_soft:$quota_hard:$phpversion:$is_enabled:$is_standard"
fi fi
fi fi
done done
@ -823,12 +896,23 @@ op_aliasadd() {
if [ $# -eq 2 ]; then if [ $# -eq 2 ]; then
vhost="${1}.conf" vhost="${1}.conf"
alias=$2 alias=$2
vhost_file="${VHOST_PATH}/${vhost}"
[ -f $VHOST_PATH/"$vhost" ] && sed -i "/ServerName .*/a \\\tServerAlias $alias" "$VHOST_PATH"/"$vhost" --follow-symlinks if [ -f "${vhost_file}" ]; then
sed -i "/ServerName .*/a \\\tServerAlias $alias" "${vhost_file}" --follow-symlinks
else
echo "VHost file \`${vhost_file}' not found'" >&2
return 1
fi
apache2ctl configtest 2>/dev/null configtest_out=$(apache2ctl configtest)
/etc/init.d/apache2 force-reload >/dev/null configtest_rc=$?
if [ "$configtest_rc" = "0" ]; then
/etc/init.d/apache2 force-reload >/dev/null
else
echo $configtest_out >&2
fi
else usage else usage
fi fi
} }
@ -859,25 +943,6 @@ op_aliasdel() {
fi fi
} }
op_listservername() {
if [ $# -eq 1 ]; then
vhost_file="$VHOST_PATH/${1}.conf";
if [ -f "${vhost_file}" ]; then
servernames=$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$vhost_file" | uniq)
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() { op_servernameupdate() {
if [ $# -eq 3 ]; then if [ $# -eq 3 ]; then
vhost="${1}.conf" vhost="${1}.conf"
@ -885,7 +950,6 @@ op_servernameupdate() {
old_servername=$3 old_servername=$3
vhost_file="${VHOST_PATH}/${vhost}" 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
if [ -f "${vhost_file}" ]; then if [ -f "${vhost_file}" ]; then
sed -i "/^ *ServerName/ s/$old_servername/$servername/g" "${vhost_file}" --follow-symlinks sed -i "/^ *ServerName/ s/$old_servername/$servername/g" "${vhost_file}" --follow-symlinks
sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" "${vhost_file}" --follow-symlinks sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" "${vhost_file}" --follow-symlinks
@ -915,7 +979,7 @@ op_checkoccurencename() {
if [ -r "$configfile" ]; then if [ -r "$configfile" ]; then
alias=$(perl -ne 'print "$1 " if /^[[:space:]]*ServerAlias (.*)/' "$configfile" | head -n 1) alias=$(perl -ne 'print "$1 " if /^[[:space:]]*ServerAlias (.*)/' "$configfile" | head -n 1)
aliases="$aliases $alias" aliases="$aliases $alias"
servername=$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq) servername=$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq)
servernames="$servernames $servername" servernames="$servernames $servername"
fi fi
@ -928,23 +992,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"
awk '/AssignUserID/ {print $2}' "$configfile" | uniq
sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $2}' | 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=$?
@ -960,12 +1022,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

@ -0,0 +1,36 @@
<?php
/**
* Suppression d'un compte web
*
* Copyright (c) 2009 Evolix - Tous droits reserves
*
* vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
*
* @author Thomas Martin <tmartin@evolix.fr>
* @version 1.0
*/
?>
<h2>Suppression du compte web</h2>
<form name="form-delete-vhost" id="form-add" action="" method="POST">
<fieldset>
<p>
<label for="vhost-name">Nom du compte :</label>
<input type="text" name="vhost-name">
</p>
<p>
<label for="vhost-delete-db">Supprimer la base de données ? :</label>
<input id="vhost-delete-db" name="vhost-delete-db" checked="checked" value="1" type="checkbox">
</p>
<p>
<label for="vhost-dbname">Nom de la base de données :</label>
<input type="text" name="vhost-dbname" id="vhost-dbname">
</p>
<p>
<input type="submit" name="delete-vhost" value="Supprimer">
</p>
</fieldset>
</form>

View File

@ -5,7 +5,7 @@
* *
* Copyright (c) 2009 Evolix - Tous droits reserves * 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 Thomas Martin <tmartin@evolix.fr> * @author Thomas Martin <tmartin@evolix.fr>
* @version 1.0 * @version 1.0
@ -38,7 +38,7 @@
<?php <?php
for ( $i=0; $i < count($alias_list); ++$i ) { for ( $i=0; $i < count($alias_list); ++$i ) {
print '<tr>'; print '<tr>';
printf('<td><a href="http://%s">http://%s</a></td>', printf('<td>%s</td>',
$alias_list[$i]['alias'], $alias_list[$i]['alias']); $alias_list[$i]['alias'], $alias_list[$i]['alias']);
if (is_superadmin()) if (is_superadmin())
printf('<td><a href="/webadmin/%s/alias/delete/%s/">Supprimer</a></td>', printf('<td><a href="/webadmin/%s/alias/delete/%s/">Supprimer</a></td>',

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/%s/itk/%s/">'.$action[1].'</a></td>',
$domain, $action[0]);
}
print '</tr>';
?>
</tbody> </tbody>
</table> </table>
<?php <?php

View File

@ -13,16 +13,16 @@
?> ?>
<h2>ServerNames</h2> <h2>Servername</h2>
<?php <?php
if(count($servername_list) > 0) { ?> if(!empty($servername)) { ?>
<table id="tab-list"> <table id="tab-list">
<thead> <thead>
<tr> <tr>
<th>ServerName</th> <th>Servername</th>
<?php if (is_superadmin()) { <?php if (is_superadmin()) {
print '<th>Action</th>'; print '<th>Action</th>';
} ?> } ?>
@ -30,20 +30,19 @@
</thead> </thead>
<tbody> <tbody>
<?php <?php
for ( $i=0; $i < count($servername_list); ++$i ) { print '<tr>';
print '<tr>'; printf('<td>%s</td>',
printf('<td>%s</td>', $servername);
$servername_list[$i]); if (is_superadmin())
if (is_superadmin()) printf('<td><a href="/webadmin/%s/domain/edit/%s/">Modifier</a></td>',
printf('<td><a href="/webadmin/%s/domain/edit/%s/">Modifier</a></td>', $domain, $servername);
$domain, $servername_list[$i]); print '</tr>';
print '</tr>'; ?>
} ?>
</tbody> </tbody>
</table> </table>
<?php <?php
} else { } else {
print "<p>Aucun ServerName existant pour le domaine $domain !</p>"; print "<p>Aucun Servername existant pour le domaine $domain !</p>";
} }

View File

@ -22,9 +22,9 @@
<thead> <thead>
<tr> <tr>
<?php if(is_superadmin()) { <?php if(is_superadmin()) {
print '<th>Propriétaire</th>'; print '<th>Virtual Host</th>';
} ?> } ?>
<th>Domaine</th> <th>Servername</th>
<?php if(is_superadmin()) { <?php if(is_superadmin()) {
print '<th>Alias</th>'; print '<th>Alias</th>';
} }
@ -61,7 +61,7 @@
if(is_superadmin()) { if(is_superadmin()) {
printf('<td>%s</td>', $vhost_info['owner']); printf('<td>%s</td>', $vhost_info['owner']);
} }
printf('<td><a href="http://%s">http://%s</a></td>', printf('<td>%s</td>',
$vhost_info['server_name'], $vhost_info['server_name']); $vhost_info['server_name'], $vhost_info['server_name']);
if ($conf['cluster']) { if ($conf['cluster']) {
@ -87,7 +87,7 @@
printf('<td>%s</td>', $vhost_info['slave']); printf('<td>%s</td>', $vhost_info['slave']);
} }
printf('<td align="left">%s</td>', preg_replace('/,/','<br />',$vhost_info['server_alias'])); printf('<td>%s</td>', preg_replace('/,/','<br />',$vhost_info['server_alias']));
if ($conf['quota']) { if ($conf['quota']) {
printf('<td>%s</td>', $vhost_info['size']); printf('<td>%s</td>', $vhost_info['size']);
@ -103,12 +103,17 @@
if (is_superadmin()) { if (is_superadmin()) {
printf('<td>'); printf('<td>');
printf('<a href="/webadmin/%s/alias/">Alias</a> - ', $vhost_info['owner']); if (!in_array($vhost_info['owner'], $_SESSION['non_standard'])) {
printf('<a href="/webadmin/%s/domain/">Servername</a> - ', $vhost_info['owner']); printf('<a href="/webadmin/%s/alias/">Alias</a> - ', $vhost_info['owner']);
if(is_multiphp()) { printf('<a href="/webadmin/%s/domain/">Servername</a> - ', $vhost_info['owner']);
printf('<a href="/webadmin/%s/php/">PHP</a>', $vhost_info['owner']); if(is_multiphp()) {
printf('<a href="/webadmin/%s/php/">PHP</a> - ', $vhost_info['owner']);
} else {
printf('<a href="/webadmin/%s/itk/">ITK</a> - ', $vhost_info['owner']);
}
printf('<a href="/webadmin/delete/%s">Supprimer</a>', $vhost_info['owner']);
} else { } else {
printf('<a href="/webadmin/%s/itk/">ITK</a>', $vhost_info['owner']); print '<span class="form-mandatory-ok">VirtualHost non standard</span>';
} }
printf('</td>'); printf('</td>');