From: paulr Date: Tue, 20 Sep 2011 17:31:26 +0000 (+1000) Subject: some structure to how configs are loaded, how the daemon works, etc X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=175dadf56670772f8d889276df67471354a36f21;p=CBFWR.git some structure to how configs are loaded, how the daemon works, etc --- diff --git a/bin/cbfwrd.php b/bin/cbfwrd.php index 3b29870..4bf1513 100644 --- a/bin/cbfwrd.php +++ b/bin/cbfwrd.php @@ -19,8 +19,17 @@ glcas_pluginLoader(); error_log("CBFWRD starting"); + $config = new Config(); +if(isset($argv[1])) { + if($argv[1] == "boot") { + // we get called here on boot. + $config->bootHardware(); + exit(0); + } +} + // now we got into daemon modes $cont = true; @@ -30,12 +39,12 @@ $cont = true; while($cont) { $comms = new Comms; + $config->loadConfig(); $comms->putConfig($config->getConfig()); $msg = $comms->waitForMessage(); //echo "Got message: $msg\n"; - - $cont = false; + if($msg == "quit") $cont = false; } ?> \ No newline at end of file diff --git a/doco/commands.txt b/doco/commands.txt new file mode 100644 index 0000000..9619cf8 --- /dev/null +++ b/doco/commands.txt @@ -0,0 +1,42 @@ +hostname +domainname + +dns server + +ntp server + +login auth + +admin via http on dev from +admin via https on dev from + +interace dev devname address4 addr/mask +interace dev devname address6 addr/mask +interace dev devname zone zonename +interace dev devname mtu|speed|duplex ... + +interface lag name with .... + +interface vlan name from + +interface bridge name with ... + + +route4|6 default|addr to
dev +route4|6 default|addr to
+route4|6 default|addr dev + +rule add and log from to in zones +rule move to + + is reject, drop, accept + +nat add... need to figure this one out + + is: +object/type/name + +where type is, host, network... thats it for now + +zonecontext is: +Zone/zonename/rulenumber \ No newline at end of file diff --git a/libcbfwr/comms.php b/libcbfwr/comms.php index db0215e..610959e 100644 --- a/libcbfwr/comms.php +++ b/libcbfwr/comms.php @@ -15,23 +15,26 @@ class Comms { $this->msgres = msg_get_queue($MESSAGE_KEY, 0666); } - function getConfig() + function getConfig($type=0) { global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY; sem_acquire($this->semres); $shm_space = shm_attach($STORE_KEY, 16*1024*1024); - $config = shm_get_var($shm_space, 0); + $config = shm_get_var($shm_space, $type); sem_release($this->semres); return $config; } - function putConfig($config) + + // type = 0 for the main config + // type = 1 for the boot hardware config + function putConfig($config, $type=0) { global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY; sem_acquire($this->semres); $shm_space = shm_attach($STORE_KEY, 16*1024*1024); - shm_put_var($shm_space, 0, $config); + shm_put_var($shm_space, $type, $config); sem_release($this->semres); } diff --git a/libcbfwr/config.php b/libcbfwr/config.php index 94cf1b3..9ca0ff9 100644 --- a/libcbfwr/config.php +++ b/libcbfwr/config.php @@ -31,29 +31,50 @@ class Config { $this->config_file = "../var/"; } else { echo "No directory where i can create a config, bailing\n"; - exit(0); + $this->config["status"] = "unconf"; } } - if($this->config["status"] == "conf") { - - $this->loadConfig($this->config_file); + + + } + } + + function bootHardware() + { + $this->findHardware(); + + $mycomm = new Comms(); + $mycomm->putConfig($this->config, 1); + + } + + function loadConfig() + { + global $AM_DAEMON; + + if($AM_DAEMON) { + if($this->config["status"] == "conf") { + $this->loadConfigFile($this->config_file); + $this->applyConfig(); $this->findHardware(); - print_r($this->config); - $this->applyConfig(); - } else { - // we go into firstrun mode + $mycomm = new Comms(); + $mycomm->putConfig($this->config); + $this->boot_config = $mycomm->getConfig(1); } - - } else { - // config comes from shm... we'll get there - } + $mycomm = new Comms(); + $this->config = $mycomm->getConfig(0); + $this->boot_config = $mycomm->getConfig(1); + + } } function findHardware() { + + // first, network interfaces $dh = opendir("/sys/class/net/"); while(($fname = readdir($dh)) !== false) { @@ -83,6 +104,11 @@ class Config { return $this->config; } + function getBootConfig() + { + return $this->boot_config; + } + function applyConfig() { global $AM_DAEMON; @@ -92,7 +118,7 @@ class Config { return true; } - function loadConfig($file) + function loadConfigFile($file) { global $AM_DAEMON; if(!$AM_DAEMON) return true; @@ -315,7 +341,7 @@ class Config { } - function saveConfig() + function saveConfigFile($file) { global $AM_DAEMON; if(!$AM_DAEMON) return true; @@ -324,6 +350,7 @@ class Config { private $config_file; private $config; + private $boot_config; }; ?> \ No newline at end of file diff --git a/libcbfwr/fwui.php b/libcbfwr/fwui.php index a94b4ad..cf8056b 100644 --- a/libcbfwr/fwui.php +++ b/libcbfwr/fwui.php @@ -2,7 +2,9 @@ function CBFWZonesPage() { - return "hi"; + $comms = new Comms(); + + $config = $comms->getConfig(); } function CBFWInterfacesPage() diff --git a/libcbfwr/web.php b/libcbfwr/web.php index 8e4967c..aa039a8 100644 --- a/libcbfwr/web.php +++ b/libcbfwr/web.php @@ -1,12 +1,12 @@ "; + echo "i.e.: add rule reject from object/host/hostname to address6/2003::123 in zones Zone/zonename/rulenum Zone/zonename/rulenum"; + $conf = new Config(); + $conf->loadConfig(); + + echo "
";
+	print_r($conf->getConfig());
+	echo "\n\n\n";
+	print_r($conf->getBootConfig());
+	echo "
"; + +} + function CBFWMenuBuilder() { global $BASE_URL, $MENU_ITEMS;