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 function group ($config, $dn= NULL)
48 {
49 plugin::plugin ($config, $dn);
51 /* Load attributes depending on the samba version */
52 $this->samba3= ($config->current['SAMBAVERSION'] == 3);
53 $this->orig_dn= $dn;
54 $this->orig_cn= $this->cn;
56 /* Get member list */
57 if (isset($this->attrs['memberUid'][0])){
58 $tmp= array();
59 for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
60 $tmp[]= $this->attrs['memberUid'][$i];
61 }
62 $this->memberUid= $tmp;
63 sort ($this->memberUid);
64 }
66 /* Save gidNumber for later use */
67 if (isset($this->attrs['gidNumber'])){
68 $this->saved_gidNumber= $this->attrs['gidNumber'][0];
69 }
71 /* Is a samba group? */
72 if (isset($this->attrs['objectClass'])){
73 if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
74 $this->smbgroup= FALSE;
75 } else {
76 $this->smbgroup= TRUE;
77 if (isset($this->attrs['sambaSID'])){
78 $this->sambaSID= $this->attrs['sambaSID'][0];
79 }
80 }
81 if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
82 $this->fon_group= FALSE;
83 } else {
84 $this->fon_group= TRUE;
85 }
86 if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
87 $this->nagios_group= FALSE;
88 } else {
89 $this->nagios_group= TRUE;
90 }
91 }
93 /* Set mail flag */
94 if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
95 $this->has_mailAccount= TRUE;
96 }
98 /* Get samba Domain in case of samba 3 */
99 if ($this->samba3 && $this->sambaSID != ""){
100 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
101 $ldap= $this->config->get_ldap_link();
102 $ldap->cd($this->config->current['BASE']);
103 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
104 if ($ldap->count() != 0){
105 $attrs= $ldap->fetch();
106 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
108 /* Get domain name for SID */
109 $this->sambaDomainName= "DEFAULT";
110 foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
111 if ($val['SID'] == $this->SID){
112 $this->sambaDomainName= $key;
113 break;
114 }
115 }
116 } else {
117 if (isset($this->config->current['RIDBASE'])){
118 $this->sambaDomainName= "DEFAULT";
119 $this->ridBase= $this->config->current['RIDBASE'];
120 $this->SID= $this->config->current['SID'];
121 } else {
122 print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
123 }
124 }
126 /* Get group type */
127 $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
128 if ($this->groupType < 500 || $this->groupType > 553){
129 $this->groupType= 0;
130 }
131 $this->oldgroupType= $this->groupType;
132 }
134 /* Get global filter config */
135 if (!is_global("gufilter")){
136 $ui= get_userinfo();
137 $base= get_base_from_people($ui->dn);
138 $gufilter= array( "dselect" => $base,
139 "regex" => "*");
140 register_global("gufilter", $gufilter);
141 }
142 $gufilter= get_global('gufilter');
144 $gufilter['SubSearchGroup'] = false;
145 $gufilter['dselect'] = $_SESSION['gufilter']['dselect'];
147 register_global('gufilter',$gufilter);
149 if ($this->dn == "new"){
150 if(isset($_SESSION['CurrentMainBase'])){
151 $this->base= $_SESSION['CurrentMainBase'];
152 }else{
153 $ui= get_userinfo();
154 $this->base= dn2base($ui->dn);
155 }
156 } else {
157 $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
158 }
160 /* This is always an account */
161 $this->is_account= TRUE;
162 $this->reload();
163 }
165 function execute()
166 {
167 /* Call parent execute */
168 plugin::execute();
170 /* Do we represent a valid group? */
171 if (!$this->is_account && $this->parent == NULL){
172 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
173 _("This 'dn' is no group.")."</b>";
174 return ($display);
175 }
177 /* Delete user from group */
178 if (isset($_POST['del_users']) && isset($_POST['members'])){
179 foreach ($_POST['members'] as $value){
180 unset ($this->members["$value"]);
181 $this->removeUser($value);
182 }
183 $this->reload();
184 }
186 /* Add objects? */
187 if (isset($_POST["edit_membership"])){
188 $this->group_dialog= TRUE;
189 $this->dialog= TRUE;
190 }
192 /* Add objects finished? */
193 if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
194 $this->group_dialog= FALSE;
195 $this->dialog= FALSE;
196 }
198 /* Add user to group */
199 if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
200 foreach ($_POST['users'] as $value){
201 $this->members["$value"]= $this->allusers[$value];
202 asort($this->members);
203 $this->addUser($value);
204 }
205 $this->reload();
206 }
208 /* Base select dialog */
209 $once = true;
210 foreach($_POST as $name => $value){
211 if(preg_match("/^chooseBase/",$name) && $once){
212 $once = false;
213 $this->dialog = new baseSelectDialog($this->config,$this);
214 $this->dialog->setCurrentBase($this->base);
215 }
216 }
218 /* Dialog handling */
219 if(is_object($this->dialog)){
220 /* Must be called before save_object */
221 $this->dialog->save_object();
223 if($this->dialog->isClosed()){
224 $this->dialog = false;
225 }elseif($this->dialog->isSelected()){
226 $this->base = $this->dialog->isSelected();
227 $this->dialog= false;
228 }else{
229 return($this->dialog->execute());
230 }
231 }
233 /* Assign templating stuff */
234 $smarty= get_smarty();
235 if ($this->samba3){
236 $smarty->assign("samba3", "true");
237 } else {
238 $smarty->assign("samba3", "");
239 }
241 if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
242 $smarty->assign("nagios",true);
243 }else{
244 $smarty->assign("nagios",false);
245 }
247 if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
248 $smarty->assign("pickupGroup",true);
249 }else{
250 $smarty->assign("pickupGroup",false);
251 }
253 /* Manage object add dialog */
254 if ($this->group_dialog){
256 /* Save data */
257 $gufilter= get_global("gufilter");
258 foreach( array("dselect", "regex") as $type){
259 if (isset($_POST[$type])){
260 $gufilter[$type]= $_POST[$type];
261 }
262 }
263 if(isset($_POST['regex'])){
264 if(isset($_POST['SubSearchGroup'])){
265 $gufilter['SubSearchGroup'] = true;
266 }else{
267 $gufilter['SubSearchGroup'] = false;
268 }
269 }
271 if (isset($_GET['search'])){
272 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
273 if ($s == "**"){
274 $s= "*";
275 }
276 $gufilter['regex']= $s;
277 }
278 register_global("gufilter", $gufilter);
279 $this->reload();
281 /* Show dialog */
282 $smarty->assign("search_image", get_template_path('images/search.png'));
283 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
284 $smarty->assign("tree_image", get_template_path('images/tree.png'));
285 $smarty->assign("deplist", $this->config->idepartments);
286 $smarty->assign("alphabet", generate_alphabet());
287 foreach( array("dselect", "regex","SubSearchGroup") as $type){
288 $smarty->assign("$type", $gufilter[$type]);
289 }
290 $smarty->assign("hint", print_sizelimit_warning());
291 $smarty->assign("users", $this->displayUsers);
292 $smarty->assign("apply", apply_filter());
293 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
294 return ($display);
295 }
297 /* Bases / Departments */
298 if (isset($_POST['base'])){
299 $this->base= $_POST['base'];
300 }
302 $smarty->assign("bases", $this->config->idepartments);
303 $smarty->assign("base_select", $this->base);
305 if ($this->samba3){
306 $domains= array();
307 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
308 $domains[$name]= $name;
309 }
310 $smarty->assign("sambaDomains", $domains);
311 $smarty->assign("sambaDomainName", $this->sambaDomainName);
312 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
313 514 => _("Domain guests"));
315 /* Don't loose special groups! If not key'ed above, add it to
316 the combo box... */
317 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
318 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
319 }
321 $smarty->assign("groupTypes", $groupTypes);
322 $smarty->assign("groupType", $this->groupType);
323 }
325 /* Members and users */
326 $smarty->assign("members", $this->members);
328 /* Checkboxes */
329 foreach (array("force_gid", "smbgroup") as $val){
330 if ($this->$val == "1"){
331 $smarty->assign("$val", "checked");
332 } else {
333 $smarty->assign("$val", "");
334 }
335 }
336 if ($this->force_gid != "1"){
337 $smarty->assign("forceMode", "disabled");
338 }else{
339 $smarty->assign("forceMode", "");
340 }
341 if ($this->fon_group){
342 $smarty->assign("fon_group", "checked");
343 } else {
344 $smarty->assign("fon_group", "");
345 }
347 if ($this->nagios_group){
348 $smarty->assign("nagios_group", "checked");
349 } else {
350 $smarty->assign("nagios_group", "");
351 }
353 /* Fields */
354 foreach (array("cn", "description", "gidNumber") as $val){
355 $smarty->assign("$val", $this->$val);
356 }
358 $tmp = $this->plInfo();
359 foreach($tmp['plProvidedAcls'] as $name => $translation){
360 $smarty->assign($name."ACL",$this->getacl($name));
361 }
363 if($this->acl_is_writeable("base")){
364 $smarty->assign("baseSelect",true);
365 }else{
366 $smarty->assign("baseSelect",false);
367 }
369 /* Show main page */
370 $smarty->assign("alphabet", generate_alphabet(10));
371 $smarty->assign("search_image", get_template_path('images/search.png'));
372 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
373 $smarty->assign("tree_image", get_template_path('images/tree.png'));
374 $smarty->assign("deplist", $this->config->idepartments);
375 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
376 }
378 function addUser($uid)
379 {
380 $this->memberUid[]= $uid;
381 $this->memberUid= array_unique($this->memberUid);
382 }
384 function removeUser($uid)
385 {
386 $temp= array();
387 foreach ($this->memberUid as $value){
388 if ($value != $uid){
389 $temp[]= $value;
390 }
391 }
392 $this->memberUid= $temp;
393 }
396 /* Reload data */
397 function reload()
398 {
399 /* Fix regex string */
400 $gufilter = get_global("gufilter");
401 $regex = normalizeLdap($gufilter['regex']);
402 $MaxUser = $this->OnlyShowFirstEntries;
404 /* Prepare ldap link */
405 $ldap= $this->config->get_ldap_link();
406 $ldap->cd($gufilter['dselect']);
409 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
410 (Store gathered sn/givenName informations in $this->allusers too,
411 to be prepared when adding/deleting users)
412 */
413 $filter = "";
414 foreach ($this->memberUid as $value){
415 if(!isset($this->members[$value])){
416 $filter .= "(uid=".normalizeLdap($value).")";
417 }
418 }
419 if(!empty($filter)){
420 $ldap->cd($this->config->current['BASE']);
421 $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
422 while($attrs = $ldap->fetch()){
423 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
424 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
425 }
426 }
428 /* check if all uids are resolved */
429 foreach ($this->memberUid as $value){
430 if(!isset($this->members[$value])){
431 $this->members[$value] = _("! unknown id")." [".$value."]";
432 }
433 }
435 /* Create display list of users matching regex & filter
436 */
437 $this->displayUsers = array();
438 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
440 /* Search in current tree or within subtrees depending on the checkbox from filter section */
441 if($gufilter['SubSearchGroup']){
442 $ldap->search($filter, array("uid", "sn","givenName"));
443 }else{
444 $ldap->ls ($filter, get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
445 }
446 $i = 0;
448 /* Fetch all users and skip already used users */
449 while($attrs = $ldap->fetch()){
450 if(in_array($attrs['uid'][0], $this->memberUid)) {
451 continue;
452 }
453 $i ++;
454 if($i > $MaxUser) {
455 break;
456 }
457 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
458 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
459 }
461 /* If more than max users are found, display a message to warn the user */
462 if(($i == $MaxUser)){
463 print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
464 }
466 /* Sort lists */
467 natcasesort($this->members);
468 reset($this->members);
469 natcasesort ($this->displayUsers);
470 reset ($this->displayUsers);
471 }
474 /* Create display name, this was used so often that it is excluded into a seperate function */
475 function createResultName($attrs)
476 {
477 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
478 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
479 } else {
480 $ret= $attrs['uid'][0];
481 }
482 return($ret);
483 }
486 function remove_from_parent()
487 {
488 plugin::remove_from_parent();
490 $ldap= $this->config->get_ldap_link();
491 $ldap->rmdir($this->dn);
492 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
494 /* Delete references to object groups */
495 $ldap->cd ($this->config->current['BASE']);
496 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
497 while ($ldap->fetch()){
498 $og= new ogroup($this->config, $ldap->getDN());
499 unset($og->member[$this->dn]);
500 $og->save ();
501 }
503 /* Send signal to the world that we've done */
504 $this->handle_post_events("remove");
505 }
508 /* Save data to object */
509 function save_object()
510 {
511 /* Save additional values for possible next step */
512 if (isset($_POST['groupedit'])){
514 plugin::save_object();
516 $this->force_gid= 0;
519 /* Only reset sambagroup flag if we are able to write this flag */
520 if($this->acl_is_writeable("sambaGroupType")){
521 $this->smbgroup = 0;
522 }
524 foreach (array(
525 "force_gid" => "gidNumber",
526 "base" => "base",
527 "smbgroup" => "sambaGroupType") as $val => $aclname) {
528 if ($this->acl_is_writeable($aclname) && isset($_POST["$val"])){
529 $this->$val= $_POST["$val"];
530 }
531 }
533 /* Save sambaDomain attribute */
534 if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
535 $this->sambaDomainName= $_POST['sambaDomainName'];
536 $this->groupType= $_POST['groupType'];
537 }
539 /* Save fon attribute */
540 if ($this->acl_is_writeable("fon_group")){
541 if (isset ($_POST['fon_group'])){
542 $this->fon_group= TRUE;
543 } else {
544 $this->fon_group= FALSE;
545 }
546 }
547 if ($this->acl_is_writeable("nagios_group")){
548 if (isset ($_POST['nagios_group'])){
549 $this->nagios_group= TRUE;
550 } else {
551 $this->nagios_group= FALSE;
552 }
553 }
554 }
555 }
558 /* Save to LDAP */
559 function save()
560 {
562 /* ID handling */
563 if ($this->force_gid == 0){
564 if ($this->saved_gidNumber != ""){
565 $this->gidNumber= $this->saved_gidNumber;
566 } else {
567 /* Calculate new, lock uids */
568 $wait= 10;
569 while (get_lock("uidnumber") != ""){
570 sleep (1);
572 /* timed out? */
573 if ($wait-- == 0){
574 break;
575 }
576 }
577 add_lock ("uidnumber", "gosa");
578 $this->gidNumber= $this->get_next_id("gidNumber");
579 }
580 }
582 plugin::save();
584 /* Remove objectClass for samba/phone support */
585 $tmp= array();
586 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
587 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
588 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
589 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
590 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
591 $tmp[]= $this->attrs['objectClass'][$i];
592 }
593 }
594 $this->attrs['objectClass']= $tmp;
595 $ldap= $this->config->get_ldap_link();
597 /* Add samba group functionality */
598 if ($this->samba3 && $this->smbgroup){
600 /* Fixed undefined index ...
601 */
602 $this->SID = $this->ridBase = "";
603 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
604 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
605 }else{
606 print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
607 }
608 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
609 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
610 }else{
611 print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
612 }
614 $this->attrs['objectClass'][]= 'sambaGroupMapping';
615 $this->attrs['sambaGroupType']= "2";
617 /* Check if we need to create a special entry */
618 if ($this->groupType == 0){
620 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
621 $gidNumber= $this->gidNumber;
622 while(TRUE){
623 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
624 $ldap->cd($this->config->current['BASE']);
625 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
626 if ($ldap->count() == 0){
627 break;
628 }
629 $gidNumber++;
630 }
631 $this->attrs['sambaSID']= $sid;
632 $this->sambaSID= $sid;
633 }
635 } else {
636 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
637 }
639 /* User wants me to fake the idMappings? This is useful for
640 making winbind resolve the group names in a reasonable amount
641 of time in combination with larger databases. */
642 if (isset($this->config->current['SAMBAIDMAPPING']) &&
643 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
644 $this->attrs['objectClass'][]= "sambaIdmapEntry";
645 }
647 }
649 /* Add phone functionality */
650 if ($this->fon_group){
651 $this->attrs['objectClass'][]= "goFonPickupGroup";
652 }
654 /* Add nagios functionality */
655 if ($this->nagios_group){
656 $this->attrs['objectClass'][]= "nagiosContactGroup";
657 }
659 /* Take members array */
660 if (count ($this->memberUid)){
661 $this->attrs['memberUid']= array_unique($this->memberUid);
662 }
664 /* New accounts need proper 'dn', propagate it to remaining objects */
665 if ($this->dn == 'new'){
666 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
667 }
669 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
670 new entries. So do a check first... */
671 $ldap->cat ($this->dn, array('dn'));
672 if ($ldap->fetch()){
673 /* Modify needs array() to remove values :-( */
674 if (!count ($this->memberUid)){
675 $this->attrs['memberUid']= array();
676 }
677 if ($this->samba3){
678 if (!$this->smbgroup){
679 $this->attrs['sambaGroupType']= array();
680 $this->attrs['sambaSID']= array();
681 }
682 }
683 $mode= "modify";
684 } else {
685 $mode= "add";
686 $ldap->cd($this->config->current['BASE']);
687 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
688 }
690 /* Write back to ldap */
691 $ldap->cd($this->dn);
692 $this->cleanup();
693 $ldap->$mode($this->attrs);
695 $ret= 0;
696 if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
697 $ret= 1;
698 }
700 /* Remove uid lock */
701 del_lock ("uidnumber");
703 /* Post that we've done*/
704 $this->handle_post_events($mode);
706 return ($ret);
707 }
709 function check()
710 {
711 /* Call common method to give check the hook */
712 $message= plugin::check();
714 /* Permissions for that base? */
715 if ($this->base != ""){
716 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
717 } else {
718 $new_dn= $this->dn;
719 }
721 if (!$this->acl_is_createable()){
722 $message[]= _("You have no permissions to create a group on this 'Base'.");
723 }
725 /* must: cn */
726 if ($this->cn == "" && $this->acl_is_writeable("cn")){
727 $message[]= "The required field 'Name' is not set.";
728 }
730 /* Check for valid input */
731 if (!is_uid($this->cn)){
732 $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
733 }
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 }
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");
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 /* Return plugin informations for acl handling */
857 function plInfo()
858 {
859 return (array(
860 "plShortName" => _("Generic"),
861 "plDescription" => _("Generic group settings"),
862 "plSelfModify" => FALSE,
863 "plDepends" => array(),
864 "plPriority" => 0,
865 "plSection" => array("admin"),
866 "plCategory" => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
868 "plProvidedAcls" => array(
869 "cn" => _("Name"),
870 "description" => _("Description"),
871 "base" => _("Base"),
873 "fonGroup" => _("Phone pickup group"),
874 "nagiosGroup" => _("Nagios group"),
876 "gidNumber" => _("GID"),
877 "memberUid" => _("Group member"),
878 "sambaGroupType" => _("Samba group type"),
879 "sambaDomainName" => _("Samba domain name"),
880 "sambaSID" => _("Samba SID"))
881 ));
882 }
883 }
885 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
886 ?>