|
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\ConferenceRooms; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
class ConferenceConf extends CoreConfigClass |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
protected string $description = 'confbridge.conf'; |
|
29
|
|
|
protected function generateConfigProtected(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$conf = ""; |
|
32
|
|
|
file_put_contents($this->config->path('asterisk.astetcdir') . '/confbridge.conf', $conf); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Возвращает номерной план для internal контекста. |
|
37
|
|
|
* |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
public function extensionGenInternal(): string |
|
41
|
|
|
{ |
|
42
|
|
|
$conf = ''; |
|
43
|
|
|
$data = self::getConferenceExtensions(); |
|
44
|
|
|
foreach ($data as $conference) { |
|
45
|
|
|
$conf .= "exten => {$conference},1,Goto(conference-rooms,{$conference},1)" . "\n"; |
|
46
|
|
|
} |
|
47
|
|
|
$conf .= "\n"; |
|
48
|
|
|
|
|
49
|
|
|
return $conf; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function extensionGenInternalTransfer(): string |
|
56
|
|
|
{ |
|
57
|
|
|
$conf = ''; |
|
58
|
|
|
$data = self::getConferenceExtensions(); |
|
59
|
|
|
foreach ($data as $conference) { |
|
60
|
|
|
$conf .= "exten => {$conference},1,Goto(conference-rooms,{$conference},1)" . "\n"; |
|
61
|
|
|
} |
|
62
|
|
|
$conf .= "\n"; |
|
63
|
|
|
|
|
64
|
|
|
return $conf; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Генерация дополнительных контекстов. |
|
69
|
|
|
* |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
public function extensionGenContexts(): string |
|
73
|
|
|
{ |
|
74
|
|
|
$PBXRecordCalls = $this->generalSettings['PBXRecordCalls']; |
|
75
|
|
|
// Генерация внутреннего номерного плана. |
|
76
|
|
|
$conf = "[hangup_handler_meetme]\n\n"; |
|
77
|
|
|
$conf .= "exten => s,1,AGI(cdr_connector.php,hangup_chan_meetme)\n\t"; |
|
78
|
|
|
$conf .= "same => n,return\n\n"; |
|
79
|
|
|
$conf .= "[conference-rooms] \n"; |
|
80
|
|
|
$data = $this->getConferences(); |
|
81
|
|
|
foreach ($data as $conference => $pin) { |
|
82
|
|
|
$conf .= 'exten => ' . $conference . ',1,NoOp(---)' . "\n\t"; |
|
83
|
|
|
// Если это Local канал, к примеру вызов через IVR, то попробуем корректно перенаправить вызов. |
|
84
|
|
|
// Ищем реальный канал. Local будут отправлены в hangup |
|
85
|
|
|
$conf .= 'same => n,Set(bridgePeer=${CHANNEL})' . "\n\t"; |
|
86
|
|
|
$conf .= 'same => n,Set(i=1)' . "\n\t"; |
|
87
|
|
|
$conf .= 'same => n,While($[${i} < 10])' . "\n\t"; |
|
88
|
|
|
$conf .= 'same => n,ExecIf($[ "${bridgePeer:0:5}" != "Local" ]?ExitWhile())' . "\n\t"; |
|
89
|
|
|
$conf .= 'same => n,ExecIf($[ "${bridgePeer:0:5}" == "Local" ]?Set(pl=${IF($["${CHANNEL:-1}" == "1"]?2:1)}))' . "\n\t"; |
|
90
|
|
|
$conf .= 'same => n,ExecIf($[ "${bridgePeer:0:5}" == "Local" ]?Set(bridgePeer=${IMPORT(${CUT(bridgePeer,\;,1)}\;${pl},BRIDGEPEER)}))' . "\n\t"; |
|
91
|
|
|
$conf .= 'same => n,ExecIf($[ "${bridgePeer}x" == "x" ]?ExitWhile())' . "\n\t"; |
|
92
|
|
|
$conf .= 'same => n,Set(i=$[${i} + 1])' . "\n\t"; |
|
93
|
|
|
$conf .= 'same => n,EndWhile' . "\n\t"; |
|
94
|
|
|
$conf .= 'same => n,ExecIf($[ "${bridgePeer}" != "${CHANNEL}" && "${bridgePeer:0:5}" != "Local" && "${bridgePeer}x" != "x" ]?ChannelRedirect(${bridgePeer},${CONTEXT},${EXTEN},${PRIORITY}))' . "\n\t"; |
|
95
|
|
|
|
|
96
|
|
|
// Если всеже это Local и не вышло определить оригинальный канал, то завершаем вызов. |
|
97
|
|
|
$conf .= 'same => n,ExecIf($["${CHANNEL(channeltype)}" == "Local"]?Hangup())' . "\n\t"; |
|
98
|
|
|
// В конференцию попадет лишь реальный канал PJSIP |
|
99
|
|
|
$conf .= 'same => n,AGI(cdr_connector.php,meetme_dial)' . "\n\t"; |
|
100
|
|
|
$conf .= 'same => n,Answer()' . "\n\t"; |
|
101
|
|
|
$conf .= 'same => n,AGI(/usr/www/src/Core/Asterisk/agi-bin/clean_timeout.php)' . "\n\t"; |
|
102
|
|
|
$conf .= 'same => n,Set(CHANNEL(hangup_handler_wipe)=hangup_handler_meetme,s,1)' . "\n\t"; |
|
103
|
|
|
if($PBXRecordCalls === '1'){ |
|
104
|
|
|
// Запускаем запись разговоров. |
|
105
|
|
|
$conf .= 'same => n,Set(CONFBRIDGE(bridge,record_file)=${MEETME_RECORDINGFILE}.wav)' . "\n\t"; |
|
106
|
|
|
$conf .= 'same => n,Set(CONFBRIDGE(bridge,record_file_timestamp)=false)' . "\n\t"; |
|
107
|
|
|
$conf .= 'same => n,Set(CONFBRIDGE(bridge,record_conference)=yes)' . "\n\t"; |
|
108
|
|
|
} |
|
109
|
|
|
$conf .= 'same => n,Set(CONFBRIDGE(bridge,video_mode)=follow_talker)' . "\n\t"; |
|
110
|
|
|
$conf .= 'same => n,Set(CONFBRIDGE(user,talk_detection_events)=yes)' . "\n\t"; |
|
111
|
|
|
$conf .= 'same => n,Set(CONFBRIDGE(user,quiet)=yes)' . "\n\t"; |
|
112
|
|
|
if(!empty($pin)){ |
|
113
|
|
|
$conf .= "same => n,Set(CONFBRIDGE(user,pin)=$pin)" . "\n\t"; |
|
114
|
|
|
} |
|
115
|
|
|
$conf .= 'same => n,Set(CONFBRIDGE(user,music_on_hold_when_empty)=yes)' . "\n\t"; |
|
116
|
|
|
$conf .= 'same => n,ConfBridge(${EXTEN})' . "\n\t"; |
|
117
|
|
|
$conf .= 'same => n,Hangup()' . "\n\n"; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $conf; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Генерация хинтов. |
|
125
|
|
|
* |
|
126
|
|
|
* @return string |
|
127
|
|
|
*/ |
|
128
|
|
|
public function extensionGenHints(): string |
|
129
|
|
|
{ |
|
130
|
|
|
$conf = ''; |
|
131
|
|
|
$data = self::getConferenceExtensions(); |
|
132
|
|
|
foreach ($data as $conference) { |
|
133
|
|
|
$conf .= "exten => {$conference},hint,Custom:{$conference} \n"; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return $conf; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Возвращает массив номеров конференц комнат. |
|
141
|
|
|
* @return array |
|
142
|
|
|
*/ |
|
143
|
|
|
public static function getConferenceExtensions():array |
|
144
|
|
|
{ |
|
145
|
|
|
$confExtensions = []; |
|
146
|
|
|
$filter = [ |
|
147
|
|
|
'order' => 'extension', |
|
148
|
|
|
'columns' => 'extension' |
|
149
|
|
|
]; |
|
150
|
|
|
|
|
151
|
|
|
$conferences = ConferenceRooms::find($filter)->toArray(); |
|
152
|
|
|
foreach ($conferences as $conference){ |
|
153
|
|
|
$confExtensions[] = $conference['extension']; |
|
154
|
|
|
} |
|
155
|
|
|
return $confExtensions; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Возвращает массив номеров конференц комнат. |
|
160
|
|
|
* @return array |
|
161
|
|
|
*/ |
|
162
|
|
|
private function getConferences():array |
|
163
|
|
|
{ |
|
164
|
|
|
$confExtensions = []; |
|
165
|
|
|
$filter = [ |
|
166
|
|
|
'order' => 'extension', |
|
167
|
|
|
'columns' => 'extension,pinCode' |
|
168
|
|
|
]; |
|
169
|
|
|
|
|
170
|
|
|
$conferences = ConferenceRooms::find($filter)->toArray(); |
|
171
|
|
|
foreach ($conferences as $conference){ |
|
172
|
|
|
$confExtensions[$conference['extension']] = $conference['pinCode']; |
|
173
|
|
|
} |
|
174
|
|
|
return $confExtensions; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
} |