X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_printGeneric.inc;h=a3a3f34a32a3c694878816caa2007b5a0ec7c8fe;hb=ccb05fb19fe5af3570c2c57b703a595b1c78bf28;hp=9cccd381a2afd013918ff2dcada07f989a971ad6;hpb=22f2e0957eb326f21a07385b8faa95a368bb7da1;p=gosa.git diff --git a/plugins/admin/systems/class_printGeneric.inc b/plugins/admin/systems/class_printGeneric.inc index 9cccd381a..a3a3f34a3 100644 --- a/plugins/admin/systems/class_printGeneric.inc +++ b/plugins/admin/systems/class_printGeneric.inc @@ -2,11 +2,6 @@ class printgeneric extends plugin { - /* CLI vars */ - var $cli_summary = "Manage terminal base objects"; - var $cli_description = "Some longer text\nfor help"; - var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); - /* Generic terminal attributes */ var $interfaces = array(); var $ignore_account = FALSE; @@ -18,6 +13,7 @@ class printgeneric extends plugin var $description = ""; var $labeledURI = ""; var $gotoPrinterPPD = ""; + var $initial_PPD = ""; var $orig_dn = ""; var $UserMember =""; @@ -64,11 +60,11 @@ class printgeneric extends plugin } /* Update dn, to ensure storing as printer instead of WS / terminal */ - if($this->BelongsTo == "Terminal"){ + if($this->BelongsTo == "Terminal" || $this->BelongsTo == "TerminalTemplate"){ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn); } - if($this->BelongsTo == "Workstation"){ + if($this->BelongsTo == "Workstation" || $this->BelongsTo == "WorkstationTemplate"){ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn); } @@ -90,6 +86,7 @@ class printgeneric extends plugin /* create dns object */ $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses); + $this->netConfigDNS->acl = $this->acl; /* Set base */ if ($this->dn == "new"){ @@ -115,6 +112,8 @@ class printgeneric extends plugin $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD); } + $this->initial_PPD = $this->gotoPrinterPPD; + /* Prepare different member types */ foreach(array("AddUser" =>"gotoUserPrinter", "AddGroup" =>"gotoGroupPrinter", @@ -240,6 +239,8 @@ class printgeneric extends plugin function execute() { + $this->netConfigDNS->acl = $this->acl; + /* Call parent execute */ plugin::execute(); @@ -248,7 +249,7 @@ class printgeneric extends plugin */ if($this->BelongsTo == "unknown"){ $display= $this->show_header(_("Add printer extension"), - _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE); + _("Could not initialize printer tab, parameter parent was missing while construction."),TRUE,TRUE); return($display); } @@ -283,10 +284,17 @@ class printgeneric extends plugin $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; + + /* Only change account state if allowed */ + if($this->is_account && $this->acl == "#all#"){ + $this->is_account= !$this->is_account; + $this->is_modified = true; + }elseif(!$this->is_account && chkacl($this->acl,"create") == "" && !((empty($this->cn)) && ($this->dn != "new"))){ + $this->is_account= !$this->is_account; + $this->is_modified = true; + } } /* Do we represent a valid printer? */ @@ -328,7 +336,7 @@ 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 && chkacl($this->acl,"base")){ $once = false; $this->dialog = new baseSelectDialog($this->config); $this->dialog->setCurrentBase($this->base); @@ -367,30 +375,31 @@ class printgeneric extends plugin $smarty->assign("baseACL", chkacl($this->acl,"base")); - if(isset($_POST['AddUser'])){ + if(isset($_POST['AddUser']) && chkacl($this->acl,"gotoUserPrinter") == ""){ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser"); } - if(isset($_POST['AddGroup'])){ + if(isset($_POST['AddGroup']) && chkacl($this->acl,"gotoGroupPrinter") == ""){ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup"); } - if(isset($_POST['AddAdminUser'])){ + if(isset($_POST['AddAdminUser']) && chkacl($this->acl,"gotoUserAdminPrinter") == ""){ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser"); } - if(isset($_POST['AddAdminGroup'])){ + if(isset($_POST['AddAdminGroup']) && chkacl($this->acl,"gotoGroupAdminPrinter") == ""){ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup"); } /* Display ppd configure/select dialog */ - if(isset($_POST['EditDriver'])){ + if(isset($_POST['EditDriver']) && chkacl($this->acl,"gotoPrinterPPD")==""){ if($this->PPDdialogToSave){ $this->dialog = $this->PPDdialogToSave; }else{ $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD); + $this->dialog->cn= $this->cn; } } /* remove ppd */ - if(isset($_POST['RemoveDriver'])){ + if(isset($_POST['RemoveDriver']) && chkacl($this->acl,"gotoPrinterPPD")==""){ $this->gotoPrinterPPD = array(); $this->PPDdialogToSave = NULL; } @@ -418,25 +427,25 @@ class printgeneric extends plugin } /* Member management, delete user / group / admin ..*/ - if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ + if((isset($_POST['DelUser']))&&(isset($_POST['UserMember'])) && chkacl($this->acl,"gotoUserPrinter")==""){ foreach($_POST['UserMember'] as $mem){ $this->DelMember('AddUser',$mem); } } - if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ + if((isset($_POST['DelUser']))&&(isset($_POST['UserMember'])) && chkacl($this->acl,"gotoGroupPrinter")==""){ foreach($_POST['UserMember'] as $mem){ $this->DelMember('AddGroup',$mem); } } - if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ + if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember'])) && chkacl($this->acl,"gotoUserAdminPrinter")==""){ foreach($_POST['AdminMember'] as $mem){ $this->DelMember('AddAdminUser',$mem); } } - if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ + if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember'])) && chkacl($this->acl,"gotoGroupAdminPrinter")==""){ foreach($_POST['AdminMember'] as $mem){ $this->DelMember('AddAdminGroup',$mem); } @@ -490,10 +499,10 @@ class printgeneric extends plugin $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD)); } }else{ - $smarty->assign("driverInfo", _("not defined")); + $smarty->assign("driverInfo", _("Not defined")); } }else{ - $smarty->assign("driverInfo",_("can't get ppd informations.")); + $smarty->assign("driverInfo",_("Can't get ppd informations.")); } /* Create user & admin user list */ @@ -522,16 +531,28 @@ class printgeneric extends plugin $smarty->assign("AdminMembers" ,$adminlist); $smarty->assign("AdminMemberKeys",array_flip($adminlist)); if($this->BelongsTo == "Printer"){ + $this->netConfigDNS->cn= $this->cn; $smarty->assign("netconfig", $this->netConfigDNS->execute()); + + /* Display sub dialog from network settings */ + if($this->netConfigDNS->dialog){ + $this->dialog = TRUE; + return($this->netConfigDNS->execute()); + }else{ + $this->dialog = FALSE; + } } else { $smarty->assign("netconfig", ""); } + return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE))); } function remove_from_parent() { + $this->netConfigDNS->acl = $this->acl; + /* Only remove if there was initially an account */ if($this->initially_was_account){ @@ -564,16 +585,22 @@ class printgeneric extends plugin $this->netConfigDNS->remove_from_parent(); $ldap->rmdir($this->dn); show_ldap_error($ldap->get_error(), _("Removing printer failed")); - $this->handle_post_events("remove"); + $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); /* Delete references to object groups */ $ldap->cd ($this->config->current['BASE']); - $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn")); + $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn")); while ($ldap->fetch()){ $og= new ogroup($this->config, $ldap->getDN()); unset($og->member[$this->dn]); $og->save (); } + + /* Remove previously selected ppd file.*/ + if(!empty($this->initial_PPD)){ + $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD); + $tmp->removeModifiedPPD(); + } } } @@ -613,13 +640,18 @@ class printgeneric extends plugin /* must: cn */ if(($this->BelongsTo == "Printer") && (empty($this->cn))){ - $message[]= "The required field 'Printer name' is not set."; + $message[]= _("The required field 'Printer name' is not set."); + } + + /* must: cn */ + if(($this->BelongsTo == "Printer") && !is_dns_name($this->cn)){ + $message[]= _("Invalid character in printer name."); } if($this->BelongsTo == "Printer"){ $ui= get_userinfo(); $acl= get_permissions ($dn, $ui->subtreeACL); - $acl= get_module_permission($acl, "printer", $this->dn); + $acl= get_module_permission($acl, "printgeneric", $dn); if (chkacl($acl, "create") != ""){ $message[]= _("You have no permissions to create a printer on this 'Base'."); } @@ -638,6 +670,9 @@ class printgeneric extends plugin $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn")); if ($ldap->count() != 0){ while ($attrs= $ldap->fetch()){ + if(preg_match("/cn=dhcp,/",$attrs['dn'])){ + continue; + } if ($attrs['dn'] != $this->orig_dn){ $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn); break; @@ -653,6 +688,8 @@ class printgeneric extends plugin /* Save to LDAP */ function save() { + $this->netConfigDNS->acl = $this->acl; + /* Update dn, to ensure storing as printer instead of WS / terminal */ if($this->BelongsTo == "Terminal"){ @@ -661,8 +698,7 @@ class printgeneric extends plugin if($this->BelongsTo == "Workstation"){ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn); - $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; - $this->netConfigDNS->macAddress = $mac; + $this->macAddress = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; } if(!$this->is_account) return; @@ -686,6 +722,36 @@ class printgeneric extends plugin $this->PPDdialogToSave->save_ppd(); } + if($this->orig_dn != $this->dn && $this->initially_was_account){ + if(!empty($this->gotoPrinterPPD)) { + $this->PPDdialogToSave = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD); + $this->PPDdialogToSave->cn = $this->cn; + $this->PPDdialogToSave->generateProperties(); + $this->gotoPrinterPPD = $this->PPDdialogToSave->update_ppd_url(); + } + } + + /* Remove previously selected ppd file.*/ + if($this->initial_PPD != $this->gotoPrinterPPD && $this->initially_was_account){ + if(!empty($this->initial_PPD)){ + $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD); + $tmp->removeModifiedPPD(); + } + } + + 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(); @@ -705,19 +771,6 @@ class printgeneric extends plugin $this->attrs= $attrs; } - if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){ - $method="https://"; - }else{ - $method="http://"; - } - - /* Only save ppd path, if the path is not empty (no ppd selected )*/ - if(count($this->gotoPrinterPPD)) { - $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD); - }else{ - $this->attrs['gotoPrinterPPD'] = array(); - } - /* Append printer user */ $this->attrs['gotoUserPrinter']=array(); @@ -748,6 +801,7 @@ class printgeneric extends plugin if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){ $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag"; + $this->attrs['gosaUnitTag'] = $this->gosaUnitTag; } if($this->orig_dn == 'new'){ @@ -758,14 +812,27 @@ class printgeneric extends plugin } } + /* Ensure to create a new object */ + if(preg_match("/ou=incoming,/",$this->orig_dn)){ + $this->orig_dn = "new"; + } + /* Write back to ldap */ $ldap= $this->config->get_ldap_link(); if ($this->orig_dn == 'new'){ $ldap->cd($this->config->current['BASE']); $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); $ldap->cd($this->dn); + + /* Remove empty values */ + foreach($this->attrs as $name => $value){ + if(empty($value)){ + unset($this->attrs[$name]); + } + } + $ldap->add($this->attrs); - $this->handle_post_events("add"); + $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); } else { if ($this->orig_dn != $this->dn){ $this->move($this->orig_dn, $this->dn); @@ -775,20 +842,16 @@ class printgeneric extends plugin $this->cleanup(); $ldap->modify ($this->attrs); - $this->handle_post_events("modify"); + $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); } show_ldap_error($ldap->get_error(), _("Saving printer failed")); - - $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(); + /* Only save dns stuff if we are a standalone printer */ + if($this->BelongsTo == "Printer"){ + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->dn = $this->dn; + $this->netConfigDNS->save($this->dn); + } } function generateList(){