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