This commit is contained in:
the-djmaze 2022-05-13 17:06:30 +02:00
parent 824311937a
commit b267458f7e
3 changed files with 11 additions and 21 deletions

View file

@ -762,6 +762,16 @@ class Actions
$aResult['ContactsPdoPassword'] = (string)APP_DUMMY;
$aResult['WeakPassword'] = \is_file(APP_PRIVATE_DATA.'admin_password.txt');
} else {
$passfile = APP_PRIVATE_DATA.'admin_password.txt';
$sPassword = $oConfig->Get('security', 'admin_password', '');
if (!$sPassword) {
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
Utils::saveFile($passfile, $sPassword . "\n");
// \chmod($passfile, 0600);
$oConfig->SetPassword($sPassword);
$oConfig->Save();
}
}
$aResult['LanguageAdmin'] = $this->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true);

View file

@ -661,21 +661,6 @@ class ActionsAdmin extends Actions
return $this->DefaultResponse(__FUNCTION__, true);
}
public function AppData(bool $bAdmin): array
{
$oConfig = $this->oConfig;
$passfile = APP_PRIVATE_DATA.'admin_password.txt';
$sPassword = $oConfig->Get('security', 'admin_password', '');
if (!$sPassword) {
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
Utils::saveFile($passfile, $sPassword . "\n");
// \chmod($passfile, 0600);
$oConfig->SetPassword($sPassword);
$oConfig->Save();
}
return parent::AppData($bAdmin);
}
private function setAdminAuthToken(string $sToken) : void
{
Utils::SetCookie(static::$AUTH_ADMIN_TOKEN_KEY, $sToken, 0);

View file

@ -177,11 +177,6 @@ abstract class AbstractConfig implements \JsonSerializable
return false;
}
public function IsFileExists() : bool
{
return \file_exists($this->sFile);
}
public function Load() : bool
{
if (\file_exists($this->sFile) && \is_readable($this->sFile))
@ -233,7 +228,7 @@ abstract class AbstractConfig implements \JsonSerializable
}
}
return false;
return $this->Save();
}
public function Save() : bool