running configuration and deltas and shit
[CBFWR.git] / bin / cbfwrd.php
1 <?php
2 $CMD_ROOT_FS = realpath(dirname(__FILE__));
3 $AM_DAEMON = true;
4
5 global $CMD_ROOT_FS;
6 global $AM_DAEMON;
7
8 // add libglcas as if it were a path in ../libglcas
9 if(file_exists("../libcbfwr")) {
10         $path = realpath($CMD_ROOT_FS."/../");
11         error_log("added cbfwr path as $path");
12         set_include_path(get_include_path().PATH_SEPARATOR.$path);
13 }
14
15 // include the based library
16 require_once("libcbfwr/lib.php");
17
18 glcas_pluginLoader();
19
20 error_log("CBFWRD starting");
21
22
23 $config = new Config();
24 global $config;
25
26 if(isset($argv[1])) {
27         if($argv[1] == "boot") {
28                 // we get called here on boot.
29                 $config->bootHardware();
30                 exit(0);
31         }
32 }
33
34 // now we got into daemon modes
35 $cont = true;
36
37 // setup our sem/shm stuff
38
39 // do the initial stuff
40 $comms = new Comms;
41 $config->loadConfig();
42 $rawconf = $config->getConfig();
43 $comms->putConfig($rawconf);
44
45 while($cont) {
46         $msg = $comms->waitForMessage();
47         
48         //echo "Got message: $msg\n";
49         if($msg == "quit") $cont = false;
50         else cbfwd_commandProcessor($msg);
51 }
52
53
54 function cbfwd_commandProcessor($command)
55 {
56         global $config;
57         $cmds = explode(" ", $command);
58         $comms = new Comms;
59         
60         $comms->lockConfigs();
61         switch($cmds[0]) {
62                 case "goodone":
63                         break;
64                         
65                 // interface change requests
66                 case "interface":
67                         $int = $cmds[1];
68                         if($cmds[2] == "changename") {
69                                 $rawconf = $comms->getConfig();
70                                 if(isset($rawconf["interface"]["$int"]["name"])) $rawconf["interface"]["$int"]["name"] = $cmds[3];
71                                 $comms->putConfig($rawconf);
72                         }
73                         break;
74                         
75                 case "zone":
76                         $cmd = $cmds[1];
77                         switch($cmd) {
78                                 case "add":
79                                         $zonename = $cmds[2];
80                                         $rawconf = $comms->getConfig();
81                                         $rawconf["zone"][$zonename]["name"] = 1;
82                                         $comms->putConfig($rawconf);
83                                         break;
84                                         
85                         }
86         }
87         $comms->unlockConfigs();
88 }
89 ?>