@@ -1017,20 +1017,58 @@ public function process() {
10171017class Hm_Handler_process_spam_report_settings extends Hm_Handler_Module {
10181018 public function process () {
10191019 list ($ success , $ form ) = $ this ->process_form (array ('save_settings ' ));
1020- if (!$ success || ! array_key_exists ( ' spamcop_settings ' , $ this -> request -> post ) ) {
1020+ if (!$ success ) {
10211021 return ;
10221022 }
10231023
10241024 $ new_settings = $ this ->get ('new_user_settings ' , array ());
1025- $ spamcop = $ this ->request ->post ['spamcop_settings ' ];
10261025
1027- $ set_email_setting = function ($ key , $ value ) use (&$ new_settings ) {
1028- $ new_settings [$ key ] = (!empty ($ value ) && filter_var ($ value , FILTER_VALIDATE_EMAIL )) ? $ value : '' ;
1026+ // Helper function for validation
1027+ $ set_setting = function ($ key , $ value , $ validator = null ) use (&$ new_settings ) {
1028+ if ($ validator && !$ validator ($ value )) {
1029+ $ new_settings [$ key ] = '' ;
1030+ } else {
1031+ $ new_settings [$ key ] = $ value ;
1032+ }
10291033 };
10301034
1031- $ new_settings ['spamcop_enabled_setting ' ] = isset ($ spamcop ['enabled ' ]);
1032- $ set_email_setting ('spamcop_submission_email_setting ' , $ spamcop ['submission_email ' ] ?? '' );
1033- $ set_email_setting ('spamcop_from_email_setting ' , $ spamcop ['from_email ' ] ?? '' );
1035+ // Process SpamCop settings
1036+ if (array_key_exists ('spamcop_settings ' , $ this ->request ->post )) {
1037+ $ spamcop = $ this ->request ->post ['spamcop_settings ' ];
1038+ $ new_settings ['spamcop_enabled_setting ' ] = isset ($ spamcop ['enabled ' ]);
1039+ $ set_setting ('spamcop_submission_email_setting ' , $ spamcop ['submission_email ' ] ?? '' , function ($ v ) {
1040+ return filter_var ($ v , FILTER_VALIDATE_EMAIL );
1041+ });
1042+ $ set_setting ('spamcop_from_email_setting ' , $ spamcop ['from_email ' ] ?? '' , function ($ v ) {
1043+ return filter_var ($ v , FILTER_VALIDATE_EMAIL );
1044+ });
1045+ }
1046+
1047+ // Process AbuseIPDB settings
1048+ if (array_key_exists ('abuseipdb_settings ' , $ this ->request ->post )) {
1049+ $ abuseipdb = $ this ->request ->post ['abuseipdb_settings ' ];
1050+ $ new_settings ['abuseipdb_enabled_setting ' ] = isset ($ abuseipdb ['enabled ' ]);
1051+
1052+ // Handle API key: if field is empty but api_key_set flag is present, preserve original key
1053+ $ api_key = $ abuseipdb ['api_key ' ] ?? '' ;
1054+ $ api_key_was_set = isset ($ abuseipdb ['api_key_set ' ]) && $ abuseipdb ['api_key_set ' ] == '1 ' ;
1055+
1056+ if (empty ($ api_key ) && $ api_key_was_set ) {
1057+ // User left field empty but key was originally set - preserve the original key
1058+ $ original_key = $ this ->user_config ->get ('abuseipdb_api_key_setting ' , '' );
1059+ if (!empty ($ original_key )) {
1060+ $ new_settings ['abuseipdb_api_key_setting ' ] = $ original_key ;
1061+ } else {
1062+ $ new_settings ['abuseipdb_api_key_setting ' ] = '' ;
1063+ }
1064+ } else {
1065+ // User entered a new value (or cleared it) - validate and set it
1066+ $ set_setting ('abuseipdb_api_key_setting ' , $ api_key , function ($ v ) {
1067+ // API key validation: non-empty string, reasonable length (10-200 chars)
1068+ return !empty ($ v ) && strlen ($ v ) >= 10 && strlen ($ v ) <= 200 ;
1069+ });
1070+ }
1071+ }
10341072
10351073 $ this ->out ('new_user_settings ' , $ new_settings , false );
10361074 }
0 commit comments