Skip to content

Commit

Permalink
#834 Добавил очистку кэш. Поправил генерацию конфигов при изменении о…
Browse files Browse the repository at this point in the history
…бщих настроек AJAM AMI
  • Loading branch information
boffart committed Nov 14, 2024
1 parent ea07641 commit e245ef4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/Common/Models/PbxSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ public static function setValue(string $key, string $value, array &$messages = [
$result = $record->save();
if (!$result) {
$messages[] = $record->getMessages();
}else{
// Clean the cache in redis
try {
$redis = Di::GetDefault()->getShared(ManagedCacheProvider::SERVICE_NAME);
foreach (['getValueByKey', 'getAllPbxSettings'] as $index){
$cacheKey = ModelsBase::makeCacheKey(PbxSettings::class, $index);
$redis->set($cacheKey, '', 1);
}
} catch (\Throwable $e) {
CriticalErrorsHandler::handleException($e);
}
}
return $result;
}
Expand Down
33 changes: 17 additions & 16 deletions src/Core/Asterisk/Configs/HttpConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,32 @@ class HttpConf extends AsteriskConfigClass
*/
protected function generateConfigProtected(): void
{
$enabled = ($this->generalSettings[PbxSettings::AJAM_ENABLED] === '1') ? 'yes' : 'no';
$conf = "[general]\n" .
"enabled=$enabled\n" .
"bindaddr=0.0.0.0\n" .
"bindport={$this->generalSettings[PbxSettings::AJAM_PORT]}\n" .
"prefix=asterisk\n" .
"enablestatic=yes\n\n";

$isEnable = intval($this->generalSettings[PbxSettings::AJAM_ENABLED]) === 1;
$enabled = ($isEnable) ? 'yes' : 'no';
$conf = "[general]".PHP_EOL .
"enabled=$enabled".PHP_EOL .
"bindaddr=0.0.0.0".PHP_EOL .
"bindport={$this->generalSettings[PbxSettings::AJAM_PORT]}".PHP_EOL .
"prefix=asterisk".PHP_EOL .
"enablestatic=yes".PHP_EOL.PHP_EOL;
if ( ! empty($this->generalSettings[PbxSettings::AJAM_PORT_TLS])) {
$keys_dir = '/etc/asterisk/keys';
Util::mwMkdir($keys_dir);
$WEBHTTPSPublicKey = $this->generalSettings[PbxSettings::WEB_HTTPS_PUBLIC_KEY];
$WEBHTTPSPrivateKey = $this->generalSettings[PbxSettings::WEB_HTTPS_PRIVATE_KEY];
$publicKey = $this->generalSettings[PbxSettings::WEB_HTTPS_PUBLIC_KEY];
$privateKey = $this->generalSettings[PbxSettings::WEB_HTTPS_PRIVATE_KEY];

if ( ! empty($WEBHTTPSPublicKey) && ! empty($WEBHTTPSPrivateKey)) {
$s_data = "$WEBHTTPSPublicKey\n$WEBHTTPSPrivateKey";
if ( ! empty($publicKey) && ! empty($privateKey)) {
$s_data = "".$publicKey.PHP_EOL.
$privateKey;
} else {
// Generate SSL certificate
$data = Util::generateSslCert();
$s_data = implode("\n", $data);
}
$conf .= "tlsenable=$enabled\n" .
"tlsbindaddr=0.0.0.0:{$this->generalSettings[PbxSettings::AJAM_PORT_TLS]}\n" .
"tlscertfile=$keys_dir/ajam.pem\n" .
"tlsprivatekey=$keys_dir/ajam.pem\n";
$conf .= "tlsenable=$enabled" . PHP_EOL.
"tlsbindaddr=0.0.0.0:{$this->generalSettings[PbxSettings::AJAM_PORT_TLS]}".PHP_EOL.
"tlscertfile=$keys_dir/ajam.pem".PHP_EOL.
"tlsprivatekey=$keys_dir/ajam.pem".PHP_EOL;
Util::fileWriteContent("$keys_dir/ajam.pem", $s_data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ public static function getDependencyTable(): array
$tables[] = [
'keys' => [
PbxSettings::AMI_PORT,
PbxSettings::AMI_ENABLED,
PbxSettings::AJAM_PORT,
PbxSettings::AJAM_PORT_TLS,
PbxSettings::AJAM_ENABLED,
],
'actions' => [
ReloadManagerAction::class,
Expand Down

0 comments on commit e245ef4

Please sign in to comment.