Skip to content

Commit

Permalink
#734 Доработал настройку indications.conf синхронизировал с системным…
Browse files Browse the repository at this point in the history
… языком.
  • Loading branch information
boffart committed Aug 8, 2024
1 parent 5ac99a2 commit 13f418c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 76 deletions.
24 changes: 19 additions & 5 deletions src/Core/Asterisk/Configs/IndicationConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
namespace MikoPBX\Core\Asterisk\Configs;


use MikoPBX\Common\Models\PbxSettings;
use MikoPBX\Common\Models\PbxSettingsConstants;
use MikoPBX\Core\System\Util;
use function MikoPBX\Common\Config\appPath;

Expand All @@ -32,8 +34,21 @@
*/
class IndicationConf extends AsteriskConfigClass
{
// The module hook applying priority
public int $priority = 1000;
public const LANG_ZONE_MAP = [
'ru-ru' => 'ru',
'en-en' => 'us',
'en-gb' => 'uk',
'de-de' => 'de',
'da-dk' => 'dk',
'es-es' => 'es',
'gr-gr' => 'gr',
'fr-ca' => 'fr',
'it-it' => 'it',
'ja-jp' => 'jp',
'nl-nl' => 'nl',
'pl-pl' => 'pl',
'pt-br' => 'pt',
];

protected string $description = 'indications.conf';

Expand All @@ -44,13 +59,12 @@ class IndicationConf extends AsteriskConfigClass
*/
protected function generateConfigProtected(): void
{
$country = 'ru'; // TODO: Add to the interface if it's an important option
$lang = PbxSettings::getValueByKey(PbxSettingsConstants::PBX_LANGUAGE);
$country = self::LANG_ZONE_MAP[$lang] ?? 'ru';
$filePath = appPath('src/Core/Asterisk/Configs/Samples/indications.conf.sample');
$data = file_get_contents($filePath);
$conf = str_replace('{country}', $country, $data);

// Write the configuration content to the file
Util::fileWriteContent($this->config->path('asterisk.astetcdir') . '/indications.conf', $conf);
}

}
16 changes: 1 addition & 15 deletions src/Core/Asterisk/Configs/SIPConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -1127,21 +1127,7 @@ public static function getContextId(string $name, string $port):string
*/
public static function getToneZone(array &$options, string $lang): void
{
$settings = [
'ru-ru' => 'ru',
'en-gb' => 'uk',
'de-de' => 'de',
'da-dk' => 'dk',
'es-es' => 'es',
'gr-gr' => 'gr',
'fr-ca' => 'fr',
'it-it' => 'it',
'ja-jp' => 'jp',
'nl-nl' => 'nl',
'pl-pl' => 'pl',
'pt-br' => 'pt',
];
$toneZone = $settings[$lang] ?? '';
$toneZone = IndicationConf::LANG_ZONE_MAP[$lang] ?? '';
if ( ! empty($toneZone)) {
$options['inband_progress'] = 'yes';
$options['tone_zone'] = $toneZone;
Expand Down
56 changes: 0 additions & 56 deletions src/Core/Asterisk/Configs/Samples/indications.conf.sample
Original file line number Diff line number Diff line change
@@ -1,62 +1,6 @@
;
; indications.conf
;
; Configuration file for location specific tone indications
;

;
; NOTE:
; When adding countries to this file, please keep them in alphabetical
; order according to the 2-character country codes!
;
; The [general] category is for certain global variables.
; All other categories are interpreted as location specific indications
;

[general]
country={country}


; [example]
; description = string
; The full name of your country, in English.
; ringcadence = num[,num]*
; List of durations the physical bell rings.
; dial = tonelist
; Set of tones to be played when one picks up the hook.
; busy = tonelist
; Set of tones played when the receiving end is busy.
; congestion = tonelist
; Set of tones played when there is some congestion (on the network?)
; callwaiting = tonelist
; Set of tones played when there is a call waiting in the background.
; dialrecall = tonelist
; Not well defined; many phone systems play a recall dial tone after hook
; flash.
; record = tonelist
; Set of tones played when call recording is in progress.
; info = tonelist
; Set of tones played with special information messages (e.g., "number is
; out of service")
; name = tonelist
; Every other variable will be available as a shortcut for the "PlayList" command
; but will not be used automatically by Asterisk.
;
;
; The tonelist itself is defined by a comma-separated sequence of elements.
; Each element consist of a frequency (f) with an optional duration (in ms)
; attached to it (f/duration). The frequency component may be a mixture of two
; frequencies (f1+f2) or a frequency modulated by another frequency (f1*f2).
; The implicit modulation depth is fixed at 90%, though.
; If the list element starts with a !, that element is NOT repeated,
; therefore, only if all elements start with !, the tonelist is time-limited,
; all others will repeat indefinitely.
;
; concisely:
; element = [!]freq[+|*freq2][/duration]
; tonelist = element[,element]*
;

[at]
description = Austria
ringcadence = 1000,5000
Expand Down
8 changes: 8 additions & 0 deletions src/Core/System/PBX.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
FeaturesConf,
HttpConf,
IAXConf,
IndicationConf,
ManagerConf,
ModulesConf,
MusicOnHoldConf,
Expand Down Expand Up @@ -163,6 +164,9 @@ public static function coreReload(): void
$asteriskConf = new AsteriskConf();
$asteriskConf->generateConfig();

$indicationConf = new IndicationConf();
$indicationConf->generateConfig();

$arr_out = [];
$asteriskPath = Util::which('asterisk');
Processes::mwExec("{$asteriskPath} -rx 'core reload'", $arr_out);
Expand All @@ -175,6 +179,10 @@ public static function coreRestart(): void
{
$asteriskConf = new AsteriskConf();
$asteriskConf->generateConfig();

$indicationConf = new IndicationConf();
$indicationConf->generateConfig();

$asteriskPath = Util::which('asterisk');
Processes::mwExec("{$asteriskPath} -rx 'core restart now'");
}
Expand Down

0 comments on commit 13f418c

Please sign in to comment.