load environment variables by default
authorChristian Weiske <cweiske@cweiske.de>
Tue, 28 Dec 2010 22:14:06 +0000 (23:14 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 28 Dec 2010 22:14:06 +0000 (23:14 +0100)
README
Wrt3g/Config.php
scripts/munin.php

diff --git a/README b/README
index 7475c5873386f46b23db1e456cfc05a5a842fd49..20ef34dddc3846b6dddda2385e73b7aefc3d1a44 100644 (file)
--- a/README
+++ b/README
@@ -17,17 +17,21 @@ The tools can be configured in three ways:
 1. Commandline options
    Use --help to get an overview
 
-2. User configuration file
+2. Environment variables
+
+3. User configuration file
    ~/.config/linksys-wrt3g-tools
 
-3. System configuration file
+4. System configuration file
    /etc/linksys-wrt3g-tools
 
 The configuration files are normal ini-style files with key=value
-lines. Supported configuration options in the files are
+lines.
+Supported configuration options in the files, and environment variables, are
  - host
  - user
  - password
+(lowercase)
 
 
 Dependencies
index a8232df490456365706881d0d45757a67eb9dbec..5036f7d0a2266e2f32d4e0b9f0beb8320cdef730 100644 (file)
@@ -88,9 +88,20 @@ class Wrt3g_Config
         if ($file) {
             $this->loadFromFile($file);
         }
+        //environment variables: we use lowercase options, which should
+        // not collide with the uppercase env variables like USER
+        $this->loadOptions($_SERVER);
+        //commandline options
         $this->loadOptions($options);
 
-        //commandline options
+        $this->logger->log(
+            sprintf(
+                "Configuration: %s:%s@%s",
+                $this->user, $this->password, $this->host
+            ),
+            2
+        );
+
         if (isset($options['save'])) {
             $this->save($file);
         }
index dc7d050ff862f0331e9c2a7ece7fe2185e60f6c6..0722035b74379e9359ac092a97f66f1eff3cf1d6 100755 (executable)
  */
 require_once 'Wrt3g.php';
 
-$options = array();
-foreach (array('host', 'user', 'password') as $variable) {
-    if (isset($_SERVER[$variable])) {
-        $options[$variable] = $_SERVER[$variable];
-    }
-}
-
 if (isset($argv[1]) && $argv[1] == 'autoconf') {
     $router = new Wrt3g();
-    $router->loadConfig($options);
+    $router->loadConfig();
     if ($router->config->host === null) {
         echo "no (no host configured)\n";
     } else {
@@ -81,7 +74,7 @@ TXT;
 
 try {
     $router = new Wrt3g();
-    $router->loadConfig($options);
+    $router->loadConfig();
 
     $arStatus = $router->getConnectionStatus();