X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_printGeneric.inc;h=021c75f9d0f5b6864dbd6fbe27e31abb6d306aac;hb=269b6da4461630896e0af284cca9742b9f819f2b;hp=c6b177fadef392029f8476493596f14808030cda;hpb=01fb82096b2384e010bb4b9dc9bad91ee711dcc1;p=gosa.git
diff --git a/plugins/admin/systems/class_printGeneric.inc b/plugins/admin/systems/class_printGeneric.inc
index c6b177fad..021c75f9d 100644
--- a/plugins/admin/systems/class_printGeneric.inc
+++ b/plugins/admin/systems/class_printGeneric.inc
@@ -14,190 +14,298 @@ class printgeneric extends plugin
/* Needed values and lists */
var $base = "";
var $cn = "";
- var $macAddress = "";
- var $ipHostNumber = "";
var $l = "";
var $description = "";
var $labeledURI = "";
var $gotoPrinterPPD = "";
var $orig_dn = "";
- var $is_terminal = false;
var $UserMember ="";
var $UserMembers =array();
var $UserMemberKeys =array();
-
+
var $AdminMember ="";
var $AdminMembers =array();
var $AdminMemberKeys =array();
- var $is_terminalBased = false;
-
+ var $PPDdialogToSave = NULL;
+ var $BelongsTo = "unknown"; // Specifies if this is a standalone printer, or belongs to a terminal / WS
+
var $member =array();
var $strings = "";
- var $type = "";
var $dialog =NULL;
+ var $netConfigDNS;
+ var $baseSelection = false;
+ var $macAddress = "";
+
+ var $gotoUserAdminPrinter;
+ var $gotoGroupAdminPrinter ;
+ var $gotoGroupPrinter;
+ var $gotoUserPrinter ;
+
/* attribute list for save action */
- var $attributes = array("cn", "description", "l", "labeledURI", "macAddress", "ipHostNumber","gotoPrinterPPD");
+ var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
+ "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
var $objectclasses = array("top", "gotoPrinter");
- function printgeneric ($config, $dn= NULL)
+ var $parent;
+
+ function printgeneric ($config, $dn,$parent_init,$parent)
{
- plugin::plugin ($config, $dn);
+ $this->config = $config;
+ $this->dn = $dn;
+
+ /* If parent was posted(the tabs object) we can detect the printer type. */
+ if($parent){
+ $this->parent = $parent;
+ $this->getTypeOfPrinter();
+ }else{
+ $this->BelongsTo = "unknown";
+ return;
+ }
+
+ /* Update dn, to ensure storing as printer instead of WS / 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(preg_match("/Workstation/i",$this->BelongsTo) || preg_match("/WorkstationTemplate/i",$this->BelongsTo)){
+ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
+ }
+
+ $this->orig_dn = $this->dn;
+
+ /* Get printer settings, possibly dn has changed */
+ plugin::plugin ($config, $this->dn);
+
+ /* Get is_account initially_was_account status */
+ $this->getTypeOfPrinter(true);
+
+ /* set orig dn to new if object is new */
$ldap= $this->config->get_ldap_link();
+ $ldap->cat($this->dn, array('dn'));
+ if(!$ldap->count()){
+ $this->orig_dn = "new";
+ }
+
+ /* create dns object */
+ $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
/* Set base */
if ($this->dn == "new"){
$ui= get_userinfo();
$this->base= dn2base($ui->dn);
$this->cn= "";
- $this->is_terminal = true;
} else {
- $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
- }
-
+
+ /* Set base and check if the extracted base exists */
+ if(preg_match("/ou=incoming,/",$this->dn)){
+ $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
+ }else{
+ $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
+ }
- /* In case of gotoWorkstation this tab is calles from workstation plugin
- * in case of gotoTerminal it is called from a terminal tab
- * else it is a standalone printer
- */
- if((isset($this->attrs['objectClass']))&&(in_array("gotoWorkstation",$this->attrs['objectClass']))){
- $this->is_terminal = "true";
- $this->dn = preg_replace("/ou=workstation/","ou=printer",$this->dn);
- $this->type = "station";
- }elseif((isset($this->attrs['objectClass']))&&(in_array("gotoTerminal",$this->attrs['objectClass']))){
- $this->type = "terminal";
- $this->is_terminal = "true";
- $this->dn = preg_replace("/ou=terminal/","ou=printer",$this->dn);
- }else{
- /* Save dn for later references */
- $this->orig_dn= $this->dn;
+ if(!isset($this->config->idepartments[$this->base])){
+ print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
+ $this->base = $_SESSION['CurrentMainBase'];
+ }
}
- /* If it is no standalone printer
- */
- if($this->is_terminal){
- // Reload plugin with new dn... (ou=printers instead of ou=terminals)
- plugin::plugin ($this->config, $this->dn);
- $ldap->cat($this->dn);
- if(count($ldap->fetch())>0){
- $this->orig_dn= $this->dn;
- $this->is_account=true;
- $this->initially_was_account = true;
- }else{
- $this->orig_dn = "new";
- $this->is_account=false;
- $this->initially_was_account = false;
- }
+ /* Extract selected ppd */
+ if(isset($this->gotoPrinterPPD)){
+ $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
}
-
- /* Prepare different member types
- */
+ /* Prepare different member types */
foreach(array("AddUser" =>"gotoUserPrinter",
- "AddGroup" =>"gotoGroupPrinter",
- "AddAdminUser" =>"gotoUserAdminPrinter",
- "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
+ "AddGroup" =>"gotoGroupPrinter",
+ "AddAdminUser" =>"gotoUserAdminPrinter",
+ "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
/* $this->members contains all members */
$this->member[$type]=array();
- unset($this->attrs[$attr]['count']);
+ if (isset($this->attrs[$attr]['count'])) {
+ unset($this->attrs[$attr]['count']);
+ }
if(isset($this->attrs[$attr])){
foreach($this->attrs[$attr] as $mem){
if(preg_match("/Group/",$type)){
$ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
- $entry = $ldap->fetch();
- if(isset($entry['description'])){
+ 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;
}
}
}
}
}
-
- $ldap->search("(&(cn=".$this->cn.")(|(objectClass=gotoTerminal)(objectClass=gotoWorkstation)))",array("cn","objectClass"));
- if($attrs = $ldap->fetch()){
- if(in_array("gotoTerminal",$attrs['objectClass'])){
- $this->is_terminalBased = "Terminal";
+ }
+
+ 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.
+ * We can detect the type printer type when comparing the tabs objects
+ */
+ function getTypeOfPrinter($UpdateAccountStatus = false)
+ {
+ /* Disable account as default
+ */
+ $this->is_account = $this->initially_was_account = false;
+
+ /* Detect type of printer via parent tabs.
+ */
+
+ $class = get_class($this->parent);
+ if(isset($this->parent->by_object['workgeneric'])){
+
+ /* Exclude templates
+ */
+ $this->cn = $this->parent->by_object['workgeneric']->cn;
+ if($this->parent->by_object['workgeneric']->cn == "wdefault"){
+ $this->BelongsTo = "WorkstationTemplate";
+ }else{
+ $this->BelongsTo = "Workstation";
+ }
+ }elseif(isset($this->parent->by_object['termgeneric'])){
+
+ /* Exclude templates
+ */
+ $this->cn = $this->parent->by_object['termgeneric']->cn;
+ if($this->parent->by_object['termgeneric']->cn == "default"){
+ $this->BelongsTo = "TerminalTemplate";
}else{
- $this->is_terminalBased = "Workstation";
+ $this->BelongsTo = "Terminal";
}
+ }elseif(isset($this->parent->by_name['printgeneric'])){
+ $this->BelongsTo = "Printer";
}
+ if($UpdateAccountStatus){
+
+ /* Set is_account / was account
+ */
+ if($this->dn == "new"){
+ $this->initially_was_account = false;
+ }
+
+ /* If is printer it must be a true account.
+ */
+ if(preg_match("/printer/i",$this->BelongsTo)){
+ $this->is_account = true;
+ }
+
+ /* Update dn, to ensure storing as printer instead of WS / terminal
+ */
+ if(preg_match("/terminal/i",$this->BelongsTo)){
+ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
+ }
+
+ 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;
+ */
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cat($this->dn, array('objectClass'));
+ if($ldap->count()){
+ $attrs = $ldap->fetch();
+ if(in_array("gotoPrinter",$attrs['objectClass'])){
+ $this->initially_was_account = true;
+ $this->is_account = true;
+ }else{
+ $this->is_account = false;
+ }
+ }
+ }
}
function execute()
{
+ /* Call parent execute */
+ plugin::execute();
+
+ /* If type of printer couldn't be detected (because of missing parent object in construction)
+ * hide this tab.
+ */
+ 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);
+ }
+
+ /* Templates can't have printer extensions
+ */
+ 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(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(preg_match("/^Workstation$/i",$this->BelongsTo)){
+ $this->cn = $this->parent->by_object['workgeneric']->cn;
+ }
+ 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="";
- /* Template management.
- * There are two ways to call this tab.
- * 1. From a printer Dialog, here we will see the full template, without a toggle state button
- * 2. As a terminal tab, here we hide the top (name,base,description) of the template.
- * Toggle Account state will be shown in this case, to disable or enable this tab.
- *
- * $this->is_terminal indecates this two different types.
- */
- if($this->is_terminal){
- $smarty->assign("is_terminal","true");
+
+ /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
+ if(preg_match("/^Printer$/i",$this->BelongsTo)){
+ $smarty->assign("StandAlone",true);
}else{
- $smarty->assign("is_terminal","false");
+ $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($this->is_terminal){
- if(empty($this->cn)){
- if(!in_array("gotoPrinter",$this->objectclasses)){
- $display= $this->show_header(_("Add printer extension"),
- _("This workstation 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);
- $this->is_account= false;
- return $display;
- }else{
- $smarty->assign("is_terminal","false");
- $skip = true;
- }
- }
-
- if(!isset($skip)){
- if (($this->is_account)){
- if($this->type=="station"){
- $display= $this->show_header(_("Remove printer extension"),
- _("This workstation has printer extension enabled.You can disable it by clicking below."));
- }else{
- $display= $this->show_header(_("Remove printer extension"),
- _("This terminal has printer extension enabled. You can disable it by clicking below."));
- }
- }else{
- if($this->type=="station"){
- $display= $this->show_header(_("Add printer extension"),
- _("This workstation has printer extension disabled. You can enable it by clicking below."));
- }else{
- $display= $this->show_header(_("Add printer extension"),
- _("This terminal has printer extension disabled. You can enable it by clicking below."));
- }
- return ($display);
- }
+ 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? */
if (!$this->is_account && $this->parent == NULL){
$display= " ".
@@ -205,39 +313,117 @@ class printgeneric extends plugin
return($display);
}
+ /* If this is a WS / Terminal depending printer, display account state button */
+ 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);
+ $this->is_account= false;
+ return $display;
+ }
+
+ if (($this->is_account)){
+ 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(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(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(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."));
+ }
+ return ($display);
+ }
+ }
+
+ /* Base select dialog */
+ $once = true;
+ foreach($_POST as $name => $value){
+ if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
+ $once = false;
+ $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
+ $this->dialog->setCurrentBase($this->base);
+ $this->baseSelection = true;
+ }
+ }
+
+ /* Dialog handling for base select dialog
+ * Check if base was selected, dialog aborted etc */
+ if(is_object($this->dialog)){
+
+ $this->dialog->save_object();
+ if($this->baseSelection){
+ if($this->dialog->isClosed()){
+ $this->dialog = false;
+ $this->baseSelection = false;
+ }elseif($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{
+ return($this->dialog->execute());
+ }
+ }
+ }
+
/* 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);
}
if(isset($_POST['AddUser'])){
- $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddUser");
+ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
}
if(isset($_POST['AddGroup'])){
- $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddGroup");
+ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
}
if(isset($_POST['AddAdminUser'])){
- $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminUser");
+ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
}
if(isset($_POST['AddAdminGroup'])){
- $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminGroup");
+ $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
}
+ /* Display ppd configure/select dialog */
if(isset($_POST['EditDriver'])){
- $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+ if($this->PPDdialogToSave){
+ $this->dialog = $this->PPDdialogToSave;
+ }else{
+ $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+ }
}
- if(isset($_POST['PrinterCancel'])){
+ /* remove ppd */
+ if(isset($_POST['RemoveDriver'])){
+ $this->gotoPrinterPPD = array();
+ $this->PPDdialogToSave = NULL;
+ }
+
+ /* Close ppd dialog */
+ if(isset($_POST['ClosePPD'])){
unset($this->dialog);
- $this->dialog= NULL;
+ $this->dialog=NULL;
}
+ /* Save selected ppd */
if(isset($_POST['SavePPD'])){
+ $this->dialog->save_object();
if(count($this->dialog->check())){
foreach($this->dialog->check() as $msg){
print_red($msg);
@@ -245,41 +431,44 @@ class printgeneric extends plugin
}else{
$this->gotoPrinterPPD = array();
$this->gotoPrinterPPD = $this->dialog->save();
+ $this->PPDdialogToSave = $this->dialog;
unset($this->dialog);
$this->dialog=NULL;
}
-
- }
-
- if(isset($_POST['ClosePPD'])){
- unset($this->dialog);
- $this->dialog=NULL;
}
+ /* 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);
}
}
+ /* Abort user / group adding dialog */
+ if(isset($_POST['PrinterCancel'])){
+ unset($this->dialog);
+ $this->dialog= NULL;
+ }
+
+ /* Save selected users / groups */
if(isset($_POST['PrinterSave'])){
$this->dialog->save_object();
if(count($this->dialog->check())){
@@ -287,56 +476,63 @@ 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;
+ $this->AddMember($new['type'], $mem['dn']);
}
unset($this->dialog);
- $this->dialog=NULL;
+ $this->dialog=NULL;
}
}
+ /* Display dialog, if there is currently one open*/
if($this->dialog != NULL){
+ $this->dialog->save_object();
$display = $this->dialog->execute();
return $display;
}
- /* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
- $smarty->assign("staticAddress", "");
+ /* Parse selected ppd file */
+ require_once ("class_ppdManager.inc");
+ if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
+ $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
+ if(!preg_match("/\/$/",$path)){
+ $path = $path."/";
+ }
- require_once ("class_ppdManager.inc");
- $ppdManager= new ppdManager('/var/spool/ppd/');
- if(!empty($this->gotoPrinterPPD)){
- $smarty->assign("driverInfo", $ppdManager->loadDescription($this->gotoPrinterPPD));
+ $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)."");
+ }else{
+ $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
+ }
+ }else{
+ $smarty->assign("driverInfo", _("not defined"));
+ }
}else{
- $smarty->assign("driverInfo", _("Undefined"));
+ $smarty->assign("driverInfo",_("can't get ppd informations."));
}
+ /* Create user & admin user list */
$list=$this->generateList();
$userlist = array_merge($list['AddUser'],$list['AddGroup']);
$adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
asort($userlist);
asort($adminlist);
- if($this->is_terminalBased){
- if($this->is_terminalBased == "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" ,_(""));
+ $smarty->assign("desc" ,"");
}
$smarty->assign("UserMember" ,$this->UserMember);
$smarty->assign("UserMembers" ,$userlist);
@@ -345,61 +541,134 @@ class printgeneric extends plugin
$smarty->assign("AdminMember" ,$this->AdminMember);
$smarty->assign("AdminMembers" ,$adminlist);
$smarty->assign("AdminMemberKeys",array_flip($adminlist));
- $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
+ 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)));
}
function remove_from_parent()
{
- $ldap= $this->config->get_ldap_link();
- $ldap->rmdir($this->dn);
- show_ldap_error($ldap->get_error());
- $this->handle_post_events("remove");
-
- /* Delete references to object groups */
- $ldap->cd ($this->config->current['BASE']);
- $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
- while ($ldap->fetch()){
- $og= new ogroup($this->config, $ldap->getDN());
- unset($og->member[$this->dn]);
- $og->save ();
+ /* Only remove if there was initially an account */
+ if($this->initially_was_account){
+
+ /* Update dn, to ensure storing as printer instead of WS / terminal
+ */
+ if(preg_match("/terminal/i",$this->BelongsTo)){
+ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
+ }
+
+ if(preg_match("/workstation/i",$this->BelongsTo)){
+ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
+ }
+
+ /* Check if this dn points to a printer, to avoid deleting something else */
+ $ldap= $this->config->get_ldap_link();
+ $ldap->cat($this->dn, array('dn',"objectClass"));
+ if(!$ldap->count()){
+ print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
+ return;
+ }
+
+ /* Check if obejct is a printer */
+ $CheckPrinter = $ldap->fetch();
+ if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
+ print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
+ return;
+ }
+
+ /* Remove account & dns extension */
+ $this->netConfigDNS->remove_from_parent();
+ $ldap->rmdir($this->dn);
+ show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
+ $this->handle_post_events("remove");
+
+ /* Delete references to object groups */
+ $ldap->cd ($this->config->current['BASE']);
+ $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
+ while ($ldap->fetch()){
+ $og= new ogroup($this->config, $ldap->getDN());
+ unset($og->member[$this->dn]);
+ $og->save ();
+ }
}
}
+
/* 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->base = $base_tmp;
- /* Save base, since this is no LDAP attribute */
- if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
- $this->base= $_POST['base'];
+ 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'];
+ }
}
}
/* Check supplied data */
function check()
{
- $message= array();
- $this->dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
+ /* Call common method to give check the hook */
+ $message= plugin::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'])){
+ if($this->parent->by_object['workgeneric']->cn == "wdefault"){
+ return $message;
+ }
+ }elseif(isset($this->parent->by_object['termgeneric'])){
+ if($this->parent->by_object['termgeneric']->cn == "default"){
+ return $message;
+ }
+ }
+
+ $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
/* must: cn */
- if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
+ if(preg_match("/printer/i",$this->BelongsTo) && (empty($this->cn))){
$message[]= "The required field 'Printer name' is not set.";
}
- $ui= get_userinfo();
- $acl= get_permissions ($this->dn, $ui->subtreeACL);
- $acl= get_module_permission($acl, "printer", $this->dn);
- if (chkacl($acl, "create") != ""){
- $message[]= _("You have no permissions to create a printer on this 'Base'.");
+ /* Set new acl base */
+ if($this->dn == "new") {
+ $this->set_acl_base($this->base);
}
- if (($this->orig_dn != $this->dn)&&(!$this->is_terminal)){
+ 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)){
+ $message[]= "The required field 'Printer URL' is not set.";
+ }
+
+ /* Check if there is already an entry with this cn*/
+ if (($this->orig_dn != $dn)&&( preg_match("/printer/i",$this->BelongsTo))){
$ldap= $this->config->get_ldap_link();
$ldap->cd ($this->base);
- $ldap->search ("(cn=".$this->cn.")", array("cn"));
+ $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
if ($ldap->count() != 0){
while ($attrs= $ldap->fetch()){
if ($attrs['dn'] != $this->orig_dn){
@@ -417,34 +686,57 @@ class printgeneric extends plugin
/* Save to LDAP */
function save()
{
- $dn= $this->dn;
- plugin::save();
- $ldap= $this->config->get_ldap_link();
-
- if((in_array("gotoTerminal",$this->attrs['objectClass']))){
- $this->dn= preg_replace("/ou=terminal/","ou=printer",$this->dn);
+ /* Update dn, to ensure storing as printer instead of WS / terminal
+ */
+ if(preg_match("/terminal/i",$this->BelongsTo)){
+ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
+ }
+
+ if(preg_match("/workstation/i",$this->BelongsTo)){
+ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
}
- if((in_array("gotoWorkstation",$this->attrs['objectClass']))){
- $this->dn= preg_replace("/ou=workstation/","ou=printer",$this->dn);
+ if(!$this->is_account) return;
+ if(isset($this->parent->by_object['workgeneric'])){
+ if($this->parent->by_object['workgeneric']->cn == "wdefault"){
+ return;
+ }
+ }elseif(isset($this->parent->by_object['termgeneric'])){
+ if($this->parent->by_object['termgeneric']->cn == "default"){
+ return;
+ }
}
- /* We are currently editing a Terminal, so we want to save a seperate printer which cn is the terminla cn
- */
- if($this->is_terminal){
-
- /* reduce objectClasses to minimun */
- $this->attrs['objectClass']= $this->objectclasses;
+ /* If type is still unknown, the initialisation of this printer failed, abort. */
+ if(preg_match("/unknown/i",$this->BelongsTo)){
+ return;
+ }
- /* If a printer with the given dn exists, modify else create new one */
- $ldap->cat($this->dn);
- if($ldap->fetch()){
- $this->orig_dn= $this->dn;
- }else{
- $this->orig_dn = "new";
- }
+ /* save ppd configuration */
+ if($this->PPDdialogToSave){
+ $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();
+
+ /* reduce objectClasses to minimun */
+ $this->attrs['objectClass']= $this->objectclasses;
+
/* Remove all empty values */
if ($this->orig_dn == 'new'){
$attrs= array();
@@ -457,56 +749,84 @@ class printgeneric extends plugin
$this->attrs= $attrs;
}
-
/* Append printer user
*/
+ $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];
}
+ 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);
- $ldap->modify($this->attrs);
+ $this->cleanup();
+ $ldap->modify ($this->attrs);
$this->handle_post_events("modify");
}
- show_ldap_error($ldap->get_error());
+ show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$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){
@@ -523,6 +843,116 @@ class printgeneric extends plugin
}
return($a_return);
}
+
+ /* Return plugin informations for acl handling
+ #FIXME FAIscript seams to ununsed within this class... */
+ function plInfo()
+ {
+ return (array(
+ "plShortName" => _("Generic"),
+ "plDescription" => _("Print generic"),
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 4,
+ "plSection" => array("administration"),
+ "plCategory" => array("printer" => array("description" => _("Printer"),
+ "objectClass" => "gotoPrinter"),"workstation","terminal"),
+ "plProvidedAcls"=> array(
+ "cn" => _("Name"),
+ "base" => _("Base") ,
+ "description" => _("Description"),
+ "l" => _("Location"),
+ "labeledURI" => _("LabeledURL"),
+ "gotoPrinterPPD" => _("Printer PPD"),
+ "gotoUserPrinter" => _("Permissions"))
+ ));
+ }
+
+
+ /* 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);
+ }
+
+
+ /* 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(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 */
+ if(preg_match("/user/i",$type)){
+ $var = "uid";
+ }else{
+ $var = "cn";
+ }
+
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($dn);
+ $ldap->cat($dn,array($var,"cn"));
+ if($ldap->count()){
+
+ $attrs = $ldap->fetch();
+
+ 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 ;
+ }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);
+ }
}