11<?php
22
3- use CrowdSecBouncer \Constants ;
3+ require_once __DIR__ .'/options-config.php ' ;
4+
5+ function writeStaticConfigFile ($ name = null , $ newValue = null )
6+ {
7+ $ crowdSecWpPluginOptions = getCrowdSecOptionsConfig ();
8+ $ data = [];
9+ foreach ($ crowdSecWpPluginOptions as $ option ) {
10+ $ data [$ option ['name ' ]] = get_option ($ option ['name ' ]);
11+ }
12+ if ($ name ) {
13+ $ data [$ name ] = $ newValue ;
14+ }
15+ $ json = json_encode ($ data );
16+ file_put_contents (CROWDSEC_CONFIG_PATH , "<?php \$crowdSecJsonStandaloneConfig=' $ json'; " );
17+ }
418
519/**
620 * The code that runs during plugin activation.
@@ -11,56 +25,17 @@ function activate_crowdsec_plugin()
1125
1226 // Set default options.
1327
14- update_option ('crowdsec_api_url ' , '' );
15- update_option ('crowdsec_api_key ' , '' );
16-
17- update_option ('crowdsec_bouncing_level ' , Constants::BOUNCING_LEVEL_NORMAL );
18- update_option ('crowdsec_public_website_only ' , true );
19-
20- update_option ('crowdsec_stream_mode ' , false );
21- update_option ('crowdsec_stream_mode_refresh_frequency ' , 60 );
22-
23- update_option ('crowdsec_cache_system ' , Constants::CACHE_SYSTEM_PHPFS );
24- update_option ('crowdsec_redis_dsn ' , '' );
25- update_option ('crowdsec_memcached_dsn ' , '' );
26- update_option ('crowdsec_clean_ip_cache_duration ' , Constants::CACHE_EXPIRATION_FOR_CLEAN_IP );
27- update_option ('crowdsec_bad_ip_cache_duration ' , Constants::CACHE_EXPIRATION_FOR_BAD_IP );
28- update_option ('crowdsec_fallback_remediation ' , Constants::REMEDIATION_CAPTCHA );
29-
30- update_option ('crowdsec_hide_mentions ' , false );
31- update_option ('crowdsec_trust_ip_forward ' , '' );
32- update_option ('crowdsec_trust_ip_forward_array ' , []);
33-
34- update_option ('crowdsec_theme_color_text_primary ' , 'black ' );
35- update_option ('crowdsec_theme_color_text_secondary ' , '#AAA ' );
36- update_option ('crowdsec_theme_color_text_button ' , 'white ' );
37- update_option ('crowdsec_theme_color_text_error_message ' , '#b90000 ' );
38- update_option ('crowdsec_theme_color_background_page ' , '#eee ' );
39- update_option ('crowdsec_theme_color_background_container ' , 'white ' );
40- update_option ('crowdsec_theme_color_background_button ' , '#626365 ' );
41- update_option ('crowdsec_theme_color_background_button_hover ' , '#333 ' );
42-
43- update_option ('crowdsec_theme_text_captcha_wall_tab_title ' , 'Oops.. ' );
44- update_option ('crowdsec_theme_text_captcha_wall_title ' , 'Hmm, sorry but... ' );
45- update_option ('crowdsec_theme_text_captcha_wall_subtitle ' , 'Please complete the security check. ' );
46- update_option ('crowdsec_theme_text_captcha_wall_refresh_image_link ' , 'refresh image ' );
47- update_option ('crowdsec_theme_text_captcha_wall_captcha_placeholder ' , 'Type here... ' );
48- update_option ('crowdsec_theme_text_captcha_wall_send_button ' , 'CONTINUE ' );
49- update_option ('crowdsec_theme_text_captcha_wall_error_message ' , 'Please try again. ' );
50- update_option ('crowdsec_theme_text_captcha_wall_footer ' , '' );
51-
52- update_option ('crowdsec_theme_text_ban_wall_tab_title ' , 'Oops.. ' );
53- update_option ('crowdsec_theme_text_ban_wall_title ' , '🤭 Oh! ' );
54- update_option ('crowdsec_theme_text_ban_wall_subtitle ' , 'This page is protected against cyber attacks and your IP has been banned by our system. ' );
55- update_option ('crowdsec_theme_text_ban_wall_footer ' , '' );
56-
57- update_option ('crowdsec_theme_custom_css ' , '' );
28+ $ crowdSecWpPluginOptions = getCrowdSecOptionsConfig ();
29+ foreach ($ crowdSecWpPluginOptions as $ crowdSecWpPluginOption ) {
30+ if ($ crowdSecWpPluginOption ['autoInit ' ]) {
31+ update_option ($ crowdSecWpPluginOption ['name ' ], $ crowdSecWpPluginOption ['default ' ]);
32+ }
33+ }
5834
5935 if (!get_option ('crowdsec_random_log_folder ' )) {
6036 update_option ('crowdsec_random_log_folder ' , bin2hex (random_bytes (64 )));
6137 }
62-
63- update_option ('crowdsec_standalone_mode ' , false );
38+ writeStaticConfigFile ();
6439}
6540
6641/**
@@ -82,49 +57,10 @@ function deactivate_crowdsec_plugin()
8257
8358 // Clean options.
8459
85- delete_option ('crowdsec_api_url ' );
86- delete_option ('crowdsec_api_key ' );
87-
88- delete_option ('crowdsec_bouncing_level ' );
89- delete_option ('crowdsec_public_website_only ' );
90-
91- delete_option ('crowdsec_stream_mode ' );
92- delete_option ('crowdsec_stream_mode_refresh_frequency ' );
93-
94- delete_option ('crowdsec_cache_system ' );
95- delete_option ('crowdsec_redis_dsn ' );
96- delete_option ('crowdsec_memcached_dsn ' );
97- delete_option ('crowdsec_clean_ip_cache_duration ' );
98- delete_option ('crowdsec_bad_ip_cache_duration ' );
99- delete_option ('crowdsec_fallback_remediation ' );
100-
101- delete_option ('crowdsec_hide_mentions ' );
102- delete_option ('crowdsec_trust_ip_forward ' );
103- delete_option ('crowdsec_trust_ip_forward_array ' );
104-
105- delete_option ('crowdsec_theme_color_text_primary ' );
106- delete_option ('crowdsec_theme_color_text_secondary ' );
107- delete_option ('crowdsec_theme_color_text_button ' );
108- delete_option ('crowdsec_theme_color_text_error_message ' );
109- delete_option ('crowdsec_theme_color_background_page ' );
110- delete_option ('crowdsec_theme_color_background_container ' );
111- delete_option ('crowdsec_theme_color_background_button ' );
112- delete_option ('crowdsec_theme_color_background_button_hover ' );
113-
114- delete_option ('crowdsec_theme_text_captcha_wall_tab_title ' );
115- delete_option ('crowdsec_theme_text_captcha_wall_title ' );
116- delete_option ('crowdsec_theme_text_captcha_wall_subtitle ' );
117- delete_option ('crowdsec_theme_text_captcha_wall_refresh_image_link ' );
118- delete_option ('crowdsec_theme_text_captcha_wall_captcha_placeholder ' );
119- delete_option ('crowdsec_theme_text_captcha_wall_send_button ' );
120- delete_option ('crowdsec_theme_text_captcha_wall_error_message ' );
121- delete_option ('crowdsec_theme_text_captcha_wall_footer ' );
122-
123- delete_option ('crowdsec_theme_text_ban_wall_tab_title ' );
124- delete_option ('crowdsec_theme_text_ban_wall_title ' );
125- delete_option ('crowdsec_theme_text_ban_wall_subtitle ' );
126- delete_option ('crowdsec_theme_text_ban_wall_footer ' );
127-
128- delete_option ('crowdsec_theme_custom_css ' );
129- delete_option ('crowdsec_standalone_mode ' );
60+ $ crowdSecWpPluginOptions = getCrowdSecOptionsConfig ();
61+ foreach ($ crowdSecWpPluginOptions as $ crowdSecWpPluginOption ) {
62+ if ($ crowdSecWpPluginOption ['autoInit ' ]) {
63+ delete_option ($ crowdSecWpPluginOption ['name ' ]);
64+ }
65+ }
13066}
0 commit comments