1 <?php
3 class aclResolver
4 {
6 private $classMapping = array();
7 private $aclTypes = array();
8 private $affectingACLs = array();
10 function __construct($config, $dn, $parent)
11 {
12 $this->config = &$config;
13 $this->dn = $dn;
15 // Get ACL category for the current object.
16 if(isset($parent->acl_category) && !empty($parent->acl_category)){
17 $this->acl_category = preg_replace("/\/$/","",$parent->acl_category);
18 }
20 // Build class mapping
21 if(!session::is_set('aclConverter::classMapping')){
22 $tmp= session::global_get('plist');
23 $plist= $tmp->info;
24 $map = array();
25 $map['all']= _("All categories");
26 foreach($plist as $class => $plInfo){
27 if(isset($plInfo['plCategory']) && is_array($plInfo['plCategory'])){
28 foreach($plInfo['plCategory'] as $category => $desc){
29 if(!is_numeric($category)){
30 $map[$category] = $desc['description'];
31 }
32 }
33 }
34 }
35 foreach($plist as $class => $plInfo){
36 if(isset($plInfo['plCategory']) && is_array($plInfo['plCategory'])){
37 foreach($plInfo['plCategory'] as $category => $desc){
38 if(!is_numeric($category)){
39 $map[$category."/".$class] = $map[$category]." - ".$plInfo['plDescription'];
40 }else{
41 $map[$desc."/".$class] = $map[$desc]." - ".$plInfo['plDescription'];
42 }
43 }
45 }
46 }
47 session::set('aclConverter::classMapping', $map);
48 }
49 $this->classMapping = session::get('aclConverter::classMapping');
51 // Go through all ACLs and get those matching out DN.
52 $ui = get_userinfo();
53 foreach($ui->allACLs as $dn => $acls){
54 if(preg_match("/".preg_quote($dn,'/')."$/i", $this->dn)){
55 foreach($acls as $prio => $acl){
56 if($acl['type'] == "reset"){
57 $this->affectingACLs[$dn][$prio] = $acl;
58 break;
59 }else{
60 foreach($acl['acl'] as $category => $attributes){
61 if(preg_match("/^all($|\/)/", $category) ||
62 preg_match("/^".$this->acl_category."($|\/)/", $category)){
63 $this->affectingACLs[$dn][$prio] = $acl;
64 break;
65 }
66 }
67 }
68 }
69 }
70 }
72 // Define ACL type translations
73 $this->aclTypes= array("reset" => _("Reset ACLs"),
74 "one" => _("One level"),
75 "base" => _("Current object"),
76 "sub" => _("Complete subtree"),
77 "psub" => _("Complete subtree (permanent)"),
78 "role" => _("Use ACL defined in role"));
79 }
82 /*! \brief Create a human readable HTML result
83 */
84 function getReadableACL()
85 {
86 $tpl =
87 "\n <tr>".
88 "\n <td>%s</td>".
89 "\n <td><b>%s</b></td>".
90 "\n <td rowspan=3>%s</td>".
91 "\n </tr>".
92 "\n <tr>".
93 "\n <td></td>".
94 "\n <td><b>"._("Group members")."</b><ul>%s</ul></td>".
95 "\n </tr>".
96 "\n <tr>".
97 "\n <td></td>".
98 "\n <td><b>"._("Members")."</b><ul>%s</ul></td>".
99 "\n </tr>".
100 "\n <tr>".
101 "\n <td></td>".
102 "\n <td><b>"._("Acls")."</b><ul>%s</ul></td>".
103 "\n </tr>".
104 "\n <tr>".
105 "\n <td colspan=3><hr></td>".
106 "\n </tr>";
109 $str = "<table summary='"._("Object permissions")."' width='100%'>";
110 foreach($this->affectingACLs as $dn => $acls){
111 foreach($acls as $acl){
112 $gmem = $umem = $defs = "";
113 $image = (isset($this->config->idepartments[$dn]))? "images/select_department.png":"images/lists/element.png";
114 $aclType = $this->aclTypes[$acl['type']];
116 foreach($acl['members'] as $type => $name){
117 if(preg_match("/^G/", $type))
118 $gmem .= "\n <li>".$name."</li>";
119 }
120 foreach($acl['members'] as $type => $name){
121 if(!preg_match("/^G/", $type))
122 $umem .= "\n <li>".$name."</li>";
123 }
125 if($acl['type']!='reset'){
126 foreach($acl['acl'] as $type => $acl){
127 if(isset($this->classMapping[$type])){
128 $defs .= "<li>".$this->classMapping[$type].": ".$this->aclToString($acl)."</li>";
129 }else{
130 $defs .= "<li>".$type.": ".$this->aclToString($acl)."</li>";
131 }
132 }
133 }
134 $str.= sprintf($tpl, image($image), $dn, $aclType, $gmem, $umem, $defs);
135 }
136 }
137 $str .= "</table>";
138 return($str);
139 }
141 function aclToString($acls)
142 {
143 $str ="<ul>";
144 foreach($acls as $name => $acl){
146 if($name == "0") $name = _("All");
148 $str .= "<li>".$name.": <i>";
150 if(preg_match("/r/", $acl)) $str.= _("read").', ';
151 if(preg_match("/w/", $acl)) $str.= _("write").', ';
152 if(preg_match("/c/", $acl)) $str.= _("Create").', ';
153 if(preg_match("/d/", $acl)) $str.= _("Remove").', ';
154 if(preg_match("/m/", $acl)) $str.= _("Move").', ';
155 if(preg_match("/s/", $acl)) $str.= _("Owner").', ';
156 $str = trim($str,', ');
157 $str.= "</i></li>";
158 }
159 return($str."</ul>");
160 }
161 }
163 ?>