diff --git a/src/Service/Config.php b/src/Service/Config.php index 4fd8cc7..88944bb 100644 --- a/src/Service/Config.php +++ b/src/Service/Config.php @@ -9,19 +9,27 @@ namespace Pfatt\Service; */ class Config { - private string $pingHost = '8.8.8.8'; + private string $pingHost; private string $ontInterface; private string $rgInterface; private string $rgEthernetMac; - public function __construct(string $ontInterface, string $rgInterface, string $rgEthernetMac, ?string $pingHost = null) + public function __construct() { - $this->ontInterface = $ontInterface; - $this->rgInterface = $rgInterface; - $this->rgEthernetMac = $rgEthernetMac; - if (isset($pingHost)) { - $this->pingHost = $pingHost; + if (file_exists('/etc/pfatt.ini')) { + $configs = parse_ini_file('/etc/pfatt.ini'); + if ($configs === false) { + // @todo warn something is wrong with the ini file. + $configs = []; + } + } else { + // @todo warn this could be a problem. + $configs = []; } + $this->pingHost = (string) ($configs['ping_host'] ?? '8.8.8.8'); + $this->ontInterface = (string) ($configs['ont_if'] ?? ''); + $this->rgInterface = (string) ($configs['rg_if'] ?? ''); + $this->rgEthernetMac = (string) ($configs['rg_mac'] ?? ''); } /**