|
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
|
|
|
use MikoPBX\Common\Models\PbxSettings; |
|
23
|
|
|
use MikoPBX\Core\System\Util; |
|
24
|
|
|
|
|
25
|
|
|
class ResParkingConf extends CoreConfigClass |
|
26
|
|
|
{ |
|
27
|
|
|
protected $ParkingExt; |
|
28
|
|
|
protected $ParkingStartSlot; |
|
29
|
|
|
protected $ParkingEndSlot; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
protected string $description = 'res_parking.conf'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* |
|
36
|
|
|
* @return array |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getDependenceModels(): array |
|
39
|
|
|
{ |
|
40
|
|
|
return [PbxSettings::class]; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* ResParkingConf constructor. |
|
45
|
|
|
* |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(){ |
|
48
|
|
|
parent::__construct(); |
|
49
|
|
|
// Вызов "getSettings" приемлем, так как идет работа с инициализированной переменной generalSettings. |
|
50
|
|
|
$this->getSettings(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function generateConfigProtected(): void |
|
54
|
|
|
{ |
|
55
|
|
|
// Генерация конфигурационных файлов. |
|
56
|
|
|
$conf = "[general] \n" . |
|
57
|
|
|
"parkeddynamic = yes \n\n" . |
|
58
|
|
|
"[default] \n" . |
|
59
|
|
|
"context => parked-calls \n" . |
|
60
|
|
|
"parkedcallreparking = caller\n" . |
|
61
|
|
|
"parkedcalltransfers = caller\n" . |
|
62
|
|
|
"parkext => {$this->ParkingExt} \n" . |
|
63
|
|
|
"findslot => next\n" . |
|
64
|
|
|
"comebacktoorigin=no\n" . |
|
65
|
|
|
"comebackcontext = parked-calls-timeout\n" . |
|
66
|
|
|
"parkpos => {$this->ParkingStartSlot}-{$this->ParkingEndSlot} \n\n"; |
|
67
|
|
|
file_put_contents($this->config->path('asterisk.astetcdir') . '/res_parking.conf', $conf); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Функция позволяет получить активные каналы. |
|
73
|
|
|
* Возвращает ассоциативный массив. Ключ - Linkedid, значение - массив каналов. |
|
74
|
|
|
* |
|
75
|
|
|
* @param ?string $EXTEN |
|
76
|
|
|
* |
|
77
|
|
|
* @return null | array |
|
78
|
|
|
*/ |
|
79
|
|
|
public static function getParkslotData(?string $EXTEN = null) : ?array |
|
80
|
|
|
{ |
|
81
|
|
|
$ParkeeChannel = null; |
|
82
|
|
|
$am = Util::getAstManager('off'); |
|
83
|
|
|
$res = $am->ParkedCalls('default'); |
|
84
|
|
|
if (count($res['data']) === 0) { |
|
85
|
|
|
return null; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
foreach ($res['data']['ParkedCall'] as $park_row) { |
|
89
|
|
|
if ($park_row['ParkingSpace'] === $EXTEN || $EXTEN === null) { |
|
90
|
|
|
$var_data = $am->GetVar($park_row['ParkeeChannel'], 'pt1c_is_dst'); |
|
91
|
|
|
$park_row['pt1c_is_dst'] = ($var_data["Value"] === '1'); |
|
92
|
|
|
$ParkeeChannel = $park_row; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $ParkeeChannel; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Получение настроек. |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getSettings(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->ParkingExt = $this->generalSettings['PBXCallParkingExt']; |
|
105
|
|
|
$this->ParkingStartSlot = (int)$this->generalSettings['PBXCallParkingStartSlot']; |
|
106
|
|
|
$this->ParkingEndSlot = (int)$this->generalSettings['PBXCallParkingEndSlot']; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Возвращает включения в контекст internal |
|
111
|
|
|
* |
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getIncludeInternal(): string |
|
115
|
|
|
{ |
|
116
|
|
|
return ''; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Возвращает включения в контекст internal-transfer |
|
121
|
|
|
* |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getIncludeInternalTransfer(): string |
|
125
|
|
|
{ |
|
126
|
|
|
// Генерация внутреннего номерного плана. |
|
127
|
|
|
return 'exten => ' . $this->ParkingExt . ',1,Goto(parked-calls,${EXTEN},1)' . "\n"; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Генерация дополнительных контекстов. |
|
132
|
|
|
* |
|
133
|
|
|
* @return string |
|
134
|
|
|
*/ |
|
135
|
|
|
public function extensionGenContexts(): string |
|
136
|
|
|
{ |
|
137
|
|
|
// Генерация внутреннего номерного плана. |
|
138
|
|
|
$conf = ''; |
|
139
|
|
|
$conf .= "[parked-calls]\n"; |
|
140
|
|
|
$conf .= "exten => _X!,1,AGI(cdr_connector.php,unpark_call)\n\t"; |
|
141
|
|
|
$conf .= 'same => n,ExecIf($["${pt1c_PARK_CHAN}x" == "x"]?Hangup())' . "\n\t"; |
|
142
|
|
|
$conf .= 'same => n,Bridge(${pt1c_PARK_CHAN},kKTt)' . "\n\t"; |
|
143
|
|
|
$conf .= 'same => n,Hangup()' . "\n\n"; |
|
144
|
|
|
|
|
145
|
|
|
$conf .= "[parked-calls-timeout]\n"; |
|
146
|
|
|
$conf .= "exten => s,1,NoOp(This is all that happens to parked calls if they time out.)\n\t"; |
|
147
|
|
|
$conf .= 'same => n,Set(FROM_PEER=${EMPTYVAR})' . "\n\t"; |
|
148
|
|
|
$conf .= 'same => n,AGI(cdr_connector.php,unpark_call_timeout)' . "\n\t"; |
|
149
|
|
|
$conf .= 'same => n,Goto(internal,${CUT(PARKER,/,2)},1)' . "\n\t"; |
|
150
|
|
|
$conf .= 'same => n,Hangup()' . "\n\n"; |
|
151
|
|
|
|
|
152
|
|
|
return $conf; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Возвращает номерной план для internal контекста. |
|
157
|
|
|
* |
|
158
|
|
|
* @return string |
|
159
|
|
|
*/ |
|
160
|
|
|
public function extensionGenInternal(): string |
|
161
|
|
|
{ |
|
162
|
|
|
$conf = ''; |
|
163
|
|
|
for ($ext = $this->ParkingStartSlot; $ext <= $this->ParkingEndSlot; $ext++) { |
|
164
|
|
|
$conf .= 'exten => ' . $ext . ',1,Goto(parked-calls,${EXTEN},1)' . "\n"; |
|
165
|
|
|
} |
|
166
|
|
|
$conf .= "\n"; |
|
167
|
|
|
|
|
168
|
|
|
return $conf; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Дополнительные параметры для секции global. |
|
173
|
|
|
* |
|
174
|
|
|
* @return string |
|
175
|
|
|
*/ |
|
176
|
|
|
public function extensionGlobals(): string |
|
177
|
|
|
{ |
|
178
|
|
|
return "PARKING_DURATION=50\n"; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Дополнительные коды feature.conf |
|
183
|
|
|
* |
|
184
|
|
|
* @return string |
|
185
|
|
|
*/ |
|
186
|
|
|
public function getFeatureMap(): string |
|
187
|
|
|
{ |
|
188
|
|
|
return "parkcall => *2 \n"; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|