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 $objects= array();
46 var $objcache= array();
47 var $memberList= array();
48 var $member= array();
49 var $orig_dn= "";
50 var $orig_cn= "";
51 var $orig_base= "";
52 var $objectSelect= FALSE;
53 var $view_logged = FALSE;
55 var $accessTo= array();
56 var $trustModel= "";
57 var $trustSelect = FALSE;
59 var $was_trust_account= FALSE;
60 var $baseSelector;
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 /* Set base */
89 if ($this->dn == "new"){
90 $ui = get_userinfo();
91 $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
92 } else {
93 $this->base= preg_replace("/^[^,]+,".preg_quote(get_ou("ogroupRDN"), '/')."/i","",$this->dn);
95 /* Is this account a trustAccount? */
96 if ($this->is_account && isset($this->attrs['trustModel'])){
97 $this->trustModel= $this->attrs['trustModel'][0];
98 $this->was_trust_account= TRUE;
99 } else {
100 $this->was_trust_account= FALSE;
101 $this->trustModel= "";
102 }
104 $this->accessTo = array();
105 if ($this->is_account && isset($this->attrs['accessTo'])){
106 for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
107 $tmp= $this->attrs['accessTo'][$i];
108 $this->accessTo[$tmp]= $tmp;
109 }
110 }
111 }
113 /* Detect all workstations, which are already assigned to an object group
114 - Those objects will be hidden in the add object dialog.
115 - Check() will complain if such a system is assigned to this object group.
116 */
117 $base = $this->config->current['BASE'];
118 $res = get_list("(|(objectClass=gotoWorkstation)(objectClass=gotoTerminal))","none" ,
119 $base, array("dn"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
120 $ws_dns = array();
121 foreach($res as $data){
122 $ws_dns[] = $data['dn'];
123 }
124 $res=get_list("(&(member=*)(objectClass=gosaGroupOfNames))","none",
125 $base, array("dn","member", "gosaGroupObjects"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
126 $this->used_workstations = array();
127 foreach($res as $og){
128 if($og['dn'] == $this->dn) continue;
129 $test = array_intersect($ws_dns,$og['member']);
130 if(($og['gosaGroupObjects'] == "[W]" || $og['gosaGroupObjects'] == "[T]") && count($test)){
131 $this->used_workstations = array_merge($this->used_workstations,$test);
132 }
133 }
135 $this->orig_cn = $this->cn;
136 $this->orig_base = $this->base;
138 /* Get global filter config */
139 if (!session::is_set("sysfilter")){
140 $ui= get_userinfo();
141 $base= get_base_from_people($ui->dn);
142 $sysfilter= array( "depselect" => $base,
143 "regex" => "*");
144 session::set("sysfilter", $sysfilter);
145 }
147 /* Instanciate base selector */
148 $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
149 $this->baseSelector->setSubmitButton(false);
150 $this->baseSelector->setHeight(300);
151 $this->baseSelector->update(true);
153 $this->reload();
154 }
156 function AddDelMembership($NewMember = false){
158 if($NewMember){
160 /* Add member and force reload */
161 $this->member[$NewMember]= $NewMember;
162 $this->reload();
164 $this->memberList[$NewMember]= $this->objcache[$NewMember];
165 unset ($this->objects[$NewMember]);
166 uasort ($this->memberList, 'sort_list');
167 reset ($this->memberList);
168 }else{
169 /* Delete objects from group */
170 if (isset($_POST['delete_membership']) && isset($_POST['members'])){
171 foreach ($_POST['members'] as $value){
172 $this->objects["$value"]= $this->memberList[$value];
173 unset ($this->memberList["$value"]);
174 unset ($this->member["$value"]);
175 uasort ($this->objects, 'sort_list');
176 reset ($this->objects);
177 }
178 $this->reload();
179 }
181 /* Add objects to group */
182 if (isset($_POST['objectSelect_save']) && $this->objectSelect instanceOf objectSelect){
183 $objects = $this->objectSelect->save();
184 $skipped = FALSE;
185 foreach($objects as $object){
187 $tmp = "";
188 foreach($this->memberList as $obj){
189 $tmp .= $obj['type'];
190 }
192 $type = $this->getObjectType($object);
193 $name= $this->getObjectName($object);
194 $dn = $object['dn'];
196 /* Fill array */
197 if (isset($object["description"][0])){
198 $object= array("text" => "$name [".$object["description"][0]."]", "type" => "$type");
199 } elseif (isset($object["uid"][0])) {
200 $object= array("text" => "$name [".$object["uid"][0]."]", "type" => "$type");
201 } else {
202 $object= array("text" => "$name", "type" => "$type");
203 }
205 if(preg_match("/T/",$tmp) && $type == "W"){
206 $skipped =TRUE;
207 }elseif(preg_match("/W/",$tmp) && $type == "T"){
208 $skipped =TRUE;
209 }else{
211 $this->memberList["$dn"]= $object;
212 $this->member["$dn"]= $dn;
213 uasort ($this->memberList, 'sort_list');
214 reset ($this->memberList);
215 }
216 }
217 if($skipped){
218 msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
219 }
220 $this->objectSelect= FALSE;
221 $this->dialog= FALSE;
222 }
223 }
224 }
226 function execute()
227 {
228 /* Call parent execute */
229 plugin::execute();
231 if(!$this->view_logged){
232 $this->view_logged = TRUE;
233 new log("view","ogroups/".get_class($this),$this->dn);
234 }
237 /* Do we represent a valid group? */
238 if (!$this->is_account){
239 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
240 msgPool::noValidExtension("object group")."</b>";
241 return ($display);
242 }
245 /* Load templating engine */
246 $smarty= get_smarty();
247 $smarty->assign("usePrototype", "true");
249 $tmp = $this->plInfo();
250 foreach($tmp['plProvidedAcls'] as $name => $translation){
251 $smarty->assign($name."ACL",$this->getacl($name));
252 }
254 /***********
255 * Trusts
256 ***********/
258 /* Add user workstation? */
259 if (isset($_POST["add_ws"])){
260 $this->trustSelect= new trustSelect($this->config,get_userinfo());
261 $this->dialog= TRUE;
262 }
264 // Add selected machines to trusted ones.
265 if (isset($_POST["add_ws_finish"]) && $this->trustSelect){
266 $trusts = $this->trustSelect->detectPostActions();
267 if(isset($trusts['targets'])){
269 $headpage = $this->trustSelect->getHeadpage();
270 foreach($trusts['targets'] as $id){
271 $attrs = $headpage->getEntry($id);
272 $this->accessTo[$attrs['cn'][0]]= $attrs['cn'][0];
273 }
274 ksort($this->accessTo);
275 $this->is_modified= TRUE;
276 }
277 $this->trustSelect= NULL;
278 $this->dialog= FALSE;
279 }
282 /* Remove user workstations? */
283 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
284 foreach($_POST['workstation_list'] as $name){
285 unset ($this->accessTo[$name]);
286 }
287 $this->is_modified= TRUE;
288 }
290 /* Add user workstation finished? */
291 if (isset($_POST["add_ws_cancel"])){
292 $this->trustSelect= NULL;
293 $this->dialog= FALSE;
294 }
296 /* Show ws dialog */
297 if ($this->trustSelect){
299 // Build up blocklist
300 session::set('filterBlacklist', array('cn' => array_values($this->accessTo)));
301 return($this->trustSelect->execute());
302 }
304 /***********
305 * Ende - Trusts
306 ***********/
309 /* Dialog handling */
310 if(is_object($this->dialog) && $this->acl_is_moveable()){
311 /* Must be called before save_object */
312 $this->dialog->save_object();
314 if($this->dialog->isClosed()){
315 $this->dialog = false;
316 }elseif($this->dialog->isSelected()){
318 /* A new base was selected, check if it is a valid one */
319 $tmp = $this->get_allowed_bases();
320 if(isset($tmp[$this->dialog->isSelected()])){
321 $this->base = $this->dialog->isSelected();
322 }
323 $this->dialog= false;
324 }else{
325 return($this->dialog->execute());
326 }
327 }
329 /* Add objects? */
330 if (isset($_POST["edit_membership"])){
331 $this->objectSelect= new objectSelect($this->config, get_userinfo());
332 $this->dialog= TRUE;
333 }
335 /* Add objects finished? */
336 if (isset($_POST["objectSelect_cancel"])){
337 $this->objectSelect= FALSE;
338 $this->dialog= FALSE;
339 }
341 /* Manage object add dialog */
342 if ($this->objectSelect){
343 session::set('filterBlacklist', array('dn'=> $this->member));
344 return($this->objectSelect->execute());
345 }
347 /* Bases / Departments */
348 if ((isset($_POST['base'])) && ($this->acl_is_moveable())){
349 $this->base= $_POST['base'];
350 }
352 /* Assemble combine string */
353 if ($this->gosaGroupObjects == "[]"){
354 $smarty->assign("combinedObjects", _("none"));
355 } elseif (strlen($this->gosaGroupObjects) > 4){
356 $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
357 } else {
358 $conv= array( "U" => _("users"),
359 "G" => _("groups"),
360 "A" => _("applications"),
361 "D" => _("departments"),
362 "S" => _("servers"),
363 "W" => _("workstations"),
364 "O" => _("winstations"),
365 "T" => _("terminals"),
366 "F" => _("phones"),
367 "P" => _("printers"));
369 $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
370 $p1= $conv[$type[0]];
371 error_reporting(0);
372 if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
373 $p2= $conv[$type[1]];
374 $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
375 } else {
376 $smarty->assign("combinedObjects", "$p1");
377 }
378 error_reporting(E_ALL | E_STRICT);
379 }
381 /* Assign variables */
382 $smarty->assign("base", $this->baseSelector->render());
383 $smarty->assign("members", $this->convert_list($this->memberList));
385 /* Objects have to be tuned... */
386 $smarty->assign("objects", $this->convert_list($this->objects));
388 /* Fields */
389 foreach ($this->attributes as $val){
390 $smarty->assign("$val", $this->$val);
391 }
393 /******
394 Trust account
395 ******/
396 $smarty->assign("trusthide", " disabled ");
397 $smarty->assign("trustmodeACL", $this->getacl("trustModel"));
398 if ($this->trustModel == "fullaccess"){
399 $trustmode= 1;
400 // pervent double disable tag in html code, this will disturb our clean w3c html
401 $smarty->assign("trustmode", $this->getacl("trustModel"));
403 } elseif ($this->trustModel == "byhost"){
404 $trustmode= 2;
405 $smarty->assign("trusthide", "");
406 } else {
407 // pervent double disable tag in html code, this will disturb our clean w3c html
408 $smarty->assign("trustmode", $this->getacl("trustModel"));
409 $trustmode= 0;
410 }
411 $smarty->assign("trustmode", $trustmode);
412 $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
413 2 => _("allow access to these hosts")));
415 $smarty->assign("workstations", $this->accessTo);
417 if((count($this->accessTo))==0){
418 $smarty->assign("emptyArrAccess",true);
419 }else{
420 $smarty->assign("emptyArrAccess",false);
421 }
422 /******
423 Ende - Trust account
424 ******/
426 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
427 }
430 /* Save data to object */
431 function save_object()
432 {
433 /* Save additional values for possible next step */
434 if (isset($_POST['ogroupedit'])){
436 /******
437 Trust account
438 ******/
440 if($this->acl_is_writeable("trustModel")){
441 if (isset($_POST['trustmode'])){
442 $saved= $this->trustModel;
443 if ($_POST['trustmode'] == "1"){
444 $this->trustModel= "fullaccess";
445 } elseif ($_POST['trustmode'] == "2"){
446 $this->trustModel= "byhost";
447 } else {
448 $this->trustModel= "";
449 }
450 if ($this->trustModel != $saved){
451 $this->is_modified= TRUE;
452 }
453 }
454 }
455 /******
456 Ende Trust account
457 ******/
459 /* Create a base backup and reset the
460 base directly after calling plugin::save_object();
461 Base will be set seperatly a few lines below */
462 $base_tmp = $this->base;
463 plugin::save_object();
464 $this->base = $base_tmp;
466 /* Refresh base */
467 if ($this->acl_is_moveable($this->base)){
468 if (!$this->baseSelector->update()) {
469 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
470 }
471 if ($this->base != $this->baseSelector->getBase()) {
472 $this->base= $this->baseSelector->getBase();
473 $this->is_modified= TRUE;
474 }
475 }
477 }
478 }
481 /* (Re-)Load objects */
482 function reload()
483 {
484 /*###########
485 Variable initialisation
486 ###########*/
488 $this->objects = array();
489 $this->ui = get_userinfo();
490 $filter = "";
491 $objectClasses = array();
493 $ogfilter = session::get("ogfilter");
494 $regex = $ogfilter['regex'];
496 $ldap= $this->config->get_ldap_link();
497 $ldap->cd ($ogfilter['dselect']);
500 /*###########
501 Generate Filter
502 ###########*/
504 $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount" ,
505 "DN"=> get_people_ou() ,"ACL" => "users"),
506 "groups" => array("OBJ"=>"group", "CLASS"=>"posixGroup" ,
507 "DN"=> get_groups_ou('ogroupRDN') ,"ACL" => "groups"),
508 "departments" => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
509 "DN"=> "" ,"ACL" => "department"),
510 "servers" => array("OBJ"=>"servgeneric", "CLASS"=>"goServer" ,
511 "DN"=> get_ou('serverRDN') ,"ACL" => "server"),
512 "workstations" => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
513 "DN"=> get_ou('workstationRDN') ,"ACL" => "workstation"),
514 "winstations" => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",
515 "DN"=> get_ou('SAMBAMACHINEACCOUNTRDN') ,"ACL" => "winstation"),
516 "terminals" => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal" ,
517 "DN"=> get_ou('terminalRDN') ,"ACL" => "terminal"),
518 "printers" => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter" ,
519 "DN"=> get_ou('printerRDN') ,"ACL" => "printer"),
520 "phones" => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware" ,
521 "DN"=> get_ou('phoneRDN') ,"ACL" => "phone"));
524 /* Allow searching for applications, if we are not using release managed applications
525 */
526 if(!$this->IsReleaseManagementActivated()){
527 $p_f[ "applications"] = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
528 "DN"=> get_ou('applicationRDN') ,"ACL" => "application");
529 }
531 /*###########
532 Perform search for selected objectClasses & regex to fill list with objects
533 ###########*/
535 $Get_list_flags = 0;
536 if($ogfilter['subtrees'] == "checked"){
537 $Get_list_flags |= GL_SUBSEARCH;
538 }
540 foreach($p_f as $post_name => $data){
542 if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
544 if($ogfilter['subtrees']){
545 $base = $ogfilter['dselect'];
546 }else{
547 $base = $data['DN'].$ogfilter['dselect'];
548 }
551 $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
552 $res = get_list($filter, $data['ACL'] , $base,
553 array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
555 /* fetch results and append them to the list */
556 foreach($res as $attrs){
558 /* Skip workstations which are already assigned to an object group.
559 */
560 if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]"){
561 if(in_array($attrs['dn'],$this->used_workstations)){
562 continue;
563 }
564 }
566 $type= $this->getObjectType($attrs);
567 $name= $this->getObjectName($attrs);
569 /* Fill array */
570 if (isset($attrs["description"][0])){
571 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
572 } elseif (isset($attrs["uid"][0])) {
573 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
574 } else {
575 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
576 }
577 }
578 }
579 }
580 uasort ($this->objects, 'sort_list');
581 reset ($this->objects);
584 /*###########
585 Build member list and try to detect obsolete entries
586 ###########*/
588 $this->memberList = array();
590 /* Walk through all single member entry */
591 foreach($this->member as $dn){
593 /* The dn for the current member can't be resolved
594 it seams that this entry was removed
595 */
596 /* Try to resolv the entry again, if it still fails, display error msg */
597 $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
599 /* It has failed, add entry with type flag I (Invalid)*/
600 if (!$ldap->success()){
601 $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".LDAP::fix($dn),"type" => "I");
603 } else {
605 /* Append this entry to our all object list */
607 /* Fetch object */
608 $attrs= $ldap->fetch();
610 $type= $this->getObjectType($attrs);
611 $name= $this->getObjectName($attrs);
613 if (isset($attrs["description"][0])){
614 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
615 } elseif (isset($attrs["uid"][0])) {
616 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
617 } else {
618 $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
619 }
620 $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass'];
622 if(isset($attrs['macAddress'][0])){
623 $this->objcache[$attrs["dn"]]['macAddress'] = $attrs['macAddress'][0];
624 }else{
625 $this->objcache[$attrs["dn"]]['macAddress'] = "";
626 }
628 if(isset($attrs['uid'])){
629 $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid'];
630 }
632 /* Fill array */
633 if (isset($attrs["description"][0])){
634 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
635 } else {
636 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
637 }
639 $this->memberList[$dn]= $this->objects[$attrs["dn"]];
640 }
641 }
642 uasort ($this->memberList, 'sort_list');
643 reset ($this->memberList);
645 /* Assemble types of currently combined objects */
646 $objectTypes= "";
647 foreach ($this->memberList as $dn => $desc){
649 /* Invalid object? */
650 if ($desc['type'] == 'I'){
651 continue;
652 }
654 /* Fine. Add to list. */
655 if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
656 $objectTypes.= $desc['type'];
657 }
658 }
659 $this->gosaGroupObjects= "[$objectTypes]";
660 }
663 function convert_list($input)
664 {
665 $temp= "";
666 $conv= array(
667 "Y" => "plugins/users/images/select_template.png",
668 "U" => "plugins/generic/images/head.png",
669 "G" => "plugins/groups/images/select_group.png",
670 "A" => "plugins/ogroups/images/application.png",
671 "D" => "plugins/departments/images/department.png",
672 "S" => "plugins/ogroups/images/server.png",
673 "W" => "plugins/ogroups/images/workstation.png",
674 "O" => "plugins/ogroups/images/winstation.png",
675 "T" => "plugins/ogroups/images/terminal.png",
676 "F" => "plugins/ogroups/images/phone.png",
677 "P" => "plugins/ogroups/images/printer.png",
678 "I" => "images/false.png");
680 foreach ($input as $key => $value){
681 /* Generate output */
682 $temp.= "<option title='".addslashes( $key)."' value=\"$key\" class=\"select\" style=\"background-image:url('".get_template_path($conv[$value['type']])."');\">".$value['text']."</option>\n";
683 }
685 return ($temp);
686 }
689 function getObjectType($attrs)
690 {
691 $type= "I";
693 foreach(array(
694 "Y" => "gosaUserTemplate",
695 "U" => "gosaAccount",
696 "G" => "posixGroup",
697 "A" => "gosaApplication",
698 "D" => "gosaDepartment",
699 "S" => "goServer",
700 "W" => "gotoWorkstation",
701 "O" => "opsiClient",
702 "T" => "gotoTerminal",
703 "F" => "goFonHardware",
704 "P" => "gotoPrinter") as $index => $class){
705 if (in_array($class, $attrs['objectClass'])){
706 $type= $index;
707 break;
708 }
709 }
711 return ($type);
712 }
715 function getObjectName($attrs)
716 {
717 /* Person? */
718 $name ="";
719 if (in_array('gosaAccount', $attrs['objectClass'])){
720 if(isset($attrs['sn']) && isset($attrs['givenName'])){
721 $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
722 } else {
723 $name= $attrs['uid'][0];
724 }
725 } else {
726 if(isset($attrs["cn"][0])) {
727 $name= $attrs['cn'][0];
728 } else {
729 $name= $attrs['ou'][0];
730 }
731 }
733 return ($name);
734 }
737 function check()
738 {
739 /* Call common method to give check the hook */
740 $message= plugin::check();
742 /* Permissions for that base? */
743 if ($this->base != ""){
744 $new_dn= 'cn='.$this->cn.','.get_ou('ogroupRDN').$this->base;
745 } else {
746 $new_dn= $this->dn;
747 }
749 /* Check if we have workstations assigned, that are already assigned to
750 another object group. */
751 if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]" ) {
752 $test =array_intersect($this->used_workstations,$this->member);
753 if(count($test)){
754 $str = "";
755 foreach($test as $dn){
756 $str .= "<li>".$dn."</li>";
757 }
758 $message[] = sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>",$str);
759 }
760 }
762 $ldap = $this->config->get_ldap_link();
763 if(LDAP::fix($this->dn) != LDAP::fix($new_dn)){
764 $ldap->cat ($new_dn, array('dn'));
765 }
767 if($ldap->count() !=0){
768 $message[]= msgPool::duplicated(_("Name"));
769 }
771 // Check if a wrong base was supplied
772 if(!$this->baseSelector->checkLastBaseUpdate()){
773 $message[]= msgPool::check_base();;
774 }
776 /* Set new acl base */
777 if($this->dn == "new") {
778 $this->set_acl_base($this->base);
779 }
781 /* must: cn */
782 if ($this->cn == ""){
783 $message[]= msgPool::required(_("Name"));
784 }
786 if (preg_match('/[=,+<>#;]/', $this->cn)) {
787 $message[] = msgPool::invalid(_("Name"), $this->cn, "/[^=+,<>#;]/");
788 }
790 /* To many different object types? */
791 if (strlen($this->gosaGroupObjects) > 4){
792 $message[]= _("You can combine two different object types at maximum, only!");
793 }
795 /* Check if we are allowed to create or move this object
796 */
797 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
798 $message[] = msgPool::permCreate();
799 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
800 $message[] = msgPool::permMove();
801 }
803 return ($message);
804 }
807 /* Save to LDAP */
808 function save()
809 {
810 plugin::save();
812 /* Move members to target array */
813 $this->attrs['member'] =array();
814 foreach ($this->member as $key => $desc){
815 $this->attrs['member'][]= LDAP::fix($key);
816 }
818 $ldap= $this->config->get_ldap_link();
820 /* New accounts need proper 'dn', propagate it to remaining objects */
821 if ($this->dn == 'new'){
822 $this->dn= 'cn='.$this->cn.','.get_ou('ogroupRDN').$this->base;
823 }
825 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
826 new entries. So do a check first... */
827 $ldap->cat ($this->dn, array('dn'));
828 if ($ldap->fetch()){
829 /* Modify needs array() to remove values :-( */
830 if (!count ($this->member)){
831 $this->attrs['member']= array();
832 }
833 $mode= "modify";
835 } else {
836 $mode= "add";
837 $ldap->cd($this->config->current['BASE']);
838 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
839 }
841 /******
842 Trust accounts
843 ******/
844 $objectclasses= array();
845 foreach ($this->attrs['objectClass'] as $key => $class){
846 if (preg_match('/trustAccount/i', $class)){
847 continue;
848 }
849 $objectclasses[]= $this->attrs['objectClass'][$key];
850 }
851 $this->attrs['objectClass']= $objectclasses;
852 if ($this->trustModel != ""){
853 $this->attrs['objectClass'][]= "trustAccount";
854 $this->attrs['trustModel']= $this->trustModel;
855 $this->attrs['accessTo']= array();
856 if ($this->trustModel == "byhost"){
857 foreach ($this->accessTo as $host){
858 $this->attrs['accessTo'][]= $host;
859 }
860 }
861 } else {
862 if ($this->was_trust_account){
863 $this->attrs['accessTo']= array();
864 $this->attrs['trustModel']= array();
865 }
866 }
868 /******
869 Ende - Trust accounts
870 ******/
872 /* Write back to ldap */
873 $ldap->cd($this->dn);
874 $this->cleanup();
875 $ldap->$mode($this->attrs);
877 if($mode == "add"){
878 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
879 }else{
880 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
881 }
883 /* Trigger post signal */
884 $this->handle_post_events($mode);
886 $ret= 0;
887 if (!$ldap->success()){
888 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
889 $ret= 1;
890 }
892 return ($ret);
893 }
895 function remove_from_parent()
896 {
897 plugin::remove_from_parent();
899 $ldap= $this->config->get_ldap_link();
900 $ldap->rmdir($this->dn);
901 if (!$ldap->success()){
902 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
903 }
905 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
907 /* Trigger remove signal */
908 $this->handle_post_events("remove");
909 }
912 function PrepareForCopyPaste($source)
913 {
914 plugin::PrepareForCopyPaste($source);
916 /* Reload tabs */
917 $this->parent->reload($this->gosaGroupObjects );
919 /* Reload plugins */
920 foreach($this->parent->by_object as $name => $class ){
921 if(get_class($this) != $name) {
922 $this->parent->by_object[$name]->PrepareForCopyPaste($source);
923 }
924 }
926 $source_o = new ogroup ($this->config, $source['dn']);
927 foreach(array("accessTo","member","gosaGroupObjects") as $attr){
928 $this->$attr = $source_o->$attr;
929 }
930 }
933 function getCopyDialog()
934 {
935 $smarty = get_smarty();
936 $smarty->assign("cn", $this->cn);
937 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
938 $ret = array();
939 $ret['string'] = $str;
940 $ret['status'] = "";
941 return($ret);
942 }
944 function saveCopyDialog()
945 {
946 if(isset($_POST['cn'])){
947 $this->cn = $_POST['cn'];
948 }
949 }
952 function IsReleaseManagementActivated()
953 {
954 /* Check if we should enable the release selection */
955 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
956 if(!empty($tmp)){
957 return(true);
958 }
959 return(false);
960 }
963 static function plInfo()
964 {
965 return (array(
966 "plShortName" => _("Generic"),
967 "plDescription" => _("Object group generic"),
968 "plSelfModify" => FALSE,
969 "plDepends" => array(),
970 "plPriority" => 1,
971 "plSection" => array("administration"),
972 "plCategory" => array("ogroups" => array("description" => _("Object groups"),
973 "objectClass" => "gosaGroupOfNames")),
974 "plProvidedAcls"=> array(
975 "cn" => _("Name"),
976 "base" => _("Base"),
977 "description" => _("Description"),
978 "trustModel" => _("Sytem trust"),
979 "member" => _("Member"))
980 ));
981 }
982 }
984 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
985 ?>