diff --git a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/SettingsController.php b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/SettingsController.php index 90149dd97..aefcc98de 100644 --- a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/SettingsController.php +++ b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/SettingsController.php @@ -29,12 +29,23 @@ namespace OPNsense\Nginx\Api; use OPNsense\Base\ApiMutableModelControllerBase; +use OPNsense\Core\Backend; class SettingsController extends ApiMutableModelControllerBase { static protected $internalModelClass = '\OPNsense\Nginx\Nginx'; static protected $internalModelName = 'nginx'; + // download rules + public function downloadrulesAction() + { + if (!$this->request->isPost()) { + return array('error' => 'Must be called via POST'); + } + $backend = new Backend(); + return array('result' => trim($backend->configdRun('nginx naxsidownloadrules'))); + } + // User List public function searchuserlistAction() diff --git a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/IndexController.php b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/IndexController.php index f6cb0cb11..257d51da8 100644 --- a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/IndexController.php +++ b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/IndexController.php @@ -57,6 +57,9 @@ class IndexController extends \OPNsense\Base\IndexController $this->view->limit_request_connection = $this->getForm("limit_request_connection"); $this->view->limit_zone = $this->getForm("limit_zone"); $this->view->cache_path = $this->getForm("cache_path"); + $nginx = new Nginx(); + $this->view->show_naxsi_download_button = + count($nginx->custom_policy->__items) == 0 && count($nginx->naxsi_rule->__items) == 0; $this->view->pick('OPNsense/Nginx/index'); } diff --git a/www/nginx/src/opnsense/mvc/app/views/OPNsense/Nginx/index.volt b/www/nginx/src/opnsense/mvc/app/views/OPNsense/Nginx/index.volt index 705e9aef4..648c7fa6d 100644 --- a/www/nginx/src/opnsense/mvc/app/views/OPNsense/Nginx/index.volt +++ b/www/nginx/src/opnsense/mvc/app/views/OPNsense/Nginx/index.volt @@ -38,7 +38,7 @@ $( document ).ready(function() { }); // update history on tab state and implement navigation - if(window.location.hash != "") { + if(window.location.hash !== "") { $('a[href="' + window.location.hash + '"]').click() } $('.nav-tabs a').on('shown.bs.tab', function (e) { @@ -56,8 +56,8 @@ $( document ).ready(function() { // form save event handlers for all defined forms $('[id*="save_"]').each(function(){ $(this).click(function() { - var frm_id = $(this).closest("form").attr("id"); - var frm_title = $(this).closest("form").attr("data-title"); + let frm_id = $(this).closest("form").attr("id"); + let frm_title = $(this).closest("form").attr("data-title"); // save data for General TAB saveFormToEndpoint(url="/api/nginx/settings/set", formid=frm_id, callback_ok=function(){ // on correct save, perform reconfigure. set progress animation when reloading @@ -67,7 +67,7 @@ $( document ).ready(function() { // when done, disable progress animation. $("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse"); - if (data != undefined && (status != "success" || data['status'] != 'ok')) { + if (data !== undefined && (status !== "success" || data['status'] !== 'ok')) { // fix error handling BootstrapDialog.show({ type:BootstrapDialog.TYPE_WARNING, @@ -105,6 +105,33 @@ $( document ).ready(function() { } ); }); + let naxsi_rule_download_button = $('#naxsiruledownloadbtn'); + naxsi_rule_download_button.click(function () { + BootstrapDialog.show({ + type: BootstrapDialog.TYPE_INFO, + title: "{{ lang._('Download NAXSI Rules') }}", + message: "{{ lang._('You are about to download the core rules from the Repository of NAXSI. You have to accept its %slicense%s to download the rules.')|format("", "") }}", + buttons: [{ + label: "{{ lang._('Accept And Download') }}", + cssClass: 'btn-primary', + icon: 'fa fa-download', + action: function(dlg){ + dlg.close(); + ajaxCall(url="/api/nginx/settings/downloadrules", sendData={}, callback=function(data,status) { + $('#naxsiruledownloadalert').hide(); + // reload view after installing rules + $('#grid-naxsirule').bootgrid('reload'); + $('#grid-custompolicy').bootgrid('reload'); + }); + } + }, { + label: '{{ lang._('Reject') }}', + action: function(dlg){ + dlg.close(); + } + }] + }); + }); }); @@ -122,7 +149,7 @@ $( document ).ready(function() { {{ lang._('HTTP(S)')}} + style="border-right:0;">{{ lang._('HTTP(S)')}}