Code

bca62c1c1571377f8d0644f91e5dc85c453e3fbc
[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 $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   var $CopyPasteVars  = array("force_gid","fon_group","smbgroup","groupType","sambaSID","sambaDomainName","SID","nagios_group","sambaGroupType");
49   function group ($config, $dn= NULL)
50   {
51     plugin::plugin ($config, $dn);
53     /* Load attributes depending on the samba version */
54     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
55     $this->orig_dn= $dn;
56     $this->orig_cn= $this->cn;
58     /* Get member list */
59     if (isset($this->attrs['memberUid'][0])){
60       $tmp= array();
61       for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
62         $tmp[]= $this->attrs['memberUid'][$i];
63       }
64       $this->memberUid= $tmp;
65       sort ($this->memberUid);
66     }
68     /* Save gidNumber for later use */
69     if (isset($this->attrs['gidNumber'])){
70       $this->saved_gidNumber= $this->attrs['gidNumber'][0];
71     }
73     /* Is a samba group? */
74     if (isset($this->attrs['objectClass'])){
75       if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
76         $this->smbgroup= FALSE;
77       } else {
78         $this->smbgroup= TRUE;
79         if (isset($this->attrs['sambaSID'])){
80           $this->sambaSID= $this->attrs['sambaSID'][0];
81         }
82       }
83       if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
84         $this->fon_group= FALSE;
85       } else {
86         $this->fon_group= TRUE;
87       }
88       if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
89         $this->nagios_group= FALSE;
90       } else {
91         $this->nagios_group= TRUE;
92       }
93     }
95     /* Set mail flag */
96     if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
97       $this->has_mailAccount= TRUE;
98     }
100     /* Get samba Domain in case of samba 3 */
101     if ($this->samba3 && $this->sambaSID != ""){
102       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
103       $ldap= $this->config->get_ldap_link();
104       $ldap->cd($this->config->current['BASE']);
105       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
106       if ($ldap->count() != 0){
107         $attrs= $ldap->fetch();
108         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
110         /* Get domain name for SID */
111         $this->sambaDomainName= "DEFAULT";
112         foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
113           if ($val['SID'] == $this->SID){
114             $this->sambaDomainName= $key;
115             break;
116           }
117         }
118       } else {
119         if (isset($this->config->current['RIDBASE'])){
120           $this->sambaDomainName= "DEFAULT";
121           $this->ridBase= $this->config->current['RIDBASE'];
122           $this->SID= $this->config->current['SID'];
123         } else {
124           print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
125         }
126       }
128       /* Get group type */
129       $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
130       if ($this->groupType < 500 || $this->groupType > 553){
131         $this->groupType= 0;
132       }
133       $this->oldgroupType= $this->groupType;
134     }
136     /* Get global filter config */
137     if (!is_global("gufilter")){
138       $ui= get_userinfo();
139       $base= get_base_from_people($ui->dn);
140       $gufilter= array( "dselect"       => $base,
141           "regex"           => "*");
142       register_global("gufilter", $gufilter);
143     }
144     $gufilter= get_global('gufilter');
146     $gufilter['SubSearchGroup'] = false;
147     $gufilter['dselect'] = $_SESSION['gufilter']['dselect'];  
149     register_global('gufilter',$gufilter);
150   
151     if ($this->dn == "new"){
152       if(isset($_SESSION['CurrentMainBase'])){
153         $this->base= $_SESSION['CurrentMainBase'];
154       }else{
155         $ui= get_userinfo();
156         $this->base= dn2base($ui->dn);
157       }
158     } else {
160       /* Get object base */
161       $this->base =preg_replace ("/^[^,]+,".normalizePreg(get_groups_ou())."/","",$this->dn);
162     }
164     /* This is always an account */
165     $this->is_account= TRUE;
166     $this->reload();
167   }
169   function execute()
170   {
171         /* Call parent execute */
172         plugin::execute();
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) && ($this->acl_is_moveable())){
216           
217         $once = false;
218         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
219         $this->dialog->setCurrentBase($this->base);
220       }
221     }
223     /* Dialog handling */
224     if(is_object($this->dialog)){
225       /* Must be called before save_object */
226       $this->dialog->save_object();
228       if($this->dialog->isClosed()){
229         $this->dialog = false;
230       }elseif($this->dialog->isSelected()){
231         if($this->acl_is_moveable()){
232           $this->base = $this->dialog->isSelected();
233         }
234         $this->dialog= false;
235       }else{
236         return($this->dialog->execute());
237       }
238     }
240    /* Assign templating stuff */
241     $smarty= get_smarty();
242     if ($this->samba3){
243       $smarty->assign("samba3", "true");
244     } else {
245       $smarty->assign("samba3", "");
246     }
248     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
249       $smarty->assign("nagios",true);
250     }else{
251       $smarty->assign("nagios",false);
252     }
253     
254     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
255       $smarty->assign("pickupGroup",true);
256     }else{
257       $smarty->assign("pickupGroup",false);
258     }
260     /* Assign base ACL */
261     $baseACL = $this->getacl("base");
262     if(!$this->acl_is_moveable()) {
263       $baseACL = preg_replace("/w/","",$baseACL);
264     }
265     $smarty->assign("baseACL",          $baseACL);
267     /* Manage object add dialog */
268     if ($this->group_dialog){
270       /* Save data */
271       $gufilter= get_global("gufilter");
272       foreach( array("dselect", "regex") as $type){
273         if (isset($_POST[$type])){
274           $gufilter[$type]= $_POST[$type];
275         }
276       }
277       if(isset($_POST['regex'])){
278         if(isset($_POST['SubSearchGroup'])){
279           $gufilter['SubSearchGroup'] = true;
280         }else{
281           $gufilter['SubSearchGroup'] = false;
282         }
283       }
285       if (isset($_GET['search'])){
286         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
287         if ($s == "**"){
288           $s= "*";
289         }
290         $gufilter['regex']= $s;
291       }
292       register_global("gufilter", $gufilter);
293       $this->reload();
295       /* Show dialog */
296       $smarty->assign("search_image", get_template_path('images/search.png'));
297       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
298       $smarty->assign("tree_image", get_template_path('images/tree.png'));
300       $smarty->assign("deplist", $this->get_allowed_bases("users/user"));
301       $smarty->assign("alphabet", generate_alphabet());
302       foreach( array("dselect", "regex","SubSearchGroup") as $type){
303         $smarty->assign("$type", $gufilter[$type]);
304       }
305       $smarty->assign("hint", print_sizelimit_warning());
306       $smarty->assign("users", $this->displayUsers);
307       $smarty->assign("apply", apply_filter());
308       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
309       return ($display);
310     }
312     /* Bases / Departments */
313     if (isset($_POST['base'])){
314       $this->base= $_POST['base'];
315     }
317     $smarty->assign("bases", $this->get_allowed_bases());
318     $smarty->assign("base_select", $this->base);
320     if ($this->samba3){
321       $domains= array();
322       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
323         $domains[$name]= $name;
324       }
325       $smarty->assign("sambaDomains", $domains);
326       $smarty->assign("sambaDomainName", $this->sambaDomainName);
327       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
328           514 => _("Domain guests"));
330       /* Don't loose special groups! If not key'ed above, add it to
331          the combo box... */    
332       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
333         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
334       }
336       $smarty->assign("groupTypes", $groupTypes);
337       $smarty->assign("groupType", $this->groupType);
338     }
340     /* Members and users */
341     $smarty->assign("members", $this->members);
343     /* Checkboxes */
344     foreach (array("force_gid", "smbgroup") as $val){
345       if ($this->$val == "1"){
346         $smarty->assign("$val", "checked");
347       } else {
348         $smarty->assign("$val", "");
349       }
350     }
351     if ($this->force_gid != "1"){
352       $smarty->assign("forceMode", "disabled");
353     }else{
354       $smarty->assign("forceMode", "");
355     }
356     if ($this->fon_group){
357       $smarty->assign("fon_group", "checked");
358     } else {
359       $smarty->assign("fon_group", "");
360     }
362     if ($this->nagios_group){
363       $smarty->assign("nagios_group", "checked");
364     } else {
365       $smarty->assign("nagios_group", "");
366     }
368     /* Fields */
369     foreach (array("cn", "description", "gidNumber") as $val){
370       $smarty->assign("$val", $this->$val);
371     }
373     $tmp = $this->plInfo();
374     foreach($tmp['plProvidedAcls'] as $name => $translation){
375       $smarty->assign($name."ACL",$this->getacl($name));
376     }
377     
378     if($this->acl_is_writeable("base")){
379       $smarty->assign("baseSelect",true);
380     }else{
381       $smarty->assign("baseSelect",false);
382     }
384     /* Show main page */
385     $smarty->assign("alphabet", generate_alphabet(10));
386     $smarty->assign("search_image", get_template_path('images/search.png'));
387     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
388     $smarty->assign("tree_image", get_template_path('images/tree.png'));
389     $smarty->assign("deplist", $this->config->idepartments);
390     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
391   }
393   function addUser($uid)
394   {
395     $this->memberUid[]= $uid;
396     $this->memberUid= array_unique($this->memberUid);
397   }
399   function removeUser($uid)
400   {
401     $temp= array();
402     foreach ($this->memberUid as $value){
403       if ($value != $uid){
404         $temp[]= $value;
405       }
406     }
407     $this->memberUid= $temp;
408   }
411   /* Reload data */
412   function reload()
413   {
414     /* Fix regex string */
415     $gufilter = get_global("gufilter");
416     $regex    = normalizeLdap($gufilter['regex']);
417     $MaxUser  = $this->OnlyShowFirstEntries;
419     /* Prepare ldap link */
420     $ldap= $this->config->get_ldap_link();
421     $ldap->cd($gufilter['dselect']);
424     /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes 
425         (Store gathered sn/givenName informations in $this->allusers too, 
426          to be prepared when adding/deleting users)
427      */    
428     $filter = "";
429     foreach ($this->memberUid as $value){
430       if(!isset($this->members[$value])){
431         $filter .= "(uid=".normalizeLdap($value).")";
432       }
433     }
434     if(!empty($filter)){    
435       $ldap->cd($this->config->current['BASE']);
436       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
437       while($attrs = $ldap->fetch()){
438         $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
439         $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
440       } 
441     }
442   
443     /* check if all uids are resolved */
444     foreach ($this->memberUid as $value){
445       if(!isset($this->members[$value])){
446         $this->members[$value] =  _("! unknown id")." [".$value."]"; 
447       }
448     }  
450     /* Create display list of users matching regex & filter 
451      */
452     $this->displayUsers = array();
453     $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
455     /* Search in current tree or within subtrees depending on the checkbox from filter section */
456     if($gufilter['SubSearchGroup']){
457       $flag = GL_SIZELIMIT | GL_SUBSEARCH;
458       $base = $gufilter['dselect'];
459     }else{
460       $flag = GL_SIZELIMIT ;
461       $base = get_people_ou().$gufilter['dselect'];
462     }
463     $i = 0;
464   
466     $res = get_list($filter,"users",$base,array("uid", "sn", "givenName"),$flag);
468     /* Fetch all users and skip already used users */
469     foreach($res as $attrs){
470       if(in_array($attrs['uid'][0], $this->memberUid)) {
471         continue;
472       }
473       $i ++;
474       if($i > $MaxUser) {
475         break;
476       }
477       $this->allusers[$attrs['uid'][0]]     = $this->createResultName($attrs);
478       $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
479     }
480   
481     /* If more than max users are found, display a message to warn the user */
482     if(($i == $MaxUser)){
483       print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
484     }
485     
486     /* Sort lists */
487     natcasesort($this->members);
488     reset($this->members);
489     natcasesort ($this->displayUsers);
490     reset ($this->displayUsers);
491   }
494   /* Create display name, this was used so often that it is excluded into a seperate function */
495   function createResultName($attrs)
496   {
497     if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
498       $ret =  $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
499     } else {
500       $ret= $attrs['uid'][0];
501     }
502     return($ret);
503   }
506   function remove_from_parent()
507   {
508     plugin::remove_from_parent();
510     $ldap= $this->config->get_ldap_link();
511     $ldap->rmdir($this->dn);
512     show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
514     /* Delete references to object groups */
515     $ldap->cd ($this->config->current['BASE']);
516     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
517     while ($ldap->fetch()){
518       $og= new ogroup($this->config, $ldap->getDN());
519       unset($og->member[$this->dn]);
520       $og->save ();
521     }
523     /* Send signal to the world that we've done */
524     $this->handle_post_events("remove");
525   }
528   /* Save data to object */
529   function save_object()
530   {
531     /* Save additional values for possible next step */
532     if (isset($_POST['groupedit'])){
534       plugin::save_object();
536       $this->force_gid= 0;
539       /* Only reset sambagroup flag if we are able to write this flag */
540       if($this->acl_is_writeable("sambaGroupType")){
541         $this->smbgroup = 0;
542       }
544       /* Get base selection */
545       if($this->acl_is_moveable() && isset($_POST['base'])){
546         $this->base = $_POST['base'];
547       }
549       foreach (array(
550             "force_gid"  => "gidNumber", 
551             "smbgroup"   => "sambaGroupType") as $val => $aclname) {
552         if ($this->acl_is_writeable($aclname)  && isset($_POST["$val"])){
553           $this->$val= $_POST["$val"];
554         }
555       }
557       /* Save sambaDomain attribute */
558       if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
559         $this->sambaDomainName= $_POST['sambaDomainName'];
560         $this->groupType= $_POST['groupType'];
561       }
563       /* Save fon attribute */
564       if ($this->acl_is_writeable("fon_group")){
565         if (isset ($_POST['fon_group'])){
566           $this->fon_group= TRUE;
567         } else {
568           $this->fon_group= FALSE;
569         }
570       }
571       if ($this->acl_is_writeable("nagios_group")){
572         if (isset ($_POST['nagios_group'])){
573           $this->nagios_group= TRUE;
574         } else {
575           $this->nagios_group= FALSE;
576         }
577       }
578     }
579   }
582   /* Save to LDAP */
583   function save()
584   {
586     /* ID handling */
587     if ($this->force_gid == 0){
588       if ($this->saved_gidNumber != ""){
589         $this->gidNumber= $this->saved_gidNumber;
590       } else {
591         /* Calculate new, lock uids */
592         $wait= 10;
593         while (get_lock("uidnumber") != ""){
594           sleep (1);
596           /* timed out? */
597           if ($wait-- == 0){
598             break;
599           }
600         }
601         add_lock ("uidnumber", "gosa");
602         $this->gidNumber= $this->get_next_id("gidNumber");
603       }
604     }
605   
606     plugin::save(); 
608     /* Remove objectClass for samba/phone support */
609     $tmp= array();
610     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
611       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
612           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
613           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
614          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
615         $tmp[]= $this->attrs['objectClass'][$i];
616       }
617     }
618     $this->attrs['objectClass']= $tmp;
619     $ldap= $this->config->get_ldap_link();
621     /* Add samba group functionality */
622     if ($this->samba3 && $this->smbgroup){
623   
624       /* Fixed undefined index ... 
625        */ 
626       $this->SID = $this->ridBase = "";
627       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
628         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
629       }else{
630         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
631       }
632       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
633         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
634       }else{
635         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
636       }
638       $this->attrs['objectClass'][]= 'sambaGroupMapping';
639       $this->attrs['sambaGroupType']= "2";
641       /* Check if we need to create a special entry */
642       if ($this->groupType == 0){
644         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
645           $gidNumber= $this->gidNumber;
646           while(TRUE){
647             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
648             $ldap->cd($this->config->current['BASE']);
649             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
650             if ($ldap->count() == 0){
651               break;
652             }
653             $gidNumber++;
654           }
655           $this->attrs['sambaSID']= $sid;
656           $this->sambaSID= $sid;
657         }
659       } else {
660         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
661       }
663       /* User wants me to fake the idMappings? This is useful for
664          making winbind resolve the group names in a reasonable amount
665          of time in combination with larger databases. */
666       if (isset($this->config->current['SAMBAIDMAPPING']) &&
667           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
668         $this->attrs['objectClass'][]= "sambaIdmapEntry";
669       }
671     }
673     /* Add phone functionality */
674     if ($this->fon_group){
675       $this->attrs['objectClass'][]= "goFonPickupGroup";
676     }
678     /* Add nagios functionality */
679     if ($this->nagios_group){
680         $this->attrs['objectClass'][]= "nagiosContactGroup";
681     }
683     /* Take members array */
684     if (count ($this->memberUid)){
685       $this->attrs['memberUid']= array_unique($this->memberUid);
686     }
688     /* New accounts need proper 'dn', propagate it to remaining objects */
689     if ($this->dn == 'new'){
690       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
691     }
693     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
694        new entries. So do a check first... */
695     $ldap->cat ($this->dn, array('dn'));
696     if ($ldap->fetch()){
697       /* Modify needs array() to remove values :-( */
698       if (!count ($this->memberUid)){
699         $this->attrs['memberUid']= array();
700       }
701       if ($this->samba3){
702         if (!$this->smbgroup){
703           $this->attrs['sambaGroupType']= array();
704           $this->attrs['sambaSID']= array();
705         }
706       }
707       $mode= "modify";
708     } else {
709       $mode= "add";
710       $ldap->cd($this->config->current['BASE']);
711       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
712     }
714     /* Write back to ldap */
715     $ldap->cd($this->dn);
716     $this->cleanup();
717     $ldap->$mode($this->attrs);
719     $ret= 0;
720     if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
721       $ret= 1;
722     }
724     /* Remove uid lock */
725     del_lock ("uidnumber");
727     /* Post that we've done*/
728     $this->handle_post_events($mode);
730     return ($ret);
731   }
733   function check()
734   {
735     /* Call common method to give check the hook */
736     $message= plugin::check();
738     /* Permissions for that base? */
739     if ($this->base != ""){
740       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
741     } else {
742       $new_dn= $this->dn;
743     }
745     /* Set new acl base */
746     if($this->dn == "new") {
747       $this->set_acl_base($this->base);
748     }
750     if ($this->orig_dn == "new" && !$this->acl_is_createable()){
751       $message[]= _("You have no permissions to create a group on this 'Base'.");
752     }
754     /* must: cn */
755     if ($this->cn == "" && $this->acl_is_writeable("cn")){
756       $message[]= "The required field 'Name' is not set.";
757     }
759     /* Check for valid input */
760     if (!is_uid($this->cn)){
761       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
762     }
764     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
766       /* Check for used 'cn' */
767       $ldap= $this->config->get_ldap_link();
768       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
769         $ldap->cd("ou=groups,".$this->base);
770         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
771         if ($ldap->count() != 0){
772           $message[]= _("Value specified as 'Name' is already used.");
773         }
774       }
776     }else{
778       /* Check for used 'cn' */
779       $ldap= $this->config->get_ldap_link();
780       $ldap->cd($this->config->current['BASE']);
781       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
782       if ($ldap->count() != 0){
784         /* New entry? */
785         if ($this->dn == 'new'){
786           $message[]= _("Value specified as 'Name' is already used.");
787         }
789         /* Moved? */
790         elseif ($new_dn != $this->orig_dn){
791           $ldap->fetch();
792           if ($ldap->getDN() != $this->orig_dn){
793             $message[]= _("Value specified as 'Name' is already used.");
794           }
795         }
796       }
797     }
798      
799     /* Check ID */
800     if ($this->force_gid == "1"){
801       if (!is_id($this->gidNumber)){
802         $message[]= _("Value specified as 'GID' is not valid.");
803       } else {
804         if ($this->gidNumber < $this->config->current['MINID']){
805           $message[]= _("Value specified as 'GID' is too small.");
806         }
808       }
809     }
811     return ($message);
812   }
814   function get_next_id($attrib)
815   {
816     $ids= array();
817     $ldap= $this->config->get_ldap_link();
819     $ldap->cd ($this->config->current['BASE']);
820     if (preg_match('/gidNumber/i', $attrib)){
821       $oc= "posixGroup";
822     } else {
823       $oc= "posixAccount";
824     }
825     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
827     /* Get list of ids */
828     while ($attrs= $ldap->fetch()){
829       $ids[]= (int)$attrs["$attrib"][0];
830     }
832     /* Find out next free id near to UID_BASE */
833     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
834       if (!in_array($id, $ids)){
835         return ($id);
836       }
837     }
839     /* Should not happen */
840     if ($id == 65000){
841       print_red(_("Too many users, can't allocate a free ID!"));
842       exit;
843     }
844   }
846   function getCopyDialog()
847   {
848     $vars = array("cn");
849   
850     if($this ->force_gid){
851       $used = " checked ";
852       $dis  = "";
853     }else{
854       $used = "";
855       $dis  = " disabled ";
856     }
858     $smarty = get_smarty();
859     $smarty->assign("used",$used);
860     $smarty->assign("dis" ,$dis);
861     $smarty->assign("cn" ,$this->cn);
862     $smarty->assign("gidNumber",$this->gidNumber);
863     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
864     $ret = array();
865     $ret['string'] = $str;
866     $ret['status'] = "";
867     return($ret);
868   }
870   function saveCopyDialog()
871   {
872     if(isset($_POST['cn'])){
873       $this->cn = $_POST['cn'];
874     }
875     if(isset($_POST['force_gid'])){
876       $this->force_gid  = 1;
877       $this->gidNumber= $_POST['gidNumber'];
878     }else{
879       $this->force_gid  = 0;
880       $this->gidNumber  = false;
881     }
882   }
884   
885   /* Return plugin informations for acl handling  */ 
886   function plInfo()
887   {
888     return (array(  
889           "plShortName" => _("Generic"),
890           "plDescription" => _("Generic group settings"),
891           "plSelfModify"  => FALSE,
892           "plDepends"     => array(),
893           "plPriority"    => 0,
894           "plSection"     => array("admin"),
895           "plCategory"    => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
897           "plProvidedAcls"    => array(
898             "cn"                => _("Name"),
899             "base"              => _("Base"),
900             "description"       => _("Description"),
902             "fonGroup"          => _("Phone pickup group"),
903             "nagiosGroup"       => _("Nagios group"),
905             "gidNumber"         => _("GID"),
906             "memberUid"         => _("Group member"),
907             "sambaGroupType"    => _("Samba group type"),
908             "sambaDomainName"   => _("Samba domain name"),
909             "sambaSID"          => _("Samba SID"))
910         ));
911   }
914 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
915 ?>