From a5d1470f2bc727b6dfd7ded8fbaf37acf7a07afd Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 19 Jul 2006 11:15:10 +0000 Subject: [PATCH] Fixed gotoPrinter membership problem git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@4235 594d385d-05f5-0310-b6e9-bd551577e9d8 --- Changelog | 1 + plugins/admin/systems/class_printGeneric.inc | 93 ++++++--- plugins/admin/systems/printer.tpl | 4 +- .../environment/class_environment.inc | 183 ++++-------------- 4 files changed, 106 insertions(+), 175 deletions(-) diff --git a/Changelog b/Changelog index ad157e458..0cddad6ee 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ GOsa2 changelog =============== * gosa 2.5.3 + - Fixed gotoPrinter membership problem. - Fixed environment shares, only available shares will be displayed (gosaUnitTag was ignored) - Fixed saving of inherited workstation settings - Removed error when no FAI repositories were present diff --git a/plugins/admin/systems/class_printGeneric.inc b/plugins/admin/systems/class_printGeneric.inc index 8d4d00a87..d19ecd245 100644 --- a/plugins/admin/systems/class_printGeneric.inc +++ b/plugins/admin/systems/class_printGeneric.inc @@ -28,7 +28,6 @@ class printgeneric extends plugin var $AdminMembers =array(); var $AdminMemberKeys =array(); - var $gotoUserPrinter ; var $PPDdialogToSave = NULL; var $BelongsTo = "unknown"; // Specifies if this is a standalone printer, or belongs to a terminal / WS @@ -41,9 +40,15 @@ class printgeneric extends plugin var $macAddress = ""; /* attribute list for save action */ - var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress"); + var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress", + "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter"); var $objectclasses = array("top", "gotoPrinter"); + var $gotoUserAdminPrinter; + var $gotoGroupAdminPrinter ; + var $gotoGroupPrinter; + var $gotoUserPrinter ; + function printgeneric ($config, $dn= NULL,$parent = NULL) { $this->config = $config; @@ -401,26 +406,26 @@ class printgeneric extends plugin /* Member management, delete user / group / admin ..*/ if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ - if(isset($this->member['AddUser'][$_POST['UserMember']])){ - unset($this->member['AddUser'][$_POST['UserMember']]); + foreach($_POST['UserMember'] as $mem){ + $this->DelMember('AddUser',$mem); } } if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ - if(isset($this->member['AddGroup'][$_POST['UserMember']])){ - unset($this->member['AddGroup'][$_POST['UserMember']]); + foreach($_POST['UserMember'] as $mem){ + $this->DelMember('AddGroup',$mem); } } if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ - if(isset($this->member['AddAdminUser'][$_POST['AdminMember']])){ - unset($this->member['AddAdminUser'][$_POST['AdminMember']]); + foreach($_POST['AdminMember'] as $mem){ + $this->DelMember('AddAdminUser',$mem); } } if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ - if(isset($this->member['AddAdminGroup'][$_POST['AdminMember']])){ - unset($this->member['AddAdminGroup'][$_POST['AdminMember']]); + foreach($_POST['AdminMember'] as $mem){ + $this->DelMember('AddAdminGroup',$mem); } } @@ -438,18 +443,10 @@ class printgeneric extends plugin print_red($msg); } }else{ - $new = $this->dialog->save(); - $data = $new; + $data= $new = $this->dialog->save(); unset($data['type']); - - if(preg_match("/User/",$new['type'])){ - $use = "uid"; - }else{ - $use = "cn"; - } - - foreach($data as $mem){ - $this->member[$new['type']][$mem[$use][0]]=$mem; + foreach($data as $mem){ + $this->AddMember($new['type'], $mem['dn']); } unset($this->dialog); $this->dialog=NULL; @@ -687,27 +684,28 @@ class printgeneric extends plugin /* Append printer user */ - if((isset($this->attrs['gotoUserPrinter'])) && (is_string($this->attrs['gotoUserPrinter']))){ - $this->attrs['gotoUserPrinter']=array(); - } + $this->attrs['gotoUserPrinter']=array(); foreach($this->member['AddUser'] as $mem){ $this->attrs['gotoUserPrinter'][]=$mem['uid'][0]; } /* Append printer group */ + $this->attrs['gotoGroupPrinter'][] = array(); foreach($this->member['AddGroup'] as $mem){ $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0]; } /* Append printer admin user */ + $this->attrs['gotoUserAdminPrinter'] =array(); foreach($this->member['AddAdminUser'] as $mem){ $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0]; } /* Append printer admin group */ + $this->attrs['gotoGroupAdminPrinter'] = array(); foreach($this->member['AddAdminGroup'] as $mem){ $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0]; } @@ -763,9 +761,54 @@ class printgeneric extends plugin } return($a_return); } -} + /* Delete member */ + function DelMember($type,$id) + { + if(isset($this->member[$type][$id])){ + unset($this->member[$type][$id]); + } + } + + /* Add given obejct to members */ + function AddMember($type,$dn) + { + $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup"); + if(!in_array_ics($type, $types)){ + print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type)); + return; + } + + /* Get name of index attributes */ + if(preg_match("/user/i",$type)){ + $var = "uid"; + }else{ + $var = "cn"; + } + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($dn); + $ldap->cat($dn,array("cn","uid")); + if($ldap->count()){ + + $attrs = $ldap->fetch(); + $name = $attrs[$var][0]; + /* Check if this uid/cn is already assigned to any permission */ + foreach($types as $ctype){ + if(isset( $this->member[$ctype][$name])){ + print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0])); + return; + } + } + + /* Everything is fine. So add the given object to members */ + $this->member[$type][$attrs[$var][0]] = $attrs ; + }else{ + print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn)); + } + } +} // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/systems/printer.tpl b/plugins/admin/systems/printer.tpl index 808d47f74..876ae22ba 100644 --- a/plugins/admin/systems/printer.tpl +++ b/plugins/admin/systems/printer.tpl @@ -68,7 +68,7 @@ {t}Users which are allowed to use this printer{/t}
- {html_options options=$UserMembers values=$UserMemberKeys}
@@ -84,7 +84,7 @@ {t}Users which are allowed to administrate this printer{/t}
- {html_options options=$AdminMembers values=$AdminMemberKeys}
diff --git a/plugins/personal/environment/class_environment.inc b/plugins/personal/environment/class_environment.inc index b1c76c3a7..c411cd138 100644 --- a/plugins/personal/environment/class_environment.inc +++ b/plugins/personal/environment/class_environment.inc @@ -930,174 +930,61 @@ class environment extends plugin /* Save usersettings to Printer */ - if(chkacl($this->acl,"gotoPrinter")!=""){ $this->gotoPrinter = array(); } + /* 1. Search all printers that have our uid/cn as member + * 2. Delete this uid/cn from every single entry and save it again. + * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix + * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal + */ + $types = array( "gotoUserPrinter" => "AddUser", + "gotoGroupPrinter" => "AddGroup", + "gotoUserAdminPrinter" => "AddAdminUser", + "gotoGroupAdminPrinter" => "AddAdminGroup"); + if($this->is_group){ $s_suffix = "Group"; + $useVar = "cn"; }else{ + $useVar = "uid"; $s_suffix = "User"; } - - /* 1. Search all printers that have our uid/cn as member - * 2. Delete this uid/cn from every single entry and save it again. - * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix - * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal - */ - $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*")); + /* Remove old entries */ + $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*")); while($attr = $ldap->fetch()){ + $printerObj = NULL; + $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']); + $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid); + $printerObj->by_object['printgeneric']->save(); + } - /* Walk trough all printers and check if our user id used, if so remove it. - * Later we will insert our uid at the right place. - */ - - /* Remove normal entries (User)*/ - if(isset($attr['goto'.$s_suffix.'Printer'])) { - - /* Avoid saving count=>0 as member */ - unset($attr['goto'.$s_suffix.'Printer']['count']); - - foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){ - if($this->uid==$user){ - unset($attr['goto'.$s_suffix.'Printer'][$key]); - } - } - $tmp = array(); - foreach($attr['goto'.$s_suffix.'Printer'] as $user){ - $tmp[] = $user; - } - $attr['goto'.$s_suffix.'Printer'] = array(); - $attr['goto'.$s_suffix.'Printer'] = $tmp; - } - - /* Remove administrational entries (Admin)*/ - if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){ - - /* Avoid saving count=>0 as member */ - unset($attr['goto'.$s_suffix.'AdminPrinter']['count']); - - foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){ - if($this->uid==$user){ - unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]); - } - } - $tmp = array(); - foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $user){ - $tmp[] = $user; - } - $attr['goto'.$s_suffix.'AdminPrinter'] = array(); - $attr['goto'.$s_suffix.'AdminPrinter'] = $tmp; - } - - /* Extract useable tags, to be able to save all changes - */ - $attrs_used = array(); - foreach($attr as $key=>$val){ - - /* If index is numeric, skip it ...*/ - if((!is_numeric($key))&&($key!="count")){ - - /* If entry contains 'count' remove it */ - if(is_array($val)&&isset($val['count'])){ - unset($val['count']); - } - $attrs_used[$key]=$val; - } - } - /* the result of cleaning the entry is - * to be able to directly save this again, - * if all changes are made - */ - $attr= $attrs_used; - -#fix : Id don't know why such an entry was set ... - if(isset($attr['GOTOADMINPRINTER'])){ - unset($attr['GOTOADMINPRINTER']); - } - - /* Save changes */ - $ldap->cd($attr['dn']); - unset($attr['dn']); -$ldap->modify ($attr); - - if($ldap->get_error()!="Success"){ - print_red(_("Error while writing printer")." : ".$ldap->get_error()); - } + $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*")); + while($attr = $ldap->fetch()){ + $printerObj = NULL; + $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']); + $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid); + $printerObj->by_object['printgeneric']->save(); } - /* All printers are cleaned, (our cn/uid removed) - * now we must add our uid / cn - * to the new configured printers. - */ - foreach($this->gotoPrinter as $printer) { - $ldap->cat($printer['dn']); - $attrs= $ldap->fetch(); - $attrs_used = array(); - foreach($attrs as $key=>$val){ - if((!is_numeric($key))&&($key!="count")){ - if(is_array($val)&&isset($val['count'])){ - unset($val['count']); - } - $attrs_used[$key]=$val; - } - } - /* $attrs contains all values - * we need, to save the entry lateron - */ - $attrs= $attrs_used; + foreach($this->gotoPrinter as $printer){ + $printerObj = NULL; + $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']); - /* Depending on the type (User/Admin) - * switch these attributes, that makes it easier - */ - if($printer['mode'] == "user"){ - $attribute = "goto".$s_suffix."Printer"; - $attribute2 = "goto".$s_suffix."AdminPrinter"; + if($printer['mode'] == "admin") { + $attribute = "goto".$s_suffix."AdminPrinter"; }else{ - $attribute = "goto".$s_suffix."AdminPrinter"; - $attribute2 = "goto".$s_suffix."Printer"; + $attribute = "goto".$s_suffix."Printer"; } - /* If this user is already assigned to $attribute2 - * delete user from $attribute2, to be albe to attach him to $attribute - * A user can't be admin and normal user for one printer - */ - if(!isset($printer[$attribute2])){ - $printer[$attribute2]=array(); - }else{ - if(in_array($this->uid,$printer[$attribute2])){ - $tmp = array_flip($printer[$attribute2]); - unset($tmp[$this->uid]); - $attrs[$attribute2]=array_flip($tmp); - } - /* If Last entry removed, clear attribute*/ - if(empty($attrs[$attribute2])){ - $attrs[$attribute2]=array(); - } - } - - /* Attach user to the $attribute, if he is'nt already attached - */ - if(!isset($attrs[$attribute])){ - $attrs[$attribute]=array($this->uid); - }else{ - unset($attrs[$attribute]['count']); - if(!in_array($this->uid,$attrs[$attribute])){ - $attrs[$attribute][]=$this->uid; - } - } + $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn); + $printerObj->by_object['printgeneric']->save(); + } + - $ldap->cd($attrs['dn']); - unset($attrs['dn']); -$ldap->modify ($attrs); - if($ldap->get_error()!="Success"){ - print_red(_("Error while writing printer settings")." : ".$ldap->get_error()); - } - } - /* Prepare HotPlug devices */ $this->attrs['gotoHotplugDevice'] = array(); foreach($this->gotoHotplugDevices as $name => $device){ -- 2.30.2