|
| 1 | +# Predefined Service Edit Buttons Implementation |
| 2 | + |
| 3 | +## Overview |
| 4 | +This document outlines the implementation of edit buttons for the predefined spam services (SpamCop, AbuseIPDB, StopForumSpam, CleanTalk) and the disabling of the "Add New Service" button. |
| 5 | + |
| 6 | +## Changes Made |
| 7 | + |
| 8 | +### 1. Disabled "Add New Service" Button |
| 9 | +**Location:** `modules/imap/output_modules.php` - `Hm_Output_spam_service_management` class |
| 10 | + |
| 11 | +**Change:** Commented out the "Add New Service" button to prevent users from adding custom services for now. |
| 12 | + |
| 13 | +```php |
| 14 | +// Add new service button (disabled for now) |
| 15 | +// $res .= '<div class="mb-3">'; |
| 16 | +// $res .= '<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addServiceModal">'; |
| 17 | +// $res .= '<i class="bi bi-plus-circle me-1"></i>'.$this->trans('Add New Service'); |
| 18 | +// $res .= '</button>'; |
| 19 | +// $res .= '</div>'; |
| 20 | +``` |
| 21 | + |
| 22 | +### 2. Added Edit Buttons to Service Settings |
| 23 | +**Location:** `modules/imap/output_modules.php` - `Hm_Output_spam_services_setting` class |
| 24 | + |
| 25 | +**Change:** Added edit buttons next to each service checkbox in the spam services settings. |
| 26 | + |
| 27 | +```php |
| 28 | +$res .= '<td>'; |
| 29 | +$res .= '<input class="form-check-input" type="checkbox"'.$checked.' value="1" id="'.$key.'" name="'.$key.'" data-default-value="'.($defaults[$key] ? 'true' : 'false').'"/>'; |
| 30 | +// Add Edit button for each service |
| 31 | +$service_id = str_replace('enable_', '', $key); |
| 32 | +$res .= '<button type="button" class="btn btn-sm btn-outline-primary ms-2" onclick="editService(\''.$service_id.'\')">'; |
| 33 | +$res .= '<i class="bi bi-pencil"></i> '.$this->trans('Edit'); |
| 34 | +$res .= '</button>'; |
| 35 | +$res .= '</td></tr>'; |
| 36 | +``` |
| 37 | + |
| 38 | +### 3. Created Predefined Service Modals |
| 39 | +**Location:** `modules/imap/output_modules.php` - `Hm_Output_predefined_service_modals` class |
| 40 | + |
| 41 | +**Features:** |
| 42 | +- **SpamCop Modal:** Simple email endpoint configuration |
| 43 | +- **AbuseIPDB Modal:** Full API configuration with authentication |
| 44 | +- **StopForumSpam Modal:** Full API configuration with authentication |
| 45 | +- **CleanTalk Modal:** Full API configuration with authentication |
| 46 | + |
| 47 | +**Each modal includes:** |
| 48 | +- Service-specific fields (email endpoint for SpamCop, API fields for others) |
| 49 | +- Current values loaded from the spam service manager |
| 50 | +- Enable/disable checkbox |
| 51 | +- Form validation |
| 52 | +- Bootstrap styling |
| 53 | + |
| 54 | +### 4. Updated JavaScript for Modal Handling |
| 55 | +**Location:** `modules/imap/output_modules.php` - `Hm_Output_spam_service_management_js` class |
| 56 | + |
| 57 | +**Change:** Modified the `editService()` function to handle predefined services. |
| 58 | + |
| 59 | +```javascript |
| 60 | +function editService(serviceId) { |
| 61 | + // Check if it's a predefined service |
| 62 | + if (["spamcop", "abuseipdb", "stopforumspam", "cleantalk"].includes(serviceId)) { |
| 63 | + // Show predefined service modal |
| 64 | + var modal = new bootstrap.Modal(document.getElementById(serviceId + "Modal")); |
| 65 | + modal.show(); |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + // Handle custom services (existing logic) |
| 70 | + // ... |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### 5. Added Handler for Predefined Service Updates |
| 75 | +**Location:** `modules/imap/handler_modules.php` - `Hm_Handler_update_predefined_service` class |
| 76 | + |
| 77 | +**Features:** |
| 78 | +- Processes form submissions from predefined service modals |
| 79 | +- Validates service-specific fields |
| 80 | +- Updates service configuration in the spam service manager |
| 81 | +- Provides success/error feedback |
| 82 | + |
| 83 | +**Supported Services:** |
| 84 | +- **SpamCop:** Email endpoint and enabled status |
| 85 | +- **AbuseIPDB:** API endpoint, method, auth type, auth header, auth value, payload template, enabled status |
| 86 | +- **StopForumSpam:** API endpoint, method, auth type, auth header, auth value, payload template, enabled status |
| 87 | +- **CleanTalk:** API endpoint, method, auth type, auth header, auth value, payload template, enabled status |
| 88 | + |
| 89 | +## Service-Specific Configurations |
| 90 | + |
| 91 | +### SpamCop (Email Service) |
| 92 | +- **Type:** Email |
| 93 | +- **Required Fields:** Email endpoint |
| 94 | +- **Default Endpoint: ** `[email protected]` |
| 95 | +- **Default Status:** Enabled |
| 96 | + |
| 97 | +### AbuseIPDB (API Service) |
| 98 | +- **Type:** API |
| 99 | +- **Required Fields:** API endpoint, HTTP method, payload template |
| 100 | +- **Optional Fields:** Authentication configuration |
| 101 | +- **Default Endpoint:** `https://api.abuseipdb.com/api/v2/report` |
| 102 | +- **Default Method:** POST |
| 103 | +- **Default Auth Type:** Header |
| 104 | +- **Default Auth Header:** Key |
| 105 | +- **Default Payload:** `{"ip": "{{ ip }}", "categories": [3], "comment": "{{ reason }}"}` |
| 106 | +- **Default Status:** Disabled |
| 107 | + |
| 108 | +### StopForumSpam (API Service) |
| 109 | +- **Type:** API |
| 110 | +- **Required Fields:** API endpoint, HTTP method, payload template |
| 111 | +- **Optional Fields:** Authentication configuration |
| 112 | +- **Default Endpoint:** `https://www.stopforumspam.com/add` |
| 113 | +- **Default Method:** POST |
| 114 | +- **Default Auth Type:** Header |
| 115 | +- **Default Auth Header:** api_key |
| 116 | +- **Default Payload:** `{"email": "{{ email }}", "ip": "{{ ip }}", "evidence": "{{ reason }}"}` |
| 117 | +- **Default Status:** Disabled |
| 118 | + |
| 119 | +### CleanTalk (API Service) |
| 120 | +- **Type:** API |
| 121 | +- **Required Fields:** API endpoint, HTTP method, payload template |
| 122 | +- **Optional Fields:** Authentication configuration |
| 123 | +- **Default Endpoint:** `https://moderate.cleantalk.org/api2.0` |
| 124 | +- **Default Method:** POST |
| 125 | +- **Default Auth Type:** Header |
| 126 | +- **Default Auth Header:** auth_key |
| 127 | +- **Default Payload:** `{"auth_key": "{{ auth_value }}", "method_name": "spam_check", "message": "{{ body }}", "sender_email": "{{ email }}", "sender_ip": "{{ ip }}"}` |
| 128 | +- **Default Status:** Disabled |
| 129 | + |
| 130 | +## Benefits |
| 131 | + |
| 132 | +1. **Simplified Interface:** Users can only edit predefined services, reducing complexity |
| 133 | +2. **Service-Specific Forms:** Each service has a tailored form with relevant fields |
| 134 | +3. **Current Value Loading:** Modals populate with existing configuration values |
| 135 | +4. **Easy Configuration:** Users can quickly configure API keys and endpoints |
| 136 | +5. **Consistent UX:** All services follow the same edit pattern |
| 137 | +6. **Validation:** Form validation ensures proper configuration |
| 138 | + |
| 139 | +## Usage |
| 140 | + |
| 141 | +1. Navigate to IMAP Settings in the admin interface |
| 142 | +2. Scroll to the "External Spam Reporting Services" section |
| 143 | +3. Click the "Edit" button next to any service |
| 144 | +4. Configure the service-specific fields |
| 145 | +5. Click "Update" to save changes |
| 146 | + |
| 147 | +## Future Enhancements |
| 148 | + |
| 149 | +- Re-enable "Add New Service" button when needed |
| 150 | +- Add service testing functionality |
| 151 | +- Add service status indicators |
| 152 | +- Add bulk service management |
| 153 | +- Add service import/export functionality |
0 commit comments