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

VMWareToolsConf::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Core\System\Configs;
21
22
23
use MikoPBX\Core\System\Processes;
24
use MikoPBX\Core\System\Util;
25
26
/**
27
 * Class VMWareToolsConf
28
 *
29
 * Represents the VMWareTools configuration.
30
 *
31
 * @package MikoPBX\Core\System\Configs
32
 */
33
class VMWareToolsConf
34
{
35
    /**
36
     * Configure and start VMWareTools.
37
     *
38
     * @return bool
39
     */
40
    public function configure(): bool
41
    {
42
        Processes::killByName("vmtoolsd");
43
44
        $conf = "[logging]\n"
45
            . "log = false\n"
46
            . "vmtoolsd.level = none\n"
47
            . ";vmsvc.data = /dev/null\n"
48
            . "vmsvc.level = none\n";
49
50
        $dirVM = '/etc/vmware-tools';
51
        if (!file_exists($dirVM)) {
52
            Util::mwMkdir($dirVM);
53
        }
54
55
        file_put_contents("{$dirVM}/tools.conf", $conf);
56
        $vmtoolsdPath = Util::which('vmtoolsd');
57
        $result = Processes::mwExec("{$vmtoolsdPath} --background=/var/run/vmtoolsd.pid > /dev/null 2> /dev/null");
58
59
        return $result === 0;
60
    }
61
}