Skip to content

Commit

Permalink
feat: add login form captcha and virus scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimds committed Nov 1, 2023
1 parent 73ad11b commit 8e9085f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ RUN apk update \
&& apk add --no-cache $PHP_GD_DEPS \
&& docker-php-ext-install gd mysqli pdo pdo_mysql zip \
&& echo "date.timezone=Europe/London" > /usr/local/etc/php/conf.d/zz-custom.ini \
&& echo "session.autostart=0" >> /usr/local/etc/php/conf.d/zz-custom.ini
&& echo "session.autostart=0" >> /usr/local/etc/php/conf.d/zz-custom.ini \
&& apk add clamav

RUN apk update && apk add --virtual --no-cache \
imagemagick imagemagick-dev linux-headers $PHPIZE_DEPS \
Expand Down
28 changes: 28 additions & 0 deletions web/app/themes/awasqa/src/gravity-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CommonKnowledge\WordPress\Awasqa\GravityForms;

use Gravity_Forms\Gravity_Forms_RECAPTCHA\GF_Field_RECAPTCHA;
use CommonKnowledge\WordPress\Awasqa;

use function CommonKnowledge\WordPress\Awasqa\Authors\get_author_organisations;
Expand Down Expand Up @@ -436,3 +437,30 @@ function ($post_id, $feed, $entry, $form) {
$post['post_status'] = $org->post_status;
return $post;
}, 10, 4);

// Add captcha to login form
add_filter('gform_userregistration_login_form', function ($form) {
$form['fields'][] = new \GF_Field_CAPTCHA();
return $form;
});

add_filter('gform_validation', function ($validation_result) {
$form = $validation_result['form'];

$files = $_FILES ?? [];
$files = array_filter($files, function ($file) {
return (bool) ($file['tmp_name'] ?? null);
});

foreach ($files as $file) {
exec("clamscan " . $file['tmp_name'], $output, $result_code);
if ($result_code !== 0) {
$validation_result['is_valid'] = false;
@unlink($file['tmp_name']);
}
}

//Assign modified $form object back to the validation result
$validation_result['form'] = $form;
return $validation_result;
});

0 comments on commit 8e9085f

Please sign in to comment.