Passed
Push — develop ( d22e43...817ba9 )
by Nikolay
04:35
created

FirewallManagementProcessor::time2stamp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 1
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\PBXCoreREST\Lib\Firewall\Fail2banUnban;
23
use MikoPBX\PBXCoreREST\Lib\Firewall\GetBannedIp;
24
use Phalcon\Di\Injectable;
25
26
/**
27
 * Class FirewallManagementProcessor
28
 *
29
 * @package MikoPBX\PBXCoreREST\Lib
30
 *
31
 */
32
class FirewallManagementProcessor extends Injectable
33
{
34
35
    /**
36
     * Processes Firewall requests
37
     *
38
     * @param array $request
39
     *
40
     * @return PBXApiResult An object containing the result of the API call.
41
     *
42
     * @throws \Exception
43
     */
44
    public static function callBack(array $request): PBXApiResult
45
    {
46
        $action         = $request['action'];
47
        $data           = $request['data'];
48
        $res = new PBXApiResult();
49
        $res->processor = __METHOD__;
50
        switch ($action) {
51
            case 'unBanIp':
52
                $res = Fail2banUnban::main($data['ip']??'');
53
                break;
54
            case 'getBannedIp':
55
                $res = GetBannedIp::main();
56
                break;
57
            default:
58
                $res->messages['error'][] = "Unknown action - {$action} in ".__CLASS__;
59
        }
60
        $res->function = $action;
61
62
        return $res;
63
    }
64
}