3 * GNU Social - a federating social network
4 * Copyright (C) 2014, Free Software Foundation, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
24 * @maintainer Mikael Nordfeldth <mmn@hethane.se>
26 class SimpleCaptchaPlugin extends Plugin
28 public function initialize()
30 // This probably needs some work. For example with IPv6 you can easily generate new IPs...
31 $client_ip = common_client_ip();
32 $this->client_ip = $client_ip[0] ?: $client_ip[1]; // [0] is proxy, [1] should be the real IP
35 public function onEndRegistrationFormData(Action $action)
37 $action->elementStart('li');
38 // TRANS: Field label.
39 $action->input('simplecaptcha', _m('Captcha'), null,
40 // TRANS: The instruction box for our simple captcha plugin
41 sprintf(_m('Copy this to the textbox: "%s"'), $this->getCaptchaText()),
42 // TRANS: Placeholder in the text box
43 /* name=id */ null, /* required */ true, ['placeholder'=>_m('Prove that you are sentient.')]);
44 $action->elementEnd('li');
48 protected function getCaptchaText()
50 return common_config('site', 'name');
53 public function onStartRegistrationTry(Action $action)
55 if ($action->arg('simplecaptcha') !== $this->getCaptchaText()) {
56 common_log(LOG_INFO, 'Stopped non-sentient registration of nickname '._ve($action->trimmed('nickname')).' from IP: '._ve($this->client_ip));
57 throw new ClientException(_m('Captcha does not match!'));
62 public function onPluginVersion(array &$versions)
64 $versions[] = array('name' => 'Simple Captcha',
65 'version' => GNUSOCIAL_VERSION,
66 'author' => 'Mikael Nordfeldth',
67 'homepage' => 'https://gnu.io/social',
69 // TRANS: Plugin description.
70 _m('A simple captcha to get rid of spambots.'));