Code

0c3310eb807e83fa4ddc954ecd91717fc43573da
[gosa.git] / plugins / admin / groups / class_groupGeneric.inc
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 $department= "";
31   var $saved_gidNumber= "";
32   var $oldgroupType= "";
33   var $orig_dn= "";
34   var $orig_cn= "";
35   var $has_mailAccount= FALSE;
36   var $group_dialog= FALSE;
37   var $nagios_group =FALSE;
38   var $sambaGroupType;
39   var $dialog;
40   var $OnlyShowFirstEntries =200;
42   var $allowGroupsWithSameNameInOtherSubtrees = true;
44   /* attribute list for save action */
45   var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
46   var $objectclasses= array("top", "posixGroup");
48   function group ($config, $dn= NULL)
49   {
50     plugin::plugin ($config, $dn);
52     /* Load attributes depending on the samba version */
53     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
54     $this->orig_dn= $dn;
55     $this->orig_cn= $this->cn;
57     /* Get member list */
58     if (isset($this->attrs['memberUid'][0])){
59       $tmp= array();
60       for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
61         $tmp[]= $this->attrs['memberUid'][$i];
62       }
63       $this->memberUid= $tmp;
64       sort ($this->memberUid);
65     }
67     /* Save gidNumber for later use */
68     if (isset($this->attrs['gidNumber'])){
69       $this->saved_gidNumber= $this->attrs['gidNumber'][0];
70     }
72     /* Is a samba group? */
73     if (isset($this->attrs['objectClass'])){
74       if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
75         $this->smbgroup= FALSE;
76       } else {
77         $this->smbgroup= TRUE;
78         if (isset($this->attrs['sambaSID'])){
79           $this->sambaSID= $this->attrs['sambaSID'][0];
80         }
81       }
82       if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
83         $this->fon_group= FALSE;
84       } else {
85         $this->fon_group= TRUE;
86       }
87       if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
88         $this->nagios_group= FALSE;
89       } else {
90         $this->nagios_group= TRUE;
91       }
92     }
94     /* Set mail flag */
95     if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
96       $this->has_mailAccount= TRUE;
97     }
99     /* Get samba Domain in case of samba 3 */
100     if ($this->samba3 && $this->sambaSID != ""){
101       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
102       $ldap= $this->config->get_ldap_link();
103       $ldap->cd($this->config->current['BASE']);
104       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
105       if ($ldap->count() != 0){
106         $attrs= $ldap->fetch();
107         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
109         /* Get domain name for SID */
110         $this->sambaDomainName= "DEFAULT";
111         foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
112           if ($val['SID'] == $this->SID){
113             $this->sambaDomainName= $key;
114             break;
115           }
116         }
117       } else {
118         if (isset($this->config->current['RIDBASE'])){
119           $this->sambaDomainName= "DEFAULT";
120           $this->ridBase= $this->config->current['RIDBASE'];
121           $this->SID= $this->config->current['SID'];
122         } else {
123           print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
124         }
125       }
127       /* Get group type */
128       $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
129       if ($this->groupType < 500 || $this->groupType > 553){
130         $this->groupType= 0;
131       }
132       $this->oldgroupType= $this->groupType;
133     }
135     /* Get global filter config */
136     if (!is_global("gufilter")){
137       $ui= get_userinfo();
138       $base= get_base_from_people($ui->dn);
139       $gufilter= array( "dselect"       => $base,
140           "regex"           => "*");
141       register_global("gufilter", $gufilter);
142     }
143     $gufilter= get_global('gufilter');
145     $gufilter['SubSearchGroup'] = false;
146     $gufilter['dselect'] = $_SESSION['gufilter']['dselect'];  
148     register_global('gufilter',$gufilter);
149   
150     if ($this->dn == "new"){
151       if(isset($_SESSION['CurrentMainBase'])){
152         $this->base= $_SESSION['CurrentMainBase'];
153       }else{
154         $ui= get_userinfo();
155         $this->base= dn2base($ui->dn);
156       }
157     } else {
158       $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
159     }
161     /* This is always an account */
162     $this->is_account= TRUE;
163     $this->reload();
164   }
166   function execute()
167   {
168         /* Call parent execute */
169         plugin::execute();
171   $ui= get_userinfo();
172   $acla= get_permissions ($ui->dn, $ui->subtreeACL);
173   $this->acl= get_module_permission($acla, "group", $ui->dn);
174   /* Do we represent a valid group? */
175     if (!$this->is_account && $this->parent == NULL){
176       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
177         _("This 'dn' is no group.")."</b>";
178       return ($display);
179     }
181     /* Delete user from group */
182     if (isset($_POST['del_users']) && isset($_POST['members'])){
183       foreach ($_POST['members'] as $value){
184         unset ($this->members["$value"]);
185         $this->removeUser($value);
186       }
187       $this->reload();
188     }
190     /* Add objects? */
191     if (isset($_POST["edit_membership"])){
192       $this->group_dialog= TRUE;
193       $this->dialog= TRUE;
194     }
196     /* Add objects finished? */
197     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
198       $this->group_dialog= FALSE;
199       $this->dialog= FALSE;
200     }
202     /* Add user to group */
203     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
204       foreach ($_POST['users'] as $value){
205         $this->members["$value"]= $this->allusers[$value];
206         asort($this->members);
207         $this->addUser($value);
208       }
209       $this->reload();
210     }
212     /* Base select dialog */
213     $once = true;
214     foreach($_POST as $name => $value){
215       if(preg_match("/^chooseBase/",$name) && $once){
216         $once = false;
217         $this->dialog = new baseSelectDialog($this->config);
218         $this->dialog->setCurrentBase($this->base);
219       }
220     }
222     /* Dialog handling */
223     if(is_object($this->dialog)){
224       /* Must be called before save_object */
225       $this->dialog->save_object();
227       if($this->dialog->isClosed()){
228         $this->dialog = false;
229       }elseif($this->dialog->isSelected()){
230         $this->base = $this->dialog->isSelected();
231         $this->dialog= false;
232       }else{
233         return($this->dialog->execute());
234       }
235     }
237    /* Assign templating stuff */
238     $smarty= get_smarty();
239     if ($this->samba3){
240       $smarty->assign("samba3", "true");
241     } else {
242       $smarty->assign("samba3", "");
243     }
245     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
246       $smarty->assign("nagios",true);
247     }else{
248       $smarty->assign("nagios",false);
249     }
250     
251     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
252       $smarty->assign("pickupGroup",true);
253     }else{
254       $smarty->assign("pickupGroup",false);
255     }
257     /* Manage object add dialog */
258     if ($this->group_dialog){
260       /* Save data */
261       $gufilter= get_global("gufilter");
262       foreach( array("dselect", "regex") as $type){
263         if (isset($_POST[$type])){
264           $gufilter[$type]= $_POST[$type];
265         }
266       }
267       if(isset($_POST['regex'])){
268         if(isset($_POST['SubSearchGroup'])){
269           $gufilter['SubSearchGroup'] = true;
270         }else{
271           $gufilter['SubSearchGroup'] = false;
272         }
273       }
275       if (isset($_GET['search'])){
276         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
277         if ($s == "**"){
278           $s= "*";
279         }
280         $gufilter['regex']= $s;
281       }
282       register_global("gufilter", $gufilter);
283       $this->reload();
285       /* Show dialog */
286       $smarty->assign("search_image", get_template_path('images/search.png'));
287       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
288       $smarty->assign("tree_image", get_template_path('images/tree.png'));
289       $smarty->assign("deplist", $this->config->idepartments);
290       $smarty->assign("alphabet", generate_alphabet());
291       foreach( array("dselect", "regex","SubSearchGroup") as $type){
292         $smarty->assign("$type", $gufilter[$type]);
293       }
294       $smarty->assign("hint", print_sizelimit_warning());
295       $smarty->assign("users", $this->displayUsers);
296       $smarty->assign("apply", apply_filter());
297       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
298       return ($display);
299     }
301     /* Bases / Departments */
302     if (isset($_POST['base'])){
303       $this->base= $_POST['base'];
304     }
306     $smarty->assign("bases", $this->config->idepartments);
307     $smarty->assign("base_select", $this->base);
308     $smarty->assign("department", $this->department);
310     if ($this->samba3){
311       $domains= array();
312       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
313         $domains[$name]= $name;
314       }
315       $smarty->assign("sambaDomains", $domains);
316       $smarty->assign("sambaDomainName", $this->sambaDomainName);
317       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
318           514 => _("Domain guests"));
320       /* Don't loose special groups! If not key'ed above, add it to
321          the combo box... */    
322       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
323         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
324       }
326       $smarty->assign("groupTypes", $groupTypes);
327       $smarty->assign("groupType", $this->groupType);
328     }
330     /* Members and users */
331     $smarty->assign("members", $this->members);
333     /* Checkboxes */
334     foreach (array("force_gid", "smbgroup") as $val){
335       if ($this->$val == "1"){
336         $smarty->assign("$val", "checked");
337       } else {
338         $smarty->assign("$val", "");
339       }
340     }
341     if ($this->force_gid != "1"){
342       $smarty->assign("forceMode", "disabled");
343     }else{
344       $smarty->assign("forceMode", "");
345     }
346     $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
347     $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
348     if ($this->fon_group){
349       $smarty->assign("fon_group", "checked");
350     } else {
351       $smarty->assign("fon_group", "");
352     }
353     $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
355     if ($this->nagios_group){
356       $smarty->assign("nagios_group", "checked");
357     } else {
358       $smarty->assign("nagios_group", "");
359     }
360     $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
362     /* Fields */
363     foreach (array("cn", "description", "gidNumber") as $val){
364       $smarty->assign("$val", $this->$val);
365       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
366     }
368     /* Missing ACL's */
369     foreach (array("base", "smbgroup", "members") as $val){
370       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
371     }
373     /* Show main page */
374     $smarty->assign("alphabet", generate_alphabet(10));
375     $smarty->assign("search_image", get_template_path('images/search.png'));
376     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
377     $smarty->assign("tree_image", get_template_path('images/tree.png'));
378     $smarty->assign("deplist", $this->config->idepartments);
379     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
380   }
382   function addUser($uid)
383   {
384     $this->memberUid[]= $uid;
385     $this->memberUid= array_unique($this->memberUid);
386   }
388   function removeUser($uid)
389   {
390     $temp= array();
391     foreach ($this->memberUid as $value){
392       if ($value != $uid){
393         $temp[]= $value;
394       }
395     }
396     $this->memberUid= $temp;
397   }
400   /* Reload data */
401   function reload()
402   {
403     /* Fix regex string */
404     $gufilter = get_global("gufilter");
405     $regex    = normalizeLdap($gufilter['regex']);
406     $MaxUser  = $this->OnlyShowFirstEntries;
408     /* Prepare ldap link */
409     $ldap= $this->config->get_ldap_link();
410     $ldap->cd($gufilter['dselect']);
413     /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes 
414         (Store gathered sn/givenName informations in $this->allusers too, 
415          to be prepared when adding/deleting users)
416      */    
417     $filter = "";
418     foreach ($this->memberUid as $value){
419       if(!isset($this->members[$value])){
420         $filter .= "(uid=".normalizeLdap($value).")";
421       }
422     }
423     if(!empty($filter)){    
424       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
425       while($attrs = $ldap->fetch()){
426         $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
427         $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
428       } 
429     }
430   
431     /* check if all uids are resolved */
432     foreach ($this->memberUid as $value){
433       if(!isset($this->members[$value])){
434         $this->members[$value] =  _("! unknown id")." [".$value."]"; 
435       }
436     }  
438     /* Create display list of users matching regex & filter 
439      */
440     $this->displayUsers = array();
441     $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
443     /* Search in current tree or within subtrees depending on the checkbox from filter section */
444     if($gufilter['SubSearchGroup']){
445       $ldap->search($filter, array("uid", "sn","givenName"));
446     }else{
447       $ldap->ls ($filter, get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
448     }
449     $i = 0;
450     
451     /* Fetch all users and skip already used users */
452     while($attrs = $ldap->fetch()){
453       if(in_array($attrs['uid'][0], $this->memberUid)) {
454         continue;
455       }
456       $i ++;
457       if($i > $MaxUser) {
458         break;
459       }
460       $this->allusers[$attrs['uid'][0]]     = $this->createResultName($attrs);
461       $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
462     }
463   
464     /* If more than max users are found, display a message to warn the user */
465     if(($i == $MaxUser)){
466       print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
467     }
468     
469     /* Sort lists */
470     natcasesort($this->members);
471     reset($this->members);
472     natcasesort ($this->displayUsers);
473     reset ($this->displayUsers);
474   }
477   /* Create display name, this was used so often that it is excluded into a seperate function */
478   function createResultName($attrs)
479   {
480     if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
481       $ret =  $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
482     } else {
483       $ret= $attrs['uid'][0];
484     }
485     return($ret);
486   }
489   function remove_from_parent()
490   {
491     plugin::remove_from_parent();
493     $ldap= $this->config->get_ldap_link();
494     $ldap->rmdir($this->dn);
495     show_ldap_error($ldap->get_error(), _("Removing group failed"));
497     /* Delete references to object groups */
498     $ldap->cd ($this->config->current['BASE']);
499     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
500     while ($ldap->fetch()){
501       $og= new ogroup($this->config, $ldap->getDN());
502       unset($og->member[$this->dn]);
503       $og->save ();
504     }
506     /* Send signal to the world that we've done */
507     $this->handle_post_events("remove");
508   }
511   /* Save data to object */
512   function save_object()
513   {
514     /* Save additional values for possible next step */
515     if (isset($_POST['groupedit'])){
517       plugin::save_object();
519       $this->force_gid= 0;
520       $this->smbgroup= 0;
521       foreach (array("force_gid", "department", "base", "smbgroup") as $val) {
522         if (chkacl ($this->acl, "$val") == "" && isset($_POST["$val"])){
523           $this->$val= $_POST["$val"];
524         }
525       }
527       /* Save sambaDomain attribute */
528       if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
529           isset ($_POST['sambaDomainName'])){
531         $this->sambaDomainName= $_POST['sambaDomainName'];
532         $this->groupType= $_POST['groupType'];
533       }
535       /* Save fon attribute */
536       if (chkacl ($this->acl, "fon_group") == ""){
537         if (isset ($_POST['fon_group'])){
538           $this->fon_group= TRUE;
539         } else {
540           $this->fon_group= FALSE;
541         }
542       }
543          if (chkacl ($this->acl, "nagios_group") == ""){
544         if (isset ($_POST['nagios_group'])){
545           $this->nagios_group= TRUE;
546         } else {
547           $this->nagios_group= FALSE;
548         }
549       }
550     }
551   }
554   /* Save to LDAP */
555   function save()
556   {
558     /* ID handling */
559     if ($this->force_gid == 0){
560       if ($this->saved_gidNumber != ""){
561         $this->gidNumber= $this->saved_gidNumber;
562       } else {
563         /* Calculate new, lock uids */
564         $wait= 10;
565         while (get_lock("uidnumber") != ""){
566           sleep (1);
568           /* timed out? */
569           if ($wait-- == 0){
570             break;
571           }
572         }
573         add_lock ("uidnumber", "gosa");
574         $this->gidNumber= $this->get_next_id("gidNumber");
575       }
576     }
577   
578     plugin::save(); 
580     /* Remove objectClass for samba/phone support */
581     $tmp= array();
582     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
583       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
584           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
585           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
586          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
587         $tmp[]= $this->attrs['objectClass'][$i];
588       }
589     }
590     $this->attrs['objectClass']= $tmp;
591     $ldap= $this->config->get_ldap_link();
593     /* Add samba group functionality */
594     if ($this->samba3 && $this->smbgroup){
595   
596       /* Fixed undefined index ... 
597        */ 
598       $this->SID = $this->ridBase = "";
599       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
600         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
601       }else{
602         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
603       }
604       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
605         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
606       }else{
607         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
608       }
610       $this->attrs['objectClass'][]= 'sambaGroupMapping';
611       $this->attrs['sambaGroupType']= "2";
613       /* Check if we need to create a special entry */
614       if ($this->groupType == 0){
616         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
617           $gidNumber= $this->gidNumber;
618           while(TRUE){
619             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
620             $ldap->cd($this->config->current['BASE']);
621             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
622             if ($ldap->count() == 0){
623               break;
624             }
625             $gidNumber++;
626           }
627           $this->attrs['sambaSID']= $sid;
628           $this->sambaSID= $sid;
629         }
631       } else {
632         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
633       }
635       /* User wants me to fake the idMappings? This is useful for
636          making winbind resolve the group names in a reasonable amount
637          of time in combination with larger databases. */
638       if (isset($this->config->current['SAMBAIDMAPPING']) &&
639           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
640         $this->attrs['objectClass'][]= "sambaIdmapEntry";
641       }
643     }
645     /* Add phone functionality */
646     if ($this->fon_group){
647       $this->attrs['objectClass'][]= "goFonPickupGroup";
648     }
650     /* Add nagios functionality */
651     if ($this->nagios_group){
652         $this->attrs['objectClass'][]= "nagiosContactGroup";
653     }
655     /* Take members array */
656     if (count ($this->memberUid)){
657       $this->attrs['memberUid']= array_unique($this->memberUid);
658     }
660     /* New accounts need proper 'dn', propagate it to remaining objects */
661     if ($this->dn == 'new'){
662       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
663     }
665     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
666        new entries. So do a check first... */
667     $ldap->cat ($this->dn, array('dn'));
668     if ($ldap->fetch()){
669       /* Modify needs array() to remove values :-( */
670       if (!count ($this->memberUid)){
671         $this->attrs['memberUid']= array();
672       }
673       if ($this->samba3){
674         if (!$this->smbgroup){
675           $this->attrs['sambaGroupType']= array();
676           $this->attrs['sambaSID']= array();
677         }
678       }
679       $mode= "modify";
680     } else {
681       $mode= "add";
682       $ldap->cd($this->config->current['BASE']);
683       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
684     }
686     /* Write back to ldap */
687     $ldap->cd($this->dn);
688     $this->cleanup();
689     $ldap->$mode($this->attrs);
691     $ret= 0;
692     if (show_ldap_error($ldap->get_error(), _("Saving group failed"))){
693       $ret= 1;
694     }
696     /* Remove uid lock */
697     del_lock ("uidnumber");
699     /* Post that we've done*/
700     $this->handle_post_events($mode);
702     return ($ret);
703   }
705   function check()
706   {
707     /* Call common method to give check the hook */
708     $message= plugin::check();
710     /* Permissions for that base? */
711     if ($this->base != ""){
712       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
713     } else {
714       $new_dn= $this->dn;
715     }
717     $ui= get_userinfo();
718     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
719     $acl= get_module_permission($acl, "group", $ui->dn);
720     if (chkacl($this->acl, "create") != ""){
721       $message[]= _("You have no permissions to create a group on this 'Base'.");
722     }
724     /* must: cn */
725     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
726       $message[]= "The required field 'Name' is not set.";
727     }
729     /* Check for valid input */
730     if (!is_uid($this->cn)){
731       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
732     }
735     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
737       /* Check for used 'cn' */
738       $ldap= $this->config->get_ldap_link();
739       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
740         $ldap->cd("ou=groups,".$this->base);
741         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
742         if ($ldap->count() != 0){
743           $message[]= _("Value specified as 'Name' is already used.");
744         }
745       }
747     }else{
749       /* Check for used 'cn' */
750       $ldap= $this->config->get_ldap_link();
751       $ldap->cd($this->config->current['BASE']);
752       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
753       if ($ldap->count() != 0){
755         /* New entry? */
756         if ($this->dn == 'new'){
757           $message[]= _("Value specified as 'Name' is already used.");
758         }
760         /* Moved? */
761         elseif ($new_dn != $this->orig_dn){
762           $ldap->fetch();
763           if ($ldap->getDN() != $this->orig_dn){
764             $message[]= _("Value specified as 'Name' is already used.");
765           }
766         }
767       }
768     }
769      
770     /* Check ID */
771     if ($this->force_gid == "1"){
772       if (!is_id($this->gidNumber)){
773         $message[]= _("Value specified as 'GID' is not valid.");
774       } else {
775         if ($this->gidNumber < $this->config->current['MINID']){
776           $message[]= _("Value specified as 'GID' is too small.");
777         }
779       }
780     }
782     return ($message);
783   }
785   function get_next_id($attrib)
786   {
787     $ids= array();
788     $ldap= $this->config->get_ldap_link();
790     $ldap->cd ($this->config->current['BASE']);
791     if (preg_match('/gidNumber/i', $attrib)){
792       $oc= "posixGroup";
793     } else {
794       $oc= "posixAccount";
795     }
796     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
798     /* Get list of ids */
799     while ($attrs= $ldap->fetch()){
800       $ids[]= (int)$attrs["$attrib"][0];
801     }
803     /* Find out next free id near to UID_BASE */
804     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
805       if (!in_array($id, $ids)){
806         return ($id);
807       }
808     }
810     /* Should not happen */
811     if ($id == 65000){
812       print_red(_("Too many users, can't allocate a free ID!"));
813       exit;
814     }
815   }
817   function getCopyDialog()
818   {
819     $vars = array("cn");
820   
821     if($this ->force_gid){
822       $used = " checked ";
823       $dis  = "";
824     }else{
825       $used = "";
826       $dis  = " disabled ";
827     }
829     $smarty = get_smarty();
830     $smarty->assign("used",$used);
831     $smarty->assign("dis" ,$dis);
832     $smarty->assign("cn" ,$this->cn);
833     $smarty->assign("gidNumber",$this->gidNumber);
834     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
835     $ret = array();
836     $ret['string'] = $str;
837     $ret['status'] = "";
838     return($ret);
839   }
841   function saveCopyDialog()
842   {
843     if(isset($_POST['cn'])){
844       $this->cn = $_POST['cn'];
845     }
846     if(isset($_POST['force_gid'])){
847       $this->force_gid  = 1;
848       $this->gidNumber= $_POST['gidNumber'];
849     }else{
850       $this->force_gid  = 0;
851       $this->gidNumber  = false;
852     }
853   }
856 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
857 ?>