update ServerName from web interface

This commit is contained in:
Nicolas Roman 2019-03-21 10:02:23 +01:00 committed by Ludovic Poujol
parent 794defa907
commit 7e02e50047
3 changed files with 252 additions and 0 deletions

View file

@ -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';

193
inc/webadmin-servername.php Normal file
View file

@ -0,0 +1,193 @@
<?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;
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 "<center>";
printf ('<p>L\'alias %s du domaine %s a bien été créé</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
} else {
print "<center>";
printf ('<p>Echec dans la creation de l\'alias %s du domaine %s</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
}
} else {
print "<center>";
printf ('<p>Alias %s du domaine %s deja existant !</p>', $serveralias['alias'], $serveralias['domain']);
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
}
}
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 "<center>";
printf ('<p>Le Server Name %s du domaine %s a bien été modifié</p>', $servername['servername'], $servername['domain']);
printf ('<p><a href="%s">Retour à la liste des Server Names</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
}
else {
print "<center>";
printf ('<p>Echec dans la modification du Server Name %s du domaine %s</p>', $servername['servername'], $servername['domain']);
printf ('<p><a href="%s">Retour à la liste des Server Names</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
}
}
}
} else {
print "<h2>Modification du ServerName</h2><hr>";
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
print " <fieldset>";
print " <legend>Modification du Server Name</legend>";
print $form;
print " <p><input type=\"submit\" value=\"Modifier\"/></p>";
print " </fieldset>";
print "</form>";
}
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';
}
?>

View file

@ -0,0 +1,55 @@
<?php
/**
* Edition d'un domaine
*
* 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>Server Name</h2>
<?php
if(count($servername_list) > 0) { ?>
<table id="tab-list">
<thead>
<tr>
<th>Server Name</th>
<?php if (is_superadmin()) {
print '<th>Action</th>';
} ?>
</tr>
</thead>
<tbody>
<?php
for ( $i=0; $i < count($servername_list); ++$i ) {
print '<tr>';
printf('<td>%s</td>',
$servername_list[$i]);
if (is_superadmin())
printf('<td><a href="/webadmin/servername/%s?edit=%s">Modifier</a></td>',
$domain, $servername_list[$i]);
print '</tr>';
} ?>
</tbody>
</table>
<?php
} else {
print "<p>Aucun alias existant pour le domaine $domain !</p>";
if (is_superadmin()) {
print "<center>";
printf('<p><a href="/webadmin/edit/%s?add">Ajouter un alias</a></p>', $domain);
print "</center>";
}
}
?>