@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | 92 | $max_size = 2; |
| 93 | - $log_dir = System::getLogDir() . '/asterisk/'; |
|
| 93 | + $log_dir = System::getLogDir().'/asterisk/'; |
|
| 94 | 94 | $text_config = "{$log_dir}{$f_name} { |
| 95 | 95 | nocreate |
| 96 | 96 | nocopytruncate |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | {$asteriskPath} -rx 'logger reload' > /dev/null 2> /dev/null |
| 106 | 106 | endscript |
| 107 | 107 | }"; |
| 108 | - $varEtcDir = $di->getShared('config')->path('core.varEtcDir'); |
|
| 109 | - $path_conf = $varEtcDir . '/asterisk_logrotate_' . $f_name . '.conf'; |
|
| 108 | + $varEtcDir = $di->getShared('config')->path('core.varEtcDir'); |
|
| 109 | + $path_conf = $varEtcDir.'/asterisk_logrotate_'.$f_name.'.conf'; |
|
| 110 | 110 | file_put_contents($path_conf, $text_config); |
| 111 | 111 | $mb10 = $max_size * 1024 * 1024; |
| 112 | 112 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | public static function checkCodec($name, $desc, $type): void |
| 204 | 204 | { |
| 205 | - $codec = Codecs::findFirst('name="' . $name . '"'); |
|
| 205 | + $codec = Codecs::findFirst('name="'.$name.'"'); |
|
| 206 | 206 | if ($codec === null) { |
| 207 | 207 | /** @var \MikoPBX\Common\Models\Codecs $codec_g722 */ |
| 208 | 208 | $codec = new Codecs(); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | public static function sipReload():void |
| 220 | 220 | { |
| 221 | - $di = Di::getDefault(); |
|
| 221 | + $di = Di::getDefault(); |
|
| 222 | 222 | if ($di === null) { |
| 223 | 223 | return; |
| 224 | 224 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | Util::mwExec("{$asteriskPath} -rx 'module reload acl'"); |
| 235 | 235 | Util::mwExec("{$asteriskPath} -rx 'core reload'"); |
| 236 | 236 | } else { |
| 237 | - Util::sysLogMsg('SIP RELOAD', 'Need reload asterisk',LOG_INFO, LOG_INFO); |
|
| 237 | + Util::sysLogMsg('SIP RELOAD', 'Need reload asterisk', LOG_INFO, LOG_INFO); |
|
| 238 | 238 | // Завершаем каналы. |
| 239 | 239 | Util::mwExec("{$asteriskPath} -rx 'channel request hangup all'"); |
| 240 | 240 | usleep(500000); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | public static function iaxReload(): void |
| 249 | 249 | { |
| 250 | - $iax = new IAXConf(); |
|
| 250 | + $iax = new IAXConf(); |
|
| 251 | 251 | $iax->generateConfig(); |
| 252 | 252 | $asteriskPath = Util::which('asterisk'); |
| 253 | 253 | Util::mwExec("{$asteriskPath} -rx 'iax2 reload'"); |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | 'result' => 'ERROR', |
| 305 | 305 | ]; |
| 306 | 306 | |
| 307 | - if ( ! $this->di->getShared('registry')->booting) { |
|
| 307 | + if (!$this->di->getShared('registry')->booting) { |
|
| 308 | 308 | $this->stop(); |
| 309 | 309 | } |
| 310 | 310 | /** |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | // Создание базы данных истории звонков. |
| 321 | 321 | /** @var \Phalcon\Db\Adapter\Pdo\Sqlite $connection */ |
| 322 | 322 | $connection = $this->di->get('dbCDR'); |
| 323 | - if ( ! $connection->tableExists('cdr')) { |
|
| 323 | + if (!$connection->tableExists('cdr')) { |
|
| 324 | 324 | RegisterDIServices::recreateDBConnections(); |
| 325 | 325 | } else { |
| 326 | 326 | CdrDb::checkDb(); |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | $conf .= $this->generateProvidersPj(); |
| 56 | 56 | $conf .= $this->generatePeersPj(); |
| 57 | 57 | |
| 58 | - Util::fileWriteContent($this->config->path('asterisk.astetcdir') . '/pjsip.conf', $conf); |
|
| 58 | + Util::fileWriteContent($this->config->path('asterisk.astetcdir').'/pjsip.conf', $conf); |
|
| 59 | 59 | $pjConf = '[log_mappings]'."\n". |
| 60 | 60 | 'type=log_mappings'."\n". |
| 61 | 61 | 'asterisk_error = 0'."\n". |
| 62 | 62 | 'asterisk_warning = 2'."\n". |
| 63 | 63 | 'asterisk_debug = 1,3,4,5,6'."\n\n"; |
| 64 | 64 | |
| 65 | - file_put_contents($this->config->path('asterisk.astetcdir') . '/pjproject.conf', $pjConf); |
|
| 66 | - file_put_contents($this->config->path('asterisk.astetcdir') . '/sorcery.conf', ''); |
|
| 65 | + file_put_contents($this->config->path('asterisk.astetcdir').'/pjproject.conf', $pjConf); |
|
| 66 | + file_put_contents($this->config->path('asterisk.astetcdir').'/sorcery.conf', ''); |
|
| 67 | 67 | |
| 68 | 68 | $db = new AstDB(); |
| 69 | 69 | foreach ($this->data_peers as $peer) { |
@@ -84,13 +84,13 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | private function generateGeneralPj(): string |
| 86 | 86 | { |
| 87 | - $lang = $this->generalSettings['PBXLanguage']; |
|
| 87 | + $lang = $this->generalSettings['PBXLanguage']; |
|
| 88 | 88 | [$topology, $extipaddr, $exthostname, $subnets] = $this->getTopologyData(); |
| 89 | 89 | |
| 90 | 90 | $codecs = $this->getCodecs(); |
| 91 | 91 | $codecConf = ''; |
| 92 | - foreach ($codecs as $codec){ |
|
| 93 | - $codecConf.= "allow = {$codec}\n"; |
|
| 92 | + foreach ($codecs as $codec) { |
|
| 93 | + $codecConf .= "allow = {$codec}\n"; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $pbxVersion = PbxSettings::getValueByKey('PBXVersion'); |
@@ -99,50 +99,50 @@ discard block |
||
| 99 | 99 | foreach ($subnets as $net) { |
| 100 | 100 | $natConf .= "local_net={$net}\n"; |
| 101 | 101 | } |
| 102 | - if ( ! empty($exthostname)) { |
|
| 102 | + if (!empty($exthostname)) { |
|
| 103 | 103 | $parts = explode(':', $exthostname); |
| 104 | - $natConf .= 'external_media_address=' . $parts[0] . "\n"; |
|
| 105 | - $natConf .= 'external_signaling_address=' . $parts[0] . "\n"; |
|
| 106 | - $natConf .= 'external_signaling_port=' . ($parts[1] ?? '5060'); |
|
| 107 | - } elseif ( ! empty($extipaddr)) { |
|
| 104 | + $natConf .= 'external_media_address='.$parts[0]."\n"; |
|
| 105 | + $natConf .= 'external_signaling_address='.$parts[0]."\n"; |
|
| 106 | + $natConf .= 'external_signaling_port='.($parts[1] ?? '5060'); |
|
| 107 | + } elseif (!empty($extipaddr)) { |
|
| 108 | 108 | $parts = explode(':', $extipaddr); |
| 109 | - $natConf .= 'external_media_address=' . $parts[0] . "\n"; |
|
| 110 | - $natConf .= 'external_signaling_address=' . $parts[0] . "\n"; |
|
| 111 | - $natConf .= 'external_signaling_port=' . ($parts[1] ?? '5060'); |
|
| 109 | + $natConf .= 'external_media_address='.$parts[0]."\n"; |
|
| 110 | + $natConf .= 'external_signaling_address='.$parts[0]."\n"; |
|
| 111 | + $natConf .= 'external_signaling_port='.($parts[1] ?? '5060'); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $conf = "[general] \n" . |
|
| 116 | - "disable_multi_domain=on\n" . |
|
| 117 | - "transport = udp \n\n" . |
|
| 115 | + $conf = "[general] \n". |
|
| 116 | + "disable_multi_domain=on\n". |
|
| 117 | + "transport = udp \n\n". |
|
| 118 | 118 | |
| 119 | - "[global] \n" . |
|
| 120 | - "type = global\n" . |
|
| 121 | - "endpoint_identifier_order=username,ip,anonymous\n" . |
|
| 122 | - "user_agent = mikopbx-{$pbxVersion}\n\n" . |
|
| 119 | + "[global] \n". |
|
| 120 | + "type = global\n". |
|
| 121 | + "endpoint_identifier_order=username,ip,anonymous\n". |
|
| 122 | + "user_agent = mikopbx-{$pbxVersion}\n\n". |
|
| 123 | 123 | |
| 124 | - "[anonymous]\n" . |
|
| 125 | - "type = endpoint\n" . |
|
| 124 | + "[anonymous]\n". |
|
| 125 | + "type = endpoint\n". |
|
| 126 | 126 | $codecConf. |
| 127 | 127 | "language={$lang}\n". |
| 128 | - "timers = no\n" . |
|
| 128 | + "timers = no\n". |
|
| 129 | 129 | "context = public-direct-dial\n\n". |
| 130 | 130 | |
| 131 | - "[transport-udp]\n" . |
|
| 132 | - "type = transport\n" . |
|
| 133 | - "protocol = udp\n" . |
|
| 131 | + "[transport-udp]\n". |
|
| 132 | + "type = transport\n". |
|
| 133 | + "protocol = udp\n". |
|
| 134 | 134 | "bind=0.0.0.0:{$this->generalSettings['SIPPort']}\n". |
| 135 | 135 | "{$natConf}\n\n". |
| 136 | 136 | |
| 137 | - "[transport-tcp]\n" . |
|
| 138 | - "type = transport\n" . |
|
| 139 | - "protocol = tcp\n" . |
|
| 137 | + "[transport-tcp]\n". |
|
| 138 | + "type = transport\n". |
|
| 139 | + "protocol = tcp\n". |
|
| 140 | 140 | "bind=0.0.0.0:{$this->generalSettings['SIPPort']}\n". |
| 141 | 141 | "{$natConf}\n\n". |
| 142 | 142 | ''; |
| 143 | 143 | |
| 144 | 144 | $varEtcDir = $this->config->path('core.varEtcDir'); |
| 145 | - file_put_contents($varEtcDir . '/topology_hash', md5($topology . $exthostname . $extipaddr. $this->generalSettings['SIPPort'])); |
|
| 145 | + file_put_contents($varEtcDir.'/topology_hash', md5($topology.$exthostname.$extipaddr.$this->generalSettings['SIPPort'])); |
|
| 146 | 146 | $conf .= "\n"; |
| 147 | 147 | |
| 148 | 148 | return $conf; |
@@ -154,19 +154,19 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function needAsteriskRestart():bool{ |
| 157 | - $di = Di::getDefault(); |
|
| 157 | + $di = Di::getDefault(); |
|
| 158 | 158 | if ($di === null) { |
| 159 | 159 | return false; |
| 160 | 160 | } |
| 161 | - $mikoPBXConfig = new MikoPBXConfig(); |
|
| 161 | + $mikoPBXConfig = new MikoPBXConfig(); |
|
| 162 | 162 | [$topology, $extipaddr, $exthostname] = $this->getTopologyData(); |
| 163 | 163 | |
| 164 | 164 | $generalSettings = $mikoPBXConfig->getGeneralSettings(); |
| 165 | - $now_hadh = md5($topology . $exthostname . $extipaddr. $generalSettings['SIPPort']); |
|
| 166 | - $old_hash = ''; |
|
| 165 | + $now_hadh = md5($topology.$exthostname.$extipaddr.$generalSettings['SIPPort']); |
|
| 166 | + $old_hash = ''; |
|
| 167 | 167 | $varEtcDir = $di->getShared('config')->path('core.varEtcDir'); |
| 168 | - if (file_exists($varEtcDir . '/topology_hash')) { |
|
| 169 | - $old_hash = file_get_contents($varEtcDir . '/topology_hash'); |
|
| 168 | + if (file_exists($varEtcDir.'/topology_hash')) { |
|
| 169 | + $old_hash = file_get_contents($varEtcDir.'/topology_hash'); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | return $old_hash !== $now_hadh; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | continue; |
| 190 | 190 | } |
| 191 | 191 | $sub = new SubnetCalculator($lan_config['ipaddr'], $lan_config['subnet']); |
| 192 | - $net = $sub->getNetworkPortion() . '/' . $lan_config['subnet']; |
|
| 192 | + $net = $sub->getNetworkPortion().'/'.$lan_config['subnet']; |
|
| 193 | 193 | if ($if_data['topology'] === 'private' && in_array($net, $subnets, true) === false) { |
| 194 | 194 | $subnets[] = $net; |
| 195 | 195 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $conf = ''; |
| 228 | 228 | $reg_strings = ''; |
| 229 | 229 | $prov_config = ''; |
| 230 | - if ($this->data_providers===null){ |
|
| 230 | + if ($this->data_providers === null) { |
|
| 231 | 231 | $this->getSettings(); |
| 232 | 232 | } |
| 233 | 233 | foreach ($this->data_providers as $provider) { |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | $need_register = $provider['noregister'] !== '1'; |
| 238 | 238 | if ($need_register) { |
| 239 | - $options = [ |
|
| 239 | + $options = [ |
|
| 240 | 240 | 'type' => 'auth', |
| 241 | 241 | 'username' => $provider['username'], |
| 242 | 242 | 'password' => $provider['secret'], |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | $reg_strings .= "[REG-AUTH-{$provider['uniqid']}]\n"; |
| 245 | 245 | $reg_strings .= Util::overrideConfigurationArray($options, $manual_attributes, 'registration-auth'); |
| 246 | 246 | |
| 247 | - $options = [ |
|
| 247 | + $options = [ |
|
| 248 | 248 | 'type' => 'registration', |
| 249 | 249 | // 'transport' => 'transport-udp', |
| 250 | 250 | 'outbound_auth' => "REG-AUTH-{$provider['uniqid']}", |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | if ('1' !== $provider['receive_calls_without_auth']) { |
| 265 | - $options = [ |
|
| 265 | + $options = [ |
|
| 266 | 266 | 'type' => 'auth', |
| 267 | 267 | 'username' => $provider['username'], |
| 268 | 268 | 'password' => $provider['secret'], |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | $defaultuser = (trim($provider['defaultuser']) === '') ? $provider['username'] : $provider['defaultuser']; |
| 275 | - if ( ! empty($defaultuser) && '1' !== $provider['receive_calls_without_auth']) { |
|
| 275 | + if (!empty($defaultuser) && '1' !== $provider['receive_calls_without_auth']) { |
|
| 276 | 276 | $contact = "sip:$defaultuser@{$provider['host']}:{$port}"; |
| 277 | 277 | } else { |
| 278 | 278 | $contact = "sip:{$provider['host']}:{$port}"; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | 'minimum_expiration' => $this->generalSettings['SIPMinExpiry'], |
| 287 | 287 | 'default_expiration' => $this->generalSettings['SIPDefaultExpiry'], |
| 288 | 288 | ]; |
| 289 | - if($provider['qualify'] === '1'){ |
|
| 289 | + if ($provider['qualify'] === '1') { |
|
| 290 | 290 | $options['qualify_frequency'] = $provider['qualifyfreq']; |
| 291 | 291 | $options['qualify_timeout'] = '3.0'; |
| 292 | 292 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | $prov_config .= "[{$provider['uniqid']}]\n"; |
| 295 | 295 | $prov_config .= Util::overrideConfigurationArray($options, $manual_attributes, 'aor'); |
| 296 | 296 | |
| 297 | - $options = [ |
|
| 297 | + $options = [ |
|
| 298 | 298 | 'type' => 'identify', |
| 299 | 299 | 'endpoint' => $provider['uniqid'], |
| 300 | 300 | 'match' => $provider['host'], |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | */ |
| 356 | 356 | public function generatePeersPj(): string |
| 357 | 357 | { |
| 358 | - if ($this->data_peers===null){ |
|
| 358 | + if ($this->data_peers === null) { |
|
| 359 | 359 | $this->getSettings(); |
| 360 | 360 | } |
| 361 | 361 | $lang = $this->generalSettings['PBXLanguage']; |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | $language = (trim($language) === '') ? 'en-en' : $language; |
| 370 | 370 | |
| 371 | 371 | $calleridname = (trim($peer['calleridname']) === '') ? $peer['extension'] : $peer['calleridname']; |
| 372 | - $busylevel = (trim($peer['busylevel']) === '') ? '1' : '' . $peer['busylevel']; |
|
| 372 | + $busylevel = (trim($peer['busylevel']) === '') ? '1' : ''.$peer['busylevel']; |
|
| 373 | 373 | |
| 374 | 374 | $options = [ |
| 375 | 375 | 'type' => 'auth', |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | 'conditions'=>'disabled="0"', |
| 522 | 522 | 'order' => 'type, priority', |
| 523 | 523 | ]; |
| 524 | - $codecs = Codecs::find($filter); |
|
| 524 | + $codecs = Codecs::find($filter); |
|
| 525 | 525 | foreach ($codecs as $codec_data) { |
| 526 | 526 | $arr_codecs[] = $codec_data->name; |
| 527 | 527 | } |
@@ -551,8 +551,8 @@ discard block |
||
| 551 | 551 | // Получим используемые кодеки. |
| 552 | 552 | $arr_data['codecs'] = $this->getCodecs(); |
| 553 | 553 | |
| 554 | - $context_id = preg_replace("/[^a-z\d]/iu", '', $sip_peer->host . $sip_peer->port); |
|
| 555 | - if ( ! isset($this->contexts_data[$context_id])) { |
|
| 554 | + $context_id = preg_replace("/[^a-z\d]/iu", '', $sip_peer->host.$sip_peer->port); |
|
| 555 | + if (!isset($this->contexts_data[$context_id])) { |
|
| 556 | 556 | $this->contexts_data[$context_id] = []; |
| 557 | 557 | } |
| 558 | 558 | $this->contexts_data[$context_id][$sip_peer->uniqid] = $sip_peer->username; |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | */ |
| 572 | 572 | private function getOutRoutes(): array |
| 573 | 573 | { |
| 574 | - if ($this->data_peers===null){ |
|
| 574 | + if ($this->data_peers === null) { |
|
| 575 | 575 | $this->getSettings(); |
| 576 | 576 | } |
| 577 | 577 | /** @var \MikoPBX\Common\Models\OutgoingRoutingTable $rout */ |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | */ |
| 607 | 607 | public function extensionGenContexts(): string |
| 608 | 608 | { |
| 609 | - if ($this->data_peers===null){ |
|
| 609 | + if ($this->data_peers === null) { |
|
| 610 | 610 | $this->getSettings(); |
| 611 | 611 | } |
| 612 | 612 | // Генерация внутреннего номерного плана. |
@@ -624,8 +624,8 @@ discard block |
||
| 624 | 624 | $contexts_data = $this->contexts_data[$provider['context_id']]; |
| 625 | 625 | if (count($contexts_data) === 1) { |
| 626 | 626 | $conf .= ExtensionsConf::generateIncomingContextPeers($provider['uniqid'], $provider['username'], ''); |
| 627 | - } elseif ( ! in_array($provider['context_id'], $contexts, true)) { |
|
| 628 | - $conf .= ExtensionsConf::generateIncomingContextPeers( |
|
| 627 | + } elseif (!in_array($provider['context_id'], $contexts, true)) { |
|
| 628 | + $conf .= ExtensionsConf::generateIncomingContextPeers( |
|
| 629 | 629 | $contexts_data, |
| 630 | 630 | null, |
| 631 | 631 | $provider['context_id'] |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | */ |
| 645 | 645 | public function extensionGenHints(): string |
| 646 | 646 | { |
| 647 | - if ($this->data_peers===null){ |
|
| 647 | + if ($this->data_peers === null) { |
|
| 648 | 648 | $this->getSettings(); |
| 649 | 649 | } |
| 650 | 650 | $conf = ''; |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | |
| 658 | 658 | public function extensionGenInternal(): string |
| 659 | 659 | { |
| 660 | - if ($this->data_peers===null){ |
|
| 660 | + if ($this->data_peers === null) { |
|
| 661 | 661 | $this->getSettings(); |
| 662 | 662 | } |
| 663 | 663 | // Генерация внутреннего номерного плана. |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | |
| 673 | 673 | public function extensionGenInternalTransfer(): string |
| 674 | 674 | { |
| 675 | - if ($this->data_peers===null){ |
|
| 675 | + if ($this->data_peers === null) { |
|
| 676 | 676 | $this->getSettings(); |
| 677 | 677 | } |
| 678 | 678 | // Генерация внутреннего номерного плана. |