author | Dan |
Tue, 20 Jan 2009 22:08:17 -0500 | |
changeset 52 | a8f0e99883d1 |
parent 51 | 508400fc5282 |
permissions | -rw-r--r-- |
51
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
1 |
<?php |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
2 |
|
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
3 |
function check_permissions($nick, $params, $quiet = true) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
4 |
{ |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
5 |
global $permissions, $irc; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
6 |
|
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
7 |
// I have all the power. |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
8 |
if ( $nick === $GLOBALS['nick'] ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
9 |
{ |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
10 |
if ( defined('LIBIRC_DEBUG') ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
11 |
echo "[!!!] Granted action {$params['context']} to {$GLOBALS['nick']} (self)\n"; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
12 |
return true; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
13 |
} |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
14 |
|
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
15 |
// Is the user in the permissions table? |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
16 |
if ( !isset($permissions[$nick]) ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
17 |
{ |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
18 |
if ( defined('LIBIRC_DEBUG') ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
19 |
echo "[!!!] Denied action {$params['context']} to {$nick} (not in table)\n"; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
20 |
return false; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
21 |
} |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
22 |
|
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
23 |
// Make sure the user is identified |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
24 |
$whois = $irc->whois($nick); |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
25 |
if ( !$whois || ( $whois && !$whois['identified']) ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
26 |
{ |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
27 |
if ( defined('LIBIRC_DEBUG') ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
28 |
echo "[!!!] Denied action {$params['context']} to {$nick} (whois check failed)\n"; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
29 |
if ( !$quiet ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
30 |
$irc->privmsg($nick, "Please identify to services before you do that. (If you are already identified, wait 20 seconds for the whois cache to clear and try again)"); |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
31 |
return false; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
32 |
} |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
33 |
|
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
34 |
// Is the user an admin? |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
35 |
if ( in_array('admin', $permissions[$nick]) && $params['context'] !== 'alert' ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
36 |
{ |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
37 |
if ( defined('LIBIRC_DEBUG') ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
38 |
echo "[!!!] Granted action {$params['context']} to {$nick} (has admin rights)\n"; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
39 |
return true; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
40 |
} |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
41 |
|
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
42 |
switch($params['context']): |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
43 |
case 'channel': |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
44 |
if ( isset($permissions[$nick]['channel']) && is_array($permissions[$nick]['channel']) ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
45 |
{ |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
46 |
if ( in_array($params['channel'], $permissions[$nick]['channel']) ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
47 |
{ |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
48 |
if ( defined('LIBIRC_DEBUG') ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
49 |
echo "[!!!] Granted action {$params['context']} to {$nick} in channel {$params['channel']} (on channel whitelist)\n"; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
50 |
return true; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
51 |
} |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
52 |
} |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
53 |
if ( defined('LIBIRC_DEBUG') ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
54 |
echo "[!!!] Denied action {$params['context']} to {$nick} in channel {$params['channel']} (not on channel whitelist)\n"; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
55 |
return false; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
56 |
default: |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
57 |
eval(eb_fetch_hook('permission_check')); |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
58 |
if ( isset($result) ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
59 |
{ |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
60 |
$perm = $result ? 'Granted' : 'Denied'; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
61 |
if ( defined('LIBIRC_DEBUG') ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
62 |
echo "[!!!] $perm action {$params['context']} to {$nick} (plugin overridden)\n"; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
63 |
return $result; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
64 |
} |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
65 |
$result = in_array($params['context'], $permissions[$nick]); |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
66 |
$perm = $result ? 'Granted' : 'Denied'; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
67 |
if ( defined('LIBIRC_DEBUG') ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
68 |
echo "[!!!] $perm action {$params['context']} to {$nick} (default handler)\n"; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
69 |
return $result; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
70 |
endswitch; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
71 |
} |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
diff
changeset
|
72 |