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 var $CopyPasteVars = array("current_acl");
31 function acl ($config, $dn= NULL, $parent= NULL)
32 {
33 plugin::plugin($config, $dn, $parent);
35 /* WorkAround */
36 include "acl_definition.inc";
37 $this->objects= $ACLD;
38 $tmp= array_keys($this->objects);
39 $this->object= reset($tmp);
41 $this->selfflag= FALSE;
42 if (isset($this->attrs['gosaSubtreeACL'][0])){
43 $this->current_acl= preg_replace("/^[^:]*:/", "", $this->attrs['gosaSubtreeACL'][0]);
44 if (preg_match("/^!:/", $this->attrs['gosaSubtreeACL'][0])){
45 $this->selfflag= TRUE;
46 }
47 }
49 /* This is allways true */
50 $this->is_account= TRUE;
51 }
53 function execute()
54 {
55 /* Call parent execute */
56 plugin::execute();
58 /* Do we represent a valid group? */
59 if (!$this->is_account && $this->parent == NULL){
60 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
61 _("This 'dn' is no acl container.")."</b>";
62 return ($display);
63 }
65 /* Show main page */
66 $smarty= get_smarty();
67 if ($_SESSION['js']==FALSE){
68 $smarty->assign("javascript", "false");
69 } else {
70 $smarty->assign("javascript", "true");
71 }
72 $smarty->assign("object", $this->object);
73 $obj= array();
74 foreach($this->objects as $key => $value){
75 $obj[$key]= $key;
76 }
77 if ($this->selfflag){
78 $smarty->assign("selfflag", "checked");
79 } else {
80 $smarty->assign("selfflag", "");
81 }
82 $smarty->assign("objects", $obj);
83 $display= $smarty->fetch (get_template_path('acl.tpl', TRUE));
85 /* Show acl stuff */
86 $this->acl= get_module_permission (array($this->current_acl), $this->object, "");
87 $display.= $this->print_attributes ($this->objects[$this->object]);
88 return ($display);
89 }
92 function remove_from_parent()
93 {
94 plugin::remove_from_parent();
96 $this->attrs['gosaSubtreeACL']= array();
98 $ldap= $this->config->get_ldap_link();
99 $ldap->cd($this->dn);
100 $this->cleanup();
101 $ldap->modify ($this->attrs);
102 show_ldap_error($ldap->get_error(), _("Removing ACL information failed"));
103 }
106 /* Save data to object */
107 function save_object()
108 {
109 plugin::save_object();
111 if (!isset($_POST['object'])){
112 return;
113 }
115 /* Strip of old information */
116 if ($this->object == "all"){
117 $this->current_acl= preg_replace ( "/[,]?all[,]?/", "", $this->current_acl);
118 }
119 $this->current_acl= preg_replace ( "/(^|[^a-z0-9A-Z])$this->object#[^,]*[,]?/", ",", $this->current_acl);
121 /* assemble new attributes */
122 $attrs= "";
123 if (isset($_POST['all'])){
124 $attrs.= "#all";
125 }
126 if ($this->object != "all" && !isset($_POST['all']) && $this->object != ""){
127 foreach ($this->objects[$this->object] as $key => $val){
128 if (is_integer($key)){
129 $aname= $val;
130 } else {
131 $aname= $key;
132 }
133 if (isset($_POST[$aname])){
134 $attrs.= "#$aname";
135 }
136 }
137 }
139 /* append information */
140 if ($attrs != ""){
141 $tmp= $this->object;
142 $attrs= $tmp.$attrs;
143 }
144 if ($this->current_acl != "" && $attrs != ""){
145 $this->current_acl.= ",";
146 }
147 $this->current_acl.= $attrs;
148 if (preg_match("/all#all/", $this->current_acl)){
149 $this->current_acl= "all";
150 }
151 if (preg_match("/^all,/", $this->current_acl)){
152 $this->current_acl= "all";
153 }
155 /* Save current object selection */
156 if (isset($_POST['object'])){
157 $this->object= $_POST['object'];
158 }
159 if (isset($_POST['selfflag'])){
160 $this->selfflag= TRUE;
161 } else {
162 $this->selfflag= FALSE;
163 }
165 /* Strip trailing colon... */
166 $this->current_acl= preg_replace("/,$/", "", $this->current_acl);
167 }
170 /* Save to LDAP */
171 function save()
172 {
173 /* Write back to LDAP */
174 $ldap= $this->config->get_ldap_link();
176 /* Read stuff and only modify subtreeACL entries */
177 plugin::save();
179 if ($this->current_acl != ""){
180 if ($this->selfflag){
181 $this->attrs['gosaSubtreeACL']= "!:".$this->current_acl;
182 } else {
183 $this->attrs['gosaSubtreeACL']= ":".$this->current_acl;
184 }
185 } else {
186 $objectclasses= array();
187 foreach ($this->attrs['objectClass'] as $oc){
188 if (!preg_match('/gosaObject/i', $oc)){
189 $objectclasses[]= $oc;
190 }
191 }
192 $this->attrs['objectClass']= $objectclasses;
193 $this->attrs['gosaSubtreeACL']= array();
194 }
196 /* Modify class */
197 $ldap->cd($this->dn);
198 $this->cleanup();
199 $ldap->modify ($this->attrs);
201 show_ldap_error($ldap->get_error(), _("Saving ACL information failed"));
202 }
205 function print_attributes ($name)
206 {
207 $display= "<input type=checkbox name=\"all\" value=\"1\"";
208 if (chkacl ($this->acl, "all") == ""){
209 $display.= " checked";
210 }
211 $display.= "><b>"._("All fields are writeable")."</b><br>";
213 # Put strings in right order
214 asort ($name);
216 # Generate checklist
217 $display.= "<table summary=\"\" style=\"width:100%;\">\n";
218 $switch= 0;
219 foreach ($name as $key => $val){
220 if ($switch == 0){
221 $display.= " <tr>\n";
222 }
224 if (is_integer($key)){
225 $display.= "<td><input type=checkbox name=\"$val\" value=\"1\" ";
226 if (chkacl ($this->acl, "$val") == ""){
227 $display.= "checked";
228 }
229 $display.= ">$val</td>";
230 } else {
231 $display.= "<td><input type=checkbox name=\"$key\" value=\"1\"";
232 if (chkacl ($this->acl, "$key") == ""){
233 $display.= "checked";
234 }
235 $display.= ">"._($val)."</td>";
236 }
238 if ($switch++ == 1){
239 $display.= " </tr>\n";
240 $switch= 0;
241 }
242 }
244 if ($switch == 1){
245 $display.= "<td></td></tr>";
246 }
247 $display.= "</table>\n";
249 return ($display);
250 }
252 }
254 ?>