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 $orig_cn= "";
52 var $orig_base= "";
53 var $objectSelect= FALSE;
54 var $view_logged = FALSE;
56 var $accessTo= array();
57 var $trustModel= "";
58 var $trustSelect = FALSE;
60 var $was_trust_account= FALSE;
62 /* Already assigned Workstations. Will be hidden in selection.
63 */
64 var $used_workstations = array();
66 /* attribute list for save action */
67 var $attributes= array("cn", "description", "gosaGroupObjects","member","accessTo","trustModel");
68 var $objectclasses= array("top", "gosaGroupOfNames");
70 function ogroup (&$config, $dn= NULL)
71 {
72 plugin::plugin ($config, $dn);
73 $this->orig_dn= $dn;
75 $this->member = array();
77 /* Load member objects */
78 if (isset($this->attrs['member'])){
79 foreach ($this->attrs['member'] as $key => $value){
80 if ("$key" != "count"){
81 $value= @LDAP::convert($value);
82 $this->member["$value"]= "$value";
83 }
84 }
85 }
86 $this->is_account= TRUE;
88 /* Get global filter config */
89 if (!session::is_set("ogfilter")){
90 $ui= get_userinfo();
91 $base= get_base_from_people($ui->dn);
92 $ogfilter= array( "dselect" => $base,
93 "regex" => "*");
94 session::set("ogfilter", $ogfilter);
95 }
96 $ogfilter= session::get('ogfilter');
98 /* Adjust flags */
99 foreach( array( "U" => "accounts",
100 "G" => "groups",
101 "A" => "applications",
102 "D" => "departments",
103 "S" => "servers",
104 "W" => "workstations",
105 "O" => "winstations",
106 "T" => "terminals",
107 "F" => "phones",
108 "_" => "subtrees",
109 "P" => "printers") as $key => $val){
111 if (preg_match("/$key/", $this->gosaGroupObjects)){
112 $ogfilter[$val]= "checked";
113 } else {
114 $ogfilter[$val]= "";
115 }
116 }
117 session::set("ogfilter", $ogfilter);
119 if(session::is_set('CurrentMainBase')){
120 $this->base = session::get('CurrentMainBase');
121 }
123 /* Set base */
124 if ($this->dn == "new"){
125 $this->base = session::get('CurrentMainBase');
126 } else {
127 $this->base= preg_replace("/^[^,]+,".preg_quote(get_ou("ogroupRDN"), '/')."/i","",$this->dn);
129 /* Is this account a trustAccount? */
130 if ($this->is_account && isset($this->attrs['trustModel'])){
131 $this->trustModel= $this->attrs['trustModel'][0];
132 $this->was_trust_account= TRUE;
133 } else {
134 $this->was_trust_account= FALSE;
135 $this->trustModel= "";
136 }
138 $this->accessTo = array();
139 if ($this->is_account && isset($this->attrs['accessTo'])){
140 for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
141 $tmp= $this->attrs['accessTo'][$i];
142 $this->accessTo[$tmp]= $tmp;
143 }
144 }
145 }
147 /* Detect all workstations, which are already assigned to an object group
148 - Those objects will be hidden in the add object dialog.
149 - Check() will complain if such a system is assigned to this object group.
150 */
151 $base = $this->config->current['BASE'];
152 $res = get_list("(|(objectClass=gotoWorkstation)(objectClass=gotoTerminal))","none" ,
153 $base, array("dn"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
154 $ws_dns = array();
155 foreach($res as $data){
156 $ws_dns[] = $data['dn'];
157 }
158 $res=get_list("(&(member=*)(objectClass=gosaGroupOfNames))","none",
159 $base, array("dn","member", "gosaGroupObjects"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
160 $this->used_workstations = array();
161 foreach($res as $og){
162 if($og['dn'] == $this->dn) continue;
163 $test = array_intersect($ws_dns,$og['member']);
164 if(($og['gosaGroupObjects'] == "[W]" || $og['gosaGroupObjects'] == "[T]") && count($test)){
165 $this->used_workstations = array_merge($this->used_workstations,$test);
166 }
167 }
169 $this->orig_cn = $this->cn;
170 $this->orig_base = $this->base;
172 /* Get global filter config */
173 if (!session::is_set("sysfilter")){
174 $ui= get_userinfo();
175 $base= get_base_from_people($ui->dn);
176 $sysfilter= array( "depselect" => $base,
177 "regex" => "*");
178 session::set("sysfilter", $sysfilter);
179 }
181 $this->reload();
182 }
184 function AddDelMembership($NewMember = false){
186 if($NewMember){
188 /* Add member and force reload */
189 $this->member[$NewMember]= $NewMember;
190 $this->reload();
192 $this->memberList[$NewMember]= $this->objcache[$NewMember];
193 unset ($this->objects[$NewMember]);
194 uasort ($this->memberList, 'sort_list');
195 reset ($this->memberList);
196 }else{
197 /* Delete objects from group */
198 if (isset($_POST['delete_membership']) && isset($_POST['members'])){
199 foreach ($_POST['members'] as $value){
200 $this->objects["$value"]= $this->memberList[$value];
201 unset ($this->memberList["$value"]);
202 unset ($this->member["$value"]);
203 uasort ($this->objects, 'sort_list');
204 reset ($this->objects);
205 }
206 $this->reload();
207 }
209 /* Add objects to group */
210 if (isset($_POST['objectSelect_save']) && $this->objectSelect instanceOf objectSelect){
211 $objects = $this->objectSelect->save();
212 $skipped = FALSE;
213 foreach($objects as $object){
215 $tmp = "";
216 foreach($this->memberList as $obj){
217 $tmp .= $obj['type'];
218 }
220 $type = $this->getObjectType($object);
221 $name= $this->getObjectName($object);
222 $dn = $object['dn'];
224 /* Fill array */
225 if (isset($object["description"][0])){
226 $object= array("text" => "$name [".$object["description"][0]."]", "type" => "$type");
227 } elseif (isset($object["uid"][0])) {
228 $object= array("text" => "$name [".$object["uid"][0]."]", "type" => "$type");
229 } else {
230 $object= array("text" => "$name", "type" => "$type");
231 }
233 if(preg_match("/T/",$tmp) && $type == "W"){
234 $skipped =TRUE;
235 }elseif(preg_match("/W/",$tmp) && $type == "T"){
236 $skipped =TRUE;
237 }else{
239 $this->memberList["$dn"]= $object;
240 $this->member["$dn"]= $dn;
241 uasort ($this->memberList, 'sort_list');
242 reset ($this->memberList);
243 }
244 }
245 if($skipped){
246 msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
247 }
248 $this->objectSelect= FALSE;
249 $this->dialog= FALSE;
250 }
251 }
252 }
254 function execute()
255 {
256 /* Call parent execute */
257 plugin::execute();
259 if(!$this->view_logged){
260 $this->view_logged = TRUE;
261 new log("view","ogroups/".get_class($this),$this->dn);
262 }
265 /* Do we represent a valid group? */
266 if (!$this->is_account){
267 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
268 msgPool::noValidExtension("object group")."</b>";
269 return ($display);
270 }
273 /* Load templating engine */
274 $smarty= get_smarty();
276 $tmp = $this->plInfo();
277 foreach($tmp['plProvidedAcls'] as $name => $translation){
278 $smarty->assign($name."ACL",$this->getacl($name));
279 }
281 /* Base select dialog */
282 $once = true;
283 foreach($_POST as $name => $value){
284 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
285 $once = false;
286 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
287 $this->dialog->setCurrentBase($this->base);
288 }
289 }
291 /***********
292 * Trusts
293 ***********/
295 /* Add user workstation? */
296 if (isset($_POST["add_ws"])){
297 $this->trustSelect= new trustSelect($this->config,get_userinfo());
298 $this->dialog= TRUE;
299 }
301 // Add selected machines to trusted ones.
302 if (isset($_POST["add_ws_finish"]) && $this->trustSelect){
303 $trusts = $this->trustSelect->detectPostActions();
304 if(isset($trusts['targets'])){
306 $headpage = $this->trustSelect->getHeadpage();
307 foreach($trusts['targets'] as $id){
308 $attrs = $headpage->getEntry($id);
309 $this->accessTo[$attrs['cn'][0]]= $attrs['cn'][0];
310 }
311 ksort($this->accessTo);
312 $this->is_modified= TRUE;
313 }
314 $this->trustSelect= NULL;
315 $this->dialog= FALSE;
316 }
319 /* Remove user workstations? */
320 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
321 foreach($_POST['workstation_list'] as $name){
322 unset ($this->accessTo[$name]);
323 }
324 $this->is_modified= TRUE;
325 }
327 /* Add user workstation finished? */
328 if (isset($_POST["add_ws_cancel"])){
329 $this->trustSelect= NULL;
330 $this->dialog= FALSE;
331 }
333 /* Show ws dialog */
334 if ($this->trustSelect){
336 // Build up blocklist
337 session::set('filterBlacklist', array('cn' => array_values($this->accessTo)));
338 return($this->trustSelect->execute());
339 }
341 /***********
342 * Ende - Trusts
343 ***********/
346 /* Dialog handling */
347 if(is_object($this->dialog) && $this->acl_is_moveable()){
348 /* Must be called before save_object */
349 $this->dialog->save_object();
351 if($this->dialog->isClosed()){
352 $this->dialog = false;
353 }elseif($this->dialog->isSelected()){
355 /* A new base was selected, check if it is a valid one */
356 $tmp = $this->get_allowed_bases();
357 if(isset($tmp[$this->dialog->isSelected()])){
358 $this->base = $this->dialog->isSelected();
359 }
360 $this->dialog= false;
361 }else{
362 return($this->dialog->execute());
363 }
364 }
366 /* Add objects? */
367 if (isset($_POST["edit_membership"])){
368 $this->objectSelect= new objectSelect($this->config, get_userinfo());
369 $this->dialog= TRUE;
370 }
372 /* Add objects finished? */
373 if (isset($_POST["objectSelect_cancel"])){
374 $this->objectSelect= FALSE;
375 $this->dialog= FALSE;
376 }
378 /* Manage object add dialog */
379 if ($this->objectSelect){
380 session::set('filterBlacklist', array('dn'=> $this->member));
381 return($this->objectSelect->execute());
382 }
384 /* Bases / Departments */
385 if ((isset($_POST['base'])) && ($this->acl_is_moveable())){
386 $this->base= $_POST['base'];
387 }
389 /* Assemble combine string */
390 if ($this->gosaGroupObjects == "[]"){
391 $smarty->assign("combinedObjects", _("none"));
392 } elseif (strlen($this->gosaGroupObjects) > 4){
393 $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
394 } else {
395 $conv= array( "U" => _("users"),
396 "G" => _("groups"),
397 "A" => _("applications"),
398 "D" => _("departments"),
399 "S" => _("servers"),
400 "W" => _("workstations"),
401 "O" => _("winstations"),
402 "T" => _("terminals"),
403 "F" => _("phones"),
404 "P" => _("printers"));
406 $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
407 $p1= $conv[$type[0]];
408 error_reporting(0);
409 if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
410 $p2= $conv[$type[1]];
411 $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
412 } else {
413 $smarty->assign("combinedObjects", "$p1");
414 }
415 error_reporting(E_ALL | E_STRICT);
416 }
418 /* Assign variables */
419 $smarty->assign("bases", $this->get_allowed_bases());
420 $smarty->assign("base_select", $this->base);
421 $smarty->assign("department", $this->department);
422 $smarty->assign("members", $this->convert_list($this->memberList));
424 /* Objects have to be tuned... */
425 $smarty->assign("objects", $this->convert_list($this->objects));
427 /* Fields */
428 foreach ($this->attributes as $val){
429 $smarty->assign("$val", $this->$val);
430 }
432 /******
433 Trust account
434 ******/
435 $smarty->assign("trusthide", " disabled ");
436 $smarty->assign("trustmodeACL", $this->getacl("trustModel"));
437 if ($this->trustModel == "fullaccess"){
438 $trustmode= 1;
439 // pervent double disable tag in html code, this will disturb our clean w3c html
440 $smarty->assign("trustmode", $this->getacl("trustModel"));
442 } elseif ($this->trustModel == "byhost"){
443 $trustmode= 2;
444 $smarty->assign("trusthide", "");
445 } else {
446 // pervent double disable tag in html code, this will disturb our clean w3c html
447 $smarty->assign("trustmode", $this->getacl("trustModel"));
448 $trustmode= 0;
449 }
450 $smarty->assign("trustmode", $trustmode);
451 $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
452 2 => _("allow access to these hosts")));
454 $smarty->assign("workstations", $this->accessTo);
456 if((count($this->accessTo))==0){
457 $smarty->assign("emptyArrAccess",true);
458 }else{
459 $smarty->assign("emptyArrAccess",false);
460 }
461 /******
462 Ende - Trust account
463 ******/
465 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
466 }
469 /* Save data to object */
470 function save_object()
471 {
472 /* Save additional values for possible next step */
473 if (isset($_POST['ogroupedit'])){
475 /******
476 Trust account
477 ******/
479 if($this->acl_is_writeable("trustModel")){
480 if (isset($_POST['trustmode'])){
481 $saved= $this->trustModel;
482 if ($_POST['trustmode'] == "1"){
483 $this->trustModel= "fullaccess";
484 } elseif ($_POST['trustmode'] == "2"){
485 $this->trustModel= "byhost";
486 } else {
487 $this->trustModel= "";
488 }
489 if ($this->trustModel != $saved){
490 $this->is_modified= TRUE;
491 }
492 }
493 }
494 /******
495 Ende Trust account
496 ******/
498 /* Create a base backup and reset the
499 base directly after calling plugin::save_object();
500 Base will be set seperatly a few lines below */
501 $base_tmp = $this->base;
502 plugin::save_object();
503 $this->base = $base_tmp;
505 /* Save base, since this is no LDAP attribute */
506 $tmp = $this->get_allowed_bases();
507 if(isset($_POST['base'])){
508 if(isset($tmp[$_POST['base']])){
509 $this->base= $_POST['base'];
510 }
511 }
512 }
513 }
516 /* (Re-)Load objects */
517 function reload()
518 {
519 /*###########
520 Variable initialisation
521 ###########*/
523 $this->objects = array();
524 $this->ui = get_userinfo();
525 $filter = "";
526 $objectClasses = array();
528 $ogfilter = session::get("ogfilter");
529 $regex = $ogfilter['regex'];
531 $ldap= $this->config->get_ldap_link();
532 $ldap->cd ($ogfilter['dselect']);
535 /*###########
536 Generate Filter
537 ###########*/
539 $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount" ,
540 "DN"=> get_people_ou() ,"ACL" => "users"),
541 "groups" => array("OBJ"=>"group", "CLASS"=>"posixGroup" ,
542 "DN"=> get_groups_ou('ogroupRDN') ,"ACL" => "groups"),
543 "departments" => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
544 "DN"=> "" ,"ACL" => "department"),
545 "servers" => array("OBJ"=>"servgeneric", "CLASS"=>"goServer" ,
546 "DN"=> get_ou('serverRDN') ,"ACL" => "server"),
547 "workstations" => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
548 "DN"=> get_ou('workstationRDN') ,"ACL" => "workstation"),
549 "winstations" => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",
550 "DN"=> get_ou('SAMBAMACHINEACCOUNTRDN') ,"ACL" => "winstation"),
551 "terminals" => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal" ,
552 "DN"=> get_ou('terminalRDN') ,"ACL" => "terminal"),
553 "printers" => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter" ,
554 "DN"=> get_ou('printerRDN') ,"ACL" => "printer"),
555 "phones" => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware" ,
556 "DN"=> get_ou('phoneRDN') ,"ACL" => "phone"));
559 /* Allow searching for applications, if we are not using release managed applications
560 */
561 if(!$this->IsReleaseManagementActivated()){
562 $p_f[ "applications"] = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
563 "DN"=> get_ou('applicationRDN') ,"ACL" => "application");
564 }
566 /*###########
567 Perform search for selected objectClasses & regex to fill list with objects
568 ###########*/
570 $Get_list_flags = 0;
571 if($ogfilter['subtrees'] == "checked"){
572 $Get_list_flags |= GL_SUBSEARCH;
573 }
575 foreach($p_f as $post_name => $data){
577 if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
579 if($ogfilter['subtrees']){
580 $base = $ogfilter['dselect'];
581 }else{
582 $base = $data['DN'].$ogfilter['dselect'];
583 }
586 $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
587 $res = get_list($filter, $data['ACL'] , $base,
588 array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
590 /* fetch results and append them to the list */
591 foreach($res as $attrs){
593 /* Skip workstations which are already assigned to an object group.
594 */
595 if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]"){
596 if(in_array($attrs['dn'],$this->used_workstations)){
597 continue;
598 }
599 }
601 $type= $this->getObjectType($attrs);
602 $name= $this->getObjectName($attrs);
604 /* Fill array */
605 if (isset($attrs["description"][0])){
606 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
607 } elseif (isset($attrs["uid"][0])) {
608 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
609 } else {
610 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
611 }
612 }
613 }
614 }
615 uasort ($this->objects, 'sort_list');
616 reset ($this->objects);
619 /*###########
620 Build member list and try to detect obsolete entries
621 ###########*/
623 $this->memberList = array();
625 /* Walk through all single member entry */
626 foreach($this->member as $dn){
628 /* The dn for the current member can't be resolved
629 it seams that this entry was removed
630 */
631 /* Try to resolv the entry again, if it still fails, display error msg */
632 $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
634 /* It has failed, add entry with type flag I (Invalid)*/
635 if (!$ldap->success()){
636 $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".LDAP::fix($dn),"type" => "I");
638 } else {
640 /* Append this entry to our all object list */
642 /* Fetch object */
643 $attrs= $ldap->fetch();
645 $type= $this->getObjectType($attrs);
646 $name= $this->getObjectName($attrs);
648 if (isset($attrs["description"][0])){
649 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
650 } elseif (isset($attrs["uid"][0])) {
651 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
652 } else {
653 $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
654 }
655 $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass'];
657 if(isset($attrs['macAddress'][0])){
658 $this->objcache[$attrs["dn"]]['macAddress'] = $attrs['macAddress'][0];
659 }else{
660 $this->objcache[$attrs["dn"]]['macAddress'] = "";
661 }
663 if(isset($attrs['uid'])){
664 $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid'];
665 }
667 /* Fill array */
668 if (isset($attrs["description"][0])){
669 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
670 } else {
671 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
672 }
674 $this->memberList[$dn]= $this->objects[$attrs["dn"]];
675 }
676 }
677 uasort ($this->memberList, 'sort_list');
678 reset ($this->memberList);
680 /* Assemble types of currently combined objects */
681 $objectTypes= "";
682 foreach ($this->memberList as $dn => $desc){
684 /* Invalid object? */
685 if ($desc['type'] == 'I'){
686 continue;
687 }
689 /* Fine. Add to list. */
690 if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
691 $objectTypes.= $desc['type'];
692 }
693 }
694 $this->gosaGroupObjects= "[$objectTypes]";
695 }
698 function convert_list($input)
699 {
700 $temp= "";
701 $conv= array(
702 "Y" => "plugins/users/images/select_template.png",
703 "U" => "plugins/generic/images/head.png",
704 "G" => "plugins/groups/images/groups.png",
705 "A" => "plugins/ogroups/images/application.png",
706 "D" => "plugins/departments/images/department.png",
707 "S" => "plugins/ogroups/images/server.png",
708 "W" => "plugins/ogroups/images/workstation.png",
709 "O" => "plugins/ogroups/images/winstation.png",
710 "T" => "plugins/ogroups/images/terminal.png",
711 "F" => "plugins/ogroups/images/phone.png",
712 "P" => "plugins/ogroups/images/printer.png",
713 "I" => "images/false.png");
715 foreach ($input as $key => $value){
716 /* Generate output */
717 $temp.= "<option title='".addslashes( $key)."' value=\"$key\" class=\"select\" style=\"background-image:url('".get_template_path($conv[$value['type']])."');\">".$value['text']."</option>\n";
718 }
720 return ($temp);
721 }
724 function getObjectType($attrs)
725 {
726 $type= "I";
728 foreach(array(
729 "Y" => "gosaUserTemplate",
730 "U" => "gosaAccount",
731 "G" => "posixGroup",
732 "A" => "gosaApplication",
733 "D" => "gosaDepartment",
734 "S" => "goServer",
735 "W" => "gotoWorkstation",
736 "O" => "opsiClient",
737 "T" => "gotoTerminal",
738 "F" => "goFonHardware",
739 "P" => "gotoPrinter") as $index => $class){
740 if (in_array($class, $attrs['objectClass'])){
741 $type= $index;
742 break;
743 }
744 }
746 return ($type);
747 }
750 function getObjectName($attrs)
751 {
752 /* Person? */
753 $name ="";
754 if (in_array('gosaAccount', $attrs['objectClass'])){
755 if(isset($attrs['sn']) && isset($attrs['givenName'])){
756 $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
757 } else {
758 $name= $attrs['uid'][0];
759 }
760 } else {
761 if(isset($attrs["cn"][0])) {
762 $name= $attrs['cn'][0];
763 } else {
764 $name= $attrs['ou'][0];
765 }
766 }
768 return ($name);
769 }
772 function check()
773 {
774 /* Call common method to give check the hook */
775 $message= plugin::check();
777 /* Permissions for that base? */
778 if ($this->base != ""){
779 $new_dn= 'cn='.$this->cn.','.get_ou('ogroupRDN').$this->base;
780 } else {
781 $new_dn= $this->dn;
782 }
784 /* Check if we have workstations assigned, that are already assigned to
785 another object group. */
786 if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]" ) {
787 $test =array_intersect($this->used_workstations,$this->member);
788 if(count($test)){
789 $str = "";
790 foreach($test as $dn){
791 $str .= "<li>".$dn."</li>";
792 }
793 $message[] = sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>",$str);
794 }
795 }
797 $ldap = $this->config->get_ldap_link();
798 if(LDAP::fix($this->dn) != LDAP::fix($new_dn)){
799 $ldap->cat ($new_dn, array('dn'));
800 }
802 if($ldap->count() !=0){
803 $message[]= msgPool::duplicated(_("Name"));
804 }
806 /* Set new acl base */
807 if($this->dn == "new") {
808 $this->set_acl_base($this->base);
809 }
811 /* must: cn */
812 if ($this->cn == ""){
813 $message[]= msgPool::required(_("Name"));
814 }
816 /* To many different object types? */
817 if (strlen($this->gosaGroupObjects) > 4){
818 $message[]= _("You can combine two different object types at maximum, only!");
819 }
821 /* Check if we are allowed to create or move this object
822 */
823 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
824 $message[] = msgPool::permCreate();
825 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
826 $message[] = msgPool::permMove();
827 }
829 return ($message);
830 }
833 /* Save to LDAP */
834 function save()
835 {
836 plugin::save();
838 /* Move members to target array */
839 $this->attrs['member'] =array();
840 foreach ($this->member as $key => $desc){
841 $this->attrs['member'][]= LDAP::fix($key);
842 }
844 $ldap= $this->config->get_ldap_link();
846 /* New accounts need proper 'dn', propagate it to remaining objects */
847 if ($this->dn == 'new'){
848 $this->dn= 'cn='.$this->cn.','.get_ou('ogroupRDN').$this->base;
849 }
851 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
852 new entries. So do a check first... */
853 $ldap->cat ($this->dn, array('dn'));
854 if ($ldap->fetch()){
855 /* Modify needs array() to remove values :-( */
856 if (!count ($this->member)){
857 $this->attrs['member']= array();
858 }
859 $mode= "modify";
861 } else {
862 $mode= "add";
863 $ldap->cd($this->config->current['BASE']);
864 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
865 }
867 /******
868 Trust accounts
869 ******/
870 $objectclasses= array();
871 foreach ($this->attrs['objectClass'] as $key => $class){
872 if (preg_match('/trustAccount/i', $class)){
873 continue;
874 }
875 $objectclasses[]= $this->attrs['objectClass'][$key];
876 }
877 $this->attrs['objectClass']= $objectclasses;
878 if ($this->trustModel != ""){
879 $this->attrs['objectClass'][]= "trustAccount";
880 $this->attrs['trustModel']= $this->trustModel;
881 $this->attrs['accessTo']= array();
882 if ($this->trustModel == "byhost"){
883 foreach ($this->accessTo as $host){
884 $this->attrs['accessTo'][]= $host;
885 }
886 }
887 } else {
888 if ($this->was_trust_account){
889 $this->attrs['accessTo']= array();
890 $this->attrs['trustModel']= array();
891 }
892 }
894 /******
895 Ende - Trust accounts
896 ******/
898 /* Write back to ldap */
899 $ldap->cd($this->dn);
900 $this->cleanup();
901 $ldap->$mode($this->attrs);
903 if($mode == "add"){
904 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
905 }else{
906 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
907 }
909 /* Trigger post signal */
910 $this->handle_post_events($mode);
912 $ret= 0;
913 if (!$ldap->success()){
914 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
915 $ret= 1;
916 }
918 return ($ret);
919 }
921 function remove_from_parent()
922 {
923 plugin::remove_from_parent();
925 $ldap= $this->config->get_ldap_link();
926 $ldap->rmdir($this->dn);
927 if (!$ldap->success()){
928 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
929 }
931 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
933 /* Trigger remove signal */
934 $this->handle_post_events("remove");
935 }
938 function PrepareForCopyPaste($source)
939 {
940 plugin::PrepareForCopyPaste($source);
942 /* Reload tabs */
943 $this->parent->reload($this->gosaGroupObjects );
945 /* Reload plugins */
946 foreach($this->parent->by_object as $name => $class ){
947 if(get_class($this) != $name) {
948 $this->parent->by_object[$name]->PrepareForCopyPaste($source);
949 }
950 }
952 $source_o = new ogroup ($this->config, $source['dn']);
953 foreach(array("accessTo","member","gosaGroupObjects") as $attr){
954 $this->$attr = $source_o->$attr;
955 }
956 }
959 function getCopyDialog()
960 {
961 $smarty = get_smarty();
962 $smarty->assign("cn", $this->cn);
963 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
964 $ret = array();
965 $ret['string'] = $str;
966 $ret['status'] = "";
967 return($ret);
968 }
970 function saveCopyDialog()
971 {
972 if(isset($_POST['cn'])){
973 $this->cn = $_POST['cn'];
974 }
975 }
978 function IsReleaseManagementActivated()
979 {
980 /* Check if we should enable the release selection */
981 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
982 if(!empty($tmp)){
983 return(true);
984 }
985 return(false);
986 }
989 static function plInfo()
990 {
991 return (array(
992 "plShortName" => _("Generic"),
993 "plDescription" => _("Object group generic"),
994 "plSelfModify" => FALSE,
995 "plDepends" => array(),
996 "plPriority" => 1,
997 "plSection" => array("administration"),
998 "plCategory" => array("ogroups" => array("description" => _("Object groups"),
999 "objectClass" => "gosaGroupOfNames")),
1000 "plProvidedAcls"=> array(
1001 "cn" => _("Name"),
1002 "base" => _("Base"),
1003 "description" => _("Description"),
1004 "trustModel" => _("Sytem trust"),
1005 "member" => _("Member"))
1006 ));
1007 }
1008 }
1010 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1011 ?>