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 {
158 /* Get object base */
159 $this->base =preg_replace ("/^[^,]+,".normalizePreg(get_groups_ou())."/","",$this->dn);
160 }
162 /* This is always an account */
163 $this->is_account= TRUE;
164 $this->reload();
165 }
167 function execute()
168 {
169 /* Call parent execute */
170 plugin::execute();
172 /* Do we represent a valid group? */
173 if (!$this->is_account && $this->parent == NULL){
174 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
175 _("This 'dn' is no group.")."</b>";
176 return ($display);
177 }
179 /* Delete user from group */
180 if (isset($_POST['del_users']) && isset($_POST['members'])){
181 foreach ($_POST['members'] as $value){
182 unset ($this->members["$value"]);
183 $this->removeUser($value);
184 }
185 $this->reload();
186 }
188 /* Add objects? */
189 if (isset($_POST["edit_membership"])){
190 $this->group_dialog= TRUE;
191 $this->dialog= TRUE;
192 }
194 /* Add objects finished? */
195 if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
196 $this->group_dialog= FALSE;
197 $this->dialog= FALSE;
198 }
200 /* Add user to group */
201 if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
202 foreach ($_POST['users'] as $value){
203 $this->members["$value"]= $this->allusers[$value];
204 asort($this->members);
205 $this->addUser($value);
206 }
207 $this->reload();
208 }
210 /* Base select dialog */
211 $once = true;
212 foreach($_POST as $name => $value){
213 if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
215 $once = false;
216 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
217 $this->dialog->setCurrentBase($this->base);
218 }
219 }
221 /* Dialog handling */
222 if(is_object($this->dialog)){
223 /* Must be called before save_object */
224 $this->dialog->save_object();
226 if($this->dialog->isClosed()){
227 $this->dialog = false;
228 }elseif($this->dialog->isSelected()){
229 if($this->acl_is_moveable()){
230 $this->base = $this->dialog->isSelected();
231 }
232 $this->dialog= false;
233 }else{
234 return($this->dialog->execute());
235 }
236 }
238 /* Assign templating stuff */
239 $smarty= get_smarty();
240 if ($this->samba3){
241 $smarty->assign("samba3", "true");
242 } else {
243 $smarty->assign("samba3", "");
244 }
246 if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
247 $smarty->assign("nagios",true);
248 }else{
249 $smarty->assign("nagios",false);
250 }
252 if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
253 $smarty->assign("pickupGroup",true);
254 }else{
255 $smarty->assign("pickupGroup",false);
256 }
258 /* Assign base ACL */
259 $baseACL = $this->getacl("base");
260 if(!$this->acl_is_moveable()) {
261 $baseACL = preg_replace("/w/","",$baseACL);
262 }
263 $smarty->assign("baseACL", $baseACL);
265 /* Manage object add dialog */
266 if ($this->group_dialog){
268 /* Save data */
269 $gufilter= get_global("gufilter");
270 foreach( array("dselect", "regex") as $type){
271 if (isset($_POST[$type])){
272 $gufilter[$type]= $_POST[$type];
273 }
274 }
275 if(isset($_POST['regex'])){
276 if(isset($_POST['SubSearchGroup'])){
277 $gufilter['SubSearchGroup'] = true;
278 }else{
279 $gufilter['SubSearchGroup'] = false;
280 }
281 }
283 if (isset($_GET['search'])){
284 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
285 if ($s == "**"){
286 $s= "*";
287 }
288 $gufilter['regex']= $s;
289 }
290 register_global("gufilter", $gufilter);
291 $this->reload();
293 /* Show dialog */
294 $smarty->assign("search_image", get_template_path('images/search.png'));
295 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
296 $smarty->assign("tree_image", get_template_path('images/tree.png'));
298 $smarty->assign("deplist", $this->get_allowed_bases("users/user"));
299 $smarty->assign("alphabet", generate_alphabet());
300 foreach( array("dselect", "regex","SubSearchGroup") as $type){
301 $smarty->assign("$type", $gufilter[$type]);
302 }
303 $smarty->assign("hint", print_sizelimit_warning());
304 $smarty->assign("users", $this->displayUsers);
305 $smarty->assign("apply", apply_filter());
306 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
307 return ($display);
308 }
310 /* Bases / Departments */
311 if (isset($_POST['base'])){
312 $this->base= $_POST['base'];
313 }
315 $smarty->assign("bases", $this->get_allowed_bases());
316 $smarty->assign("base_select", $this->base);
318 if ($this->samba3){
319 $domains= array();
320 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
321 $domains[$name]= $name;
322 }
323 $smarty->assign("sambaDomains", $domains);
324 $smarty->assign("sambaDomainName", $this->sambaDomainName);
325 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
326 514 => _("Domain guests"));
328 /* Don't loose special groups! If not key'ed above, add it to
329 the combo box... */
330 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
331 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
332 }
334 $smarty->assign("groupTypes", $groupTypes);
335 $smarty->assign("groupType", $this->groupType);
336 }
338 /* Members and users */
339 $smarty->assign("members", $this->members);
341 /* Checkboxes */
342 foreach (array("force_gid", "smbgroup") as $val){
343 if ($this->$val == "1"){
344 $smarty->assign("$val", "checked");
345 } else {
346 $smarty->assign("$val", "");
347 }
348 }
349 if ($this->force_gid != "1"){
350 $smarty->assign("forceMode", "disabled");
351 }else{
352 $smarty->assign("forceMode", "");
353 }
354 if ($this->fon_group){
355 $smarty->assign("fon_group", "checked");
356 } else {
357 $smarty->assign("fon_group", "");
358 }
360 if ($this->nagios_group){
361 $smarty->assign("nagios_group", "checked");
362 } else {
363 $smarty->assign("nagios_group", "");
364 }
366 /* Fields */
367 foreach (array("cn", "description", "gidNumber") as $val){
368 $smarty->assign("$val", $this->$val);
369 }
371 $tmp = $this->plInfo();
372 foreach($tmp['plProvidedAcls'] as $name => $translation){
373 $smarty->assign($name."ACL",$this->getacl($name));
374 }
376 if($this->acl_is_writeable("base")){
377 $smarty->assign("baseSelect",true);
378 }else{
379 $smarty->assign("baseSelect",false);
380 }
382 /* Show main page */
383 $smarty->assign("alphabet", generate_alphabet(10));
384 $smarty->assign("search_image", get_template_path('images/search.png'));
385 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
386 $smarty->assign("tree_image", get_template_path('images/tree.png'));
387 $smarty->assign("deplist", $this->config->idepartments);
388 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
389 }
391 function addUser($uid)
392 {
393 $this->memberUid[]= $uid;
394 $this->memberUid= array_unique($this->memberUid);
395 }
397 function removeUser($uid)
398 {
399 $temp= array();
400 foreach ($this->memberUid as $value){
401 if ($value != $uid){
402 $temp[]= $value;
403 }
404 }
405 $this->memberUid= $temp;
406 }
409 /* Reload data */
410 function reload()
411 {
412 /* Fix regex string */
413 $gufilter = get_global("gufilter");
414 $regex = normalizeLdap($gufilter['regex']);
415 $MaxUser = $this->OnlyShowFirstEntries;
417 /* Prepare ldap link */
418 $ldap= $this->config->get_ldap_link();
419 $ldap->cd($gufilter['dselect']);
422 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
423 (Store gathered sn/givenName informations in $this->allusers too,
424 to be prepared when adding/deleting users)
425 */
426 $filter = "";
427 foreach ($this->memberUid as $value){
428 if(!isset($this->members[$value])){
429 $filter .= "(uid=".normalizeLdap($value).")";
430 }
431 }
432 if(!empty($filter)){
433 $ldap->cd($this->config->current['BASE']);
434 $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
435 while($attrs = $ldap->fetch()){
436 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
437 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
438 }
439 }
441 /* check if all uids are resolved */
442 foreach ($this->memberUid as $value){
443 if(!isset($this->members[$value])){
444 $this->members[$value] = _("! unknown id")." [".$value."]";
445 }
446 }
448 /* Create display list of users matching regex & filter
449 */
450 $this->displayUsers = array();
451 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
453 /* Search in current tree or within subtrees depending on the checkbox from filter section */
454 if($gufilter['SubSearchGroup']){
455 $flag = GL_SIZELIMIT | GL_SUBSEARCH;
456 $base = $gufilter['dselect'];
457 }else{
458 $flag = GL_SIZELIMIT ;
459 $base = get_people_ou().$gufilter['dselect'];
460 }
461 $i = 0;
464 $res = get_list($filter,"users",$base,array("uid", "sn", "givenName"),$flag);
466 /* Fetch all users and skip already used users */
467 foreach($res as $attrs){
468 if(in_array($attrs['uid'][0], $this->memberUid)) {
469 continue;
470 }
471 $i ++;
472 if($i > $MaxUser) {
473 break;
474 }
475 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
476 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
477 }
479 /* If more than max users are found, display a message to warn the user */
480 if(($i == $MaxUser)){
481 print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
482 }
484 /* Sort lists */
485 natcasesort($this->members);
486 reset($this->members);
487 natcasesort ($this->displayUsers);
488 reset ($this->displayUsers);
489 }
492 /* Create display name, this was used so often that it is excluded into a seperate function */
493 function createResultName($attrs)
494 {
495 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
496 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
497 } else {
498 $ret= $attrs['uid'][0];
499 }
500 return($ret);
501 }
504 function remove_from_parent()
505 {
506 plugin::remove_from_parent();
508 $ldap= $this->config->get_ldap_link();
509 $ldap->rmdir($this->dn);
510 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
512 /* Delete references to object groups */
513 $ldap->cd ($this->config->current['BASE']);
514 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
515 while ($ldap->fetch()){
516 $og= new ogroup($this->config, $ldap->getDN());
517 unset($og->member[$this->dn]);
518 $og->save ();
519 }
521 /* Send signal to the world that we've done */
522 $this->handle_post_events("remove");
523 }
526 /* Save data to object */
527 function save_object()
528 {
529 /* Save additional values for possible next step */
530 if (isset($_POST['groupedit'])){
532 plugin::save_object();
534 $this->force_gid= 0;
537 /* Only reset sambagroup flag if we are able to write this flag */
538 if($this->acl_is_writeable("sambaGroupType")){
539 $this->smbgroup = 0;
540 }
542 /* Get base selection */
543 if($this->acl_is_moveable() && isset($_POST['base'])){
544 $this->base = $_POST['base'];
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");
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 if ($this->orig_dn == "new" && !$this->acl_is_createable()){
744 $message[]= _("You have no permissions to create a group on this 'Base'.");
745 }
747 /* must: cn */
748 if ($this->cn == "" && $this->acl_is_writeable("cn")){
749 $message[]= "The required field 'Name' is not set.";
750 }
752 /* Check for valid input */
753 if (!is_uid($this->cn)){
754 $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
755 }
757 if($this->allowGroupsWithSameNameInOtherSubtrees == true){
759 /* Check for used 'cn' */
760 $ldap= $this->config->get_ldap_link();
761 if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
762 $ldap->cd("ou=groups,".$this->base);
763 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
764 if ($ldap->count() != 0){
765 $message[]= _("Value specified as 'Name' is already used.");
766 }
767 }
769 }else{
771 /* Check for used 'cn' */
772 $ldap= $this->config->get_ldap_link();
773 $ldap->cd($this->config->current['BASE']);
774 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
775 if ($ldap->count() != 0){
777 /* New entry? */
778 if ($this->dn == 'new'){
779 $message[]= _("Value specified as 'Name' is already used.");
780 }
782 /* Moved? */
783 elseif ($new_dn != $this->orig_dn){
784 $ldap->fetch();
785 if ($ldap->getDN() != $this->orig_dn){
786 $message[]= _("Value specified as 'Name' is already used.");
787 }
788 }
789 }
790 }
792 /* Check ID */
793 if ($this->force_gid == "1"){
794 if (!is_id($this->gidNumber)){
795 $message[]= _("Value specified as 'GID' is not valid.");
796 } else {
797 if ($this->gidNumber < $this->config->current['MINID']){
798 $message[]= _("Value specified as 'GID' is too small.");
799 }
801 }
802 }
804 return ($message);
805 }
807 function get_next_id($attrib)
808 {
809 $ids= array();
810 $ldap= $this->config->get_ldap_link();
812 $ldap->cd ($this->config->current['BASE']);
813 if (preg_match('/gidNumber/i', $attrib)){
814 $oc= "posixGroup";
815 } else {
816 $oc= "posixAccount";
817 }
818 $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
820 /* Get list of ids */
821 while ($attrs= $ldap->fetch()){
822 $ids[]= (int)$attrs["$attrib"][0];
823 }
825 /* Find out next free id near to UID_BASE */
826 for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
827 if (!in_array($id, $ids)){
828 return ($id);
829 }
830 }
832 /* Should not happen */
833 if ($id == 65000){
834 print_red(_("Too many users, can't allocate a free ID!"));
835 exit;
836 }
837 }
839 function getCopyDialog()
840 {
841 $vars = array("cn");
843 if($this ->force_gid){
844 $used = " checked ";
845 $dis = "";
846 }else{
847 $used = "";
848 $dis = " disabled ";
849 }
851 $smarty = get_smarty();
852 $smarty->assign("used",$used);
853 $smarty->assign("dis" ,$dis);
854 $smarty->assign("cn" ,$this->cn);
855 $smarty->assign("gidNumber",$this->gidNumber);
856 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
857 $ret = array();
858 $ret['string'] = $str;
859 $ret['status'] = "";
860 return($ret);
861 }
863 function saveCopyDialog()
864 {
865 if(isset($_POST['cn'])){
866 $this->cn = $_POST['cn'];
867 }
868 if(isset($_POST['force_gid'])){
869 $this->force_gid = 1;
870 $this->gidNumber= $_POST['gidNumber'];
871 }else{
872 $this->force_gid = 0;
873 $this->gidNumber = false;
874 }
875 }
878 /* Return plugin informations for acl handling */
879 function plInfo()
880 {
881 return (array(
882 "plShortName" => _("Generic"),
883 "plDescription" => _("Generic group settings"),
884 "plSelfModify" => FALSE,
885 "plDepends" => array(),
886 "plPriority" => 0,
887 "plSection" => array("admin"),
888 "plCategory" => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
890 "plProvidedAcls" => array(
891 "cn" => _("Name"),
892 "base" => _("Base"),
893 "description" => _("Description"),
895 "fonGroup" => _("Phone pickup group"),
896 "nagiosGroup" => _("Nagios group"),
898 "gidNumber" => _("GID"),
899 "memberUid" => _("Group member"),
900 "sambaGroupType" => _("Samba group type"),
901 "sambaDomainName" => _("Samba domain name"),
902 "sambaSID" => _("Samba SID"))
903 ));
904 }
905 }
907 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
908 ?>