diff --git a/src/appmixer/cloudflare/jobs.js b/src/appmixer/cloudflare/jobs.js index 7e3a0f2b3..f40762f0f 100644 --- a/src/appmixer/cloudflare/jobs.js +++ b/src/appmixer/cloudflare/jobs.js @@ -43,9 +43,6 @@ module.exports = async (context) => { const expired = await context.db.collection(IPListModel.collection).deleteMany({ $expr: { $gt: [{ $subtract: ['$mtime', '$removeAfter'] }, timespan] } }); - await context.db.collection(RulesIPsModel.collection).deleteMany({ - $expr: { $gt: [{ $subtract: ['$mtime', '$removeAfter'] }, timespan] } - }); if (expired.deletedCount) { await context.log('info', { stage: `[CloudFlare] Deleted ${expired.deletedCount} orphaned rules.` }); diff --git a/src/appmixer/cloudflare/routes.js b/src/appmixer/cloudflare/routes.js index 20ea3bcbc..53a1c60d0 100644 --- a/src/appmixer/cloudflare/routes.js +++ b/src/appmixer/cloudflare/routes.js @@ -3,7 +3,6 @@ module.exports = (context, options) => { const IPListModel = require('./IPListModel')(context); - const RulesIPsModel = require('./RulesIPsModel')(context); context.http.router.register({ method: 'POST', path: '/ip-list', options: { @@ -20,21 +19,6 @@ module.exports = (context, options) => { } }); - context.http.router.register({ - method: 'POST', path: '/block-ip-rules', options: { - handler: async req => { - - const items = req.payload.items; - const operations = items.map(item => ({ - updateOne: { - filter: { ip: item.ip, zoneId: item.zoneId }, update: { $set: item }, upsert: true - } - })); - return await (context.db.collection(RulesIPsModel.collection)).bulkWrite(operations); - } - } - }); - context.http.router.register({ method: 'GET', path: '/ip-list', options: { handler: async req => { @@ -42,12 +26,4 @@ module.exports = (context, options) => { } } }); - - context.http.router.register({ - method: 'GET', path: '/block-ip-rules', options: { - handler: async req => { - return RulesIPsModel.find({}); - } - } - }); }; diff --git a/src/appmixer/cloudflareWAF/auth.js b/src/appmixer/cloudflareWAF/auth.js index a9db7a581..242fd94bf 100644 --- a/src/appmixer/cloudflareWAF/auth.js +++ b/src/appmixer/cloudflareWAF/auth.js @@ -1,6 +1,6 @@ 'use strict'; -const CloudflareAPI = require('../CloudflareAPI'); +const CloudflareAPI = require('./CloudflareAPI'); module.exports = { diff --git a/src/appmixer/cloudflareWAF/jobs.js b/src/appmixer/cloudflareWAF/jobs.js index 532ea776f..4a30eabe4 100644 --- a/src/appmixer/cloudflareWAF/jobs.js +++ b/src/appmixer/cloudflareWAF/jobs.js @@ -9,14 +9,14 @@ module.exports = async (context) => { await context.scheduleJob('cloud-flare-waf-ips-delete-job', config.ipDeleteJob.schedule, async () => { try { - const lock = await context.job.lock('cloud-flare-lists-rule-block-ips-delete-job', { ttl: config.ipDeleteJob.lockTTL }); + const lock = await context.job.lock('cloud-flare-waf-rule-block-ips-delete-job', { ttl: config.ipDeleteJob.lockTTL }); await context.log('trace', '[CloudFlare WAF] rule delete job started.'); try { await wafJobs.deleteExpireIps(context); } finally { lock.unlock(); - await context.log('trace', '[CloudFlare] rule delete job finished. Lock unlocked.'); + await context.log('trace', '[CloudFlare WAF] rule delete job finished. Lock unlocked.'); } } catch (err) { if (err.message !== 'locked') { diff --git a/src/appmixer/cloudflareWAF/plugin.js b/src/appmixer/cloudflareWAF/plugin.js index a96c44169..bbc1143f0 100644 --- a/src/appmixer/cloudflareWAF/plugin.js +++ b/src/appmixer/cloudflareWAF/plugin.js @@ -3,5 +3,5 @@ module.exports = async context => { await require('./routes')(context); await require('./jobs')(context); - context.log('info', '[CloudFlare] CloudFlare plugin successfully initialized.'); + context.log('info', '[CloudFlare WAF] CloudFlare WAF plugin successfully initialized.'); }; diff --git a/src/appmixer/cloudflareWAF/routes.js b/src/appmixer/cloudflareWAF/routes.js index 20ea3bcbc..00a35aa3f 100644 --- a/src/appmixer/cloudflareWAF/routes.js +++ b/src/appmixer/cloudflareWAF/routes.js @@ -2,24 +2,8 @@ module.exports = (context, options) => { - const IPListModel = require('./IPListModel')(context); const RulesIPsModel = require('./RulesIPsModel')(context); - context.http.router.register({ - method: 'POST', path: '/ip-list', options: { - handler: async req => { - - const items = req.payload.items; - const operations = items.map(item => ({ - updateOne: { - filter: { id: item.id }, update: { $set: item }, upsert: true - } - })); - return await (context.db.collection(IPListModel.collection)).bulkWrite(operations); - } - } - }); - context.http.router.register({ method: 'POST', path: '/block-ip-rules', options: { handler: async req => { @@ -35,14 +19,6 @@ module.exports = (context, options) => { } }); - context.http.router.register({ - method: 'GET', path: '/ip-list', options: { - handler: async req => { - return IPListModel.find({}); - } - } - }); - context.http.router.register({ method: 'GET', path: '/block-ip-rules', options: { handler: async req => { diff --git a/src/appmixer/cloudflareWAF/service.json b/src/appmixer/cloudflareWAF/service.json index 9647447a3..f48ebe660 100644 --- a/src/appmixer/cloudflareWAF/service.json +++ b/src/appmixer/cloudflareWAF/service.json @@ -1,5 +1,5 @@ { - "name": "appmixer.cloudflare", + "name": "appmixer.cloudflareWAF", "label": "CloudFlare WAF", "category": "applications", "description": "CloudFlare WAF integrations allows you to actively block attacker IP by using CloudFlare WAF infrastructure.", diff --git a/src/appmixer/cloudflareWAF/waf/CreateCustomRules/component.json b/src/appmixer/cloudflareWAF/waf/CreateCustomRules/component.json index 683bf5ac1..b28c4e3d6 100644 --- a/src/appmixer/cloudflareWAF/waf/CreateCustomRules/component.json +++ b/src/appmixer/cloudflareWAF/waf/CreateCustomRules/component.json @@ -1,6 +1,6 @@ { "name": "appmixer.cloudflareWAF.waf.CreateCustomRules", - "label": "CreateCustomRules", + "label": "Block IPs", "description": "Create custom rules in waf", "private": false, "version": "1.0.5",