error_log("CBFWRD starting");
+$comms = new Comms;
-$config = new Config();
-global $config;
if(isset($argv[1])) {
+ // we get called here on boot.
if($argv[1] == "boot") {
- // we get called here on boot.
- $config->bootHardware();
+ $config = new Config(false);
+ $config->findHardware();
+ $conf = $config->getConfig();
+ $comms->putConfig($conf, 1);
exit(0);
}
}
// setup our sem/shm stuff
// do the initial stuff
-$comms = new Comms;
-$config->loadConfig();
+$config = new Config(true);
+$config->loadConfigFile();
$rawconf = $config->getConfig();
$comms->putConfig($rawconf);
+$config->applyConfig();
+$runconf["status"] = "nochange";
+$comms->putConfig($runconf, 2);
+$res = $comms->getConfig(3);
+if($res === false) {
+ $comms->putConfig($runconf, 3);
+}
+
while($cont) {
$msg = $comms->waitForMessage();
$comms->lockConfigs();
switch($cmds[0]) {
- case "goodone":
- break;
-
- // interface change requests
- case "interface":
- $int = $cmds[1];
- if($cmds[2] == "changename") {
- $rawconf = $comms->getConfig();
- if(isset($rawconf["interface"]["$int"]["name"])) $rawconf["interface"]["$int"]["name"] = $cmds[3];
- $comms->putConfig($rawconf);
- }
+ case "applyclientconfig":
break;
- case "zone":
- $cmd = $cmds[1];
- switch($cmd) {
- case "add":
- $zonename = $cmds[2];
- $rawconf = $comms->getConfig();
- $rawconf["zone"][$zonename]["name"] = 1;
- $comms->putConfig($rawconf);
- break;
-
- }
}
$comms->unlockConfigs();
}
0 - fs configuration
1 - boot hardware config
2 - running config (deltas from 0)
-3 - web config (contains only deltas from 0).
\ No newline at end of file
+3 - web config (contains only deltas from 0).
+
+web config writes directly to 3 and messages cbrwrd about stuff.
+
+config layout is like this:
+
<?php
// C = msg key
// L = locking key
-$MESSAGE_KEY = ftok(realpath(dirname(__FILE__)), "c");
+$MESSAGE_KEY = ftok(realpath(dirname(__FILE__)), "c"); // to daemon
$LOCKING_KEY = ftok(realpath(dirname(__FILE__)), "l");
$STORE_KEY = ftok(realpath(dirname(__FILE__)), "s");
+$CONF_STORE_SIZE = 16777216; // 16M by default
-global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
+global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE;
class Comms {
function __construct()
function getConfig($type=0)
{
- global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
+ global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE;
sem_acquire($this->semres);
- $shm_space = shm_attach($STORE_KEY, 16*1024*1024);
+ $shm_space = shm_attach($STORE_KEY, $CONF_STORE_SIZE);
$config = shm_get_var($shm_space, $type);
sem_release($this->semres);
// type = 3 for web config
function putConfig($config, $type=0)
{
- global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
+ global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE;
sem_acquire($this->semres);
- $shm_space = shm_attach($STORE_KEY, 16*1024*1024);
+ $shm_space = shm_attach($STORE_KEY, $CONF_STORE_SIZE);
shm_put_var($shm_space, $type, $config);
sem_release($this->semres);
}
// here we load a config if we can find it
// there are two sides to every class, the fwd side
// and the web page site (command line is web for all intents)
- function __construct()
+ function __construct($look_for_config = false)
{
- global $AM_DAEMON;
- if($AM_DAEMON) {
+ if($look_for_config) {
$this->config_file = null;
if(file_exists("../var/fw.conf")) {
$this->config_file = realpath("../var/fw.conf");
$this->config_file = "/var/lib/fwd/fw.conf";
} else if(is_dir("../var/")) {
echo "no config file found. Will use ../var/fw.conf for now\n";
- $this->config_file = "../var/";
+ $this->config_file = "../var/fw.conf";
} else {
echo "No directory where i can create a config, bailing\n";
$this->config["status"] = "nodir";
}
}
-
-
-
}
}
- function bootHardware()
+ function loadConfig($config)
{
- $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();
-
- $mycomm = new Comms();
- $mycomm->putConfig($this->config);
- $this->boot_config = $mycomm->getConfig(1);
- }
- } else {
- $mycomm = new Comms();
- $this->config = $mycomm->getConfig(0);
- $this->boot_config = $mycomm->getConfig(1);
-
- }
+ $this->config = $config;
}
function findHardware()
return $this->config;
}
- function getBootConfig()
- {
- return $this->boot_config;
- }
-
function applyConfig()
{
global $AM_DAEMON;
return true;
}
- function loadConfigFile($file)
+ function mergeConfig($configone, $configtwo)
{
- global $AM_DAEMON;
- if(!$AM_DAEMON) return true;
+ // yep
+ }
+
+ function loadConfigFile($file=null)
+ {
+
+ if($file == null) {
+ if($this->config["status"] == "nodir") {
+ return "nodir";
+ } else $file = $this->config_file;
+ }
+
+ if(!file_exists($file)) return "noconf";
$fp = fopen($file, "r");
private $config_file;
private $config;
- private $boot_config;
};
?>
\ No newline at end of file
set_include_path(get_include_path().PATH_SEPARATOR.$adpath);
*/
+
+global $BASE_URL;
+
+
require_once("libcbfwr/config.php");
require_once("libcbfwr/comms.php");
require_once("libcbfwr/web.php");
$bodycontent = null;
$conf = new Config();
- $conf->loadConfig();
+ $comms = new Comms();
+ $conf->loadConfig($comms->getConfig(0));
$rconfig = $conf->getConfig();
if($rconfig["status"] != "conf") {
+ if($rconfig["status"] == "nodir") {
+ cbfw_startnodir();
+ return 0;
+ }
cbfw_startinstaller();
return 0;
}
<?php
}
+function cbfw_startnodir()
+{
+?>
+<html>
+<h1>Cant Run</h1>
+There is no config and no directory where i can store one. Login to the server and either create /var/run/cbfwr or <?php echo $LIB_ROOT_FS?>/var
+</html>
+<?php
+}
+
?>
\ No newline at end of file
$comms = new Comms();
-while(true) {
- sleep(5);
- $conf = $comms->getConfig();
+echo "0 - fs config";
+$conf = $comms->getConfig(0);
+print_r($conf);
- print_r($conf);
-}
+echo "1 - boot hardware";
+$conf = $comms->getConfig(1);
+print_r($conf);
+
+echo "2 - running config";
+$conf = $comms->getConfig(2);
+print_r($conf);
+
+echo "3 - client config";
+$conf = $comms->getConfig(3);
+print_r($conf);
?>
\ No newline at end of file
--- /dev/null
+<?php
+$CMD_ROOT_FS = realpath(dirname(__FILE__));
+$AM_DAEMON = false;
+
+global $CMD_ROOT_FS;
+global $AM_DAEMON;
+
+// add libglcas as if it were a path in ../libglcas
+if(file_exists("../libcbfwr")) {
+ $path = realpath($CMD_ROOT_FS."/../");
+ error_log("added cbfwr path as $path");
+ set_include_path(get_include_path().PATH_SEPARATOR.$path);
+}
+
+// include the based library
+require_once("libcbfwr/lib.php");
+
+glcas_pluginLoader();
+
+$comms = new Comms();
+
+while(true) {
+ sleep(5);
+ $conf = $comms->getConfig(0);
+
+ print_r($conf);
+}
+
+?>
\ No newline at end of file