Project

General

Profile

Download (1.29 KB) Statistics
| Branch: | Tag: | Revision:
1 bd7ad5d2 Scott Ullrich
<?php
2
require_once('config.inc');
3
require_once('globals.inc');
4
require_once('service-utils.inc');
5
6
function openntpd_install() {
7
	global $g;
8
9
	$config_file = $g['varetc_path'] . '/openntpd.conf';
10
	$rcfile = array();
11
	$rcfile['file'] = 'openntpd.sh';
12
	$rcfile['start'] = <<<EOD
13
if [ -f $config_file ]; then
14
	ntpd -f $config_file
15
fi
16
17
EOD;
18
	$rcfile['stop'] = "killall ntpd";
19
	write_rcfile($rcfile);
20
}
21
22
function openntpd_get_iface_ip($iface) {
23
	$iface = convert_friendly_interface_to_real_interface_name($iface);
24
	$line = trim(shell_exec("ifconfig $iface | grep inet | grep -v inet6"));
25
	list($dummy, $ip, $dummy2, $dummy3) = explode(' ', $line);
26
27
	return $ip;
28
}
29
30
function openntpd_resync() {
31
	global $g, $config;
32
33
	$settings = $config['installedpackages']['openntpd']['config'][0];
34
	$config_file = $g['varetc_path'] . '/openntpd.conf';
35
36
	if ($settings['enable'] == 'on') {
37
		$conf = '';
38
39
		$ifaces = explode(',', $settings['interface']);
40
		$ips = array_map('openntpd_get_iface_ip', $ifaces);
41
		foreach ($ips as $ip)
42
			$conf .= "listen on $ip\n";
43
44
		$servers = explode(',', $config['system']['timeservers']);
45
		foreach ($servers as $server)
46
			$conf .= "servers $server\n";
47
48
		file_put_contents($config_file, $conf);
49
	}
50
	else {
51
		if (file_exists($config_file))
52
			unlink($config_file);
53
	}
54
	restart_service('openntpd');
55
}