-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
executable file
·76 lines (62 loc) · 2.38 KB
/
action.php
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* DokuWiki Plugin restrictedregistration (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Stean <[email protected]>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_PLUGIN.'action.php';
class action_plugin_restrictedregistration extends DokuWiki_Action_Plugin {
/**
* register the eventhandlers
*/
public function register(Doku_Event_Handler &$controller) {
$controller->register_hook('AUTH_USER_CHANGE', 'BEFORE', $this, 'handle_auth_user_change');
}
/**
* Checks if email address is on the list
*/
public function handle_auth_user_change(Doku_Event &$event, $param) {
//we are only interested in account registrations
//TODO: What about changing the address after successful registration?
if ($event->data["type"] == "create") {
if (!$this->checkMail($event->data["params"][3])) {
$event->preventDefault();
$event->stopPropagation();
msg($this->getLang("not_allowed_address"), -1);
}
}
}
private function checkMail($mailaddress) {
$addresses = $this->getAddressList();
/*
* Allow, if something goes wrong but the fallback action is set to "allow"
* or if everything goes well and the entered address is found
*/
if (($addresses == FALSE && $this->getConf("fallback_action") == "disallow") ||
($addresses != FALSE && in_array($mailaddress, $addresses))) {
return TRUE;
}else{
return FALSE;
}
}
private function getAddressList() {
//Initialize $output
unset($output);
$commandstr=$this->getConf("ezmlm-binary"). " ".$this->getConf("mailinglist-subdir");
exec($commandstr, $output, $retval); //TODO: Replace exec by PHP-based file parsing
if ($retval != 0) {
//Log error
dbglog("Execution of `$commandstr` failed with returnvalue $retval and output \"$output\"");
return FALSE;
}else{
return $output;
}
}
}
// vim:ts=4:sw=4:et: