diff --git a/net/chrony/Makefile b/net/chrony/Makefile new file mode 100644 index 000000000..2ca167d2e --- /dev/null +++ b/net/chrony/Makefile @@ -0,0 +1,8 @@ +PLUGIN_NAME= chrony +PLUGIN_VERSION= 0.1 +PLUGIN_COMMENT= Chrony time synchronisation +PLUGIN_DEPENDS= chrony +PLUGIN_MAINTAINER= m.muenz@gmail.com +PLUGIN_DEVEL= yes + +.include "../../Mk/plugins.mk" diff --git a/net/chrony/pkg-descr b/net/chrony/pkg-descr new file mode 100644 index 000000000..0fd3f4ae5 --- /dev/null +++ b/net/chrony/pkg-descr @@ -0,0 +1,14 @@ +An alternative to native ntpd daemon. In some edge cases chrony works +better in virtual environments. + +Plugin Changelog +---------------- + +1.0 + +* Allow to adjust the listening port +* Allow setting of up to three peers +* Use of allowed networks + + +WWW: https://chrony.tuxfamily.org/ diff --git a/net/chrony/src/etc/inc/plugins.inc.d/chrony.inc b/net/chrony/src/etc/inc/plugins.inc.d/chrony.inc new file mode 100644 index 000000000..36af05a37 --- /dev/null +++ b/net/chrony/src/etc/inc/plugins.inc.d/chrony.inc @@ -0,0 +1,49 @@ + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +function chrony_services() +{ + global $config; + + $services = array(); + + if (isset($config['OPNsense']['chrony']['general']['enabled']) && $config['OPNsense']['chrony']['general']['enabled'] == 1) { + $services[] = array( + 'description' => gettext('chrony daemon'), + 'configd' => array( + 'restart' => array('chrony restart'), + 'start' => array('chrony start'), + 'stop' => array('chrony stop'), + ), + 'name' => 'chronyd', + 'pidfile' => '/var/run/chrony/chronyd.pid' + ); + } + + return $services; +} diff --git a/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/Api/GeneralController.php b/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/Api/GeneralController.php new file mode 100644 index 000000000..d96f5a121 --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/Api/GeneralController.php @@ -0,0 +1,37 @@ + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +namespace OPNsense\Chrony\Api; + +use OPNsense\Base\ApiMutableModelControllerBase; + +class GeneralController extends ApiMutableModelControllerBase +{ + protected static $internalModelClass = '\OPNsense\Chrony\General'; + protected static $internalModelName = 'general'; +} diff --git a/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/Api/ServiceController.php b/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/Api/ServiceController.php new file mode 100644 index 000000000..d441d9dc6 --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/Api/ServiceController.php @@ -0,0 +1,39 @@ + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +namespace OPNsense\Chrony\Api; + +use OPNsense\Base\ApiMutableServiceControllerBase; + +class ServiceController extends ApiMutableServiceControllerBase +{ + protected static $internalServiceClass = '\OPNsense\Chrony\General'; + protected static $internalServiceTemplate = 'OPNsense/Chrony'; + protected static $internalServiceEnabled = 'enabled'; + protected static $internalServiceName = 'chrony'; +} diff --git a/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/GeneralController.php b/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/GeneralController.php new file mode 100644 index 000000000..faa214b6a --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/GeneralController.php @@ -0,0 +1,38 @@ + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +namespace OPNsense\Chrony; + +class GeneralController extends \OPNsense\Base\IndexController +{ + public function indexAction() + { + $this->view->generalForm = $this->getForm('general'); + $this->view->pick('OPNsense/Chrony/general'); + } +} diff --git a/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/forms/general.xml b/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/forms/general.xml new file mode 100644 index 000000000..ee8d8326c --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/controllers/OPNsense/Chrony/forms/general.xml @@ -0,0 +1,30 @@ +
+ + general.enabled + + checkbox + Enable Chrony time daemon. + + + general.port + + text + Set the port chrony listen to. + + + general.peers + + + select_multiple + true + Set as many NTP peers you need. + + + general.allowednetworks + + + select_multiple + true + Set the networks allowed to synchronize time with this server. If this value is not set it will also not listen to the port and just synchronize the time for itself. + +
diff --git a/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/ACL/ACL.xml b/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/ACL/ACL.xml new file mode 100644 index 000000000..ece3f4af8 --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/ACL/ACL.xml @@ -0,0 +1,9 @@ + + + Services: Chrony + + ui/chrony/* + api/chrony/* + + + diff --git a/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/General.php b/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/General.php new file mode 100644 index 000000000..ddbdd9413 --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/General.php @@ -0,0 +1,35 @@ + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +namespace OPNsense\Chrony; + +use OPNsense\Base\BaseModel; + +class General extends BaseModel +{ +} diff --git a/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/General.xml b/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/General.xml new file mode 100644 index 000000000..30b99eb53 --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/General.xml @@ -0,0 +1,26 @@ + + //OPNsense/chrony/general + Chrony configuration + 0.0.1 + + + 0 + Y + + + 323 + Y + + + 0.opnsense.pool.ntp.org + Y + , + Y + + + N + , + Y + + + diff --git a/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/Menu/Menu.xml b/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/Menu/Menu.xml new file mode 100644 index 000000000..e11f5fe9c --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/models/OPNsense/Chrony/Menu/Menu.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/net/chrony/src/opnsense/mvc/app/views/OPNsense/Chrony/general.volt b/net/chrony/src/opnsense/mvc/app/views/OPNsense/Chrony/general.volt new file mode 100644 index 000000000..be8b75de2 --- /dev/null +++ b/net/chrony/src/opnsense/mvc/app/views/OPNsense/Chrony/general.volt @@ -0,0 +1,58 @@ +{# + # Copyright (c) 2019 Deciso B.V. + # Copyright (c) 2020 Michael Muenz + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without modification, + # are permitted provided that the following conditions are met: + # + # 1. Redistributions of source code must retain the above copyright notice, + # this list of conditions and the following disclaimer. + # + # 2. Redistributions in binary form must reproduce the above copyright notice, + # this list of conditions and the following disclaimer in the documentation + # and/or other materials provided with the distribution. + # + # THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + # POSSIBILITY OF SUCH DAMAGE. + #} + +
+ {{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}} +
+
+ +
+
+ + diff --git a/net/chrony/src/opnsense/scripts/OPNsense/Chrony/setup.sh b/net/chrony/src/opnsense/scripts/OPNsense/Chrony/setup.sh new file mode 100644 index 000000000..ddc03d6a0 --- /dev/null +++ b/net/chrony/src/opnsense/scripts/OPNsense/Chrony/setup.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +mkdir -p /var/db/chrony/ /var/run/chrony/ +chown -R chronyd:chronyd /var/db/chrony/ /var/run/chrony/ +chmod 750 /var/db/chrony/ /var/run/chrony/ diff --git a/net/chrony/src/opnsense/service/conf/actions.d/actions_chrony.conf b/net/chrony/src/opnsense/service/conf/actions.d/actions_chrony.conf new file mode 100644 index 000000000..dd50d41c4 --- /dev/null +++ b/net/chrony/src/opnsense/service/conf/actions.d/actions_chrony.conf @@ -0,0 +1,23 @@ +[start] +command:/usr/local/opnsense/scripts/OPNsense/Chrony/setup.sh;/usr/local/etc/rc.d/chronyd start +parameters: +type:script +message:starting chrony + +[stop] +command:/usr/local/etc/rc.d/chronyd stop +parameters: +type:script +message:stopping chrony + +[restart] +command:/usr/local/opnsense/scripts/OPNsense/Chrony/setup.sh;/usr/local/etc/rc.d/chronyd restart +parameters: +type:script +message:restarting chrony + +[status] +command:/usr/local/etc/rc.d/chronyd status;exit 0 +parameters: +type:script_output +message:request chrony status diff --git a/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/+TARGETS b/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/+TARGETS new file mode 100644 index 000000000..a0947f190 --- /dev/null +++ b/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/+TARGETS @@ -0,0 +1,2 @@ +chronyd:/etc/rc.conf.d/chronyd +chrony.conf:/usr/local/etc/chrony.conf diff --git a/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/chrony.conf b/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/chrony.conf new file mode 100644 index 000000000..38397c3a6 --- /dev/null +++ b/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/chrony.conf @@ -0,0 +1,19 @@ +{% if helpers.exists('OPNsense.chrony.general.enabled') and OPNsense.chrony.general.enabled == '1' %} + +port {{ OPNsense.chrony.general.port }} +driftfile /var/db/chrony/drift +pidfile /var/run/chrony/chronyd.pid + +{% if not helpers.empty('OPNsense.chrony.general.peers') %} +{% for peer in OPNsense.chrony.general.peers.split(',') %} +server {{ peer }} iburst +{% endfor %} +{% endif %} + +{% if not helpers.empty('OPNsense.chrony.general.allowednetworks') %} +{% for network in OPNsense.chrony.general.allowednetworks.split(',') %} +allow {{ network }} +{% endfor %} +{% endif %} + +{% endif %} diff --git a/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/chronyd b/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/chronyd new file mode 100644 index 000000000..2faa5b55b --- /dev/null +++ b/net/chrony/src/opnsense/service/templates/OPNsense/Chrony/chronyd @@ -0,0 +1,7 @@ +{% if helpers.exists('OPNsense.chrony.general.enabled') and OPNsense.chrony.general.enabled == '1' %} +chronyd_var_script="/usr/local/opnsense/scripts/OPNsense/Chrony/setup.sh" +chronyd_enable="YES" +{% else %} +chronyd_enable="NO" +{% endif %} +chronyd_var_mfs="/var/db/chronyd /var/run/chronyd"