Améliore la génération de la conf apache

* hooks
 * retrocompatibilité
This commit is contained in:
Alan Garcia 2014-01-03 09:30:35 +00:00
parent 7c349f887f
commit 7d50c398c7
3 changed files with 80 additions and 6 deletions

View File

@ -105,6 +105,10 @@ define('ALTERNC_LOCALES', ALTERNC_PANEL."/locales");
define('ALTERNC_LOCK_JOBS', '/var/run/alternc/jobs-lock'); define('ALTERNC_LOCK_JOBS', '/var/run/alternc/jobs-lock');
define('ALTERNC_LOCK_PANEL', '/var/lib/alternc/panel/nologin.lock'); define('ALTERNC_LOCK_PANEL', '/var/lib/alternc/panel/nologin.lock');
define('ALTERNC_APACHE2_GEN_TMPL_DIR', '/etc/alternc/templates/apache2/'); define('ALTERNC_APACHE2_GEN_TMPL_DIR', '/etc/alternc/templates/apache2/');
define('ALTERNC_VHOST_DIR',"/var/lib/alternc/apache-vhost/");
define('ALTERNC_VHOST_FILE',ALTERNC_VHOST_DIR."vhosts_all.conf");
define('ALTERNC_VHOST_MANUALCONF',ALTERNC_VHOST_DIR."manual/");
/* PHPLIB inclusions : */ /* PHPLIB inclusions : */
$root=ALTERNC_PANEL."/"; $root=ALTERNC_PANEL."/";

View File

@ -1819,13 +1819,13 @@ class m_dom {
/** /**
* Return an array with all the needed parameters to generate the apache conf * Return an array with all the needed parameters to generate conf
* of a vhost. * of a vhost.
* If no parameters, return the parameters for ALL the vhost. * If no parameters, return the parameters for ALL the vhost.
* Optionnal parameters: id of the sub_domaines * Optionnal parameters: id of the sub_domaines
* *
**/ **/
function generation_parameters($id=null) { function generation_parameters($id=null, $only_apache=true) {
global $db,$err; global $db,$err;
$err->log("dom","generation_parameters"); $err->log("dom","generation_parameters");
$params=""; $params="";
@ -1833,7 +1833,33 @@ function generation_parameters($id=null) {
$id=intval($id); $id=intval($id);
$params=" AND sd.id = $id "; $params=" AND sd.id = $id ";
} }
$db->query("select sd.id as sub_id, lower(sd.type) as type, m.login, m.uid as uid, if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) as fqdn, concat_ws('@',m.login,v.value) as mail, sd.valeur from sub_domaines sd,membres m,variable v, domaines_type dt where sd.compte=m.uid and v.name='mailname_bounce' and lower(dt.name) = lower(sd.type) and dt.only_dns is false $params order by m.login, sd.domaine, sd.sub ;"); if ($only_apache) {
$params.=" and dt.only_dns is false ";
}
// BUG BUG BUG FIXME
// Suppression de comptes -> membres existe pas -> domaines a supprimer ne sont pas lister
$db->query("
select
sd.id as sub_id,
lower(sd.type) as type,
m.login,
m.uid as uid,
if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) as fqdn,
concat_ws('@',m.login,v.value) as mail,
sd.valeur
from
sub_domaines sd left join membres m on sd.compte=m.uid,
variable v,
domaines_type dt
where
v.name='mailname_bounce'
and lower(dt.name) = lower(sd.type)
$params
order by
m.login,
sd.domaine,
sd.sub
;");
$r = array(); $r = array();
while ($db->next_record()) { while ($db->next_record()) {
$r[ $db->Record['sub_id'] ] = $db->Record; $r[ $db->Record['sub_id'] ] = $db->Record;
@ -1862,6 +1888,33 @@ function generation_domains_type() {
return $d; return $d;
} }
// Launch old fashionned hooks as there was in AlternC 1.0
function generate_conf_oldhook($action, $lst_sub, $sub_obj=null) {
if (is_null($sub_obj)) $sub_obj=$this->generation_parameters(null, false);
if (!isset($lst_sub[strtoupper($action)]) || empty( $lst_sub[strtoupper($action)] )) {
return false;
}
$lst_by_type = $lst_sub[strtoupper($action)] ;
foreach ( $lst_by_type as $type => $lid_arr) {
$script = "/etc/alternc/functions_hosting/hosting_".strtolower($type).".sh";
if (! @is_executable($script) ) {
continue;
}
foreach ($lid_arr as $lid ) {
$o = $sub_obj[$lid];
$cmd = $script." ".escapeshellcmd(strtolower($action))." ";
$cmd .= escapeshellcmd($o['fqdn'])." ".escapeshellcmd($o['valeur']);
system($cmd);
}
} // foreach $lst_by_type
}
/** /**
* Generate apache configuration. * Generate apache configuration.
* Die if a specific FQDN have 2 vhost conf. * Die if a specific FQDN have 2 vhost conf.
@ -1908,6 +1961,17 @@ function generate_apacheconf($p = null) {
return $ret; return $ret;
} }
// Return an array with the list of id of sub_domains waiting for an action
function generation_todo() {
global $db,$err;
$err->log("dom","generation_todo");
$db->query("select id as sub_id, web_action, type from sub_domaines where web_action !='ok';");
$r = array();
while ($db->next_record()) {
$r[ strtoupper($db->Record['web_action']) ][ strtoupper($db->Record['type']) ][] = $db->f('sub_id');
}
return $r;
}
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** hook function called by AlternC-upnp to know which open /** hook function called by AlternC-upnp to know which open

View File

@ -19,9 +19,6 @@ ini_set("display_errors", 1);
FIXME : FIXME :
- add security check - add security check
- add hooks
- make better retro compatibility
*/ */
// Check if we can modify Apache conf // Check if we can modify Apache conf
@ -39,6 +36,8 @@ if ( ! in_array('force', $argv) && $nb_todo < 1) {
die('0'); die('0');
} }
$todo = $dom->generation_todo();
$parameters = $dom->generation_parameters();
// Generate apache conf // Generate apache conf
$conf = $dom->generate_apacheconf(); $conf = $dom->generate_apacheconf();
@ -67,5 +66,12 @@ if (! file_put_contents(ALTERNC_VHOST_FILE, $conf2) ) {
die("Error: writing content\n"); die("Error: writing content\n");
} }
// Hooks !
foreach (array('DELETE', 'CREATE', 'UPDATE', 'ENABLE', 'DISABLE') as $y) {
if (!isset($todo[$y]) || empty($todo[$y])) continue;
$dom->generate_conf_oldhook($y, $todo); // old hooks for compatibility
$hooks->invoke("hook_genconf", array($y, $todo[$y], $parameters)); // modern hooks
}
echo $nb_todo; echo $nb_todo;