Skip to content

Commit 470adaa

Browse files
feat: Support for Contact Form 7 (#6)
1 parent c5a221b commit 470adaa

6 files changed

Lines changed: 105 additions & 6 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,39 @@ Please contact [hello@attachmentav.com](mailto:hello@attachmentav.com) in case y
2525

2626
## Development
2727

28+
To clear the database, run:
29+
30+
```
31+
docker compose down --volumes
32+
```
33+
2834
Use the following command to spin up a development environment.
2935

3036
```
3137
docker compose up
3238
```
3339

40+
To make email work:
41+
42+
```
43+
docker ps
44+
CONTAINER ID IMAGE COMMAND
45+
93b4f65875ae wordpress:latest "docker-entrypoint.s…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp attachmentav-wordpress-wordpress-1
46+
47+
docker exec -it 93b4f65875ae /bin/bash
48+
49+
apt-get update && apt-get install -y sendmail && apt-get clean
50+
/usr/sbin/sendmail -bd
51+
```
52+
3453
Optionally use `ngrok` to get a publicly reachable development domain.
3554

3655
```
3756
ngrok http http://localhost:80
3857
```
3958

59+
> You might need to set the `siteurl` an `home` option in [phpMyAdmin](http://localhost:8081/index.php?route=/sql&pos=0&db=wordpress&table=wp_options) to `http://localhost` or the ngrok URL if this changed since last time.
60+
4061
Inside PHP, use `error_log('log line');` or `error_log(print_r($var, true));` to print debug logs.
4162

4263
### Release

compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ services:
3333
phpmyadmin:
3434
image: 'phpmyadmin:5.2.2'
3535
ports:
36-
- '8081:80'
36+
- '8081:80'
3737
depends_on:
38-
- db
38+
- db
3939
environment:
4040
PMA_HOST: db
4141
volumes:

plugin/README.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: andreaswittig,michaelwittig
33
Tags: malware,virus,antivirus,malware scanner,security
44
Requires at least: 6.0
55
Tested up to: 6.8
6-
Stable tag: 1.3
6+
Stable tag: 1.4
77
License: GPLv2
88
License URI: http://www.gnu.org/licenses/gpl-2.0.html
99

@@ -45,6 +45,7 @@ attachmentAV scans all files uploaded via:
4545
* The plugin [WPForms](https://wpforms.com/)
4646
* The plugin [Formidable Forms](https://formidableforms.com/)
4747
* The plugin [WordPress File Upload](https://wordpress.org/plugins/wp-file-upload/)
48+
* The plugin [Contact Form 7](https://contactform7.com/)
4849

4950
== Screenshots ==
5051

@@ -53,6 +54,9 @@ attachmentAV scans all files uploaded via:
5354

5455
== Changelog ==
5556

57+
= 1.4.0 =
58+
* Support for plugin Contact Form 7 added
59+
5660
= 1.3.0 =
5761
* Support Wordpress 6.8
5862

plugin/admin/class-attachmentav-admin.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,18 @@ public function page_init() {
119119
array( $this, 'sanitize_text' ) // Sanitize
120120
);
121121

122+
register_setting(
123+
'attachmentav', // Option group
124+
'attachmentav_scan_wpcf7', // Option name
125+
array( $this, 'sanitize_text' ) // Sanitize
126+
);
127+
122128
add_settings_section(
123129
'attachmentav_subscription', // ID
124130
'Subscription', // Title
125131
array( $this, 'print_subscription_section' ), // Callback
126132
'attachmentav' // Page
127-
);
133+
);
128134

129135
add_settings_field(
130136
'attachmentav_api_key', // ID
@@ -134,6 +140,14 @@ public function page_init() {
134140
'attachmentav_subscription' // Section
135141
);
136142

143+
add_settings_field(
144+
'attachmentav_upsell', // ID
145+
'API Integration Available', // Title
146+
array( $this, 'print_block_upsell' ), // Callback
147+
'attachmentav', // Page
148+
'attachmentav_subscription' // Section
149+
);
150+
137151
add_settings_section(
138152
'attachmentav_general', // ID
139153
'General', // Title
@@ -172,6 +186,14 @@ public function page_init() {
172186
'attachmentav_plugins' // Section
173187
);
174188

189+
add_settings_field(
190+
'attachmentav_scan_wpcf7', // ID
191+
'Scan files uploaded with plugin "Contact Form 7"?', // Title
192+
array( $this, 'print_block_scan_wpcf7' ), // Callback
193+
'attachmentav', // Page
194+
'attachmentav_plugins' // Section
195+
);
196+
175197
add_settings_field(
176198
'attachmentav_scan_formidable', // ID
177199
'Scan files uploaded with plugin "Formidable Forms"?', // Title
@@ -195,6 +217,11 @@ public function print_subscription_section()
195217
print '<a target="_blank" href="https://attachmentav.com/subscribe/wordpress/">Subscribe to attachmentAV</a> and enter the API key below.';
196218
}
197219

220+
public function print_block_upsell()
221+
{
222+
print 'Take our antivirus protection beyond WordPress. Our API integrates with any workflow or application to secure your data wherever it lives. <a target="_blank" href="https://attachmentav.com/solution/virus-malware-scan-api/?utm_source=dashboard&utm_campaign=upsell">Learn more</a>!';
223+
}
224+
198225
public function print_general_section()
199226
{
200227
print 'Enter your settings below:';
@@ -236,6 +263,14 @@ public function print_block_scan_wpfileupload() {
236263
}
237264
}
238265

266+
public function print_block_scan_wpcf7() {
267+
if (get_option('attachmentav_scan_wpcf7') != 'false') {
268+
print('<select name="attachmentav_scan_wpcf7"><option value="true" selected>Yes</option><option value="false">No</option></select>');
269+
} else {
270+
print('<select name="attachmentav_scan_wpcf7"><option value="true">Yes</option><option value="false" selected>No</option></select>');
271+
}
272+
}
273+
239274
public function print_block_scan_formidable() {
240275
print('Always active');
241276
}

plugin/attachmentav.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Plugin Name: attachmentAV
1717
* Plugin URI: https://attachmentav.com/solution/malware-protection-for-wordpress/
1818
* Description: Protect your blog from malware. Scan attachments for viruses, worms, and trojans by sending them to the attachmentAV API powered by Sophos. To get started, please go to your <a href="/wp-admin/admin.php?page=attachmentav">attachmentAV Settings page</a> to set up your API key.
19-
* Version: 1.3.0
19+
* Version: 1.4.0
2020
* Author: widdix GmbH
2121
* License: GPL-2.0+
2222
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@@ -34,7 +34,7 @@
3434
* Start at version 1.0.0 and use SemVer - https://semver.org
3535
* Rename this for your plugin and update it as you release new versions.
3636
*/
37-
define( 'ATTACHMENTAV_VERSION', '1.3.0' );
37+
define( 'ATTACHMENTAV_VERSION', '1.4.0' );
3838

3939
/**
4040
* The code that runs during plugin activation.

plugin/includes/class-attachmentav-loader.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,45 @@ function wfu_after_file_loaded($changable_data, $additional_data) {
350350
if (get_option('attachmentav_scan_wpfileupload') != 'false') {
351351
add_filter('wfu_after_file_loaded', 'wfu_after_file_loaded', 10, 2);
352352
}
353+
354+
function wpcf7_validate_file($result, $tag, $additional_data) {
355+
foreach ($additional_data['uploaded_files'] as $file) {
356+
$endpoint = 'https://eu.developer.attachmentav.com/v1/scan/sync/binary';
357+
$response = wp_remote_post( $endpoint, array(
358+
'timeout' => 30,
359+
'body' => file_get_contents($file),
360+
'headers' => array(
361+
'x-api-key' => get_option('attachmentav_api_key'),
362+
'x-wordpress-site-url' => get_site_url(),
363+
'Content-Type' => 'application/octet-stream',
364+
),
365+
));
366+
if (is_wp_error($response)) {
367+
$error_messages = implode(',', $response->get_error_messages());
368+
$result->invalidate($tag, "Failed to scan uploaded file for malware ({$error_messages}).");
369+
} else {
370+
if ($response['response']['code'] == 200) {
371+
$body = json_decode($response['body'], true);
372+
if ($body['status'] == 'no' && get_option('attachmentav_block_unscannable') == 'true') {
373+
$result->invalidate($tag, "Could not scan file (e.g., encrypted files). Upload blocked.");
374+
} else if ($body['status'] == 'infected') {
375+
$result->invalidate($tag, "Uploaded file is infected ({$body['finding']}). Upload blocked.");
376+
}
377+
} else if ($response['response']['code'] == 401) {
378+
$result->invalidate($tag, "Could not scan uploaded file for malware as license key is missing or invalid.");
379+
} else if ($response['response']['code'] == 429) {
380+
$result->invalidate($tag, "You've reached the maximum number of malware scans.");
381+
} else {
382+
$result->invalidate($tag, "Failed to scan uploaded file for malware due to unknown error.");
383+
}
384+
}
385+
}
386+
return $result;
387+
}
388+
if (get_option('attachmentav_scan_wpcf7') != 'false') {
389+
add_filter('wpcf7_validate_file*', 'wpcf7_validate_file', 20, 3);
390+
add_filter('wpcf7_validate_file', 'wpcf7_validate_file', 20, 3);
391+
}
353392
}
354393

355394
}

0 commit comments

Comments
 (0)