X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/d573cd45cde3631ed5bdfd51e35084c1602cebc8..a460539284aca97046cfd0b46d2c6dd832b43c39:/src/shpub/Config.php diff --git a/src/shpub/Config.php b/src/shpub/Config.php index 9a23705..f3ca543 100644 --- a/src/shpub/Config.php +++ b/src/shpub/Config.php @@ -12,9 +12,14 @@ class Config */ public $host; + public $debug = false; + + public $dryRun = false; + protected function getConfigFilePath() { if (!isset($_SERVER['HOME'])) { + Log::err('Cannot determine home directory'); return false; } @@ -64,10 +69,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() @@ -77,10 +90,10 @@ class Config } foreach ($this->hosts as $key => $host) { if ($host->default) { - return $host; + return $key; } } - + reset($this->hosts); return key($this->hosts); } @@ -97,5 +110,23 @@ class Config } return null; } + + public static function quoteIniValue($val) + { + if (strpos($val, '=') === false) { + return $val; + } + return '"' . $val . '"'; + } + + public function setDebug($debug) + { + $this->debug = $debug; + } + + public function setDryRun($dryRun) + { + $this->dryRun = $dryRun; + } } ?>