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);
150 if ($this->dn == "new"){
151 if(isset($_SESSION['CurrentMainBase'])){
152 $this->base= $_SESSION['CurrentMainBase'];
153 }else{
154 $ui= get_userinfo();
155 $this->base= dn2base($ui->dn);
156 }
157 } else {
158 $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
159 }
161 /* This is always an account */
162 $this->is_account= TRUE;
163 $this->reload();
164 }
166 function execute()
167 {
168 /* Call parent execute */
169 plugin::execute();
171 $ui= get_userinfo();
172 $acla= get_permissions ($ui->dn, $ui->subtreeACL);
173 $this->acl= get_module_permission($acla, "group", $ui->dn);
174 /* Do we represent a valid group? */
175 if (!$this->is_account && $this->parent == NULL){
176 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
177 _("This 'dn' is no group.")."</b>";
178 return ($display);
179 }
181 /* Delete user from group */
182 if (isset($_POST['del_users']) && isset($_POST['members'])){
183 foreach ($_POST['members'] as $value){
184 unset ($this->members["$value"]);
185 $this->removeUser($value);
186 }
187 $this->reload();
188 }
190 /* Add objects? */
191 if (isset($_POST["edit_membership"])){
192 $this->group_dialog= TRUE;
193 $this->dialog= TRUE;
194 }
196 /* Add objects finished? */
197 if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
198 $this->group_dialog= FALSE;
199 $this->dialog= FALSE;
200 }
202 /* Add user to group */
203 if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
204 foreach ($_POST['users'] as $value){
205 $this->members["$value"]= $this->allusers[$value];
206 asort($this->members);
207 $this->addUser($value);
208 }
209 $this->reload();
210 }
212 /* Base select dialog */
213 $once = true;
214 foreach($_POST as $name => $value){
215 if(preg_match("/^chooseBase/",$name) && $once){
216 $once = false;
217 $this->dialog = new baseSelectDialog($this->config,$this);
218 $this->dialog->setCurrentBase($this->base);
219 }
220 }
222 /* Dialog handling */
223 if(is_object($this->dialog)){
224 /* Must be called before save_object */
225 $this->dialog->save_object();
227 if($this->dialog->isClosed()){
228 $this->dialog = false;
229 }elseif($this->dialog->isSelected()){
230 $this->base = $this->dialog->isSelected();
231 $this->dialog= false;
232 }else{
233 return($this->dialog->execute());
234 }
235 }
237 /* Assign templating stuff */
238 $smarty= get_smarty();
239 if ($this->samba3){
240 $smarty->assign("samba3", "true");
241 } else {
242 $smarty->assign("samba3", "");
243 }
245 if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
246 $smarty->assign("nagios",true);
247 }else{
248 $smarty->assign("nagios",false);
249 }
251 if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
252 $smarty->assign("pickupGroup",true);
253 }else{
254 $smarty->assign("pickupGroup",false);
255 }
257 /* Manage object add dialog */
258 if ($this->group_dialog){
260 /* Save data */
261 $gufilter= get_global("gufilter");
262 foreach( array("dselect", "regex") as $type){
263 if (isset($_POST[$type])){
264 $gufilter[$type]= $_POST[$type];
265 }
266 }
267 if(isset($_POST['regex'])){
268 if(isset($_POST['SubSearchGroup'])){
269 $gufilter['SubSearchGroup'] = true;
270 }else{
271 $gufilter['SubSearchGroup'] = false;
272 }
273 }
275 if (isset($_GET['search'])){
276 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
277 if ($s == "**"){
278 $s= "*";
279 }
280 $gufilter['regex']= $s;
281 }
282 register_global("gufilter", $gufilter);
283 $this->reload();
285 /* Show dialog */
286 $smarty->assign("search_image", get_template_path('images/search.png'));
287 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
288 $smarty->assign("tree_image", get_template_path('images/tree.png'));
289 $smarty->assign("deplist", $this->config->idepartments);
290 $smarty->assign("alphabet", generate_alphabet());
291 foreach( array("dselect", "regex","SubSearchGroup") as $type){
292 $smarty->assign("$type", $gufilter[$type]);
293 }
294 $smarty->assign("hint", print_sizelimit_warning());
295 $smarty->assign("users", $this->displayUsers);
296 $smarty->assign("apply", apply_filter());
297 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
298 return ($display);
299 }
301 /* Bases / Departments */
302 if (isset($_POST['base'])){
303 $this->base= $_POST['base'];
304 }
306 $smarty->assign("bases", $this->config->idepartments);
307 $smarty->assign("base_select", $this->base);
308 $smarty->assign("department", $this->department);
310 if ($this->samba3){
311 $domains= array();
312 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
313 $domains[$name]= $name;
314 }
315 $smarty->assign("sambaDomains", $domains);
316 $smarty->assign("sambaDomainName", $this->sambaDomainName);
317 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
318 514 => _("Domain guests"));
320 /* Don't loose special groups! If not key'ed above, add it to
321 the combo box... */
322 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
323 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
324 }
326 $smarty->assign("groupTypes", $groupTypes);
327 $smarty->assign("groupType", $this->groupType);
328 }
330 /* Members and users */
331 $smarty->assign("members", $this->members);
333 /* Checkboxes */
334 foreach (array("force_gid", "smbgroup") as $val){
335 if ($this->$val == "1"){
336 $smarty->assign("$val", "checked");
337 } else {
338 $smarty->assign("$val", "");
339 }
340 }
341 if ($this->force_gid != "1"){
342 $smarty->assign("forceMode", "disabled");
343 }else{
344 $smarty->assign("forceMode", "");
345 }
346 $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
347 $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
348 if ($this->fon_group){
349 $smarty->assign("fon_group", "checked");
350 } else {
351 $smarty->assign("fon_group", "");
352 }
353 $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
355 if ($this->nagios_group){
356 $smarty->assign("nagios_group", "checked");
357 } else {
358 $smarty->assign("nagios_group", "");
359 }
360 $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
362 /* Fields */
363 foreach (array("cn", "description", "gidNumber") as $val){
364 $smarty->assign("$val", $this->$val);
365 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
366 }
368 /* Missing ACL's */
369 foreach (array("base", "smbgroup", "members") as $val){
370 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
371 }
373 /* Show main page */
374 $smarty->assign("alphabet", generate_alphabet(10));
375 $smarty->assign("search_image", get_template_path('images/search.png'));
376 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
377 $smarty->assign("tree_image", get_template_path('images/tree.png'));
378 $smarty->assign("deplist", $this->config->idepartments);
379 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
380 }
382 function addUser($uid)
383 {
384 $this->memberUid[]= $uid;
385 $this->memberUid= array_unique($this->memberUid);
386 }
388 function removeUser($uid)
389 {
390 $temp= array();
391 foreach ($this->memberUid as $value){
392 if ($value != $uid){
393 $temp[]= $value;
394 }
395 }
396 $this->memberUid= $temp;
397 }
400 /* Reload data */
401 function reload()
402 {
403 /* Fix regex string */
404 $gufilter = get_global("gufilter");
405 $regex = normalizeLdap($gufilter['regex']);
406 $MaxUser = $this->OnlyShowFirstEntries;
408 /* Prepare ldap link */
409 $ldap= $this->config->get_ldap_link();
410 $ldap->cd($gufilter['dselect']);
413 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
414 (Store gathered sn/givenName informations in $this->allusers too,
415 to be prepared when adding/deleting users)
416 */
417 $filter = "";
418 foreach ($this->memberUid as $value){
419 if(!isset($this->members[$value])){
420 $filter .= "(uid=".normalizeLdap($value).")";
421 }
422 }
423 if(!empty($filter)){
424 $ldap->cd($this->config->current['BASE']);
425 $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
426 while($attrs = $ldap->fetch()){
427 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
428 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
429 }
430 }
432 /* check if all uids are resolved */
433 foreach ($this->memberUid as $value){
434 if(!isset($this->members[$value])){
435 $this->members[$value] = _("! unknown id")." [".$value."]";
436 }
437 }
439 /* Create display list of users matching regex & filter
440 */
441 $this->displayUsers = array();
442 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
444 /* Search in current tree or within subtrees depending on the checkbox from filter section */
445 if($gufilter['SubSearchGroup']){
446 $ldap->search($filter, array("uid", "sn","givenName"));
447 }else{
448 $ldap->ls ($filter, get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
449 }
450 $i = 0;
452 /* Fetch all users and skip already used users */
453 while($attrs = $ldap->fetch()){
454 if(in_array($attrs['uid'][0], $this->memberUid)) {
455 continue;
456 }
457 $i ++;
458 if($i > $MaxUser) {
459 break;
460 }
461 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
462 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
463 }
465 /* If more than max users are found, display a message to warn the user */
466 if(($i == $MaxUser)){
467 print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
468 }
470 /* Sort lists */
471 natcasesort($this->members);
472 reset($this->members);
473 natcasesort ($this->displayUsers);
474 reset ($this->displayUsers);
475 }
478 /* Create display name, this was used so often that it is excluded into a seperate function */
479 function createResultName($attrs)
480 {
481 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
482 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
483 } else {
484 $ret= $attrs['uid'][0];
485 }
486 return($ret);
487 }
490 function remove_from_parent()
491 {
492 plugin::remove_from_parent();
494 $ldap= $this->config->get_ldap_link();
495 $ldap->rmdir($this->dn);
496 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
498 /* Delete references to object groups */
499 $ldap->cd ($this->config->current['BASE']);
500 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
501 while ($ldap->fetch()){
502 $og= new ogroup($this->config, $ldap->getDN());
503 unset($og->member[$this->dn]);
504 $og->save ();
505 }
507 /* Send signal to the world that we've done */
508 $this->handle_post_events("remove");
509 }
512 /* Save data to object */
513 function save_object()
514 {
515 /* Save additional values for possible next step */
516 if (isset($_POST['groupedit'])){
518 plugin::save_object();
520 $this->force_gid= 0;
521 $this->smbgroup= 0;
522 foreach (array("force_gid", "department", "base", "smbgroup") as $val) {
523 if (chkacl ($this->acl, "$val") == "" && isset($_POST["$val"])){
524 $this->$val= $_POST["$val"];
525 }
526 }
528 /* Save sambaDomain attribute */
529 if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
530 isset ($_POST['sambaDomainName'])){
532 $this->sambaDomainName= $_POST['sambaDomainName'];
533 $this->groupType= $_POST['groupType'];
534 }
536 /* Save fon attribute */
537 if (chkacl ($this->acl, "fon_group") == ""){
538 if (isset ($_POST['fon_group'])){
539 $this->fon_group= TRUE;
540 } else {
541 $this->fon_group= FALSE;
542 }
543 }
544 if (chkacl ($this->acl, "nagios_group") == ""){
545 if (isset ($_POST['nagios_group'])){
546 $this->nagios_group= TRUE;
547 } else {
548 $this->nagios_group= FALSE;
549 }
550 }
551 }
552 }
555 /* Save to LDAP */
556 function save()
557 {
559 /* ID handling */
560 if ($this->force_gid == 0){
561 if ($this->saved_gidNumber != ""){
562 $this->gidNumber= $this->saved_gidNumber;
563 } else {
564 /* Calculate new, lock uids */
565 $wait= 10;
566 while (get_lock("uidnumber") != ""){
567 sleep (1);
569 /* timed out? */
570 if ($wait-- == 0){
571 break;
572 }
573 }
574 add_lock ("uidnumber", "gosa");
575 $this->gidNumber= $this->get_next_id("gidNumber");
576 }
577 }
579 plugin::save();
581 /* Remove objectClass for samba/phone support */
582 $tmp= array();
583 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
584 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
585 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
586 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
587 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
588 $tmp[]= $this->attrs['objectClass'][$i];
589 }
590 }
591 $this->attrs['objectClass']= $tmp;
592 $ldap= $this->config->get_ldap_link();
594 /* Add samba group functionality */
595 if ($this->samba3 && $this->smbgroup){
597 /* Fixed undefined index ...
598 */
599 $this->SID = $this->ridBase = "";
600 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
601 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
602 }else{
603 print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
604 }
605 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
606 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
607 }else{
608 print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
609 }
611 $this->attrs['objectClass'][]= 'sambaGroupMapping';
612 $this->attrs['sambaGroupType']= "2";
614 /* Check if we need to create a special entry */
615 if ($this->groupType == 0){
617 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
618 $gidNumber= $this->gidNumber;
619 while(TRUE){
620 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
621 $ldap->cd($this->config->current['BASE']);
622 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
623 if ($ldap->count() == 0){
624 break;
625 }
626 $gidNumber++;
627 }
628 $this->attrs['sambaSID']= $sid;
629 $this->sambaSID= $sid;
630 }
632 } else {
633 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
634 }
636 /* User wants me to fake the idMappings? This is useful for
637 making winbind resolve the group names in a reasonable amount
638 of time in combination with larger databases. */
639 if (isset($this->config->current['SAMBAIDMAPPING']) &&
640 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
641 $this->attrs['objectClass'][]= "sambaIdmapEntry";
642 }
644 }
646 /* Add phone functionality */
647 if ($this->fon_group){
648 $this->attrs['objectClass'][]= "goFonPickupGroup";
649 }
651 /* Add nagios functionality */
652 if ($this->nagios_group){
653 $this->attrs['objectClass'][]= "nagiosContactGroup";
654 }
656 /* Take members array */
657 if (count ($this->memberUid)){
658 $this->attrs['memberUid']= array_unique($this->memberUid);
659 }
661 /* New accounts need proper 'dn', propagate it to remaining objects */
662 if ($this->dn == 'new'){
663 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
664 }
666 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
667 new entries. So do a check first... */
668 $ldap->cat ($this->dn, array('dn'));
669 if ($ldap->fetch()){
670 /* Modify needs array() to remove values :-( */
671 if (!count ($this->memberUid)){
672 $this->attrs['memberUid']= array();
673 }
674 if ($this->samba3){
675 if (!$this->smbgroup){
676 $this->attrs['sambaGroupType']= array();
677 $this->attrs['sambaSID']= array();
678 }
679 }
680 $mode= "modify";
681 } else {
682 $mode= "add";
683 $ldap->cd($this->config->current['BASE']);
684 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
685 }
687 /* Write back to ldap */
688 $ldap->cd($this->dn);
689 $this->cleanup();
690 $ldap->$mode($this->attrs);
692 $ret= 0;
693 if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
694 $ret= 1;
695 }
697 /* Remove uid lock */
698 del_lock ("uidnumber");
700 /* Post that we've done*/
701 $this->handle_post_events($mode);
703 return ($ret);
704 }
706 function check()
707 {
708 /* Call common method to give check the hook */
709 $message= plugin::check();
711 /* Permissions for that base? */
712 if ($this->base != ""){
713 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
714 } else {
715 $new_dn= $this->dn;
716 }
718 $ui= get_userinfo();
719 $acl= get_permissions ($ui->dn, $ui->subtreeACL);
720 $acl= get_module_permission($acl, "group", $ui->dn);
721 if (chkacl($this->acl, "create") != ""){
722 $message[]= _("You have no permissions to create a group on this 'Base'.");
723 }
725 /* must: cn */
726 if ($this->cn == "" && chkacl ($this->acl, "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 }
736 if($this->allowGroupsWithSameNameInOtherSubtrees == true){
738 /* Check for used 'cn' */
739 $ldap= $this->config->get_ldap_link();
740 if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
741 $ldap->cd("ou=groups,".$this->base);
742 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
743 if ($ldap->count() != 0){
744 $message[]= _("Value specified as 'Name' is already used.");
745 }
746 }
748 }else{
750 /* Check for used 'cn' */
751 $ldap= $this->config->get_ldap_link();
752 $ldap->cd($this->config->current['BASE']);
753 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
754 if ($ldap->count() != 0){
756 /* New entry? */
757 if ($this->dn == 'new'){
758 $message[]= _("Value specified as 'Name' is already used.");
759 }
761 /* Moved? */
762 elseif ($new_dn != $this->orig_dn){
763 $ldap->fetch();
764 if ($ldap->getDN() != $this->orig_dn){
765 $message[]= _("Value specified as 'Name' is already used.");
766 }
767 }
768 }
769 }
771 /* Check ID */
772 if ($this->force_gid == "1"){
773 if (!is_id($this->gidNumber)){
774 $message[]= _("Value specified as 'GID' is not valid.");
775 } else {
776 if ($this->gidNumber < $this->config->current['MINID']){
777 $message[]= _("Value specified as 'GID' is too small.");
778 }
780 }
781 }
783 return ($message);
784 }
786 function get_next_id($attrib)
787 {
788 $ids= array();
789 $ldap= $this->config->get_ldap_link();
791 $ldap->cd ($this->config->current['BASE']);
792 if (preg_match('/gidNumber/i', $attrib)){
793 $oc= "posixGroup";
794 } else {
795 $oc= "posixAccount";
796 }
797 $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
799 /* Get list of ids */
800 while ($attrs= $ldap->fetch()){
801 $ids[]= (int)$attrs["$attrib"][0];
802 }
804 /* Find out next free id near to UID_BASE */
805 for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
806 if (!in_array($id, $ids)){
807 return ($id);
808 }
809 }
811 /* Should not happen */
812 if ($id == 65000){
813 print_red(_("Too many users, can't allocate a free ID!"));
814 exit;
815 }
816 }
818 function getCopyDialog()
819 {
820 $vars = array("cn");
822 if($this ->force_gid){
823 $used = " checked ";
824 $dis = "";
825 }else{
826 $used = "";
827 $dis = " disabled ";
828 }
830 $smarty = get_smarty();
831 $smarty->assign("used",$used);
832 $smarty->assign("dis" ,$dis);
833 $smarty->assign("cn" ,$this->cn);
834 $smarty->assign("gidNumber",$this->gidNumber);
835 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
836 $ret = array();
837 $ret['string'] = $str;
838 $ret['status'] = "";
839 return($ret);
840 }
842 function saveCopyDialog()
843 {
844 if(isset($_POST['cn'])){
845 $this->cn = $_POST['cn'];
846 }
847 if(isset($_POST['force_gid'])){
848 $this->force_gid = 1;
849 $this->gidNumber= $_POST['gidNumber'];
850 }else{
851 $this->force_gid = 0;
852 $this->gidNumber = false;
853 }
854 }
855 }
857 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
858 ?>