|
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; |
|
21
|
|
|
|
|
22
|
|
|
use MikoPBX\Core\System\Processes; |
|
23
|
|
|
use MikoPBX\Core\System\Util; |
|
24
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\ConvertAudioFileAction; |
|
25
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\GetDateAction; |
|
26
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\RebootAction; |
|
27
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\RestoreDefaultSettingsAction; |
|
28
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\SendMailAction; |
|
29
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\SetDateAction; |
|
30
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\ShutdownAction; |
|
31
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\UpdateMailSettingsAction; |
|
32
|
|
|
use MikoPBX\PBXCoreREST\Lib\System\UpgradeFromImageAction; |
|
33
|
|
|
use Phalcon\Di\Injectable; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class SystemManagementProcessor |
|
37
|
|
|
* |
|
38
|
|
|
* @package MikoPBX\PBXCoreREST\Lib |
|
39
|
|
|
* |
|
40
|
|
|
*/ |
|
41
|
|
|
class SystemManagementProcessor extends Injectable |
|
42
|
|
|
{ |
|
43
|
|
|
/** |
|
44
|
|
|
* Processes System requests |
|
45
|
|
|
* |
|
46
|
|
|
* @param array $request |
|
47
|
|
|
* |
|
48
|
|
|
* @return PBXApiResult An object containing the result of the API call. |
|
49
|
|
|
* |
|
50
|
|
|
* @throws \Exception |
|
51
|
|
|
*/ |
|
52
|
|
|
public static function callBack(array $request): PBXApiResult |
|
53
|
|
|
{ |
|
54
|
|
|
$action = $request['action']; |
|
55
|
|
|
$data = $request['data']; |
|
56
|
|
|
$res = new PBXApiResult(); |
|
57
|
|
|
$res->processor = __METHOD__; |
|
58
|
|
|
switch ($action) { |
|
59
|
|
|
case 'reboot': |
|
60
|
|
|
$res = RebootAction::main(); |
|
61
|
|
|
break; |
|
62
|
|
|
case 'shutdown': |
|
63
|
|
|
$res= ShutdownAction::main(); |
|
64
|
|
|
break; |
|
65
|
|
|
case 'getDate': |
|
66
|
|
|
$res= GetDateAction::main(); |
|
67
|
|
|
break; |
|
68
|
|
|
case 'setDate': |
|
69
|
|
|
$res= SetDateAction::main($data); |
|
70
|
|
|
break; |
|
71
|
|
|
case 'updateMailSettings': |
|
72
|
|
|
$res = UpdateMailSettingsAction::main(); |
|
73
|
|
|
break; |
|
74
|
|
|
case 'sendMail': |
|
75
|
|
|
$res = SendMailAction::main($data); |
|
76
|
|
|
break; |
|
77
|
|
|
case 'upgrade': |
|
78
|
|
|
$imageFileLocation = $data['temp_filename']??''; |
|
79
|
|
|
$res = UpgradeFromImageAction::main($imageFileLocation); |
|
80
|
|
|
break; |
|
81
|
|
|
case 'restoreDefault': |
|
82
|
|
|
$ch = 0; |
|
83
|
|
|
do{ |
|
84
|
|
|
$ch++; |
|
85
|
|
|
$res = RestoreDefaultSettingsAction::main(); |
|
86
|
|
|
sleep(1); |
|
87
|
|
|
}while($ch <= 10 && !$res->success); |
|
88
|
|
|
break; |
|
89
|
|
|
case 'convertAudioFile': |
|
90
|
|
|
$mvPath = Util::which('mv'); |
|
91
|
|
|
Processes::mwExec("{$mvPath} {$request['data']['temp_filename']} {$request['data']['filename']}"); |
|
92
|
|
|
$res = ConvertAudioFileAction::main($request['data']['filename']); |
|
93
|
|
|
break; |
|
94
|
|
|
default: |
|
95
|
|
|
$res->messages['error'][] = "Unknown action - $action in ".__CLASS__; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$res->function = $action; |
|
99
|
|
|
|
|
100
|
|
|
return $res; |
|
101
|
|
|
} |
|
102
|
|
|
} |