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 $group_dialog= FALSE;
54 var $view_logged = FALSE;
56 var $accessTo= array();
57 var $trustModel= "";
58 var $show_ws_dialog = FALSE;
60 var $was_trust_account= FALSE;
62 /* attribute list for save action */
63 var $attributes= array("cn", "description", "gosaGroupObjects","member","accessTo","trustModel");
64 var $objectclasses= array("top", "gosaGroupOfNames");
66 function ogroup (&$config, $dn= NULL)
67 {
68 plugin::plugin ($config, $dn);
69 $this->orig_dn= $dn;
71 $this->member = array();
73 /* Load member objects */
74 if (isset($this->attrs['member'])){
75 foreach ($this->attrs['member'] as $key => $value){
76 if ("$key" != "count"){
77 $value= @LDAP::convert($value);
78 $this->member["$value"]= "$value";
79 }
80 }
81 }
82 $this->is_account= TRUE;
84 /* Get global filter config */
85 if (!session::is_set("ogfilter")){
86 $ui= get_userinfo();
87 $base= get_base_from_people($ui->dn);
88 $ogfilter= array( "dselect" => $base,
89 "regex" => "*");
90 session::set("ogfilter", $ogfilter);
91 }
92 $ogfilter= session::get('ogfilter');
94 /* Adjust flags */
95 foreach( array( "U" => "accounts",
96 "G" => "groups",
97 "A" => "applications",
98 "D" => "departments",
99 "S" => "servers",
100 "W" => "workstations",
101 "O" => "winstations",
102 "T" => "terminals",
103 "F" => "phones",
104 "_" => "subtrees",
105 "P" => "printers") as $key => $val){
107 if (preg_match("/$key/", $this->gosaGroupObjects)){
108 $ogfilter[$val]= "checked";
109 } else {
110 $ogfilter[$val]= "";
111 }
112 }
113 session::set("ogfilter", $ogfilter);
115 if(session::is_set('CurrentMainBase')){
116 $this->base = session::get('CurrentMainBase');
117 }
119 /* Set base */
120 if ($this->dn == "new"){
121 $this->base = session::get('CurrentMainBase');
122 } else {
123 $this->base= preg_replace("/^[^,]+,".normalizePreg(get_ou("ogroupou"))."/","",$this->dn);
125 /* Is this account a trustAccount? */
126 if ($this->is_account && isset($this->attrs['trustModel'])){
127 $this->trustModel= $this->attrs['trustModel'][0];
128 $this->was_trust_account= TRUE;
129 } else {
130 $this->was_trust_account= FALSE;
131 $this->trustModel= "";
132 }
134 $this->accessTo = array();
135 if ($this->is_account && isset($this->attrs['accessTo'])){
136 for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
137 $tmp= $this->attrs['accessTo'][$i];
138 $this->accessTo[$tmp]= $tmp;
139 }
140 }
141 }
143 $this->orig_cn = $this->cn;
144 $this->orig_base = $this->base;
146 /* Load member data */
147 $this->reload();
148 }
150 function AddDelMembership($NewMember = false){
152 if($NewMember){
154 /* Add member and force reload */
155 $this->member[$NewMember]= $NewMember;
156 $this->reload();
158 $this->memberList[$NewMember]= $this->objcache[$NewMember];
159 unset ($this->objects[$NewMember]);
160 uasort ($this->memberList, 'sort_list');
161 reset ($this->memberList);
162 }else{
163 /* Delete objects from group */
164 if (isset($_POST['delete_membership']) && isset($_POST['members'])){
165 foreach ($_POST['members'] as $value){
166 $this->objects["$value"]= $this->memberList[$value];
167 unset ($this->memberList["$value"]);
168 unset ($this->member["$value"]);
169 uasort ($this->objects, 'sort_list');
170 reset ($this->objects);
171 }
172 $this->reload();
173 }
175 /* Add objects to group */
176 if (isset($_POST['add_object_finish']) && isset($_POST['objects'])){
178 $tmp = "";
179 foreach($this->memberList as $obj){
180 $tmp .= $obj['type'];
181 }
182 $skipped = FALSE;
183 foreach ($_POST['objects'] as $value){
184 if(preg_match("/T/",$tmp) && $this->objects[$value]['type'] == "W"){
185 $skipped =TRUE;
186 }elseif(preg_match("/W/",$tmp) && $this->objects[$value]['type'] == "T"){
187 $skipped =TRUE;
188 }else{
189 $this->memberList["$value"]= $this->objects[$value];
190 $this->member["$value"]= $value;
191 unset ($this->objects[$value]);
192 uasort ($this->memberList, 'sort_list');
193 reset ($this->memberList);
194 }
195 }
196 if($skipped){
197 msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
198 }
199 $this->reload();
200 }
201 }
202 }
204 function execute()
205 {
206 /* Call parent execute */
207 plugin::execute();
209 if(!$this->view_logged){
210 $this->view_logged = TRUE;
211 new log("view","ogroups/".get_class($this),$this->dn);
212 }
215 /* Do we represent a valid group? */
216 if (!$this->is_account){
217 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
218 msgPool::noValidExtension("object group")."</b>";
219 return ($display);
220 }
223 /* Load templating engine */
224 $smarty= get_smarty();
226 $tmp = $this->plInfo();
227 foreach($tmp['plProvidedAcls'] as $name => $translation){
228 $smarty->assign($name."ACL",$this->getacl($name));
229 }
231 /* Base select dialog */
232 $once = true;
233 foreach($_POST as $name => $value){
234 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
235 $once = false;
236 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
237 $this->dialog->setCurrentBase($this->base);
238 }
239 }
241 /***********
242 * Trusts
243 ***********/
245 /* Add user workstation? */
246 if (isset($_POST["add_ws"])){
247 $this->show_ws_dialog= TRUE;
248 $this->dialog= TRUE;
249 }
251 /* Add user workstation? */
252 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
253 foreach($_POST['wslist'] as $ws){
254 $this->accessTo[$ws]= $ws;
255 }
256 ksort($this->accessTo);
257 $this->is_modified= TRUE;
258 }
260 /* Remove user workstations? */
261 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
262 foreach($_POST['workstation_list'] as $name){
263 unset ($this->accessTo[$name]);
264 }
265 $this->is_modified= TRUE;
266 }
268 /* Add user workstation finished? */
269 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
270 $this->show_ws_dialog= FALSE;
271 $this->dialog= FALSE;
272 }
274 /* Show ws dialog */
275 if ($this->show_ws_dialog){
276 /* Save data */
277 $sysfilter= session::get("sysfilter");
278 foreach( array("depselect", "regex") as $type){
279 if (isset($_POST[$type])){
280 $sysfilter[$type]= $_POST[$type];
281 }
282 }
283 if (isset($_GET['search'])){
284 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
285 if ($s == "**"){
286 $s= "*";
287 }
288 $sysfilter['regex']= $s;
289 }
290 session::set("sysfilter", $sysfilter);
292 /* Get workstation list */
293 $exclude= "";
294 foreach($this->accessTo as $ws){
295 $exclude.= "(cn=$ws)";
296 }
297 if ($exclude != ""){
298 $exclude= "(!(|$exclude))";
299 }
300 $regex= $sysfilter['regex'];
301 $filter= "(&(|(objectClass=goServer)(objectClass=gotoWorkstation)(objectClass=gotoTerminal))$exclude(cn=*)(cn=$regex))";
303 $deps_a = array(get_ou("serverou"),
304 get_ou("terminalou"),
305 get_ou("workstationou"));
306 $res= get_sub_list($filter, array("terminal","server","workstation"), $deps_a, get_ou("systemsou").$sysfilter['depselect'],
307 array("cn"), GL_SUBSEARCH | GL_SIZELIMIT);
308 $wslist= array();
309 foreach ($res as $attrs){
310 $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
311 }
312 asort($wslist);
313 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
314 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
315 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
316 $smarty->assign("deplist", $this->config->idepartments);
317 $smarty->assign("alphabet", generate_alphabet());
318 foreach( array("depselect", "regex") as $type){
319 $smarty->assign("$type", $sysfilter[$type]);
320 }
321 $smarty->assign("hint", print_sizelimit_warning());
322 $smarty->assign("wslist", $wslist);
323 $smarty->assign("apply", apply_filter());
324 $display= $smarty->fetch (get_template_path('trust_machines.tpl', TRUE, dirname(__FILE__)));
325 return ($display);
326 }
328 /***********
329 * Ende - Trusts
330 ***********/
333 /* Dialog handling */
334 if(is_object($this->dialog) && $this->acl_is_moveable()){
335 /* Must be called before save_object */
336 $this->dialog->save_object();
338 if($this->dialog->isClosed()){
339 $this->dialog = false;
340 }elseif($this->dialog->isSelected()){
342 /* A new base was selected, check if it is a valid one */
343 $tmp = $this->get_allowed_bases();
344 if(isset($tmp[$this->dialog->isSelected()])){
345 $this->base = $this->dialog->isSelected();
346 }
347 $this->dialog= false;
348 }else{
349 return($this->dialog->execute());
350 }
351 }
353 /* Add objects? */
354 if (isset($_POST["edit_membership"])){
355 $this->group_dialog= TRUE;
356 $this->dialog= TRUE;
357 }
359 /* Add objects finished? */
360 if (isset($_POST["add_object_finish"]) || isset($_POST["add_object_cancel"])){
361 $this->group_dialog= FALSE;
362 $this->dialog= FALSE;
363 }
365 /* Manage object add dialog */
366 if ($this->group_dialog){
368 /* Save data */
369 $ogfilter= session::get("ogfilter");
370 foreach( array("dselect", "regex") as $type){
371 if (isset($_POST[$type])){
372 $ogfilter[$type]= $_POST[$type];
373 }
374 }
375 if (isset($_POST['dselect'])){
376 foreach( array("accounts", "groups", "applications", "departments",
377 "servers", "workstations", "winstations", "terminals", "printers","subtrees",
378 "phones") as $type){
380 if (isset($_POST[$type])) {
381 $ogfilter[$type]= "checked";
382 } else {
383 $ogfilter[$type]= "";
384 }
385 }
386 }
387 if (isset($_GET['search'])){
388 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
389 if ($s == "**"){
390 $s= "*";
391 }
392 $ogfilter['regex']= $s;
393 }
394 session::set("ogfilter", $ogfilter);
395 $this->reload();
397 /* Calculate actual groups */
398 $smarty->assign("objects", $this->convert_list($this->objects));
400 /* Show dialog */
401 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
402 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
403 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
404 $smarty->assign("deplist", $this->config->idepartments);
405 $smarty->assign("alphabet", generate_alphabet());
406 foreach( array("dselect", "regex", "subtrees") as $type){
407 $smarty->assign("$type", $ogfilter[$type]);
408 }
409 $smarty->assign("hint", print_sizelimit_warning());
410 $smarty->assign("apply", apply_filter());
412 /* Build up checkboxes
413 */
414 $ar = array(
415 "departments" => array(
416 "T" => msgPool::selectToView(_("departments")),
417 "C" => (isset($ogfilter['departments']) && ($ogfilter['departments'])),
418 "L" => sprintf(_("Show %s"),_("departments"))),
419 "accounts" => array(
420 "T" => msgPool::selectToView(_("people")),
421 "C" => (isset($ogfilter['accounts']) && ($ogfilter['accounts'])),
422 "L" => sprintf(_("Show %s"),_("people"))),
423 "groups"=> array(
424 "T" => msgPool::selectToView(_("groups")),
425 "C" => (isset($ogfilter['groups']) && ($ogfilter['groups'])),
426 "L" => sprintf(_("Show %s"),_("groups"))),
427 "servers"=> array(
428 "T" => msgPool::selectToView(_("servers")),
429 "C" => (isset($ogfilter['servers']) && ($ogfilter['servers'])),
430 "L" => sprintf(_("Show %s"),_("servers"))),
431 "workstations"=> array(
432 "T" => msgPool::selectToView(_("workstations")),
433 "C" => (isset($ogfilter['workstations']) && ($ogfilter['workstations'])),
434 "L" => sprintf(_("Show %s"),_("workstations"))),
435 "terminals"=> array(
436 "T" => msgPool::selectToView(_("terminals")),
437 "C" => (isset($ogfilter['terminals']) && ($ogfilter['terminals'])),
438 "L" => sprintf(_("Show %s"),_("terminals"))),
439 "printers"=> array(
440 "T" => msgPool::selectToView(_("printer")),
441 "C" => (isset($ogfilter['printers']) && ($ogfilter['printers'])),
442 "L" => sprintf(_("Show %s"),_("printers"))),
443 "phones"=> array(
444 "T" => msgPool::selectToView(_("phones")),
445 "C" => (isset($ogfilter['phones']) && ($ogfilter['phones'])),
446 "L" => sprintf(_("Show %s"),_("phones"))));
448 /* Allow selecting applications if we are having a non
449 release managed application storage */
450 if(!$this->IsReleaseManagementActivated()){
451 $ar["applications"] = array(
452 "T" => msgPool::selectToView(_("applications")),
453 "C" => (isset($ogfilter['applications']) && ($ogfilter['applications'])),
454 "L" => sprintf(_("Show %s"),_("applications")));
455 }
457 $smarty->assign("checkboxes",$ar);
458 $display= $smarty->fetch (get_template_path('ogroup_objects.tpl', TRUE, dirname(__FILE__)));
459 return ($display);
460 }
462 /* Bases / Departments */
463 if ((isset($_POST['base'])) && ($this->acl_is_moveable())){
464 $this->base= $_POST['base'];
465 }
467 /* Assemble combine string */
468 if ($this->gosaGroupObjects == "[]"){
469 $smarty->assign("combinedObjects", _("none"));
470 } elseif (strlen($this->gosaGroupObjects) > 4){
471 $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
472 } else {
473 $conv= array( "U" => _("users"),
474 "G" => _("groups"),
475 "A" => _("applications"),
476 "D" => _("departments"),
477 "S" => _("servers"),
478 "W" => _("workstations"),
479 "O" => _("winstations"),
480 "T" => _("terminals"),
481 "F" => _("phones"),
482 "P" => _("printers"));
484 $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
485 $p1= $conv[$type[0]];
486 error_reporting(0);
487 if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
488 $p2= $conv[$type[1]];
489 $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
490 } else {
491 $smarty->assign("combinedObjects", "$p1");
492 }
493 error_reporting(E_ALL | E_STRICT);
494 }
496 /* Assign variables */
497 $smarty->assign("bases", $this->get_allowed_bases());
498 $smarty->assign("base_select", $this->base);
499 $smarty->assign("department", $this->department);
500 $smarty->assign("members", $this->convert_list($this->memberList));
502 /* Objects have to be tuned... */
503 $smarty->assign("objects", $this->convert_list($this->objects));
505 /* Fields */
506 foreach ($this->attributes as $val){
507 $smarty->assign("$val", $this->$val);
508 }
510 /******
511 Trust account
512 ******/
513 $smarty->assign("trusthide", " disabled ");
514 $smarty->assign("trustmodeACL", $this->getacl("trustModel"));
515 if ($this->trustModel == "fullaccess"){
516 $trustmode= 1;
517 // pervent double disable tag in html code, this will disturb our clean w3c html
518 $smarty->assign("trustmode", $this->getacl("trustModel"));
520 } elseif ($this->trustModel == "byhost"){
521 $trustmode= 2;
522 $smarty->assign("trusthide", "");
523 } else {
524 // pervent double disable tag in html code, this will disturb our clean w3c html
525 $smarty->assign("trustmode", $this->getacl("trustModel"));
526 $trustmode= 0;
527 }
528 $smarty->assign("trustmode", $trustmode);
529 $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
530 2 => _("allow access to these hosts")));
532 $smarty->assign("workstations", $this->accessTo);
534 if((count($this->accessTo))==0){
535 $smarty->assign("emptyArrAccess",true);
536 }else{
537 $smarty->assign("emptyArrAccess",false);
538 }
539 /******
540 Ende - Trust account
541 ******/
543 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
544 }
547 /* Save data to object */
548 function save_object()
549 {
550 /* Save additional values for possible next step */
551 if (isset($_POST['ogroupedit'])){
553 /******
554 Trust account
555 ******/
557 if($this->acl_is_writeable("trustModel")){
558 if (isset($_POST['trustmode'])){
559 $saved= $this->trustModel;
560 if ($_POST['trustmode'] == "1"){
561 $this->trustModel= "fullaccess";
562 } elseif ($_POST['trustmode'] == "2"){
563 $this->trustModel= "byhost";
564 } else {
565 $this->trustModel= "";
566 }
567 if ($this->trustModel != $saved){
568 $this->is_modified= TRUE;
569 }
570 }
571 }
572 /******
573 Ende Trust account
574 ******/
576 /* Create a base backup and reset the
577 base directly after calling plugin::save_object();
578 Base will be set seperatly a few lines below */
579 $base_tmp = $this->base;
580 plugin::save_object();
581 $this->base = $base_tmp;
583 /* Save base, since this is no LDAP attribute */
584 $tmp = $this->get_allowed_bases();
585 if(isset($_POST['base'])){
586 if(isset($tmp[$_POST['base']])){
587 $this->base= $_POST['base'];
588 }
589 }
590 }
591 }
594 /* (Re-)Load objects */
595 function reload()
596 {
597 /*###########
598 Variable initialisation
599 ###########*/
601 $this->objects = array();
602 $this->ui = get_userinfo();
603 $filter = "";
604 $objectClasses = array();
606 $ogfilter = session::get("ogfilter");
607 $regex = $ogfilter['regex'];
609 $ldap= $this->config->get_ldap_link();
610 $ldap->cd ($ogfilter['dselect']);
613 /*###########
614 Generate Filter
615 ###########*/
617 $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount" ,
618 "DN"=> get_people_ou() ,"ACL" => "users"),
619 "groups" => array("OBJ"=>"group", "CLASS"=>"posixGroup" ,
620 "DN"=> get_groups_ou('ogroupou') ,"ACL" => "groups"),
621 "departments" => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
622 "DN"=> "" ,"ACL" => "department"),
623 "servers" => array("OBJ"=>"servgeneric", "CLASS"=>"goServer" ,
624 "DN"=> get_ou('serverou') ,"ACL" => "server"),
625 "workstations" => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
626 "DN"=> get_ou('workstationou') ,"ACL" => "workstation"),
627 "winstations" => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",
628 "DN"=> get_ou('WINSTATIONS') ,"ACL" => "winstation"),
629 "terminals" => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal" ,
630 "DN"=> get_ou('terminalou') ,"ACL" => "terminal"),
631 "printers" => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter" ,
632 "DN"=> get_ou('printerou') ,"ACL" => "printer"),
633 "phones" => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware" ,
634 "DN"=> get_ou('phoneou') ,"ACL" => "phone"));
637 /* Allow searching for applications, if we are not using release managed applications
638 */
639 if(!$this->IsReleaseManagementActivated()){
640 $p_f[ "applications"] = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
641 "DN"=> get_ou('applicationou') ,"ACL" => "application");
642 }
644 /*###########
645 Perform search for selected objectClasses & regex to fill list with objects
646 ###########*/
648 $Get_list_flags = 0;
649 if($ogfilter['subtrees'] == "checked"){
650 $Get_list_flags |= GL_SUBSEARCH;
651 }
653 foreach($p_f as $post_name => $data){
655 if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
657 if($ogfilter['subtrees']){
658 $base = $ogfilter['dselect'];
659 }else{
660 $base = $data['DN'].$ogfilter['dselect'];
661 }
664 $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
665 $res = get_list($filter, $data['ACL'] , $base,
666 array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
668 /* fetch results and append them to the list */
669 foreach($res as $attrs){
671 $type= $this->getObjectType($attrs);
672 $name= $this->getObjectName($attrs);
674 /* Fill array */
675 if (isset($attrs["description"][0])){
676 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
677 } elseif (isset($attrs["uid"][0])) {
678 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
679 } else {
680 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
681 }
682 }
683 }
684 }
685 uasort ($this->objects, 'sort_list');
686 reset ($this->objects);
689 /*###########
690 Build member list and try to detect obsolete entries
691 ###########*/
693 $this->memberList = array();
695 /* Walk through all single member entry */
696 foreach($this->member as $dn){
698 /* The dn for the current member can't be resolved
699 it seams that this entry was removed
700 */
701 /* Try to resolv the entry again, if it still fails, display error msg */
702 $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
704 /* It has failed, add entry with type flag I (Invalid)*/
705 if (!$ldap->success()){
706 $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".@LDAP::fix($dn),"type" => "I");
708 } else {
710 /* Append this entry to our all object list */
712 /* Fetch object */
713 $attrs= $ldap->fetch();
715 $type= $this->getObjectType($attrs);
716 $name= $this->getObjectName($attrs);
718 if (isset($attrs["description"][0])){
719 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
720 } elseif (isset($attrs["uid"][0])) {
721 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
722 } else {
723 $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
724 }
725 $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass'];
727 if(isset($attrs['macAddress'][0])){
728 $this->objcache[$attrs["dn"]]['macAddress'] = $attrs['macAddress'][0];
729 }else{
730 $this->objcache[$attrs["dn"]]['macAddress'] = "";
731 }
733 if(isset($attrs['uid'])){
734 $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid'];
735 }
737 /* Fill array */
738 if (isset($attrs["description"][0])){
739 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
740 } else {
741 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
742 }
744 $this->memberList[$dn]= $this->objects[$attrs["dn"]];
745 }
746 }
747 uasort ($this->memberList, 'sort_list');
748 reset ($this->memberList);
750 /* Assemble types of currently combined objects */
751 $objectTypes= "";
752 foreach ($this->memberList as $dn => $desc){
754 /* Invalid object? */
755 if ($desc['type'] == 'I'){
756 continue;
757 }
759 /* Fine. Add to list. */
760 if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
761 $objectTypes.= $desc['type'];
762 }
763 }
764 $this->gosaGroupObjects= "[$objectTypes]";
765 }
768 function convert_list($input)
769 {
770 $temp= "";
771 $conv= array(
772 "U" => "plugins/generic/images/head.png",
773 "G" => "plugins/groups/images/groups.png",
774 "A" => "plugins/ogroups/images/application.png",
775 "D" => "plugins/departments/images/department.png",
776 "S" => "plugins/ogroups/images/server.png",
777 "W" => "plugins/ogroups/images/workstation.png",
778 "O" => "plugins/ogroups/images/winstation.png",
779 "T" => "plugins/ogroups/images/terminal.png",
780 "F" => "plugins/ogroups/images/phone.png",
781 "I" => "images/lists/flag.png",
782 "P" => "plugins/ogroups/images/printer.png");
784 foreach ($input as $key => $value){
785 /* Generate output */
786 $temp.= "<option title='".addslashes( $key)."' value=\"$key\" class=\"select\" style=\"background-image:url('".get_template_path($conv[$value['type']])."');\">".$value['text']."</option>\n";
787 }
789 return ($temp);
790 }
793 function getObjectType($attrs)
794 {
795 $type= "I";
797 foreach(array( "U" => "gosaAccount",
798 "G" => "posixGroup",
799 "A" => "gosaApplication",
800 "D" => "gosaDepartment",
801 "S" => "goServer",
802 "W" => "gotoWorkstation",
803 "O" => "opsiClient",
804 "T" => "gotoTerminal",
805 "F" => "goFonHardware",
806 "P" => "gotoPrinter") as $index => $class){
807 if (in_array($class, $attrs['objectClass'])){
808 $type= $index;
809 break;
810 }
811 }
813 return ($type);
814 }
817 function getObjectName($attrs)
818 {
819 /* Person? */
820 $name ="";
821 if (in_array('gosaAccount', $attrs['objectClass'])){
822 if(isset($attrs['sn']) && isset($attrs['givenName'])){
823 $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
824 } else {
825 $name= $attrs['uid'][0];
826 }
827 } else {
828 if(isset($attrs["cn"][0])) {
829 $name= $attrs['cn'][0];
830 } else {
831 $name= $attrs['ou'][0];
832 }
833 }
835 return ($name);
836 }
839 function check()
840 {
841 /* Call common method to give check the hook */
842 $message= plugin::check();
844 /* Permissions for that base? */
845 if ($this->base != ""){
846 $new_dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
847 } else {
848 $new_dn= $this->dn;
849 }
852 $ldap = $this->config->get_ldap_link();
853 if($this->dn != $new_dn){
854 $ldap->cat ($new_dn, array('dn'));
855 }
857 if($ldap->count() !=0){
858 $message[]= msgPool::duplicated(_("Name"));
859 }
861 /* Set new acl base */
862 if($this->dn == "new") {
863 $this->set_acl_base($this->base);
864 }
866 /* must: cn */
867 if ($this->cn == ""){
868 $message[]= msgPool::required(_("Name"));
869 }
871 /* To many different object types? */
872 if (strlen($this->gosaGroupObjects) > 4){
873 $message[]= _("You can combine two different object types at maximum, only!");
874 }
876 /* Check if we are allowed to create or move this object
877 */
878 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
879 $message[] = msgPool::permCreate();
880 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
881 $message[] = msgPool::permMove();
882 }
884 return ($message);
885 }
888 /* Save to LDAP */
889 function save()
890 {
891 plugin::save();
893 /* Move members to target array */
894 $this->attrs['member'] =array();
895 foreach ($this->member as $key => $desc){
896 $this->attrs['member'][]= @LDAP::fix($key);
897 }
899 $ldap= $this->config->get_ldap_link();
901 /* New accounts need proper 'dn', propagate it to remaining objects */
902 if ($this->dn == 'new'){
903 $this->dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
904 }
906 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
907 new entries. So do a check first... */
908 $ldap->cat ($this->dn, array('dn'));
909 if ($ldap->fetch()){
910 /* Modify needs array() to remove values :-( */
911 if (!count ($this->member)){
912 $this->attrs['member']= array();
913 }
914 $mode= "modify";
916 } else {
917 $mode= "add";
918 $ldap->cd($this->config->current['BASE']);
919 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
920 }
922 /******
923 Trust accounts
924 ******/
925 $objectclasses= array();
926 foreach ($this->attrs['objectClass'] as $key => $class){
927 if (preg_match('/trustAccount/i', $class)){
928 continue;
929 }
930 $objectclasses[]= $this->attrs['objectClass'][$key];
931 }
932 $this->attrs['objectClass']= $objectclasses;
933 if ($this->trustModel != ""){
934 $this->attrs['objectClass'][]= "trustAccount";
935 $this->attrs['trustModel']= $this->trustModel;
936 $this->attrs['accessTo']= array();
937 if ($this->trustModel == "byhost"){
938 foreach ($this->accessTo as $host){
939 $this->attrs['accessTo'][]= $host;
940 }
941 }
942 } else {
943 if ($this->was_trust_account){
944 $this->attrs['accessTo']= array();
945 $this->attrs['trustModel']= array();
946 }
947 }
949 /******
950 Ende - Trust accounts
951 ******/
953 /* Write back to ldap */
954 $ldap->cd($this->dn);
955 $this->cleanup();
956 $ldap->$mode($this->attrs);
958 if($mode == "add"){
959 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
960 }else{
961 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
962 }
964 /* Trigger post signal */
965 $this->handle_post_events($mode);
967 $ret= 0;
968 if (!$ldap->success()){
969 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
970 $ret= 1;
971 }
973 return ($ret);
974 }
976 function remove_from_parent()
977 {
978 plugin::remove_from_parent();
980 $ldap= $this->config->get_ldap_link();
981 $ldap->rmdir($this->dn);
982 if (!$ldap->success()){
983 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
984 }
986 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
988 /* Trigger remove signal */
989 $this->handle_post_events("remove");
990 }
993 function PrepareForCopyPaste($source)
994 {
995 /* Update available object types */
996 if(isset($source['gosaGroupObjects'][0])){
997 $this->gosaGroupObjects = $source['gosaGroupObjects'][0];
998 }
1000 /* Reload tabs */
1001 $this->parent->reload($this->gosaGroupObjects );
1003 /* Reload plugins */
1004 foreach($this->parent->by_object as $name => $class ){
1005 if(get_class($this) != $name) {
1006 $this->parent->by_object[$name]->PrepareForCopyPaste($source);
1007 }
1008 }
1010 /* Load member objects */
1011 if (isset($source['member'])){
1012 foreach ($source['member'] as $key => $value){
1013 if ("$key" != "count"){
1014 $value= @LDAP::convert($value);
1015 $this->member["$value"]= "$value";
1016 }
1017 }
1018 }
1020 }
1023 function getCopyDialog()
1024 {
1025 $smarty = get_smarty();
1026 $smarty->assign("cn", $this->cn);
1027 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1028 $ret = array();
1029 $ret['string'] = $str;
1030 $ret['status'] = "";
1031 return($ret);
1032 }
1034 function saveCopyDialog()
1035 {
1036 if(isset($_POST['cn'])){
1037 $this->cn = $_POST['cn'];
1038 }
1039 }
1042 function IsReleaseManagementActivated()
1043 {
1044 /* Check if we should enable the release selection */
1045 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1046 if(!empty($tmp)){
1047 return(true);
1048 }
1049 return(false);
1050 }
1053 static function plInfo()
1054 {
1055 return (array(
1056 "plShortName" => _("Generic"),
1057 "plDescription" => _("Object group generic"),
1058 "plSelfModify" => FALSE,
1059 "plDepends" => array(),
1060 "plPriority" => 1,
1061 "plSection" => array("administration"),
1062 "plCategory" => array("ogroups" => array("description" => _("Object groups"),
1063 "objectClass" => "gosaGroupOfNames")),
1064 "plProvidedAcls"=> array(
1065 "cn" => _("Name"),
1066 "base" => _("Base"),
1067 "description" => _("Description"),
1068 "member" => _("Member"))
1069 ));
1070 }
1071 }
1073 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1074 ?>