ed4489d30420a8f62af7b00def5012b010937fb1
1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2004 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_ogroups.inc";
22 class ogroupManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Object groups";
26 var $plDescription= "This does something";
28 /* attribute list for save action */
29 var $attributes= array();
30 var $objectclasses= array();
31 var $obtypes= array();
32 var $ogroup;
34 function ogroupManagement ($config, $dn= NULL)
35 {
36 /* Include config object */
37 $this->config= $config;
38 $this->ui= get_userinfo();
40 /* Fill translation array */
41 $this->obtypes= array( "posixAccount" => _("UNIX accounts"),
42 "posixGroup" => _("Groups"),
43 "gosaDepartment" => _("Departments"),
44 "gosaApplication" => _("Applications"),
45 "goServer" => _("Servers"),
46 "gotoTerminal" => _("Thin Clients"),
47 "gotoWorkstation" => _("Workstations"),
48 "goFonHardware" => _("Phone"),
49 "gotoPrinter" => _("Printer"));
50 asort($this->obtypes);
52 /* Get global filter config */
53 if (!is_global("ogroupfilter")){
54 $ui= get_userinfo();
55 $base= get_base_from_people($ui->dn);
56 $ogroupfilter= array( "usergroups" => "checked",
57 "groupgroups" => "checked",
58 "appgroups" => "checked",
59 "depgroups" => "checked",
60 "servergroups" => "checked",
61 "wsgroups" => "checked",
62 "prtgroups" => "checked",
63 "tcgroups" => "checked",
64 "fongroups" => "checked",
65 "depselect" => $base,
66 "regex" => "*");
67 register_global("ogroupfilter", $ogroupfilter);
68 }
69 }
71 function execute()
72 {
73 /* Call parent execute */
74 plugin::execute();
76 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/");
78 /* Prepare template */
79 $smarty= get_smarty();
81 $ogroupfilter= get_global("ogroupfilter");
82 $s_action = "";
83 $s_entry = "";
85 foreach( array("depselect", "regex") as $type){
86 if (isset($_POST[$type])){
87 $ogroupfilter[$type]= $_POST[$type];
88 }
89 }
90 if (isset($_POST['Ogroup_dialog_posted'])){
91 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
92 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups") as $type){
94 if (isset($_POST[$type])) {
95 $ogroupfilter[$type]= "checked";
96 } else {
97 $ogroupfilter[$type]= "";
98 }
99 }
100 }
101 if (isset($_GET['search'])){
102 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
103 if ($s == "**"){
104 $s= "*";
105 }
106 $ogroupfilter['regex']= $s;
107 }
109 /* Test Posts */
110 foreach($_POST as $key => $val){
111 // Post for delete
112 if(preg_match("/group_del.*/",$key)){
113 $s_action = "del";
114 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
115 // Post for edit
116 }elseif(preg_match("/group_edit_.*/",$key)){
117 $s_action="edit";
118 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
119 // Post for new
120 }elseif(preg_match("/dep_back.*/i",$key)){
121 $s_action="back";
122 }elseif(preg_match("/group_new.*/",$key)){
123 $s_action="new";
124 }elseif(preg_match("/dep_home.*/i",$key)){
125 $s_action="home";
126 }elseif(preg_match("/group_tplnew.*/i",$key)){
127 $s_action="new_tpl";
128 }elseif(preg_match("/group_chgpw.*/i",$key)){
129 $s_action="change_pw";
130 $s_entry = preg_replace("/group_chgpw_/i","",$key);
131 }elseif(preg_match("/dep_root.*/i",$key)){
132 $s_action="root";
133 }
134 }
135 $s_entry = preg_replace("/_.$/","",$s_entry);
137 /* Department changed? */
138 if(isset($_POST['depselect']) && $_POST['depselect']){
139 $ogroupfilter['depselect']= $_POST['depselect'];
140 }
142 /* Start for New List Managment */
143 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
144 $s_action="open";
145 $s_entry = base64_decode($_GET['dep_id']);
146 $ogroupfilter['depselect']= "".$this->config->departments[trim($s_entry)];
147 }
149 /* If Backbutton is Posted */
150 if($s_action=="back"){
151 $base_back = preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']);
152 $base_back = convert_department_dn($base_back);
154 if(isset($this->config->departments[trim($base_back)])){
155 $ogroupfilter['depselect']= $this->config->departments[trim($base_back)];
156 }else{
157 $ogroupfilter['depselect']= $this->config->departments["/"];
158 }
159 register_global("ogroupfilter", $ogroupfilter);
160 }
162 /* Homebutton is posted */
163 if($s_action=="home"){
164 $ogroupfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
165 $ogroupfilter['depselect']=(preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']));
166 }
168 /* root posted */
169 if($s_action=="root"){
170 $ogroupfilter['depselect']=($this->config->current['BASE']);
171 }
173 // Edit if
174 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
175 $s_action ="edit";
176 $s_entry = $_GET['id'];
177 }
179 register_global("ogroupfilter", $ogroupfilter);
181 $this->reload();
183 /* Check for exeeded sizelimit */
184 if (($message= check_sizelimit()) != ""){
185 return($message);
186 }
188 /* New group? */
189 if ($s_action=="new"){
191 /* By default we set 'dn' to 'new', all relevant plugins will
192 react on this. */
193 $this->dn= "new";
195 /* Create new usertab object */
196 $this->ogroup= new ogrouptabs($this->config,
197 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
198 }
200 if ($s_action=="del"){
202 /* Get 'dn' from posted 'uid' */
203 $this->dn= $this->ogrouplist[$s_entry]['dn'];
205 /* Load permissions for selected 'dn' and check if
206 we're allowed to remove this 'dn' */
207 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
208 $this->acl= get_module_permission($acl, "ogroup", $this->dn);
209 if (chkacl($this->acl, "delete") == ""){
211 /* Check locking, save current plugin in 'back_plugin', so
212 the dialog knows where to return. */
213 if (($user= get_lock($this->dn)) != ""){
214 return(gen_locked_message ($user, $this->dn));
215 }
217 /* Lock the current entry, so nobody will edit it during deletion */
218 add_lock ($this->dn, $this->ui->dn);
219 $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), LDAP::fix($this->dn)));
220 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
221 } else {
223 /* Obviously the user isn't allowed to delete. Show message and
224 clean session. */
225 print_red (_("You are not allowed to delete this object group!"));
226 }
227 }
229 /* Confirmation for deletion has been passed. Group should be deleted. */
230 if (isset($_POST['delete_group_confirm'])){
232 /* Some nice guy may send this as POST, so we've to check
233 for the permissions again. */
234 if (chkacl($this->acl, "delete") == ""){
236 /* Delete request is permitted, perform LDAP action */
237 $this->ogroup= new ogrouptabs($this->config,
238 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
239 $this->ogroup->set_acl(array($this->acl));
240 $this->ogroup->delete ();
241 gosa_log ("Object group'".$this->dn."' has been removed");
242 unset ($this->ogroup);
243 $this->ogroup= NULL;
245 /* Group list has changed, reload it. */
246 $this->reload ();
247 } else {
249 /* Normally this shouldn't be reached, send some extra
250 logs to notify the administrator */
251 print_red (_("You are not allowed to delete this object group!"));
252 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
253 }
255 /* Remove lock file after successfull deletion */
256 del_lock ($this->dn);
257 unset($_SESSION['objectinfo']);
258 }
261 /* Delete group canceled? */
262 if (isset($_POST['delete_cancel'])){
263 del_lock ($this->dn);
264 unset($_SESSION['objectinfo']);
265 }
267 if ($s_action=="edit"){
269 /* Get 'dn' from posted 'uid', must be unique */
270 $this->dn= $this->ogrouplist[$s_entry]['dn'];
272 /* Check locking, save current plugin in 'back_plugin', so
273 the dialog knows where to return. */
274 if (($user= get_lock($this->dn)) != ""){
275 return(gen_locked_message ($user, $this->dn));
276 }
278 /* Lock the current entry, so everyone will get the
279 above dialog */
280 add_lock ($this->dn, $this->ui->dn);
282 /* Set up the users ACL's for this 'dn' */
283 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
285 /* Register grouptab to trigger edit dialog */
286 $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
287 $this->dn);
288 $this->ogroup->set_acl($acl);
289 $_SESSION['objectinfo']= $this->dn;
290 }
292 /* Finish button has been pressed */
293 if (isset($_POST['edit_finish'])){
295 /* Check tabs, will feed message array */
296 $message= $this->ogroup->check();
298 /* Save, or display error message? */
299 if (count($message) == 0){
301 /* Save user data to ldap */
302 $this->ogroup->save();
303 gosa_log ("Object group'".$this->dn."' has been saved");
305 /* Group has been saved successfully, remove lock from
306 LDAP. */
307 if ($this->dn != "new"){
308 del_lock ($this->dn);
309 }
311 /* There's no page reload so we have to read new users at
312 this point. */
313 $this->reload ();
314 unset ($this->ogroup);
315 $this->ogroup= NULL;
316 unset ($_SESSION['objectinfo']);
318 } else {
319 /* Ok. There seem to be errors regarding to the tab data,
320 show message and continue as usual. */
321 show_errors($message);
322 }
323 }
325 /* Cancel dialogs */
326 if (isset($_POST['edit_cancel'])){
327 del_lock ($this->ogroup->dn);
328 unset ($this->ogroup);
329 $this->ogroup= NULL;
330 unset($_SESSION['objectinfo']);
331 }
333 /* Show dialog if object is present */
334 if ($this->ogroup){
335 $display= $this->ogroup->execute();
337 /* Don't show buttons if tab dialog requests this */
338 if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
339 $display.= "<p style=\"text-align:right\">\n";
340 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
341 $display.= " \n";
342 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
343 $display.= "</p>";
344 }
345 return ($display);
346 }
348 /* Prepare departments */
349 $options= "";
350 foreach ($this->config->idepartments as $key => $value){
351 if ($ogroupfilter['depselect'] == $key){
352 $options.= "<option selected value='$key'>$value</option>";
353 } else {
354 $options.= "<option value='$key'>$value</option>";
355 }
356 }
358 // Managment
359 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
360 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
361 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."'
362 name='dep_root' alt='"._("Root")."'> ".
363 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."'
364 alt='"._("Home")."' name='dep_home'> ".
365 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
366 " <input class='center' type='image' align='middle' src='images/list_new_ogroup.png' title='"._("Create new object group")."' alt='"._("new")."' name='group_new'>".
367 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
368 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
369 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
370 "</div>";
373 $actions = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
374 $actions.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
376 // Defining Links
377 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
379 // image Buttons
380 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
381 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
383 // Extension images
384 $mailimg = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
386 // Space
387 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
389 // List Setup
390 $divlist = new divlist("ogroubstab");
391 $divlist->SetHeader(array(
392 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
393 array("string" => _("Name of object groups")." / "._("Departments"), "attach" => "style=''"),
394 array("string" => _("Properties"), "attach" => "style='width:136px;'"),
395 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")
396 ));
399 $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
400 $divlist->SetEntriesPerPage(0);
402 foreach($this->departments as $key=> $val){
404 if(!isset($this->config->departments[trim($key)])){
405 $this->config->departments[trim($key)]="";
406 }
408 $non_empty="";
409 $keys= str_replace("/","\/",$key);
410 foreach($this->config->departments as $keyd=>$vald ){
411 if(preg_match("/".$keys."\/.*/",$keyd)){
412 $non_empty="full";
413 }
414 }
418 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='"._("Department")."'>", "attach" => "style='text-align:center;width:20px;'");
419 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
420 $field3 = array("string" => " ", "attach" => "style='width:136px;'");
421 $field4 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
423 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
424 }
426 // Assigning ogroups
427 foreach($this->ogrouplist as $key => $val){
429 if(isset($val['mail'])){
430 $mail = $mailimg;
431 }else{
432 $mail = $empty;
433 }
435 $title = "title='dn : ".$val['dn']."'";
437 if(!isset($val['description'][0])){
438 $desc = "";
439 }else{
440 $desc = " - [ ".$val['description'][0]." ]";
441 }
442 $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width:20px;'");
443 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
444 $field3 = array("string" => $this->convert_list($val)." ".$mail, "attach" => "style='width:136px;'");
445 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
447 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
448 }
455 /* Show main page */
456 $smarty->assign("search_image", get_template_path('images/search.png'));
457 $smarty->assign("tree_image", get_template_path('images/tree.png'));
458 $smarty->assign("infoimage", get_template_path('images/info.png'));
459 $smarty->assign("launchimage", get_template_path('images/launch.png'));
460 $smarty->assign("deplist", $this->config->idepartments);
462 $smarty->assign("groupshead", $listhead);
463 $smarty->assign("groups", $divlist->DrawList());
465 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
466 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups", "regex", "depselect") as $type){
467 $smarty->assign("$type", $ogroupfilter[$type]);
468 }
470 $smarty->assign("hint", print_sizelimit_warning());
471 $smarty->assign("apply", apply_filter());
472 $smarty->assign("alphabet", generate_alphabet());
473 return ($smarty->fetch (get_template_path('headpage.tpl', TRUE)));
474 }
477 function convert_list($input)
478 {
479 $temp= "";
482 $conv= array(
483 "U" => array("select_user.png",_("User")),
484 "G" => array("select_groups.png",_("Group")),
485 "A" => array("select_application.png",_("Application")),
486 "D" => array("select_department.png",_("Department")),
487 "S" => array("select_server.png",_("Server")),
488 "F" => array("select_phone.png",_("Phone")),
489 "W" => array("select_workstation.png",_("Workstation")),
490 "T" => array("select_terminal.png",_("Terminal")),
491 "P" => array("select_printer.png",_("Printer")));
493 /* Assemble picture */
494 $type= $input['gosaGroupObjects'][0];
495 $type= preg_replace("/[^A-Z]/i","",$type);
496 if (isset($type[0])){
497 $p1['pic']= $conv[$type[0]][0];
498 $p1['tit']= $conv[$type[0]][1];
499 $p1['alt']= $type[0];
500 } else {
501 $p1['pic']= "empty.png";
502 $p1['tit']= "";
503 $p1['alt']= "";
504 }
505 if (isset($type[1])){
506 $p2['pic']= $conv[$type[1]][0];
507 $p2['alt']= $type[1];
508 $p2['tit']= $conv[$type[1]][1];
509 } else {
510 $p2['pic']= "empty.png";
511 $p2['alt']= "";
512 $p2['tit']= "";
513 }
514 $temp = "<img class='center' src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
515 $temp.= "<img class='center' src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
516 return ($temp);
517 }
520 function reload()
521 {
522 /* Get config */
523 $ogroupfilter= get_global('ogroupfilter');
525 /* Set base for all searches */
526 $base= $ogroupfilter['depselect'];
528 /* Regex filter? */
529 if ($ogroupfilter['regex'] != ""){
530 $regex= $ogroupfilter['regex'];
531 } else {
532 $regex= "*";
533 }
535 /* User filter? */
536 $this->oogrouplist= array();
538 /* Generate oogrouplist filter */
539 $filter= "";
541 if ($ogroupfilter['usergroups'] == "checked"){
542 $filter.= "(gosaGroupObjects=*U*)";
543 }
544 if ($ogroupfilter['groupgroups'] == "checked"){
545 $filter.= "(gosaGroupObjects=*G*)";
546 }
547 if ($ogroupfilter['appgroups'] == "checked"){
548 $filter.= "(gosaGroupObjects=*A*)";
549 }
550 if ($ogroupfilter['depgroups'] == "checked"){
551 $filter.= "(gosaGroupObjects=*D*)";
552 }
553 if ($ogroupfilter['servergroups'] == "checked"){
554 $filter.= "(gosaGroupObjects=*S*)";
555 }
556 if ($ogroupfilter['wsgroups'] == "checked"){
557 $filter.= "(gosaGroupObjects=*W*)";
558 }
559 if ($ogroupfilter['prtgroups'] == "checked"){
560 $filter.= "(gosaGroupObjects=*P*)";
561 }
562 if ($ogroupfilter['tcgroups'] == "checked"){
563 $filter.= "(gosaGroupObjects=*T*)";
564 }
565 if ($ogroupfilter['fongroups'] == "checked"){
566 $filter.= "(gosaGroupObjects=*F*)";
567 }
568 $filter.= "(gosaGroupObjects=[])";
570 if ($filter != ""){
571 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames)(|$filter))";
572 } else {
573 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames))";
574 }
576 $groups = ($this->config->current['GROUPS']);
578 $res= get_list($this->ui->subtreeACL, "$filter",FALSE, $groups.",".$base, array("*"), TRUE);
579 $this->ogrouplist= $res;
580 ksort ($this->ogrouplist);
581 reset ($this->ogrouplist);
584 /* NEW LIST MANAGMENT
585 * We also need to search for the departments
586 * So we are able to navigate like in konquerer
587 */
588 $peopleOU = get_people_ou();
590 if(empty($peopleOU)){
591 $base2 = $base;
592 }else{
593 $base2 = preg_replace("/".$peopleOU."/i","",$base);
594 }
596 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
597 TRUE, $base2, array("ou", "description"), TRUE);
601 $this->departments= array();
602 $tmp = array();
603 foreach ($res3 as $value){
604 $tmp[strtolower($value['dn']).$value['dn']]=$value;
605 }
606 ksort($tmp);
607 foreach($tmp as $value){
608 if(isset($value["description"][0])){
609 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
610 }else{
611 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
612 }
613 }
614 /* END NEW LIST MANAGMENT
615 */
617 $tmp=array();
618 foreach($this->ogrouplist as $tkey => $val ){
619 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
620 }
621 ksort($tmp);
622 $this->ogrouplist=array();
623 foreach($tmp as $val){
624 $this->ogrouplist[]=$val;
625 }
626 reset ($this->ogrouplist);
630 }
632 }
634 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
635 ?>