1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* MikoPBX - free phone system for small business |
4
|
|
|
* Copyright © 2017-2023 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\PBXCoreREST\Lib\Sip; |
21
|
|
|
|
22
|
|
|
use MikoPBX\Common\Models\Extensions; |
23
|
|
|
use MikoPBX\PBXCoreREST\Lib\PBXApiResult; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get the SIP secret for the extension sipAPI.js JavaScript script. |
27
|
|
|
* |
28
|
|
|
* @package MikoPBX\PBXCoreREST\Lib\Sip |
29
|
|
|
*/ |
30
|
|
|
class GetSipSecret extends \Phalcon\Di\Injectable |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Get the SIP secret for the AJAX request. |
34
|
|
|
* |
35
|
|
|
* @param string $number The extension number |
36
|
|
|
* @return PBXApiResult Result with SIP secret |
37
|
|
|
*/ |
38
|
|
|
public static function main(string $number): PBXApiResult |
39
|
|
|
{ |
40
|
|
|
$res = new PBXApiResult(); |
41
|
|
|
$res->processor = __METHOD__; |
42
|
|
|
$res->success = true; |
43
|
|
|
$res->data['number'] = $number; |
44
|
|
|
$res->data['secret'] = ''; |
45
|
|
|
|
46
|
|
|
$extension = Extensions::findFirstByNumber($number); |
47
|
|
|
if ($extension !== null) { |
48
|
|
|
$res->data['secret'] = $extension->Sip->secret??''; |
49
|
|
|
return $res; |
50
|
|
|
} |
51
|
|
|
return $res; |
52
|
|
|
} |
53
|
|
|
} |