X-Git-Url: http://git.pjr.cc/?p=CBFWR.git;a=blobdiff_plain;f=libcbfwr%2Fconfig.php;h=3720d6a30021a3e02c983a872265b1b7b9fa9b7a;hp=e63f13c378f0897f9efeab2f9312abdd85094bf3;hb=fa4d5e8e3250b981ee563f21df08c729dd3d4c57;hpb=8b23a340e9a8371cf18cf535dc3f8951c0a67241 diff --git a/libcbfwr/config.php b/libcbfwr/config.php index e63f13c..3720d6a 100644 --- a/libcbfwr/config.php +++ b/libcbfwr/config.php @@ -4,11 +4,10 @@ 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() + 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"); @@ -28,51 +27,55 @@ class Config { $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"; - 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 - } - - - } else { - // config comes from shm... we'll get there - } + } + } + + function loadConfig($config) + { + $this->config = $config; } 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/mtu")) $this->config["hardware"]["netdev"][$fname]["mtu"] = file_get_contents("/sys/class/net/$fname/mtu"); + 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 applyConfig() { global $AM_DAEMON; @@ -82,10 +85,21 @@ class Config { return true; } - function loadConfig($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"); @@ -305,7 +319,7 @@ class Config { } - function saveConfig() + function saveConfigFile($file) { global $AM_DAEMON; if(!$AM_DAEMON) return true;