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 /* Only display bases that we are able to read/write */
209 $ui = get_userinfo();
210 $bases = array();
211 if($this->dn == "new") {
212 foreach($this->config->idepartments as $dn => $name){
213 $acl = $ui->get_permissions($dn,"groups/group") ;
214 if(preg_match("/c/",$acl)){
215 $bases[$dn]=$name;
216 }
217 }
218 }else{
219 foreach($this->config->idepartments as $dn => $name){
220 $acl = $ui->get_category_permissions($dn,"groups") ;
221 if(preg_match("/w/",$acl)){
222 $bases[$dn]=$name;
223 }
224 }
225 }
228 /* Base select dialog */
229 $once = true;
230 foreach($_POST as $name => $value){
231 if(preg_match("/^chooseBase/",$name) && $once){
232 $once = false;
233 $this->dialog = new baseSelectDialog($this->config,$this,$bases);
234 $this->dialog->setCurrentBase($this->base);
235 }
236 }
238 /* Dialog handling */
239 if(is_object($this->dialog)){
240 /* Must be called before save_object */
241 $this->dialog->save_object();
243 if($this->dialog->isClosed()){
244 $this->dialog = false;
245 }elseif($this->dialog->isSelected()){
246 $this->base = $this->dialog->isSelected();
247 $this->dialog= false;
248 }else{
249 return($this->dialog->execute());
250 }
251 }
253 /* Assign templating stuff */
254 $smarty= get_smarty();
255 if ($this->samba3){
256 $smarty->assign("samba3", "true");
257 } else {
258 $smarty->assign("samba3", "");
259 }
261 if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
262 $smarty->assign("nagios",true);
263 }else{
264 $smarty->assign("nagios",false);
265 }
267 if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
268 $smarty->assign("pickupGroup",true);
269 }else{
270 $smarty->assign("pickupGroup",false);
271 }
273 /* Manage object add dialog */
274 if ($this->group_dialog){
276 /* Save data */
277 $gufilter= get_global("gufilter");
278 foreach( array("dselect", "regex") as $type){
279 if (isset($_POST[$type])){
280 $gufilter[$type]= $_POST[$type];
281 }
282 }
283 if(isset($_POST['regex'])){
284 if(isset($_POST['SubSearchGroup'])){
285 $gufilter['SubSearchGroup'] = true;
286 }else{
287 $gufilter['SubSearchGroup'] = false;
288 }
289 }
291 if (isset($_GET['search'])){
292 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
293 if ($s == "**"){
294 $s= "*";
295 }
296 $gufilter['regex']= $s;
297 }
298 register_global("gufilter", $gufilter);
299 $this->reload();
301 /* Show dialog */
302 $smarty->assign("search_image", get_template_path('images/search.png'));
303 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
304 $smarty->assign("tree_image", get_template_path('images/tree.png'));
306 /* Generate list of bases */
307 $check = $ui->get_module_departments("users");
308 $bases_user_select = array();
309 foreach($check as $dn_allowed){
310 $bases_user_select[$dn_allowed] = $this->config->idepartments[$dn_allowed];
311 }
313 $smarty->assign("deplist", $bases_user_select);
314 $smarty->assign("alphabet", generate_alphabet());
315 foreach( array("dselect", "regex","SubSearchGroup") as $type){
316 $smarty->assign("$type", $gufilter[$type]);
317 }
318 $smarty->assign("hint", print_sizelimit_warning());
319 $smarty->assign("users", $this->displayUsers);
320 $smarty->assign("apply", apply_filter());
321 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
322 return ($display);
323 }
325 /* Bases / Departments */
326 if (isset($_POST['base'])){
327 $this->base= $_POST['base'];
328 }
330 $smarty->assign("bases", $bases);
331 $smarty->assign("base_select", $this->base);
333 if ($this->samba3){
334 $domains= array();
335 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
336 $domains[$name]= $name;
337 }
338 $smarty->assign("sambaDomains", $domains);
339 $smarty->assign("sambaDomainName", $this->sambaDomainName);
340 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
341 514 => _("Domain guests"));
343 /* Don't loose special groups! If not key'ed above, add it to
344 the combo box... */
345 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
346 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
347 }
349 $smarty->assign("groupTypes", $groupTypes);
350 $smarty->assign("groupType", $this->groupType);
351 }
353 /* Members and users */
354 $smarty->assign("members", $this->members);
356 /* Checkboxes */
357 foreach (array("force_gid", "smbgroup") as $val){
358 if ($this->$val == "1"){
359 $smarty->assign("$val", "checked");
360 } else {
361 $smarty->assign("$val", "");
362 }
363 }
364 if ($this->force_gid != "1"){
365 $smarty->assign("forceMode", "disabled");
366 }else{
367 $smarty->assign("forceMode", "");
368 }
369 if ($this->fon_group){
370 $smarty->assign("fon_group", "checked");
371 } else {
372 $smarty->assign("fon_group", "");
373 }
375 if ($this->nagios_group){
376 $smarty->assign("nagios_group", "checked");
377 } else {
378 $smarty->assign("nagios_group", "");
379 }
381 /* Fields */
382 foreach (array("cn", "description", "gidNumber") as $val){
383 $smarty->assign("$val", $this->$val);
384 }
386 $tmp = $this->plInfo();
387 foreach($tmp['plProvidedAcls'] as $name => $translation){
388 $smarty->assign($name."ACL",$this->getacl($name));
389 }
391 if($this->acl_is_writeable("base")){
392 $smarty->assign("baseSelect",true);
393 }else{
394 $smarty->assign("baseSelect",false);
395 }
397 /* Show main page */
398 $smarty->assign("alphabet", generate_alphabet(10));
399 $smarty->assign("search_image", get_template_path('images/search.png'));
400 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
401 $smarty->assign("tree_image", get_template_path('images/tree.png'));
402 $smarty->assign("deplist", $this->config->idepartments);
403 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
404 }
406 function addUser($uid)
407 {
408 $this->memberUid[]= $uid;
409 $this->memberUid= array_unique($this->memberUid);
410 }
412 function removeUser($uid)
413 {
414 $temp= array();
415 foreach ($this->memberUid as $value){
416 if ($value != $uid){
417 $temp[]= $value;
418 }
419 }
420 $this->memberUid= $temp;
421 }
424 /* Reload data */
425 function reload()
426 {
427 /* Fix regex string */
428 $gufilter = get_global("gufilter");
429 $regex = normalizeLdap($gufilter['regex']);
430 $MaxUser = $this->OnlyShowFirstEntries;
432 /* Prepare ldap link */
433 $ldap= $this->config->get_ldap_link();
434 $ldap->cd($gufilter['dselect']);
437 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
438 (Store gathered sn/givenName informations in $this->allusers too,
439 to be prepared when adding/deleting users)
440 */
441 $filter = "";
442 foreach ($this->memberUid as $value){
443 if(!isset($this->members[$value])){
444 $filter .= "(uid=".normalizeLdap($value).")";
445 }
446 }
447 if(!empty($filter)){
448 $ldap->cd($this->config->current['BASE']);
449 $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
450 while($attrs = $ldap->fetch()){
451 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
452 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
453 }
454 }
456 /* check if all uids are resolved */
457 foreach ($this->memberUid as $value){
458 if(!isset($this->members[$value])){
459 $this->members[$value] = _("! unknown id")." [".$value."]";
460 }
461 }
463 /* Create display list of users matching regex & filter
464 */
465 $this->displayUsers = array();
466 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
468 /* Search in current tree or within subtrees depending on the checkbox from filter section */
469 if($gufilter['SubSearchGroup']){
470 $flag = GL_SIZELIMIT | GL_SUBSEARCH;
471 $base = $gufilter['dselect'];
472 }else{
473 $flag = GL_SIZELIMIT ;
474 $base = get_people_ou().$gufilter['dselect'];
475 }
476 $i = 0;
479 $res = get_list($filter,"users",$base,array("uid", "sn", "givenName"),$flag);
481 /* Fetch all users and skip already used users */
482 foreach($res as $attrs){
483 if(in_array($attrs['uid'][0], $this->memberUid)) {
484 continue;
485 }
486 $i ++;
487 if($i > $MaxUser) {
488 break;
489 }
490 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
491 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
492 }
494 /* If more than max users are found, display a message to warn the user */
495 if(($i == $MaxUser)){
496 print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
497 }
499 /* Sort lists */
500 natcasesort($this->members);
501 reset($this->members);
502 natcasesort ($this->displayUsers);
503 reset ($this->displayUsers);
504 }
507 /* Create display name, this was used so often that it is excluded into a seperate function */
508 function createResultName($attrs)
509 {
510 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
511 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
512 } else {
513 $ret= $attrs['uid'][0];
514 }
515 return($ret);
516 }
519 function remove_from_parent()
520 {
521 plugin::remove_from_parent();
523 $ldap= $this->config->get_ldap_link();
524 $ldap->rmdir($this->dn);
525 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
527 /* Delete references to object groups */
528 $ldap->cd ($this->config->current['BASE']);
529 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
530 while ($ldap->fetch()){
531 $og= new ogroup($this->config, $ldap->getDN());
532 unset($og->member[$this->dn]);
533 $og->save ();
534 }
536 /* Send signal to the world that we've done */
537 $this->handle_post_events("remove");
538 }
541 /* Save data to object */
542 function save_object()
543 {
544 /* Save additional values for possible next step */
545 if (isset($_POST['groupedit'])){
547 plugin::save_object();
549 $this->force_gid= 0;
552 /* Only reset sambagroup flag if we are able to write this flag */
553 if($this->acl_is_writeable("sambaGroupType")){
554 $this->smbgroup = 0;
555 }
557 foreach (array(
558 "force_gid" => "gidNumber",
559 "base" => "base",
560 "smbgroup" => "sambaGroupType") as $val => $aclname) {
561 if ($this->acl_is_writeable($aclname) && isset($_POST["$val"])){
562 $this->$val= $_POST["$val"];
563 }
564 }
566 /* Save sambaDomain attribute */
567 if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
568 $this->sambaDomainName= $_POST['sambaDomainName'];
569 $this->groupType= $_POST['groupType'];
570 }
572 /* Save fon attribute */
573 if ($this->acl_is_writeable("fon_group")){
574 if (isset ($_POST['fon_group'])){
575 $this->fon_group= TRUE;
576 } else {
577 $this->fon_group= FALSE;
578 }
579 }
580 if ($this->acl_is_writeable("nagios_group")){
581 if (isset ($_POST['nagios_group'])){
582 $this->nagios_group= TRUE;
583 } else {
584 $this->nagios_group= FALSE;
585 }
586 }
587 }
588 }
591 /* Save to LDAP */
592 function save()
593 {
595 /* ID handling */
596 if ($this->force_gid == 0){
597 if ($this->saved_gidNumber != ""){
598 $this->gidNumber= $this->saved_gidNumber;
599 } else {
600 /* Calculate new, lock uids */
601 $wait= 10;
602 while (get_lock("uidnumber") != ""){
603 sleep (1);
605 /* timed out? */
606 if ($wait-- == 0){
607 break;
608 }
609 }
610 add_lock ("uidnumber", "gosa");
611 $this->gidNumber= $this->get_next_id("gidNumber");
612 }
613 }
615 plugin::save();
617 /* Remove objectClass for samba/phone support */
618 $tmp= array();
619 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
620 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
621 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
622 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
623 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
624 $tmp[]= $this->attrs['objectClass'][$i];
625 }
626 }
627 $this->attrs['objectClass']= $tmp;
628 $ldap= $this->config->get_ldap_link();
630 /* Add samba group functionality */
631 if ($this->samba3 && $this->smbgroup){
633 /* Fixed undefined index ...
634 */
635 $this->SID = $this->ridBase = "";
636 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
637 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
638 }else{
639 print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
640 }
641 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
642 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
643 }else{
644 print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
645 }
647 $this->attrs['objectClass'][]= 'sambaGroupMapping';
648 $this->attrs['sambaGroupType']= "2";
650 /* Check if we need to create a special entry */
651 if ($this->groupType == 0){
653 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
654 $gidNumber= $this->gidNumber;
655 while(TRUE){
656 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
657 $ldap->cd($this->config->current['BASE']);
658 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
659 if ($ldap->count() == 0){
660 break;
661 }
662 $gidNumber++;
663 }
664 $this->attrs['sambaSID']= $sid;
665 $this->sambaSID= $sid;
666 }
668 } else {
669 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
670 }
672 /* User wants me to fake the idMappings? This is useful for
673 making winbind resolve the group names in a reasonable amount
674 of time in combination with larger databases. */
675 if (isset($this->config->current['SAMBAIDMAPPING']) &&
676 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
677 $this->attrs['objectClass'][]= "sambaIdmapEntry";
678 }
680 }
682 /* Add phone functionality */
683 if ($this->fon_group){
684 $this->attrs['objectClass'][]= "goFonPickupGroup";
685 }
687 /* Add nagios functionality */
688 if ($this->nagios_group){
689 $this->attrs['objectClass'][]= "nagiosContactGroup";
690 }
692 /* Take members array */
693 if (count ($this->memberUid)){
694 $this->attrs['memberUid']= array_unique($this->memberUid);
695 }
697 /* New accounts need proper 'dn', propagate it to remaining objects */
698 if ($this->dn == 'new'){
699 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
700 }
702 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
703 new entries. So do a check first... */
704 $ldap->cat ($this->dn, array('dn'));
705 if ($ldap->fetch()){
706 /* Modify needs array() to remove values :-( */
707 if (!count ($this->memberUid)){
708 $this->attrs['memberUid']= array();
709 }
710 if ($this->samba3){
711 if (!$this->smbgroup){
712 $this->attrs['sambaGroupType']= array();
713 $this->attrs['sambaSID']= array();
714 }
715 }
716 $mode= "modify";
717 } else {
718 $mode= "add";
719 $ldap->cd($this->config->current['BASE']);
720 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
721 }
723 /* Write back to ldap */
724 $ldap->cd($this->dn);
725 $this->cleanup();
726 $ldap->$mode($this->attrs);
728 $ret= 0;
729 if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
730 $ret= 1;
731 }
733 /* Remove uid lock */
734 del_lock ("uidnumber");
736 /* Post that we've done*/
737 $this->handle_post_events($mode);
739 return ($ret);
740 }
742 function check()
743 {
744 /* Call common method to give check the hook */
745 $message= plugin::check();
747 /* Permissions for that base? */
748 if ($this->base != ""){
749 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
750 } else {
751 $new_dn= $this->dn;
752 }
754 if ($this->orig_dn == "new" && !$this->acl_is_createable()){
755 $message[]= _("You have no permissions to create a group on this 'Base'.");
756 }
758 /* must: cn */
759 if ($this->cn == "" && $this->acl_is_writeable("cn")){
760 $message[]= "The required field 'Name' is not set.";
761 }
763 /* Check for valid input */
764 if (!is_uid($this->cn)){
765 $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
766 }
768 if($this->allowGroupsWithSameNameInOtherSubtrees == true){
770 /* Check for used 'cn' */
771 $ldap= $this->config->get_ldap_link();
772 if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
773 $ldap->cd("ou=groups,".$this->base);
774 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
775 if ($ldap->count() != 0){
776 $message[]= _("Value specified as 'Name' is already used.");
777 }
778 }
780 }else{
782 /* Check for used 'cn' */
783 $ldap= $this->config->get_ldap_link();
784 $ldap->cd($this->config->current['BASE']);
785 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
786 if ($ldap->count() != 0){
788 /* New entry? */
789 if ($this->dn == 'new'){
790 $message[]= _("Value specified as 'Name' is already used.");
791 }
793 /* Moved? */
794 elseif ($new_dn != $this->orig_dn){
795 $ldap->fetch();
796 if ($ldap->getDN() != $this->orig_dn){
797 $message[]= _("Value specified as 'Name' is already used.");
798 }
799 }
800 }
801 }
803 /* Check ID */
804 if ($this->force_gid == "1"){
805 if (!is_id($this->gidNumber)){
806 $message[]= _("Value specified as 'GID' is not valid.");
807 } else {
808 if ($this->gidNumber < $this->config->current['MINID']){
809 $message[]= _("Value specified as 'GID' is too small.");
810 }
812 }
813 }
815 return ($message);
816 }
818 function get_next_id($attrib)
819 {
820 $ids= array();
821 $ldap= $this->config->get_ldap_link();
823 $ldap->cd ($this->config->current['BASE']);
824 if (preg_match('/gidNumber/i', $attrib)){
825 $oc= "posixGroup";
826 } else {
827 $oc= "posixAccount";
828 }
829 $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
831 /* Get list of ids */
832 while ($attrs= $ldap->fetch()){
833 $ids[]= (int)$attrs["$attrib"][0];
834 }
836 /* Find out next free id near to UID_BASE */
837 for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
838 if (!in_array($id, $ids)){
839 return ($id);
840 }
841 }
843 /* Should not happen */
844 if ($id == 65000){
845 print_red(_("Too many users, can't allocate a free ID!"));
846 exit;
847 }
848 }
850 function getCopyDialog()
851 {
852 $vars = array("cn");
854 if($this ->force_gid){
855 $used = " checked ";
856 $dis = "";
857 }else{
858 $used = "";
859 $dis = " disabled ";
860 }
862 $smarty = get_smarty();
863 $smarty->assign("used",$used);
864 $smarty->assign("dis" ,$dis);
865 $smarty->assign("cn" ,$this->cn);
866 $smarty->assign("gidNumber",$this->gidNumber);
867 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
868 $ret = array();
869 $ret['string'] = $str;
870 $ret['status'] = "";
871 return($ret);
872 }
874 function saveCopyDialog()
875 {
876 if(isset($_POST['cn'])){
877 $this->cn = $_POST['cn'];
878 }
879 if(isset($_POST['force_gid'])){
880 $this->force_gid = 1;
881 $this->gidNumber= $_POST['gidNumber'];
882 }else{
883 $this->force_gid = 0;
884 $this->gidNumber = false;
885 }
886 }
889 /* Return plugin informations for acl handling */
890 function plInfo()
891 {
892 return (array(
893 "plShortName" => _("Generic"),
894 "plDescription" => _("Generic group settings"),
895 "plSelfModify" => FALSE,
896 "plDepends" => array(),
897 "plPriority" => 0,
898 "plSection" => array("admin"),
899 "plCategory" => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
901 "plProvidedAcls" => array(
902 "cn" => _("Name"),
903 "description" => _("Description"),
904 "base" => _("Base"),
906 "fonGroup" => _("Phone pickup group"),
907 "nagiosGroup" => _("Nagios group"),
909 "gidNumber" => _("GID"),
910 "memberUid" => _("Group member"),
911 "sambaGroupType" => _("Samba group type"),
912 "sambaDomainName" => _("Samba domain name"),
913 "sambaSID" => _("Samba SID"))
914 ));
915 }
916 }
918 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
919 ?>