@@ -2820,16 +2820,49 @@ private static void makeFirstUserAdmin(BackwardCompatibility backwardCompatibili
2820
2820
}
2821
2821
2822
2822
private static void addDefaultAdvancedFilters (BackwardCompatibility backwardCompatibility ){
2823
- if (backwardCompatibility .getAddDefaultFilters () == 0 ){
2823
+ if (backwardCompatibility .getAddDefaultFilters () == 0 || backwardCompatibility . getAddDefaultFilters () < 1734502264 ){
2824
2824
String contentAllow = "id: DEFAULT_ALLOW_FILTER\n filter:\n url:\n regex: '.*'" ;
2825
- String contentBlock = "id: DEFAULT_BLOCK_FILTER\n filter:\n response_code:\n gte: 400" ;
2825
+ String contentBlock = "id: DEFAULT_BLOCK_FILTER\n " +
2826
+ "filter:\n " +
2827
+ " or:\n " +
2828
+ " - response_code:\n " +
2829
+ " gte: 400\n " +
2830
+ " - response_headers:\n " +
2831
+ " for_one:\n " +
2832
+ " key:\n " +
2833
+ " eq: content-type\n " +
2834
+ " value:\n " +
2835
+ " contains_either:\n " +
2836
+ " - html\n " +
2837
+ " - text/html\n " +
2838
+ " - request_headers:\n " +
2839
+ " for_one:\n " +
2840
+ " key:\n " +
2841
+ " eq: host\n " +
2842
+ " value:\n " +
2843
+ " regex: .*localhost.*" ;
2844
+
2845
+ if (!DashboardMode .isMetered ()){
2846
+ contentBlock = "id: DEFAULT_BLOCK_FILTER\n filter:\n response_code:\n gte: 400" ;
2847
+ }
2848
+
2826
2849
2827
2850
AdvancedTrafficFiltersAction action = new AdvancedTrafficFiltersAction ();
2828
2851
action .setYamlContent (contentAllow );
2829
2852
action .saveYamlTemplateForTrafficFilters ();
2830
2853
2831
- action .setYamlContent (contentBlock );
2832
- action .saveYamlTemplateForTrafficFilters ();
2854
+ if (backwardCompatibility .getAddDefaultFilters () != 0 && DashboardMode .isMetered ()){
2855
+ Bson defaultFilterQ = Filters .eq (Constants .ID , "DEFAULT_BLOCK_FILTER" );
2856
+ YamlTemplate blockTemplate = AdvancedTrafficFiltersDao .instance .findOne (defaultFilterQ );
2857
+ if ((blockTemplate .getUpdatedAt () - blockTemplate .getCreatedAt ()) <= 10 ){
2858
+ AdvancedTrafficFiltersDao .instance .deleteAll (defaultFilterQ );
2859
+ action .setYamlContent (contentBlock );
2860
+ action .saveYamlTemplateForTrafficFilters ();
2861
+ }
2862
+ }else {
2863
+ action .setYamlContent (contentBlock );
2864
+ action .saveYamlTemplateForTrafficFilters ();
2865
+ }
2833
2866
2834
2867
BackwardCompatibilityDao .instance .updateOne (
2835
2868
Filters .eq ("_id" , backwardCompatibility .getId ()),
0 commit comments