Fichiers de configuration pmwiki
[platal.git] / plugins / pmwiki.platalAuth.php
1 <?php
2
3 $AuthFunction = "AuthPlatal";
4
5 function authPerms($pagename,$key,$could=false)
6 {
7 $words = explode(' ', $key);
8 $auth = false;
9 $and = false;
10 foreach ($words as $word) {
11 $iauth = false;
12 if ($word == 'and:') { $and = true; continue; }
13 $parts = explode(':', $word);
14 $cond = $parts[0];
15 $param = $parts[1];
16 if ($cond == "identified" && $could)
17 $cond = "logged";
18 $iauth = CondText($pagename, "if ".$cond." ".$param, true);
19 if ($and) $auth &= $iauth;
20 else $auth |= $iauth;
21 $and = false;
22 }
23 return $auth;
24 }
25
26 function TryAllAuths($pagename, $level, $page_read, $group_read, $could = false)
27 {
28 global $DefaultPasswords;
29 if (isset($page_read['passwd'.$level]) && $page_read['passwd'.$level] != '*')
30 return authPerms($pagename,$page_read['passwd'.$level], $could);
31 if (isset($group_read['passwd'.$level]) && $group_read['passwd'.$level] != '*')
32 return authPerms($pagename,$group_read['passwd'.$level], $could);
33 if (isset($DefaultPasswords[$level]))
34 return authPerms($pagename,$DefaultPasswords[$level], $could);
35 return false;
36 }
37
38 function AuthPlatal($pagename, $level, $authprompt, $since)
39 {
40 global $Conditions;
41 $authUser = false;
42 $authPage = false;
43
44 $page_read = ReadPage($pagename, $since);
45 $groupattr = FmtPageName('$Group/GroupAttributes', $pagename);
46 $group_read = ReadPage($groupattr, $since);
47
48 if (!isset($Conditions['canedit']))
49 $Conditions['canedit'] = TryAllAuths($pagename, 'edit', $page_read, $group_read, true);
50 if (!isset($Conditions['canattr']))
51 $Conditions['canattr'] = TryAllAuths($pagename, 'attr', $page_read, $group_read, true);
52
53 if (TryAllAuths($pagename, $level, $page_read, $group_read))
54 {
55 return $page_read;
56 }
57
58 if ($authprompt && !identified())
59 {
60 new_skinned_page('wiki.tpl', AUTH_MDP);
61 }
62
63 global $page;
64 new_skinned_page('', AUTH_MDP);
65 if (has_perms())
66 $page->trig("Erreur : page Wiki inutilisable sur plat/al");
67 else
68 $page->trig("Tu n'as pas le droit d'accéder à ce service");
69 // don't return false or pmwiki will send an exit breaking smarty page
70 return 1;
71 }
72
73 $Conditions['logged'] = 'logged()';
74 $Conditions['identified'] = 'identified()';
75 $Conditions['has_perms'] = 'has_perms()';
76 $Conditions['public'] = 'true';
77 $Conditions['only_public'] = '!identified()';
78