mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-21 23:20:22 +00:00
Define RASPI_CONFIG_API, update class constructor, load + createEnv
This commit is contained in:
parent
282b839f45
commit
5d8fed824a
3 changed files with 20 additions and 2 deletions
|
@ -4,6 +4,7 @@ define('RASPI_BRAND_TEXT', 'RaspAP');
|
||||||
define('RASPI_CONFIG', '/etc/raspap');
|
define('RASPI_CONFIG', '/etc/raspap');
|
||||||
define('RASPI_CONFIG_NETWORK', RASPI_CONFIG.'/networking/defaults.json');
|
define('RASPI_CONFIG_NETWORK', RASPI_CONFIG.'/networking/defaults.json');
|
||||||
define('RASPI_CONFIG_PROVIDERS', 'config/vpn-providers.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_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth');
|
||||||
define('RASPI_WIFI_AP_INTERFACE', 'wlan0');
|
define('RASPI_WIFI_AP_INTERFACE', 'wlan0');
|
||||||
define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap');
|
define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap');
|
||||||
|
|
|
@ -9,6 +9,7 @@ $defaults = [
|
||||||
'RASPI_VERSION' => '3.0.8',
|
'RASPI_VERSION' => '3.0.8',
|
||||||
'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/defaults.json',
|
'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/defaults.json',
|
||||||
'RASPI_CONFIG_PROVIDERS' => 'config/vpn-providers.json',
|
'RASPI_CONFIG_PROVIDERS' => 'config/vpn-providers.json',
|
||||||
|
'RASPI_CONFIG_API' => RASPI_CONFIG.'/api',
|
||||||
'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth',
|
'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth',
|
||||||
'RASPI_WIFI_AP_INTERFACE' => 'wlan0',
|
'RASPI_WIFI_AP_INTERFACE' => 'wlan0',
|
||||||
'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap',
|
'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap',
|
||||||
|
|
|
@ -17,13 +17,17 @@ class DotEnv
|
||||||
protected $envFile;
|
protected $envFile;
|
||||||
protected $data = [];
|
protected $data = [];
|
||||||
|
|
||||||
public function __construct($envFile = '.env')
|
public function __construct($envFile = RASPI_CONFIG_API. '/.env')
|
||||||
{
|
{
|
||||||
$this->envFile = $envFile;
|
$this->envFile = $envFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load()
|
public function load()
|
||||||
{
|
{
|
||||||
|
if (!file_exists($this->envFile)) {
|
||||||
|
$this->createEnv();
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists($this->envFile)) {
|
if (file_exists($this->envFile)) {
|
||||||
$this->data = parse_ini_file($this->envFile);
|
$this->data = parse_ini_file($this->envFile);
|
||||||
foreach ($this->data as $key => $value) {
|
foreach ($this->data as $key => $value) {
|
||||||
|
@ -68,7 +72,19 @@ class DotEnv
|
||||||
// if key doesn't exist, append it
|
// if key doesn't exist, append it
|
||||||
$content .= "$key=$value\n";
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue