diff options
-rw-r--r-- | usr/local/pkg/openntpd.inc | 55 | ||||
-rw-r--r-- | usr/local/pkg/openntpd.xml | 42 | ||||
-rwxr-xr-x | usr/local/www/fbegin.inc | 1 |
3 files changed, 98 insertions, 0 deletions
diff --git a/usr/local/pkg/openntpd.inc b/usr/local/pkg/openntpd.inc new file mode 100644 index 0000000..c4914b8 --- /dev/null +++ b/usr/local/pkg/openntpd.inc @@ -0,0 +1,55 @@ +<?php +require_once('config.inc'); +require_once('globals.inc'); +require_once('service-utils.inc'); + +function openntpd_install() { + global $g; + + $config_file = $g['varetc_path'] . '/openntpd.conf'; + $rcfile = array(); + $rcfile['file'] = 'openntpd.sh'; + $rcfile['start'] = <<<EOD +if [ -f $config_file ]; then + ntpd -f $config_file +fi + +EOD; + $rcfile['stop'] = "killall ntpd"; + write_rcfile($rcfile); +} + +function openntpd_get_iface_ip($iface) { + $iface = convert_friendly_interface_to_real_interface_name($iface); + $line = trim(shell_exec("ifconfig $iface | grep inet | grep -v inet6")); + list($dummy, $ip, $dummy2, $dummy3) = explode(' ', $line); + + return $ip; +} + +function openntpd_resync() { + global $g, $config; + + $settings = $config['installedpackages']['openntpd']['config'][0]; + $config_file = $g['varetc_path'] . '/openntpd.conf'; + + if ($settings['enable'] == 'on') { + $conf = ''; + + $ifaces = explode(',', $settings['interface']); + $ips = array_map('openntpd_get_iface_ip', $ifaces); + foreach ($ips as $ip) + $conf .= "listen on $ip\n"; + + $servers = explode(',', $config['system']['timeservers']); + foreach ($servers as $server) + $conf .= "servers $server\n"; + + file_put_contents($config_file, $conf); + } + else { + if (file_exists($config_file)) + unlink($config_file); + } + restart_service('openntpd'); +} diff --git a/usr/local/pkg/openntpd.xml b/usr/local/pkg/openntpd.xml new file mode 100644 index 0000000..8d16323 --- /dev/null +++ b/usr/local/pkg/openntpd.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<packagegui> + <include_file>openntpd.inc</include_file> + <custom_php_install_command> + openntpd_install(); + </custom_php_install_command> + <menu> + <name>NTP server</name> + <tooltiptext>Configure the time server settings.</tooltiptext> + <section>Services</section> + <url>/pkg_edit.php?xml=openntpd.xml&id=0</url> + </menu> + <service> + <name>OpenNTPD</name> + <description>NTP server.</description> + <rcfile>openntpd.sh</rcfile> + <executable>ntpd</executable> + </service> + <!-- Interface --> + <name>openntpd</name> + <title>NTP server</title> + <fields> + <field> + <fieldname>enable</fieldname> + <fielddescr>Enable</fielddescr> + <description>Check this to enable the NTP server.</description> + <type>checkbox</type> + <enablefields>interface</enablefields> + </field> + <field> + <fieldname>interface</fieldname> + <fielddescr>Interface</fielddescr> + <description>Select the interface the NTP server will listen on.</description> + <default_value>lan</default_value> + <type>interfaces_selection</type> + <multiple/> + </field> + </fields> + <custom_php_resync_config_command> + openntpd_resync(); + </custom_php_resync_config_command> +</packagegui> diff --git a/usr/local/www/fbegin.inc b/usr/local/www/fbegin.inc index 4a2254f..4e5d003 100755 --- a/usr/local/www/fbegin.inc +++ b/usr/local/www/fbegin.inc @@ -155,6 +155,7 @@ require_once("notices.inc"); <li><a href="/pkg_edit.php?xml=olsrd.xml&id=0" class="navlnk">OLSR</a></li> <li><a href="/services_snmp.php" class="navlnk">SNMP</a></li> <li><a href="/status_upnp.php" class="navlnk">MiniUPnPd</a></li> + <li><a href="/pkg_edit.php?xml=openntpd.xml&id=0">OpenNTPD</a></li> <li><a href="/services_wol.php" class="navlnk">Wake on LAN</a></li> <?php echo return_ext_menu("Services"); ?> </ul> |