121cdae0 |
1 | <?php |
2 | |
3 | $AuthFunction = "AuthPlatal"; |
4 | |
5 | function authPerms($pagename,$key,$could=false) |
6 | { |
fd5c9770 |
7 | $words = explode(' ', $key); |
8 | $auth = false; |
9 | $and = false; |
10 | foreach ($words as $word) { |
11 | $iauth = false; |
12 | if ($word == 'and:') { |
13 | $and = true; |
14 | continue; |
15 | } |
16 | $parts = explode(':', $word); |
17 | $cond = $parts[0]; |
18 | $param = $parts[1]; |
19 | if ($cond == "identified" && $could) { |
20 | $cond = "logged"; |
21 | } |
22 | $iauth = CondText($pagename, "if ".$cond." ".$param, true); |
23 | if ($and) { |
24 | $auth &= $iauth; |
25 | } else { |
26 | $auth |= $iauth; |
27 | } |
28 | $and = false; |
29 | } |
30 | return $auth; |
121cdae0 |
31 | } |
32 | |
d0adba41 |
33 | function TryAllAuths($pagename, $level, $page_read, $group_read) |
121cdae0 |
34 | { |
fd5c9770 |
35 | global $DefaultPasswords; |
36 | if (isset($page_read['passwd'.$level]) && $page_read['passwd'.$level] != '*') { |
37 | return array('page', $page_read['passwd'.$level]); |
38 | } |
39 | if (isset($group_read['passwd'.$level]) && $group_read['passwd'.$level] != '*') { |
40 | return array('group', $group_read['passwd'.$level]); |
41 | } |
42 | if (isset($DefaultPasswords[$level])) { |
43 | return array('site', $DefaultPasswords[$level]); |
44 | } |
45 | return array('none', ''); |
121cdae0 |
46 | } |
47 | |
48 | function AuthPlatal($pagename, $level, $authprompt, $since) |
49 | { |
fd5c9770 |
50 | global $Conditions; |
51 | $authUser = false; |
52 | $authPage = false; |
121cdae0 |
53 | |
fd5c9770 |
54 | $page_read = ReadPage($pagename, $since); |
55 | $groupattr = FmtPageName('$Group/GroupAttributes', $pagename); |
56 | $group_read = ReadPage($groupattr, $since); |
121cdae0 |
57 | |
fd5c9770 |
58 | $levels = array('read', 'attr', 'edit', 'upload'); |
d0adba41 |
59 | |
fd5c9770 |
60 | foreach ($levels as $l) |
61 | { |
62 | list($from, $pass) = TryAllAuths($pagename, $l, $page_read, $group_read); |
63 | $passwds[$l] = $pass; |
64 | $pwsources[$l] = $from; |
65 | } |
121cdae0 |
66 | |
fd5c9770 |
67 | if (!isset($Conditions['canedit'])) { |
68 | $Conditions['canedit'] = authPerms($pagename, $passwds['edit'], true); |
69 | } |
70 | if (!isset($Conditions['canattr'])) { |
71 | $Conditions['canattr'] = authPerms($pagename, $passwds['attr'], true); |
72 | } |
121cdae0 |
73 | |
fd5c9770 |
74 | if (authPerms($pagename, $passwds[$level])) |
75 | { |
76 | $page_read['=passwd'] = $passwds; |
77 | $page_read['=pwsource'] = $pwsources; |
78 | return $page_read; |
79 | } |
80 | |
81 | if ($authprompt && !identified()) |
82 | { |
83 | new_skinned_page('wiki.tpl', AUTH_MDP); |
84 | } |
85 | |
86 | global $page; |
87 | new_skinned_page('', AUTH_MDP); |
88 | if (has_perms()) { |
89 | $page->trig("Erreur : page Wiki inutilisable sur plat/al"); |
90 | } else { |
91 | $page->trig("Tu n'as pas le droit d'accéder à ce service"); |
92 | } |
93 | // don't return false or pmwiki will send an exit breaking smarty page |
94 | return 1; |
121cdae0 |
95 | } |
96 | |
fd5c9770 |
97 | $Conditions['logged'] = 'logged()'; |
98 | $Conditions['identified'] = 'identified()'; |
99 | $Conditions['has_perms'] = 'has_perms()'; |
100 | $Conditions['public'] = 'true'; |
101 | $Conditions['only_public'] = '!identified()'; |
121cdae0 |
102 | |
fd5c9770 |
103 | ?> |