|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © MIKO LLC - All Rights Reserved |
|
4
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited |
|
5
|
|
|
* Proprietary and confidential |
|
6
|
|
|
* Written by Alexey Portnov, 8 2020 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace MikoPBX\PBXCoreREST\Controllers\Sysinfo; |
|
10
|
|
|
|
|
11
|
|
|
use MikoPBX\PBXCoreREST\Controllers\BaseController; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* /pbxcore/api/sysinfo/{name} Get system logs (GET) |
|
15
|
|
|
* |
|
16
|
|
|
* Get system information |
|
17
|
|
|
* curl http://172.16.156.223/pbxcore/api/sysinfo/getInfo; |
|
18
|
|
|
* |
|
19
|
|
|
* Get external IP address: |
|
20
|
|
|
* curl http://172.16.156.212/pbxcore/api/sysinfo/getExternalIpInfo |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
class GetController extends BaseController |
|
24
|
|
|
{ |
|
25
|
|
|
public function callAction($actionName): void |
|
26
|
|
|
{ |
|
27
|
|
|
$data = null; |
|
|
|
|
|
|
28
|
|
|
switch ($actionName) { |
|
29
|
|
|
case 'getInfo': |
|
30
|
|
|
$this->getInfoAction(); |
|
31
|
|
|
break; |
|
32
|
|
|
default: |
|
33
|
|
|
$data = $this->request->getPost(); |
|
34
|
|
|
$this->sendRequestToBackendWorker('sysinfo', $actionName, $data); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Parses content of file and puts it to answer |
|
40
|
|
|
* |
|
41
|
|
|
*/ |
|
42
|
|
|
private function getInfoAction(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$requestMessage = json_encode( |
|
45
|
|
|
[ |
|
46
|
|
|
'processor' => 'sysinfo', |
|
47
|
|
|
'data' => $this->request->getPost(), |
|
48
|
|
|
'action' => 'getInfo', |
|
49
|
|
|
] |
|
50
|
|
|
); |
|
51
|
|
|
$connection = $this->di->getShared('beanstalkConnection'); |
|
52
|
|
|
$response = $connection->request($requestMessage, 30, 0); |
|
53
|
|
|
if ($response !== false) { |
|
54
|
|
|
$response = json_decode($response, true); |
|
55
|
|
|
$filename = $response['data']['filename'] ?? ''; |
|
56
|
|
|
if ( ! file_exists($filename)) { |
|
57
|
|
|
$response['messages'][] = 'System information collected file not found'; |
|
58
|
|
|
} else { |
|
59
|
|
|
$response['data']['content'] = '' . file_get_contents($filename); |
|
60
|
|
|
unlink($filename); |
|
61
|
|
|
} |
|
62
|
|
|
$this->response->setPayloadSuccess($response); |
|
|
|
|
|
|
63
|
|
|
} else { |
|
64
|
|
|
$this->sendError(500); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |