|
1 <?php |
|
2 |
|
3 function check_permissions($nick, $params, $quiet = true) |
|
4 { |
|
5 global $permissions, $irc; |
|
6 |
|
7 // I have all the power. |
|
8 if ( $nick === $GLOBALS['nick'] ) |
|
9 { |
|
10 if ( defined('LIBIRC_DEBUG') ) |
|
11 echo "[!!!] Granted action {$params['context']} to {$GLOBALS['nick']} (self)\n"; |
|
12 return true; |
|
13 } |
|
14 |
|
15 // Is the user in the permissions table? |
|
16 if ( !isset($permissions[$nick]) ) |
|
17 { |
|
18 if ( defined('LIBIRC_DEBUG') ) |
|
19 echo "[!!!] Denied action {$params['context']} to {$nick} (not in table)\n"; |
|
20 return false; |
|
21 } |
|
22 |
|
23 // Make sure the user is identified |
|
24 $whois = $irc->whois($nick); |
|
25 if ( !$whois || ( $whois && !$whois['identified']) ) |
|
26 { |
|
27 if ( defined('LIBIRC_DEBUG') ) |
|
28 echo "[!!!] Denied action {$params['context']} to {$nick} (whois check failed)\n"; |
|
29 if ( !$quiet ) |
|
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)"); |
|
31 return false; |
|
32 } |
|
33 |
|
34 // Is the user an admin? |
|
35 if ( in_array('admin', $permissions[$nick]) && $params['context'] !== 'alert' ) |
|
36 { |
|
37 if ( defined('LIBIRC_DEBUG') ) |
|
38 echo "[!!!] Granted action {$params['context']} to {$nick} (has admin rights)\n"; |
|
39 return true; |
|
40 } |
|
41 |
|
42 switch($params['context']): |
|
43 case 'channel': |
|
44 if ( isset($permissions[$nick]['channel']) && is_array($permissions[$nick]['channel']) ) |
|
45 { |
|
46 if ( in_array($params['channel'], $permissions[$nick]['channel']) ) |
|
47 { |
|
48 if ( defined('LIBIRC_DEBUG') ) |
|
49 echo "[!!!] Granted action {$params['context']} to {$nick} in channel {$params['channel']} (on channel whitelist)\n"; |
|
50 return true; |
|
51 } |
|
52 } |
|
53 if ( defined('LIBIRC_DEBUG') ) |
|
54 echo "[!!!] Denied action {$params['context']} to {$nick} in channel {$params['channel']} (not on channel whitelist)\n"; |
|
55 return false; |
|
56 default: |
|
57 eval(eb_fetch_hook('permission_check')); |
|
58 if ( isset($result) ) |
|
59 { |
|
60 $perm = $result ? 'Granted' : 'Denied'; |
|
61 if ( defined('LIBIRC_DEBUG') ) |
|
62 echo "[!!!] $perm action {$params['context']} to {$nick} (plugin overridden)\n"; |
|
63 return $result; |
|
64 } |
|
65 $result = in_array($params['context'], $permissions[$nick]); |
|
66 $perm = $result ? 'Granted' : 'Denied'; |
|
67 if ( defined('LIBIRC_DEBUG') ) |
|
68 echo "[!!!] $perm action {$params['context']} to {$nick} (default handler)\n"; |
|
69 return $result; |
|
70 endswitch; |
|
71 } |
|
72 |