Passed
Push — develop ( 9d9a8f...564466 )
by Nikolay
05:09
created

GetHypervisorInfoAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
c 1
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A main() 0 15 2
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\Sysinfo;
21
22
use MikoPBX\Core\System\Util;
23
use MikoPBX\PBXCoreREST\Lib\PBXApiResult;
24
25
/**
26
 * Returns hypervisor information
27
 *
28
 * @package MikoPBX\PBXCoreREST\Lib\Sysinfo
29
 */
30
class GetHypervisorInfoAction extends \Phalcon\Di\Injectable
31
{
32
    /**
33
     * Returns hypervisor information
34
     *
35
     * @return PBXApiResult An object containing the result of the API call.
36
     */
37
    public static function main(): PBXApiResult
38
    {
39
        $res            = new PBXApiResult();
40
        $res->processor = __METHOD__;
41
42
        $dmesg = Util::which('dmesg');
43
        $grep = Util::which('grep');
44
        $awk = Util::which('awk');
45
        $result = shell_exec("$dmesg | $grep 'Hypervisor detected' | $awk -F 'Hypervisor detected: ' '{ print $2}'");
46
        $result = trim($result);
47
        $res->data =['Hypervisor'=>$result];
48
        if ($result){
49
            $res->success = true;
50
        }
51
        return $res;
52
    }
53
54
}