diff --git a/security/stunnel/src/etc/inc/plugins.inc.d/stunnel.inc b/security/stunnel/src/etc/inc/plugins.inc.d/stunnel.inc index 364caa028..faa26282e 100644 --- a/security/stunnel/src/etc/inc/plugins.inc.d/stunnel.inc +++ b/security/stunnel/src/etc/inc/plugins.inc.d/stunnel.inc @@ -33,6 +33,39 @@ function stunnel_configure() ); } +function stunnel_services() +{ + $services = array(); + $mdl = new \OPNsense\Stunnel\Stunnel(); + if ($mdl->general->enabled == '1') { + $services[] = array( + 'description' => gettext('Stunnel'), + 'stunnel' => array( + 'restart' => array('stunnel restart'), + 'start' => array('stunnel start'), + 'stop' => array('stunnel stop'), + ), + 'name' => 'stunnel', + 'pidfile' => '/var/run/stunnel/stunnel.pid', + ); + if ($mdl->general->enable_ident_server == '1') { + // only report status from identd seperately, control is combined with stunnel + $services[] = array( + 'description' => gettext('Identd (stunnel)'), + 'stunnel' => array( + 'restart' => array('stunnel restart'), + 'start' => array('stunnel start'), + 'stop' => array('stunnel stop'), + ), + 'name' => 'identd_stunnel', + 'pidfile' => '/var/run/stunnel_identd.pid', + ); + } + } + return $services; +} + + function stunnel_refresh_crls() { $stunnel = new OPNsense\Stunnel\Stunnel(); @@ -90,7 +123,7 @@ function stunnel_syslog() { $logfacilities = array(); $logfacilities['stunnel'] = array( - 'facility' => array('stunnel') + 'facility' => array('stunnel', 'identd_stunnel') ); return $logfacilities; } diff --git a/security/stunnel/src/etc/rc.d/identd_stunnel b/security/stunnel/src/etc/rc.d/identd_stunnel new file mode 100755 index 000000000..003c2c3c4 --- /dev/null +++ b/security/stunnel/src/etc/rc.d/identd_stunnel @@ -0,0 +1,55 @@ +#!/bin/sh +# +# $FreeBSD$ +# +# PROVIDE: identd_stunnel +# REQUIRE: SERVERS +# KEYWORD: shutdown +# + +. /etc/rc.subr + +name=identd_stunnel +rcvar=identd_stunnel_enable +command=/usr/local/opnsense/scripts/stunnel/identd_stunnel.py +command_interpreter=/usr/local/bin/python3 +pidfile="/var/run/${name}.pid" +load_rc_config $name + +# Set defaults +: ${identd_stunnel_enable:=NO} + +stop_cmd=identd_stunnel_stop + +# kill configd +identd_stunnel_stop() +{ + if [ -z "$rc_pid" ]; then + [ -n "$rc_fast" ] && return 0 + _run_rc_notrunning + return 1 + fi + + echo -n "Stopping ${name}." + # first ask gently to exit + kill -15 ${rc_pid} + + # wait max 5 seconds for gentle exit + for i in $(seq 1 50); + do + if [ -z "`/bin/ps -ax | /usr/bin/awk '{print $1;}' | /usr/bin/grep "^${rc_pid}"`" ]; then + break + fi + sleep 0.1 + done + + # kill any remaining identd_stunnel processes (if still running) + for identd_stunnel_pid in `/bin/ps -ax | grep 'identd_stunnel.py' | /usr/bin/awk '{print $1;}' ` + do + kill -9 $identd_stunnel_pid >/dev/null 2>&1 + done + + echo "..done" +} + +run_rc_command $1 diff --git a/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/Api/ServicesController.php b/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/Api/ServicesController.php index c0ed5b2db..c84ae5cfb 100644 --- a/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/Api/ServicesController.php +++ b/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/Api/ServicesController.php @@ -45,7 +45,7 @@ class ServicesController extends ApiMutableModelControllerBase break; } } - parent::save(); + return parent::save(); } public function searchItemAction() @@ -77,4 +77,13 @@ class ServicesController extends ApiMutableModelControllerBase { return $this->toggleBase("services.service", $uuid, $enabled); } + + public function getAction() + { + $result = array(); + $result[static::$internalModelName] = [ + "general" => $this->getModel()->general->getNodes() + ]; + return $result; + } } diff --git a/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/ServicesController.php b/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/ServicesController.php index caf2b73be..e693259d3 100644 --- a/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/ServicesController.php +++ b/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/ServicesController.php @@ -36,5 +36,6 @@ class ServicesController extends IndexController { $this->view->pick('OPNsense/Stunnel/services'); $this->view->formDialogService = $this->getForm("dialogService"); + $this->view->formGeneral = $this->getForm("general"); } } diff --git a/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/forms/general.xml b/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/forms/general.xml new file mode 100644 index 000000000..958e5a830 --- /dev/null +++ b/security/stunnel/src/opnsense/mvc/app/controllers/OPNsense/Stunnel/forms/general.xml @@ -0,0 +1,21 @@ +
+ + stunnel.general.chroot + + checkbox + Start stunnel in it a chroot, although this is a more secure option there are small points of attention before + using this. Since system logging is detached after startup, stunnel seems to have difficulties handing syslog configuration changes + which need a service restart. If this happens, you need to restart stunnel manually as well. + + + + stunnel.general.enable_ident_server + + checkbox + Enable internal ident service (rfc1413), which tracks authenticated tcp sessions and returns the associated user + of the certificate used by stunnel (cn part). When enabled, this service listens on port tcp/113 and accepts port pairs as defined by rfc1413. + Make sure you deny untrusted clients access to this facility, usually it only makes sense to allow access from this + firewall (allowed by default). + + +
diff --git a/security/stunnel/src/opnsense/mvc/app/models/OPNsense/Stunnel/Stunnel.xml b/security/stunnel/src/opnsense/mvc/app/models/OPNsense/Stunnel/Stunnel.xml index b17406bbb..b76adc6c5 100644 --- a/security/stunnel/src/opnsense/mvc/app/models/OPNsense/Stunnel/Stunnel.xml +++ b/security/stunnel/src/opnsense/mvc/app/models/OPNsense/Stunnel/Stunnel.xml @@ -11,6 +11,14 @@ 1 Y + + 0 + Y + + + 0 + Y + diff --git a/security/stunnel/src/opnsense/mvc/app/views/OPNsense/Stunnel/services.volt b/security/stunnel/src/opnsense/mvc/app/views/OPNsense/Stunnel/services.volt index fd6ba46c4..fe9967c40 100644 --- a/security/stunnel/src/opnsense/mvc/app/views/OPNsense/Stunnel/services.volt +++ b/security/stunnel/src/opnsense/mvc/app/views/OPNsense/Stunnel/services.volt @@ -35,14 +35,30 @@ toggle:'/api/stunnel/services/toggleItem/' } ); - $("#reconfigureAct").SimpleActionButton(); + $("#reconfigureAct").SimpleActionButton({ + onPreAction: function() { + const dfObj = new $.Deferred(); + saveFormToEndpoint("/api/stunnel/services/set", 'frm_general_settings', function(){ + dfObj.resolve(); + }); + return dfObj; + } + }); updateServiceControlUI('stunnel'); + + let data_get_map = {'frm_general_settings':"/api/stunnel/services/get"}; + mapDataToFormUI(data_get_map).done(function(data){ + formatTokenizersUI(); + $('.selectpicker').selectpicker('refresh'); + }); + });
@@ -69,6 +85,10 @@
+
+ + {{ partial("layout_partials/base_form",['fields':formGeneral,'id':'frm_general_settings'])}} +