Passed
Push — develop ( b91c6d...602856 )
by Nikolay
05:44 queued 10s
created

NTPConf   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 21 4
A __construct() 0 3 1
1
<?php
2
/**
3
 * Copyright (C) MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Nikolay Beketov, 7 2020
7
 *
8
 */
9
namespace MikoPBX\Core\System\Configs;
10
11
use MikoPBX\Core\System\MikoPBXConfig;
12
use MikoPBX\Core\System\Util;
13
use Phalcon\Di\Injectable;
14
15
class NTPConf extends Injectable
16
{
17
    private MikoPBXConfig $mikoPBXConfig;
18
19
    /**
20
     * NTPConf constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->mikoPBXConfig = new MikoPBXConfig();
25
    }
26
27
    /**
28
     * Setup ntp daemon
29
     */
30
    public function configure(): void
31
    {
32
        $ntp_server = $this->mikoPBXConfig->getGeneralSettings('NTPServer');
33
        if ( ! empty($ntp_server)) {
34
            $ntp_conf = "server {$ntp_server}";
35
        } else {
36
            $ntp_conf = 'server 0.pool.ntp.org
37
server 1.pool.ntp.org
38
server 2.pool.ntp.org';
39
        }
40
        Util::fileWriteContent('/etc/ntp.conf', $ntp_conf);
41
42
        if (Util::isSystemctl()) {
43
            return;
44
        }
45
        Util::killByName("ntpd");
46
        usleep(500000);
47
        $manual_time = $this->mikoPBXConfig->getGeneralSettings('PBXManualTimeSettings');
48
        if ($manual_time !== '1') {
49
            $ntpdPath = Util::which('ntpd');
50
            Util::mwExec($ntpdPath);
51
        }
52
    }
53
}
54