Alternc  latest
Alternc logiel libre pour l'hébergement
generate_apache_conf.php
Go to the documentation of this file.
1 #!/usr/bin/php -q
2 <?php
3 
4 /**
5  *
6  * Generate Apache configuration for AlternC
7  *
8  * To force generation, /launch/generate_apache_conf.php force
9  *
10  * Return the number of vhost modified, return 0 if no action
11  *
12  **/
13 
14 require_once("/usr/share/alternc/panel/class/config_nochk.php");
15 ini_set("display_errors", 1);
16 
17 
18 /*
19 
20 FIXME :
21  - add security check
22 */
23 
24 // Check if we can modify Apache conf
25 @touch(ALTERNC_VHOST_FILE);
26 if ( ! is_writable( ALTERNC_VHOST_FILE )) {
27  die("Error: ".ALTERNC_VHOST_FILE." is not writable\n");
28 }
29 
30 // Do we need to regenerate apache conf ?
31 $db->query("select count(*) as c from sub_domaines where web_action != 'OK';");
32 if (! $db->next_record()) $nb_todo = 0;
33 $nb_todo = $db->f('c');
34 
35 // But, we may have forced it
36 if ( ! in_array('force', $argv) && $nb_todo < 1) {
37  die('0');
38 }
39 
40 $todo = $dom->generation_todo();
41 $parameters = $dom->generation_parameters();
42 
43 // Generate apache conf
44 $conf = $dom->generate_apacheconf();
45 
46 if (! $conf) {
47  die("Error: generate empty configuration\n");
48 }
49 
50 // Add some headers
51 $conf2 = "###BEGIN OF ALTERNC AUTO-GENERATED FILE - DO NOT EDIT MANUALLY###
52 # Generation: ".date('Y-m-d H:i:s');
53 
54 // Do we need to include manual configuration ?
55 if ( is_dir( ALTERNC_VHOST_MANUALCONF ) ) {
56  $conf2.="\n## Manual VHOST\nInclude ".ALTERNC_VHOST_MANUALCONF."\n" ;
57 } else {
58  $conf2.="\n## Manual VHOST directory missing (".ALTERNC_VHOST_MANUALCONF.")\n" ;
59 }
60 
61 $conf2.="\n$conf\n\n###END OF ALTERNC AUTO-GENERATED FILE - DO NOT EDIT MANUALLY###\n";
62 
63 // Write the conf !
64 if (! file_put_contents(ALTERNC_VHOST_FILE, $conf2) ) {
65  die("Error: writing content\n");
66 }
67 
68 // Update the database to inform that we did the job
69 foreach ( $todo as $taction=>$tlist){
70  foreach ($tlist as $ttype) {
71  foreach($ttype as $tid) {
72  $dom->subdomain_modif_are_done($tid, $taction);
73  }
74  }
75 }
76 
77 // Hooks !
78 foreach (array('DELETE', 'CREATE', 'UPDATE', 'ENABLE', 'DISABLE') as $y) {
79  if (!isset($todo[$y]) || empty($todo[$y])) continue;
80  $dom->generate_conf_oldhook($y, $todo); // old hooks for compatibility
81  $hooks->invoke("hook_genconf", array($y, $todo[$y], $parameters)); // modern hooks
82 }
83 
84 echo $nb_todo;
85 
$hooks
Definition: bootstrap.php:75
if(! $conf) $conf2
global $db
Definition: bootstrap.php:22
const ALTERNC_VHOST_FILE
Definition: config.php:94
if(! in_array('force', $argv) && $nb_todo< 1) $todo
const ALTERNC_VHOST_MANUALCONF
Definition: config.php:95
$dom
Definition: whois_test.php:10