diff --git a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java index d1ca2c773d..eab2ec43ae 100644 --- a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java +++ b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java @@ -2820,16 +2820,49 @@ private static void makeFirstUserAdmin(BackwardCompatibility backwardCompatibili } private static void addDefaultAdvancedFilters(BackwardCompatibility backwardCompatibility){ - if(backwardCompatibility.getAddDefaultFilters() == 0){ + if(backwardCompatibility.getAddDefaultFilters() == 0 || backwardCompatibility.getAddDefaultFilters() < 1734502264){ String contentAllow = "id: DEFAULT_ALLOW_FILTER\nfilter:\n url:\n regex: '.*'"; - String contentBlock = "id: DEFAULT_BLOCK_FILTER\nfilter:\n response_code:\n gte: 400"; + String contentBlock = "id: DEFAULT_BLOCK_FILTER\n" + + "filter:\n" + + " or:\n" + + " - response_code:\n" + + " gte: 400\n" + + " - response_headers:\n" + + " for_one:\n" + + " key:\n" + + " eq: content-type\n" + + " value:\n" + + " contains_either:\n" + + " - html\n" + + " - text/html\n" + + " - request_headers:\n" + + " for_one:\n" + + " key:\n" + + " eq: host\n" + + " value:\n" + + " regex: .*localhost.*"; + + if(!DashboardMode.isMetered()){ + contentBlock = "id: DEFAULT_BLOCK_FILTER\nfilter:\n response_code:\n gte: 400"; + } + AdvancedTrafficFiltersAction action = new AdvancedTrafficFiltersAction(); action.setYamlContent(contentAllow); action.saveYamlTemplateForTrafficFilters(); - action.setYamlContent(contentBlock); - action.saveYamlTemplateForTrafficFilters(); + if(backwardCompatibility.getAddDefaultFilters() != 0 && DashboardMode.isMetered()){ + Bson defaultFilterQ = Filters.eq(Constants.ID, "DEFAULT_BLOCK_FILTER"); + YamlTemplate blockTemplate = AdvancedTrafficFiltersDao.instance.findOne(defaultFilterQ); + if((blockTemplate.getUpdatedAt() - blockTemplate.getCreatedAt()) <= 10){ + AdvancedTrafficFiltersDao.instance.deleteAll(defaultFilterQ); + action.setYamlContent(contentBlock); + action.saveYamlTemplateForTrafficFilters(); + } + }else{ + action.setYamlContent(contentBlock); + action.saveYamlTemplateForTrafficFilters(); + } BackwardCompatibilityDao.instance.updateOne( Filters.eq("_id", backwardCompatibility.getId()), diff --git a/apps/dashboard/src/main/java/com/akto/utils/TrafficFilterUtil.java b/apps/dashboard/src/main/java/com/akto/utils/TrafficFilterUtil.java index 980eef9084..cc249401f0 100644 --- a/apps/dashboard/src/main/java/com/akto/utils/TrafficFilterUtil.java +++ b/apps/dashboard/src/main/java/com/akto/utils/TrafficFilterUtil.java @@ -38,8 +38,9 @@ public static BasicDBList getFilterTemplates(Map configs){ public static List getDbUpdateForTemplate(String content, String userEmail) throws Exception{ try { String author = userEmail; - int createdAt = Context.now(); - int updatedAt = Context.now(); + int timeNow = Context.now(); + int createdAt = timeNow; + int updatedAt = timeNow; List updates = new ArrayList<>( Arrays.asList(