more config and web page stuff
[CBFWR.git] / libcbfwr / config.php
index e63f13c..7bffc1d 100644 (file)
@@ -31,48 +31,85 @@ class Config {
                                        $this->config_file = "../var/";
                                } else {
                                        echo "No directory where i can create a config, bailing\n";
-                                       exit(0);
+                                       $this->config["status"] = "nodir";
                                }
                        }
                        
-                       if($this->config["status"] == "conf") {
-                               $this->loadConfig($this->config_file);
-                               print_r($this->config);
-                               $this->config = array();
-                               $this->findHardware();
-                               print_r($this->config);
-                               $this->applyConfig();
-                       } else {
-                               // we go into firstrun mode
-                       }
                        
                        
+               }
+       }
+       
+       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();
+                               
+                               $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) {
-                       if($fname != "." && $fname != ".." && $fname != "lo") {
-                               $this->config["hardware"]["netdev"][$fname]["int"] = true;
+                       if($fname != "." && $fname != ".." && $fname != "lo" && is_dir("/sys/class/net/$fname/")) {
+                               $this->config["hardware"]["netdev"][$fname]["name"] = $fname;
                                // now read drive name if you can
-                               $fp = fopen("/sys/class/net/$fname/device/uevent", "r");
-                               if($fp) while(!feof($fp)) {
-                                       $line = trim(fgets($fp));
-                                       $lpl = explode("=", $line);
-                                       if($lpl[0] == "DRIVER") {
-                                               $this->config["hardware"]["netdev"][$fname]["driver"] = $lpl[1];
+                               if(file_exists("/sys/class/net/$fname/device/uevent")) $fp = fopen("/sys/class/net/$fname/device/uevent", "r");
+                               else $fp = false;
+                               if($fp) {
+                                       while(!feof($fp)) {
+                                               $line = trim(fgets($fp));
+                                               $lpl = explode("=", $line);
+                                               if($lpl[0] == "DRIVER") {
+                                                       $this->config["hardware"]["netdev"][$fname]["driver"] = $lpl[1];
+                                               }
                                        }
+                                       fclose($fp);
                                }
-                               fclose($fp);
+                               if(file_exists("/sys/class/net/$fname/address")) $this->config["hardware"]["netdev"][$fname]["hwaddress"] = file_get_contents("/sys/class/net/$fname/address");
+                               if(file_exists("/sys/class/net/$fname/bonding")) $this->config["hardware"]["netdev"][$fname]["bonding"] = true;
+                               if(file_exists("/sys/class/net/$fname/bridge")) $this->config["hardware"]["netdev"][$fname]["bridge"] = true;
                        }
                }
        }
        
+       function getConfig()
+       {
+               return $this->config;
+       }
+       
+       function getBootConfig()
+       {
+               return $this->boot_config;
+       }
+       
        function applyConfig()
        {
                global $AM_DAEMON;
@@ -82,7 +119,7 @@ class Config {
                return true;
        }
        
-       function loadConfig($file)
+       function loadConfigFile($file)
        {
                global $AM_DAEMON;
                if(!$AM_DAEMON) return true;
@@ -305,7 +342,7 @@ class Config {
 
        }
        
-       function saveConfig()
+       function saveConfigFile($file)
        {
                global $AM_DAEMON;
                if(!$AM_DAEMON) return true;
@@ -314,6 +351,7 @@ class Config {
        
        private $config_file;
        private $config;
+       private $boot_config;
 };
 
 ?>
\ No newline at end of file