diff --git a/README.md b/README.md index 0bad17f66..3bfcdd5b6 100644 --- a/README.md +++ b/README.md @@ -1,111 +1,176 @@ -

- -

- - - - - - - -

+# open-appsec NPM Proxy Manager integration (beta) -This project comes as a pre-built docker image that enables you to easily forward to your websites -running at home or otherwise, including free SSL, without having to know too much about Nginx or Letsencrypt. +This is the repository for the beta release of the new integration of open-appsec WAF with NGINX Proxy Manager. +This will allow NGINX Proxy Manager (NPM) users to protect their web applications and web APIs exposed by NGINX Proxy Manager by easily activating and configuring open-appsec protection for each of the configured Proxy Host objects in NPM directly from the NPM Web UI and also to monitor security events. +This new integration of open-appsec WAF with NGINX Proxy Manager not only closes the security gap caused by the soon end-of-life ModSecurity WAF, but provides a modern, strong protection alternative in form of open-appsec, a preemptive, machine-learning based, fully automatic WAF that does not rely on signatures at all. -- [Quick Setup](#quick-setup) -- [Full Setup](https://nginxproxymanager.com/setup/) -- [Screenshots](https://nginxproxymanager.com/screenshots/) +### NGINX Proxy Manager +Nginx Proxy Manager is a popular open-source project that simplifies the management of NGINX reverse proxy configurations, offering a user-friendly web-based interface for easy setup and maintenance. It was created by “jc21” (https://www.jc21.com). +This project is particularly useful for individuals and organizations looking to streamline the deployment of web applications and services by efficiently managing multiple domains and subdomains through a centralized interface. +With NGINX Proxy Manager, users can effortlessly create and manage SSL certificates, enabling secure HTTPS connections for their applications, while also providing advanced features such as Let's Encrypt integration for automated certificate renewal. +NGINX Proxy Manager (NPM) is based on NGINX and provided as a container image that can be easily deployed in containerized environments like Docker (typically using Docker Compose) or others. +NPM itself does not include any WAF solution for effective Threat Prevention against modern attacks or Zero-day attacks. -## Project Goal +Website and Docs: https://nginxproxymanager.com +Github: https://github.com/NginxProxyManager -I created this project to fill a personal need to provide users with a easy way to accomplish reverse -proxying hosts with SSL termination and it had to be so easy that a monkey could do it. This goal hasn't changed. -While there might be advanced options they are optional and the project should be as simple as possible -so that the barrier for entry here is low. +### open-appsec WAF: -Buy Me A Coffee +open-appsec WAF provides automatic, preemptive threat prevention for reverse proxies like NGINX. It is machine learning based, which means it doesn’t require signatures (or updating them) at all. This enables it to provide state-of-the-art threat prevention even for true zero-day attacks while significantly reducing both, administrative effort as well as the amount of false-positives. +open-appsec therefore is a great fit to provide advanced threat prevention to the services exposed by NGINX Proxy Manager. +Website: https://www.openappsec.io +Github: https://github.com/openappsec +Docs: https://docs.openappsec.io -## Features +### Integration of open-appsec WAF with NGINX Proxy Manager: -- Beautiful and Secure Admin Interface based on [Tabler](https://tabler.github.io/) -- Easily create forwarding domains, redirections, streams and 404 hosts without knowing anything about Nginx -- Free SSL using Let's Encrypt or provide your own custom SSL certificates -- Access Lists and basic HTTP Authentication for your hosts -- Advanced Nginx configuration available for super users -- User management, permissions and audit log +With this integration we are focusing on maximum simplicity for the user to maintain the low entry barrier as a key design principle of the NGINX proxy manager (NPM) project, which we want in the same way to apply also to the addition of open-appsec. +The actual deployment of NPM with open-appsec is performed using a slightly enhanced docker compose file (see below) which also adds the open-appsec agent container to it, which will perform the actual security inspection. +The NGINX proxy manager container deployed as part of the docker compose is using the “open-appsec-npm” image, provided by the open-appsec team, which is based on the regular NPM code but also adds the open-appsec attachment to it as an NGINX module. This attachment enables the connection between the NGINX and the open-appsec agent and provides the HTTP data for inspection to the Agent. +The “open-appsec-npm” container also contains various NPM WebUI enhancements and the integration logic allowing the configuration, administration and monitoring of open-appsec. -## Hosting your home network +You can read more about open-appsec’s Technology here: +https://www.openappsec.io/tech -I won't go in to too much detail here but here are the basics for someone new to this self-hosted world. +After successful deployment you can then activate and configure open-appsec directly from the enhanced NPM Web UI interface to which the most relevant configuration options for the open-appsec WAF as well as an option to view the open-appsec logs have been added. -1. Your home router will have a Port Forwarding section somewhere. Log in and find it -2. Add port forwarding for port 80 and 443 to the server hosting this project -3. Configure your domain name details to point to your home, either with a static ip or a service like DuckDNS or [Amazon Route53](https://github.com/jc21/route53-ddns) -4. Use the Nginx Proxy Manager as your gateway to forward to your other web based services +The resulting architecture with the open-appsec Agent container and the NGINX Proxy Manager container then looks like this: -## Quick Setup +![image](https://github.com/openappsec/open-appsec-npm/assets/126462046/db4af2d7-c298-4370-899a-0d1d48504d6d) -1. Install Docker and Docker-Compose +Documentation: https://docs.openappsec.io/integrations/nginx-proxy-manager-integration -- [Docker Install documentation](https://docs.docker.com/install/) -- [Docker-Compose Install documentation](https://docs.docker.com/compose/install/) - -2. Create a docker-compose.yml file similar to this: +# Deployment Step-by-Step: +Before you start, make sure to have a Linux environment with Docker and Docker Compose suitable with version 3.3 available. +To deploy NGINX Proxy Manager with open-appsec integration follow the steps below: +1. Within the directory which you want to use for the deployment: +Create a folder appsec-localconfig which will hold the appsec declarative configuration file (this will be managed by the enhanced NPM WebUI) +``` +mkdir ./appsec-localconfig +``` +2. Download the initial declarative configuration file for open-appsec into that folder. +This will be managed from the NPM WebUI. +``` +wget https://raw.githubusercontent.com/openappsec/open-appsec-npm/main/deployment/local_policy.yaml -O ./appsec-localconfig/local_policy.yaml +``` +3. Create a docker-compose.yaml file with the content below, it can be downloaded as follows: +``` +wget https://raw.githubusercontent.com/openappsec/open-appsec-npm/main/deployment/docker-compose.yaml +``` +4. Edit the docker-compose.yaml file and replace "user@email.com" with your own email address, so we can provide assistance in case of any issues with the specific deployment in the future and provide information proactively regarding open-appsec. +This is an optional parameter and can be removed. If we send automatic emails there will also be an opt-out option included for receiving similar communication in the future." -```yml -version: '3.8' -services: - app: - image: 'jc21/nginx-proxy-manager:latest' - restart: unless-stopped - ports: - - '80:80' - - '81:81' - - '443:443' - volumes: - - ./data:/data - - ./letsencrypt:/etc/letsencrypt +6. Run docker-compose up to start the deployment of all relevant containers: +``` +docker-compose up -d ``` +6. Check if the nginx-proxy-manager-attachment and the appsec-agent containers are up and running: +``` +docker ps +``` +Congratulations, now you are all set and you can login with your web browser to the WebUI of NGINX Proxy Manager with open-appsec integration as follows: +``` +http://[hostname or IP of your host]:81 +``` +![image](https://github.com/openappsec/open-appsec-npm/assets/126462046/685d8f60-4dc3-4a83-9844-1b52d5d5062e) -This is the bare minimum configuration required. See the [documentation](https://nginxproxymanager.com/setup/) for more. -3. Bring up your stack by running +At first login please use the following default administrator user credentials: -```bash -docker-compose up -d +E-mail address: admin@example.com +Password: changeme -# If using docker-compose-plugin -docker compose up -d +You will then be prompted to provide your own user details and asked to change the password, before being presented with the NGINX Proxy Manager Dashboard view: -``` +![image](https://github.com/openappsec/open-appsec-npm/assets/126462046/077536bb-9764-48d5-a1ac-50fc593db402) + +# Configuration +To learn how to use NGINX Proxy Manager (NPM) please see project documentation, as NPM usage and configuration will not be explained here: +https://nginx-proxy-manager.com + +Once you created a new Proxy Host within NGINX Proxy Manager WebUI you can now easily enable and configure open-appsec protection (see also screenshot below): +1. Enable open-appsec by flipping the “open-appsec” switch to enabled. +2. Select the Enforcement Mode, it can be either “Prevent-Learn” or “Detect-Learn” +3. Select the minimum confidence level for open-appsec to prevent an attack (only relevant when in prevent mode), it can be either “Critical”, “High” or “Medium” confidence. +4. Click “Save” + +![image](https://github.com/openappsec/open-appsec-npm/assets/126462046/d9b6d6b6-0ae5-414f-9546-b78d8a061a53) -4. Log in to the Admin UI +This screenshot for example shows a “Proxy Host” reverse proxy configuration in NPM that will listen to inbound traffic for hostnames “100.25.161.101”, “localhost” or “my.webserver.com”. +This “Proxy Host” has open-appsec enabled in “Prevent-Learn” mode and therefore will prevent incoming http or https requests when there’s a minimum confidence level of “High” or higher, as configured for the “Minimum confidence for prevent” setting. +Non-malicious traffic will then be proxied using “http” protocol to the configured backend webserver with the IP address “192.168.160.2” on port “80”. -When your docker container is running, connect to it on port `81` for the admin interface. -Sometimes this can take a little bit because of the entropy of keys. +Note: Changes in the open-appsec configuration performed and saved in the NPM Web UI can take up to 30 seconds before they become effective. -[http://127.0.0.1:81](http://127.0.0.1:81) +This was just a very basic overview to get you started, there's many more things you can configure as part of the open-appsec NGINX Proxy Manager integration. -Default Admin User: +If you want to check out the open-appsec Security Logs click on the new menu option “Security Log” which allows you to view the open-appsec specific logs directly from the NPM Web UI: +![image](https://github.com/openappsec/open-appsec-npm/assets/126462046/76b9eec3-1125-428a-99c3-7c183da9a658) + + +**You find the full documentation including FAQ here: +https://docs.openappsec.io/integrations/nginx-proxy-manager-integration/** + +# Compilation Instructions + +**Important: In order to deploy and use the open-appsec NGINX Proxy Manager integration you do not have to compile the code yourself.** +We offer a pre-compiled ready-to-use "open-appsec-npm" container (see above in the "Deployment" section). + +## Prerequisites +- Linux Machine with Docker engine deployed + +## Additional perquisites for compiling against other NGINX Proxy Manager version +Precompiled libraries for open-appsec Attachment for the specific version of NGINX Proxy Manager you want to compile agasint. +You find the detailed compilation instructions in this repo: https://github.com/openappsec/attachment + +Make sure to compile the attachment using a container with the exact same OS version as used in the NPM container version you want to build the integration upon and provide also the NGINX version information from that container. +libngx_module.so libosrc_compression_utils.so libosrc_nginx_attachment_util.so libosrc_shmem_ipc.so + +## Preparations +Clone this repository to your local Linux machine: ``` -Email: admin@example.com -Password: changeme +git clone https://github.com/openappsec/open-appsec-npm.git ``` -Immediately after logging in with this default user you will be asked to modify your details and change your password. +Change into the open-appsec-npm directory: +``` +cd open-appsec-npm +``` +### If you are compiling against other NGINX proxy Manager version +Replace the files in the ```docker/lib``` folder with the libraries you've precompiled. + +Compilation - Build the Frontend: +--- +``` +cd scripts/ci +bash frontend-build +``` + +Build the open-appsec-npm Container Image: +-- +``` +cd ../.. +docker buildx build --load -t open-appsec-npm -f docker/Dockerfile . +``` +**Congratulations, you have successfully built your own open-appsec-npm container.** +You can deploy it now by specifying it within the docker-compose.yaml file. +You find the deployment instructions above in the "Deployment" section. +If you also want to build your own open-appsec Agent container you find the instructions in this repo: +https://github.com/openappsec/openappsec -## Contributors +# Contributing +We welcome everyone that wishes to share their knowledge and expertise to enhance and expand this project. -Special thanks to [all of our contributors](https://github.com/NginxProxyManager/nginx-proxy-manager/graphs/contributors). +Please see the [Contributing Guidelines](https://github.com/openappsec/openappsec-npm/blob/main/CONTRIBUTING.md). +# Final notes -## Getting Support +We hope this integration will be useful for you and provide you easy-to-configure yet highly effective protection based on open-appsec for your web services or web APIs against known and especially unknown, zero day attacks! -1. [Found a bug?](https://github.com/NginxProxyManager/nginx-proxy-manager/issues) -2. [Discussions](https://github.com/NginxProxyManager/nginx-proxy-manager/discussions) -3. [Development Gitter](https://gitter.im/nginx-proxy-manager/community) -4. [Reddit](https://reddit.com/r/nginxproxymanager) +If you have any questions, feedback or need assistance with some issue you can +- contact us at info@openappsec.io +- contact us using the chat on our project website https://www.openappsec.io +- open an issue in the GitHub project diff --git a/backend/internal/nginx-openappsec.js b/backend/internal/nginx-openappsec.js new file mode 100755 index 000000000..c29a38a99 --- /dev/null +++ b/backend/internal/nginx-openappsec.js @@ -0,0 +1,314 @@ +const util = require('util'); +const execPromise = util.promisify(require('child_process').exec); +const { exec } = require('child_process'); +const _ = require('lodash'); +const fs = require('fs'); +const logger = require('../logger').nginx; +const config = require('../lib/config'); +const yaml = require('js-yaml'); +const path = require('path'); +const constants = require('../lib/constants'); + +const internalNginxOpenappsec = { + + // module constants + CONFIG_TEMPLATE_FILE_NAME: 'local-policy-open-appsec-enabled-for-proxy-host.yaml', + CONFIG_TEMPLATE_DIR: '/app/templates', + + // module variables + config: null, + configTemplate: null, + + /** + * Generate an open-appsec config file for a proxy host. + * + * @param {Object} access + * @param {Object} row + * @param {Object} data + * @returns {Promise} + */ + generateConfig: (access, row, data) => { + return access.can('settings:update', row.id) + .then(() => { + if (config.debug()) { + logger.info('Generating openappsec config:', JSON.stringify(data, null, 2)); + } + + const openappsecMode = data.use_openappsec == false ? 'inactive' : data.openappsec_mode; + + const configTemplateFilePath = path.join(internalNginxOpenappsec.CONFIG_TEMPLATE_DIR, internalNginxOpenappsec.CONFIG_TEMPLATE_FILE_NAME) + const configFilePath = path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME); + + let openappsecConfig = yaml.load(fs.readFileSync(configFilePath, 'utf8')); + let openappsecConfigTemplate = yaml.load(fs.readFileSync(configTemplateFilePath, 'utf8')); + + internalNginxOpenappsec.config = openappsecConfig; + internalNginxOpenappsec.configTemplate = openappsecConfigTemplate; + + const specificRuleName = 'npm-managed-specific-rule-proxyhost-' + row.id; + const logTriggerName = 'npm-managed-log-trigger-proxyhost-' + row.id; + const practiceName = 'npm-managed-practice-proxyhost-' + row.id; + + _.remove(openappsecConfig.policies['specific-rules'], rule => rule.name === specificRuleName || rule.name.startsWith(`${specificRuleName}.`)); + + data.domain_names.forEach((domain, index) => { + let ruleName = index > 0 ? `${specificRuleName}.${index}` : specificRuleName; + let specificRuleNode = { + host: domain, + name: ruleName, + triggers: [logTriggerName], + mode: openappsecMode, + practices: [practiceName] + }; + internalNginxOpenappsec.updateNode('policies', 'specific-rules', specificRuleNode, openappsecMode); + }); + + internalNginxOpenappsec.updateNode('', 'practices', { name: practiceName, 'web-attacks.override-mode': openappsecMode, 'web-attacks.minimum-confidence': data.minimum_confidence }, openappsecMode); + internalNginxOpenappsec.updateNode('', 'log-triggers', { name: logTriggerName }, openappsecMode); + + // remove all openappsec managed location config nodes for a proxy host. + let pattern = new RegExp(`^npm-managed.*-${row.id}-.*`); + internalNginxOpenappsec.removeMatchingNodes(openappsecConfig, pattern); + + // for each data.location, create location config nodes + data.locations.forEach((location, index) => { + let locationSpecificRuleName = 'npm-managed-specific-rule-proxyhost-' + row.id + '-' + index; + let locationLogTriggerName = 'npm-managed-log-trigger-proxyhost-' + row.id + '-' + index; + let locationPracticeName = 'npm-managed-practice-proxyhost-' + row.id + '-' + index; + + let locationOpenappsecMode = location.use_openappsec == false ? 'inactive' : location.openappsec_mode; + + _.remove(openappsecConfig.policies['specific-rules'], rule => rule.name === locationSpecificRuleName || rule.name.startsWith(`${locationSpecificRuleName}.`)); + + data.domain_names.forEach((domain, index) => { + let locationUrl = domain + location.path; + let ruleName = index > 0 ? `${locationSpecificRuleName}.${index}` : locationSpecificRuleName; + + let domainSpecificRuleNode = { + host: locationUrl, + name: ruleName, + triggers: [locationLogTriggerName], + mode: locationOpenappsecMode, + practices: [locationPracticeName] + }; + internalNginxOpenappsec.updateNode('policies', 'specific-rules', domainSpecificRuleNode, locationOpenappsecMode, 'location', openappsecMode); + }); + + internalNginxOpenappsec.updateNode('', 'practices', { name: locationPracticeName, 'web-attacks.override-mode': locationOpenappsecMode, 'web-attacks.minimum-confidence': location.minimum_confidence }, locationOpenappsecMode, 'location', openappsecMode); + internalNginxOpenappsec.updateNode('', 'log-triggers', { name: locationLogTriggerName }, locationOpenappsecMode, 'location', openappsecMode); + }); + + fs.writeFileSync(configFilePath, yaml.dump(openappsecConfig)); + }, + (err) => { + logger.error('Error generating openappsec config:', err); + return Promise.reject(err); + }) + .then(() => { + // Return the notifyPolicyUpdate promise chain + // notify openappsec to apply the policy + return internalNginxOpenappsec.notifyPolicyUpdate().catch((errorMessage) => { + // console.error('Error:', errorMessage); + const errorMessageForUI = `Error: Policy couldn’t be applied, open-appsec-agent container is not responding. + Check if open-appec-agent container is running, then apply open-appsec Configuration + again by clicking here: +
Settings -> open-appsec Advanced -> Save Settings`; + + return Promise.reject(new Error(errorMessageForUI)); + }); + }); + }, + + /** + * Remove all openappsec managed config nodes for a proxy host. + * + * @param {Object} access + * @param {Object} row + * @returns {Promise} + * + */ + deleteConfig: (access, row) => { + return access.can('settings:update', row.id) + .then(() => { + const configFilePath = path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME); + let openappsecConfig = yaml.load(fs.readFileSync(configFilePath, 'utf8')); + + // remove all openappsec managed location config nodes for a proxy host. + let pattern = new RegExp(`^npm-managed.*-${row.id}`); + internalNginxOpenappsec.removeMatchingNodes(openappsecConfig, pattern); + fs.writeFileSync(configFilePath, yaml.dump(openappsecConfig)); + }) + .then(() => { + // Return the notifyPolicyUpdate promise chain + // notify openappsec to apply the policy + return internalNginxOpenappsec.notifyPolicyUpdate().catch((errorMessage) => { + console.error('---Error:', errorMessage); + const errorMessageForUI = `Error: Policy couldn’t be applied, open-appsec-agent container is not responding. + Check if open-appec-agent container is running, then apply open-appsec Configuration + again by clicking here: +
Settings -> open-appsec Advanced -> Save Settings`; + + return Promise.reject(new Error(errorMessageForUI)); + }); + }) + .catch((err) => { + logger.error('Error deleting openappsec config:', err); + // throw err; // Propagate the error to the caller + }); + }, + + /** + * Update a node in the openappsec config. + * - if the node does not exist, create it. + * - if the node exists, update it. + * - if openappsecMode is 'inactive', delete the node. + * + * @param {String} parentNodePath - path to the parent node. e.g. 'policies'. + * @param {String} nodeName - name of the node. e.g. 'specific-rules', 'practices', 'log-triggers'. + * @param {Object} nodeItemProperties + * @param {String} openappsecMode + * @param {String} nodeType - 'host' or 'location' + * @param {String} hostAppsecMode - to check if the host of a location is inactive. + */ + updateNode: function (parentNodePath, nodeName, nodeItemProperties, openappsecMode, nodeType = 'host', hostAppsecMode = '') { + // if no parent node path is specified, use the root of the config object. + const parent = parentNodePath ? _.get(this.config, parentNodePath, this.config) : this.config; + + if (!parent) { + console.log('parent is not defined'); + return; + } + + let nodeItems = _.find(parent[nodeName], { name: nodeItemProperties.name }); + if (openappsecMode == 'inactive' && nodeItems) { + _.remove(parent[nodeName], { name: nodeItemProperties.name }); + } + + if (openappsecMode !== 'inactive' || nodeType === 'location' && hostAppsecMode !== 'inactive') { + if (!nodeItems) { + // create the node from the template if it does not exist. + let templateSearchPath = parentNodePath ? `${parentNodePath}.${nodeName}[0]` : `${nodeName}[0]`; + nodeItems = _.cloneDeep(_.get(this.configTemplate, templateSearchPath)); + + // update the node with the nodeItemProperties. if the nodeType is 'location' and the openappsecMode is 'inactive', only update the name, host, and the (inactive) mode. + if (nodeType === 'location' && openappsecMode === 'inactive') { + nodeItemProperties = _.pick(nodeItemProperties, ['name', 'host', 'triggers', 'practices', 'mode', 'web-attacks.override-mode']); + } + + Object.keys(nodeItemProperties).forEach(key => { + _.set(nodeItems, key, nodeItemProperties[key]); + }); + parent[nodeName] = parent[nodeName] || []; + parent[nodeName].push(nodeItems); + } else { + // update the node if it exists. + Object.keys(nodeItemProperties).forEach(key => { + _.set(nodeItems, key, nodeItemProperties[key]); + }); + } + } + }, + + notifyPolicyUpdate: async function() { + if (!constants.USE_NOTIFY_POLICY) { + console.log('USE_NOTIFY_POLICY is false'); + return; + } + let ports = constants.PORTS; + let lastError = null; + for (let port of ports) { + try { + const data = `{"policy_path":"${constants.POLICY_PATH}"}`; + const command = `curl -s -o /dev/null -w "%{http_code}" --data '${data}' ${constants.HOSTURL}:${port}/set-apply-policy`; + let { stdout } = await execPromise(command); + if (stdout === '200') { + console.log(`Policy applied successfully on port ${port}`); + return; + } else { + console.log(`Policy Unexpected response code: ${stdout}`); + lastError = new Error(`Unexpected response code: ${stdout}`); + } + } catch (error) { + console.log(`Error notifying openappsec to apply the policy on port ${port}: ${error.message}`); + lastError = error; + } + } + + // if (lastError) { + // throw lastError; + // } + }, + + /** + * Recursively removes nodes from a JavaScript object based on a pattern. + * + * @param {Object|Array} obj - The object or array to remove nodes from. + * @param {RegExp} pattern - The pattern to match against node names. + */ + removeMatchingNodes: function (obj, pattern) { + _.forEach(obj, (value, key) => { + if (_.isPlainObject(value)) { + if (pattern.test(key)) { + delete obj[key]; + } else { + this.removeMatchingNodes(value, pattern); + } + } else if (_.isArray(value)) { + _.remove(value, function (item) { + return _.isPlainObject(item) && pattern.test(item.name); + }); + value.forEach(item => { + if (_.isPlainObject(item)) { + this.removeMatchingNodes(item, pattern); + } + }); + } + }); + }, + + /** + * Get the openappsec mode, use_openappsec and minimum_confidence for a proxy host. + * + * @param {Object} openappsecConfig - openappsec config object + * @param {Number} rowId - proxy host id + * @returns {Object} { mode, use_openappsec, minimum_confidence } + */ + getOpenappsecFields: (openappsecConfig, rowId) => { + const specificRuleName = 'npm-managed-specific-rule-proxyhost-' + rowId; + + const specificRule = _.find(openappsecConfig?.policies['specific-rules'], { name: specificRuleName }); + const mode = specificRule?.mode || 'inactive'; + const use_openappsec = mode !== 'inactive' && mode !== undefined; + + const practiceName = 'npm-managed-practice-proxyhost-' + rowId; + const practice = _.find(openappsecConfig?.practices, { name: practiceName }); + const minimum_confidence = practice?.['web-attacks']['minimum-confidence'] || 'high'; + + return { mode, use_openappsec, minimum_confidence }; + }, + + /** + * get the openappsec config file path. + */ + getConfigFilePath: () => { + const configFilePath = path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME); + return configFilePath; + }, + + /** + * A simple wrapper around unlinkSync that writes to the logger + * + * @param {String} filename + */ + deleteFile: (filename) => { + logger.debug('Deleting file: ' + filename); + try { + fs.unlinkSync(filename); + } catch (err) { + logger.debug('Could not delete file:', JSON.stringify(err, null, 2)); + } + } + +}; + +module.exports = internalNginxOpenappsec; \ No newline at end of file diff --git a/backend/internal/openappsec-log.js b/backend/internal/openappsec-log.js new file mode 100755 index 000000000..dfa770a57 --- /dev/null +++ b/backend/internal/openappsec-log.js @@ -0,0 +1,152 @@ +const fs = require('fs'); +const path = require('path'); +const util = require('util'); +const error = require('../lib/error'); +const { APPSEC_LOG_DIR } = require('../lib/constants'); + +const internalOpenappsecLog = { + + countTotalLines: async function (directoryPath) { + const files = await fs.promises.readdir(directoryPath); + const logFiles = files.filter(file => path.extname(file).startsWith('.log')); + + let totalLineCount = 0; + + for (const file of logFiles) { + const filePath = path.join(directoryPath, file); + + // Read only the first line of the file + const readStream = fs.createReadStream(filePath); + const rl = readline.createInterface({ input: readStream }); + const firstLine = await new Promise(resolve => { + rl.on('line', line => { + rl.close(); + resolve(line); + }); + }); + + // Check if the first line is a non-data line + try { + JSON.parse(firstLine); + } catch (err) { + continue; // Skip this file if the first line is a non-data line + } + + // If the first line is a data line, read the rest of the file + const content = await fs.promises.readFile(filePath, 'utf8'); + const lines = content.split('\n'); + totalLineCount += lines.length; + } + + return totalLineCount; + }, + + processFile: async function (filePath) { + const content = await fs.promises.readFile(filePath, 'utf8'); + const lines = content.split('\n'); + const dataLines = []; + + for (const line of lines) { + try { + const json = JSON.parse(line); + const groupName = path.basename(filePath, path.extname(filePath)); + const wrappedObject = { + source: groupName, + meta: json, + serviceName: json.eventSource.serviceName, + eventPriority: json.eventPriority, + eventSeverity: json.eventSeverity, + eventLevel: json.eventLevel, + eventTime: json.eventTime, + assetName: json.eventSource.assetName, + securityAction: json.eventData.securityAction, + waapIncidentType: json.eventData.waapIncidentType, + httpSourceId: json.eventData.httpSourceId, + sourceIP: json.eventData.sourceIP, + proxyIP: json.eventData.proxyIP, + httpHostName: json.eventData.httpHostName, + httpMethod: json.eventData.httpMethod, + httpUriPath: json.eventData.httpUriPath, + eventTopic: json.eventSource.eventTopic, + matchedLocation: json.eventData.matchedLocation, + matchedParameter: json.eventData.matchedParameter, + matchedSample: json.eventData.matchedSample, + eventName: json.eventName + }; + dataLines.push(wrappedObject); + } catch (err) { + // Ignore lines that don't contain JSON data + } + } + + return dataLines; + }, + + + getAll: function (access, expand, search_query) { + return access.can('auditlog:list') + .then(async () => { + const directoryPath = APPSEC_LOG_DIR; + const files = await fs.promises.readdir(directoryPath); + const logFiles = files.filter(file => path.extname(file).startsWith('.log')); + + // Sort the logFiles array + logFiles.sort((a, b) => { + const baseA = path.basename(a, path.extname(a)); + const baseB = path.basename(b, path.extname(b)); + return baseA.localeCompare(baseB, undefined, { numeric: true, sensitivity: 'base' }); + }); + + const wrappedObjects = []; + for (const file of logFiles) { + const filePath = path.join(directoryPath, file); + const dataLines = await this.processFile(filePath); + wrappedObjects.push(...dataLines); + } + + return wrappedObjects; + }); + }, + + getPage: function (access, expand, search_query, page, perPage) { + return access.can('auditlog:list') + .then(async () => { + const directoryPath = APPSEC_LOG_DIR; + let totalDataLines = await this.countTotalLines(directoryPath); + + const files = await fs.promises.readdir(directoryPath); + const logFiles = files.filter(file => path.extname(file).startsWith('.log')); + + // Sort the logFiles array + logFiles.sort((a, b) => { + const baseA = path.basename(a, path.extname(a)); + const baseB = path.basename(b, path.extname(b)); + return baseA.localeCompare(baseB, undefined, { numeric: true, sensitivity: 'base' }); + }); + + const wrappedObjects = []; + let lineCount = 0; + let start = (page - 1) * perPage; + let end = page * perPage; + + for (const file of logFiles) { + if (lineCount >= end) { + break; + } + + const filePath = path.join(directoryPath, file); + const dataLines = await this.processFile(filePath); + const pageDataLines = dataLines.slice(start - lineCount, end - lineCount); + wrappedObjects.push(...pageDataLines); + lineCount += pageDataLines.length; + } + + return { + data: wrappedObjects, + totalDataLines: totalDataLines, + }; + }); + }, +}; + +module.exports = internalOpenappsecLog; diff --git a/backend/internal/proxy-host.js b/backend/internal/proxy-host.js index 02a98da26..25e4fe8bd 100644 --- a/backend/internal/proxy-host.js +++ b/backend/internal/proxy-host.js @@ -4,8 +4,12 @@ const utils = require('../lib/utils'); const proxyHostModel = require('../models/proxy_host'); const internalHost = require('./host'); const internalNginx = require('./nginx'); +const internalNginxOpenappsec= require('./nginx-openappsec'); const internalAuditLog = require('./audit-log'); const internalCertificate = require('./certificate'); +const fs = require('fs'); +const path = require('path'); +const yaml = require('js-yaml'); function omissions () { return ['is_deleted']; @@ -48,9 +52,15 @@ const internalProxyHost = { data.owner_user_id = access.token.getUserId(1); data = internalHost.cleanSslHstsData(data); + let db_data = _.assign({}, data); + // Remove the openappsec fields from data. they are not in the database. + delete db_data.use_openappsec; + delete db_data.openappsec_mode; + delete db_data.minimum_confidence; + return proxyHostModel .query() - .insertAndFetch(data) + .insertAndFetch(db_data) .then(utils.omitRow(omissions())); }) .then((row) => { @@ -84,6 +94,16 @@ const internalProxyHost = { return row; }); }) + .then(row => { + return internalNginxOpenappsec.generateConfig(access, row, data) + .then(() => { + return row; + }) + .catch((err) => { + console.log("Error generating openappsec config: " + err); + // throw new error.ConfigurationError(err.message); + }); + }) .then((row) => { // Audit log data.meta = _.assign({}, data.meta || {}, row.meta); @@ -159,6 +179,16 @@ const internalProxyHost = { return row; } }) + .then(row => { + return internalNginxOpenappsec.generateConfig(access, row, data) + .then(() => { + return row; + }) + .catch((err) => { + console.log("Error generating openappsec config: " + err); + // throw new error.ConfigurationError(err.message); + }); + }) .then((row) => { // Add domain_names to the data in case it isn't there, so that the audit log renders correctly. The order is important here. data = _.assign({}, { @@ -167,6 +197,11 @@ const internalProxyHost = { data = internalHost.cleanSslHstsData(data, row); + // Remove the openappsec fields from data. they are not in the database + delete data.use_openappsec; + delete data.openappsec_mode; + delete data.minimum_confidence; + return proxyHostModel .query() .where({id: data.id}) @@ -247,6 +282,22 @@ const internalProxyHost = { if (typeof data.omit !== 'undefined' && data.omit !== null) { row = _.omit(row, data.omit); } + return row; + }) + .then((row) => { + // add openappsec fields to row + try { + const configFilePath = internalNginxOpenappsec.getConfigFilePath(access); + const openappsecConfig = yaml.load(fs.readFileSync(configFilePath, 'utf8')); + let result = internalNginxOpenappsec.getOpenappsecFields(openappsecConfig, row.id); + row.use_openappsec = result.use_openappsec; + row.openappsec_mode = result.mode; + row.minimum_confidence = result.minimum_confidence; + } + catch (e) { + console.log("Error reading openappsec config file: " + e); + } + return row; }); }, @@ -274,6 +325,14 @@ const internalProxyHost = { .patch({ is_deleted: 1 }) + .then(() => { + // Delete openappsec config + return internalNginxOpenappsec.deleteConfig(access, row) + .catch((err) => { + throw new error.ConfigurationError(err.message); + }); + + }) .then(() => { // Delete Nginx Config return internalNginx.deleteConfig('proxy_host', row) @@ -430,6 +489,21 @@ const internalProxyHost = { return query.then(utils.omitRows(omissions())); }) .then((rows) => { + // add openappsec fields to rows + try { + const configFilePath = internalNginxOpenappsec.getConfigFilePath(access); + const openappsecConfig = yaml.load(fs.readFileSync(configFilePath, 'utf8')); + rows.map(function (row, idx) { + let result = internalNginxOpenappsec.getOpenappsecFields(openappsecConfig, row.id); + rows[idx].use_openappsec = result.use_openappsec; + rows[idx].openappsec_mode = result.mode; + rows[idx].minimum_confidence = result.minimum_confidence; + }); + } + catch (e) { + console.log("Error reading openappsec config file: " + e); + } + if (typeof expand !== 'undefined' && expand !== null && expand.indexOf('certificate') !== -1) { return internalHost.cleanAllRowsCertificateMeta(rows); } diff --git a/backend/internal/setting-openappsec.js b/backend/internal/setting-openappsec.js new file mode 100755 index 000000000..e009bc9fc --- /dev/null +++ b/backend/internal/setting-openappsec.js @@ -0,0 +1,52 @@ +const fs = require('fs'); +const error = require('../lib/error'); +const path = require('path'); + +const constants = require('../lib/constants'); + +const internalOpenappsecSetting = { + configFilePath: path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME), + + /** + * @param {Access} access + * @return {Promise} + */ + getLocalPolicy: (access) => { + return access.can('settings:list') + .then(() => { + try { + const filePath = internalOpenappsecSetting.configFilePath + if (!fs.existsSync(filePath)) { + return; + } + const fileContent = fs.readFileSync(filePath, 'utf8'); + const jsonStr = JSON.stringify(fileContent); + return jsonStr; + + } catch (err) { + console.error(err); + } + }); + }, + + /** + * @param {Access} access + * @param {Object} data + * @return {Promise} + */ + updateLocalPolicy: (access, data) => { + return access.can('settings:list') + .then(() => { + const filePath = internalOpenappsecSetting.configFilePath + const yamlStr = data.local_policy; + fs.writeFileSync(filePath, yamlStr, {encoding: 'utf8'}); + return true; + }) + .catch((err) => { + console.error(err); + throw new error.ConfigurationError(err.message); + }); + } +}; + +module.exports = internalOpenappsecSetting; diff --git a/backend/lib/constants.js b/backend/lib/constants.js new file mode 100755 index 000000000..7b9618654 --- /dev/null +++ b/backend/lib/constants.js @@ -0,0 +1,9 @@ +module.exports = { + APPSEC_CONFIG_FILE_NAME: 'local_policy.yaml', + APPSEC_EXT_DIR: '/ext/appsec', + APPSEC_LOG_DIR: '/ext/appsec-logs', + USE_NOTIFY_POLICY: true, + PORTS: [7777, 7778], + HOSTURL: 'http://127.0.0.1', + POLICY_PATH: '/etc/cp/conf/local_policy.yaml', +}; \ No newline at end of file diff --git a/backend/package.json b/backend/package.json index e8f582556..fde84012c 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "nginx-proxy-manager", - "version": "0.0.0", + "version": "1.0.0", "description": "A beautiful interface for creating Nginx endpoints", "main": "js/index.js", "dependencies": { @@ -13,6 +13,7 @@ "express": "^4.17.3", "express-fileupload": "^1.1.9", "gravatar": "^1.8.0", + "js-yaml": "^4.1.0", "json-schema-ref-parser": "^8.0.0", "jsonwebtoken": "^9.0.0", "knex": "2.4.2", diff --git a/backend/routes/api/main.js b/backend/routes/api/main.js index 33cbbc21f..5eeea4517 100644 --- a/backend/routes/api/main.js +++ b/backend/routes/api/main.js @@ -29,8 +29,10 @@ router.use('/schema', require('./schema')); router.use('/tokens', require('./tokens')); router.use('/users', require('./users')); router.use('/audit-log', require('./audit-log')); +router.use('/openappsec-log', require('./openappsec-log')); router.use('/reports', require('./reports')); router.use('/settings', require('./settings')); +router.use('/openappsec-settings', require('./openappsec-settings')); router.use('/nginx/proxy-hosts', require('./nginx/proxy_hosts')); router.use('/nginx/redirection-hosts', require('./nginx/redirection_hosts')); router.use('/nginx/dead-hosts', require('./nginx/dead_hosts')); diff --git a/backend/routes/api/openappsec-log.js b/backend/routes/api/openappsec-log.js new file mode 100755 index 000000000..aa70d48d1 --- /dev/null +++ b/backend/routes/api/openappsec-log.js @@ -0,0 +1,35 @@ +const express = require('express'); +const jwtdecode = require('../../lib/express/jwt-decode'); +const internalOpenappsecLog = require('../../internal/openappsec-log'); + +let router = express.Router({ + caseSensitive: true, + strict: true, + mergeParams: true +}); + +/** + * /api/openappsec-log + */ +router + .route('/') + .options((req, res) => { + res.sendStatus(204); + }) + .all(jwtdecode()) + + /** + * GET /api/openappsec-log + * + * Retrieve all logs + */ + .get((req, res, next) => { + return internalOpenappsecLog.getAll(res.locals.access) + .then((policy) => { + res.status(200) + .send(policy); + }) + .catch(next); + }); + +module.exports = router; diff --git a/backend/routes/api/openappsec-settings.js b/backend/routes/api/openappsec-settings.js new file mode 100755 index 000000000..dcda2333b --- /dev/null +++ b/backend/routes/api/openappsec-settings.js @@ -0,0 +1,49 @@ +const express = require('express'); +const jwtdecode = require('../../lib/express/jwt-decode'); +const internalOpenappsecSetting = require('../../internal/setting-openappsec'); + +let router = express.Router({ + caseSensitive: true, + strict: true, + mergeParams: true +}); + +/** + * /api/openappsec-settings + */ +router + .route('/') + .options((req, res) => { + res.sendStatus(204); + }) + .all(jwtdecode()) + + /** + * GET /api/openappsec-settings + * + * Retrieve the open-appsec local policy. + */ + .get((req, res, next) => { + return internalOpenappsecSetting.getLocalPolicy(res.locals.access) + .then((policy) => { + res.status(200) + .send(policy); + }) + .catch(next); + }) + + /** + * PUT /api/openappsec-settings + * + * Update the open-appsec local policy. + */ + .put((req, res, next) => { + return internalOpenappsecSetting.updateLocalPolicy(res.locals.access, req.body) + .then((result) => { + res.status(200) + .send(result); + }) + .catch(next); + }); + +module.exports = router; diff --git a/backend/schema/definitions.json b/backend/schema/definitions.json index 4b4f3405c..b3c87b57b 100644 --- a/backend/schema/definitions.json +++ b/backend/schema/definitions.json @@ -137,6 +137,18 @@ } ] }, + "openappsec_mode": { + "description": "openappsec_mode ID", + "type": "string", + "minLength": 1, + "maxLength": 255 + }, + "minimum_confidence": { + "description": "minimum_confidence ID", + "type": "string", + "minLength": 1, + "maxLength": 255 + }, "access_list_id": { "description": "Access List ID", "example": 1234, @@ -231,6 +243,11 @@ "example": true, "type": "boolean" }, + "use_openappsec": { + "description": "Use openappsec", + "example": true, + "type": "boolean" + }, "caching_enabled": { "description": "Should we cache assets", "example": true, diff --git a/backend/schema/endpoints/proxy-hosts.json b/backend/schema/endpoints/proxy-hosts.json index 9a3fff2fc..029fd61f1 100644 --- a/backend/schema/endpoints/proxy-hosts.json +++ b/backend/schema/endpoints/proxy-hosts.json @@ -50,6 +50,15 @@ "block_exploits": { "$ref": "../definitions.json#/definitions/block_exploits" }, + "use_openappsec": { + "$ref": "../definitions.json#/definitions/use_openappsec" + }, + "openappsec_mode": { + "$ref": "../definitions.json#/definitions/openappsec_mode" + }, + "minimum_confidence": { + "$ref": "../definitions.json#/definitions/minimum_confidence" + }, "caching_enabled": { "$ref": "../definitions.json#/definitions/caching_enabled" }, @@ -104,6 +113,15 @@ }, "advanced_config": { "type": "string" + }, + "use_openappsec": { + "type": "boolean" + }, + "openappsec_mode": { + "type": "string" + }, + "minimum_confidence": { + "type": "string" } } } @@ -149,6 +167,15 @@ "block_exploits": { "$ref": "#/definitions/block_exploits" }, + "use_openappsec": { + "$ref": "#/definitions/use_openappsec" + }, + "openappsec_mode": { + "$ref": "#/definitions/openappsec_mode" + }, + "minimum_confidence": { + "$ref": "#/definitions/minimum_confidence" + }, "caching_enabled": { "$ref": "#/definitions/caching_enabled" }, @@ -239,6 +266,15 @@ "block_exploits": { "$ref": "#/definitions/block_exploits" }, + "use_openappsec": { + "$ref": "#/definitions/use_openappsec" + }, + "openappsec_mode": { + "$ref": "#/definitions/openappsec_mode" + }, + "minimum_confidence": { + "$ref": "#/definitions/minimum_confidence" + }, "caching_enabled": { "$ref": "#/definitions/caching_enabled" }, @@ -312,6 +348,15 @@ "block_exploits": { "$ref": "#/definitions/block_exploits" }, + "use_openappsec": { + "$ref": "#/definitions/use_openappsec" + }, + "openappsec_mode": { + "$ref": "#/definitions/openappsec_mode" + }, + "minimum_confidence": { + "$ref": "#/definitions/minimum_confidence" + }, "caching_enabled": { "$ref": "#/definitions/caching_enabled" }, diff --git a/backend/templates/local-policy-open-appsec-enabled-for-proxy-host.yaml b/backend/templates/local-policy-open-appsec-enabled-for-proxy-host.yaml new file mode 100755 index 000000000..6b560b3f8 --- /dev/null +++ b/backend/templates/local-policy-open-appsec-enabled-for-proxy-host.yaml @@ -0,0 +1,122 @@ +# This example is for NPM Proxy Host with open-appsec enabled, +# Enforcement Mode set to Prevent/Learn, hostname web.server.com/example + +policies: + default: + triggers: + - appsec-default-log-trigger + mode: inactive + practices: + - webapp-default-practice + custom-response: appsec-default-web-user-response + specific-rules: + - host: web.server.com/example + # as set in "Edit Proxy Host" in "Domain Names" field + # IMPORTANT LIMITATION: Currently open-appsec declarative with CRD version 1.0 only supports single host entry per specific rule + # This will be resolved with new CRDs 2.0 + name: npm-managed-specific-rule-proxyhost-1 + # This “name” key will be the actual reference to a specific Reverse Proxy object defined in NPM + triggers: + - npm-managed-log-trigger-proxyhost-1 + mode: prevent-learn + practices: + - npm-managed-practice-proxyhost-1 + +practices: + - name: webapp-default-practice + web-attacks: + max-body-size-kb: 1000000 + max-header-size-bytes: 102400 + max-object-depth: 40 + max-url-size-bytes: 32768 + minimum-confidence: high + override-mode: inactive + protections: + csrf-protection: inactive + error-disclosure: inactive + non-valid-http-methods: false + open-redirect: inactive + anti-bot: + injected-URIs: [] + validated-URIs: [] + override-mode: inactive + snort-signatures: + configmap: [] + override-mode: inactive + openapi-schema-validation: + configmap: [] + override-mode: inactive + + - name: npm-managed-practice-proxyhost-1 + web-attacks: + max-body-size-kb: 1000000 + max-header-size-bytes: 102400 + max-object-depth: 40 + max-url-size-bytes: 32768 + minimum-confidence: high + override-mode: inactive + protections: + csrf-protection: inactive + error-disclosure: inactive + non-valid-http-methods: false + open-redirect: inactive + anti-bot: + injected-URIs: [] + validated-URIs: [] + override-mode: inactive + snort-signatures: + configmap: [] + override-mode: inactive + openapi-schema-validation: + configmap: [] + override-mode: inactive + +log-triggers: + - name: appsec-default-log-trigger + access-control-logging: + allow-events: false + drop-events: true + additional-suspicious-events-logging: + enabled: true + minimum-severity: high + response-body: false + response-code: true + appsec-logging: + all-web-requests: false + detect-events: true + prevent-events: true + extended-logging: + http-headers: false + request-body: false + url-path: true + url-query: true + log-destination: + cloud: false + stdout: + format: json + - name: npm-managed-log-trigger-proxyhost-1 + access-control-logging: + allow-events: false + drop-events: true + additional-suspicious-events-logging: + enabled: true + minimum-severity: high + response-body: false + appsec-logging: + all-web-requests: false + detect-events: true + prevent-events: true + extended-logging: + http-headers: false + request-body: false + url-path: false + url-query: false + log-destination: + cloud: false + stdout: + format: json + +custom-responses: + - name: appsec-default-web-user-response + mode: response-code-only + http-response-code: 403 \ No newline at end of file diff --git a/backend/templates/openappsec.conf b/backend/templates/openappsec.conf new file mode 100755 index 000000000..bc350cab1 --- /dev/null +++ b/backend/templates/openappsec.conf @@ -0,0 +1,16 @@ +policies: + default: + triggers: + - appsec-default-log-trigger + mode: inactive + practices: + - webapp-default-practice + custom-response: appsec-default-web-user-response + specific-rules: + - host: {{ domain_names.first }} + triggers: + - appsec-default-log-trigger + mode: {{openappsec_mode}} + practices: + - webapp-default-practice + custom-response: appsec-default-web-user-response \ No newline at end of file diff --git a/deployment/docker-compose.yaml b/deployment/docker-compose.yaml new file mode 100644 index 000000000..ab99cc9c8 --- /dev/null +++ b/deployment/docker-compose.yaml @@ -0,0 +1,49 @@ +# Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: '3.3' +# docker compose for npm open-appsec integration + +services: + appsec-npm: + container_name: npm-attachment + image: 'ghcr.io/openappsec/nginx-proxy-manager-attachment:latest' + ipc: host + restart: unless-stopped + ports: + - '80:80' # Public HTTP Port + - '443:443' # Public HTTPS Port + - '81:81' # Admin Web Port + volumes: + - ./data:/data + - ./letsencrypt:/etc/letsencrypt + - ./appsec-logs:/ext/appsec-logs + - ./appsec-localconfig:/ext/appsec + + appsec-agent: + container_name: appsec-agent + image: 'ghcr.io/openappsec/agent:latest' + network_mode: service:appsec-npm + ipc: host + restart: unless-stopped + environment: + # adjust with your own email below + - user_email=user@email.com + - nginxproxymanager=true + - autoPolicyLoad=true + volumes: + - ./appsec-config:/etc/cp/conf + - ./appsec-data:/etc/cp/data + - ./appsec-logs:/var/log/nano_agent + - ./appsec-localconfig:/ext/appsec + command: /cp-nano-agent --standalone diff --git a/deployment/local_policy.yaml b/deployment/local_policy.yaml new file mode 100644 index 000000000..e288a7a19 --- /dev/null +++ b/deployment/local_policy.yaml @@ -0,0 +1,63 @@ +policies: + default: + triggers: + - appsec-default-log-trigger + mode: inactive + practices: + - webapp-default-practice + custom-response: appsec-default-web-user-response + specific-rules: [] + +practices: + - name: webapp-default-practice + web-attacks: + max-body-size-kb: 1000000 + max-header-size-bytes: 102400 + max-object-depth: 40 + max-url-size-bytes: 32768 + minimum-confidence: high + override-mode: inactive + protections: + csrf-protection: inactive + error-disclosure: inactive + non-valid-http-methods: false + open-redirect: inactive + anti-bot: + injected-URIs: [] + validated-URIs: [] + override-mode: inactive + snort-signatures: + configmap: [] + override-mode: inactive + openapi-schema-validation: + configmap: [] + override-mode: inactive + +log-triggers: + - name: appsec-default-log-trigger + access-control-logging: + allow-events: false + drop-events: true + additional-suspicious-events-logging: + enabled: true + minimum-severity: high + response-body: false + response-code: true + appsec-logging: + all-web-requests: false + detect-events: true + prevent-events: true + extended-logging: + http-headers: false + request-body: false + url-path: true + url-query: true + log-destination: + cloud: false + stdout: + format: json + +custom-responses: + - name: appsec-default-web-user-response + mode: response-code-only + http-response-code: 403 diff --git a/deployment/managed-from-npm-ui/docker-compose.yaml b/deployment/managed-from-npm-ui/docker-compose.yaml new file mode 100644 index 000000000..ab99cc9c8 --- /dev/null +++ b/deployment/managed-from-npm-ui/docker-compose.yaml @@ -0,0 +1,49 @@ +# Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: '3.3' +# docker compose for npm open-appsec integration + +services: + appsec-npm: + container_name: npm-attachment + image: 'ghcr.io/openappsec/nginx-proxy-manager-attachment:latest' + ipc: host + restart: unless-stopped + ports: + - '80:80' # Public HTTP Port + - '443:443' # Public HTTPS Port + - '81:81' # Admin Web Port + volumes: + - ./data:/data + - ./letsencrypt:/etc/letsencrypt + - ./appsec-logs:/ext/appsec-logs + - ./appsec-localconfig:/ext/appsec + + appsec-agent: + container_name: appsec-agent + image: 'ghcr.io/openappsec/agent:latest' + network_mode: service:appsec-npm + ipc: host + restart: unless-stopped + environment: + # adjust with your own email below + - user_email=user@email.com + - nginxproxymanager=true + - autoPolicyLoad=true + volumes: + - ./appsec-config:/etc/cp/conf + - ./appsec-data:/etc/cp/data + - ./appsec-logs:/var/log/nano_agent + - ./appsec-localconfig:/ext/appsec + command: /cp-nano-agent --standalone diff --git a/deployment/managed-from-open-appsec-ui/docker-compose.yaml b/deployment/managed-from-open-appsec-ui/docker-compose.yaml new file mode 100644 index 000000000..ce0b66907 --- /dev/null +++ b/deployment/managed-from-open-appsec-ui/docker-compose.yaml @@ -0,0 +1,44 @@ +# Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: '3.3' +# docker compose for npm open-appsec integration + +services: + npm-centrally-managed-attachment: + container_name: npm-attachment + image: 'ghcr.io/openappsec/nginx-proxy-manager-centrally-managed-attachment:latest' + ipc: host + restart: unless-stopped + ports: + - '80:80' # Public HTTP Port + - '443:443' # Public HTTPS Port + - '81:81' # Admin Web Port + volumes: + - ./data:/data + - ./letsencrypt:/etc/letsencrypt + + appsec-agent: + container_name: appsec-agent + image: 'ghcr.io/openappsec/agent:latest' + ipc: host + restart: unless-stopped + environment: + # adjust with your own email below + - user_email=user@email.com + - nginxproxymanager=true + volumes: + - ./appsec-config:/etc/cp/conf + - ./appsec-data:/etc/cp/data + - ./appsec-logs:/var/log/nano_agent + command: /cp-nano-agent --token # replace with your own token below diff --git a/docker/Dockerfile b/docker/Dockerfile index 82ec9355a..df4d1f611 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -42,9 +42,20 @@ WORKDIR /app RUN yarn install \ && yarn cache clean +# add open-appsec attachment +RUN mkdir -p /usr/lib/nginx +RUN mkdir -p /usr/lib/nginx/modules +COPY docker/lib/libngx_module.so /usr/lib/nginx/modules/libngx_module.so +COPY docker/lib/libosrc_nginx_attachment_util.so /usr/lib/libosrc_nginx_attachment_util.so +COPY docker/lib/libosrc_compression_utils.so /usr/lib/libosrc_compression_utils.so +COPY docker/lib/libosrc_shmem_ipc.so /usr/lib/libosrc_shmem_ipc.so + # add late to limit cache-busting by modifications COPY docker/rootfs / +# patch nginx.conf for open-appsec attachment +RUN sed -i -e '/include \/etc\/nginx\/modules\/\*\.conf/a\load_module /usr/lib/nginx/modules/libngx_module.so;' -e '/http {/a\\tcp_worker_processes auto;' /etc/nginx/nginx.conf + # Remove frontend service not required for prod, dev nginx config as well RUN rm -rf /etc/s6-overlay/s6-rc.d/user/contents.d/frontend /etc/nginx/conf.d/dev.conf \ && chmod 644 /etc/logrotate.d/nginx-proxy-manager \ diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index 6d8cf87c6..ce659441a 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -33,6 +33,8 @@ services: volumes: - npm_data:/data - le_data:/etc/letsencrypt + - ../open-appsec-agent-deployment/localconfig:/ext/appsec + - ../open-appsec-agent-deployment/logs:/ext/appsec-logs - ../backend:/app - ../frontend:/app/frontend - ../global:/app/global diff --git a/docker/lib/libngx_module.so b/docker/lib/libngx_module.so new file mode 100644 index 000000000..f764515e4 Binary files /dev/null and b/docker/lib/libngx_module.so differ diff --git a/docker/lib/libosrc_compression_utils.so b/docker/lib/libosrc_compression_utils.so new file mode 100644 index 000000000..0c2a832a3 Binary files /dev/null and b/docker/lib/libosrc_compression_utils.so differ diff --git a/docker/lib/libosrc_nginx_attachment_util.so b/docker/lib/libosrc_nginx_attachment_util.so new file mode 100644 index 000000000..52c2ee361 Binary files /dev/null and b/docker/lib/libosrc_nginx_attachment_util.so differ diff --git a/docker/lib/libosrc_shmem_ipc.so b/docker/lib/libosrc_shmem_ipc.so new file mode 100644 index 000000000..5aa5ec117 Binary files /dev/null and b/docker/lib/libosrc_shmem_ipc.so differ diff --git a/docs/yarn.lock b/docs/yarn.lock index 3a38e241a..85dafbb0c 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -1808,7 +1808,16 @@ array-unique@^0.3.2: resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" integrity sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg= -asn1.js@^5.2.0, asn1.js@^5.4.1: +asn1.js@^4.0.0: + version "4.10.1" + resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.10.1.tgz#b9c2bf5805f1e64aadeed6df3a2bfafb5a73f5a0" + integrity sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw== + dependencies: + bn.js "^4.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + +asn1.js@^5.4.1: version "5.4.1" resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-5.4.1.tgz#11a980b84ebb91781ce35b0fdc2ee294e3783f07" integrity sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA== @@ -2056,10 +2065,10 @@ bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.9: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== -bn.js@^5.0.0, bn.js@^5.1.2, bn.js@^5.2.1: - version "5.2.1" - resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" - integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== +bn.js@^5.1.1, bn.js@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.2.tgz#c9686902d3c9a27729f43ab10f9d79c2004da7b0" + integrity sha512-40rZaf3bUNKTVYu9sIeeEGOg7g14Yvnj9kH7b50EiwX0Q7A6umbvfI5tvHaOERH0XigqKkfLkFQxzb4e6CIXnA== body-parser@1.19.2, body-parser@^1.19.0: version "1.19.2" @@ -2175,28 +2184,28 @@ browserify-des@^1.0.0, browserify-des@^1.0.2: inherits "^2.0.1" safe-buffer "^5.1.2" -browserify-rsa@^4.0.0, browserify-rsa@^4.0.1, browserify-rsa@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.1.0.tgz#b2fd06b5b75ae297f7ce2dc651f918f5be158c8d" - integrity sha512-AdEER0Hkspgno2aR97SAf6vi0y0k8NuOpGnVH3O99rcA5Q6sh8QxcngtHuJ6uXwnfAXNM4Gn1Gb7/MV1+Ymbog== +browserify-rsa@^4.0.0, browserify-rsa@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.0.1.tgz#21e0abfaf6f2029cf2fafb133567a701d4135524" + integrity sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ= dependencies: - bn.js "^5.0.0" + bn.js "^4.1.0" randombytes "^2.0.1" browserify-sign@^4.0.0, browserify-sign@^4.2.1: - version "4.2.2" - resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.2.2.tgz#e78d4b69816d6e3dd1c747e64e9947f9ad79bc7e" - integrity sha512-1rudGyeYY42Dk6texmv7c4VcQ0EsvVbLwZkA+AQB7SxvXxmcD93jcHie8bzecJ+ChDlmAm2Qyu0+Ccg5uhZXCg== + version "4.2.1" + resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.2.1.tgz#eaf4add46dd54be3bb3b36c0cf15abbeba7956c3" + integrity sha512-/vrA5fguVAKKAVTNJjgSm1tRQDHUU6DbwO9IROu/0WAzC8PKhucDSh18J0RMvVeHAn5puMd+QHC2erPRNf8lmg== dependencies: - bn.js "^5.2.1" - browserify-rsa "^4.1.0" + bn.js "^5.1.1" + browserify-rsa "^4.0.1" create-hash "^1.2.0" create-hmac "^1.1.7" - elliptic "^6.5.4" + elliptic "^6.5.3" inherits "^2.0.4" - parse-asn1 "^5.1.6" - readable-stream "^3.6.2" - safe-buffer "^5.2.1" + parse-asn1 "^5.1.5" + readable-stream "^3.6.0" + safe-buffer "^5.2.0" browserify-zlib@^0.2.0: version "0.2.0" @@ -3739,7 +3748,7 @@ electron-to-chromium@^1.3.522, electron-to-chromium@^1.3.719: resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.739.tgz#f07756aa92cabd5a6eec6f491525a64fe62f98b9" integrity sha512-+LPJVRsN7hGZ9EIUUiWCpO7l4E3qBYHNadazlucBfsXBbccDFNKUBAgzE68FnkWGJPwD/AfKhSzL+G+Iqb8A4A== -elliptic@^6.5.3, elliptic@^6.5.4: +elliptic@^6.5.3: version "6.5.4" resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ== @@ -7186,13 +7195,14 @@ parent-module@^1.0.0: dependencies: callsites "^3.0.0" -parse-asn1@^5.0.0, parse-asn1@^5.1.5, parse-asn1@^5.1.6: - version "5.1.6" - resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.6.tgz#385080a3ec13cb62a62d39409cb3e88844cdaed4" - integrity sha512-RnZRo1EPU6JBnra2vGHj0yhp6ebyjBZpmUCLHWiFhxlzvBCCpAuZ7elsBp1PVAbQN0/04VD/19rfzlBSwLstMw== +parse-asn1@^5.0.0, parse-asn1@^5.1.5: + version "5.1.5" + resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.5.tgz#003271343da58dc94cace494faef3d2147ecea0e" + integrity sha512-jkMYn1dcJqF6d5CpU689bq7w/b5ALS9ROVSpQDPrZsqqesUJii9qutvoT5ltGedNXMO2e16YUWIghG9KxaViTQ== dependencies: - asn1.js "^5.2.0" + asn1.js "^4.0.0" browserify-aes "^1.0.0" + create-hash "^1.1.0" evp_bytestokey "^1.0.0" pbkdf2 "^3.0.3" safe-buffer "^5.1.1" @@ -8056,10 +8066,10 @@ rc@^1.2.8: string_decoder "~1.1.1" util-deprecate "~1.0.1" -"readable-stream@2 || 3", readable-stream@3, readable-stream@^3.0.2, readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.5.0, readable-stream@^3.6.0, readable-stream@^3.6.2: - version "3.6.2" - resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967" - integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA== +"readable-stream@2 || 3", readable-stream@3, readable-stream@^3.0.2, readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.5.0, readable-stream@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" + integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== dependencies: inherits "^2.0.3" string_decoder "^1.1.1" diff --git a/frontend/app-images/open-appsec-logo.svg b/frontend/app-images/open-appsec-logo.svg new file mode 100755 index 000000000..57b415516 --- /dev/null +++ b/frontend/app-images/open-appsec-logo.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + diff --git a/frontend/html/login.ejs b/frontend/html/login.ejs index bc4b9a27f..d24a76e35 100644 --- a/frontend/html/login.ejs +++ b/frontend/html/login.ejs @@ -1,9 +1,9 @@ <% var title = 'Login – Nginx Proxy Manager' %> <%- include partials/header.ejs %> -
+
- + <%- include partials/footer.ejs %> diff --git a/frontend/html/partials/header.ejs b/frontend/html/partials/header.ejs index cabb9df28..c2e67a449 100644 --- a/frontend/html/partials/header.ejs +++ b/frontend/html/partials/header.ejs @@ -21,6 +21,7 @@ + diff --git a/frontend/js/app/api.js b/frontend/js/app/api.js index 6e33a6dca..6829745a4 100644 --- a/frontend/js/app/api.js +++ b/frontend/js/app/api.js @@ -112,7 +112,7 @@ function makeExpansionString(expand) { * @param {String} [query] * @returns {Promise} */ -function getAllObjects(path, expand, query) { +function getAllObjects(path, expand, query, page, perPage) { let params = []; if (typeof expand === 'object' && expand !== null && expand.length) { @@ -123,7 +123,13 @@ function getAllObjects(path, expand, query) { params.push('query=' + query); } - return fetch('get', path + (params.length ? '?' + params.join('&') : '')); + if (page && perPage) { + params.push('page=' + page); + params.push('perPage=' + perPage); + } + + let url = path + (params.length ? '?' + params.join('&') : ''); + return fetch('get', url); } function FileUpload(path, fd) { @@ -716,6 +722,17 @@ module.exports = { } }, + OpenappsecLog: { + /** + * @param {Array} [expand] + * @param {String} [query] + * @returns {Promise} + */ + getAll: function (expand, query) { + return getAllObjects('openappsec-log', expand, query); + }, + }, + Reports: { /** @@ -753,5 +770,22 @@ module.exports = { delete data.id; return fetch('put', 'settings/' + id, data); } + }, + + OpenAppsecSettings: { + /** + * @returns {Promise} + */ + get: function () { + return fetch('get', 'openappsec-settings'); + }, + + /** + * @param {Object} data + * @returns {Promise} + */ + save: function (data) { + return fetch('put', 'openappsec-settings', data); } + }, }; diff --git a/frontend/js/app/controller.js b/frontend/js/app/controller.js index ccb2978a8..3bb6a94d7 100644 --- a/frontend/js/app/controller.js +++ b/frontend/js/app/controller.js @@ -407,6 +407,40 @@ module.exports = { } }, + /** + * openappsec Log + */ + showOpenappsecLogPage: function (page) { + page = parseInt(page) || 1; + let controller = this; + if (Cache.User.isAdmin()) { + require(['./main', './openappsec-log/main'], (App, View) => { + controller.navigate('/openappsec-log/page/' + page); + + // Show the view with the data + App.UI.showAppContent(new View({ + page: page, + perPage: 50 + })); + }); + } else { + this.showDashboard(); + } + }, + + /** + * openappsec Log Metadata + * + * @param model + */ + showOpenappsecMeta: function (model) { + if (Cache.User.isAdmin()) { + require(['./main', './openappsec-log/meta'], function (App, View) { + App.UI.showModalDialog(new View({model: model})); + }); + } + }, + /** * Settings */ diff --git a/frontend/js/app/nginx/proxy/form.ejs b/frontend/js/app/nginx/proxy/form.ejs index 56868f552..8d0246238 100644 --- a/frontend/js/app/nginx/proxy/form.ejs +++ b/frontend/js/app/nginx/proxy/form.ejs @@ -72,6 +72,7 @@
+
+ +
+
+ +
+ +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ diff --git a/frontend/js/app/nginx/proxy/form.js b/frontend/js/app/nginx/proxy/form.js index 1dfb5c189..50b0dd30e 100644 --- a/frontend/js/app/nginx/proxy/form.js +++ b/frontend/js/app/nginx/proxy/form.js @@ -33,6 +33,9 @@ module.exports = Mn.View.extend({ certificate_select: 'select[name="certificate_id"]', access_list_select: 'select[name="access_list_id"]', ssl_forced: 'input[name="ssl_forced"]', + use_openappsec: 'input[name="use_openappsec"]', + openappsec_mode: 'select[name="openappsec_mode"]', + minimum_confidence: 'select[name="minimum_confidence"]', hsts_enabled: 'input[name="hsts_enabled"]', hsts_subdomains: 'input[name="hsts_subdomains"]', http2_support: 'input[name="http2_support"]', @@ -75,6 +78,24 @@ module.exports = Mn.View.extend({ inputs.trigger('change'); }, + 'change @ui.use_openappsec': function () { + let checked = this.ui.use_openappsec.prop('checked'); + this.ui.openappsec_mode + .prop('disabled', !checked) + .parents('.form-group') + .css('opacity', checked ? 1 : 0.5); + + this.ui.minimum_confidence + .prop('disabled', !checked) + .parents('.form-group') + .css('opacity', checked ? 1 : 0.5); + + /*** check this */ + if (!checked) { + this.ui.openappsec_mode.prop('checked', false); + } + }, + 'change @ui.ssl_forced': function () { let checked = this.ui.ssl_forced.prop('checked'); this.ui.hsts_enabled @@ -146,14 +167,32 @@ module.exports = Mn.View.extend({ } let view = this; - let data = this.ui.form.serializeJSON(); - // Add locations + // enable openappsec inputs for serialization. if we don't do this, serialization of custom locations will be added to the root object instead of the missing root properties with the same name. + + let topHostDisabledElements = this.ui.form.find('#details [name*="openappsec"]:disabled, [name="minimum_confidence"]:disabled'); + topHostDisabledElements.prop('disabled', false); + let data = this.ui.form.serializeJSON(); + topHostDisabledElements.prop('disabled', true); + + // Check if openappsec is enabled. serializeJSON() will only return its value attribute, not its checked attribute. + let use_openappsec = this.ui.use_openappsec.prop('checked'); + data.use_openappsec = use_openappsec; + + // Add locations using the model defined in file frontend/js/app/nginx/proxy/location.js and the template frontend/js/app/nginx/proxy/location-item.ejs. + // input fields with the class 'model' will automatically update the model. data.locations = []; this.locationsCollection.models.forEach((location) => { data.locations.push(location.toJSON()); }); + // convert all "false" strings to false booleans in data. + Object.keys(data).forEach(key => { + if (typeof data[key] === 'string' && data[key].toLowerCase() === 'false') { + data[key] = false; + } + }); + // Serialize collects path from custom locations // This field must be removed from root object delete data.path; @@ -161,6 +200,7 @@ module.exports = Mn.View.extend({ // Manipulate data.forward_port = parseInt(data.forward_port, 10); data.block_exploits = !!data.block_exploits; + data.use_openappsec = !!data.use_openappsec; data.caching_enabled = !!data.caching_enabled; data.allow_websocket_upgrade = !!data.allow_websocket_upgrade; data.http2_support = !!data.http2_support; @@ -266,6 +306,7 @@ module.exports = Mn.View.extend({ this.ui.ssl_forced.trigger('change'); this.ui.hsts_enabled.trigger('change'); + this.ui.use_openappsec.trigger('change'); // Domain names this.ui.domain_names.selectize({ diff --git a/frontend/js/app/nginx/proxy/location-item.ejs b/frontend/js/app/nginx/proxy/location-item.ejs index 466cb9bad..c0866740a 100644 --- a/frontend/js/app/nginx/proxy/location-item.ejs +++ b/frontend/js/app/nginx/proxy/location-item.ejs @@ -16,7 +16,7 @@
+
+
+
+
+ +
+
+
+ +
+
+
+ + +
+
+ +
+
+ + +
+
+
<%- i18n('locations', 'delete') %> diff --git a/frontend/js/app/nginx/proxy/location.js b/frontend/js/app/nginx/proxy/location.js index e9513a480..6e1fe9ae6 100644 --- a/frontend/js/app/nginx/proxy/location.js +++ b/frontend/js/app/nginx/proxy/location.js @@ -7,7 +7,10 @@ const LocationView = Mn.View.extend({ className: 'location_block', ui: { - toggle: 'input[type="checkbox"]', + use_openappsec: 'input[name="use_openappsec"]', + openappsec_mode: 'select[name="openappsec_mode"]', + minimum_confidence: 'select[name="minimum_confidence"]', + toggle: 'input[type="checkbox"]#advanced_config_toggle', config: '.config', delete: '.location-delete' }, @@ -21,6 +24,27 @@ const LocationView = Mn.View.extend({ } }, + 'change @ui.use_openappsec': function () { + let checked = this.ui.use_openappsec.prop('checked'); + this.model.set('use_openappsec', checked); + + this.ui.openappsec_mode + .prop('disabled', !checked) + .parents('.form-group') + .css('opacity', checked ? 1 : 0.5); + + this.ui.minimum_confidence + .prop('disabled', !checked) + .parents('.form-group') + .css('opacity', checked ? 1 : 0.5); + + /*** check this */ + if (!checked) { + this.ui.openappsec_mode.prop('checked', false); + } + }, + + // input fields with the class 'model' will automatically update the model. 'change .model': function (e) { const map = {}; map[e.target.name] = e.target.value; diff --git a/frontend/js/app/nginx/redirection/form.js b/frontend/js/app/nginx/redirection/form.js index 1f81feebc..d14bfd3de 100644 --- a/frontend/js/app/nginx/redirection/form.js +++ b/frontend/js/app/nginx/redirection/form.js @@ -129,6 +129,7 @@ module.exports = Mn.View.extend({ // Manipulate data.block_exploits = !!data.block_exploits; + data.use_openappsec = !!data.use_openappsec; data.preserve_path = !!data.preserve_path; data.http2_support = !!data.http2_support; data.hsts_enabled = !!data.hsts_enabled; diff --git a/frontend/js/app/openappsec-log/list-all/item.ejs b/frontend/js/app/openappsec-log/list-all/item.ejs new file mode 100644 index 000000000..27f057d92 --- /dev/null +++ b/frontend/js/app/openappsec-log/list-all/item.ejs @@ -0,0 +1,16 @@ +open +<%- formatDbDate(eventTime, 'MMM DD YYYY, H:mm') %> +<%= createSpecificTableCell(eventSeverity) %> +<%= createSpecificTableCell(assetName) %> +<%= createSpecificTableCell(securityAction) %> +<%= createSpecificTableCell(waapIncidentType) %> +<%= createSpecificTableCell(httpSourceId) %> +<%= createSpecificTableCell(sourceIP) %> +<%= createSpecificTableCell(proxyIP) %> +<%= createSpecificTableCell(httpHostName) %> +<%= createSpecificTableCell(httpMethod) %> +<%= createSpecificTableCell(httpResponseCode) %> +<%= createSpecificTableCell(httpUriPath) %> +<%= createSpecificTableCell(matchedLocation) %> +<%= createSpecificTableCell(matchedParameter) %> +<%= createSpecificTableCell(matchedSample) %> diff --git a/frontend/js/app/openappsec-log/list-all/item.js b/frontend/js/app/openappsec-log/list-all/item.js new file mode 100644 index 000000000..5ed43006e --- /dev/null +++ b/frontend/js/app/openappsec-log/list-all/item.js @@ -0,0 +1,40 @@ +const Mn = require('backbone.marionette'); +const Controller = require('../../controller'); +const template = require('./item.ejs'); + +module.exports = Mn.View.extend({ + template: template, + tagName: 'tr', + + ui: { + meta: 'a.meta' + }, + + events: { + 'click @ui.meta': function (e) { + e.preventDefault(); + Controller.showOpenappsecMeta(this.model); + } + }, + + templateContext: { + more: function() { + switch (this.object_type) { + case 'redirection-host': + case 'stream': + case 'proxy-host': + return this.meta.domain_names.join(', '); + } + + return '#' + (this.object_id || '?'); + }, + createSpecificTableCell: function(value) { + if (value && value.trim() !== '') { + value = value.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); + return `${value}`; + } else { + return `-`; + } + } + } +}); diff --git a/frontend/js/app/openappsec-log/list-all/main.ejs b/frontend/js/app/openappsec-log/list-all/main.ejs new file mode 100644 index 000000000..3357f286e --- /dev/null +++ b/frontend/js/app/openappsec-log/list-all/main.ejs @@ -0,0 +1,21 @@ + +   + Time + Event Severity + Asset Name + Security Action + AppSec Incident Type + Source Identifier + Source IP + Proxy IP + HTTP Host + HTTP Method + HTTP Response Code + HTTP URI Path + Matched Location + Matched Parameter + Matched Sample + + + + diff --git a/frontend/js/app/openappsec-log/list-all/main.js b/frontend/js/app/openappsec-log/list-all/main.js new file mode 100644 index 000000000..55b8bcdef --- /dev/null +++ b/frontend/js/app/openappsec-log/list-all/main.js @@ -0,0 +1,49 @@ +const Mn = require('backbone.marionette'); +const ItemView = require('./item'); +const template = require('./main.ejs'); + +let TableBody = Mn.CollectionView.extend({ + tagName: 'tbody', + childView: ItemView, + + initialize: function (options) { + this.options = new Backbone.Model(options); + // this.page = options.page; + // this.perPage = options.perPage; + this.updatePage(); + // this.listenTo(this.options, 'change:page', this.updatePage); + }, + + updatePage: function () { + let perPage = this.perPage || this.collection.length; + let page = this.page || 1; + let models; + if (this.perPage && this.page) { + models = this.collection.models.slice((page - 1) * perPage, page * perPage); + } else { + models = this.collection.models; + } + this.collection.reset(models); + } +}); + +module.exports = Mn.View.extend({ + tagName: 'table', + className: 'table table-hover table-outline table-vcenter card-table', + template: template, + + regions: { + body: { + el: 'tbody', + replaceElement: true + } + }, + + onRender: function () { + this.showChildView('body', new TableBody({ + collection: this.collection, + // page: this.options.page, + // perPage: this.options.perPage + })); + } +}); diff --git a/frontend/js/app/openappsec-log/list-important/item.ejs b/frontend/js/app/openappsec-log/list-important/item.ejs new file mode 100644 index 000000000..a311a62c0 --- /dev/null +++ b/frontend/js/app/openappsec-log/list-important/item.ejs @@ -0,0 +1,16 @@ +open +<%- formatDbDate(eventTime, 'MMM DD YYYY, H:mm') %> +<%= createSpecificTableCell(eventSeverity) %> +<%= createSpecificTableCell(assetName) %> +<%= createSpecificTableCell(securityAction) %> +<%= createSpecificTableCell(waapIncidentType) %> +<%= createSpecificTableCell(httpSourceId) %> +<%= createSpecificTableCell(sourceIP) %> +<%= createSpecificTableCell(proxyIP) %> +<%= createSpecificTableCell(httpHostName) %> +<%= createSpecificTableCell(httpMethod) %> +<%= createSpecificTableCell(httpResponseCode) %> +<%= createSpecificTableCell(httpUriPath) %> +<%= createSpecificTableCell(matchedLocation) %> +<%= createSpecificTableCell(matchedParameter) %> +<%= createSpecificTableCell(matchedSample) %> \ No newline at end of file diff --git a/frontend/js/app/openappsec-log/list-important/item.js b/frontend/js/app/openappsec-log/list-important/item.js new file mode 100644 index 000000000..49de809f4 --- /dev/null +++ b/frontend/js/app/openappsec-log/list-important/item.js @@ -0,0 +1,40 @@ +const Mn = require('backbone.marionette'); +const Controller = require('../../controller'); +const template = require('./item.ejs'); + +module.exports = Mn.View.extend({ + template: template, + tagName: 'tr', + + ui: { + meta: 'a.meta' + }, + + events: { + 'click @ui.meta': function (e) { + e.preventDefault(); + Controller.showOpenappsecMeta(this.model); + } + }, + + templateContext: { + more: function() { + switch (this.object_type) { + case 'redirection-host': + case 'stream': + case 'proxy-host': + return this.meta.domain_names.join(', '); + } + + return '#' + (this.object_id || '?'); + }, + createSpecificTableCell: function(value) { + if (value && value.trim() !== '') { + value = value.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); + return `${value}`; + } else { + return `-`; + } + } + } +}); diff --git a/frontend/js/app/openappsec-log/list-important/main.ejs b/frontend/js/app/openappsec-log/list-important/main.ejs new file mode 100644 index 000000000..3357f286e --- /dev/null +++ b/frontend/js/app/openappsec-log/list-important/main.ejs @@ -0,0 +1,21 @@ + +   + Time + Event Severity + Asset Name + Security Action + AppSec Incident Type + Source Identifier + Source IP + Proxy IP + HTTP Host + HTTP Method + HTTP Response Code + HTTP URI Path + Matched Location + Matched Parameter + Matched Sample + + + + diff --git a/frontend/js/app/openappsec-log/list-important/main.js b/frontend/js/app/openappsec-log/list-important/main.js new file mode 100644 index 000000000..a7ef3281c --- /dev/null +++ b/frontend/js/app/openappsec-log/list-important/main.js @@ -0,0 +1,42 @@ +const Mn = require('backbone.marionette'); +const ItemView = require('./item'); +const template = require('./main.ejs'); + +let TableBody = Mn.CollectionView.extend({ + tagName: 'tbody', + childView: ItemView, + + initialize: function (options) { + this.options = new Backbone.Model(options); + this.page = options.page; + this.perPage = options.perPage; + this.updatePage(); + this.listenTo(this.options, 'change:page', this.updatePage); + }, + + updatePage: function () { + let models = this.collection.models.slice((this.page - 1) * this.perPage, this.page * this.perPage); + this.collection.reset(models); + } +}); + +module.exports = Mn.View.extend({ + tagName: 'table', + className: 'table table-hover table-outline table-vcenter card-table', + template: template, + + regions: { + body: { + el: 'tbody', + replaceElement: true + } + }, + + onRender: function () { + this.showChildView('body', new TableBody({ + collection: this.collection, + page: this.options.page, + perPage: this.options.perPage + })); + } +}); diff --git a/frontend/js/app/openappsec-log/list-notifications/item.ejs b/frontend/js/app/openappsec-log/list-notifications/item.ejs new file mode 100644 index 000000000..f97a9c49b --- /dev/null +++ b/frontend/js/app/openappsec-log/list-notifications/item.ejs @@ -0,0 +1,8 @@ +open +<%- formatDbDate(eventTime, 'MMM DD YYYY, H:mm') %> +<%= createSpecificTableCell(eventSeverity) %> +<%= createSpecificTableCell(eventPriority) %> +<%= createSpecificTableCell(eventTopic) %> +<%= createSpecificTableCell(eventName) %> +<%= createSpecificTableCell(suggestedRemediation) %> +<%= createSpecificTableCell(assetName) %> \ No newline at end of file diff --git a/frontend/js/app/openappsec-log/list-notifications/item.js b/frontend/js/app/openappsec-log/list-notifications/item.js new file mode 100644 index 000000000..49933fe8f --- /dev/null +++ b/frontend/js/app/openappsec-log/list-notifications/item.js @@ -0,0 +1,40 @@ +const Mn = require('backbone.marionette'); +const Controller = require('../../controller'); +const template = require('./item.ejs'); + +module.exports = Mn.View.extend({ + template: template, + tagName: 'tr', + + ui: { + meta: 'a.meta' + }, + + events: { + 'click @ui.meta': function (e) { + e.preventDefault(); + Controller.showOpenappsecMeta(this.model); + } + }, + + templateContext: { + more: function() { + switch (this.object_type) { + case 'redirection-host': + case 'stream': + case 'proxy-host': + return this.meta.domain_names.join(', '); + } + + return '#' + (this.object_id || '?'); + }, + createSpecificTableCell: function(value) { + if (value && value.trim() !== '') { + value = value.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); + return `${value}`; + } else { + return `-`; + } + } + } +}); diff --git a/frontend/js/app/openappsec-log/list-notifications/main.ejs b/frontend/js/app/openappsec-log/list-notifications/main.ejs new file mode 100644 index 000000000..73c69806e --- /dev/null +++ b/frontend/js/app/openappsec-log/list-notifications/main.ejs @@ -0,0 +1,13 @@ + +   + Time + Event Severity + Event Priority + Event Topic + Event Name + Suggested Remediation if Applicable + Asset Name + + + + \ No newline at end of file diff --git a/frontend/js/app/openappsec-log/list-notifications/main.js b/frontend/js/app/openappsec-log/list-notifications/main.js new file mode 100644 index 000000000..a7ef3281c --- /dev/null +++ b/frontend/js/app/openappsec-log/list-notifications/main.js @@ -0,0 +1,42 @@ +const Mn = require('backbone.marionette'); +const ItemView = require('./item'); +const template = require('./main.ejs'); + +let TableBody = Mn.CollectionView.extend({ + tagName: 'tbody', + childView: ItemView, + + initialize: function (options) { + this.options = new Backbone.Model(options); + this.page = options.page; + this.perPage = options.perPage; + this.updatePage(); + this.listenTo(this.options, 'change:page', this.updatePage); + }, + + updatePage: function () { + let models = this.collection.models.slice((this.page - 1) * this.perPage, this.page * this.perPage); + this.collection.reset(models); + } +}); + +module.exports = Mn.View.extend({ + tagName: 'table', + className: 'table table-hover table-outline table-vcenter card-table', + template: template, + + regions: { + body: { + el: 'tbody', + replaceElement: true + } + }, + + onRender: function () { + this.showChildView('body', new TableBody({ + collection: this.collection, + page: this.options.page, + perPage: this.options.perPage + })); + } +}); diff --git a/frontend/js/app/openappsec-log/list/item.ejs b/frontend/js/app/openappsec-log/list/item.ejs new file mode 100755 index 000000000..57c4feab6 --- /dev/null +++ b/frontend/js/app/openappsec-log/list/item.ejs @@ -0,0 +1,77 @@ + + +
+ <% var sevirityClass = 'bg-success'; + switch (eventSeverity) { + case 'Critical': + sevirityClass = 'bg-danger'; + break; + case 'Warning': + sevirityClass = 'bg-warning'; + break; + case 'Info': + sevirityClass = 'bg-success'; + //sevirityClass = 'bg-info'; + break; + case 'Debug': + sevirityClass = 'bg-success'; + break; + } + %> + <%- eventSeverity %> +
+ + +
+ <% + var items = []; + object_type = "test"; + switch (object_type) { + case 'proxy-host': + %> <% + items = meta.domain_names; + break; + case 'redirection-host': + %> <% + items = meta.domain_names; + break; + case 'stream': + %> <% + items.push(meta.incoming_port); + break; + case 'dead-host': + %> <% + items = meta.domain_names; + break; + case 'access-list': + %> <% + items.push(meta.name); + break; + case 'user': + %> <% + items.push(meta.name); + break; + case 'certificate': + %> <% + if (meta.provider === 'letsencrypt') { + items = meta.domain_names; + } else { + //items.push(meta.nice_name); + items.push("test"); + } + break; + } + %><%- eventName %> +
+
+ <%- formatDbDate(eventTime, 'Do MMMM YYYY, h:mm a') %> +
+ + +
+ <%- serviceName %> +
+ + + open + diff --git a/frontend/js/app/openappsec-log/list/item.js b/frontend/js/app/openappsec-log/list/item.js new file mode 100755 index 000000000..009e3a3e6 --- /dev/null +++ b/frontend/js/app/openappsec-log/list/item.js @@ -0,0 +1,32 @@ +const Mn = require('backbone.marionette'); +const Controller = require('../../controller'); +const template = require('./item.ejs'); + +module.exports = Mn.View.extend({ + template: template, + tagName: 'tr', + + ui: { + meta: 'a.meta' + }, + + events: { + 'click @ui.meta': function (e) { + e.preventDefault(); + Controller.showOpenappsecMeta(this.model); + } + }, + + templateContext: { + more: function() { + switch (this.object_type) { + case 'redirection-host': + case 'stream': + case 'proxy-host': + return this.meta.domain_names.join(', '); + } + + return '#' + (this.object_id || '?'); + } + } +}); diff --git a/frontend/js/app/openappsec-log/list/main.ejs b/frontend/js/app/openappsec-log/list/main.ejs new file mode 100755 index 000000000..0bb40fa15 --- /dev/null +++ b/frontend/js/app/openappsec-log/list/main.ejs @@ -0,0 +1,9 @@ + + Severity + Event + Handler +   + + + + diff --git a/frontend/js/app/openappsec-log/list/main.js b/frontend/js/app/openappsec-log/list/main.js new file mode 100755 index 000000000..a7ef3281c --- /dev/null +++ b/frontend/js/app/openappsec-log/list/main.js @@ -0,0 +1,42 @@ +const Mn = require('backbone.marionette'); +const ItemView = require('./item'); +const template = require('./main.ejs'); + +let TableBody = Mn.CollectionView.extend({ + tagName: 'tbody', + childView: ItemView, + + initialize: function (options) { + this.options = new Backbone.Model(options); + this.page = options.page; + this.perPage = options.perPage; + this.updatePage(); + this.listenTo(this.options, 'change:page', this.updatePage); + }, + + updatePage: function () { + let models = this.collection.models.slice((this.page - 1) * this.perPage, this.page * this.perPage); + this.collection.reset(models); + } +}); + +module.exports = Mn.View.extend({ + tagName: 'table', + className: 'table table-hover table-outline table-vcenter card-table', + template: template, + + regions: { + body: { + el: 'tbody', + replaceElement: true + } + }, + + onRender: function () { + this.showChildView('body', new TableBody({ + collection: this.collection, + page: this.options.page, + perPage: this.options.perPage + })); + } +}); diff --git a/frontend/js/app/openappsec-log/main.ejs b/frontend/js/app/openappsec-log/main.ejs new file mode 100755 index 000000000..0b486f17f --- /dev/null +++ b/frontend/js/app/openappsec-log/main.ejs @@ -0,0 +1,45 @@ +
+
+
+

Security Log

+
+ +
+
+
+ + +
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
diff --git a/frontend/js/app/openappsec-log/main.js b/frontend/js/app/openappsec-log/main.js new file mode 100755 index 000000000..bfcdc1d3e --- /dev/null +++ b/frontend/js/app/openappsec-log/main.js @@ -0,0 +1,229 @@ +const Mn = require('backbone.marionette'); +const App = require('../main'); +const OpenappsecLogModel = require('../../models/openappsec-log'); +const ListViewTab1 = require('./list-important/main'); +const ListViewTab2 = require('./list-all/main'); +const ListViewTab3 = require('./list-notifications/main'); +const template = require('./main.ejs'); +const paginationTemplate = require('./pagination.ejs'); +const ErrorView = require('../error/main'); +const EmptyView = require('../empty/main'); +const { data } = require('jquery'); +const Controller = require('../controller'); + +let PaginationView = Mn.View.extend({ + tagName: 'ul', + className: 'pagination justify-content-center mt-4 border-top pt-3', + + initialize: function (options) { + this.totalPages = parseInt(options.totalPages) || 1; + this.currentPage = parseInt(options.currentPage) || 1; + this.totalDataLines = parseInt(options.totalDataLines) || 1; + this.maxPageLinks = 15; + }, + + template: paginationTemplate, + + templateContext: function () { + return { + totalDataLines: this.totalDataLines, + totalPages: this.totalPages, + currentPage: this.currentPage, + maxPageLinks: this.maxPageLinks + }; + } +}); + +module.exports = Mn.View.extend({ + id: 'openappsec-log', + template: template, + + initialize: function (options) { + this.options = options; + }, + + ui: { + list_region: '.list-region', + dimmer: '.dimmer', + search: '.search-form', + query: 'input[name="source-query"]', + pagination_region: '.pagination-region' + }, + + fetch: App.Api.OpenappsecLog.getAll, + + showData: function (response, tab = 'tab1') { + + // Filter the response data for each tab + const eventSeverities = ["critical", "high"]; + const tab1Data = response.filter(item => eventSeverities.includes(item.eventSeverity.trim().toLowerCase())); + + const eventNames = ["waap telemetry", "waap attack type telemetry", "ips stats"]; + const tab2Data = response.filter(item => !eventNames.includes(item.eventName.trim().toLowerCase())); + + const eventLevels = ["action item"]; + const tab3Data = response.filter(item => eventLevels.includes(item.eventLevel.trim().toLowerCase())); + + // Sort the data for each tab by timestamp in descending order. + tab1Data.sort((a, b) => { + return new Date(b.eventTime) - new Date(a.eventTime); + }); + + tab2Data.sort((a, b) => { + return new Date(b.eventTime) - new Date(a.eventTime); + }); + + tab3Data.sort((a, b) => { + return new Date(b.eventTime) - new Date(a.eventTime); + }); + + // Store the lengths of the original collections + this.tabCollectionLengths = { + tab1: response.length, + tab2: response.length, + tab3: response.length + }; + + this.tabCollections = { + tab1: new OpenappsecLogModel.Collection(tab1Data), + tab2: new OpenappsecLogModel.Collection(tab2Data), + tab3: new OpenappsecLogModel.Collection(tab3Data) + }; + + this.tabPaginationStates = { + tab1: { page: 1, perPage: this.options.perPage, totalDataLines: tab1Data.length }, + tab2: { page: 1, perPage: this.options.perPage, totalDataLines: tab2Data.length }, + tab3: { page: 1, perPage: this.options.perPage, totalDataLines: tab3Data.length } + }; + + // Define an object mapping for the ListViews + const listViewMapping = { + tab1: ListViewTab1, + tab2: ListViewTab2, + tab3: ListViewTab3 + }; + + // Get the current tab + const currentTab = tab; // Replace this with the actual current tab + + // Select the ListView for the current tab + const CurrentListView = listViewMapping[currentTab]; + + // Show the ListView for the current tab + this.showChildView('list_region', new CurrentListView({ + collection: this.tabCollections[currentTab], + // page: 1, + // perPage: this.options.perPage + page: this.tabPaginationStates[currentTab].page, + perPage: this.tabPaginationStates[currentTab].perPage + })); + + // this.showChildView('pagination_region', new PaginationView({ + // totalDataLines: this.tabPaginationStates[currentTab].totalDataLines, + // totalPages: Math.ceil(this.tabPaginationStates[currentTab].totalDataLines / this.options.perPage), + // currentPage: this.tabPaginationStates[currentTab].page + // })); + }, + + showError: function (err) { + this.showChildView('list_region', new ErrorView({ + code: err.code, + message: err.message, + retry: function () { + App.Controller.showOpenappsecLog(); + } + })); + + console.error(err); + }, + + showEmpty: function () { + this.showChildView('list_region', new EmptyView({ + title: App.i18n('audit-log', 'empty'), + subtitle: App.i18n('audit-log', 'empty-subtitle') + })); + }, + + regions: { + list_region: '@ui.list_region', + pagination_region: '@ui.pagination_region' + }, + + events: { + 'submit @ui.search': function (e) { + e.preventDefault(); + let query = this.ui.query.val(); + + this.fetch(['user'], query) + .then(response => this.showData(response)) + .catch(err => { + this.showError(err); + }); + }, + + 'click .nav-link': 'onTabClick', + + 'click @ui.pagination_region a': function (e) { + e.preventDefault(); + + // get the page number from the link + const newPage = $(e.currentTarget).attr('href').split('/').pop(); + Controller.navigate('/openappsec-log/page/' + newPage, { trigger: true }); + } + }, + + onTabClick: function(event) { + event.preventDefault(); + const selectedTab = event.target.id; + let view = this; + let query = this.ui.query.val() || ''; + view.ui.dimmer.addClass('active'); + view.fetch(['user'], query) + .then(response => { + if (!view.isDestroyed() && response) { + view.showData(response, selectedTab); + } else { + view.showEmpty(); + } + }) + .catch(err => { + view.showError(err); + }) + .then(() => { + view.ui.dimmer.removeClass('active'); + }); + + // this.showChildView('list_region', new ListView({ + // collection: this.tabCollections[selectedTab], + // page: this.tabPaginationStates[selectedTab].page, + // perPage: this.tabPaginationStates[selectedTab].perPage + // })); + + // this.showChildView('pagination_region', new PaginationView({ + // totalDataLines: this.tabCollections[selectedTab].length, + // totalPages: Math.ceil(this.tabCollections[selectedTab].length / this.options.perPage), + // currentPage: this.tabPaginationStates[selectedTab].page + // })); + + }, + + onRender: function () { + let view = this; + let query = this.ui.query.val() || ''; + + view.fetch(['user'], query) + .then(response => { + if (!view.isDestroyed() && response) { + view.showData(response); + } else { + view.showEmpty(); + } + }) + .catch(err => { + view.showError(err); + }) + .then(() => { + view.ui.dimmer.removeClass('active'); + }); + } +}); diff --git a/frontend/js/app/openappsec-log/meta.ejs b/frontend/js/app/openappsec-log/meta.ejs new file mode 100755 index 000000000..fe5831176 --- /dev/null +++ b/frontend/js/app/openappsec-log/meta.ejs @@ -0,0 +1,27 @@ + diff --git a/frontend/js/app/openappsec-log/meta.js b/frontend/js/app/openappsec-log/meta.js new file mode 100755 index 000000000..815cdfac9 --- /dev/null +++ b/frontend/js/app/openappsec-log/meta.js @@ -0,0 +1,7 @@ +const Mn = require('backbone.marionette'); +const template = require('./meta.ejs'); + +module.exports = Mn.View.extend({ + template: template, + className: 'modal-dialog wide' +}); diff --git a/frontend/js/app/openappsec-log/pagination.ejs b/frontend/js/app/openappsec-log/pagination.ejs new file mode 100644 index 000000000..a4885b2e0 --- /dev/null +++ b/frontend/js/app/openappsec-log/pagination.ejs @@ -0,0 +1,23 @@ +
  • "> + First +
  • +
  • "> + Previous +
  • +<% let startPage = Math.max(1, currentPage - Math.floor(maxPageLinks / 2)); %> +<% let endPage = Math.min(startPage + maxPageLinks - 1, totalPages); %> +<% startPage = Math.max(1, endPage - maxPageLinks + 1); %> +<% for (let i = startPage; i <= endPage; i++) { %> +
  • "> + <%= i %> +
  • +<% } %> +
  • "> + Next +
  • +
  • "> + Last +
  • +
  • + Total lines: <%= totalDataLines %> +
  • \ No newline at end of file diff --git a/frontend/js/app/router.js b/frontend/js/app/router.js index a036bfc57..e782623c9 100644 --- a/frontend/js/app/router.js +++ b/frontend/js/app/router.js @@ -13,6 +13,8 @@ module.exports = AppRouter.default.extend({ 'nginx/access': 'showNginxAccess', 'nginx/certificates': 'showNginxCertificates', 'audit-log': 'showAuditLog', + 'openappsec-log': 'showOpenappsecLogPage', + 'openappsec-log/page/:number': 'showOpenappsecLogPage', 'settings': 'showSettings', '*default': 'showDashboard' } diff --git a/frontend/js/app/settings/main.ejs b/frontend/js/app/settings/main.ejs index 2b02769f2..2031a4fee 100644 --- a/frontend/js/app/settings/main.ejs +++ b/frontend/js/app/settings/main.ejs @@ -3,12 +3,55 @@

    <%- i18n('settings', 'title') %>

    -
    +
    + + + +
    + + +
    +
    +
    + +
    +
    +
    + + +
    +
    + +
    +
    +
    +
    + + +
    + + + +
    +
    + +
    + +
    +
    + +
    +
    diff --git a/frontend/js/app/settings/main.js b/frontend/js/app/settings/main.js index 96b2941ff..ea7b41c2d 100644 --- a/frontend/js/app/settings/main.js +++ b/frontend/js/app/settings/main.js @@ -5,11 +5,18 @@ const ListView = require('./list/main'); const ErrorView = require('../error/main'); const template = require('./main.ejs'); +require('jquery-serializejson'); + module.exports = Mn.View.extend({ id: 'settings', template: template, ui: { + local_policy_field: '#open-appsec form #local_policy', + lp_success_info: '#open-appsec form #lp_success_info', + lp_error_info: '#open-appsec form #lp_error_info', + form: '#open-appsec form', + save: 'button.save', list_region: '.list-region', add: '.add-item', dimmer: '.dimmer' @@ -19,9 +26,57 @@ module.exports = Mn.View.extend({ list_region: '@ui.list_region' }, + events: { + 'click @ui.save': function (e) { + e.preventDefault(); + + this.ui.lp_success_info.hide(); + this.ui.lp_error_info.hide(); + + let data = this.ui.form.serializeJSON(); + console.log(data); + App.Api.OpenAppsecSettings.save(data) + .then(response => { + this.showSuccess(); + }) + .catch(err => { + console.error(err); + this.showError(err); + }); + } + }, + + showSuccess: function () { + this.ui.lp_success_info.show(); + setTimeout(() => { + this.ui.lp_success_info.fadeOut(); + }, 1000); + }, + + showError: function (err) { + this.ui.lp_error_info.show(); + this.ui.lp_error_info.html(err.message); + setTimeout(() => { + this.ui.lp_error_info.fadeOut(); + }, 3000); + }, + onRender: function () { let view = this; + this.ui.lp_success_info.hide(); + this.ui.lp_error_info.hide(); + + App.Api.OpenAppsecSettings.get() + .then(response => { + if (!view.isDestroyed() && response) { + view.ui.local_policy_field.val(response); + } + }) + .catch(err => { + console.error(err); + }); + App.Api.Settings.getAll() .then(response => { if (!view.isDestroyed() && response && response.length) { diff --git a/frontend/js/app/ui/header/main.ejs b/frontend/js/app/ui/header/main.ejs index 18ed2b6a6..456db4ef7 100644 --- a/frontend/js/app/ui/header/main.ejs +++ b/frontend/js/app/ui/header/main.ejs @@ -1,4 +1,4 @@ -
    +