Code

Prepared group Generic & Template for new acls .... not tested & not complete
[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   /* Do we represent a valid group? */
172     if (!$this->is_account && $this->parent == NULL){
173       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
174         _("This 'dn' is no group.")."</b>";
175       return ($display);
176     }
178     /* Delete user from group */
179     if (isset($_POST['del_users']) && isset($_POST['members'])){
180       foreach ($_POST['members'] as $value){
181         unset ($this->members["$value"]);
182         $this->removeUser($value);
183       }
184       $this->reload();
185     }
187     /* Add objects? */
188     if (isset($_POST["edit_membership"])){
189       $this->group_dialog= TRUE;
190       $this->dialog= TRUE;
191     }
193     /* Add objects finished? */
194     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
195       $this->group_dialog= FALSE;
196       $this->dialog= FALSE;
197     }
199     /* Add user to group */
200     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
201       foreach ($_POST['users'] as $value){
202         $this->members["$value"]= $this->allusers[$value];
203         asort($this->members);
204         $this->addUser($value);
205       }
206       $this->reload();
207     }
209     /* Base select dialog */
210     $once = true;
211     foreach($_POST as $name => $value){
212       if(preg_match("/^chooseBase/",$name) && $once){
213         $once = false;
214         $this->dialog = new baseSelectDialog($this->config,$this);
215         $this->dialog->setCurrentBase($this->base);
216       }
217     }
219     /* Dialog handling */
220     if(is_object($this->dialog)){
221       /* Must be called before save_object */
222       $this->dialog->save_object();
224       if($this->dialog->isClosed()){
225         $this->dialog = false;
226       }elseif($this->dialog->isSelected()){
227         $this->base = $this->dialog->isSelected();
228         $this->dialog= false;
229       }else{
230         return($this->dialog->execute());
231       }
232     }
234    /* Assign templating stuff */
235     $smarty= get_smarty();
236     if ($this->samba3){
237       $smarty->assign("samba3", "true");
238     } else {
239       $smarty->assign("samba3", "");
240     }
242     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
243       $smarty->assign("nagios",true);
244     }else{
245       $smarty->assign("nagios",false);
246     }
247     
248     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
249       $smarty->assign("pickupGroup",true);
250     }else{
251       $smarty->assign("pickupGroup",false);
252     }
254     /* Manage object add dialog */
255     if ($this->group_dialog){
257       /* Save data */
258       $gufilter= get_global("gufilter");
259       foreach( array("dselect", "regex") as $type){
260         if (isset($_POST[$type])){
261           $gufilter[$type]= $_POST[$type];
262         }
263       }
264       if(isset($_POST['regex'])){
265         if(isset($_POST['SubSearchGroup'])){
266           $gufilter['SubSearchGroup'] = true;
267         }else{
268           $gufilter['SubSearchGroup'] = false;
269         }
270       }
272       if (isset($_GET['search'])){
273         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
274         if ($s == "**"){
275           $s= "*";
276         }
277         $gufilter['regex']= $s;
278       }
279       register_global("gufilter", $gufilter);
280       $this->reload();
282       /* Show dialog */
283       $smarty->assign("search_image", get_template_path('images/search.png'));
284       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
285       $smarty->assign("tree_image", get_template_path('images/tree.png'));
286       $smarty->assign("deplist", $this->config->idepartments);
287       $smarty->assign("alphabet", generate_alphabet());
288       foreach( array("dselect", "regex","SubSearchGroup") as $type){
289         $smarty->assign("$type", $gufilter[$type]);
290       }
291       $smarty->assign("hint", print_sizelimit_warning());
292       $smarty->assign("users", $this->displayUsers);
293       $smarty->assign("apply", apply_filter());
294       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
295       return ($display);
296     }
298     /* Bases / Departments */
299     if (isset($_POST['base'])){
300       $this->base= $_POST['base'];
301     }
303     $smarty->assign("bases", $this->config->idepartments);
304     $smarty->assign("base_select", $this->base);
305     $smarty->assign("department", $this->department);
307     if ($this->samba3){
308       $domains= array();
309       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
310         $domains[$name]= $name;
311       }
312       $smarty->assign("sambaDomains", $domains);
313       $smarty->assign("sambaDomainName", $this->sambaDomainName);
314       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
315           514 => _("Domain guests"));
317       /* Don't loose special groups! If not key'ed above, add it to
318          the combo box... */    
319       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
320         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
321       }
323       $smarty->assign("groupTypes", $groupTypes);
324       $smarty->assign("groupType", $this->groupType);
325     }
327     /* Members and users */
328     $smarty->assign("members", $this->members);
330     /* Checkboxes */
331     foreach (array("force_gid", "smbgroup") as $val){
332       if ($this->$val == "1"){
333         $smarty->assign("$val", "checked");
334       } else {
335         $smarty->assign("$val", "");
336       }
337     }
338     if ($this->force_gid != "1"){
339       $smarty->assign("forceMode", "disabled");
340     }else{
341       $smarty->assign("forceMode", "");
342     }
343     if ($this->fon_group){
344       $smarty->assign("fon_group", "checked");
345     } else {
346       $smarty->assign("fon_group", "");
347     }
349     if ($this->nagios_group){
350       $smarty->assign("nagios_group", "checked");
351     } else {
352       $smarty->assign("nagios_group", "");
353     }
355     /* Fields */
356     foreach (array("cn", "description", "gidNumber") as $val){
357       $smarty->assign("$val", $this->$val);
358     }
360     $tmp = $this->plInfo();
361     foreach($tmp['plProvidedAcls'] as $name => $translation){
362       $smarty->assign($name."ACL",$this->getacl($name));
363     }
364     
365     if($this->acl_is_writeable("base")){
366       $smarty->assign("baseSelect",true);
367     }else{
368       $smarty->assign("baseSelect",false);
369     }
371     /* Show main page */
372     $smarty->assign("alphabet", generate_alphabet(10));
373     $smarty->assign("search_image", get_template_path('images/search.png'));
374     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
375     $smarty->assign("tree_image", get_template_path('images/tree.png'));
376     $smarty->assign("deplist", $this->config->idepartments);
377     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
378   }
380   function addUser($uid)
381   {
382     $this->memberUid[]= $uid;
383     $this->memberUid= array_unique($this->memberUid);
384   }
386   function removeUser($uid)
387   {
388     $temp= array();
389     foreach ($this->memberUid as $value){
390       if ($value != $uid){
391         $temp[]= $value;
392       }
393     }
394     $this->memberUid= $temp;
395   }
398   /* Reload data */
399   function reload()
400   {
401     /* Fix regex string */
402     $gufilter = get_global("gufilter");
403     $regex    = normalizeLdap($gufilter['regex']);
404     $MaxUser  = $this->OnlyShowFirstEntries;
406     /* Prepare ldap link */
407     $ldap= $this->config->get_ldap_link();
408     $ldap->cd($gufilter['dselect']);
411     /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes 
412         (Store gathered sn/givenName informations in $this->allusers too, 
413          to be prepared when adding/deleting users)
414      */    
415     $filter = "";
416     foreach ($this->memberUid as $value){
417       if(!isset($this->members[$value])){
418         $filter .= "(uid=".normalizeLdap($value).")";
419       }
420     }
421     if(!empty($filter)){    
422       $ldap->cd($this->config->current['BASE']);
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(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
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 ($this->acl_is_writeable("$val")  && isset($_POST["$val"])){
522           $this->$val= $_POST["$val"];
523         }
524       }
526       /* Save sambaDomain attribute */
527       if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
528         $this->sambaDomainName= $_POST['sambaDomainName'];
529         $this->groupType= $_POST['groupType'];
530       }
532       /* Save fon attribute */
533       if ($this->acl_is_writeable("fon_group")){
534         if (isset ($_POST['fon_group'])){
535           $this->fon_group= TRUE;
536         } else {
537           $this->fon_group= FALSE;
538         }
539       }
540          if ($this->acl_is_writeable("nagios_group")){
541         if (isset ($_POST['nagios_group'])){
542           $this->nagios_group= TRUE;
543         } else {
544           $this->nagios_group= FALSE;
545         }
546       }
547     }
548   }
551   /* Save to LDAP */
552   function save()
553   {
555     /* ID handling */
556     if ($this->force_gid == 0){
557       if ($this->saved_gidNumber != ""){
558         $this->gidNumber= $this->saved_gidNumber;
559       } else {
560         /* Calculate new, lock uids */
561         $wait= 10;
562         while (get_lock("uidnumber") != ""){
563           sleep (1);
565           /* timed out? */
566           if ($wait-- == 0){
567             break;
568           }
569         }
570         add_lock ("uidnumber", "gosa");
571         $this->gidNumber= $this->get_next_id("gidNumber");
572       }
573     }
574   
575     plugin::save(); 
577     /* Remove objectClass for samba/phone support */
578     $tmp= array();
579     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
580       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
581           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
582           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
583          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
584         $tmp[]= $this->attrs['objectClass'][$i];
585       }
586     }
587     $this->attrs['objectClass']= $tmp;
588     $ldap= $this->config->get_ldap_link();
590     /* Add samba group functionality */
591     if ($this->samba3 && $this->smbgroup){
592   
593       /* Fixed undefined index ... 
594        */ 
595       $this->SID = $this->ridBase = "";
596       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
597         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
598       }else{
599         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
600       }
601       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
602         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
603       }else{
604         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
605       }
607       $this->attrs['objectClass'][]= 'sambaGroupMapping';
608       $this->attrs['sambaGroupType']= "2";
610       /* Check if we need to create a special entry */
611       if ($this->groupType == 0){
613         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
614           $gidNumber= $this->gidNumber;
615           while(TRUE){
616             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
617             $ldap->cd($this->config->current['BASE']);
618             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
619             if ($ldap->count() == 0){
620               break;
621             }
622             $gidNumber++;
623           }
624           $this->attrs['sambaSID']= $sid;
625           $this->sambaSID= $sid;
626         }
628       } else {
629         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
630       }
632       /* User wants me to fake the idMappings? This is useful for
633          making winbind resolve the group names in a reasonable amount
634          of time in combination with larger databases. */
635       if (isset($this->config->current['SAMBAIDMAPPING']) &&
636           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
637         $this->attrs['objectClass'][]= "sambaIdmapEntry";
638       }
640     }
642     /* Add phone functionality */
643     if ($this->fon_group){
644       $this->attrs['objectClass'][]= "goFonPickupGroup";
645     }
647     /* Add nagios functionality */
648     if ($this->nagios_group){
649         $this->attrs['objectClass'][]= "nagiosContactGroup";
650     }
652     /* Take members array */
653     if (count ($this->memberUid)){
654       $this->attrs['memberUid']= array_unique($this->memberUid);
655     }
657     /* New accounts need proper 'dn', propagate it to remaining objects */
658     if ($this->dn == 'new'){
659       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
660     }
662     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
663        new entries. So do a check first... */
664     $ldap->cat ($this->dn, array('dn'));
665     if ($ldap->fetch()){
666       /* Modify needs array() to remove values :-( */
667       if (!count ($this->memberUid)){
668         $this->attrs['memberUid']= array();
669       }
670       if ($this->samba3){
671         if (!$this->smbgroup){
672           $this->attrs['sambaGroupType']= array();
673           $this->attrs['sambaSID']= array();
674         }
675       }
676       $mode= "modify";
677     } else {
678       $mode= "add";
679       $ldap->cd($this->config->current['BASE']);
680       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
681     }
683     /* Write back to ldap */
684     $ldap->cd($this->dn);
685     $this->cleanup();
686     $ldap->$mode($this->attrs);
688     $ret= 0;
689     if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
690       $ret= 1;
691     }
693     /* Remove uid lock */
694     del_lock ("uidnumber");
696     /* Post that we've done*/
697     $this->handle_post_events($mode);
699     return ($ret);
700   }
702   function check()
703   {
704     /* Call common method to give check the hook */
705     $message= plugin::check();
707     /* Permissions for that base? */
708     if ($this->base != ""){
709       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
710     } else {
711       $new_dn= $this->dn;
712     }
714     if (!$this->acl_is_createable()){
715       $message[]= _("You have no permissions to create a group on this 'Base'.");
716     }
718     /* must: cn */
719     if ($this->cn == "" && $this->acl_is_writeable("cn")){
720       $message[]= "The required field 'Name' is not set.";
721     }
723     /* Check for valid input */
724     if (!is_uid($this->cn)){
725       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
726     }
728     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
730       /* Check for used 'cn' */
731       $ldap= $this->config->get_ldap_link();
732       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
733         $ldap->cd("ou=groups,".$this->base);
734         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
735         if ($ldap->count() != 0){
736           $message[]= _("Value specified as 'Name' is already used.");
737         }
738       }
740     }else{
742       /* Check for used 'cn' */
743       $ldap= $this->config->get_ldap_link();
744       $ldap->cd($this->config->current['BASE']);
745       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
746       if ($ldap->count() != 0){
748         /* New entry? */
749         if ($this->dn == 'new'){
750           $message[]= _("Value specified as 'Name' is already used.");
751         }
753         /* Moved? */
754         elseif ($new_dn != $this->orig_dn){
755           $ldap->fetch();
756           if ($ldap->getDN() != $this->orig_dn){
757             $message[]= _("Value specified as 'Name' is already used.");
758           }
759         }
760       }
761     }
762      
763     /* Check ID */
764     if ($this->force_gid == "1"){
765       if (!is_id($this->gidNumber)){
766         $message[]= _("Value specified as 'GID' is not valid.");
767       } else {
768         if ($this->gidNumber < $this->config->current['MINID']){
769           $message[]= _("Value specified as 'GID' is too small.");
770         }
772       }
773     }
775     return ($message);
776   }
778   function get_next_id($attrib)
779   {
780     $ids= array();
781     $ldap= $this->config->get_ldap_link();
783     $ldap->cd ($this->config->current['BASE']);
784     if (preg_match('/gidNumber/i', $attrib)){
785       $oc= "posixGroup";
786     } else {
787       $oc= "posixAccount";
788     }
789     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
791     /* Get list of ids */
792     while ($attrs= $ldap->fetch()){
793       $ids[]= (int)$attrs["$attrib"][0];
794     }
796     /* Find out next free id near to UID_BASE */
797     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
798       if (!in_array($id, $ids)){
799         return ($id);
800       }
801     }
803     /* Should not happen */
804     if ($id == 65000){
805       print_red(_("Too many users, can't allocate a free ID!"));
806       exit;
807     }
808   }
810   function getCopyDialog()
811   {
812     $vars = array("cn");
813   
814     if($this ->force_gid){
815       $used = " checked ";
816       $dis  = "";
817     }else{
818       $used = "";
819       $dis  = " disabled ";
820     }
822     $smarty = get_smarty();
823     $smarty->assign("used",$used);
824     $smarty->assign("dis" ,$dis);
825     $smarty->assign("cn" ,$this->cn);
826     $smarty->assign("gidNumber",$this->gidNumber);
827     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
828     $ret = array();
829     $ret['string'] = $str;
830     $ret['status'] = "";
831     return($ret);
832   }
834   function saveCopyDialog()
835   {
836     if(isset($_POST['cn'])){
837       $this->cn = $_POST['cn'];
838     }
839     if(isset($_POST['force_gid'])){
840       $this->force_gid  = 1;
841       $this->gidNumber= $_POST['gidNumber'];
842     }else{
843       $this->force_gid  = 0;
844       $this->gidNumber  = false;
845     }
846   }
848   
849   /* Return plugin informations for acl handling  */ 
850   function plInfo()
851   {
852     return (array(  
853           "plShortName" => _("Generic"),
854           "plDescription" => _("Generic group settings"),
855           "plSelfModify"  => FALSE,
856           "plDepends"     => array(),
857           "plPriority"    => 0,
858           "plSection"     => array("admin"),
859           "plCategory"    => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
861           "plProvidedAcls"    => array(
862             "cn"                => _("Name"),
863             "description"       => _("Description"),
864             "base"              => _("Base"),
866             "fonGroup"         => _("Phone pickup group"),
867             "nagiosGroup"      => _("Nagios group"),
869             "gidNumber"         => _("GID"),
870             "memberUid"         => _("Group member"),
871             "sambaGroupType"    => _("Samba group type"),
872             "sambaDomainName"   => _("Samba domain name"),
873             "sambaSID"          => _("Samba SID"))
874         ));
875   }
878 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
879 ?>