From 7d50c398c710eba0d72ef4568828ead023d6863a Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Fri, 3 Jan 2014 09:30:35 +0000 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20la=20g=C3=A9n=C3=A9ration=20de?= =?UTF-8?q?=20la=20conf=20apache=20=20*=20hooks=20=20*=20retrocompatibilit?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bureau/class/config.php | 4 +++ bureau/class/m_dom.php | 70 ++++++++++++++++++++++++++++++++++-- src/generate_apache_conf.php | 12 +++++-- 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/bureau/class/config.php b/bureau/class/config.php index 8f0ac688..6af3fd9d 100644 --- a/bureau/class/config.php +++ b/bureau/class/config.php @@ -105,6 +105,10 @@ define('ALTERNC_LOCALES', ALTERNC_PANEL."/locales"); define('ALTERNC_LOCK_JOBS', '/var/run/alternc/jobs-lock'); define('ALTERNC_LOCK_PANEL', '/var/lib/alternc/panel/nologin.lock'); 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 : */ $root=ALTERNC_PANEL."/"; diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 61c8c11d..9759db67 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -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. * If no parameters, return the parameters for ALL the vhost. * Optionnal parameters: id of the sub_domaines * **/ -function generation_parameters($id=null) { +function generation_parameters($id=null, $only_apache=true) { global $db,$err; $err->log("dom","generation_parameters"); $params=""; @@ -1833,7 +1833,33 @@ function generation_parameters($id=null) { $id=intval($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(); while ($db->next_record()) { $r[ $db->Record['sub_id'] ] = $db->Record; @@ -1862,6 +1888,33 @@ function generation_domains_type() { 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. * Die if a specific FQDN have 2 vhost conf. @@ -1908,6 +1961,17 @@ function generate_apacheconf($p = null) { 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 diff --git a/src/generate_apache_conf.php b/src/generate_apache_conf.php index a9000c2e..90eb0302 100755 --- a/src/generate_apache_conf.php +++ b/src/generate_apache_conf.php @@ -19,9 +19,6 @@ ini_set("display_errors", 1); FIXME : - add security check - - add hooks - - make better retro compatibility - */ // Check if we can modify Apache conf @@ -39,6 +36,8 @@ if ( ! in_array('force', $argv) && $nb_todo < 1) { die('0'); } +$todo = $dom->generation_todo(); +$parameters = $dom->generation_parameters(); // Generate apache conf $conf = $dom->generate_apacheconf(); @@ -67,5 +66,12 @@ if (! file_put_contents(ALTERNC_VHOST_FILE, $conf2) ) { 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;