|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* MikoPBX - free phone system for small business |
|
4
|
|
|
* Copyright © 2017-2024 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\SysLogs; |
|
21
|
|
|
|
|
22
|
|
|
use MikoPBX\Core\System\Network; |
|
23
|
|
|
use MikoPBX\Core\System\Processes; |
|
24
|
|
|
use MikoPBX\Core\System\System; |
|
25
|
|
|
use MikoPBX\Core\System\Util; |
|
26
|
|
|
use MikoPBX\PBXCoreREST\Lib\PBXApiResult; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Starts the collection of logs and captures TCP packets. |
|
30
|
|
|
* |
|
31
|
|
|
* @package MikoPBX\PBXCoreREST\Lib\SysLogs |
|
32
|
|
|
*/ |
|
33
|
|
|
class StartLogAction extends \Phalcon\Di\Injectable |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Starts the collection of logs and captures TCP packets. |
|
37
|
|
|
* |
|
38
|
|
|
* @return PBXApiResult An object containing the result of the API call. |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function main(): PBXApiResult |
|
41
|
|
|
{ |
|
42
|
|
|
$res = new PBXApiResult(); |
|
43
|
|
|
$res->processor = __METHOD__; |
|
44
|
|
|
$logDir = System::getLogDir(); |
|
45
|
|
|
|
|
46
|
|
|
// TCP dump |
|
47
|
|
|
$tcpDumpDir = "{$logDir}/tcpDump"; |
|
48
|
|
|
Util::mwMkdir($tcpDumpDir); |
|
49
|
|
|
$network = new Network(); |
|
50
|
|
|
$arr_eth = $network->getInterfacesNames(); |
|
51
|
|
|
$tcpdumpPath = Util::which('tcpdump'); |
|
52
|
|
|
$timeout = 300; |
|
53
|
|
|
foreach ($arr_eth as $eth) { |
|
54
|
|
|
Processes::mwExecBgWithTimeout( |
|
55
|
|
|
"{$tcpdumpPath} -i {$eth} -n -s 0 -vvv -w {$tcpDumpDir}/{$eth}.pcap", |
|
56
|
|
|
$timeout, |
|
57
|
|
|
"{$tcpDumpDir}/{$eth}_out.log" |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
$res->success = true; |
|
61
|
|
|
|
|
62
|
|
|
return $res; |
|
63
|
|
|
} |
|
64
|
|
|
} |