Code

61a63131439c63402c0361fbb53458343999457d
[gosa.git] / plugins / admin / groups / class_groupGeneric.inc
1 <?php
2 class group extends plugin
3 {
4   /* CLI vars */
5   var $cli_summary= "Handling of GOsa's base group object";
6   var $cli_description= "Some longer text\nfor help";
7   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* Group attributes */
10   var $cn= "";
11   var $description= "";
12   var $gidNumber= "";
13   var $memberUid= array();
15   /* Helpers */
16   var $base= "";
17   var $force_gid= FALSE;
18   var $fon_group= FALSE;
19   var $smbgroup= FALSE;
20   var $groupType= FALSE;
21   var $samba3= FALSE;
22   var $sambaSID= "";
23   var $sambaDomainName= "DEFAULT";
24   var $SID= "";
25   var $ridBase= 0;
26   var $members= array();
27   var $users= array();
28   var $allusers= array();
29   var $department= "";
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);
148   
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   $ui= get_userinfo();
171   $acla= get_permissions ($ui->dn, $ui->subtreeACL);
172   $this->acl= get_module_permission($acla, "group", $ui->dn);
173   /* Do we represent a valid group? */
174     if (!$this->is_account && $this->parent == NULL){
175       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
176         _("This 'dn' is no group.")."</b>";
177       return ($display);
178     }
180     /* Delete user from group */
181     if (isset($_POST['del_users']) && isset($_POST['members'])){
182       foreach ($_POST['members'] as $value){
183         unset ($this->members["$value"]);
184         $this->removeUser($value);
185       }
186       $this->reload();
187     }
189     /* Add objects? */
190     if (isset($_POST["edit_membership"])){
191       $this->group_dialog= TRUE;
192       $this->dialog= TRUE;
193     }
195     /* Add objects finished? */
196     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
197       $this->group_dialog= FALSE;
198       $this->dialog= FALSE;
199     }
201     /* Add user to group */
202     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
203       foreach ($_POST['users'] as $value){
204         $this->members["$value"]= $this->allusers[$value];
205         asort($this->members);
206         $this->addUser($value);
207       }
208       $this->reload();
209     }
211     /* Base select dialog */
212     $once = true;
213     foreach($_POST as $name => $value){
214       if(preg_match("/^chooseBase/",$name) && $once){
215         $once = false;
216         $this->dialog = new baseSelectDialog($this->config);
217         $this->dialog->setCurrentBase($this->base);
218       }
219     }
221     /* Dialog handling */
222     if(is_object($this->dialog)){
223       /* Must be called before save_object */
224       $this->dialog->save_object();
226       if($this->dialog->isClosed()){
227         $this->dialog = false;
228       }elseif($this->dialog->isSelected()){
229         $this->base = $this->dialog->isSelected();
230         $this->dialog= false;
231       }else{
232         return($this->dialog->execute());
233       }
234     }
236    /* Assign templating stuff */
237     $smarty= get_smarty();
238     if ($this->samba3){
239       $smarty->assign("samba3", "true");
240     } else {
241       $smarty->assign("samba3", "");
242     }
244     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
245       $smarty->assign("nagios",true);
246     }else{
247       $smarty->assign("nagios",false);
248     }
249     
250     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
251       $smarty->assign("pickupGroup",true);
252     }else{
253       $smarty->assign("pickupGroup",false);
254     }
256     /* Manage object add dialog */
257     if ($this->group_dialog){
259       /* Save data */
260       $gufilter= get_global("gufilter");
261       foreach( array("dselect", "regex") as $type){
262         if (isset($_POST[$type])){
263           $gufilter[$type]= $_POST[$type];
264         }
265       }
266       if(isset($_POST['regex'])){
267         if(isset($_POST['SubSearchGroup'])){
268           $gufilter['SubSearchGroup'] = true;
269         }else{
270           $gufilter['SubSearchGroup'] = false;
271         }
272       }
274       if (isset($_GET['search'])){
275         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
276         if ($s == "**"){
277           $s= "*";
278         }
279         $gufilter['regex']= $s;
280       }
281       register_global("gufilter", $gufilter);
282       $this->reload();
284       /* Show dialog */
285       $smarty->assign("search_image", get_template_path('images/search.png'));
286       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
287       $smarty->assign("tree_image", get_template_path('images/tree.png'));
288       $smarty->assign("deplist", $this->config->idepartments);
289       $smarty->assign("alphabet", generate_alphabet());
290       foreach( array("dselect", "regex","SubSearchGroup") as $type){
291         $smarty->assign("$type", $gufilter[$type]);
292       }
293       $smarty->assign("hint", print_sizelimit_warning());
294       $smarty->assign("users", $this->displayUsers);
295       $smarty->assign("apply", apply_filter());
296       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
297       return ($display);
298     }
300     /* Bases / Departments */
301     if (isset($_POST['base'])){
302       $this->base= $_POST['base'];
303     }
305     $smarty->assign("bases", $this->config->idepartments);
306     $smarty->assign("base_select", $this->base);
307     $smarty->assign("department", $this->department);
309     if ($this->samba3){
310       $domains= array();
311       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
312         $domains[$name]= $name;
313       }
314       $smarty->assign("sambaDomains", $domains);
315       $smarty->assign("sambaDomainName", $this->sambaDomainName);
316       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
317           514 => _("Domain guests"));
319       /* Don't loose special groups! If not key'ed above, add it to
320          the combo box... */    
321       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
322         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
323       }
325       $smarty->assign("groupTypes", $groupTypes);
326       $smarty->assign("groupType", $this->groupType);
327     }
329     /* Members and users */
330     $smarty->assign("members", $this->members);
332     /* Checkboxes */
333     foreach (array("force_gid", "smbgroup") as $val){
334       if ($this->$val == "1"){
335         $smarty->assign("$val", "checked");
336       } else {
337         $smarty->assign("$val", "");
338       }
339     }
340     if ($this->force_gid != "1"){
341       $smarty->assign("forceMode", "disabled");
342     }else{
343       $smarty->assign("forceMode", "");
344     }
345     $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
346     $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
347     if ($this->fon_group){
348       $smarty->assign("fon_group", "checked");
349     } else {
350       $smarty->assign("fon_group", "");
351     }
352     $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
354     if ($this->nagios_group){
355       $smarty->assign("nagios_group", "checked");
356     } else {
357       $smarty->assign("nagios_group", "");
358     }
359     $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
361     /* Fields */
362     foreach (array("cn", "description", "gidNumber") as $val){
363       $smarty->assign("$val", $this->$val);
364       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
365     }
367     /* Missing ACL's */
368     foreach (array("base", "smbgroup", "members") as $val){
369       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
370     }
372     /* Show main page */
373     $smarty->assign("alphabet", generate_alphabet(10));
374     $smarty->assign("search_image", get_template_path('images/search.png'));
375     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
376     $smarty->assign("tree_image", get_template_path('images/tree.png'));
377     $smarty->assign("deplist", $this->config->idepartments);
378     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
379   }
381   function addUser($uid)
382   {
383     $this->memberUid[]= $uid;
384     $this->memberUid= array_unique($this->memberUid);
385   }
387   function removeUser($uid)
388   {
389     $temp= array();
390     foreach ($this->memberUid as $value){
391       if ($value != $uid){
392         $temp[]= $value;
393       }
394     }
395     $this->memberUid= $temp;
396   }
399   /* Reload data */
400   function reload()
401   {
402     /* Fix regex string */
403     $gufilter = get_global("gufilter");
404     $regex    = normalizeLdap($gufilter['regex']);
405     $MaxUser  = $this->OnlyShowFirstEntries;
407     /* Prepare ldap link */
408     $ldap= $this->config->get_ldap_link();
409     $ldap->cd($gufilter['dselect']);
412     /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes 
413         (Store gathered sn/givenName informations in $this->allusers too, 
414          to be prepared when adding/deleting users)
415      */    
416     $filter = "";
417     foreach ($this->memberUid as $value){
418       if(!isset($this->members[$value])){
419         $filter .= "(uid=".normalizeLdap($value).")";
420       }
421     }
422     if(!empty($filter)){    
423       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
424       while($attrs = $ldap->fetch()){
425         $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
426         $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
427       } 
428     }
429   
430     /* check if all uids are resolved */
431     foreach ($this->memberUid as $value){
432       if(!isset($this->members[$value])){
433         $this->members[$value] =  _("! unknown id")." [".$value."]"; 
434       }
435     }  
437     /* Create display list of users matching regex & filter 
438      */
439     $this->displayUsers = array();
440     $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
442     /* Search in current tree or within subtrees depending on the checkbox from filter section */
443     if($gufilter['SubSearchGroup']){
444       $ldap->search($filter, array("uid", "sn","givenName"));
445     }else{
446       $ldap->ls ($filter, get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
447     }
448     $i = 0;
449     
450     /* Fetch all users and skip already used users */
451     while($attrs = $ldap->fetch()){
452       if(in_array($attrs['uid'][0], $this->memberUid)) {
453         continue;
454       }
455       $i ++;
456       if($i > $MaxUser) {
457         break;
458       }
459       $this->allusers[$attrs['uid'][0]]     = $this->createResultName($attrs);
460       $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
461     }
462   
463     /* If more than max users are found, display a message to warn the user */
464     if(($i == $MaxUser)){
465       print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
466     }
467     
468     /* Sort lists */
469     natcasesort($this->members);
470     reset($this->members);
471     natcasesort ($this->displayUsers);
472     reset ($this->displayUsers);
473   }
476   /* Create display name, this was used so often that it is excluded into a seperate function */
477   function createResultName($attrs)
478   {
479     if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
480       $ret =  $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
481     } else {
482       $ret= $attrs['uid'][0];
483     }
484     return($ret);
485   }
488   function remove_from_parent()
489   {
490     plugin::remove_from_parent();
492     $ldap= $this->config->get_ldap_link();
493     $ldap->rmdir($this->dn);
494     show_ldap_error($ldap->get_error());
496     /* Delete references to object groups */
497     $ldap->cd ($this->config->current['BASE']);
498     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
499     while ($ldap->fetch()){
500       $og= new ogroup($this->config, $ldap->getDN());
501       unset($og->member[$this->dn]);
502       $og->save ();
503     }
505     /* Send signal to the world that we've done */
506     $this->handle_post_events("remove");
507   }
510   /* Save data to object */
511   function save_object()
512   {
513     /* Save additional values for possible next step */
514     if (isset($_POST['groupedit'])){
516       plugin::save_object();
518       $this->force_gid= 0;
519       $this->smbgroup= 0;
520       foreach (array("force_gid", "department", "base", "smbgroup") as $val) {
521         if (chkacl ($this->acl, "$val") == "" && isset($_POST["$val"])){
522           $this->$val= $_POST["$val"];
523         }
524       }
526       /* Save sambaDomain attribute */
527       if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
528           isset ($_POST['sambaDomainName'])){
530         $this->sambaDomainName= $_POST['sambaDomainName'];
531         $this->groupType= $_POST['groupType'];
532       }
534       /* Save fon attribute */
535       if (chkacl ($this->acl, "fon_group") == ""){
536         if (isset ($_POST['fon_group'])){
537           $this->fon_group= TRUE;
538         } else {
539           $this->fon_group= FALSE;
540         }
541       }
542          if (chkacl ($this->acl, "nagios_group") == ""){
543         if (isset ($_POST['nagios_group'])){
544           $this->nagios_group= TRUE;
545         } else {
546           $this->nagios_group= FALSE;
547         }
548       }
549     }
550   }
553   /* Save to LDAP */
554   function save()
555   {
557     /* ID handling */
558     if ($this->force_gid == 0){
559       if ($this->saved_gidNumber != ""){
560         $this->gidNumber= $this->saved_gidNumber;
561       } else {
562         /* Calculate new, lock uids */
563         $wait= 10;
564         while (get_lock("uidnumber") != ""){
565           sleep (1);
567           /* timed out? */
568           if ($wait-- == 0){
569             break;
570           }
571         }
572         add_lock ("uidnumber", "gosa");
573         $this->gidNumber= $this->get_next_id("gidNumber");
574       }
575     }
576   
577     plugin::save(); 
579     /* Remove objectClass for samba/phone support */
580     $tmp= array();
581     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
582       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
583           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
584           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
585          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
586         $tmp[]= $this->attrs['objectClass'][$i];
587       }
588     }
589     $this->attrs['objectClass']= $tmp;
590     $ldap= $this->config->get_ldap_link();
592     /* Add samba group functionality */
593     if ($this->samba3 && $this->smbgroup){
594   
595       /* Fixed undefined index ... 
596        */ 
597       $this->SID = $this->ridBase = "";
598       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
599         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
600       }else{
601         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
602       }
603       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
604         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
605       }else{
606         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
607       }
609       $this->attrs['objectClass'][]= 'sambaGroupMapping';
610       $this->attrs['sambaGroupType']= "2";
612       /* Check if we need to create a special entry */
613       if ($this->groupType == 0){
615         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
616           $gidNumber= $this->gidNumber;
617           while(TRUE){
618             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
619             $ldap->cd($this->config->current['BASE']);
620             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
621             if ($ldap->count() == 0){
622               break;
623             }
624             $gidNumber++;
625           }
626           $this->attrs['sambaSID']= $sid;
627           $this->sambaSID= $sid;
628         }
630       } else {
631         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
632       }
634       /* User wants me to fake the idMappings? This is useful for
635          making winbind resolve the group names in a reasonable amount
636          of time in combination with larger databases. */
637       if (isset($this->config->current['SAMBAIDMAPPING']) &&
638           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
639         $this->attrs['objectClass'][]= "sambaIdmapEntry";
640       }
642     }
644     /* Add phone functionality */
645     if ($this->fon_group){
646       $this->attrs['objectClass'][]= "goFonPickupGroup";
647     }
649     /* Add nagios functionality */
650     if ($this->nagios_group){
651         $this->attrs['objectClass'][]= "nagiosContactGroup";
652     }
654     /* Take members array */
655     if (count ($this->memberUid)){
656       $this->attrs['memberUid']= array_unique($this->memberUid);
657     }
659     /* New accounts need proper 'dn', propagate it to remaining objects */
660     if ($this->dn == 'new'){
661       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
662     }
664     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
665        new entries. So do a check first... */
666     $ldap->cat ($this->dn);
667     if ($ldap->fetch()){
668       /* Modify needs array() to remove values :-( */
669       if (!count ($this->memberUid)){
670         $this->attrs['memberUid']= array();
671       }
672       if ($this->samba3){
673         if (!$this->smbgroup){
674           $this->attrs['sambaGroupType']= array();
675           $this->attrs['sambaSID']= array();
676         }
677       }
678       $mode= "modify";
679     } else {
680       $mode= "add";
681       $ldap->cd($this->config->current['BASE']);
682       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
683     }
685     /* Write back to ldap */
686     $ldap->cd($this->dn);
687     $this->cleanup();
688     $ldap->$mode($this->attrs);
690     $ret= 0;
691     if (show_ldap_error($ldap->get_error())){
692       $ret= 1;
693     }
695     /* Remove uid lock */
696     del_lock ("uidnumber");
698     /* Post that we've done*/
699     $this->handle_post_events($mode);
701     return ($ret);
702   }
704   function check()
705   {
706     /* Call common method to give check the hook */
707     $message= plugin::check();
709     /* Permissions for that base? */
710     if ($this->base != ""){
711       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
712     } else {
713       $new_dn= $this->dn;
714     }
716     $ui= get_userinfo();
717     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
718     $acl= get_module_permission($acl, "group", $ui->dn);
719     if (chkacl($this->acl, "create") != ""){
720       $message[]= _("You have no permissions to create a group on this 'Base'.");
721     }
723     /* must: cn */
724     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
725       $message[]= "The required field 'Name' is not set.";
726     }
728     /* Check for valid input */
729     if (!is_uid($this->cn)){
730       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
731     }
734     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
736       /* Check for used 'cn' */
737       $ldap= $this->config->get_ldap_link();
738       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
739         $ldap->cd("ou=groups,".$this->base);
740         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
741         if ($ldap->count() != 0){
742           $message[]= _("Value specified as 'Name' is already used.");
743         }
744       }
746     }else{
748       /* Check for used 'cn' */
749       $ldap= $this->config->get_ldap_link();
750       $ldap->cd($this->config->current['BASE']);
751       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
752       if ($ldap->count() != 0){
754         /* New entry? */
755         if ($this->dn == 'new'){
756           $message[]= _("Value specified as 'Name' is already used.");
757         }
759         /* Moved? */
760         elseif ($new_dn != $this->orig_dn){
761           $ldap->fetch();
762           if ($ldap->getDN() != $this->orig_dn){
763             $message[]= _("Value specified as 'Name' is already used.");
764           }
765         }
766       }
767     }
768      
769     /* Check ID */
770     if ($this->force_gid == "1"){
771       if (!is_id($this->gidNumber)){
772         $message[]= _("Value specified as 'GID' is not valid.");
773       } else {
774         if ($this->gidNumber < $this->config->current['MINID']){
775           $message[]= _("Value specified as 'GID' is too small.");
776         }
778       }
779     }
781     return ($message);
782   }
784   function get_next_id($attrib)
785   {
786     $ids= array();
787     $ldap= $this->config->get_ldap_link();
789     $ldap->cd ($this->config->current['BASE']);
790     if (preg_match('/gidNumber/i', $attrib)){
791       $oc= "posixGroup";
792     } else {
793       $oc= "posixAccount";
794     }
795     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
797     /* Get list of ids */
798     while ($attrs= $ldap->fetch()){
799       $ids[]= (int)$attrs["$attrib"][0];
800     }
802     /* Find out next free id near to UID_BASE */
803     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
804       if (!in_array($id, $ids)){
805         return ($id);
806       }
807     }
809     /* Should not happen */
810     if ($id == 65000){
811       print_red(_("Too many users, can't allocate a free ID!"));
812       exit;
813     }
814   }
816   function getCopyDialog()
817   {
818     $vars = array("cn");
819   
820     if($this ->force_gid){
821       $used = " checked ";
822       $dis  = "";
823     }else{
824       $used = "";
825       $dis  = " disabled ";
826     }
828     $smarty = get_smarty();
829     $smarty->assign("used",$used);
830     $smarty->assign("dis" ,$dis);
831     $smarty->assign("cn" ,$this->cn);
832     $smarty->assign("gidNumber",$this->gidNumber);
833     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
834     $ret = array();
835     $ret['string'] = $str;
836     $ret['status'] = "";
837     return($ret);
838   }
840   function saveCopyDialog()
841   {
842     if(isset($_POST['cn'])){
843       $this->cn = $_POST['cn'];
844     }
845     if(isset($_POST['force_gid'])){
846       $this->force_gid  = 1;
847       $this->gidNumber= $_POST['gidNumber'];
848     }else{
849       $this->force_gid  = 0;
850       $this->gidNumber  = false;
851     }
852   }
855 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
856 ?>