363ef2eac585a994ec0ff8b868695c24954393e5
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 }
164 }
167 /* Save to LDAP */
168 function save()
169 {
170 /* Write back to LDAP */
171 $ldap= $this->config->get_ldap_link();
173 /* Read stuff and only modify subtreeACL entries */
174 plugin::save();
176 if ($this->current_acl != ""){
177 if ($this->selfflag){
178 $this->attrs['gosaSubtreeACL']= "!:".$this->current_acl;
179 } else {
180 $this->attrs['gosaSubtreeACL']= ":".$this->current_acl;
181 }
182 } else {
183 $objectclasses= array();
184 foreach ($this->attrs['objectClass'] as $oc){
185 if (!preg_match('/gosaObject/i', $oc)){
186 $objectclasses[]= $oc;
187 }
188 }
189 $this->attrs['objectClass']= $objectclasses;
190 $this->attrs['gosaSubtreeACL']= array();
191 }
193 /* Modify class */
194 $ldap->cd($this->dn);
195 $this->cleanup();
196 $ldap->modify ($this->attrs);
198 show_ldap_error($ldap->get_error(), _("Saving ACL information failed"));
199 }
202 function print_attributes ($name)
203 {
204 $display= "<input type=checkbox name=\"all\" value=\"1\"";
205 if (chkacl ($this->acl, "all") == ""){
206 $display.= " checked";
207 }
208 $display.= "><b>"._("All fields are writeable")."</b><br>";
210 # Put strings in right order
211 asort ($name);
213 # Generate checklist
214 $display.= "<table summary=\"\" style=\"width:100%;\">\n";
215 $switch= 0;
216 foreach ($name as $key => $val){
217 if ($switch == 0){
218 $display.= " <tr>\n";
219 }
221 if (is_integer($key)){
222 $display.= "<td><input type=checkbox name=\"$val\" value=\"1\" ";
223 if (chkacl ($this->acl, "$val") == ""){
224 $display.= "checked";
225 }
226 $display.= ">$val</td>";
227 } else {
228 $display.= "<td><input type=checkbox name=\"$key\" value=\"1\"";
229 if (chkacl ($this->acl, "$key") == ""){
230 $display.= "checked";
231 }
232 $display.= ">"._($val)."</td>";
233 }
235 if ($switch++ == 1){
236 $display.= " </tr>\n";
237 $switch= 0;
238 }
239 }
241 if ($switch == 1){
242 $display.= "<td></td></tr>";
243 }
244 $display.= "</table>\n";
246 return ($display);
247 }
249 }
251 ?>