Alternc  3.2
Alternc logiel libre pour l'h├ębergement
 All Data Structures Namespaces Files Functions Variables Pages
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 ## LogFormat informations
54 Include \"/etc/alternc/apache_logformat.conf\"";
55 
56 // Do we need to include manual configuration ?
57 if ( is_dir( ALTERNC_VHOST_MANUALCONF ) ) {
58  $conf2.="\n## Manual VHOST\nInclude ".ALTERNC_VHOST_MANUALCONF."\n" ;
59 } else {
60  $conf2.="\n## Manual VHOST directory missing (".ALTERNC_VHOST_MANUALCONF.")\n" ;
61 }
62 
63 $conf2.="\n$conf\n\n###END OF ALTERNC AUTO-GENERATED FILE - DO NOT EDIT MANUALLY###\n";
64 
65 // Write the conf !
66 if (! file_put_contents(ALTERNC_VHOST_FILE, $conf2) ) {
67  die("Error: writing content\n");
68 }
69 
70 // Update the database to inform that we did the job
71 foreach ( $todo as $taction=>$tlist){
72  foreach ($tlist as $ttype) {
73  foreach($ttype as $tid) {
74  $dom->subdomain_modif_are_done($tid, $taction);
75  }
76  }
77 }
78 
79 // Hooks !
80 foreach (array('DELETE', 'CREATE', 'UPDATE', 'ENABLE', 'DISABLE') as $y) {
81  if (!isset($todo[$y]) || empty($todo[$y])) continue;
82  $dom->generate_conf_oldhook($y, $todo); // old hooks for compatibility
83  $hooks->invoke("hook_genconf", array($y, $todo[$y], $parameters)); // modern hooks
84 }
85 
86 echo $nb_todo;
87