1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /* Sort multidimensional arrays for key 'text' */
24 function sort_list($val1, $val2)
25 {
26 $v1= strtolower($val1['text']);
27 $v2= strtolower($val2['text']);
28 if ($v1 > $v2){
29 return 1;
30 }
31 if ($v1 < $v2){
32 return -1;
33 }
34 return 0;
35 }
38 class ogroup extends plugin
39 {
40 /* Variables */
41 var $cn= "";
42 var $description= "";
43 var $base= "";
44 var $gosaGroupObjects= "";
45 var $department= "";
46 var $objects= array();
47 var $objcache= array();
48 var $memberList= array();
49 var $member= array();
50 var $orig_dn= "";
51 var $group_dialog= FALSE;
52 var $view_logged = FALSE;
54 var $accessTo= array();
55 var $trustModel= "";
56 var $show_ws_dialog = FALSE;
58 var $was_trust_account= FALSE;
60 /* attribute list for save action */
61 var $attributes= array("cn", "description", "gosaGroupObjects","member","accessTo","trustModel");
62 var $objectclasses= array("top", "gosaGroupOfNames");
64 function ogroup (&$config, $dn= NULL)
65 {
66 plugin::plugin ($config, $dn);
67 $this->orig_dn= $dn;
69 $this->member = array();
71 /* Load member objects */
72 if (isset($this->attrs['member'])){
73 foreach ($this->attrs['member'] as $key => $value){
74 if ("$key" != "count"){
75 $value= @LDAP::convert($value);
76 $this->member["$value"]= "$value";
77 }
78 }
79 }
80 $this->is_account= TRUE;
82 /* Get global filter config */
83 if (!session::is_set("ogfilter")){
84 $ui= get_userinfo();
85 $base= get_base_from_people($ui->dn);
86 $ogfilter= array( "dselect" => $base,
87 "regex" => "*");
88 session::set("ogfilter", $ogfilter);
89 }
90 $ogfilter= session::get('ogfilter');
92 /* Adjust flags */
93 foreach( array( "U" => "accounts",
94 "G" => "groups",
95 "A" => "applications",
96 "D" => "departments",
97 "S" => "servers",
98 "W" => "workstations",
99 "O" => "winstations",
100 "T" => "terminals",
101 "F" => "phones",
102 "_" => "subtrees",
103 "P" => "printers") as $key => $val){
105 if (preg_match("/$key/", $this->gosaGroupObjects)){
106 $ogfilter[$val]= "checked";
107 } else {
108 $ogfilter[$val]= "";
109 }
110 }
111 session::set("ogfilter", $ogfilter);
113 if(session::is_set('CurrentMainBase')){
114 $this->base = session::get('CurrentMainBase');
115 }
117 /* Set base */
118 if ($this->dn == "new"){
119 $this->base = session::get('CurrentMainBase');
120 } else {
121 $this->base= preg_replace("/^[^,]+,".normalizePreg(get_ou("ogroupou"))."/","",$this->dn);
123 /* Is this account a trustAccount? */
124 if ($this->is_account && isset($this->attrs['trustModel'])){
125 $this->trustModel= $this->attrs['trustModel'][0];
126 $this->was_trust_account= TRUE;
127 } else {
128 $this->was_trust_account= FALSE;
129 $this->trustModel= "";
130 }
132 $this->accessTo = array();
133 if ($this->is_account && isset($this->attrs['accessTo'])){
134 for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
135 $tmp= $this->attrs['accessTo'][$i];
136 $this->accessTo[$tmp]= $tmp;
137 }
138 }
139 }
141 /* Load member data */
142 $this->reload();
143 }
145 function AddDelMembership($NewMember = false){
147 if($NewMember){
149 /* Add member and force reload */
150 $this->member[$NewMember]= $NewMember;
151 $this->reload();
153 $this->memberList[$NewMember]= $this->objcache[$NewMember];
154 unset ($this->objects[$NewMember]);
155 uasort ($this->memberList, 'sort_list');
156 reset ($this->memberList);
157 }else{
158 /* Delete objects from group */
159 if (isset($_POST['delete_membership']) && isset($_POST['members'])){
160 foreach ($_POST['members'] as $value){
161 $this->objects["$value"]= $this->memberList[$value];
162 unset ($this->memberList["$value"]);
163 unset ($this->member["$value"]);
164 uasort ($this->objects, 'sort_list');
165 reset ($this->objects);
166 }
167 $this->reload();
168 }
170 /* Add objects to group */
171 if (isset($_POST['add_object_finish']) && isset($_POST['objects'])){
173 $tmp = "";
174 foreach($this->memberList as $obj){
175 $tmp .= $obj['type'];
176 }
177 $skipped = FALSE;
178 foreach ($_POST['objects'] as $value){
179 if(preg_match("/T/",$tmp) && $this->objects[$value]['type'] == "W"){
180 $skipped =TRUE;
181 }elseif(preg_match("/W/",$tmp) && $this->objects[$value]['type'] == "T"){
182 $skipped =TRUE;
183 }else{
184 $this->memberList["$value"]= $this->objects[$value];
185 $this->member["$value"]= $value;
186 unset ($this->objects[$value]);
187 uasort ($this->memberList, 'sort_list');
188 reset ($this->memberList);
189 }
190 }
191 if($skipped){
192 msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
193 }
194 $this->reload();
195 }
196 }
197 }
199 function execute()
200 {
201 /* Call parent execute */
202 plugin::execute();
204 if(!$this->view_logged){
205 $this->view_logged = TRUE;
206 new log("view","ogroups/".get_class($this),$this->dn);
207 }
210 /* Do we represent a valid group? */
211 if (!$this->is_account){
212 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
213 msgPool::noValidExtension("object group")."</b>";
214 return ($display);
215 }
218 /* Load templating engine */
219 $smarty= get_smarty();
221 $tmp = $this->plInfo();
222 foreach($tmp['plProvidedAcls'] as $name => $translation){
223 $smarty->assign($name."ACL",$this->getacl($name));
224 }
226 /* Base select dialog */
227 $once = true;
228 foreach($_POST as $name => $value){
229 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
230 $once = false;
231 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
232 $this->dialog->setCurrentBase($this->base);
233 }
234 }
236 /***********
237 * Trusts
238 ***********/
240 /* Add user workstation? */
241 if (isset($_POST["add_ws"])){
242 $this->show_ws_dialog= TRUE;
243 $this->dialog= TRUE;
244 }
246 /* Add user workstation? */
247 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
248 foreach($_POST['wslist'] as $ws){
249 $this->accessTo[$ws]= $ws;
250 }
251 ksort($this->accessTo);
252 $this->is_modified= TRUE;
253 }
255 /* Remove user workstations? */
256 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
257 foreach($_POST['workstation_list'] as $name){
258 unset ($this->accessTo[$name]);
259 }
260 $this->is_modified= TRUE;
261 }
263 /* Add user workstation finished? */
264 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
265 $this->show_ws_dialog= FALSE;
266 $this->dialog= FALSE;
267 }
269 /* Show ws dialog */
270 if ($this->show_ws_dialog){
271 /* Save data */
272 $sysfilter= session::get("sysfilter");
273 foreach( array("depselect", "regex") as $type){
274 if (isset($_POST[$type])){
275 $sysfilter[$type]= $_POST[$type];
276 }
277 }
278 if (isset($_GET['search'])){
279 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
280 if ($s == "**"){
281 $s= "*";
282 }
283 $sysfilter['regex']= $s;
284 }
285 session::set("sysfilter", $sysfilter);
287 /* Get workstation list */
288 $exclude= "";
289 foreach($this->accessTo as $ws){
290 $exclude.= "(cn=$ws)";
291 }
292 if ($exclude != ""){
293 $exclude= "(!(|$exclude))";
294 }
295 $regex= $sysfilter['regex'];
296 $filter= "(&(|(objectClass=goServer)(objectClass=gotoWorkstation)(objectClass=gotoTerminal))$exclude(cn=*)(cn=$regex))";
298 $deps_a = array(get_ou("serverou"),
299 get_ou("terminalou"),
300 get_ou("workstationou"));
301 $res= get_sub_list($filter, array("terminal","server","workstation"), $deps_a, get_ou("systemsou").$sysfilter['depselect'],
302 array("cn"), GL_SUBSEARCH | GL_SIZELIMIT);
303 $wslist= array();
304 foreach ($res as $attrs){
305 $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
306 }
307 asort($wslist);
308 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
309 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
310 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
311 $smarty->assign("deplist", $this->config->idepartments);
312 $smarty->assign("alphabet", generate_alphabet());
313 foreach( array("depselect", "regex") as $type){
314 $smarty->assign("$type", $sysfilter[$type]);
315 }
316 $smarty->assign("hint", print_sizelimit_warning());
317 $smarty->assign("wslist", $wslist);
318 $smarty->assign("apply", apply_filter());
319 $display= $smarty->fetch (get_template_path('trust_machines.tpl', TRUE, dirname(__FILE__)));
320 return ($display);
321 }
323 /***********
324 * Ende - Trusts
325 ***********/
328 /* Dialog handling */
329 if(is_object($this->dialog) && $this->acl_is_moveable()){
330 /* Must be called before save_object */
331 $this->dialog->save_object();
333 if($this->dialog->isClosed()){
334 $this->dialog = false;
335 }elseif($this->dialog->isSelected()){
337 /* A new base was selected, check if it is a valid one */
338 $tmp = $this->get_allowed_bases();
339 if(isset($tmp[$this->dialog->isSelected()])){
340 $this->base = $this->dialog->isSelected();
341 }
342 $this->dialog= false;
343 }else{
344 return($this->dialog->execute());
345 }
346 }
348 /* Add objects? */
349 if (isset($_POST["edit_membership"])){
350 $this->group_dialog= TRUE;
351 $this->dialog= TRUE;
352 }
354 /* Add objects finished? */
355 if (isset($_POST["add_object_finish"]) || isset($_POST["add_object_cancel"])){
356 $this->group_dialog= FALSE;
357 $this->dialog= FALSE;
358 }
360 /* Manage object add dialog */
361 if ($this->group_dialog){
363 /* Save data */
364 $ogfilter= session::get("ogfilter");
365 foreach( array("dselect", "regex") as $type){
366 if (isset($_POST[$type])){
367 $ogfilter[$type]= $_POST[$type];
368 }
369 }
370 if (isset($_POST['dselect'])){
371 foreach( array("accounts", "groups", "applications", "departments",
372 "servers", "workstations", "winstations", "terminals", "printers","subtrees",
373 "phones") as $type){
375 if (isset($_POST[$type])) {
376 $ogfilter[$type]= "checked";
377 } else {
378 $ogfilter[$type]= "";
379 }
380 }
381 }
382 if (isset($_GET['search'])){
383 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
384 if ($s == "**"){
385 $s= "*";
386 }
387 $ogfilter['regex']= $s;
388 }
389 session::set("ogfilter", $ogfilter);
390 $this->reload();
392 /* Calculate actual groups */
393 $smarty->assign("objects", $this->convert_list($this->objects));
395 /* Show dialog */
396 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
397 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
398 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
399 $smarty->assign("deplist", $this->config->idepartments);
400 $smarty->assign("alphabet", generate_alphabet());
401 foreach( array("dselect", "regex", "subtrees") as $type){
402 $smarty->assign("$type", $ogfilter[$type]);
403 }
404 $smarty->assign("hint", print_sizelimit_warning());
405 $smarty->assign("apply", apply_filter());
407 /* Build up checkboxes
408 */
409 $ar = array(
410 "departments" => array(
411 "T" => msgPool::selectToView(_("departments")),
412 "C" => (isset($ogfilter['departments']) && ($ogfilter['departments'])),
413 "L" => sprintf(_("Show %s"),_("departments"))),
414 "accounts" => array(
415 "T" => msgPool::selectToView(_("people")),
416 "C" => (isset($ogfilter['accounts']) && ($ogfilter['accounts'])),
417 "L" => sprintf(_("Show %s"),_("people"))),
418 "groups"=> array(
419 "T" => msgPool::selectToView(_("groups")),
420 "C" => (isset($ogfilter['groups']) && ($ogfilter['groups'])),
421 "L" => sprintf(_("Show %s"),_("groups"))),
422 "servers"=> array(
423 "T" => msgPool::selectToView(_("servers")),
424 "C" => (isset($ogfilter['servers']) && ($ogfilter['servers'])),
425 "L" => sprintf(_("Show %s"),_("servers"))),
426 "workstations"=> array(
427 "T" => msgPool::selectToView(_("workstations")),
428 "C" => (isset($ogfilter['workstations']) && ($ogfilter['workstations'])),
429 "L" => sprintf(_("Show %s"),_("workstations"))),
430 "terminals"=> array(
431 "T" => msgPool::selectToView(_("terminals")),
432 "C" => (isset($ogfilter['terminals']) && ($ogfilter['terminals'])),
433 "L" => sprintf(_("Show %s"),_("terminals"))),
434 "printers"=> array(
435 "T" => msgPool::selectToView(_("printer")),
436 "C" => (isset($ogfilter['printers']) && ($ogfilter['printers'])),
437 "L" => sprintf(_("Show %s"),_("printers"))),
438 "phones"=> array(
439 "T" => msgPool::selectToView(_("phones")),
440 "C" => (isset($ogfilter['phones']) && ($ogfilter['phones'])),
441 "L" => sprintf(_("Show %s"),_("phones"))));
443 /* Allow selecting applications if we are having a non
444 release managed application storage */
445 if(!$this->IsReleaseManagementActivated()){
446 $ar["applications"] = array(
447 "T" => msgPool::selectToView(_("applications")),
448 "C" => (isset($ogfilter['applications']) && ($ogfilter['applications'])),
449 "L" => sprintf(_("Show %s"),_("applications")));
450 }
452 $smarty->assign("checkboxes",$ar);
453 $display= $smarty->fetch (get_template_path('ogroup_objects.tpl', TRUE, dirname(__FILE__)));
454 return ($display);
455 }
457 /* Bases / Departments */
458 if ((isset($_POST['base'])) && ($this->acl_is_moveable())){
459 $this->base= $_POST['base'];
460 }
462 /* Assemble combine string */
463 if ($this->gosaGroupObjects == "[]"){
464 $smarty->assign("combinedObjects", _("none"));
465 } elseif (strlen($this->gosaGroupObjects) > 4){
466 $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
467 } else {
468 $conv= array( "U" => _("users"),
469 "G" => _("groups"),
470 "A" => _("applications"),
471 "D" => _("departments"),
472 "S" => _("servers"),
473 "W" => _("workstations"),
474 "O" => _("winstations"),
475 "T" => _("terminals"),
476 "F" => _("phones"),
477 "P" => _("printers"));
479 $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
480 $p1= $conv[$type[0]];
481 error_reporting(0);
482 if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
483 $p2= $conv[$type[1]];
484 $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
485 } else {
486 $smarty->assign("combinedObjects", "$p1");
487 }
488 error_reporting(E_ALL | E_STRICT);
489 }
491 /* Assign variables */
492 $smarty->assign("bases", $this->get_allowed_bases());
493 $smarty->assign("base_select", $this->base);
494 $smarty->assign("department", $this->department);
495 $smarty->assign("members", $this->convert_list($this->memberList));
497 /* Objects have to be tuned... */
498 $smarty->assign("objects", $this->convert_list($this->objects));
500 /* Fields */
501 foreach ($this->attributes as $val){
502 $smarty->assign("$val", $this->$val);
503 }
505 /******
506 Trust account
507 ******/
508 $smarty->assign("trusthide", " disabled ");
509 $smarty->assign("trustmodeACL", $this->getacl("trustModel"));
510 if ($this->trustModel == "fullaccess"){
511 $trustmode= 1;
512 // pervent double disable tag in html code, this will disturb our clean w3c html
513 $smarty->assign("trustmode", $this->getacl("trustModel"));
515 } elseif ($this->trustModel == "byhost"){
516 $trustmode= 2;
517 $smarty->assign("trusthide", "");
518 } else {
519 // pervent double disable tag in html code, this will disturb our clean w3c html
520 $smarty->assign("trustmode", $this->getacl("trustModel"));
521 $trustmode= 0;
522 }
523 $smarty->assign("trustmode", $trustmode);
524 $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
525 2 => _("allow access to these hosts")));
527 $smarty->assign("workstations", $this->accessTo);
529 if((count($this->accessTo))==0){
530 $smarty->assign("emptyArrAccess",true);
531 }else{
532 $smarty->assign("emptyArrAccess",false);
533 }
534 /******
535 Ende - Trust account
536 ******/
538 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
539 }
542 /* Save data to object */
543 function save_object()
544 {
545 /* Save additional values for possible next step */
546 if (isset($_POST['ogroupedit'])){
548 /******
549 Trust account
550 ******/
552 if($this->acl_is_writeable("trustModel")){
553 if (isset($_POST['trustmode'])){
554 $saved= $this->trustModel;
555 if ($_POST['trustmode'] == "1"){
556 $this->trustModel= "fullaccess";
557 } elseif ($_POST['trustmode'] == "2"){
558 $this->trustModel= "byhost";
559 } else {
560 $this->trustModel= "";
561 }
562 if ($this->trustModel != $saved){
563 $this->is_modified= TRUE;
564 }
565 }
566 }
567 /******
568 Ende Trust account
569 ******/
571 /* Create a base backup and reset the
572 base directly after calling plugin::save_object();
573 Base will be set seperatly a few lines below */
574 $base_tmp = $this->base;
575 plugin::save_object();
576 $this->base = $base_tmp;
578 /* Save base, since this is no LDAP attribute */
579 $tmp = $this->get_allowed_bases();
580 if(isset($_POST['base'])){
581 if(isset($tmp[$_POST['base']])){
582 $this->base= $_POST['base'];
583 }
584 }
585 }
586 }
589 /* (Re-)Load objects */
590 function reload()
591 {
592 /*###########
593 Variable initialisation
594 ###########*/
596 $this->objects = array();
597 $this->ui = get_userinfo();
598 $filter = "";
599 $objectClasses = array();
601 $ogfilter = session::get("ogfilter");
602 $regex = $ogfilter['regex'];
604 $ldap= $this->config->get_ldap_link();
605 $ldap->cd ($ogfilter['dselect']);
608 /*###########
609 Generate Filter
610 ###########*/
612 $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount" ,
613 "DN"=> get_people_ou() ,"ACL" => "users"),
614 "groups" => array("OBJ"=>"group", "CLASS"=>"posixGroup" ,
615 "DN"=> get_groups_ou('ogroupou') ,"ACL" => "groups"),
616 "departments" => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
617 "DN"=> "" ,"ACL" => "department"),
618 "servers" => array("OBJ"=>"servgeneric", "CLASS"=>"goServer" ,
619 "DN"=> get_ou('serverou') ,"ACL" => "server"),
620 "workstations" => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
621 "DN"=> get_ou('workstationou') ,"ACL" => "workstation"),
622 "winstations" => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",
623 "DN"=> get_ou('WINSTATIONS') ,"ACL" => "winstation"),
624 "terminals" => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal" ,
625 "DN"=> get_ou('terminalou') ,"ACL" => "terminal"),
626 "printers" => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter" ,
627 "DN"=> get_ou('printerou') ,"ACL" => "printer"),
628 "phones" => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware" ,
629 "DN"=> get_ou('phoneou') ,"ACL" => "phone"));
632 /* Allow searching for applications, if we are not using release managed applications
633 */
634 if(!$this->IsReleaseManagementActivated()){
635 $p_f[ "applications"] = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
636 "DN"=> get_ou('applicationou') ,"ACL" => "application");
637 }
639 /*###########
640 Perform search for selected objectClasses & regex to fill list with objects
641 ###########*/
643 $Get_list_flags = 0;
644 if($ogfilter['subtrees'] == "checked"){
645 $Get_list_flags |= GL_SUBSEARCH;
646 }
648 foreach($p_f as $post_name => $data){
650 if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
652 if($ogfilter['subtrees']){
653 $base = $ogfilter['dselect'];
654 }else{
655 $base = $data['DN'].$ogfilter['dselect'];
656 }
659 $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
660 $res = get_list($filter, $data['ACL'] , $base,
661 array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
663 /* fetch results and append them to the list */
664 foreach($res as $attrs){
666 $type= $this->getObjectType($attrs);
667 $name= $this->getObjectName($attrs);
669 /* Fill array */
670 if (isset($attrs["description"][0])){
671 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
672 } elseif (isset($attrs["uid"][0])) {
673 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
674 } else {
675 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
676 }
677 }
678 }
679 }
680 uasort ($this->objects, 'sort_list');
681 reset ($this->objects);
684 /*###########
685 Build member list and try to detect obsolete entries
686 ###########*/
688 $this->memberList = array();
690 /* Walk through all single member entry */
691 foreach($this->member as $dn){
693 /* The dn for the current member can't be resolved
694 it seams that this entry was removed
695 */
696 /* Try to resolv the entry again, if it still fails, display error msg */
697 $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
699 /* It has failed, add entry with type flag I (Invalid)*/
700 if (!$ldap->success()){
701 $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".@LDAP::fix($dn),"type" => "I");
703 } else {
705 /* Append this entry to our all object list */
707 /* Fetch object */
708 $attrs= $ldap->fetch();
710 $type= $this->getObjectType($attrs);
711 $name= $this->getObjectName($attrs);
713 if (isset($attrs["description"][0])){
714 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
715 } elseif (isset($attrs["uid"][0])) {
716 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
717 } else {
718 $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
719 }
720 $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass'];
722 if(isset($attrs['macAddress'][0])){
723 $this->objcache[$attrs["dn"]]['macAddress'] = $attrs['macAddress'][0];
724 }else{
725 $this->objcache[$attrs["dn"]]['macAddress'] = "";
726 }
728 if(isset($attrs['uid'])){
729 $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid'];
730 }
732 /* Fill array */
733 if (isset($attrs["description"][0])){
734 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
735 } else {
736 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
737 }
739 $this->memberList[$dn]= $this->objects[$attrs["dn"]];
740 }
741 }
742 uasort ($this->memberList, 'sort_list');
743 reset ($this->memberList);
745 /* Assemble types of currently combined objects */
746 $objectTypes= "";
747 foreach ($this->memberList as $dn => $desc){
749 /* Invalid object? */
750 if ($desc['type'] == 'I'){
751 continue;
752 }
754 /* Fine. Add to list. */
755 if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
756 $objectTypes.= $desc['type'];
757 }
758 }
759 $this->gosaGroupObjects= "[$objectTypes]";
760 }
763 function convert_list($input)
764 {
765 $temp= "";
766 $conv= array( "U" => "select_user.png",
767 "G" => "plugins/groups/images/groups.png",
768 "A" => "plugins/ogroups/images/application.png",
769 "D" => "plugins/departments/images/department.png",
770 "S" => "plugins/ogroups/images/server.png",
771 "W" => "plugins/ogroups/images/workstation.png",
772 "O" => "plugins/ogroups/images/winstation.png",
773 "T" => "plugins/ogroups/images/terminal.png",
774 "F" => "plugins/ogroups/images/phone.png",
775 "I" => "images/lists/flag.png",
776 "P" => "plugins/ogroups/images/printer.png");
778 foreach ($input as $key => $value){
779 /* Generate output */
780 $temp.= "<option title='".addslashes( $key)."' value=\"$key\" class=\"select\" style=\"background-image:url('".get_template_path($conv[$value['type']])."');\">".$value['text']."</option>\n";
781 }
783 return ($temp);
784 }
787 function getObjectType($attrs)
788 {
789 $type= "I";
791 foreach(array( "U" => "gosaAccount",
792 "G" => "posixGroup",
793 "A" => "gosaApplication",
794 "D" => "gosaDepartment",
795 "S" => "goServer",
796 "W" => "gotoWorkstation",
797 "O" => "opsiClient",
798 "T" => "gotoTerminal",
799 "F" => "goFonHardware",
800 "P" => "gotoPrinter") as $index => $class){
801 if (in_array($class, $attrs['objectClass'])){
802 $type= $index;
803 break;
804 }
805 }
807 return ($type);
808 }
811 function getObjectName($attrs)
812 {
813 /* Person? */
814 $name ="";
815 if (in_array('gosaAccount', $attrs['objectClass'])){
816 if(isset($attrs['sn']) && isset($attrs['givenName'])){
817 $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
818 } else {
819 $name= $attrs['uid'][0];
820 }
821 } else {
822 if(isset($attrs["cn"][0])) {
823 $name= $attrs['cn'][0];
824 } else {
825 $name= $attrs['ou'][0];
826 }
827 }
829 return ($name);
830 }
833 function check()
834 {
835 /* Call common method to give check the hook */
836 $message= plugin::check();
838 /* Permissions for that base? */
839 if ($this->base != ""){
840 $new_dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
841 } else {
842 $new_dn= $this->dn;
843 }
846 $ldap = $this->config->get_ldap_link();
847 if($this->dn != $new_dn){
848 $ldap->cat ($new_dn, array('dn'));
849 }
851 if($ldap->count() !=0){
852 $message[]= msgPool::duplicated(_("Name"));
853 }
855 /* Set new acl base */
856 if($this->dn == "new") {
857 $this->set_acl_base($this->base);
858 }
860 /* must: cn */
861 if ($this->cn == ""){
862 $message[]= msgPool::required(_("Name"));
863 }
865 /* To many different object types? */
866 if (strlen($this->gosaGroupObjects) > 4){
867 $message[]= _("You can combine two different object types at maximum, only!");
868 }
870 return ($message);
871 }
874 /* Save to LDAP */
875 function save()
876 {
877 plugin::save();
879 /* Move members to target array */
880 $this->attrs['member'] =array();
881 foreach ($this->member as $key => $desc){
882 $this->attrs['member'][]= @LDAP::fix($key);
883 }
885 $ldap= $this->config->get_ldap_link();
887 /* New accounts need proper 'dn', propagate it to remaining objects */
888 if ($this->dn == 'new'){
889 $this->dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
890 }
892 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
893 new entries. So do a check first... */
894 $ldap->cat ($this->dn, array('dn'));
895 if ($ldap->fetch()){
896 /* Modify needs array() to remove values :-( */
897 if (!count ($this->member)){
898 $this->attrs['member']= array();
899 }
900 $mode= "modify";
902 } else {
903 $mode= "add";
904 $ldap->cd($this->config->current['BASE']);
905 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
906 }
908 /******
909 Trust accounts
910 ******/
911 $objectclasses= array();
912 foreach ($this->attrs['objectClass'] as $key => $class){
913 if (preg_match('/trustAccount/i', $class)){
914 continue;
915 }
916 $objectclasses[]= $this->attrs['objectClass'][$key];
917 }
918 $this->attrs['objectClass']= $objectclasses;
919 if ($this->trustModel != ""){
920 $this->attrs['objectClass'][]= "trustAccount";
921 $this->attrs['trustModel']= $this->trustModel;
922 $this->attrs['accessTo']= array();
923 if ($this->trustModel == "byhost"){
924 foreach ($this->accessTo as $host){
925 $this->attrs['accessTo'][]= $host;
926 }
927 }
928 } else {
929 if ($this->was_trust_account){
930 $this->attrs['accessTo']= array();
931 $this->attrs['trustModel']= array();
932 }
933 }
935 /******
936 Ende - Trust accounts
937 ******/
939 /* Write back to ldap */
940 $ldap->cd($this->dn);
941 $this->cleanup();
942 $ldap->$mode($this->attrs);
944 if($mode == "add"){
945 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
946 }else{
947 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
948 }
950 /* Trigger post signal */
951 $this->handle_post_events($mode);
953 $ret= 0;
954 if (!$ldap->success()){
955 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
956 $ret= 1;
957 }
959 return ($ret);
960 }
962 function remove_from_parent()
963 {
964 plugin::remove_from_parent();
966 $ldap= $this->config->get_ldap_link();
967 $ldap->rmdir($this->dn);
968 if (!$ldap->success()){
969 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
970 }
972 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
974 /* Trigger remove signal */
975 $this->handle_post_events("remove");
976 }
979 function PrepareForCopyPaste($source)
980 {
981 /* Update available object types */
982 if(isset($source['gosaGroupObjects'][0])){
983 $this->gosaGroupObjects = $source['gosaGroupObjects'][0];
984 }
986 /* Reload tabs */
987 $this->parent->reload($this->gosaGroupObjects );
989 /* Reload plugins */
990 foreach($this->parent->by_object as $name => $class ){
991 if(get_class($this) != $name) {
992 $this->parent->by_object[$name]->PrepareForCopyPaste($source);
993 }
994 }
996 /* Load member objects */
997 if (isset($source['member'])){
998 foreach ($source['member'] as $key => $value){
999 if ("$key" != "count"){
1000 $value= @LDAP::convert($value);
1001 $this->member["$value"]= "$value";
1002 }
1003 }
1004 }
1006 }
1009 function getCopyDialog()
1010 {
1011 $smarty = get_smarty();
1012 $smarty->assign("cn", $this->cn);
1013 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1014 $ret = array();
1015 $ret['string'] = $str;
1016 $ret['status'] = "";
1017 return($ret);
1018 }
1020 function saveCopyDialog()
1021 {
1022 if(isset($_POST['cn'])){
1023 $this->cn = $_POST['cn'];
1024 }
1025 }
1028 function IsReleaseManagementActivated()
1029 {
1030 /* Check if we should enable the release selection */
1031 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1032 if(!empty($tmp)){
1033 return(true);
1034 }
1035 return(false);
1036 }
1039 static function plInfo()
1040 {
1041 return (array(
1042 "plShortName" => _("Generic"),
1043 "plDescription" => _("Object group generic"),
1044 "plSelfModify" => FALSE,
1045 "plDepends" => array(),
1046 "plPriority" => 1,
1047 "plSection" => array("administration"),
1048 "plCategory" => array("ogroups" => array("description" => _("Object groups"),
1049 "objectClass" => "gosaGroupOfNames")),
1050 "plProvidedAcls"=> array(
1051 "cn" => _("Name"),
1052 "base" => _("Base"),
1053 "description" => _("Description"),
1054 "member" => _("Member"))
1055 ));
1056 }
1057 }
1059 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1060 ?>