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);
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\"> <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())){
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()){
232 /* Check if selected base is valid */
233 $tmp = $this->get_allowed_bases();
234 if(isset($tmp[$this->dialog->isSelected()])){
235 $this->base = $this->dialog->isSelected();
236 }
237 $this->dialog= false;
238 }else{
239 return($this->dialog->execute());
240 }
241 }
243 /* Assign templating stuff */
244 $smarty= get_smarty();
245 if ($this->samba3){
246 $smarty->assign("samba3", "true");
247 } else {
248 $smarty->assign("samba3", "");
249 }
251 if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
252 $smarty->assign("nagios",true);
253 }else{
254 $smarty->assign("nagios",false);
255 }
257 if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
258 $smarty->assign("pickupGroup",true);
259 }else{
260 $smarty->assign("pickupGroup",false);
261 }
263 /* Manage object add dialog */
264 if ($this->group_dialog){
266 /* Save data */
267 $gufilter= get_global("gufilter");
268 foreach( array("dselect", "regex") as $type){
269 if (isset($_POST[$type])){
270 $gufilter[$type]= $_POST[$type];
271 }
272 }
273 if(isset($_POST['regex'])){
274 if(isset($_POST['SubSearchGroup'])){
275 $gufilter['SubSearchGroup'] = true;
276 }else{
277 $gufilter['SubSearchGroup'] = false;
278 }
279 }
281 if (isset($_GET['search'])){
282 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
283 if ($s == "**"){
284 $s= "*";
285 }
286 $gufilter['regex']= $s;
287 }
288 register_global("gufilter", $gufilter);
289 $this->reload();
291 /* Show dialog */
292 $smarty->assign("search_image", get_template_path('images/search.png'));
293 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
294 $smarty->assign("tree_image", get_template_path('images/tree.png'));
296 $smarty->assign("deplist", $this->get_allowed_bases("users/user"));
297 $smarty->assign("alphabet", generate_alphabet());
298 foreach( array("dselect", "regex","SubSearchGroup") as $type){
299 $smarty->assign("$type", $gufilter[$type]);
300 }
301 $smarty->assign("hint", print_sizelimit_warning());
302 $smarty->assign("users", $this->displayUsers);
303 $smarty->assign("apply", apply_filter());
304 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
305 return ($display);
306 }
308 $smarty->assign("bases", $this->get_allowed_bases());
309 $smarty->assign("base_select", $this->base);
311 if ($this->samba3){
312 $domains= array();
313 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
314 $domains[$name]= $name;
315 }
316 $smarty->assign("sambaDomains", $domains);
317 $smarty->assign("sambaDomainName", $this->sambaDomainName);
318 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
319 514 => _("Domain guests"));
321 /* Don't loose special groups! If not key'ed above, add it to
322 the combo box... */
323 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
324 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
325 }
327 $smarty->assign("groupTypes", $groupTypes);
328 $smarty->assign("groupType", $this->groupType);
329 }
331 /* Members and users */
332 $smarty->assign("members", $this->members);
334 /* Checkboxes */
335 foreach (array("force_gid", "smbgroup") as $val){
336 if ($this->$val == "1"){
337 $smarty->assign("$val", "checked");
338 } else {
339 $smarty->assign("$val", "");
340 }
341 }
342 if ($this->force_gid != "1"){
343 $smarty->assign("forceMode", "disabled");
344 }else{
345 $smarty->assign("forceMode", "");
346 }
347 if ($this->fon_group){
348 $smarty->assign("fon_group", "checked");
349 } else {
350 $smarty->assign("fon_group", "");
351 }
353 if ($this->nagios_group){
354 $smarty->assign("nagios_group", "checked");
355 } else {
356 $smarty->assign("nagios_group", "");
357 }
359 /* Fields */
360 foreach (array("cn", "description", "gidNumber") as $val){
361 $smarty->assign("$val", $this->$val);
362 }
364 $tmp = $this->plInfo();
365 foreach($tmp['plProvidedAcls'] as $name => $translation){
366 $smarty->assign($name."ACL",$this->getacl($name));
367 }
369 if($this->acl_is_writeable("base")){
370 $smarty->assign("baseSelect",true);
371 }else{
372 $smarty->assign("baseSelect",false);
373 }
375 /* Show main page */
376 $smarty->assign("alphabet", generate_alphabet(10));
377 $smarty->assign("search_image", get_template_path('images/search.png'));
378 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
379 $smarty->assign("tree_image", get_template_path('images/tree.png'));
380 $smarty->assign("deplist", $this->config->idepartments);
381 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
382 }
384 function addUser($uid)
385 {
386 $this->memberUid[]= $uid;
387 $this->memberUid= array_unique($this->memberUid);
388 }
390 function removeUser($uid)
391 {
392 $temp= array();
393 foreach ($this->memberUid as $value){
394 if ($value != $uid){
395 $temp[]= $value;
396 }
397 }
398 $this->memberUid= $temp;
399 }
402 /* Reload data */
403 function reload()
404 {
405 /* Fix regex string */
406 $gufilter = get_global("gufilter");
407 $regex = normalizeLdap($gufilter['regex']);
408 $MaxUser = $this->OnlyShowFirstEntries;
410 /* Prepare ldap link */
411 $ldap= $this->config->get_ldap_link();
412 $ldap->cd($gufilter['dselect']);
415 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
416 (Store gathered sn/givenName informations in $this->allusers too,
417 to be prepared when adding/deleting users)
418 */
419 $filter = "";
420 foreach ($this->memberUid as $value){
421 if(!isset($this->members[$value])){
422 $filter .= "(uid=".normalizeLdap($value).")";
423 }
424 }
425 if(!empty($filter)){
426 $ldap->cd($this->config->current['BASE']);
427 $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
428 while($attrs = $ldap->fetch()){
429 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
430 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
431 }
432 }
434 /* check if all uids are resolved */
435 foreach ($this->memberUid as $value){
436 if(!isset($this->members[$value])){
437 $this->members[$value] = _("! unknown id")." [".$value."]";
438 }
439 }
441 /* Create display list of users matching regex & filter
442 */
443 $this->displayUsers = array();
444 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
446 /* Search in current tree or within subtrees depending on the checkbox from filter section */
447 if($gufilter['SubSearchGroup']){
448 $flag = GL_SIZELIMIT | GL_SUBSEARCH;
449 $base = $gufilter['dselect'];
450 }else{
451 $flag = GL_SIZELIMIT ;
452 $base = get_people_ou().$gufilter['dselect'];
453 }
454 $i = 0;
457 $res = get_list($filter,"users",$base,array("uid", "sn", "givenName"),$flag);
459 /* Fetch all users and skip already used users */
460 foreach($res as $attrs){
461 if(in_array($attrs['uid'][0], $this->memberUid)) {
462 continue;
463 }
464 $i ++;
465 if($i > $MaxUser) {
466 break;
467 }
468 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
469 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
470 }
472 /* If more than max users are found, display a message to warn the user */
473 if(($i == $MaxUser)){
474 print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
475 }
477 /* Sort lists */
478 natcasesort($this->members);
479 reset($this->members);
480 natcasesort ($this->displayUsers);
481 reset ($this->displayUsers);
482 }
485 /* Create display name, this was used so often that it is excluded into a seperate function */
486 function createResultName($attrs)
487 {
488 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
489 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
490 } else {
491 $ret= $attrs['uid'][0];
492 }
493 return($ret);
494 }
497 function remove_from_parent()
498 {
499 plugin::remove_from_parent();
501 $ldap= $this->config->get_ldap_link();
502 $ldap->rmdir($this->dn);
503 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
505 /* Delete references to object groups */
506 $ldap->cd ($this->config->current['BASE']);
507 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
508 while ($ldap->fetch()){
509 $og= new ogroup($this->config, $ldap->getDN());
510 unset($og->member[$this->dn]);
511 $og->save ();
512 }
514 /* Send signal to the world that we've done */
515 $this->handle_post_events("remove");
516 }
519 /* Save data to object */
520 function save_object()
521 {
522 /* Save additional values for possible next step */
523 if (isset($_POST['groupedit'])){
525 /* Create a base backup and reset the
526 base directly after calling plugin::save_object();
527 Base will be set seperatly a few lines below */
528 $base_tmp = $this->base;
529 plugin::save_object();
530 $this->base = $base_tmp;
532 $this->force_gid= 0;
534 /* Only reset sambagroup flag if we are able to write this flag */
535 if($this->acl_is_writeable("sambaGroupType")){
536 $this->smbgroup = 0;
537 }
539 /* Get base selection */
540 if(isset($_POST['base'])){
541 $tmp = $this->get_allowed_bases();
542 if(isset($tmp[$_POST['base']])){
543 $this->base = $_POST['base'];
544 }
545 }
547 foreach (array(
548 "force_gid" => "gidNumber",
549 "smbgroup" => "sambaGroupType") as $val => $aclname) {
550 if ($this->acl_is_writeable($aclname) && isset($_POST["$val"])){
551 $this->$val= $_POST["$val"];
552 }
553 }
555 /* Save sambaDomain attribute */
556 if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
557 $this->sambaDomainName= $_POST['sambaDomainName'];
558 $this->groupType= $_POST['groupType'];
559 }
561 /* Save fon attribute */
562 if ($this->acl_is_writeable("fon_group")){
563 if (isset ($_POST['fon_group'])){
564 $this->fon_group= TRUE;
565 } else {
566 $this->fon_group= FALSE;
567 }
568 }
569 if ($this->acl_is_writeable("nagios_group")){
570 if (isset ($_POST['nagios_group'])){
571 $this->nagios_group= TRUE;
572 } else {
573 $this->nagios_group= FALSE;
574 }
575 }
576 }
577 }
580 /* Save to LDAP */
581 function save()
582 {
584 /* ID handling */
585 if ($this->force_gid == 0){
586 if ($this->saved_gidNumber != ""){
587 $this->gidNumber= $this->saved_gidNumber;
588 } else {
589 /* Calculate new, lock uids */
590 $wait= 10;
591 while (get_lock("uidnumber") != ""){
592 sleep (1);
594 /* timed out? */
595 if ($wait-- == 0){
596 break;
597 }
598 }
599 add_lock ("uidnumber", "gosa");
600 $this->gidNumber= $this->get_next_id("gidNumber", $this->dn);
601 }
602 }
604 plugin::save();
606 /* Remove objectClass for samba/phone support */
607 $tmp= array();
608 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
609 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
610 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
611 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
612 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
613 $tmp[]= $this->attrs['objectClass'][$i];
614 }
615 }
616 $this->attrs['objectClass']= $tmp;
617 $ldap= $this->config->get_ldap_link();
619 /* Add samba group functionality */
620 if ($this->samba3 && $this->smbgroup){
622 /* Fixed undefined index ...
623 */
624 $this->SID = $this->ridBase = "";
625 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
626 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
627 }else{
628 print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
629 }
630 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
631 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
632 }else{
633 print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
634 }
636 $this->attrs['objectClass'][]= 'sambaGroupMapping';
637 $this->attrs['sambaGroupType']= "2";
639 /* Check if we need to create a special entry */
640 if ($this->groupType == 0){
642 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
643 $gidNumber= $this->gidNumber;
644 while(TRUE){
645 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
646 $ldap->cd($this->config->current['BASE']);
647 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
648 if ($ldap->count() == 0){
649 break;
650 }
651 $gidNumber++;
652 }
653 $this->attrs['sambaSID']= $sid;
654 $this->sambaSID= $sid;
655 }
657 } else {
658 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
659 }
661 /* User wants me to fake the idMappings? This is useful for
662 making winbind resolve the group names in a reasonable amount
663 of time in combination with larger databases. */
664 if (isset($this->config->current['SAMBAIDMAPPING']) &&
665 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
666 $this->attrs['objectClass'][]= "sambaIdmapEntry";
667 }
669 }
671 /* Add phone functionality */
672 if ($this->fon_group){
673 $this->attrs['objectClass'][]= "goFonPickupGroup";
674 }
676 /* Add nagios functionality */
677 if ($this->nagios_group){
678 $this->attrs['objectClass'][]= "nagiosContactGroup";
679 }
681 /* Take members array */
682 if (count ($this->memberUid)){
683 $this->attrs['memberUid']= array_unique($this->memberUid);
684 }
686 /* New accounts need proper 'dn', propagate it to remaining objects */
687 if ($this->dn == 'new'){
688 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
689 }
691 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
692 new entries. So do a check first... */
693 $ldap->cat ($this->dn, array('dn'));
694 if ($ldap->fetch()){
695 /* Modify needs array() to remove values :-( */
696 if (!count ($this->memberUid)){
697 $this->attrs['memberUid']= array();
698 }
699 if ($this->samba3){
700 if (!$this->smbgroup){
701 $this->attrs['sambaGroupType']= array();
702 $this->attrs['sambaSID']= array();
703 }
704 }
705 $mode= "modify";
706 } else {
707 $mode= "add";
708 $ldap->cd($this->config->current['BASE']);
709 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
710 }
712 /* Write back to ldap */
713 $ldap->cd($this->dn);
714 $this->cleanup();
715 $ldap->$mode($this->attrs);
717 $ret= 0;
718 if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
719 $ret= 1;
720 }
722 /* Remove uid lock */
723 del_lock ("uidnumber");
725 /* Post that we've done*/
726 $this->handle_post_events($mode);
728 return ($ret);
729 }
731 function check()
732 {
733 /* Call common method to give check the hook */
734 $message= plugin::check();
736 /* Permissions for that base? */
737 if ($this->base != ""){
738 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
739 } else {
740 $new_dn= $this->dn;
741 }
743 /* must: cn */
744 if ($this->cn == "" && $this->acl_is_writeable("cn")){
745 $message[]= "The required field 'Name' is not set.";
746 }
748 /* Check for valid input */
749 if (!is_uid($this->cn)){
750 $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
751 }
753 if($this->allowGroupsWithSameNameInOtherSubtrees == true){
755 /* Check for used 'cn' */
756 $ldap= $this->config->get_ldap_link();
757 if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
758 $ldap->cd("ou=groups,".$this->base);
759 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
760 if ($ldap->count() != 0){
761 $message[]= _("Value specified as 'Name' is already used.");
762 }
763 }
765 }else{
767 /* Check for used 'cn' */
768 $ldap= $this->config->get_ldap_link();
769 $ldap->cd($this->config->current['BASE']);
770 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
771 if ($ldap->count() != 0){
773 /* New entry? */
774 if ($this->dn == 'new'){
775 $message[]= _("Value specified as 'Name' is already used.");
776 }
778 /* Moved? */
779 elseif ($new_dn != $this->orig_dn){
780 $ldap->fetch();
781 if ($ldap->getDN() != $this->orig_dn){
782 $message[]= _("Value specified as 'Name' is already used.");
783 }
784 }
785 }
786 }
788 /* Check ID */
789 if ($this->force_gid == "1"){
790 if (!is_id($this->gidNumber)){
791 $message[]= _("Value specified as 'GID' is not valid.");
792 } else {
793 if ($this->gidNumber < $this->config->current['MINID']){
794 $message[]= _("Value specified as 'GID' is too small.");
795 }
797 }
798 }
800 return ($message);
801 }
803 function get_next_id($attrib, $dn)
804 {
805 $ids= array();
806 $ldap= $this->config->get_ldap_link();
808 $ldap->cd ($this->config->current['BASE']);
809 if (preg_match('/gidNumber/i', $attrib)){
810 $oc= "posixGroup";
811 } else {
812 $oc= "posixAccount";
813 }
814 $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
816 /* Get list of ids */
817 while ($attrs= $ldap->fetch()){
818 $ids[]= (int)$attrs["$attrib"][0];
819 }
821 /* Find out next free id near to UID_BASE */
822 if (!isset($this->config->current['BASE_HOOK'])){
823 $base= $this->config->current['UIDBASE'];
824 } else {
825 /* Call base hook */
826 $base= get_base_from_hook($dn, $attrib);
827 }
828 for ($id= $base; $id++; $id < pow(2,32)){
829 if (!in_array($id, $ids)){
830 return ($id);
831 }
832 }
834 /* Check if id reached maximum */
835 if ($id >= pow(2,32)){
836 print_red(_("Too many users, can't allocate a free ID!"));
837 exit;
838 }
839 }
841 function getCopyDialog()
842 {
843 $vars = array("cn");
845 if($this ->force_gid){
846 $used = " checked ";
847 $dis = "";
848 }else{
849 $used = "";
850 $dis = " disabled ";
851 }
853 $smarty = get_smarty();
854 $smarty->assign("used",$used);
855 $smarty->assign("dis" ,$dis);
856 $smarty->assign("cn" ,$this->cn);
857 $smarty->assign("gidNumber",$this->gidNumber);
858 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
859 $ret = array();
860 $ret['string'] = $str;
861 $ret['status'] = "";
862 return($ret);
863 }
865 function saveCopyDialog()
866 {
867 if(isset($_POST['cn'])){
868 $this->cn = $_POST['cn'];
869 }
870 if(isset($_POST['force_gid'])){
871 $this->force_gid = 1;
872 $this->gidNumber= $_POST['gidNumber'];
873 }else{
874 $this->force_gid = 0;
875 $this->gidNumber = false;
876 }
877 }
880 /* Return plugin informations for acl handling */
881 function plInfo()
882 {
883 return (array(
884 "plShortName" => _("Generic"),
885 "plDescription" => _("Generic group settings"),
886 "plSelfModify" => FALSE,
887 "plDepends" => array(),
888 "plPriority" => 0,
889 "plSection" => array("admin"),
890 "plCategory" => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
892 "plProvidedAcls" => array(
893 "cn" => _("Name"),
894 "base" => _("Base"),
895 "description" => _("Description"),
897 "fonGroup" => _("Phone pickup group"),
898 "nagiosGroup" => _("Nagios group"),
900 "gidNumber" => _("GID"),
901 "memberUid" => _("Group member"),
902 "sambaGroupType" => _("Samba group type"),
903 "sambaDomainName" => _("Samba domain name"),
904 "sambaSID" => _("Samba SID"))
905 ));
906 }
907 }
909 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
910 ?>