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 $member= array();
30 var $allusers= array();
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 $rfc2307bis= FALSE;
41 var $OnlyShowFirstEntries =200;
42 var $dnMapping= array();
43 var $view_logged = FALSE;
44 var $allowGroupsWithSameNameInOtherSubtrees = true;
46 /* attribute list for save action */
47 var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
48 var $objectclasses= array("top", "posixGroup");
50 var $CopyPasteVars = array("force_gid","fon_group","smbgroup","groupType","sambaSID","sambaDomainName","SID","nagios_group","sambaGroupType");
52 function group ($config, $dn= NULL)
53 {
54 /* Set rfc2307bis flag */
55 if (isset($config->current['RFC2307BIS']) && ($config->current['RFC2307BIS']== "true")){
56 $this->rfc2307bis= TRUE;
57 $this->attributes[]= "member";
58 $this->objectclasses[]= "groupOfNames";
59 }
61 plugin::plugin ($config, $dn);
63 /* Load attributes depending on the samba version */
64 $this->samba3= ($config->current['SAMBAVERSION'] == 3);
65 $this->orig_dn= $dn;
66 $this->orig_cn= $this->cn;
68 /* Get member list */
69 if (isset($this->attrs['memberUid'][0])){
70 $tmp= array();
71 for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
72 $tmp[]= $this->attrs['memberUid'][$i];
73 }
74 $this->memberUid= $tmp;
75 sort ($this->memberUid);
76 }
78 /* Save gidNumber for later use */
79 if (isset($this->attrs['gidNumber'])){
80 $this->saved_gidNumber= $this->attrs['gidNumber'][0];
81 }
83 /* Is a samba group? */
84 if (isset($this->attrs['objectClass'])){
85 if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
86 $this->smbgroup= FALSE;
87 } else {
88 $this->smbgroup= TRUE;
89 if (isset($this->attrs['sambaSID'])){
90 $this->sambaSID= $this->attrs['sambaSID'][0];
91 }
92 }
93 if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
94 $this->fon_group= FALSE;
95 } else {
96 $this->fon_group= TRUE;
97 }
98 if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
99 $this->nagios_group= FALSE;
100 } else {
101 $this->nagios_group= TRUE;
102 }
103 }
105 /* Set mail flag */
106 if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
107 $this->has_mailAccount= TRUE;
108 }
110 /* Get samba Domain in case of samba 3 */
111 if ($this->samba3 && $this->sambaSID != ""){
112 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
113 $ldap= $this->config->get_ldap_link();
114 $ldap->cd($this->config->current['BASE']);
115 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
116 if ($ldap->count() != 0){
117 $attrs= $ldap->fetch();
118 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
120 /* Get domain name for SID */
121 $this->sambaDomainName= "DEFAULT";
122 foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
123 if ($val['SID'] == $this->SID){
124 $this->sambaDomainName= $key;
125 break;
126 }
127 }
128 } else {
129 if (isset($this->config->current['RIDBASE'])){
130 $this->sambaDomainName= "DEFAULT";
131 $this->ridBase= $this->config->current['RIDBASE'];
132 $this->SID= $this->config->current['SID'];
133 } else {
134 print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
135 }
136 }
138 /* Get group type */
139 $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
140 if ($this->groupType < 500 || $this->groupType > 553){
141 $this->groupType= 0;
142 }
143 $this->oldgroupType= $this->groupType;
144 }
146 /* Get global filter config */
147 if (!is_global("gufilter")){
148 $ui= get_userinfo();
149 $base= get_base_from_people($ui->dn);
150 $gufilter= array( "dselect" => $base,
151 "regex" => "*");
152 register_global("gufilter", $gufilter);
153 }
154 $gufilter= get_global('gufilter');
156 $gufilter['SubSearchGroup'] = false;
157 $gufilter['dselect'] = $_SESSION['gufilter']['dselect'];
159 register_global('gufilter',$gufilter);
161 if ($this->dn == "new"){
162 if(isset($_SESSION['CurrentMainBase'])){
163 $this->base= $_SESSION['CurrentMainBase'];
164 }else{
165 $ui= get_userinfo();
166 $this->base= dn2base($ui->dn);
167 }
168 } else {
170 /* Get object base */
171 $this->base =preg_replace ("/^[^,]+,".normalizePreg(get_groups_ou())."/","",$this->dn);
172 }
174 /* This is always an account */
175 $this->is_account= TRUE;
176 $this->reload();
177 }
179 function execute()
180 {
181 /* Call parent execute */
182 plugin::execute();
184 /* Log view */
185 if($this->is_account && !$this->view_logged){
186 $this->view_logged = TRUE;
187 @log::log("view","groups/".get_class($this),$this->dn);
188 }
190 /* Do we represent a valid group? */
191 if (!$this->is_account && $this->parent == NULL){
192 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
193 _("This 'dn' is no group.")."</b>";
194 return ($display);
195 }
197 /* Delete user from group */
198 if (isset($_POST['del_users']) && isset($_POST['members'])){
199 foreach ($_POST['members'] as $value){
200 unset ($this->members["$value"]);
201 $this->removeUser($value);
202 }
203 $this->reload();
204 }
206 /* Add objects? */
207 if (isset($_POST["edit_membership"])){
208 $this->group_dialog= TRUE;
209 $this->dialog= TRUE;
210 }
212 /* Add objects finished? */
213 if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
214 $this->group_dialog= FALSE;
215 $this->dialog= FALSE;
216 }
218 /* Add user to group */
219 if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
220 foreach ($_POST['users'] as $value){
221 $this->members["$value"]= $this->allusers[$value];
222 asort($this->members);
223 $this->addUser($value);
224 }
225 $this->reload();
226 }
228 /* Base select dialog */
229 $once = true;
230 foreach($_POST as $name => $value){
231 if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
233 $once = false;
234 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
235 $this->dialog->setCurrentBase($this->base);
236 }
237 }
239 /* Dialog handling */
240 if(is_object($this->dialog)){
241 /* Must be called before save_object */
242 $this->dialog->save_object();
244 if($this->dialog->isClosed()){
245 $this->dialog = false;
246 }elseif($this->dialog->isSelected()){
248 /* Check if selected base is valid */
249 $tmp = $this->get_allowed_bases();
250 if(isset($tmp[$this->dialog->isSelected()])){
251 $this->base = $this->dialog->isSelected();
252 }
253 $this->dialog= false;
254 }else{
255 return($this->dialog->execute());
256 }
257 }
259 /* Assign templating stuff */
260 $smarty= get_smarty();
261 if ($this->samba3){
262 $smarty->assign("samba3", "true");
263 } else {
264 $smarty->assign("samba3", "");
265 }
267 if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
268 $smarty->assign("nagios",true);
269 }else{
270 $smarty->assign("nagios",false);
271 }
273 if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
274 $smarty->assign("pickupGroup",true);
275 }else{
276 $smarty->assign("pickupGroup",false);
277 }
279 /* Manage object add dialog */
280 if ($this->group_dialog){
282 /* Save data */
283 $gufilter= get_global("gufilter");
284 foreach( array("dselect", "regex") as $type){
285 if (isset($_POST[$type])){
286 $gufilter[$type]= $_POST[$type];
287 }
288 }
289 if(isset($_POST['regex'])){
290 if(isset($_POST['SubSearchGroup'])){
291 $gufilter['SubSearchGroup'] = true;
292 }else{
293 $gufilter['SubSearchGroup'] = false;
294 }
295 }
297 if (isset($_GET['search'])){
298 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
299 if ($s == "**"){
300 $s= "*";
301 }
302 $gufilter['regex']= $s;
303 }
304 register_global("gufilter", $gufilter);
305 $this->reload();
307 /* Show dialog */
308 $smarty->assign("search_image", get_template_path('images/search.png'));
309 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
310 $smarty->assign("tree_image", get_template_path('images/tree.png'));
312 $smarty->assign("deplist", $this->get_allowed_bases("users/user"));
313 $smarty->assign("alphabet", generate_alphabet());
314 foreach( array("dselect", "regex","SubSearchGroup") as $type){
315 $smarty->assign("$type", $gufilter[$type]);
316 }
317 $smarty->assign("hint", print_sizelimit_warning());
318 $smarty->assign("users", $this->displayUsers);
319 $smarty->assign("apply", apply_filter());
320 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
321 return ($display);
322 }
324 $smarty->assign("bases", $this->get_allowed_bases());
325 $smarty->assign("base_select", $this->base);
327 if ($this->samba3){
328 $domains= array();
329 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
330 $domains[$name]= $name;
331 }
332 $smarty->assign("sambaDomains", $domains);
333 $smarty->assign("sambaDomainName", $this->sambaDomainName);
334 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
335 514 => _("Domain guests"));
337 /* Don't loose special groups! If not key'ed above, add it to
338 the combo box... */
339 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
340 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
341 }
343 $smarty->assign("groupTypes", $groupTypes);
344 $smarty->assign("groupType", $this->groupType);
345 }
347 /* Members and users */
348 $smarty->assign("members", $this->members);
350 /* Checkboxes */
351 foreach (array("force_gid", "smbgroup") as $val){
352 if ($this->$val == "1"){
353 $smarty->assign("$val", "checked");
354 } else {
355 $smarty->assign("$val", "");
356 }
357 }
358 if ($this->force_gid != "1"){
359 $smarty->assign("forceMode", "disabled");
360 }else{
361 $smarty->assign("forceMode", "");
362 }
363 if ($this->fon_group){
364 $smarty->assign("fon_group", "checked");
365 } else {
366 $smarty->assign("fon_group", "");
367 }
369 if ($this->nagios_group){
370 $smarty->assign("nagios_group", "checked");
371 } else {
372 $smarty->assign("nagios_group", "");
373 }
375 /* Fields */
376 foreach (array("cn", "description", "gidNumber") as $val){
377 $smarty->assign("$val", $this->$val);
378 }
380 $tmp = $this->plInfo();
381 foreach($tmp['plProvidedAcls'] as $name => $translation){
382 $smarty->assign($name."ACL",$this->getacl($name));
383 }
385 if($this->acl_is_writeable("base")){
386 $smarty->assign("baseSelect",true);
387 }else{
388 $smarty->assign("baseSelect",false);
389 }
391 /* Show main page */
392 $smarty->assign("alphabet", generate_alphabet(10));
393 $smarty->assign("search_image", get_template_path('images/search.png'));
394 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
395 $smarty->assign("tree_image", get_template_path('images/tree.png'));
396 $smarty->assign("deplist", $this->config->idepartments);
397 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
398 }
400 function addUser($uid)
401 {
402 $this->memberUid[]= $uid;
403 $this->memberUid= array_unique($this->memberUid);
404 }
406 function removeUser($uid)
407 {
408 $temp= array();
409 foreach ($this->memberUid as $value){
410 if ($value != $uid){
411 $temp[]= $value;
412 }
413 }
414 $this->memberUid= $temp;
415 }
418 /* Reload data */
419 function reload()
420 {
421 /* Fix regex string */
422 $gufilter = get_global("gufilter");
423 $regex = normalizeLdap($gufilter['regex']);
424 $MaxUser = $this->OnlyShowFirstEntries;
426 /* Prepare ldap link */
427 $ldap= $this->config->get_ldap_link();
428 $ldap->cd($gufilter['dselect']);
431 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
432 (Store gathered sn/givenName informations in $this->allusers too,
433 to be prepared when adding/deleting users)
434 */
435 $filter = "";
436 foreach ($this->memberUid as $value){
437 if(!isset($this->members[$value])){
438 $filter .= "(uid=".normalizeLdap($value).")";
439 }
440 }
441 if(!empty($filter)){
442 $ldap->cd($this->config->current['BASE']);
443 $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("dn", "uid","sn","givenName"));
444 while($attrs = $ldap->fetch()){
445 $this->dnMapping[$attrs['uid'][0]] = $attrs['dn'];
446 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
447 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
448 }
449 }
451 /* check if all uids are resolved */
452 foreach ($this->memberUid as $value){
453 if(!isset($this->members[$value])){
454 $this->members[$value] = _("! unknown id")." [".$value."]";
455 }
456 }
458 /* Create display list of users matching regex & filter
459 */
460 $this->displayUsers = array();
461 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
463 /* Search in current tree or within subtrees depending on the checkbox from filter section */
464 if($gufilter['SubSearchGroup']){
465 $flag = GL_SIZELIMIT | GL_SUBSEARCH;
466 $base = $gufilter['dselect'];
467 }else{
468 $flag = GL_SIZELIMIT ;
469 $base = get_people_ou().$gufilter['dselect'];
470 }
471 $i = 0;
474 $res = get_list($filter,"users",$base,array("dn", "uid", "sn", "givenName"),$flag);
476 /* Fetch all users and skip already used users */
477 foreach($res as $attrs){
478 if(in_array($attrs['uid'][0], $this->memberUid)) {
479 continue;
480 }
481 $i ++;
482 if($i > $MaxUser) {
483 break;
484 }
485 $this->dnMapping[$attrs['uid'][0]]= $attrs["dn"];
486 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
487 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
488 }
490 /* If more than max users are found, display a message to warn the user */
491 if(($i == $MaxUser)){
492 print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
493 }
495 /* Sort lists */
496 natcasesort($this->members);
497 reset($this->members);
498 natcasesort ($this->displayUsers);
499 reset ($this->displayUsers);
500 }
503 /* Create display name, this was used so often that it is excluded into a seperate function */
504 function createResultName($attrs)
505 {
506 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
507 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
508 } else {
509 $ret= $attrs['uid'][0];
510 }
511 return($ret);
512 }
515 function remove_from_parent()
516 {
517 plugin::remove_from_parent();
519 $ldap= $this->config->get_ldap_link();
520 $ldap->rmdir($this->dn);
521 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
523 @log::log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
525 /* Delete references to object groups */
526 $ldap->cd ($this->config->current['BASE']);
527 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
528 while ($ldap->fetch()){
529 $og= new ogroup($this->config, $ldap->getDN());
530 unset($og->member[$this->dn]);
531 $og->save ();
532 }
534 /* Send signal to the world that we've done */
535 $this->handle_post_events("remove");
536 }
539 /* Save data to object */
540 function save_object()
541 {
542 /* Save additional values for possible next step */
543 if (isset($_POST['groupedit'])){
545 /* Create a base backup and reset the
546 base directly after calling plugin::save_object();
547 Base will be set seperatly a few lines below */
548 $base_tmp = $this->base;
549 plugin::save_object();
550 $this->base = $base_tmp;
552 $this->force_gid= 0;
554 /* Only reset sambagroup flag if we are able to write this flag */
555 if($this->acl_is_writeable("sambaGroupType")){
556 $this->smbgroup = 0;
557 }
559 /* Get base selection */
560 if(isset($_POST['base'])){
561 $tmp = $this->get_allowed_bases();
562 if(isset($tmp[$_POST['base']])){
563 $this->base = $_POST['base'];
564 }
565 }
567 foreach (array(
568 "force_gid" => "gidNumber",
569 "smbgroup" => "sambaGroupType") as $val => $aclname) {
570 if ($this->acl_is_writeable($aclname) && isset($_POST["$val"])){
571 $this->$val= $_POST["$val"];
572 }
573 }
575 /* Save sambaDomain attribute */
576 if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
577 $this->sambaDomainName= $_POST['sambaDomainName'];
578 $this->groupType= $_POST['groupType'];
579 }
581 /* Save fon attribute */
582 if ($this->acl_is_writeable("fon_group")){
583 if (isset ($_POST['fon_group'])){
584 $this->fon_group= TRUE;
585 } else {
586 $this->fon_group= FALSE;
587 }
588 }
589 if ($this->acl_is_writeable("nagios_group")){
590 if (isset ($_POST['nagios_group'])){
591 $this->nagios_group= TRUE;
592 } else {
593 $this->nagios_group= FALSE;
594 }
595 }
596 }
597 }
600 /* Save to LDAP */
601 function save()
602 {
604 /* ID handling */
605 if ($this->force_gid == 0){
606 if ($this->saved_gidNumber != ""){
607 $this->gidNumber= $this->saved_gidNumber;
608 } else {
609 /* Calculate new, lock uids */
610 $wait= 10;
611 while (get_lock("uidnumber") != ""){
612 sleep (1);
614 /* timed out? */
615 if ($wait-- == 0){
616 break;
617 }
618 }
619 add_lock ("uidnumber", "gosa");
620 $this->gidNumber= $this->get_next_id("gidNumber", $this->dn);
621 }
622 }
624 plugin::save();
626 /* Remove objectClass for samba/phone support */
627 $tmp= array();
628 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
629 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
630 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
631 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
632 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
633 $tmp[]= $this->attrs['objectClass'][$i];
634 }
635 }
636 $this->attrs['objectClass']= $tmp;
637 $ldap= $this->config->get_ldap_link();
639 /* Add samba group functionality */
640 if ($this->samba3 && $this->smbgroup){
642 /* Fixed undefined index ...
643 */
644 $this->SID = $this->ridBase = "";
645 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
646 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
647 }else{
648 print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
649 }
650 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
651 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
652 }else{
653 print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
654 }
656 $this->attrs['objectClass'][]= 'sambaGroupMapping';
657 $this->attrs['sambaGroupType']= "2";
659 /* Check if we need to create a special entry */
660 if ($this->groupType == 0){
662 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
663 $gidNumber= $this->gidNumber;
664 while(TRUE){
665 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
666 $ldap->cd($this->config->current['BASE']);
667 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
668 if ($ldap->count() == 0){
669 break;
670 }
671 $gidNumber++;
672 }
673 $this->attrs['sambaSID']= $sid;
674 $this->sambaSID= $sid;
675 }
677 } else {
678 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
679 }
681 /* User wants me to fake the idMappings? This is useful for
682 making winbind resolve the group names in a reasonable amount
683 of time in combination with larger databases. */
684 if (isset($this->config->current['SAMBAIDMAPPING']) &&
685 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
686 $this->attrs['objectClass'][]= "sambaIdmapEntry";
687 }
689 }
691 /* Add phone functionality */
692 if ($this->fon_group){
693 $this->attrs['objectClass'][]= "goFonPickupGroup";
694 }
696 /* Add nagios functionality */
697 if ($this->nagios_group){
698 $this->attrs['objectClass'][]= "nagiosContactGroup";
699 }
701 /* Take members array */
702 if (count ($this->memberUid)){
703 $this->attrs['memberUid']= array_unique($this->memberUid);
704 }
706 /* New accounts need proper 'dn', propagate it to remaining objects */
707 if ($this->dn == 'new'){
708 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
709 }
711 /* Add member dn's for RFC2307bis Support */
712 if ($this->rfc2307bis){
713 if (count($this->memberUid)){
714 $this->attrs['member'] = array();
715 foreach($this->attrs['memberUid'] as $uid) {
716 $this->attrs['member'][]= $this->dnMapping[$uid];
717 }
718 } else {
719 $this->attrs['member'][]= $this->dn;
720 }
721 }
723 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
724 new entries. So do a check first... */
725 $ldap->cat ($this->dn, array('dn'));
726 if ($ldap->fetch()){
727 /* Modify needs array() to remove values :-( */
728 if (!count ($this->memberUid)){
729 $this->attrs['memberUid']= array();
730 }
731 if ($this->samba3){
732 if (!$this->smbgroup){
733 $this->attrs['sambaGroupType']= array();
734 $this->attrs['sambaSID']= array();
735 }
736 }
737 $mode= "modify";
738 } else {
739 $mode= "add";
740 $ldap->cd($this->config->current['BASE']);
741 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
742 }
744 /* Write back to ldap */
745 $ldap->cd($this->dn);
746 $this->cleanup();
747 $ldap->$mode($this->attrs);
749 if($this->initially_was_account){
750 @log::log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
751 }else{
752 @log::log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
753 }
755 $ret= 0;
756 if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
757 $ret= 1;
758 }
760 /* Remove uid lock */
761 del_lock ("uidnumber");
763 /* Post that we've done*/
764 $this->handle_post_events($mode);
766 return ($ret);
767 }
769 function check()
770 {
771 /* Call common method to give check the hook */
772 $message= plugin::check();
774 /* Permissions for that base? */
775 if ($this->base != ""){
776 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
777 } else {
778 $new_dn= $this->dn;
779 }
781 /* must: cn */
782 if ($this->cn == "" && $this->acl_is_writeable("cn")){
783 $message[]= "The required field 'Name' is not set.";
784 }
786 /* Check for valid input */
787 if (!is_uid($this->cn)){
788 $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
789 }
791 if($this->allowGroupsWithSameNameInOtherSubtrees == true){
793 /* Check for used 'cn' */
794 $ldap= $this->config->get_ldap_link();
795 if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
796 $ldap->cd("ou=groups,".$this->base);
797 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
798 if ($ldap->count() != 0){
799 $message[]= _("Value specified as 'Name' is already used.");
800 }
801 }
803 }else{
805 /* Check for used 'cn' */
806 $ldap= $this->config->get_ldap_link();
807 $ldap->cd($this->config->current['BASE']);
808 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
809 if ($ldap->count() != 0){
811 /* New entry? */
812 if ($this->dn == 'new'){
813 $message[]= _("Value specified as 'Name' is already used.");
814 }
816 /* Moved? */
817 elseif ($new_dn != $this->orig_dn){
818 $ldap->fetch();
819 if ($ldap->getDN() != $this->orig_dn){
820 $message[]= _("Value specified as 'Name' is already used.");
821 }
822 }
823 }
824 }
826 /* Check ID */
827 if ($this->force_gid == "1"){
828 if (!is_id($this->gidNumber)){
829 $message[]= _("Value specified as 'GID' is not valid.");
830 } else {
831 if ($this->gidNumber < $this->config->current['MINID']){
832 $message[]= _("Value specified as 'GID' is too small.");
833 }
835 }
836 }
838 return ($message);
839 }
841 function get_next_id($attrib, $dn)
842 {
843 $ids= array();
844 $ldap= $this->config->get_ldap_link();
846 $ldap->cd ($this->config->current['BASE']);
847 if (preg_match('/gidNumber/i', $attrib)){
848 $oc= "posixGroup";
849 } else {
850 $oc= "posixAccount";
851 }
852 $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
854 /* Get list of ids */
855 while ($attrs= $ldap->fetch()){
856 $ids[]= (int)$attrs["$attrib"][0];
857 }
859 /* Find out next free id near to UID_BASE */
860 if (!isset($this->config->current['BASE_HOOK'])){
861 $base= $this->config->current['UIDBASE'];
862 } else {
863 /* Call base hook */
864 $base= get_base_from_hook($dn, $attrib);
865 }
866 for ($id= $base; $id++; $id < pow(2,32)){
867 if (!in_array($id, $ids)){
868 return ($id);
869 }
870 }
872 /* Check if id reached maximum */
873 if ($id >= pow(2,32)){
874 print_red(_("Too many users, can't allocate a free ID!"));
875 exit;
876 }
877 }
879 function getCopyDialog()
880 {
881 $vars = array("cn");
883 if($this ->force_gid){
884 $used = " checked ";
885 $dis = "";
886 }else{
887 $used = "";
888 $dis = " disabled ";
889 }
891 $smarty = get_smarty();
892 $smarty->assign("used",$used);
893 $smarty->assign("dis" ,$dis);
894 $smarty->assign("cn" ,$this->cn);
895 $smarty->assign("gidNumber",$this->gidNumber);
896 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
897 $ret = array();
898 $ret['string'] = $str;
899 $ret['status'] = "";
900 return($ret);
901 }
903 function saveCopyDialog()
904 {
905 if(isset($_POST['cn'])){
906 $this->cn = $_POST['cn'];
907 }
908 if(isset($_POST['force_gid'])){
909 $this->force_gid = 1;
910 $this->gidNumber= $_POST['gidNumber'];
911 }else{
912 $this->force_gid = 0;
913 $this->gidNumber = false;
914 }
915 }
918 /* Return plugin informations for acl handling */
919 function plInfo()
920 {
921 return (array(
922 "plShortName" => _("Generic"),
923 "plDescription" => _("Generic group settings"),
924 "plSelfModify" => FALSE,
925 "plDepends" => array(),
926 "plPriority" => 0,
927 "plSection" => array("admin"),
928 "plCategory" => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
930 "plProvidedAcls" => array(
931 "cn" => _("Name"),
932 "base" => _("Base"),
933 "description" => _("Description"),
935 "fonGroup" => _("Phone pickup group"),
936 "nagiosGroup" => _("Nagios group"),
938 "gidNumber" => _("GID"),
939 "memberUid" => _("Group member"),
940 "sambaGroupType" => _("Samba group type"),
941 "sambaDomainName" => _("Samba domain name"),
942 "sambaSID" => _("Samba SID"))
943 ));
944 }
945 }
947 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
948 ?>