From e27f0eaa1e79c089559505842b23b6671e8f3ad2 Mon Sep 17 00:00:00 2001 From: Fabian Franz BSc Date: Mon, 23 Jul 2018 22:52:25 +0200 Subject: [PATCH] www/nginx: some bugfixes; add a rule for the upcoming naxsi release; add restart action to acme (#742) * www/nginx: some bugfixes; add a rule for the upcoming naxsi release * www/nginx: theme the two other error pages like the waf error page * security/acme-client: allow to restart nginx (if installed) * add .idea to gitignore * bump versions and upcase nginx --- .gitignore | 2 + net/haproxy/Makefile | 2 +- .../models/OPNsense/AcmeClient/AcmeClient.xml | 1 + .../OPNsense/AcmeClient/certhelper.php | 7 ++- www/nginx/Makefile | 2 +- .../etc/nginx/views/opnsense_error_404.html | 44 +++++++++++++++++-- .../nginx/views/opnsense_server_error.html | 44 +++++++++++++++++-- .../templates/OPNsense/Nginx/naxsirule.conf | 18 ++++---- .../templates/OPNsense/Nginx/php-www.conf | 3 ++ .../templates/OPNsense/Nginx/ruleset.conf | 1 + 10 files changed, 104 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 2b2c3a7c8..b4b781414 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ */*/work *.pyc +.idea/ + diff --git a/net/haproxy/Makefile b/net/haproxy/Makefile index a0087958b..1dc057c91 100644 --- a/net/haproxy/Makefile +++ b/net/haproxy/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= haproxy -PLUGIN_VERSION= 2.7 +PLUGIN_VERSION= 2.8 PLUGIN_REVISION= 2 PLUGIN_COMMENT= Reliable, high performance TCP/HTTP load balancer PLUGIN_DEPENDS= haproxy-devel diff --git a/security/acme-client/src/opnsense/mvc/app/models/OPNsense/AcmeClient/AcmeClient.xml b/security/acme-client/src/opnsense/mvc/app/models/OPNsense/AcmeClient/AcmeClient.xml index a5b52262a..4ee6b1ff5 100644 --- a/security/acme-client/src/opnsense/mvc/app/models/OPNsense/AcmeClient/AcmeClient.xml +++ b/security/acme-client/src/opnsense/mvc/app/models/OPNsense/AcmeClient/AcmeClient.xml @@ -677,6 +677,7 @@ Restart OPNsense Web UI Restart HAProxy (OPNsense plugin) + Restart Nginx (OPNsense plugin) System or Plugin Command (select below) diff --git a/security/acme-client/src/opnsense/scripts/OPNsense/AcmeClient/certhelper.php b/security/acme-client/src/opnsense/scripts/OPNsense/AcmeClient/certhelper.php index ee2220ee8..9ab17b7be 100755 --- a/security/acme-client/src/opnsense/scripts/OPNsense/AcmeClient/certhelper.php +++ b/security/acme-client/src/opnsense/scripts/OPNsense/AcmeClient/certhelper.php @@ -1056,8 +1056,8 @@ function import_certificate($certObj, $modelObj) // Write changes to config // TODO: Legacy code, should be replaced with code from OPNsense framework - write_config("${import_log_message} Let's Encrypt SSL certificate: ${cert_cn}"); - log_error("AcmeClient: ${import_log_message} Let's Encrypt SSL certificate: ${cert_cn}"); + write_config("${import_log_message} Let's Encrypt X.509 certificate: ${cert_cn}"); + log_error("AcmeClient: ${import_log_message} Let's Encrypt X.509 certificate: ${cert_cn}"); // Update (acme) certificate object (through MVC framework) $uuid = $certObj->attributes()->uuid; @@ -1138,6 +1138,9 @@ function run_restart_actions($certlist, $modelObj) case 'restart_haproxy': $response = $backend->configdRun("haproxy restart"); break; + case 'restart_nginx': + $response = $backend->configdRun("nginx restart"); + break; case 'configd': // Make sure a configd command was specified. if (empty((string)$action->configd)) { diff --git a/www/nginx/Makefile b/www/nginx/Makefile index 849242b50..c4529bdc5 100644 --- a/www/nginx/Makefile +++ b/www/nginx/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= nginx -PLUGIN_VERSION= 0.2 +PLUGIN_VERSION= 0.3 PLUGIN_COMMENT= Nginx HTTP server and reverse proxy PLUGIN_DEPENDS= nginx PLUGIN_MAINTAINER= franz.fabian.94@gmail.com diff --git a/www/nginx/src/etc/nginx/views/opnsense_error_404.html b/www/nginx/src/etc/nginx/views/opnsense_error_404.html index 54200472c..274bd281a 100644 --- a/www/nginx/src/etc/nginx/views/opnsense_error_404.html +++ b/www/nginx/src/etc/nginx/views/opnsense_error_404.html @@ -8,16 +8,52 @@ -

Not Found

-

The resource you want to access is not available.

-

Please contact the webmaster if you think this is an error.

+

Not Found

+

The resource you want to access is not available.

+

Please contact the webmaster if you think this is an error.

+
+ diff --git a/www/nginx/src/etc/nginx/views/opnsense_server_error.html b/www/nginx/src/etc/nginx/views/opnsense_server_error.html index 6a3267f4a..293d9ae83 100644 --- a/www/nginx/src/etc/nginx/views/opnsense_server_error.html +++ b/www/nginx/src/etc/nginx/views/opnsense_server_error.html @@ -8,16 +8,52 @@ -

Server Error

-

Sorry, but something went wrong on our side.

-

There is nothing you can do except waiting until we fix the issue.

+

Server Error

+

Sorry, but something went wrong on our side.

+

There is nothing you can do except waiting until we fix the issue.

+
+ diff --git a/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/naxsirule.conf b/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/naxsirule.conf index bc543f3fa..4a279bd8e 100644 --- a/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/naxsirule.conf +++ b/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/naxsirule.conf @@ -47,15 +47,17 @@ {% if naxsi_ruletype == 'basic' %} {# current policy in loop is available as custom_policy, the uuid as custom_policy_uuid #} -{% for naxsi_rule_uuid in custom_policy.naxsi_rules.split(',') %} -{% if naxsi_rule_uuid not in added_policies %} -{% set basic_rule = helpers.getUUID(naxsi_rule_uuid) %} -{% if basic_rule.ruletype == 'basic' %} -{{ naxsi_rule(custom_policy_uuid, basic_rule, "BasicRule") }} -{% do added_policies.append(naxsi_rule_uuid) %} +{% if custom_policy.naxsi_rules is defined %} +{% for naxsi_rule_uuid in custom_policy.naxsi_rules.split(',') %} +{% if naxsi_rule_uuid not in added_policies %} +{% set basic_rule = helpers.getUUID(naxsi_rule_uuid) %} +{% if basic_rule.ruletype == 'basic' %} +{{ naxsi_rule(custom_policy_uuid, basic_rule, "BasicRule") }} +{% do added_policies.append(naxsi_rule_uuid) %} +{% endif %} {% endif %} -{% endif %} -{% endfor %} +{% endfor %} +{% endif %} {% endif %} {% if naxsi_ruletype == 'main' %} {{ naxsi_rule(custom_policy_uuid, main_rule, "MainRule") }} diff --git a/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/php-www.conf b/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/php-www.conf index 30547aacd..39b9cb982 100644 --- a/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/php-www.conf +++ b/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/php-www.conf @@ -3,6 +3,9 @@ user = www group = www listen = /var/run/php-www.socket +listen.owner = www +listen.group = www +listen.mode = 0660 pm = dynamic pm.max_children = 5 pm.start_servers = 2 diff --git a/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/ruleset.conf b/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/ruleset.conf index d08db7a21..c43533e8f 100644 --- a/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/ruleset.conf +++ b/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/ruleset.conf @@ -1,3 +1,4 @@ +MainRule wl:19; {% set naxsi_ruletype = 'main' %} {% set main_policies = [] %} {% set main_rules = [] %}