diff --git a/net/ntopng/Makefile b/net/ntopng/Makefile index 652921b6a..c384da90c 100644 --- a/net/ntopng/Makefile +++ b/net/ntopng/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= ntopng -PLUGIN_VERSION= 1.0 -PLUGIN_REVISION= 1 +PLUGIN_VERSION= 1.1 PLUGIN_COMMENT= Traffic Analysis and Flow Collection PLUGIN_DEPENDS= ntopng PLUGIN_MAINTAINER= m.muenz@gmail.com diff --git a/net/ntopng/src/opnsense/mvc/app/controllers/OPNsense/Ntopng/forms/general.xml b/net/ntopng/src/opnsense/mvc/app/controllers/OPNsense/Ntopng/forms/general.xml index 6beb01346..e417cd9f6 100644 --- a/net/ntopng/src/opnsense/mvc/app/controllers/OPNsense/Ntopng/forms/general.xml +++ b/net/ntopng/src/opnsense/mvc/app/controllers/OPNsense/Ntopng/forms/general.xml @@ -18,6 +18,18 @@ text HTTP Port this service listens on. + + general.httpsport + + text + HTTPS Port this service listens on. If you enable HTTPS you will be redirected from HTTP to HTTPS. Please select a certificate below + + + general.cert + + dropdown + Set the certificate to use for HTTPS connections. + general.dnsmode diff --git a/net/ntopng/src/opnsense/mvc/app/models/OPNsense/Ntopng/General.xml b/net/ntopng/src/opnsense/mvc/app/models/OPNsense/Ntopng/General.xml index c16a21d26..822fc38dc 100644 --- a/net/ntopng/src/opnsense/mvc/app/models/OPNsense/Ntopng/General.xml +++ b/net/ntopng/src/opnsense/mvc/app/models/OPNsense/Ntopng/General.xml @@ -15,6 +15,27 @@ Y 3000 + + N + + + Please select a HTTPS port and a valid certificate + AllOrNoneConstraint + + cert + + + + + + cert + N + + + httpsport.check001 + + + N diff --git a/net/ntopng/src/opnsense/scripts/OPNsense/Ntopng/generate_certs.php b/net/ntopng/src/opnsense/scripts/OPNsense/Ntopng/generate_certs.php new file mode 100644 index 000000000..56021fe7b --- /dev/null +++ b/net/ntopng/src/opnsense/scripts/OPNsense/Ntopng/generate_certs.php @@ -0,0 +1,73 @@ +#!/usr/local/bin/php +object(); +if (isset($configObj->OPNsense->ntopng)) { + foreach ($configObj->OPNsense->ntopng->children() as $find_cert) { + $cert_refid = (string)$find_cert->cert; + // if httpsport has a certificate attached, search for its contents + if ($cert_refid != "") { + foreach ($configObj->cert as $cert) { + if ($cert_refid == (string)$cert->refid) { + // generate cert pem file + $pem_content = trim(str_replace("\n\n", "\n", str_replace( + "\r", + "", + base64_decode((string)$cert->crt) + ))); + + $pem_content .= "\n"; + $pem_content .= trim(str_replace( + "\n\n", + "\n", + str_replace("\r", "", base64_decode((string)$cert->prv)) + )); + $pem_content .= "\n"; + $cert_pem_content .= $pem_content; + } + } + } + } +} + +file_put_contents($cert_pem_filename, $cert_pem_content); +chmod($cert_pem_filename, 0644); +echo "Certificates generated $cert_pem_filename\n"; diff --git a/net/ntopng/src/opnsense/scripts/OPNsense/Ntopng/setup.sh b/net/ntopng/src/opnsense/scripts/OPNsense/Ntopng/setup.sh index 41fb211a3..df542c686 100755 --- a/net/ntopng/src/opnsense/scripts/OPNsense/Ntopng/setup.sh +++ b/net/ntopng/src/opnsense/scripts/OPNsense/Ntopng/setup.sh @@ -7,3 +7,5 @@ chown ntopng:ntopng /var/run/ntopng mkdir -p /var/tmp/ntopng/ chmod 755 /var/tmp/ntopng chown ntopng:wheel /var/tmp/ntopng + +/usr/local/opnsense/scripts/OPNsense/Ntopng/generate_certs.php diff --git a/net/ntopng/src/opnsense/service/conf/actions.d/actions_ntopng.conf b/net/ntopng/src/opnsense/service/conf/actions.d/actions_ntopng.conf index d023859ab..172e64bb7 100644 --- a/net/ntopng/src/opnsense/service/conf/actions.d/actions_ntopng.conf +++ b/net/ntopng/src/opnsense/service/conf/actions.d/actions_ntopng.conf @@ -17,7 +17,7 @@ type:script message:restarting ntopng [status] -command:sh /usr/local/etc/rc.d/ntopng status;exit 0 +command:/usr/local/etc/rc.d/ntopng status; exit 0 parameters: type:script_output message:ntopng status diff --git a/net/ntopng/src/opnsense/service/templates/OPNsense/Ntopng/ntopng.conf b/net/ntopng/src/opnsense/service/templates/OPNsense/Ntopng/ntopng.conf index e9fff19f2..fbb21fb24 100644 --- a/net/ntopng/src/opnsense/service/templates/OPNsense/Ntopng/ntopng.conf +++ b/net/ntopng/src/opnsense/service/templates/OPNsense/Ntopng/ntopng.conf @@ -6,6 +6,9 @@ {% if helpers.exists('OPNsense.ntopng.general.httpport') and OPNsense.ntopng.general.httpport != '' %} -w={{ OPNsense.ntopng.general.httpport }} {% endif %} +{% if helpers.exists('OPNsense.ntopng.general.httpsport') and OPNsense.ntopng.general.httpsport != '' %} +-W={{ OPNsense.ntopng.general.httpsport }} +{% endif %} {% if helpers.exists('OPNsense.ntopng.general.dnsmode') and OPNsense.ntopng.general.dnsmode != '' %} -n={{ OPNsense.ntopng.general.dnsmode }} {% endif %}