1 <?php
3 class group extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Handling of GOsa's base group object";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* Group attributes */
11 var $cn= "";
12 var $description= "";
13 var $gidNumber= "";
14 var $memberUid= array();
16 /* Helpers */
17 var $base= "";
18 var $force_gid= FALSE;
19 var $fon_group= FALSE;
20 var $smbgroup= FALSE;
21 var $groupType= FALSE;
22 var $samba3= FALSE;
23 var $sambaSID= "";
24 var $sambaDomainName= "DEFAULT";
25 var $SID= "";
26 var $ridBase= 0;
27 var $members= array();
28 var $users= array();
29 var $allusers= array();
30 var $saved_gidNumber= "";
31 var $oldgroupType= "";
32 var $orig_dn= "";
33 var $orig_cn= "";
34 var $has_mailAccount= FALSE;
35 var $group_dialog= FALSE;
36 var $nagios_group =FALSE;
37 var $sambaGroupType;
38 var $dialog;
39 var $OnlyShowFirstEntries =200;
41 var $allowGroupsWithSameNameInOtherSubtrees = true;
43 /* attribute list for save action */
44 var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
45 var $objectclasses= array("top", "posixGroup");
47 function group ($config, $dn= NULL)
48 {
49 plugin::plugin ($config, $dn);
51 /* Load attributes depending on the samba version */
52 $this->samba3= ($config->current['SAMBAVERSION'] == 3);
53 $this->orig_dn= $dn;
54 $this->orig_cn= $this->cn;
56 /* Get member list */
57 if (isset($this->attrs['memberUid'][0])){
58 $tmp= array();
59 for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
60 $tmp[]= $this->attrs['memberUid'][$i];
61 }
62 $this->memberUid= $tmp;
63 sort ($this->memberUid);
64 }
66 /* Save gidNumber for later use */
67 if (isset($this->attrs['gidNumber'])){
68 $this->saved_gidNumber= $this->attrs['gidNumber'][0];
69 }
71 /* Is a samba group? */
72 if (isset($this->attrs['objectClass'])){
73 if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
74 $this->smbgroup= FALSE;
75 } else {
76 $this->smbgroup= TRUE;
77 if (isset($this->attrs['sambaSID'])){
78 $this->sambaSID= $this->attrs['sambaSID'][0];
79 }
80 }
81 if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
82 $this->fon_group= FALSE;
83 } else {
84 $this->fon_group= TRUE;
85 }
86 if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
87 $this->nagios_group= FALSE;
88 } else {
89 $this->nagios_group= TRUE;
90 }
91 }
93 /* Set mail flag */
94 if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
95 $this->has_mailAccount= TRUE;
96 }
98 /* Get samba Domain in case of samba 3 */
99 if ($this->samba3 && $this->sambaSID != ""){
100 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
101 $ldap= $this->config->get_ldap_link();
102 $ldap->cd($this->config->current['BASE']);
103 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
104 if ($ldap->count() != 0){
105 $attrs= $ldap->fetch();
106 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
108 /* Get domain name for SID */
109 $this->sambaDomainName= "DEFAULT";
110 foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
111 if ($val['SID'] == $this->SID){
112 $this->sambaDomainName= $key;
113 break;
114 }
115 }
116 } else {
117 if (isset($this->config->current['RIDBASE'])){
118 $this->sambaDomainName= "DEFAULT";
119 $this->ridBase= $this->config->current['RIDBASE'];
120 $this->SID= $this->config->current['SID'];
121 } else {
122 print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
123 }
124 }
126 /* Get group type */
127 $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
128 if ($this->groupType < 500 || $this->groupType > 553){
129 $this->groupType= 0;
130 }
131 $this->oldgroupType= $this->groupType;
132 }
134 /* Get global filter config */
135 if (!is_global("gufilter")){
136 $ui= get_userinfo();
137 $base= get_base_from_people($ui->dn);
138 $gufilter= array( "dselect" => $base,
139 "regex" => "*");
140 register_global("gufilter", $gufilter);
141 }
142 $gufilter= get_global('gufilter');
144 $gufilter['SubSearchGroup'] = false;
145 $gufilter['dselect'] = $_SESSION['gufilter']['dselect'];
147 register_global('gufilter',$gufilter);
149 if ($this->dn == "new"){
150 if(isset($_SESSION['CurrentMainBase'])){
151 $this->base= $_SESSION['CurrentMainBase'];
152 }else{
153 $ui= get_userinfo();
154 $this->base= dn2base($ui->dn);
155 }
156 } else {
157 $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
158 }
160 /* This is always an account */
161 $this->is_account= TRUE;
162 $this->reload();
163 }
165 function execute()
166 {
167 /* Call parent execute */
168 plugin::execute();
170 /* Do we represent a valid group? */
171 if (!$this->is_account && $this->parent == NULL){
172 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
173 _("This 'dn' is no group.")."</b>";
174 return ($display);
175 }
177 /* Delete user from group */
178 if (isset($_POST['del_users']) && isset($_POST['members'])){
179 foreach ($_POST['members'] as $value){
180 unset ($this->members["$value"]);
181 $this->removeUser($value);
182 }
183 $this->reload();
184 }
186 /* Add objects? */
187 if (isset($_POST["edit_membership"])){
188 $this->group_dialog= TRUE;
189 $this->dialog= TRUE;
190 }
192 /* Add objects finished? */
193 if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
194 $this->group_dialog= FALSE;
195 $this->dialog= FALSE;
196 }
198 /* Add user to group */
199 if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
200 foreach ($_POST['users'] as $value){
201 $this->members["$value"]= $this->allusers[$value];
202 asort($this->members);
203 $this->addUser($value);
204 }
205 $this->reload();
206 }
208 /* Get bases */
209 $ui = get_userinfo();
210 $check = $ui->get_module_departments("groups");
211 $bases = array();
212 foreach($check as $dn_allowed){
213 $bases[$dn_allowed] = $this->config->idepartments[$dn_allowed];
214 }
216 /* Base select dialog */
217 $once = true;
218 foreach($_POST as $name => $value){
219 if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
221 $once = false;
222 $this->dialog = new baseSelectDialog($this->config,$this,$bases);
223 $this->dialog->setCurrentBase($this->base);
224 }
225 }
227 /* Dialog handling */
228 if(is_object($this->dialog)){
229 /* Must be called before save_object */
230 $this->dialog->save_object();
232 if($this->dialog->isClosed()){
233 $this->dialog = false;
234 }elseif($this->dialog->isSelected()){
235 if($this->acl_is_moveable()){
236 $this->base = $this->dialog->isSelected();
237 }
238 $this->dialog= false;
239 }else{
240 return($this->dialog->execute());
241 }
242 }
244 /* Assign templating stuff */
245 $smarty= get_smarty();
246 if ($this->samba3){
247 $smarty->assign("samba3", "true");
248 } else {
249 $smarty->assign("samba3", "");
250 }
252 if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
253 $smarty->assign("nagios",true);
254 }else{
255 $smarty->assign("nagios",false);
256 }
258 if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
259 $smarty->assign("pickupGroup",true);
260 }else{
261 $smarty->assign("pickupGroup",false);
262 }
264 /* Assign base ACL */
265 $baseACL = $this->getacl("base");
266 if(!$this->acl_is_moveable()) {
267 $baseACL = preg_replace("/w/","",$baseACL);
268 }
269 $smarty->assign("baseACL", $baseACL);
271 /* Manage object add dialog */
272 if ($this->group_dialog){
274 /* Save data */
275 $gufilter= get_global("gufilter");
276 foreach( array("dselect", "regex") as $type){
277 if (isset($_POST[$type])){
278 $gufilter[$type]= $_POST[$type];
279 }
280 }
281 if(isset($_POST['regex'])){
282 if(isset($_POST['SubSearchGroup'])){
283 $gufilter['SubSearchGroup'] = true;
284 }else{
285 $gufilter['SubSearchGroup'] = false;
286 }
287 }
289 if (isset($_GET['search'])){
290 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
291 if ($s == "**"){
292 $s= "*";
293 }
294 $gufilter['regex']= $s;
295 }
296 register_global("gufilter", $gufilter);
297 $this->reload();
299 /* Show dialog */
300 $smarty->assign("search_image", get_template_path('images/search.png'));
301 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
302 $smarty->assign("tree_image", get_template_path('images/tree.png'));
304 /* Get bases */
305 $ui = get_userinfo();
306 $check = $ui->get_module_departments("groups");
307 $bases = array();
308 foreach($check as $dn_allowed){
309 $bases[$dn_allowed] = $this->config->idepartments[$dn_allowed];
310 }
312 $smarty->assign("deplist", $bases_user_select);
313 $smarty->assign("alphabet", generate_alphabet());
314 foreach( array("dselect", "regex","SubSearchGroup") as $type){
315 $smarty->assign("$type", $gufilter[$type]);
316 }
317 $smarty->assign("hint", print_sizelimit_warning());
318 $smarty->assign("users", $this->displayUsers);
319 $smarty->assign("apply", apply_filter());
320 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
321 return ($display);
322 }
324 /* Bases / Departments */
325 if (isset($_POST['base'])){
326 $this->base= $_POST['base'];
327 }
329 $smarty->assign("bases", $bases);
330 $smarty->assign("base_select", $this->base);
332 if ($this->samba3){
333 $domains= array();
334 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
335 $domains[$name]= $name;
336 }
337 $smarty->assign("sambaDomains", $domains);
338 $smarty->assign("sambaDomainName", $this->sambaDomainName);
339 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
340 514 => _("Domain guests"));
342 /* Don't loose special groups! If not key'ed above, add it to
343 the combo box... */
344 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
345 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
346 }
348 $smarty->assign("groupTypes", $groupTypes);
349 $smarty->assign("groupType", $this->groupType);
350 }
352 /* Members and users */
353 $smarty->assign("members", $this->members);
355 /* Checkboxes */
356 foreach (array("force_gid", "smbgroup") as $val){
357 if ($this->$val == "1"){
358 $smarty->assign("$val", "checked");
359 } else {
360 $smarty->assign("$val", "");
361 }
362 }
363 if ($this->force_gid != "1"){
364 $smarty->assign("forceMode", "disabled");
365 }else{
366 $smarty->assign("forceMode", "");
367 }
368 if ($this->fon_group){
369 $smarty->assign("fon_group", "checked");
370 } else {
371 $smarty->assign("fon_group", "");
372 }
374 if ($this->nagios_group){
375 $smarty->assign("nagios_group", "checked");
376 } else {
377 $smarty->assign("nagios_group", "");
378 }
380 /* Fields */
381 foreach (array("cn", "description", "gidNumber") as $val){
382 $smarty->assign("$val", $this->$val);
383 }
385 $tmp = $this->plInfo();
386 foreach($tmp['plProvidedAcls'] as $name => $translation){
387 $smarty->assign($name."ACL",$this->getacl($name));
388 }
390 if($this->acl_is_writeable("base")){
391 $smarty->assign("baseSelect",true);
392 }else{
393 $smarty->assign("baseSelect",false);
394 }
396 /* Show main page */
397 $smarty->assign("alphabet", generate_alphabet(10));
398 $smarty->assign("search_image", get_template_path('images/search.png'));
399 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
400 $smarty->assign("tree_image", get_template_path('images/tree.png'));
401 $smarty->assign("deplist", $this->config->idepartments);
402 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
403 }
405 function addUser($uid)
406 {
407 $this->memberUid[]= $uid;
408 $this->memberUid= array_unique($this->memberUid);
409 }
411 function removeUser($uid)
412 {
413 $temp= array();
414 foreach ($this->memberUid as $value){
415 if ($value != $uid){
416 $temp[]= $value;
417 }
418 }
419 $this->memberUid= $temp;
420 }
423 /* Reload data */
424 function reload()
425 {
426 /* Fix regex string */
427 $gufilter = get_global("gufilter");
428 $regex = normalizeLdap($gufilter['regex']);
429 $MaxUser = $this->OnlyShowFirstEntries;
431 /* Prepare ldap link */
432 $ldap= $this->config->get_ldap_link();
433 $ldap->cd($gufilter['dselect']);
436 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
437 (Store gathered sn/givenName informations in $this->allusers too,
438 to be prepared when adding/deleting users)
439 */
440 $filter = "";
441 foreach ($this->memberUid as $value){
442 if(!isset($this->members[$value])){
443 $filter .= "(uid=".normalizeLdap($value).")";
444 }
445 }
446 if(!empty($filter)){
447 $ldap->cd($this->config->current['BASE']);
448 $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
449 while($attrs = $ldap->fetch()){
450 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
451 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
452 }
453 }
455 /* check if all uids are resolved */
456 foreach ($this->memberUid as $value){
457 if(!isset($this->members[$value])){
458 $this->members[$value] = _("! unknown id")." [".$value."]";
459 }
460 }
462 /* Create display list of users matching regex & filter
463 */
464 $this->displayUsers = array();
465 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
467 /* Search in current tree or within subtrees depending on the checkbox from filter section */
468 if($gufilter['SubSearchGroup']){
469 $flag = GL_SIZELIMIT | GL_SUBSEARCH;
470 $base = $gufilter['dselect'];
471 }else{
472 $flag = GL_SIZELIMIT ;
473 $base = get_people_ou().$gufilter['dselect'];
474 }
475 $i = 0;
478 $res = get_list($filter,"users",$base,array("uid", "sn", "givenName"),$flag);
480 /* Fetch all users and skip already used users */
481 foreach($res as $attrs){
482 if(in_array($attrs['uid'][0], $this->memberUid)) {
483 continue;
484 }
485 $i ++;
486 if($i > $MaxUser) {
487 break;
488 }
489 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
490 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
491 }
493 /* If more than max users are found, display a message to warn the user */
494 if(($i == $MaxUser)){
495 print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
496 }
498 /* Sort lists */
499 natcasesort($this->members);
500 reset($this->members);
501 natcasesort ($this->displayUsers);
502 reset ($this->displayUsers);
503 }
506 /* Create display name, this was used so often that it is excluded into a seperate function */
507 function createResultName($attrs)
508 {
509 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
510 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
511 } else {
512 $ret= $attrs['uid'][0];
513 }
514 return($ret);
515 }
518 function remove_from_parent()
519 {
520 plugin::remove_from_parent();
522 $ldap= $this->config->get_ldap_link();
523 $ldap->rmdir($this->dn);
524 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
526 /* Delete references to object groups */
527 $ldap->cd ($this->config->current['BASE']);
528 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
529 while ($ldap->fetch()){
530 $og= new ogroup($this->config, $ldap->getDN());
531 unset($og->member[$this->dn]);
532 $og->save ();
533 }
535 /* Send signal to the world that we've done */
536 $this->handle_post_events("remove");
537 }
540 /* Save data to object */
541 function save_object()
542 {
543 /* Save additional values for possible next step */
544 if (isset($_POST['groupedit'])){
546 plugin::save_object();
548 $this->force_gid= 0;
551 /* Only reset sambagroup flag if we are able to write this flag */
552 if($this->acl_is_writeable("sambaGroupType")){
553 $this->smbgroup = 0;
554 }
556 /* Get base selection */
557 if($this->acl_is_moveable() && isset($_POST['base'])){
558 $this->base = $_POST['base'];
559 }
561 foreach (array(
562 "force_gid" => "gidNumber",
563 "smbgroup" => "sambaGroupType") as $val => $aclname) {
564 if ($this->acl_is_writeable($aclname) && isset($_POST["$val"])){
565 $this->$val= $_POST["$val"];
566 }
567 }
569 /* Save sambaDomain attribute */
570 if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
571 $this->sambaDomainName= $_POST['sambaDomainName'];
572 $this->groupType= $_POST['groupType'];
573 }
575 /* Save fon attribute */
576 if ($this->acl_is_writeable("fon_group")){
577 if (isset ($_POST['fon_group'])){
578 $this->fon_group= TRUE;
579 } else {
580 $this->fon_group= FALSE;
581 }
582 }
583 if ($this->acl_is_writeable("nagios_group")){
584 if (isset ($_POST['nagios_group'])){
585 $this->nagios_group= TRUE;
586 } else {
587 $this->nagios_group= FALSE;
588 }
589 }
590 }
591 }
594 /* Save to LDAP */
595 function save()
596 {
598 /* ID handling */
599 if ($this->force_gid == 0){
600 if ($this->saved_gidNumber != ""){
601 $this->gidNumber= $this->saved_gidNumber;
602 } else {
603 /* Calculate new, lock uids */
604 $wait= 10;
605 while (get_lock("uidnumber") != ""){
606 sleep (1);
608 /* timed out? */
609 if ($wait-- == 0){
610 break;
611 }
612 }
613 add_lock ("uidnumber", "gosa");
614 $this->gidNumber= $this->get_next_id("gidNumber");
615 }
616 }
618 plugin::save();
620 /* Remove objectClass for samba/phone support */
621 $tmp= array();
622 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
623 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
624 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
625 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
626 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
627 $tmp[]= $this->attrs['objectClass'][$i];
628 }
629 }
630 $this->attrs['objectClass']= $tmp;
631 $ldap= $this->config->get_ldap_link();
633 /* Add samba group functionality */
634 if ($this->samba3 && $this->smbgroup){
636 /* Fixed undefined index ...
637 */
638 $this->SID = $this->ridBase = "";
639 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
640 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
641 }else{
642 print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
643 }
644 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
645 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
646 }else{
647 print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
648 }
650 $this->attrs['objectClass'][]= 'sambaGroupMapping';
651 $this->attrs['sambaGroupType']= "2";
653 /* Check if we need to create a special entry */
654 if ($this->groupType == 0){
656 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
657 $gidNumber= $this->gidNumber;
658 while(TRUE){
659 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
660 $ldap->cd($this->config->current['BASE']);
661 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
662 if ($ldap->count() == 0){
663 break;
664 }
665 $gidNumber++;
666 }
667 $this->attrs['sambaSID']= $sid;
668 $this->sambaSID= $sid;
669 }
671 } else {
672 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
673 }
675 /* User wants me to fake the idMappings? This is useful for
676 making winbind resolve the group names in a reasonable amount
677 of time in combination with larger databases. */
678 if (isset($this->config->current['SAMBAIDMAPPING']) &&
679 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
680 $this->attrs['objectClass'][]= "sambaIdmapEntry";
681 }
683 }
685 /* Add phone functionality */
686 if ($this->fon_group){
687 $this->attrs['objectClass'][]= "goFonPickupGroup";
688 }
690 /* Add nagios functionality */
691 if ($this->nagios_group){
692 $this->attrs['objectClass'][]= "nagiosContactGroup";
693 }
695 /* Take members array */
696 if (count ($this->memberUid)){
697 $this->attrs['memberUid']= array_unique($this->memberUid);
698 }
700 /* New accounts need proper 'dn', propagate it to remaining objects */
701 if ($this->dn == 'new'){
702 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
703 }
705 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
706 new entries. So do a check first... */
707 $ldap->cat ($this->dn, array('dn'));
708 if ($ldap->fetch()){
709 /* Modify needs array() to remove values :-( */
710 if (!count ($this->memberUid)){
711 $this->attrs['memberUid']= array();
712 }
713 if ($this->samba3){
714 if (!$this->smbgroup){
715 $this->attrs['sambaGroupType']= array();
716 $this->attrs['sambaSID']= array();
717 }
718 }
719 $mode= "modify";
720 } else {
721 $mode= "add";
722 $ldap->cd($this->config->current['BASE']);
723 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
724 }
726 /* Write back to ldap */
727 $ldap->cd($this->dn);
728 $this->cleanup();
729 $ldap->$mode($this->attrs);
731 $ret= 0;
732 if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
733 $ret= 1;
734 }
736 /* Remove uid lock */
737 del_lock ("uidnumber");
739 /* Post that we've done*/
740 $this->handle_post_events($mode);
742 return ($ret);
743 }
745 function check()
746 {
747 /* Call common method to give check the hook */
748 $message= plugin::check();
750 /* Permissions for that base? */
751 if ($this->base != ""){
752 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
753 } else {
754 $new_dn= $this->dn;
755 }
757 if ($this->orig_dn == "new" && !$this->acl_is_createable()){
758 $message[]= _("You have no permissions to create a group on this 'Base'.");
759 }
761 /* must: cn */
762 if ($this->cn == "" && $this->acl_is_writeable("cn")){
763 $message[]= "The required field 'Name' is not set.";
764 }
766 /* Check for valid input */
767 if (!is_uid($this->cn)){
768 $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
769 }
771 if($this->allowGroupsWithSameNameInOtherSubtrees == true){
773 /* Check for used 'cn' */
774 $ldap= $this->config->get_ldap_link();
775 if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
776 $ldap->cd("ou=groups,".$this->base);
777 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
778 if ($ldap->count() != 0){
779 $message[]= _("Value specified as 'Name' is already used.");
780 }
781 }
783 }else{
785 /* Check for used 'cn' */
786 $ldap= $this->config->get_ldap_link();
787 $ldap->cd($this->config->current['BASE']);
788 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
789 if ($ldap->count() != 0){
791 /* New entry? */
792 if ($this->dn == 'new'){
793 $message[]= _("Value specified as 'Name' is already used.");
794 }
796 /* Moved? */
797 elseif ($new_dn != $this->orig_dn){
798 $ldap->fetch();
799 if ($ldap->getDN() != $this->orig_dn){
800 $message[]= _("Value specified as 'Name' is already used.");
801 }
802 }
803 }
804 }
806 /* Check ID */
807 if ($this->force_gid == "1"){
808 if (!is_id($this->gidNumber)){
809 $message[]= _("Value specified as 'GID' is not valid.");
810 } else {
811 if ($this->gidNumber < $this->config->current['MINID']){
812 $message[]= _("Value specified as 'GID' is too small.");
813 }
815 }
816 }
818 return ($message);
819 }
821 function get_next_id($attrib)
822 {
823 $ids= array();
824 $ldap= $this->config->get_ldap_link();
826 $ldap->cd ($this->config->current['BASE']);
827 if (preg_match('/gidNumber/i', $attrib)){
828 $oc= "posixGroup";
829 } else {
830 $oc= "posixAccount";
831 }
832 $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
834 /* Get list of ids */
835 while ($attrs= $ldap->fetch()){
836 $ids[]= (int)$attrs["$attrib"][0];
837 }
839 /* Find out next free id near to UID_BASE */
840 for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
841 if (!in_array($id, $ids)){
842 return ($id);
843 }
844 }
846 /* Should not happen */
847 if ($id == 65000){
848 print_red(_("Too many users, can't allocate a free ID!"));
849 exit;
850 }
851 }
853 function getCopyDialog()
854 {
855 $vars = array("cn");
857 if($this ->force_gid){
858 $used = " checked ";
859 $dis = "";
860 }else{
861 $used = "";
862 $dis = " disabled ";
863 }
865 $smarty = get_smarty();
866 $smarty->assign("used",$used);
867 $smarty->assign("dis" ,$dis);
868 $smarty->assign("cn" ,$this->cn);
869 $smarty->assign("gidNumber",$this->gidNumber);
870 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
871 $ret = array();
872 $ret['string'] = $str;
873 $ret['status'] = "";
874 return($ret);
875 }
877 function saveCopyDialog()
878 {
879 if(isset($_POST['cn'])){
880 $this->cn = $_POST['cn'];
881 }
882 if(isset($_POST['force_gid'])){
883 $this->force_gid = 1;
884 $this->gidNumber= $_POST['gidNumber'];
885 }else{
886 $this->force_gid = 0;
887 $this->gidNumber = false;
888 }
889 }
892 /* Return plugin informations for acl handling */
893 function plInfo()
894 {
895 return (array(
896 "plShortName" => _("Generic"),
897 "plDescription" => _("Generic group settings"),
898 "plSelfModify" => FALSE,
899 "plDepends" => array(),
900 "plPriority" => 0,
901 "plSection" => array("admin"),
902 "plCategory" => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
904 "plProvidedAcls" => array(
905 "cn" => _("Name"),
906 "base" => _("Base"),
907 "description" => _("Description"),
909 "fonGroup" => _("Phone pickup group"),
910 "nagiosGroup" => _("Nagios group"),
912 "gidNumber" => _("GID"),
913 "memberUid" => _("Group member"),
914 "sambaGroupType" => _("Samba group type"),
915 "sambaDomainName" => _("Samba domain name"),
916 "sambaSID" => _("Samba SID"))
917 ));
918 }
919 }
921 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
922 ?>