1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* MikoPBX - free phone system for small business |
4
|
|
|
* Copyright © 2017-2021 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\Core\System\Configs; |
21
|
|
|
use MikoPBX\Core\System\Util; |
22
|
|
|
|
23
|
|
|
class VmToolsConf |
24
|
|
|
{ |
25
|
|
|
public const VMWARE = 'vmware'; |
26
|
|
|
public function configure():bool |
27
|
|
|
{ |
28
|
|
|
$result = true; |
29
|
|
|
if(Util::isDocker()){ |
30
|
|
|
return $result; |
31
|
|
|
} |
32
|
|
|
$vars = [ |
33
|
|
|
self::VMWARE => VMWareToolsConf::class |
34
|
|
|
]; |
35
|
|
|
$vendor = $this->getCpuVendor(); |
36
|
|
|
$className = $vars[$vendor]??''; |
37
|
|
|
if(class_exists($className)){ |
38
|
|
|
$tools = new $className(); |
39
|
|
|
$result = $tools->configure(); |
40
|
|
|
} |
41
|
|
|
return $result; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
private function getCpuVendor():string |
45
|
|
|
{ |
46
|
|
|
$lsCpuPath = Util::which('lscpu'); |
47
|
|
|
$grepPath = Util::which('grep'); |
48
|
|
|
$awk = Util::which('awk'); |
49
|
|
|
$result = shell_exec("$lsCpuPath | $grepPath vendor | $awk -F ' ' '{ print $3}'"); |
50
|
|
|
return strtolower(trim($result)); |
51
|
|
|
} |
52
|
|
|
} |