Add new features:

- Unix quota management
  - Apache ServerAlias management
  - support for multiple versions of PHP
  - MySQL databases management (new page dbadmin)
This commit is contained in:
Romain Dessort 2017-08-22 12:32:33 -04:00
parent ee8b8a6437
commit 483482ab59
10 changed files with 243 additions and 20 deletions

View file

@ -27,6 +27,8 @@ $oriconf['cache'] = '/home/evoadmin/www/cache.sqlite';
$oriconf['known_host'] = '/home/evoadmin/www/known_host';
$oriconf['ftpadmin'] = FALSE;
$oriconf['bindadmin'] = FALSE;
$oriconf['php_versions'] = array();
$oriconf['quota'] = FALSE;
$oriconf['noreplication'] = array('srv00.example.com', 'srv01.example.com', 'srv02.example.com');
$oriconf['postponedreplication'] = array('srv00.example.com', 'srv01.example.com', 'srv02.example.com');

View file

@ -68,6 +68,10 @@ if (!array_key_exists('auth', $_SESSION) || $_SESSION['auth']!=1) {
include_once EVOADMIN_BASE . '../inc/destroy.php';
} elseif (preg_match('#^/dbadmin/?$#', $uri, $params)) {
include_once EVOADMIN_BASE . '../inc/dbadmin.php';
} else {
die ("Cette page n'existe pas !!!");
}

View file

@ -52,6 +52,14 @@ function web_add($form, $admin_mail) {
}
}
if (array_key_exists('php_versions', $conf) && count($conf['php_versions']) > 1) {
$exec_cmd .= sprintf(' -r %s', $conf['php_versions'][$form->getField('php_version')->getValue()]);
}
if ($conf['quota']) {
$exec_cmd .= sprintf(' -q %s:%s', $form->getField('quota_soft')->getValue(), $form->getField('quota_hard')->getValue());
}
$exec_cmd .= sprintf(' -l %s %s %s 2>&1', $admin_mail,
$form->getField('username')->getValue(),
$form->getField('domain')->getValue());
@ -63,11 +71,10 @@ function web_add($form, $admin_mail) {
if ( $form->getField('domain_alias')->getValue() ) {
$domain_alias = preg_split('/,/', $form->getField('domain_alias')->getValue());
foreach ( $domain_alias as $domain ) {
$exec_cmd = 'web-add.sh add-alias '.$form->getField('username')->getValue().' ';
$exec_cmd = 'web-add-multi.sh add-alias '.$form->getField('username')->getValue().' ';
$domain = trim($domain);
$exec_cmd .= $domain.' '.$master.' '.$slave;
$exec_cmd .= $domain.' '. $server_list;
sudoexec($exec_cmd, $exec_output, $exec_return);
//domain_add($form, gethostbyname($master), false);
}
$exec_return |= $exec_return2; // $exec_return == 0 if $exec_return == 0 && $exec_return2 == 0
array_push($exec_output, $exec_output2);
@ -339,6 +346,19 @@ if ($conf['bindadmin']) {
$form->addField('use_gmail_mxs', new CheckboxInputFormField("Utilisation des serveurs Gmail en MX ?", FALSE));
}
if (array_key_exists('php_versions', $conf) && count($conf['php_versions']) > 1) {
$form->addField('php_version', new SelectFormField("Version de PHP", FALSE, $conf['php_versions']));
}
if ($conf['quota']) {
$field_quota_soft = new TextInputFormField("Quota soft (GiB, entier)", TRUE);
$field_quota_soft->setValue('1');
$form->addField('quota_soft', $field_quota_soft);
$field_quota_hard = new TextInputFormField("Quota hard (GiB, entier)", TRUE);
$field_quota_hard->setValue('2');
$form->addField('quota_hard', $field_quota_hard);
}
/* Traitement du formulaire */
if(!empty($_POST)) {
$form->isCurrentPage(TRUE);

45
inc/dbadmin.php Normal file
View file

@ -0,0 +1,45 @@
<?php
/**
* Databases 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
*/
global $conf;
if (!$conf['dbadmin'])
http_redirect('/');
$cmd = 'dbadmin.sh list';
if(!is_superadmin()) {
$cmd .= ' ' . $_SESSION['user'];
}
sudoexec($cmd, $data_output, $exec_return);
/*
* Put command output to db_list array.
*/
$db_list = array();
foreach ($data_output as $data_line) {
$data_split = explode(':', $data_line);
array_push($db_list, array(
'owner' => $data_split[0],
'database' => $data_split[1])
);
}
include_once EVOADMIN_BASE . '../tpl/header.tpl.php';
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';
include_once EVOADMIN_BASE . '../tpl/dbadmin.tpl.php';
include_once EVOADMIN_BASE . '../tpl/footer.tpl.php';
?>

View file

@ -71,6 +71,15 @@ if (isset($_GET['del']) ) {
} else
print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
}
else {
$exec_cmd = 'web-add.sh del-alias ' . $serveralias['domain'] . ' ' . $serveralias['alias'];
sudoexec($exec_cmd, $exec_output, $exec_return);
if ($exec_return == 0) {
printf ('<p>Alias %s est supprimé.</p>', $serveralias['alias']);
} else
print "<p>La suppression a échouée. Veuillez contacter votre administrateur.</p>";
}
printf ('<p><a href="%s">Retour à la liste des alias</a></p>', $_SERVER['REDIRECT_URL']);
print "</center>";
@ -171,9 +180,33 @@ if (isset($_GET['del']) ) {
}
}
else {
$serveralias = array (
'domain' => htmlspecialchars(basename($_SERVER['REDIRECT_URL'])),
'alias' => $form->getField('domain_alias')->getValue(),
);
$account_name=$serveralias['domain'];
$exec_cmd = 'web-add.sh add-alias ' . $serveralias['domain'] . ' ' . $serveralias['alias'];
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>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 "<h2>Ajout d'un serveralias</h2><hr>";
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
print " <fieldset>";
print " <legend>Ajout d'un serveralias</legend>";
@ -212,6 +245,26 @@ if (isset($_GET['del']) ) {
$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);
/* Récupération de cette liste dans le tableau $vhost_list */
$vhost_list = array();
foreach($data_output as $data_line) {
$data_split = explode(':', $data_line);
if ($data_split[0] == $domain && $data_split[3] != '') {
$alias_split = explode(',', $data_split[3]);
foreach($alias_split as $alias) {
$alias_array['alias'] = $alias;
array_push($alias_list, $alias_array);
}
}
}
}
include_once EVOADMIN_BASE . '../tpl/header.tpl.php';
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';

View file

@ -22,6 +22,7 @@ global $conf;
if (!$conf['cluster']) {
$cmd = 'web-add.sh list-vhost';
if(!is_superadmin()) {
$cmd = sprintf('%s %s', $cmd, $_SESSION['user']);
}
@ -31,12 +32,46 @@ if (!$conf['cluster']) {
$vhost_list = array();
foreach($data_output as $data_line) {
$data_split = explode(':', $data_line);
array_push($vhost_list, array(
'owner' => $data_split[0],
'configid' => $data_split[1],
'server_name' => $data_split[2],
'server_alias' => $data_split[3])
);
if (strstr($data_split[4],'K')) {
$taille_utilise = number_format(($data_split[4]/1024), 2, '.', '').'M';
$taille_utilise_mo = $taille_utilise;
if ($taille_utilise >= 1024) {
$taille_utilise = number_format(($taille_utilise/1024), 2, '.', '').'G';
}
} else if ($data_split[4] >= 1024) {
$taille_utilise_mo = $data_split[4];
$taille_utilise = number_format(($data_split[4]/1024), 2, '.', '').'G';
} else {
$taille_utilise_mo = $data_split[4];
$taille_utilise = $data_split[4];
}
$quota_bas_mo = $data_split[5];
$quota_bas = number_format(($data_split[5]/1024), 2, '.', '').'G';
$quota_haut = number_format(($data_split[6]/1024), 2, '.', '').'G';
$occupation = number_format((($taille_utilise_mo/$quota_bas_mo)*100), 2, '.', '');
if ($occupation >= 90) {
$occupation = '<span style="color:red;font-weight:bold;">'.$occupation.'%</span>';
} else if ($occupation >= 80) {
$occupation = '<span style="color:MediumVioletRed;font-weight:bold;">'.$occupation.'%</span>';
} else if ($occupation >= 70) {
$occupation = '<span style="color:Fuchsia;font-weight:bold;">'.$occupation.'%</span>';
} else {
$occupation = $occupation.'%';
}
array_push($vhost_list, array(
'owner' => $data_split[0],
'configid' => $data_split[1],
'server_name' => $data_split[2],
'server_alias' => $data_split[3],
'size' => $taille_utilise,
'quota_soft' => $quota_bas,
'quota_hard' => $quota_haut,
'occupation' => $occupation,
'php_version' => $data_split[7],
'is_enabled' => $data_split[8])
);
}
}

42
tpl/dbadmin.tpl.php Normal file
View file

@ -0,0 +1,42 @@
<?php
/**
* Databases management page template
*
* 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
*/
?>
<div class="container">
<h2>Bases de données</h2><hr>
<?php if(count($db_list) > 0) { ?>
<table id="tab-list" class="table table-striped table-condensed">
<thead>
<tr>
<th>Propriétaire</th>
<th>Bases de données</th>
</tr>
</thead>
<tbody>
<?php foreach($db_list as $db_info) {
print '<tr>';
printf('<td align="left">&nbsp;&nbsp;%s</td>', preg_replace("/'/", "", $db_info['owner']));
printf('<td align="left">&nbsp;&nbsp;%s</td>', $db_info['database']);
print '</tr>';
} ?>
</tbody>
</table>
<?php
} else {
print '<div class="alert alert-info" role="alert">Aucune base existante !</div>';
}
?>
</div>

View file

@ -25,6 +25,9 @@
<li><a href="/ftpadmin/add">Ajout FTP</a></li>
<li><a href="/ftpadmin">Comptes FTP</a></li>
<?php } ?>
<?php if ($conf['dbadmin']) { ?>
<li><a href="/dbadmin">Bases de données</a></li>
<?php } ?>
<li><a href="/destroy">Déconnexion</a></li>
</ul>
<br/>

View file

@ -16,7 +16,6 @@
<h2>Server Alias</h2>
<?php
if ($conf['cluster']) {
if(count($alias_list) > 0) {
@ -59,6 +58,5 @@
}
}
?>

View file

@ -25,6 +25,21 @@
print '<th>Propriétaire</th>';
} ?>
<th>Domaine</th>
<?php if(is_superadmin()) {
print '<th>Alias</th>';
}
if($conf['quota']) {
print '<th>&nbsp;Utilisé&nbsp;</th>';
print '<th>&nbsp;Soft&nbsp;</th>';
print '<th>&nbsp;Hard&nbsp;</th>';
print '<th>&nbsp;Occupation&nbsp;</th>';
}
if (array_key_exists('php_versions', $conf) && count($conf['php_versions']) > 1) {
print '<th>&nbsp;PHP&nbsp;</th>';
}
?>
<th>&nbsp;Actif&nbsp;</th>
<th>&nbsp;Action&nbsp;</th>
<!--<th>Opérations</th>-->
<?php if($conf['cluster']) { ?>
<th>Bdd</th>
@ -32,12 +47,8 @@
<th>Replication</th>
<th>Master</th>
<th>Slave</th>
<?php
}
if(is_superadmin()) {
print '<th>Alias</th>';
} ?>
<tr>
<?php } ?>
</tr>
</thead>
<tbody>
<?php foreach($vhost_list as $vhost_info) {
@ -69,10 +80,20 @@
printf('<td bgcolor="#696969"/>');
else
printf('<td>%s</td>', $vhost_info['slave']);
}
printf('<td align="left">%s</td>', preg_replace('/,/','<br />',$vhost_info['server_alias']));
if ($conf['quota']) {
printf('<td>%s</td>', $vhost_info['size']);
printf('<td>%s</td>', $vhost_info['quota_soft']);
printf('<td>%s</td>', $vhost_info['quota_hard']);
printf('<td>%s</td>', $vhost_info['occupation']);
}
else {
printf('<td>%s</td>', $vhost_info['server_alias']);
if (array_key_exists('php_versions', $conf) && count($conf['php_versions']) > 1) {
printf('<td>%s</td>', preg_replace("/^(\d)(\d)$/", '\1.\2', $vhost_info['php_version']));
}
printf('<td>%s</td>', $vhost_info['is_enabled']);
if (is_superadmin()) {
printf('<td><a href="/webadmin/edit/%s">Lister/Modifier</a></td>',
$vhost_info['owner']);