Skip to content

Commit

Permalink
#739 предусмотрел ситуацию, когда домен разный резолвится в один и то…
Browse files Browse the repository at this point in the history
…т же IP.
  • Loading branch information
boffart committed Jun 17, 2024
1 parent 875b3a2 commit f1c9cd9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Core/Asterisk/Configs/ExtensionsOutWorkTimeConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ public function extensionGenContexts(): string
return $this->conf;
}


/**
*
* @return string Set global vars.
*/
public function extensionGlobals(): string
{
$configs = '';
$dbData = Sip::find("type = 'friend' AND ( disabled <> '1')");
foreach ($dbData as $sipPeer) {
$context_id = SIPConf::getContextId($sipPeer->host, $sipPeer->port);
$configs .= "CONTEXT_ID_$sipPeer->uniqid=$context_id".PHP_EOL;
}
return $configs;
}

/**
* Generates the customized incoming context for a specific route before dialing system.
*
Expand All @@ -101,6 +117,7 @@ public function generateIncomingRoutBeforeDialSystem(string $rout_number): strin
// Check the schedule for incoming external calls.
return 'same => n,NoOp(contextID: ${contextID})' . PHP_EOL . "\t" .
'same => n,ExecIf($["${CONTEXT}" == "public-direct-dial"]?Set(contextID=none-incoming))' . PHP_EOL . "\t" .
'same => n,ExecIf($["${contextID}x" == "x"]?Set(contextID=${CONTEXT_ID_${providerID}}))' . PHP_EOL . "\t" .
'same => n,ExecIf($["${contextID}x" == "x"]?Set(contextID=${CONTEXT}))' . PHP_EOL . "\t" .
'same => n,GosubIf($["${IGNORE_TIME}" != "1"]?' . self::OUT_WORK_TIME_CONTEXT . ',${EXTEN},1)' . PHP_EOL . "\t";
}
Expand Down
9 changes: 7 additions & 2 deletions src/Core/Asterisk/Configs/SIPConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ private function generateProviderEndpoint(array $provider, array $manual_attribu

// Add configuration section header
$conf .= "[{$provider['uniqid']}]".PHP_EOL;
$conf .= 'set_var=contextID='.$provider['context_id'].PHP_EOL;
$conf .= 'set_var=providerID='.$provider['uniqid'].PHP_EOL;

// Generate and add configuration options
$conf .= Util::overrideConfigurationArray($options, $manual_attributes, 'endpoint');
Expand All @@ -1107,7 +1107,12 @@ private function generateProviderEndpoint(array $provider, array $manual_attribu
*/
public static function getContextId(string $name, string $port):string
{
return preg_replace("/[^a-z\d]/iu", '', $name.$port).'-incoming';
if (filter_var($name, FILTER_VALIDATE_IP)) {
$nameNew = $name;
}else{
$nameNew = gethostbyname($name);
}
return preg_replace("/[^a-z\d]/iu", '', $nameNew.$port).'-incoming';
}

/**
Expand Down

0 comments on commit f1c9cd9

Please sign in to comment.