Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vtalas committed Jan 10, 2025
1 parent 0a2ed79 commit f1d26c7
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 57 deletions.
3 changes: 0 additions & 3 deletions src/appmixer/cloudflare/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.` });
Expand Down
24 changes: 0 additions & 24 deletions src/appmixer/cloudflare/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -20,34 +19,11 @@ 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 => {
return IPListModel.find({});
}
}
});

context.http.router.register({
method: 'GET', path: '/block-ip-rules', options: {
handler: async req => {
return RulesIPsModel.find({});
}
}
});
};
2 changes: 1 addition & 1 deletion src/appmixer/cloudflareWAF/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const CloudflareAPI = require('../CloudflareAPI');
const CloudflareAPI = require('./CloudflareAPI');

module.exports = {

Expand Down
4 changes: 2 additions & 2 deletions src/appmixer/cloudflareWAF/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion src/appmixer/cloudflareWAF/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
};
24 changes: 0 additions & 24 deletions src/appmixer/cloudflareWAF/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/appmixer/cloudflareWAF/service.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit f1d26c7

Please sign in to comment.