1 <?php
3 class aclResolver extends userinfo
4 {
5 private $attrs = array();
7 private $affectingACLs = array();
8 private $acl_category = "none";
10 function __construct($config, $dn, $parent)
11 {
12 $this->config = &$config;
13 $this->dn = $dn;
14 $this->parent = &$parent;
16 $ldap = $this->config->get_ldap_link();
17 $ldap->cd($this->config->current['BASE']);
18 $ldap->cat($dn);
19 $this->attrs = $ldap->fetch();
21 if(isset($this->parent->acl_category) && !empty($this->parent->acl_category)){
22 $this->acl_category = preg_replace("/\/$/","",$this->parent->acl_category);
23 }
25 if(isset($attrs['uid'][0])){
26 $this->uid = $attrs['uid'][0];
27 }
29 $this->ignoreACL = ($this->config->get_cfg_value("ignoreAcl") == $this->dn);
30 $this->reset_acl_cache();
31 $this->loadACL();
35 foreach($this->allACLs as $dn => $acls){
36 if(preg_match("/".preg_quote($dn,'/')."$/i", $this->dn)){
38 foreach($acls as $prio => $acl){
39 if($acl['type'] == "reset"){
40 $this->affectingACLs[$dn][$prio] = $acl;
41 break;
42 }else{
43 foreach($acl['acl'] as $category => $attributes){
44 if(preg_match("/^all($|\/)/", $category) ||
45 preg_match("/^".$this->acl_category."($|\/)/", $category)){
46 $this->affectingACLs[$dn][$prio] = $acl;
47 break;
48 }
49 }
50 }
51 }
52 }
53 }
54 }
57 function getReadableACL()
58 {
59 $str = "<table summary='"._("Object permissions")."' width='100%'>";
61 foreach($this->affectingACLs as $dn => $acls){
63 foreach($acls as $acl){
65 $str.="<tr>";
66 if(isset($this->config->idepartments[$dn])){
67 $image= image("images/select_department.png");
68 }else{
69 $image= image("images/lists/element.png");
70 }
71 $aclTypes= array("reset" => _("Reset ACLs"),
72 "one" => _("One level"),
73 "base" => _("Current object"),
74 "sub" => _("Complete subtree"),
75 "psub" => _("Complete subtree (permanent)"),
76 "role" => _("Use ACL defined in role"));
78 $str.="<td style='width:20px;'>".$image."</td>";
79 $str.="<td><b>".$dn."</b></td>";
80 $str.="<td>".$aclTypes[$acl['type']]."</td>";
81 $str.="</tr><tr>";
82 $str.="<td></td><td><b>"._("Members")."</b><ul>";
83 foreach($acl['members'] as $type => $name){
84 $str .= "<li>".$name."</li>";
85 }
86 $str .= "</ul>";
87 $str .= "</td>";
88 $str.="";
90 if($acl['type']!='reset'){
91 $str.="<td><b>"._("Acls")."</b><ul>";
92 foreach($acl['acl'] as $type => $name){
93 $str .= "<li>".$type.": <i>".$this->aclToString(implode(array_unique($name)))."</i></li>";
94 }
95 $str .= "</ul>";
96 $str .= "</td>";
97 $str .= "</tr>";
98 }
99 $str .= "<tr><td colspan=3><hr></td></tr>";
100 }
101 }
102 $str .= "</table>";
103 return($str);
104 }
106 function aclToString($acl)
107 {
108 $str ="";
109 if(preg_match("/r/", $acl)) $str.= _("read").', ';
110 if(preg_match("/w/", $acl)) $str.= _("write").', ';
111 if(preg_match("/c/", $acl)) $str.= _("Create").', ';
112 if(preg_match("/d/", $acl)) $str.= _("Remove").', ';
113 if(preg_match("/m/", $acl)) $str.= _("Move").', ';
114 if(preg_match("/s/", $acl)) $str.= _("Owner").', ';
115 return(trim($str,', '));
116 }
117 }
119 ?>