debug option to print curl requests
[shpub.git] / src / shpub / Config.php
index 9a2370507b0ca9fb11e53e620e59792f818c6d80..c9ebb4d783655e1d1544286be2b86f47a5b612fd 100644 (file)
@@ -12,9 +12,12 @@ class Config
      */
     public $host;
 
+    public $debug = false;
+
     protected function getConfigFilePath()
     {
         if (!isset($_SERVER['HOME'])) {
+            Log::err('Cannot determine home directory');
             return false;
         }
 
@@ -64,10 +67,18 @@ class Config
                 if ($hostVal == '') {
                     continue;
                 }
-                $str .= $hostProp . '=' . $hostVal . "\n";
+                $str .= $hostProp
+                    . '=' . static::quoteIniValue($hostVal) . "\n";
             }
         }
-        file_put_contents($this->getConfigFilePath(), $str);
+        $cfgFilePath = $this->getConfigFilePath();
+        $cfgDir = dirname($cfgFilePath);
+        if (!is_dir($cfgDir)) {
+            mkdir($cfgDir, 0700);
+        }
+        file_put_contents($cfgFilePath, $str);
+        //contains sensitive data; nobody else may read that
+        chmod($cfgFilePath, 0600);
     }
 
     public function getDefaultHost()
@@ -97,5 +108,18 @@ class Config
         }
         return null;
     }
+
+    public static function quoteIniValue($val)
+    {
+        if (strpos($val, '=') === false) {
+            return $val;
+        }
+        return '"' . $val . '"';
+    }
+
+    public function setDebug($debug)
+    {
+        $this->debug = $debug;
+    }
 }
 ?>