4e28493250fc868cdd17729d30e1f59e4bc5283f
1 <?php
2 class group extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Handling of GOsa's base group object";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* Group attributes */
10 var $cn= "";
11 var $description= "";
12 var $gidNumber= "";
13 var $memberUid= array();
15 /* Helpers */
16 var $base= "";
17 var $force_gid= FALSE;
18 var $fon_group= FALSE;
19 var $smbgroup= FALSE;
20 var $groupType= FALSE;
21 var $samba3= FALSE;
22 var $sambaSID= "";
23 var $sambaDomainName= "DEFAULT";
24 var $SID= "";
25 var $ridBase= 0;
26 var $members= array();
27 var $users= array();
28 var $allusers= array();
29 var $department= "";
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 /* remove Release Tag if we have release management enabled
52 */
53 $tmp = search_config($config->data,"faiManagement","CLASS");
54 if(!empty($tmp)){
55 $this->description = preg_replace("/\(.*\)$/","",$this->description);
56 }
58 /* Load attributes depending on the samba version */
59 $this->samba3= ($config->current['SAMBAVERSION'] == 3);
60 $this->orig_dn= $dn;
61 $this->orig_cn= $this->cn;
63 /* Get member list */
64 if (isset($this->attrs['memberUid'][0])){
65 $tmp= array();
66 for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
67 $tmp[]= $this->attrs['memberUid'][$i];
68 }
69 $this->memberUid= $tmp;
70 sort ($this->memberUid);
71 }
73 /* Save gidNumber for later use */
74 if (isset($this->attrs['gidNumber'])){
75 $this->saved_gidNumber= $this->attrs['gidNumber'][0];
76 }
78 /* Is a samba group? */
79 if (isset($this->attrs['objectClass'])){
80 if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
81 $this->smbgroup= FALSE;
82 } else {
83 $this->smbgroup= TRUE;
84 if (isset($this->attrs['sambaSID'])){
85 $this->sambaSID= $this->attrs['sambaSID'][0];
86 }
87 }
88 if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
89 $this->fon_group= FALSE;
90 } else {
91 $this->fon_group= TRUE;
92 }
93 if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
94 $this->nagios_group= FALSE;
95 } else {
96 $this->nagios_group= TRUE;
97 }
98 }
100 /* Set mail flag */
101 if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
102 $this->has_mailAccount= TRUE;
103 }
105 /* Get samba Domain in case of samba 3 */
106 if ($this->samba3 && $this->sambaSID != ""){
107 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
108 $ldap= $this->config->get_ldap_link();
109 $ldap->cd($this->config->current['BASE']);
110 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
111 if ($ldap->count() != 0){
112 $attrs= $ldap->fetch();
113 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
115 /* Get domain name for SID */
116 $this->sambaDomainName= "DEFAULT";
117 foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
118 if ($val['SID'] == $this->SID){
119 $this->sambaDomainName= $key;
120 break;
121 }
122 }
123 } else {
124 if (isset($this->config->current['RIDBASE'])){
125 $this->sambaDomainName= "DEFAULT";
126 $this->ridBase= $this->config->current['RIDBASE'];
127 $this->SID= $this->config->current['SID'];
128 } else {
129 print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
130 }
131 }
133 /* Get group type */
134 $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
135 if ($this->groupType < 500 || $this->groupType > 553){
136 $this->groupType= 0;
137 }
138 $this->oldgroupType= $this->groupType;
139 }
141 /* Get global filter config */
142 if (!is_global("gufilter")){
143 $ui= get_userinfo();
144 $base= get_base_from_people($ui->dn);
145 $gufilter= array( "dselect" => $base,
146 "regex" => "*");
147 register_global("gufilter", $gufilter);
148 }
149 $gufilter= get_global('gufilter');
151 $gufilter['SubSearchGroup'] = false;
152 $gufilter['dselect'] = $_SESSION['gufilter']['dselect'];
154 register_global('gufilter',$gufilter);
156 if ($this->dn == "new"){
157 if(isset($_SESSION['CurrentMainBase'])){
158 $this->base= $_SESSION['CurrentMainBase'];
159 }else{
160 $ui= get_userinfo();
161 $this->base= dn2base($ui->dn);
162 }
163 } else {
164 $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
165 }
167 /* This is always an account */
168 $this->is_account= TRUE;
169 $this->reload();
170 }
172 function execute()
173 {
174 /* Call parent execute */
175 plugin::execute();
177 $ui= get_userinfo();
178 $acla= get_permissions ($ui->dn, $ui->subtreeACL);
179 $this->acl= get_module_permission($acla, "group", $ui->dn);
180 /* Do we represent a valid group? */
181 if (!$this->is_account && $this->parent == NULL){
182 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
183 _("This 'dn' is no group.")."</b>";
184 return ($display);
185 }
187 /* Delete user from group */
188 if (isset($_POST['del_users']) && isset($_POST['members'])){
189 foreach ($_POST['members'] as $value){
190 unset ($this->members["$value"]);
191 $this->removeUser($value);
192 }
193 $this->reload();
194 }
196 /* Add objects? */
197 if (isset($_POST["edit_membership"])){
198 $this->group_dialog= TRUE;
199 $this->dialog= TRUE;
200 }
202 /* Add objects finished? */
203 if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
204 $this->group_dialog= FALSE;
205 $this->dialog= FALSE;
206 }
208 /* Add user to group */
209 if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
210 foreach ($_POST['users'] as $value){
211 $this->members["$value"]= $this->allusers[$value];
212 asort($this->members);
213 $this->addUser($value);
214 }
215 $this->reload();
216 }
218 /* Base select dialog */
219 $once = true;
220 foreach($_POST as $name => $value){
221 if(preg_match("/^chooseBase/",$name) && $once){
222 $once = false;
223 $this->dialog = new baseSelectDialog($this->config);
224 $this->dialog->setCurrentBase($this->base);
225 }
226 }
228 /* Dialog handling */
229 if(is_object($this->dialog)){
230 /* Must be called before save_object */
231 $this->dialog->save_object();
233 if($this->dialog->isClosed()){
234 $this->dialog = false;
235 }elseif($this->dialog->isSelected()){
236 $this->base = $this->dialog->isSelected();
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'));
295 $smarty->assign("deplist", $this->config->idepartments);
296 $smarty->assign("alphabet", generate_alphabet());
297 foreach( array("dselect", "regex","SubSearchGroup") as $type){
298 $smarty->assign("$type", $gufilter[$type]);
299 }
300 $smarty->assign("hint", print_sizelimit_warning());
301 $smarty->assign("users", $this->displayUsers);
302 $smarty->assign("apply", apply_filter());
303 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
304 return ($display);
305 }
307 /* Bases / Departments */
308 if (isset($_POST['base'])){
309 $this->base= $_POST['base'];
310 }
312 $smarty->assign("bases", $this->config->idepartments);
313 $smarty->assign("base_select", $this->base);
314 $smarty->assign("department", $this->department);
316 if ($this->samba3){
317 $domains= array();
318 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
319 $domains[$name]= $name;
320 }
321 $smarty->assign("sambaDomains", $domains);
322 $smarty->assign("sambaDomainName", $this->sambaDomainName);
323 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
324 514 => _("Domain guests"));
326 /* Don't loose special groups! If not key'ed above, add it to
327 the combo box... */
328 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
329 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
330 }
332 $smarty->assign("groupTypes", $groupTypes);
333 $smarty->assign("groupType", $this->groupType);
334 }
336 /* Members and users */
337 $smarty->assign("members", $this->members);
339 /* Checkboxes */
340 foreach (array("force_gid", "smbgroup") as $val){
341 if ($this->$val == "1"){
342 $smarty->assign("$val", "checked");
343 } else {
344 $smarty->assign("$val", "");
345 }
346 }
347 if ($this->force_gid != "1"){
348 $smarty->assign("forceMode", "disabled");
349 }else{
350 $smarty->assign("forceMode", "");
351 }
352 $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
353 $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
354 if ($this->fon_group){
355 $smarty->assign("fon_group", "checked");
356 } else {
357 $smarty->assign("fon_group", "");
358 }
359 $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
361 if ($this->nagios_group){
362 $smarty->assign("nagios_group", "checked");
363 } else {
364 $smarty->assign("nagios_group", "");
365 }
366 $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
368 /* Fields */
369 foreach (array("cn", "description", "gidNumber") as $val){
370 $smarty->assign("$val", $this->$val);
371 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
372 }
374 /* Missing ACL's */
375 foreach (array("base", "smbgroup", "members") as $val){
376 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
377 }
379 /* Show main page */
380 $smarty->assign("alphabet", generate_alphabet(10));
381 $smarty->assign("search_image", get_template_path('images/search.png'));
382 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
383 $smarty->assign("tree_image", get_template_path('images/tree.png'));
384 $smarty->assign("deplist", $this->config->idepartments);
385 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
386 }
388 function addUser($uid)
389 {
390 $this->memberUid[]= $uid;
391 $this->memberUid= array_unique($this->memberUid);
392 }
394 function removeUser($uid)
395 {
396 $temp= array();
397 foreach ($this->memberUid as $value){
398 if ($value != $uid){
399 $temp[]= $value;
400 }
401 }
402 $this->memberUid= $temp;
403 }
406 /* Reload data */
407 function reload()
408 {
409 /* Fix regex string */
410 $gufilter = get_global("gufilter");
411 $regex = normalizeLdap($gufilter['regex']);
412 $MaxUser = $this->OnlyShowFirstEntries;
414 /* Prepare ldap link */
415 $ldap= $this->config->get_ldap_link();
416 $ldap->cd($gufilter['dselect']);
419 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
420 (Store gathered sn/givenName informations in $this->allusers too,
421 to be prepared when adding/deleting users)
422 */
423 $filter = "";
424 foreach ($this->memberUid as $value){
425 if(!isset($this->members[$value])){
426 $filter .= "(uid=".normalizeLdap($value).")";
427 }
428 }
429 if(!empty($filter)){
430 $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
431 while($attrs = $ldap->fetch()){
432 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
433 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
434 }
435 }
438 /* Create display list of users matching regex & filter
439 */
440 $this->displayUsers = array();
441 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
443 /* Search in current tree or within subtrees depending on the checkbox from filter section */
444 if($gufilter['SubSearchGroup']){
445 $ldap->search($filter, array("uid", "sn","givenName"));
446 }else{
447 $ldap->ls ($filter, get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
448 }
449 $i = 0;
451 /* Fetch all users and skip already used users */
452 while($attrs = $ldap->fetch()){
453 if(in_array($attrs['uid'][0], $this->memberUid)) {
454 continue;
455 }
456 $i ++;
457 if($i > $MaxUser) {
458 break;
459 }
460 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
461 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
462 }
464 /* If more than max users are found, display a message to warn the user */
465 if(($i == $MaxUser)){
466 print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
467 }
469 /* Sort lists */
470 natcasesort($this->members);
471 reset($this->members);
472 natcasesort ($this->displayUsers);
473 reset ($this->displayUsers);
474 }
477 /* Create display name, this was used so often that it is excluded into a seperate function */
478 function createResultName($attrs)
479 {
480 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
481 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
482 } else {
483 $ret= $attrs['uid'][0];
484 }
485 return($ret);
486 }
489 function remove_from_parent()
490 {
491 plugin::remove_from_parent();
493 $ldap= $this->config->get_ldap_link();
494 $ldap->rmdir($this->dn);
495 show_ldap_error($ldap->get_error());
497 /* Delete references to object groups */
498 $ldap->cd ($this->config->current['BASE']);
499 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
500 while ($ldap->fetch()){
501 $og= new ogroup($this->config, $ldap->getDN());
502 unset($og->member[$this->dn]);
503 $og->save ();
504 }
506 /* Send signal to the world that we've done */
507 $this->handle_post_events("remove");
508 }
511 /* Save data to object */
512 function save_object()
513 {
514 /* Save additional values for possible next step */
515 if (isset($_POST['groupedit'])){
517 plugin::save_object();
519 $this->force_gid= 0;
520 $this->smbgroup= 0;
521 foreach (array("force_gid", "department", "base", "smbgroup") as $val) {
522 if (chkacl ($this->acl, "$val") == "" && isset($_POST["$val"])){
523 $this->$val= $_POST["$val"];
524 }
525 }
527 /* Save sambaDomain attribute */
528 if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
529 isset ($_POST['sambaDomainName'])){
531 $this->sambaDomainName= $_POST['sambaDomainName'];
532 $this->groupType= $_POST['groupType'];
533 }
535 /* Save fon attribute */
536 if (chkacl ($this->acl, "fon_group") == ""){
537 if (isset ($_POST['fon_group'])){
538 $this->fon_group= TRUE;
539 } else {
540 $this->fon_group= FALSE;
541 }
542 }
543 if (chkacl ($this->acl, "nagios_group") == ""){
544 if (isset ($_POST['nagios_group'])){
545 $this->nagios_group= TRUE;
546 } else {
547 $this->nagios_group= FALSE;
548 }
549 }
550 }
551 }
554 /* Save to LDAP */
555 function save()
556 {
558 /* ID handling */
559 if ($this->force_gid == 0){
560 if ($this->saved_gidNumber != ""){
561 $this->gidNumber= $this->saved_gidNumber;
562 } else {
563 /* Calculate new, lock uids */
564 $wait= 10;
565 while (get_lock("uidnumber") != ""){
566 sleep (1);
568 /* timed out? */
569 if ($wait-- == 0){
570 break;
571 }
572 }
573 add_lock ("uidnumber", "gosa");
574 $this->gidNumber= $this->get_next_id("gidNumber");
575 }
576 }
578 /* If release management is enabled ....
579 Append release name to description tag ..
580 #FIXME release name within description is a very bad solution, use ldap attribute instead
581 */
582 $tmp = search_config($this->config->data,"faiManagement","CLASS");
583 if(!empty($tmp)){
584 if(isset($this->parent)){
585 if(isset($this->parent->by_object['appgroup'])){
586 $baseObj = $this->parent->by_object['appgroup'];
587 if($baseObj->is_account){
588 if(isset($baseObj->Release)){
589 $this->description .= " (".trim($baseObj->Release).")";
590 }
591 }
592 }
593 }
594 }
596 plugin::save();
598 /* Remove objectClass for samba/phone support */
599 $tmp= array();
600 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
601 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
602 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
603 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
604 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
605 $tmp[]= $this->attrs['objectClass'][$i];
606 }
607 }
608 $this->attrs['objectClass']= $tmp;
609 $ldap= $this->config->get_ldap_link();
611 /* Add samba group functionality */
612 if ($this->samba3 && $this->smbgroup){
614 /* Fixed undefined index ...
615 */
616 $this->SID = $this->ridBase = "";
617 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
618 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
619 }else{
620 print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
621 }
622 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
623 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
624 }else{
625 print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
626 }
628 $this->attrs['objectClass'][]= 'sambaGroupMapping';
629 $this->attrs['sambaGroupType']= "2";
631 /* Check if we need to create a special entry */
632 if ($this->groupType == 0){
634 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
635 $gidNumber= $this->gidNumber;
636 while(TRUE){
637 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
638 $ldap->cd($this->config->current['BASE']);
639 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
640 if ($ldap->count() == 0){
641 break;
642 }
643 $gidNumber++;
644 }
645 $this->attrs['sambaSID']= $sid;
646 $this->sambaSID= $sid;
647 }
649 } else {
650 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
651 }
653 /* User wants me to fake the idMappings? This is useful for
654 making winbind resolve the group names in a reasonable amount
655 of time in combination with larger databases. */
656 if (isset($this->config->current['SAMBAIDMAPPING']) &&
657 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
658 $this->attrs['objectClass'][]= "sambaIdmapEntry";
659 }
661 }
663 /* Add phone functionality */
664 if ($this->fon_group){
665 $this->attrs['objectClass'][]= "goFonPickupGroup";
666 }
668 /* Add nagios functionality */
669 if ($this->nagios_group){
670 $this->attrs['objectClass'][]= "nagiosContactGroup";
671 }
673 /* Take members array */
674 if (count ($this->memberUid)){
675 $this->attrs['memberUid']= array_unique($this->memberUid);
676 }
678 /* New accounts need proper 'dn', propagate it to remaining objects */
679 if ($this->dn == 'new'){
680 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
681 }
683 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
684 new entries. So do a check first... */
685 $ldap->cat ($this->dn);
686 if ($ldap->fetch()){
687 /* Modify needs array() to remove values :-( */
688 if (!count ($this->memberUid)){
689 $this->attrs['memberUid']= array();
690 }
691 if ($this->samba3){
692 if (!$this->smbgroup){
693 $this->attrs['sambaGroupType']= array();
694 $this->attrs['sambaSID']= array();
695 }
696 }
697 $mode= "modify";
698 } else {
699 $mode= "add";
700 $ldap->cd($this->config->current['BASE']);
701 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
702 }
704 /* Write back to ldap */
705 $ldap->cd($this->dn);
706 $this->cleanup();
707 $ldap->$mode($this->attrs);
709 $ret= 0;
710 if (show_ldap_error($ldap->get_error())){
711 $ret= 1;
712 }
714 /* Remove uid lock */
715 del_lock ("uidnumber");
717 /* Post that we've done*/
718 $this->handle_post_events($mode);
720 return ($ret);
721 }
723 function check()
724 {
725 /* Call common method to give check the hook */
726 $message= plugin::check();
728 /* Permissions for that base? */
729 if ($this->base != ""){
730 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
731 } else {
732 $new_dn= $this->dn;
733 }
735 $ui= get_userinfo();
736 $acl= get_permissions ($ui->dn, $ui->subtreeACL);
737 $acl= get_module_permission($acl, "group", $ui->dn);
738 if (chkacl($this->acl, "create") != ""){
739 $message[]= _("You have no permissions to create a group on this 'Base'.");
740 }
742 /* must: cn */
743 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
744 $message[]= "The required field 'Name' is not set.";
745 }
747 /* Check for valid input */
748 if (!is_uid($this->cn)){
749 $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
750 }
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 //FIXME: hardcoded ou=groups,
760 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))","ou=groups,".$this->base,array("cn"));
761 if ($ldap->count() != 0){
762 $message[]= _("Value specified as 'Name' is already used.");
763 }
764 }
766 }else{
768 /* Check for used 'cn' */
769 $ldap= $this->config->get_ldap_link();
770 $ldap->cd($this->config->current['BASE']);
771 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
772 if ($ldap->count() != 0){
774 /* New entry? */
775 if ($this->dn == 'new'){
776 $message[]= _("Value specified as 'Name' is already used.");
777 }
779 /* Moved? */
780 elseif ($new_dn != $this->orig_dn){
781 $ldap->fetch();
782 if ($ldap->getDN() != $this->orig_dn){
783 $message[]= _("Value specified as 'Name' is already used.");
784 }
785 }
786 }
787 }
789 /* Check ID */
790 if ($this->force_gid == "1"){
791 if (!is_id($this->gidNumber)){
792 $message[]= _("Value specified as 'GID' is not valid.");
793 } else {
794 if ($this->gidNumber < $this->config->current['MINID']){
795 $message[]= _("Value specified as 'GID' is too small.");
796 }
798 }
799 }
801 return ($message);
802 }
804 function get_next_id($attrib)
805 {
806 $ids= array();
807 $ldap= $this->config->get_ldap_link();
809 $ldap->cd ($this->config->current['BASE']);
810 if (preg_match('/gidNumber/i', $attrib)){
811 $oc= "posixGroup";
812 } else {
813 $oc= "posixAccount";
814 }
815 $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
817 /* Get list of ids */
818 while ($attrs= $ldap->fetch()){
819 $ids[]= (int)$attrs["$attrib"][0];
820 }
822 /* Find out next free id near to UID_BASE */
823 for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
824 if (!in_array($id, $ids)){
825 return ($id);
826 }
827 }
829 /* Should not happen */
830 if ($id == 65000){
831 print_red(_("Too many users, can't allocate a free ID!"));
832 exit;
833 }
834 }
836 function getCopyDialog()
837 {
838 $vars = array("cn");
840 if($this ->force_gid){
841 $used = " checked ";
842 $dis = "";
843 }else{
844 $used = "";
845 $dis = " disabled ";
846 }
848 $smarty = get_smarty();
849 $smarty->assign("used",$used);
850 $smarty->assign("dis" ,$dis);
851 $smarty->assign("cn" ,$this->cn);
852 $smarty->assign("gidNumber",$this->gidNumber);
853 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
854 $ret = array();
855 $ret['string'] = $str;
856 $ret['status'] = "";
857 return($ret);
858 }
860 function saveCopyDialog()
861 {
862 if(isset($_POST['cn'])){
863 $this->cn = $_POST['cn'];
864 }
865 if(isset($_POST['force_gid'])){
866 $this->force_gid = 1;
867 $this->gidNumber= $_POST['gidNumber'];
868 }else{
869 $this->force_gid = 0;
870 $this->gidNumber = false;
871 }
872 }
873 }
875 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
876 ?>