Note: Vanilla Forums Register Spam


  • Not full code, just excerption
  1. open applications/dashboard/controllers/class.entrycontroller.php
  2. find function named RegisterCaptcha()
  3. change to
    1
    2
    3
    4
    5
    6
    7
    8
    $this->UserModel->Validation->ApplyRule('Password', 'Required');
    $this->UserModel->Validation->ApplyRule('Password', 'Match');
    // $this->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge');

    $this->EventArguments['formValues'] = $this->Form->FormValues(); // add
    $this->FireEvent('BeforeRegistionCaptcha'); // add

    if (!$this->UserModel->InsertForBasic($this->Form->FormValues())) {
  4. Save

  1. new plugin in plugin directory named RSpam
  2. new file default.php
  3. content is
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    if (!defined('APPLICATION')) exit();

    // Define the plugin:
    $PluginInfo['RSpam'] = array(
    'Name' => 'RSpam Plugin',
    'Description' => "Just a simple hack",
    'Version' => '1',
    'Author' => "Zeuxis.Lo",
    'AuthorEmail' => '',
    'AuthorUrl' => 'http://studio.zeuik.com/',
    );

    class RSpamPlugin extends Gdn_Plugin {

    public function EntryController_BeforeRegistionCaptcha_Handler(&$Sender) {
    $formValues = $Sender->EventArguments['formValues'];
    $email = $formValues['Email'];
    $name = $formValues['Name'];

    if (empty($email) === true) return;
    if (empty($name) === true) return;

    if ($this->StopForumSpamCheckBy("username", $name) == true) {
    exit("系統錯誤->帳號");
    }else if ($this->StopForumSpamCheckBy("email", $email) === true) {
    exit("系統錯誤->電郵");
    }
    }

    public function StopForumSpamCheckBy($type, $value) {
    $url = "http://www.stopforumspam.com/api?";

    switch($type) {
    case "username":
    $url .= "username=".rawurlencode($value);
    break;
    case "email":
    $url .= "email=".$value;
    break;
    case "ip":
    $url .= "ip=".$value;
    break;
    }

    $data = file_get_contents($url);
    $xml = new SimpleXMLElement($data);

    return $xml->appears == 'yes';
    }

    public function Setup() {
    // No setup required
    }
    }
  4. Save and retest register again