1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* MikoPBX - free phone system for small business |
4
|
|
|
* Copyright (C) 2017-2021 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\SoundFiles; |
23
|
|
|
use MikoPBX\Core\System\Util; |
24
|
|
|
|
25
|
|
|
class ExtensionsAnnounceRecording extends CoreConfigClass |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Prepares additional contexts sections in the extensions.conf file |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function extensionGenContexts(): string |
33
|
|
|
{ |
34
|
|
|
// |
35
|
|
|
return '[annonce-spy]' . PHP_EOL . |
36
|
|
|
'exten => _.!,1,ExecIf($[ "${EXTEN}" == "h" ]?Hangup()' . PHP_EOL . "\t" . |
37
|
|
|
'same => n,ExecIf($["${CHANNELS(PJSIP/${EXTEN})}x" != "x"]?Chanspy(PJSIP/${EXTEN},uBq))' . PHP_EOL . "\t" . |
38
|
|
|
'same => n,Hangup()' . PHP_EOL |
39
|
|
|
. PHP_EOL . |
40
|
|
|
'[annonce-playback-in]' . PHP_EOL . |
41
|
|
|
'exten => annonce,1,Answer()' . PHP_EOL . "\t" . |
42
|
|
|
'same => n,ExecIf("${PBX_REC_ANNONCE_IN}x" != "x"]?Playback(${PBX_REC_ANNONCE_IN}))' . PHP_EOL . "\t" . |
43
|
|
|
'same => n,Hangup()' . PHP_EOL |
44
|
|
|
. PHP_EOL . |
45
|
|
|
'[annonce-playback-out]' . PHP_EOL . |
46
|
|
|
'exten => annonce,1,Answer()' . PHP_EOL . "\t" . |
47
|
|
|
'same => n,ExecIf("${PBX_REC_ANNONCE_OUT}x" != "x"]?Playback(${PBX_REC_ANNONCE_OUT}))' . PHP_EOL . "\t" . |
48
|
|
|
'same => n,Hangup()' . PHP_EOL; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns path to announce file by it's id |
53
|
|
|
* |
54
|
|
|
* @param string $id |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public static function getPathAnnounceFile(string $id): string |
59
|
|
|
{ |
60
|
|
|
$filename = ''; |
61
|
|
|
if ( ! empty($id)) { |
62
|
|
|
/** @var SoundFiles $fileData */ |
63
|
|
|
$fileData = SoundFiles::findFirst($id); |
64
|
|
|
if ($fileData !== null) { |
65
|
|
|
$filename = Util::trimExtensionForFile($fileData->path); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $filename; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Prepares additional parameters for each outgoing route context |
74
|
|
|
* before dial call in the extensions.conf file |
75
|
|
|
* |
76
|
|
|
* @param array $rout |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function generateOutRoutContext(array $rout): string |
81
|
|
|
{ |
82
|
|
|
return 'same => n,Set(_OUT_NEED_ANNONCE=1)' . "\n\t"; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Prepares additional parameters for each incoming context for each incoming route before dial in the |
87
|
|
|
* extensions.conf file |
88
|
|
|
* |
89
|
|
|
* @param string $rout_number |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function generateIncomingRoutBeforeDial(string $rout_number): string |
94
|
|
|
{ |
95
|
|
|
return 'same => n,Set(IN_NEED_ANNONCE=1)' . "\n\t"; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |