some config work
authorpaulr <me@pjr.cc>
Mon, 19 Sep 2011 14:24:02 +0000 (00:24 +1000)
committerpaulr <me@pjr.cc>
Mon, 19 Sep 2011 14:24:02 +0000 (00:24 +1000)
bin/cbfwrd.php
etc/config.php [deleted file]
libcbfwr/comms.php
libcbfwr/config.php
www/index.php

index 23897e1..6f49afe 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 $CMD_ROOT_FS = realpath(dirname(__FILE__));
+$AM_DAEMON = true;
 
 global $CMD_ROOT_FS;
+global $AM_DAEMON;
 
 // add libglcas as if it were a path in ../libglcas
 if(file_exists("../libcbfwr")) {
@@ -16,4 +18,6 @@ require_once("libcbfwr/lib.php");
 glcas_pluginLoader();
 
 error_log("CBFWRD starting");
+
+$config = new Config();
 ?>
\ No newline at end of file
diff --git a/etc/config.php b/etc/config.php
deleted file mode 100644 (file)
index e69de29..0000000
index 0098db1..808d1f8 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 // C = msg key
 // L = locking key
-$message_key = ftok(realpath(dirname(__FILE__)), "c");
-$locking_key = ftok(realpath(dirname(__FILE__)), "l");
-$store_key = ftok(realpath(dirname(__FILE__)), "s");
+$MESSAGE_KEY = ftok(realpath(dirname(__FILE__)), "c");
+$LOCKING_KEY = ftok(realpath(dirname(__FILE__)), "l");
+$STORE_KEY = ftok(realpath(dirname(__FILE__)), "s");
 
-echo "comms key: $message_key, $locking_key, $store_key\n";
+global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
 
 ?>
\ No newline at end of file
index 67c94a5..c0873b5 100644 (file)
@@ -1,2 +1,43 @@
 <?php
+
+class Config {
+       // 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()
+       {
+               global $AM_DAEMON;
+               
+               if($AM_DAEMON) {
+                       $this->config_file = null;
+                       if(file_exists("../var/fw.conf")) {
+                               $this->config_file = realpath("../var/fw.conf");
+                       }
+                       if(file_exists("/var/lib/fwd/fw.conf")) {
+                               $this->config_file = "/var/lib/fwd/fw.conf";
+                       }
+                       
+                       if($this->config_file == null) {
+                               $this->config["status"] = "noconf";
+                               if(is_dir("/var/lib/fwd/")) {
+                                       echo "no config file found. Will use ../var/fw.conf for now\n";
+                                       $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/";
+                               } else {
+                                       echo "No directory where i can create a config, bailing\n";
+                                       exit(0);
+                               }
+                       }
+               } else {
+                       // config comes from shm... we'll get there
+               }       
+       }
+       
+       
+       private $config_file;
+       private $config;
+};
+
 ?>
\ No newline at end of file
index dd6163c..33f5ab2 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 $WEB_ROOT_FS = realpath(dirname(__FILE__));
 $BASE_URL = dirname($_SERVER["PHP_SELF"]);
+$AM_DAEMON=false;
 
-global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL, $AM_DAEMON;
 
 // add libglcas as if it were a path in ../libglcas
 if(file_exists("../libcbfwr")) {