1 <?php
4 /* FIXME: the complete acl stuff will be redesigned to be more intuitive,
5 which will be possible after introducing templates for html pages.
6 just be patient. */
9 class acl extends plugin
10 {
11 /* CLI vars */
12 var $cli_summary= "Manage group ACL's";
13 var $cli_description= "Some longer text\nfor help";
14 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
16 /* Helpers */
17 var $department= "";
18 var $objects= array();
19 var $object= "";
20 var $current_acl= "";
21 var $selfflag= FALSE;
23 var $gosaSubtreeACL;
25 /* attribute list for save action */
26 var $attributes= array("gosaSubtreeACL");
27 var $objectclasses= array("gosaObject");
29 function acl ($config, $dn= NULL)
30 {
31 plugin::plugin($config, $dn);
33 /* WorkAround */
34 include "acl_definition.inc";
35 $this->objects= $ACLD;
36 $tmp= array_keys($this->objects);
37 $this->object= reset($tmp);
39 $this->selfflag= FALSE;
40 if (isset($this->attrs['gosaSubtreeACL'][0])){
41 $this->current_acl= preg_replace("/^[^:]*:/", "", $this->attrs['gosaSubtreeACL'][0]);
42 if (preg_match("/^!:/", $this->attrs['gosaSubtreeACL'][0])){
43 $this->selfflag= TRUE;
44 }
45 }
47 /* This is allways true */
48 $this->is_account= TRUE;
49 }
51 function execute()
52 {
53 /* Call parent execute */
54 plugin::execute();
56 /* Do we represent a valid group? */
57 if (!$this->is_account && $this->parent == NULL){
58 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
59 _("This 'dn' is no acl container.")."</b>";
60 return ($display);
61 }
63 /* Show main page */
64 $smarty= get_smarty();
65 if ($_SESSION['js']==FALSE){
66 $smarty->assign("javascript", "false");
67 } else {
68 $smarty->assign("javascript", "true");
69 }
70 $smarty->assign("object", $this->object);
71 $obj= array();
72 foreach($this->objects as $key => $value){
73 $obj[$key]= $key;
74 }
75 if ($this->selfflag){
76 $smarty->assign("selfflag", "checked");
77 } else {
78 $smarty->assign("selfflag", "");
79 }
80 $smarty->assign("objects", $obj);
81 $display= $smarty->fetch (get_template_path('acl.tpl', TRUE));
83 /* Show acl stuff */
84 $this->acl= get_module_permission (array($this->current_acl), $this->object, "");
85 $display.= $this->print_attributes ($this->objects[$this->object]);
86 return ($display);
87 }
90 function remove_from_parent()
91 {
92 plugin::remove_from_parent();
94 $this->attrs['gosaSubtreeACL']= array();
96 $ldap= $this->config->get_ldap_link();
97 $ldap->cd($this->dn);
98 $this->cleanup();
99 $ldap->modify ($this->attrs);
101 show_ldap_error($ldap->get_error());
102 }
105 /* Save data to object */
106 function save_object()
107 {
108 plugin::save_object();
110 if (!isset($_POST['object'])){
111 return;
112 }
114 /* Strip of old information */
115 if ($this->object == "all"){
116 $this->current_acl= preg_replace ( "/[,]?all[,]?/", "", $this->current_acl);
117 }
118 $this->current_acl= preg_replace ( "/(^|[^a-z0-9A-Z])$this->object#[^,]*[,]?/", "", $this->current_acl);
120 /* assemble new attributes */
121 $attrs= "";
122 if (isset($_POST['all'])){
123 $attrs.= "#all";
124 }
125 if ($this->object != "all" && !isset($_POST['all']) && $this->object != ""){
126 foreach ($this->objects[$this->object] as $key => $val){
127 if (is_integer($key)){
128 $aname= $val;
129 } else {
130 $aname= $key;
131 }
132 if (isset($_POST[$aname])){
133 $attrs.= "#$aname";
134 }
135 }
136 }
138 /* append information */
139 if ($attrs != ""){
140 $tmp= $this->object;
141 $attrs= $tmp.$attrs;
142 }
143 if ($this->current_acl != "" && $attrs != ""){
144 $this->current_acl.= ",";
145 }
146 $this->current_acl.= $attrs;
147 if (preg_match("/all#all/", $this->current_acl)){
148 $this->current_acl= "all";
149 }
150 if (preg_match("/^all,/", $this->current_acl)){
151 $this->current_acl= "all";
152 }
154 /* Save current object selection */
155 if (isset($_POST['object'])){
156 $this->object= $_POST['object'];
157 }
158 if (isset($_POST['selfflag'])){
159 $this->selfflag= TRUE;
160 } else {
161 $this->selfflag= FALSE;
162 }
163 }
166 /* Save to LDAP */
167 function save()
168 {
169 /* Write back to LDAP */
170 $ldap= $this->config->get_ldap_link();
172 /* Read stuff and only modify subtreeACL entries */
173 plugin::save();
175 if ($this->current_acl != ""){
176 if ($this->selfflag){
177 $this->attrs['gosaSubtreeACL']= "!:".$this->current_acl;
178 } else {
179 $this->attrs['gosaSubtreeACL']= ":".$this->current_acl;
180 }
181 } else {
182 $objectclasses= array();
183 foreach ($this->attrs['objectClass'] as $oc){
184 if (!preg_match('/gosaObject/i', $oc)){
185 $objectclasses[]= $oc;
186 }
187 }
188 $this->attrs['objectClass']= $objectclasses;
189 $this->attrs['gosaSubtreeACL']= array();
190 }
192 /* Modify class */
193 $ldap->cd($this->dn);
194 $this->cleanup();
195 $ldap->modify ($this->attrs);
197 show_ldap_error($ldap->get_error());
198 }
201 function print_attributes ($name)
202 {
203 $display= "<input type=checkbox name=\"all\" value=\"1\"";
204 if (chkacl ($this->acl, "all") == ""){
205 $display.= " checked";
206 }
207 $display.= "><b>"._("All fields are writeable")."</b><br>";
209 # Put strings in right order
210 asort ($name);
212 # Generate checklist
213 $display.= "<table summary=\"\" style=\"width:100%;\">\n";
214 $switch= 0;
215 foreach ($name as $key => $val){
216 if ($switch == 0){
217 $display.= " <tr>\n";
218 }
220 if (is_integer($key)){
221 $display.= "<td><input type=checkbox name=\"$val\" value=\"1\" ";
222 if (chkacl ($this->acl, "$val") == ""){
223 $display.= "checked";
224 }
225 $display.= ">$val</td>";
226 } else {
227 $display.= "<td><input type=checkbox name=\"$key\" value=\"1\"";
228 if (chkacl ($this->acl, "$key") == ""){
229 $display.= "checked";
230 }
231 $display.= ">"._($val)."</td>";
232 }
234 if ($switch++ == 1){
235 $display.= " </tr>\n";
236 $switch= 0;
237 }
238 }
240 if ($switch == 1){
241 $display.= "<td></td></tr>";
242 }
243 $display.= "</table>\n";
245 return ($display);
246 }
248 }
250 ?>