mirror of
				https://github.com/billz/raspap-webgui.git
				synced 2025-03-01 10:31:47 +00:00 
			
		
		
		
	Define RASPI_CONFIG_API, update class constructor, load + createEnv
This commit is contained in:
		| @@ -4,6 +4,7 @@ define('RASPI_BRAND_TEXT', 'RaspAP'); | ||||
| define('RASPI_CONFIG', '/etc/raspap'); | ||||
| define('RASPI_CONFIG_NETWORK', RASPI_CONFIG.'/networking/defaults.json'); | ||||
| define('RASPI_CONFIG_PROVIDERS', 'config/vpn-providers.json'); | ||||
| define('RASPI_CONFIG_API', RASPI_CONFIG.'/api'); | ||||
| define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); | ||||
| define('RASPI_WIFI_AP_INTERFACE', 'wlan0'); | ||||
| define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap'); | ||||
|   | ||||
| @@ -9,6 +9,7 @@ $defaults = [ | ||||
|   'RASPI_VERSION' => '3.0.8', | ||||
|   'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/defaults.json', | ||||
|   'RASPI_CONFIG_PROVIDERS' => 'config/vpn-providers.json', | ||||
|   'RASPI_CONFIG_API' => RASPI_CONFIG.'/api', | ||||
|   'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth', | ||||
|   'RASPI_WIFI_AP_INTERFACE' => 'wlan0', | ||||
|   'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap', | ||||
|   | ||||
| @@ -17,13 +17,17 @@ class DotEnv | ||||
|     protected $envFile; | ||||
|     protected $data = []; | ||||
|  | ||||
|     public function __construct($envFile = '.env') | ||||
|     public function __construct($envFile = RASPI_CONFIG_API. '/.env') | ||||
|     { | ||||
|         $this->envFile = $envFile; | ||||
|     } | ||||
|  | ||||
|     public function load() | ||||
|     { | ||||
|         if (!file_exists($this->envFile)) { | ||||
|             $this->createEnv(); | ||||
|         } | ||||
|  | ||||
|         if (file_exists($this->envFile)) { | ||||
|             $this->data = parse_ini_file($this->envFile); | ||||
|             foreach ($this->data as $key => $value) { | ||||
| @@ -68,7 +72,19 @@ class DotEnv | ||||
|             // if key doesn't exist, append it | ||||
|             $content .= "$key=$value\n"; | ||||
|         } | ||||
|         file_put_contents($this->envFile, $content); | ||||
|         file_put_contents("/tmp/.env", $content); | ||||
|         system('sudo mv /tmp/.env '.$this->envFile, $result); | ||||
|         if ($result !== 0) { | ||||
|             throw new Exception("Unable to move .env file: ". $this->envFile); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     protected function createEnv() | ||||
|     { | ||||
|         exec('sudo touch '. escapeshellarg($this->envFile), $output, $result); | ||||
|         if ($result !== 0) { | ||||
|             throw new Exception("Unable to create .env file: ". $this->envFile); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user