79c28d043e02932ef844d1e0807a79ee34434a8b
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 $this->cleanup();
98 $ldap->modify ($this->attrs);
100 show_ldap_error($ldap->get_error());
101 }
104 /* Save data to object */
105 function save_object()
106 {
107 plugin::save_object();
109 if (!isset($_POST['object'])){
110 return;
111 }
113 /* Strip of old information */
114 if ($this->object == "all"){
115 $this->current_acl= preg_replace ( "/[,]?all[,]?/", "", $this->current_acl);
116 }
117 $this->current_acl= preg_replace ( "/[^a-z0-9A-Z]$this->object#[^,]*[,]?/", "", $this->current_acl);
119 /* assemble new attributes */
120 $attrs= "";
121 if (isset($_POST['all'])){
122 $attrs.= "#all";
123 }
124 if ($this->object != "all" && !isset($_POST['all']) && $this->object != ""){
125 foreach ($this->objects[$this->object] as $key => $val){
126 if (is_integer($key)){
127 $aname= $val;
128 } else {
129 $aname= $key;
130 }
131 if (isset($_POST[$aname])){
132 $attrs.= "#$aname";
133 }
134 }
135 }
137 /* append information */
138 if ($this->current_acl != "" && $attrs != ""){
139 $this->current_acl.= ",";
140 }
141 if ($attrs != ""){
142 $tmp= $this->object;
143 $attrs= $tmp.$attrs;
144 }
145 $this->current_acl.= $attrs;
146 if (preg_match("/all#all/", $this->current_acl)){
147 $this->current_acl= "all";
148 }
149 if (preg_match("/^all,/", $this->current_acl)){
150 $this->current_acl= "all";
151 }
153 /* Save current object selection */
154 if (isset($_POST['object'])){
155 $this->object= $_POST['object'];
156 }
157 if (isset($_POST['selfflag'])){
158 $this->selfflag= TRUE;
159 } else {
160 $this->selfflag= FALSE;
161 }
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 ?>