X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_printGeneric.inc;h=021c75f9d0f5b6864dbd6fbe27e31abb6d306aac;hb=269b6da4461630896e0af284cca9742b9f819f2b;hp=6363daca18b29aeefbe01344865b3c490013c997;hpb=b591c3d0d2cc65073f421b8037f6e73bedf78bee;p=gosa.git diff --git a/plugins/admin/systems/class_printGeneric.inc b/plugins/admin/systems/class_printGeneric.inc index 6363daca1..021c75f9d 100644 --- a/plugins/admin/systems/class_printGeneric.inc +++ b/plugins/admin/systems/class_printGeneric.inc @@ -49,11 +49,13 @@ class printgeneric extends plugin "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter"); var $objectclasses = array("top", "gotoPrinter"); - function printgeneric ($config, $dn= NULL,$parent = NULL) + var $parent; + + function printgeneric ($config, $dn,$parent_init,$parent) { $this->config = $config; $this->dn = $dn; - + /* If parent was posted(the tabs object) we can detect the printer type. */ if($parent){ $this->parent = $parent; @@ -64,11 +66,11 @@ class printgeneric extends plugin } /* Update dn, to ensure storing as printer instead of WS / terminal */ - if($this->BelongsTo == "Terminal"){ + if(preg_match("/Terminal/i",$this->BelongsTo) || preg_match("/TerminalTemplate/i",$this->BelongsTo)){ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn); } - if($this->BelongsTo == "Workstation"){ + if(preg_match("/Workstation/i",$this->BelongsTo) || preg_match("/WorkstationTemplate/i",$this->BelongsTo)){ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn); } @@ -132,12 +134,14 @@ class printgeneric extends plugin foreach($this->attrs[$attr] as $mem){ if(preg_match("/Group/",$type)){ $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description")); - $entry = $ldap->fetch(); - $this->member[$type][$entry['cn'][0]]=$entry; + if($ldap->count()){ + $entry = $ldap->fetch(); + $this->member[$type][$entry['cn'][0]]=$entry; + } }else{ $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid")); - $entry = $ldap->fetch(); - if(isset($entry['uid'])){ + if($ldap->count()){ + $entry = $ldap->fetch(); $this->member[$type][$entry['uid'][0]]=$entry; } } @@ -146,6 +150,21 @@ class printgeneric extends plugin } } + function set_acl_base($base) + { + plugin::set_acl_base($base); + if(is_object($this->netConfigDNS)){ + $this->netConfigDNS->set_acl_base($base); + } + } + + function set_acl_category($cat) + { + plugin::set_acl_category($cat); + if(is_object($this->netConfigDNS)){ + $this->netConfigDNS->set_acl_category($cat); + } + } /* Detect type of printer. * Printer can be stand alone, belong to a workstation or belong to a terminal. @@ -159,6 +178,8 @@ class printgeneric extends plugin /* Detect type of printer via parent tabs. */ + + $class = get_class($this->parent); if(isset($this->parent->by_object['workgeneric'])){ /* Exclude templates @@ -193,23 +214,22 @@ class printgeneric extends plugin /* If is printer it must be a true account. */ - if($this->BelongsTo == "Printer"){ + if(preg_match("/printer/i",$this->BelongsTo)){ $this->is_account = true; } /* Update dn, to ensure storing as printer instead of WS / terminal */ - if($this->BelongsTo == "Terminal"){ + if(preg_match("/terminal/i",$this->BelongsTo)){ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn); } - if($this->BelongsTo == "Workstation"){ + if(preg_match("/workstation/i",$this->BelongsTo)){ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn); } /* Detect if this is a valid printer account; */ - //FIXME: do we need to do this? we've already everything we need in $this->attrs... $ldap = $this->config->get_ldap_link(); $ldap->cat($this->dn, array('objectClass')); @@ -233,7 +253,7 @@ class printgeneric extends plugin /* If type of printer couldn't be detected (because of missing parent object in construction) * hide this tab. */ - if($this->BelongsTo == "unknown"){ + if(preg_match("/unknown/i",$this->BelongsTo)){ $display= $this->show_enable_header(_("Add printer extension"), _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE); return($display); @@ -241,39 +261,49 @@ class printgeneric extends plugin /* Templates can't have printer extensions */ - if($this->BelongsTo == "WorkstationTemplate"){ + if(preg_match("/WorkstationTemplate/i",$this->BelongsTo)){ $display= $this->show_enable_header(_("Add printer extension"), _("This is a workstation template, printer tab is disabled."),TRUE,TRUE); return($display); } - if($this->BelongsTo == "TerminalTemplate"){ + if(preg_match("/TerminalTemplate/i",$this->BelongsTo)){ $display= $this->show_enable_header(_("Add printer extension"), _("This is a terminal template, printer tab is disabled."),TRUE,TRUE); return($display); } /* Get cn from base object */ - if($this->BelongsTo == "Workstation"){ + if(preg_match("/^Workstation$/i",$this->BelongsTo)){ $this->cn = $this->parent->by_object['workgeneric']->cn; } - if($this->BelongsTo == "Terminal"){ + if(preg_match("/^Terminal$/i",$this->BelongsTo)){ $this->cn = $this->parent->by_object['termgeneric']->cn; } $smarty= get_smarty(); + + /* Assign acls */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL", $this->getacl($name)); + } + $display=""; /* Tell smarty if this is a standalone object or a terminal / WS depending printer */ - if($this->BelongsTo == "Printer"){ + if(preg_match("/^Printer$/i",$this->BelongsTo)){ $smarty->assign("StandAlone",true); }else{ $smarty->assign("StandAlone",false); } /* Do we need to flip is_account state? */ - if (isset($_POST['modify_state'])){ - $this->is_modified = true; - $this->is_account= !$this->is_account; + if(isset($_POST['modify_state'])){ + if($this->is_account && $this->acl_is_removeable()){ + $this->is_account= FALSE; + }elseif(!$this->is_account && $this->acl_is_createable()){ + $this->is_account= TRUE; + } } /* Do we represent a valid printer? */ @@ -284,7 +314,7 @@ class printgeneric extends plugin } /* If this is a WS / Terminal depending printer, display account state button */ - if($this->BelongsTo != "Printer"){ + if(!preg_match("/^Printer$/i",$this->BelongsTo)){ if((empty($this->cn)) && ($this->dn != "new")){ $display= $this->show_enable_header(_("Add printer extension"), _("This object has printer extension disabled. You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template"),TRUE,TRUE); @@ -293,18 +323,18 @@ class printgeneric extends plugin } if (($this->is_account)){ - if($this->BelongsTo=="Workstation"){ + if(preg_match("/^Workstation$/i",$this->BelongsTo)){ $display= $this->show_disable_header(_("Remove printer extension"), _("This workstation has printer extension enabled.You can disable it by clicking below.")); - }elseif($this->BelongsTo=="Terminal"){ + }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){ $display= $this->show_disable_header(_("Remove printer extension"), _("This terminal has printer extension enabled. You can disable it by clicking below.")); } }else{ - if($this->BelongsTo=="Workstation"){ + if(preg_match("/^Workstation$/i",$this->BelongsTo)){ $display= $this->show_disable_header(_("Add printer extension"), _("This workstation has printer extension disabled. You can enable it by clicking below.")); - }elseif($this->BelongsTo=="Terminal"){ + }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){ $display= $this->show_enable_header(_("Add printer extension"), _("This terminal has printer extension disabled. You can enable it by clicking below.")); } @@ -315,9 +345,9 @@ class printgeneric extends plugin /* Base select dialog */ $once = true; foreach($_POST as $name => $value){ - if(preg_match("/^chooseBase/",$name) && $once){ + if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){ $once = false; - $this->dialog = new baseSelectDialog($this->config,$this); + $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases()); $this->dialog->setCurrentBase($this->base); $this->baseSelection = true; } @@ -333,7 +363,13 @@ class printgeneric extends plugin $this->dialog = false; $this->baseSelection = false; }elseif($this->dialog->isSelected()){ - $this->base = $this->dialog->isSelected(); + + /* A new base was selected, check if it is a valid one */ + $tmp = $this->get_allowed_bases(); + if(isset($tmp[$this->dialog->isSelected()])){ + $this->base = $this->dialog->isSelected(); + } + $this->dialog= false; $this->baseSelection = false; }else{ @@ -343,17 +379,14 @@ class printgeneric extends plugin } /* Fill templating stuff */ - $smarty->assign("bases", $this->config->idepartments); + $smarty->assign("bases", $this->get_allowed_bases()); $smarty->assign("base_select", $this->base); /* Assign attributes */ foreach ($this->attributes as $attr){ - $smarty->assign($attr."ACL", chkacl($this->acl, $attr)); $smarty->assign("$attr", $this->$attr); } - $smarty->assign("baseACL", chkacl($this->acl,"base")); - if(isset($_POST['AddUser'])){ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser"); } @@ -472,7 +505,7 @@ class printgeneric extends plugin $ppdManager= new ppdManager($path); if(!empty($this->gotoPrinterPPD)){ if((!file_exists($path.$this->gotoPrinterPPD))){ - $smarty->assign("driverInfo", "".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD)).""; + $smarty->assign("driverInfo", "".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD).""); }else{ $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD)); } @@ -491,13 +524,13 @@ class printgeneric extends plugin asort($userlist); asort($adminlist); - if($this->BelongsTo != "Printer"){ - if($this->BelongsTo == "Terminal"){ + if(!preg_match("/Printer/i",$this->BelongsTo)){ + if(preg_match("/Terminal/i",$this->BelongsTo)){ $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"".$this->cn."")); }else{ $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"".$this->cn."")); } - $smarty->assign("cnACL" ," disabled "); + $smarty->assign("cnACL" , $this->getacl("cn",true)); }else{ $smarty->assign("desc" ,""); } @@ -508,7 +541,11 @@ class printgeneric extends plugin $smarty->assign("AdminMember" ,$this->AdminMember); $smarty->assign("AdminMembers" ,$adminlist); $smarty->assign("AdminMemberKeys",array_flip($adminlist)); - $smarty->assign("netconfig", $this->netConfigDNS->execute()); + if(preg_match("/Printer/i",$this->BelongsTo)){ + $smarty->assign("netconfig", $this->netConfigDNS->execute()); + } else { + $smarty->assign("netconfig", ""); + } return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE))); } @@ -520,11 +557,11 @@ class printgeneric extends plugin /* Update dn, to ensure storing as printer instead of WS / terminal */ - if($this->BelongsTo == "Terminal"){ + if(preg_match("/terminal/i",$this->BelongsTo)){ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn); } - if($this->BelongsTo == "Workstation"){ + if(preg_match("/workstation/i",$this->BelongsTo)){ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn); } @@ -564,11 +601,23 @@ class printgeneric extends plugin /* Save data to object */ function save_object() { + /* Create a base backup and reset the + base directly after calling plugin::save_object(); + Base will be set seperatly a few lines below */ + $base_tmp = $this->base; plugin::save_object(); - $this->netConfigDNS->save_object(); - /* Save base, since this is no LDAP attribute */ - if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){ - $this->base= $_POST['base']; + $this->base = $base_tmp; + + if(is_object($this->netConfigDNS)){ + $this->netConfigDNS->save_object(); + } + + /* Set new base if allowed */ + $tmp = $this->get_allowed_bases(); + if(isset($_POST['base'])){ + if(isset($tmp[$_POST['base']])){ + $this->base= $_POST['base']; + } } } @@ -577,7 +626,9 @@ class printgeneric extends plugin { /* Call common method to give check the hook */ $message= plugin::check(); - $message= array_merge($message, $this->netConfigDNS->check()); + if (preg_match("/printer/i",$this->BelongsTo)){ + $message= array_merge($message, $this->netConfigDNS->check()); + } /* Don't display check messages if this is a template object */ if(isset($this->parent->by_object['workgeneric'])){ @@ -593,9 +644,20 @@ class printgeneric extends plugin $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base; /* must: cn */ - if(($this->BelongsTo == "Printer") && (empty($this->cn))){ + if(preg_match("/printer/i",$this->BelongsTo) && (empty($this->cn))){ $message[]= "The required field 'Printer name' is not set."; } + + /* Set new acl base */ + if($this->dn == "new") { + $this->set_acl_base($this->base); + } + + if(preg_match("/printer/i",$this->BelongsTo)){ + if ($this->orig_dn == "new" && !$this->acl_is_createable()){ + $message[]= _("You have no permissions to create a group on this 'Base'."); + } + } /* must: labeledURI */ if(empty($this->labeledURI)){ @@ -603,7 +665,7 @@ class printgeneric extends plugin } /* Check if there is already an entry with this cn*/ - if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){ + if (($this->orig_dn != $dn)&&( preg_match("/printer/i",$this->BelongsTo))){ $ldap= $this->config->get_ldap_link(); $ldap->cd ($this->base); $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn")); @@ -626,11 +688,11 @@ class printgeneric extends plugin { /* Update dn, to ensure storing as printer instead of WS / terminal */ - if($this->BelongsTo == "Terminal"){ + if(preg_match("/terminal/i",$this->BelongsTo)){ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn); } - if($this->BelongsTo == "Workstation"){ + if(preg_match("/workstation/i",$this->BelongsTo)){ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn); } @@ -646,7 +708,7 @@ class printgeneric extends plugin } /* If type is still unknown, the initialisation of this printer failed, abort. */ - if($this->BelongsTo == "unknown"){ + if(preg_match("/unknown/i",$this->BelongsTo)){ return; } @@ -655,6 +717,19 @@ class printgeneric extends plugin $this->PPDdialogToSave->save_ppd(); } + if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){ + $method="https://"; + }else{ + $method="http://"; + } + + /* If no ppd is selected, remove this attribute */ + if(!empty($this->gotoPrinterPPD)) { + $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD); + }else{ + $this->gotoPrinterPPD = array(); + } + $dn= $this->dn; plugin::save(); $ldap= $this->config->get_ldap_link(); @@ -674,14 +749,6 @@ class printgeneric extends plugin $this->attrs= $attrs; } - if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){ - $method="https://"; - }else{ - $method="http://"; - } - - $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD); - /* Append printer user */ $this->attrs['gotoUserPrinter']=array(); @@ -710,42 +777,56 @@ class printgeneric extends plugin $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0]; } - if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){ - $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag"; + if($this->orig_dn == 'new'){ + foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){ + if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){ + unset($this->attrs[$checkVar]); + } + } + }else{ + if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){ + $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag"; + } } + /* Move object in necessary*/ + if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){ + $this->move($this->orig_dn, $this->dn); + } /* Write back to ldap */ $ldap= $this->config->get_ldap_link(); - if ($this->orig_dn == 'new'){ + $ldap->cat($this->dn); + if(!$ldap->count()){ $ldap->cd($this->config->current['BASE']); $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); $ldap->cd($this->dn); $ldap->add($this->attrs); $this->handle_post_events("add"); } else { - if ($this->orig_dn != $this->dn){ - $this->move($this->orig_dn, $this->dn); - } - $ldap->cd($this->dn); $this->cleanup(); $ldap->modify ($this->attrs); - $this->handle_post_events("modify"); } show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn)); - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->dn = $this->dn; - $this->netConfigDNS->save($this->dn); + if(preg_match("/printer/i",$this->BelongsTo)){ + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->dn = $this->dn; + $this->netConfigDNS->save($this->dn); + } /* Optionally execute a command after we're done */ $this->postcreate(); + + /* This is a multi object. Handle tagging here... */ + $this->handle_object_tagging(); } function generateList(){ $a_return=array(); + foreach($this->member as $type => $values){ $a_return[$type]=array(); foreach($values as $value){ @@ -772,12 +853,13 @@ class printgeneric extends plugin "plDescription" => _("Print generic"), "plSelfModify" => FALSE, "plDepends" => array(), - "plPriority" => 0, + "plPriority" => 4, "plSection" => array("administration"), "plCategory" => array("printer" => array("description" => _("Printer"), - "objectClass" => "gotoPrinter")), + "objectClass" => "gotoPrinter"),"workstation","terminal"), "plProvidedAcls"=> array( - "cn" => _("Name"), + "cn" => _("Name"), + "base" => _("Base") , "description" => _("Description"), "l" => _("Location"), "labeledURI" => _("LabeledURL"), @@ -790,9 +872,23 @@ class printgeneric extends plugin /* Delete member */ function DelMember($type,$id) { + /* Check if there was a printer "dn" given, or the "cn" */ + foreach($this->member[$type] as $key => $printer){ + if($printer['dn'] == $id) { + $id = $key; + } + } + + if(!$this->acl_is_writeable("gotoUserPrinter")){ + print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn)); + return(FALSE); + } + if(isset($this->member[$type][$id])){ unset($this->member[$type][$id]); + return(TRUE); } + return(FALSE); } @@ -802,7 +898,12 @@ class printgeneric extends plugin $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; + return(FALSE); + } + + if(!$this->acl_is_writeable("gotoUserPrinter")){ + print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn)); + return(FALSE); } /* Get name of index attributes */ @@ -814,29 +915,44 @@ class printgeneric extends plugin $ldap = $this->config->get_ldap_link(); $ldap->cd($dn); - $ldap->cat($dn,array("cn","uid")); + $ldap->cat($dn,array($var,"cn")); 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; + + if(isset($attrs[$var][0])){ + $name = $attrs[$var][0]; + + /* Check if this uid/cn is already assigned to any permission */ + foreach($types as $ctype){ + + /* If we want to add a user, only check user/userAdmin members */ + if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){ + continue; + } + + /* If we want to add a group, only check groups/adminGroups .. */ + if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){ + continue; + } + + 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(FALSE); + } } - } - /* Everything is fine. So add the given object to members */ - $this->member[$type][$attrs[$var][0]] = $attrs ; + /* Everything is fine. So add the given object to members */ + $this->member[$type][$attrs[$var][0]] = $attrs ; + }else{ + print_a($attrs); + } }else{ print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn)); + return(FALSE); } + return(TRUE); } - - - }