changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / spam / antibot_delay.php
1 <?php
2 /*
3    Most automated link/spambots load the edit screen and try to send a
4    submit response immediately after that. This plugin enforces a short
5    delay of 5 seconds before save submissions are accepted - an error
6    message is displayed to users who hit [save] too quickly after the
7    edit page was loaded.
8    This will defend the majority of current bots and zombie computers.
9    And never forget: 'time is money' even more so counts for spammers.
10    A later version may need to hash-assert the timestamp (with nonce).
11    Idea taken from phpBB2 "disable_spambots" by <magenta*trikuare.cx>.
12 */
13
14
15 #-- config
16 define("EWIKI_UP_SAVE_DELAY", "e_g_t");
17 define("EWIKI_EDIT_SAVE_DELAY", 5);
18
19
20 #-- embed timestamp
21 $ewiki_plugins["edit_form_append"][] = "ewiki_aedit_antibot_delay";
22 function ewiki_aedit_antibot_delay($id, &$data, $action) {
23    return('<input type="hidden" name="'.EWIKI_UP_SAVE_DELAY.'" value="'.time().'" />');
24 }
25
26
27 #-- check timespan
28 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_antibot_delay";
29 function ewiki_edit_save_antibot_delay(&$save, &$data) {
30    global $ewiki_errmsg;
31
32    if (!isset($GLOBALS["ewiki_no_bot"])) {
33       if (time() < $_REQUEST[EWIKI_UP_SAVE_DELAY] + EWIKI_EDIT_SAVE_DELAY) {
34          $save = NULL;
35          $ewiki_errmsg = ewiki_t("Too hasty saving rejected. Please go back, wait 3 seconds and hit [save] again.");
36       }
37    }
38 }
39
40
41 ?>