|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* MikoPBX - free phone system for small business |
|
4
|
|
|
* Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace MikoPBX\Core\Asterisk\Configs; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
use MikoPBX\Common\Models\NetworkFilters; |
|
24
|
|
|
use MikoPBX\Common\Models\Sip; |
|
25
|
|
|
use MikoPBX\Core\System\Util; |
|
26
|
|
|
|
|
27
|
|
|
class AclConf extends CoreConfigClass |
|
28
|
|
|
{ |
|
29
|
|
|
protected string $description = 'acl.conf'; |
|
30
|
|
|
protected array $data_peers; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getDependenceModels(): array |
|
37
|
|
|
{ |
|
38
|
|
|
return [Sip::class, NetworkFilters::class]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Получение настроек. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getSettings(): void |
|
45
|
|
|
{ |
|
46
|
|
|
// Настройки для текущего класса. |
|
47
|
|
|
$this->data_peers = $this->getPeers(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Получение данных по SIP пирам. |
|
52
|
|
|
* |
|
53
|
|
|
* @return array |
|
54
|
|
|
*/ |
|
55
|
|
|
private function getPeers(): array |
|
56
|
|
|
{ |
|
57
|
|
|
$data = []; |
|
58
|
|
|
$db_data = Sip::find("type = 'peer' AND ( disabled <> '1')"); |
|
59
|
|
|
foreach ($db_data as $sip_peer) { |
|
60
|
|
|
$arr_data = $sip_peer->toArray(); |
|
61
|
|
|
$network_filter = null; |
|
62
|
|
|
if (null != $sip_peer->networkfilterid) { |
|
63
|
|
|
$network_filter = NetworkFilters::findFirst($sip_peer->networkfilterid); |
|
64
|
|
|
} |
|
65
|
|
|
$arr_data['permit'] = ($network_filter === null) ? '' : $network_filter->permit; |
|
66
|
|
|
$arr_data['deny'] = ($network_filter === null) ? '' : $network_filter->deny; |
|
67
|
|
|
|
|
68
|
|
|
$data[] = $arr_data; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $data; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected function generateConfigProtected(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$conf_acl = ''; |
|
77
|
|
|
foreach ($this->data_peers as $peer) { |
|
78
|
|
|
$manual_attributes = Util::parseIniSettings($peer['manualattributes'] ?? ''); |
|
79
|
|
|
|
|
80
|
|
|
$deny = (trim($peer['deny']) === '') ? '0.0.0.0/0.0.0.0' : $peer['deny']; |
|
81
|
|
|
$permit = (trim($peer['permit']) === '') ? '0.0.0.0/0.0.0.0' : $peer['permit']; |
|
82
|
|
|
|
|
83
|
|
|
$options = [ |
|
84
|
|
|
'deny' => $deny, |
|
85
|
|
|
'permit' => $permit, |
|
86
|
|
|
]; |
|
87
|
|
|
$conf_acl .= "[acl_{$peer['extension']}] \n"; |
|
88
|
|
|
$conf_acl .= Util::overrideConfigurationArray($options, $manual_attributes, 'acl'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
Util::fileWriteContent($this->config->path('asterisk.astetcdir') . '/acl.conf', $conf_acl); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
} |