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