mirror of
https://github.com/splitbrain/dokuwiki-plugin-captcha.git
synced 2025-08-16 17:37:27 +00:00
clean up action.php, remove support for deprecated forms
This commit is contained in:
58
action.php
58
action.php
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
use dokuwiki\Extension\ActionPlugin;
|
||||
use dokuwiki\Extension\EventHandler;
|
||||
use dokuwiki\Extension\Event;
|
||||
use dokuwiki\Extension\EventHandler;
|
||||
use dokuwiki\Form\Form;
|
||||
use dokuwiki\plugin\captcha\FileCookie;
|
||||
use dokuwiki\plugin\captcha\IpCounter;
|
||||
@ -21,35 +21,29 @@ class action_plugin_captcha extends ActionPlugin
|
||||
public function register(EventHandler $controller)
|
||||
{
|
||||
// check CAPTCHA success
|
||||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_captcha_input', []);
|
||||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleCaptchaInput', []);
|
||||
|
||||
// inject in edit form
|
||||
$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handle_form_output', []); //old
|
||||
$controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handle_form_output', []); //new
|
||||
$controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handleFormOutput', []);
|
||||
|
||||
// inject in user registration
|
||||
$controller->register_hook('HTML_REGISTERFORM_OUTPUT', 'BEFORE', $this, 'handle_form_output', []); //old
|
||||
$controller->register_hook('FORM_REGISTER_OUTPUT', 'BEFORE', $this, 'handle_form_output', []); //new
|
||||
$controller->register_hook('FORM_REGISTER_OUTPUT', 'BEFORE', $this, 'handleFormOutput', []);
|
||||
|
||||
// inject in password reset
|
||||
$controller->register_hook('HTML_RESENDPWDFORM_OUTPUT', 'BEFORE', $this, 'handle_form_output', []); //old
|
||||
$controller->register_hook('FORM_RESENDPWD_OUTPUT', 'BEFORE', $this, 'handle_form_output', []); //new
|
||||
$controller->register_hook('FORM_RESENDPWD_OUTPUT', 'BEFORE', $this, 'handleFormOutput', []);
|
||||
|
||||
// inject in login form
|
||||
$controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handle_form_output', []); // old
|
||||
$controller->register_hook('FORM_LOGIN_OUTPUT', 'BEFORE', $this, 'handle_form_output', []); // new
|
||||
$controller->register_hook('FORM_LOGIN_OUTPUT', 'BEFORE', $this, 'handleFormOutput', []);
|
||||
|
||||
// check on login
|
||||
$controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE', $this, 'handle_login', []);
|
||||
$controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE', $this, 'handleLogin', []);
|
||||
|
||||
// clean up captcha cookies
|
||||
$controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'handle_indexer', []);
|
||||
|
||||
$this->getConf('loginprotect');
|
||||
$controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'handleIndexer', []);
|
||||
|
||||
// log authentication failures
|
||||
if ((int)$this->getConf('loginprotect') > 1) {
|
||||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_auth', []);
|
||||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleAuth', []);
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +57,7 @@ class action_plugin_captcha extends ActionPlugin
|
||||
* @param string $act cleaned action mode
|
||||
* @return bool
|
||||
*/
|
||||
protected function needs_checking($act)
|
||||
protected function needsChecking($act)
|
||||
{
|
||||
global $INPUT;
|
||||
|
||||
@ -90,7 +84,7 @@ class action_plugin_captcha extends ActionPlugin
|
||||
* @param string $act cleaned action mode
|
||||
* @return string the new mode to use
|
||||
*/
|
||||
protected function abort_action($act)
|
||||
protected function abortAction($act)
|
||||
{
|
||||
global $INPUT;
|
||||
|
||||
@ -131,7 +125,7 @@ class action_plugin_captcha extends ActionPlugin
|
||||
* @param Event $event
|
||||
* @param $param
|
||||
*/
|
||||
public function handle_login(Event $event, $param)
|
||||
public function handleLogin(Event $event, $param)
|
||||
{
|
||||
global $INPUT;
|
||||
if (!$this->protectLogin()) return; // no protection wanted
|
||||
@ -154,12 +148,12 @@ class action_plugin_captcha extends ActionPlugin
|
||||
/**
|
||||
* Intercept all actions and check for CAPTCHA first.
|
||||
*/
|
||||
public function handle_captcha_input(Event $event, $param)
|
||||
public function handleCaptchaInput(Event $event, $param)
|
||||
{
|
||||
global $INPUT;
|
||||
|
||||
$act = act_clean($event->data);
|
||||
if (!$this->needs_checking($act)) return;
|
||||
if (!$this->needsChecking($act)) return;
|
||||
|
||||
// do nothing if logged in user and no CAPTCHA required
|
||||
if (!$this->getConf('forusers') && $INPUT->server->str('REMOTE_USER')) {
|
||||
@ -170,22 +164,18 @@ class action_plugin_captcha extends ActionPlugin
|
||||
/** @var helper_plugin_captcha $helper */
|
||||
$helper = plugin_load('helper', 'captcha');
|
||||
if (!$helper->check()) {
|
||||
$event->data = $this->abort_action($act);
|
||||
$event->data = $this->abortAction($act);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the CAPTCHA in a DokuForm or \dokuwiki\Form\Form
|
||||
* Inject the CAPTCHA in a \dokuwiki\Form\Form
|
||||
*/
|
||||
public function handle_form_output(Event $event, $param)
|
||||
public function handleFormOutput(Event $event, $param)
|
||||
{
|
||||
global $INPUT;
|
||||
|
||||
if (
|
||||
($event->name === 'FORM_LOGIN_OUTPUT' || $event->name === 'HTML_LOGINFORM_OUTPUT')
|
||||
&&
|
||||
!$this->protectLogin()
|
||||
) {
|
||||
if ($event->name === 'FORM_LOGIN_OUTPUT' && !$this->protectLogin()) {
|
||||
// no login protection wanted
|
||||
return;
|
||||
}
|
||||
@ -194,11 +184,7 @@ class action_plugin_captcha extends ActionPlugin
|
||||
$form = $event->data;
|
||||
|
||||
// get position of submit button
|
||||
if (is_a($form, Form::class)) {
|
||||
$pos = $form->findPositionByAttribute('type', 'submit');
|
||||
} else {
|
||||
$pos = $form->findElementByAttribute('type', 'submit');
|
||||
}
|
||||
if (!$pos) return; // no button -> source view mode
|
||||
|
||||
// do nothing if logged in user and no CAPTCHA required
|
||||
@ -212,17 +198,13 @@ class action_plugin_captcha extends ActionPlugin
|
||||
$out = $helper->getHTML();
|
||||
|
||||
// insert before the submit button
|
||||
if (is_a($form, Form::class)) {
|
||||
$form->addHTML($out, $pos);
|
||||
} else {
|
||||
$form->insertElement($pos, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean cookies once per day
|
||||
*/
|
||||
public function handle_indexer(Event $event, $param)
|
||||
public function handleIndexer(Event $event, $param)
|
||||
{
|
||||
$lastrun = getCacheName('captcha', '.captcha');
|
||||
$last = @filemtime($lastrun);
|
||||
@ -238,7 +220,7 @@ class action_plugin_captcha extends ActionPlugin
|
||||
/**
|
||||
* Count failed login attempts
|
||||
*/
|
||||
public function handle_auth(Event $event, $param)
|
||||
public function handleAuth(Event $event, $param)
|
||||
{
|
||||
global $INPUT;
|
||||
$act = act_clean($event->data);
|
||||
|
Reference in New Issue
Block a user