From d3f0b67f8e3c3a6dd63d2b1a4e93d2da9651973b Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 23 Jul 2010 14:58:45 +0000 Subject: [PATCH] Updated class server/component and systemManagement -Fixed post handling and object listing. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19092 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../admin/systems/class_componentGeneric.inc | 574 ++-- .../admin/systems/class_filterOPSIHOSTS.inc | 74 +- .../admin/systems/class_filterSYSTEMS.inc | 2 +- .../systems/class_filterServerService.inc | 48 +- .../admin/systems/class_servGeneric.inc | 883 +++--- .../admin/systems/class_systemManagement.inc | 2576 ++++++++--------- .../systems/admin/systems/class_termDNS.inc | 2152 +++++++------- 7 files changed, 3158 insertions(+), 3151 deletions(-) diff --git a/gosa-plugins/systems/admin/systems/class_componentGeneric.inc b/gosa-plugins/systems/admin/systems/class_componentGeneric.inc index 4c4a3f4e0..3df59a13e 100644 --- a/gosa-plugins/systems/admin/systems/class_componentGeneric.inc +++ b/gosa-plugins/systems/admin/systems/class_componentGeneric.inc @@ -22,342 +22,342 @@ class componentGeneric extends plugin { - /* Generic terminal attributes */ - var $interfaces= array(); - var $ignore_account= TRUE; - - /* Needed values and lists */ - var $base= ""; - var $cn= ""; - var $description= ""; - var $orig_dn= ""; - var $orig_cn= ""; - var $orig_base= ""; - - /* attribute list for save action */ - var $attributes= array("cn", "description"); - var $objectclasses= array("top", "device", "ipHost", "ieee802Device"); - var $netConfigDNS; - var $view_logged = FALSE; - var $baseSelector; - - function componentGeneric (&$config, $dn= NULL, $parent= NULL) - { - plugin::plugin ($config, $dn, $parent); - - /* Set base */ - if ($this->dn == "new"){ - $ui= get_userinfo(); - $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn); - $this->cn= ""; - } else { - $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("componentGeneric", "componentRDN"), '/')."/i", "", $this->dn); + /* Generic terminal attributes */ + var $interfaces= array(); + var $ignore_account= TRUE; + + /* Needed values and lists */ + var $base= ""; + var $cn= ""; + var $description= ""; + var $orig_dn= ""; + var $orig_cn= ""; + var $orig_base= ""; + + /* attribute list for save action */ + var $attributes= array("cn", "description"); + var $objectclasses= array("top", "device", "ipHost", "ieee802Device"); + var $netConfigDNS; + var $view_logged = FALSE; + var $baseSelector; + + function componentGeneric (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config, $dn, $parent); + + /* Set base */ + if ($this->dn == "new"){ + $ui= get_userinfo(); + $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn); + $this->cn= ""; + } else { + $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("componentGeneric", "componentRDN"), '/')."/i", "", $this->dn); + } + $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses, true); + /* Save dn for later references */ + $this->orig_dn= $this->dn; + + $this->orig_base = $this->base; + $this->orig_cn = $this->cn; + + /* Instanciate base selector */ + $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base); + $this->baseSelector->setSubmitButton(false); + $this->baseSelector->setHeight(300); + $this->baseSelector->update(true); } - $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses, true); - /* Save dn for later references */ - $this->orig_dn= $this->dn; - $this->orig_base = $this->base; - $this->orig_cn = $this->cn; - /* Instanciate base selector */ - $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base); - $this->baseSelector->setSubmitButton(false); - $this->baseSelector->setHeight(300); - $this->baseSelector->update(true); - } + function execute() + { + /* Call parent execute */ + plugin::execute(); + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","component/".get_class($this),$this->dn); + } - function execute() - { - /* Call parent execute */ - plugin::execute(); + /* Do we represent a valid phone? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + msgPool::noValidExtension(_("component")).""; + return($display); + } - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","component/".get_class($this),$this->dn); - } + /* Fill templating stuff */ + $smarty= get_smarty(); - /* Do we represent a valid phone? */ - if (!$this->is_account && $this->parent === NULL){ - $display= "\"\" ". - msgPool::noValidExtension(_("component")).""; - return($display); - } - /* Fill templating stuff */ - $smarty= get_smarty(); + /* Set acls */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + /* Assign attributes */ + foreach ($this->attributes as $attr){ + $smarty->assign("$attr", set_post($this->$attr)); + } + $smarty->assign("base", $this->baseSelector->render()); - /* Set acls */ - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL",$this->getacl($name)); + /* Show main page */ + $str = $this->netConfigDNS->execute(); + if(is_object($this->netConfigDNS->dialog)){ + return($str); + } + $smarty->assign("netconfig", $str); + return($smarty->fetch (get_template_path('component.tpl', TRUE))); } - /* Assign attributes */ - foreach ($this->attributes as $attr){ - $smarty->assign("$attr", $this->$attr); + function set_acl_base($base) + { + plugin::set_acl_base($base); + $this->netConfigDNS->set_acl_base($base); } - $smarty->assign("base", $this->baseSelector->render()); - /* Show main page */ - $str = $this->netConfigDNS->execute(); - if(is_object($this->netConfigDNS->dialog)){ - return($str); - } - $smarty->assign("netconfig", $str); - return($smarty->fetch (get_template_path('component.tpl', TRUE))); - } - - function set_acl_base($base) - { - plugin::set_acl_base($base); - $this->netConfigDNS->set_acl_base($base); - } - - function set_acl_category($cat) - { - plugin::set_acl_category($cat); - $this->netConfigDNS->set_acl_category($cat); - } - - function remove_from_parent() - { - $ldap= $this->config->get_ldap_link(); - $this->netConfigDNS->remove_from_parent(); - $ldap->rmdir($this->dn); - - new log("remove","component/".get_class($this),$this->dn,$this->attributes,$ldap->get_error()); - - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class())); + function set_acl_category($cat) + { + plugin::set_acl_category($cat); + $this->netConfigDNS->set_acl_category($cat); } - $this->handle_post_events(array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + function remove_from_parent() + { + $ldap= $this->config->get_ldap_link(); + $this->netConfigDNS->remove_from_parent(); + $ldap->rmdir($this->dn); + + new log("remove","component/".get_class($this),$this->dn,$this->attributes,$ldap->get_error()); - /* Delete references to object groups */ - $ldap->cd ($this->config->current['BASE']); - $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 (); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class())); + } + + $this->handle_post_events(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=".LDAP::prepare4filter($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; - - $this->netConfigDNS->save_object(); - - /* Refresh base */ - if ($this->acl_is_moveable($this->base)){ - if (!$this->baseSelector->update()) { - msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG); - } - if ($this->base != $this->baseSelector->getBase()) { - $this->base= $this->baseSelector->getBase(); - $this->is_modified= TRUE; - } + + + /* 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; + + $this->netConfigDNS->save_object(); + + /* Refresh base */ + if ($this->acl_is_moveable($this->base)){ + if (!$this->baseSelector->update()) { + msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG); + } + if ($this->base != $this->baseSelector->getBase()) { + $this->base= $this->baseSelector->getBase(); + $this->is_modified= TRUE; + } + } + } - } + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + $message= array_merge($message,$this->netConfigDNS->check()); - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - $message= array_merge($message,$this->netConfigDNS->check()); + $this->dn= "cn=".$this->cn.",".get_ou("componentGeneric", "componentRDN").$this->base; - $this->dn= "cn=".$this->cn.",".get_ou("componentGeneric", "componentRDN").$this->base; + if ($this->cn == "" ){ + $message[]= msgPool::required(_("Component name")); + } - if ($this->cn == "" ){ - $message[]= msgPool::required(_("Component name")); - } + /* Check if given name is a valid host/dns name */ + if(!tests::is_dns_name($this->cn)){ + $message[]= msgPool::invalid(_("Component name"), $this->cn, "/[a-z0-9\.\-]/i"); + } - /* Check if given name is a valid host/dns name */ - if(!tests::is_dns_name($this->cn)){ - $message[]= msgPool::invalid(_("Component name"), $this->cn, "/[a-z0-9\.\-]/i"); - } + /* To check for valid ip*/ + if($this->netConfigDNS->ipHostNumber == ""){ + $message[]= msgPool::required(_("IP address")); + } else { + if (!tests::is_ip($this->netConfigDNS->ipHostNumber)){ + $message[]= msgPool::invalid(_("IP address"), "", "", "192.168.1.2"); + } + } - /* To check for valid ip*/ - if($this->netConfigDNS->ipHostNumber == ""){ - $message[]= msgPool::required(_("IP address")); - } else { - if (!tests::is_ip($this->netConfigDNS->ipHostNumber)){ - $message[]= msgPool::invalid(_("IP address"), "", "", "192.168.1.2"); - } - } + if ($this->orig_dn != $this->dn){ + $ldap= $this->config->get_ldap_link(); + $ldap->cd ($this->base); + $ldap->search ("(cn=".$this->cn.")", array("cn")); + if ($ldap->count() != 0){ + while ($attrs= $ldap->fetch()){ + if(preg_match("/cn=dhcp,/",$attrs['dn'])){ + continue; + } + if ($attrs['dn'] != $this->orig_dn && preg_match("/".preg_quote(get_ou("componentGeneric", "componentRDN"), '/')."/i",$attrs['dn'])){ + $message[]= msgPool::duplicated(_("Component name")); + break; + } + } + } + } - if ($this->orig_dn != $this->dn){ - $ldap= $this->config->get_ldap_link(); - $ldap->cd ($this->base); - $ldap->search ("(cn=".$this->cn.")", array("cn")); - if ($ldap->count() != 0){ - while ($attrs= $ldap->fetch()){ - if(preg_match("/cn=dhcp,/",$attrs['dn'])){ - continue; - } - if ($attrs['dn'] != $this->orig_dn && preg_match("/".preg_quote(get_ou("componentGeneric", "componentRDN"), '/')."/i",$attrs['dn'])){ - $message[]= msgPool::duplicated(_("Component name")); - break; - } + /* Check if we are allowed to create or move this object + */ + if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){ + $message[] = msgPool::permCreate(); + }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){ + $message[] = msgPool::permMove(); } - } - } - /* Check if we are allowed to create or move this object - */ - if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){ - $message[] = msgPool::permCreate(); - }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){ - $message[] = msgPool::permMove(); - } + // Check if a wrong base was supplied + if(!$this->baseSelector->checkLastBaseUpdate()){ + $message[]= msgPool::check_base();; + } - // Check if a wrong base was supplied - if(!$this->baseSelector->checkLastBaseUpdate()){ - $message[]= msgPool::check_base();; + return ($message); } - return ($message); - } + /* Save to LDAP */ + function save() + { + plugin::save(); + + /* Remove all empty values */ + if ($this->orig_dn == 'new'){ + $attrs= array(); + foreach ($this->attrs as $key => $val){ + if (is_array($val) && count($val) == 0){ + continue; + } + $attrs[$key]= $val; + } + $this->attrs= $attrs; + } - /* Save to LDAP */ - function save() - { - plugin::save(); + /* If this is a new Object IP & Mac aren't set. + IP & Mac are msut attributes, so we set this values by here. */ + if($this->orig_dn == 'new'){ + $this->attrs['ipHostNumber'] = $this->netConfigDNS->ipHostNumber; + $this->attrs['macAddress'] = $this->netConfigDNS->macAddress; + } - /* Remove all empty values */ - if ($this->orig_dn == 'new'){ - $attrs= array(); - foreach ($this->attrs as $key => $val){ - if (is_array($val) && count($val) == 0){ - continue; + /* 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); + $ldap->add($this->attrs); + new log("create","component/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + + } else { + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + new log("modify","component/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + } + + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->save(); + + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class())); } - $attrs[$key]= $val; - } - $this->attrs= $attrs; } - /* If this is a new Object IP & Mac aren't set. - IP & Mac are msut attributes, so we set this values by here. */ - if($this->orig_dn == 'new'){ - $this->attrs['ipHostNumber'] = $this->netConfigDNS->ipHostNumber; - $this->attrs['macAddress'] = $this->netConfigDNS->macAddress; + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Generic"), + "plDescription" => _("Component generic"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 1, + "plSection" => array("administration"), + "plCategory" => array("component" => array("description" => _("Network device"), + "objectClass" => array("device", "ipHost", "ieee802Device"))), + "plProperties" => + array( + array( + "name" => "componentRDN", + "type" => "rdn", + "default" => "ou=netdevices,ou=systems,", + "description" => _("The 'componentRDN' statement defines the location where new components will be created. The default is 'ou=netdevices,ou=systems,'."), + "check" => "gosaProperty::isRdn", + "migrate" => "migrate_componentRDN", + "group" => "plugin", + "mandatory" => FALSE + ) + ), + + "plProvidedAcls"=> array( + "cn" => _("Name"), + "base" => _("Base"), + "description" => _("Description"), + "userPassword" => _("Root password")) + )); } - /* 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); - $ldap->add($this->attrs); - new log("create","component/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - - } else { - $ldap->cd($this->dn); - $this->cleanup(); - $ldap->modify ($this->attrs); - new log("modify","component/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + /* Display generic part for server copy & paste */ + function getCopyDialog() + { + $vars = array("cn"); + $smarty = get_smarty(); + $smarty->assign("cn", set_post($this->cn)); + $smarty->assign("object","component"); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); } - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->save(); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class())); - } - } - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Generic"), - "plDescription" => _("Component generic"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 1, - "plSection" => array("administration"), - "plCategory" => array("component" => array("description" => _("Network device"), - "objectClass" => array("device", "ipHost", "ieee802Device"))), - "plProperties" => - array( - array( - "name" => "componentRDN", - "type" => "rdn", - "default" => "ou=netdevices,ou=systems,", - "description" => _("The 'componentRDN' statement defines the location where new components will be created. The default is 'ou=netdevices,ou=systems,'."), - "check" => "gosaProperty::isRdn", - "migrate" => "migrate_componentRDN", - "group" => "plugin", - "mandatory" => FALSE - ) - ), - - "plProvidedAcls"=> array( - "cn" => _("Name"), - "base" => _("Base"), - "description" => _("Description"), - "userPassword" => _("Root password")) - )); - } - - /* Display generic part for server copy & paste */ - function getCopyDialog() - { - $vars = array("cn"); - $smarty = get_smarty(); - $smarty->assign("cn" ,$this->cn); - $smarty->assign("object","component"); - $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); - $ret = array(); - $ret['string'] = $str; - $ret['status'] = ""; - return($ret); - } - - - function saveCopyDialog() - { - if(isset($_POST['cn'])){ - $this->cn = $_POST['cn']; + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = get_post('cn'); + } } - } - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - if(isset($source['macAddress'][0])){ - $this->netConfigDNS->macAddress = $source['macAddress'][0]; - } - if(isset($source['ipHostNumber'][0])){ - $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0]; + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + if(isset($source['macAddress'][0])){ + $this->netConfigDNS->macAddress = $source['macAddress'][0]; + } + if(isset($source['ipHostNumber'][0])){ + $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0]; + } } - } - function is_modal_dialog() - { - return((isset($this->dialog) && $this->dialog) || (isset($this->netConfigDNS->dialog) && $this->netConfigDNS->dialog)); - } + function is_modal_dialog() + { + return((isset($this->dialog) && $this->dialog) || (isset($this->netConfigDNS->dialog) && $this->netConfigDNS->dialog)); + } } diff --git a/gosa-plugins/systems/admin/systems/class_filterOPSIHOSTS.inc b/gosa-plugins/systems/admin/systems/class_filterOPSIHOSTS.inc index 48f718659..e088db595 100644 --- a/gosa-plugins/systems/admin/systems/class_filterOPSIHOSTS.inc +++ b/gosa-plugins/systems/admin/systems/class_filterOPSIHOSTS.inc @@ -2,49 +2,49 @@ class filterOPSIHOSTS { - static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "") - { - // Append opsi stuff ... - global $config; - $ui = get_userinfo(); - $entries = array(); + static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "") + { + // Append opsi stuff ... + global $config; + $ui = get_userinfo(); + $entries = array(); - if(class_available('opsi') && $base == $config->current['BASE']){ + if(class_available('opsi') && $base == $config->current['BASE']){ - // Explode filter into attribute and value to search for. - $attr = $value = ""; - $filter = preg_replace("/\*/",".*",$filter); - if(preg_match("/=/", $filter)) { - list($fAttr,$fValue) = preg_split("/=/", $filter); - } - - // Check ACLs and opsi handle - $opsi_acl = $ui->get_permissions($base,"opsi/opsiProperties"); - $opsi = new opsi($config); - $objects = array(); - if($opsi instanceof opsi && $opsi->enabled() && preg_match("/r/",$opsi_acl)){ + // Explode filter into attribute and value to search for. + $attr = $value = ""; + $filter = preg_replace("/\*/",".*",$filter); + if(preg_match("/=/", $filter)) { + list($fAttr,$fValue) = preg_split("/=/", $filter); + } + + // Check ACLs and opsi handle + $opsi_acl = $ui->get_permissions($base,"opsi/opsiProperties"); + $opsi = new opsi($config); + $objects = array(); + if($opsi instanceof opsi && $opsi->enabled() && preg_match("/r/",$opsi_acl)){ - // Get list of opsi hosts - $opsi_clients = $opsi->get_hosts_for_system_management(); - if($opsi->is_error()){ - msg_dialog::display(_("Error"),msgPool::siError($opsi->get_error()),ERROR_DIALOG); - }else{ - foreach($opsi_clients as $entry){ - if(empty($fAttr) || preg_match("/{$fValue}/i",$entry[$fAttr][0])){ - $entry['objectClass'] = array("FAKE_OC_OpsiHost"); - $item = array('count' => count($entry)); - foreach($entry as $name => $value){ - $item[] = $name; - $item[$name] = $value; - } - $entries[] = $item; + // Get list of opsi hosts + $opsi_clients = $opsi->get_hosts_for_system_management(); + if($opsi->is_error()){ + msg_dialog::display(_("Error"),msgPool::siError($opsi->get_error()),ERROR_DIALOG); + }else{ + foreach($opsi_clients as $entry){ + if(empty($fAttr) || preg_match("/{$fValue}/i",$entry[$fAttr][0])){ + $entry['objectClass'] = array("FAKE_OC_OpsiHost"); + $item = array('count' => count($entry)); + foreach($entry as $name => $value){ + $item[] = $name; + $item[$name] = $value; + } + $entries[] = $item; + } + } + } } - } } - } + return($entries); } - return($entries); - } } ?> diff --git a/gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc b/gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc index 35e0d0138..f709de00a 100644 --- a/gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc +++ b/gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc @@ -89,7 +89,7 @@ class filterSYSTEMS { } } } - + if(isset($entries[$key])){ $entries[$key][$entries[$key]['count']]= 'state'; $entries[$key]['state']= $state; diff --git a/gosa-plugins/systems/admin/systems/class_filterServerService.inc b/gosa-plugins/systems/admin/systems/class_filterServerService.inc index 84ac8e7e9..55b9b91b6 100644 --- a/gosa-plugins/systems/admin/systems/class_filterServerService.inc +++ b/gosa-plugins/systems/admin/systems/class_filterServerService.inc @@ -2,32 +2,32 @@ class filterServerService { - static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "") - { - $plugins = ServerService::getServiceList(); - $list = array(); - foreach($plugins as $name => $obj){ - if($obj->is_account){ - $data = $plugins[$name]->getListEntry(); - $data['objectClass'] = array('FAKE_OC_ServerService'); - $data['name'] = $name; - if($data['AllowStart']) $data['objectClass'][] = "AllowStart"; - if($data['AllowStop']) $data['objectClass'][] = "AllowStop"; - if($data['AllowRestart']) $data['objectClass'][] = "AllowRestart"; - if($data['AllowRemove']) $data['objectClass'][] = "AllowRemove"; - if($data['AllowEdit']) $data['objectClass'][] = "AllowEdit"; - foreach($data as $key => $value){ - if(!is_array($data[$key])) $data[$key] = array($data[$key]); - $list[$name][] = $key; - $list[$name][$key] = $data[$key]; - $list[$name][$key]['count'] = count($data[$key]); - $list[$name]['count'] = count($data); - $list[$name]['dn'] = $name; + static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "") + { + $plugins = ServerService::getServiceList(); + $list = array(); + foreach($plugins as $name => $obj){ + if($obj->is_account){ + $data = $plugins[$name]->getListEntry(); + $data['objectClass'] = array('FAKE_OC_ServerService'); + $data['name'] = $name; + if($data['AllowStart']) $data['objectClass'][] = "AllowStart"; + if($data['AllowStop']) $data['objectClass'][] = "AllowStop"; + if($data['AllowRestart']) $data['objectClass'][] = "AllowRestart"; + if($data['AllowRemove']) $data['objectClass'][] = "AllowRemove"; + if($data['AllowEdit']) $data['objectClass'][] = "AllowEdit"; + foreach($data as $key => $value){ + if(!is_array($data[$key])) $data[$key] = array($data[$key]); + $list[$name][] = $key; + $list[$name][$key] = $data[$key]; + $list[$name][$key]['count'] = count($data[$key]); + $list[$name]['count'] = count($data); + $list[$name]['dn'] = $name; + } + } } - } + return(array_values($list)); } - return(array_values($list)); - } } ?> diff --git a/gosa-plugins/systems/admin/systems/class_servGeneric.inc b/gosa-plugins/systems/admin/systems/class_servGeneric.inc index b14d73f9e..0ba0017a0 100644 --- a/gosa-plugins/systems/admin/systems/class_servGeneric.inc +++ b/gosa-plugins/systems/admin/systems/class_servGeneric.inc @@ -22,511 +22,518 @@ class servgeneric extends plugin { - /* Generic terminal attributes */ - var $ignore_account= TRUE; - var $interfaces= array(); - - /* Needed values and lists */ - var $base= ""; - var $cn= ""; - var $l= ""; - var $description= ""; - var $orig_dn= ""; - var $orig_cn= ""; - var $orig_base= ""; - - /* attribute list for save action */ - var $attributes= array("cn", "description","gotoMode"); - var $objectclasses= array("top", "GOhard", "goServer"); - - var $gotoMode= "locked"; - - var $netConfigDNS; - var $modes = array(); - var $ui ; - var $validActions = array("reboot" => "", "update" => "", "localboot" => "", "reinstall" => "", "rescan" => "", - "wakeup" => "", "memcheck" => "", "sysinfo" => ""); - - var $fai_activated =FALSE; - var $view_logged = FALSE; - - var $currently_installing = FALSE; - var $currently_installing_warned = FALSE; - - var $kerberos_key_service = NULL; - var $baseSelector; - - var $mapActions = array("reboot" => "", - "instant_update" => "softupdate", - "localboot" => "localboot", - "update" => "sceduledupdate", - "reinstall" => "install", - "rescan" => "", - "wakeup" => "", - "memcheck" => "memcheck", - "sysinfo" => "sysinfo"); - - - function servgeneric (&$config, $dn= NULL, $parent= NULL) - { - /* Check if FAI is activated */ - $this->fai_activated = $config->pluginEnabled("faiManagement"); - - plugin::plugin ($config, $dn, $parent); - - /* Initialize */ - $this->ui = get_userinfo(); - $this->modes["active"]= _("Activated"); - $this->modes["locked"]= _("Locked"); - - /* Set base */ - if ($this->dn == "new"){ - $ui= get_userinfo(); - $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn); - $this->cn= ""; - } elseif(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $this->dn)){ - $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", "", $this->dn); - } else { - $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("servgeneric", "serverRDN"), '/')."/i", "", $this->dn); - } - $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses); - $this->netConfigDNS->set_acl_category("server"); - $this->netConfigDNS->set_acl_base($this->base); - $this->netConfigDNS->MACisMust =TRUE; - - /* Initialize kerberos host key plugin */ - if(class_available("krbHostKeys")){ - $this->kerberos_key_service = new krbHostKeys($this->config,$this); - } + /* Generic terminal attributes */ + var $ignore_account= TRUE; + var $interfaces= array(); + + /* Needed values and lists */ + var $base= ""; + var $cn= ""; + var $l= ""; + var $description= ""; + var $orig_dn= ""; + var $orig_cn= ""; + var $orig_base= ""; + + /* attribute list for save action */ + var $attributes= array("cn", "description","gotoMode"); + var $objectclasses= array("top", "GOhard", "goServer"); + + var $gotoMode= "locked"; + + var $netConfigDNS; + var $modes = array(); + var $ui ; + var $validActions = array("reboot" => "", "update" => "", "localboot" => "", "reinstall" => "", "rescan" => "", + "wakeup" => "", "memcheck" => "", "sysinfo" => ""); + + var $fai_activated =FALSE; + var $view_logged = FALSE; + + var $currently_installing = FALSE; + var $currently_installing_warned = FALSE; + + var $kerberos_key_service = NULL; + var $baseSelector; + + var $mapActions = array("reboot" => "", + "instant_update" => "softupdate", + "localboot" => "localboot", + "update" => "sceduledupdate", + "reinstall" => "install", + "rescan" => "", + "wakeup" => "", + "memcheck" => "memcheck", + "sysinfo" => "sysinfo"); + + + function servgeneric (&$config, $dn= NULL, $parent= NULL) + { + /* Check if FAI is activated */ + $this->fai_activated = $config->pluginEnabled("faiManagement"); + + plugin::plugin ($config, $dn, $parent); + + /* Initialize */ + $this->ui = get_userinfo(); + $this->modes["active"]= _("Activated"); + $this->modes["locked"]= _("Locked"); + + /* Set base */ + if ($this->dn == "new"){ + $ui= get_userinfo(); + $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn); + $this->cn= ""; + } elseif(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $this->dn)){ + $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", "", $this->dn); + } else { + $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("servgeneric", "serverRDN"), '/')."/i", "", $this->dn); + } + $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses); + $this->netConfigDNS->set_acl_category("server"); + $this->netConfigDNS->set_acl_base($this->base); + $this->netConfigDNS->MACisMust =TRUE; + + /* Initialize kerberos host key plugin */ + if(class_available("krbHostKeys")){ + $this->kerberos_key_service = new krbHostKeys($this->config,$this); + } - /* Check if this host is currently in installation process*/ - if($this->dn != "new" && class_available("gosaSupportDaemon") && class_available("DaemonEvent")){ - $o = new gosaSupportDaemon(); - $e_types = DaemonEvent::get_event_types(USER_EVENT | SYSTEM_EVENT | HIDDEN_EVENT); - $evts = $o->get_entries_by_mac(array($this->netConfigDNS->macAddress)); - foreach($evts as $evt){ - if(isset($e_types['QUEUED'][$evt['HEADERTAG']]) && $evt['STATUS'] == "processing" && - $e_types['QUEUED'][$evt['HEADERTAG']] == "DaemonEvent_reinstall"){ - $this->currently_installing =TRUE; + /* Check if this host is currently in installation process*/ + if($this->dn != "new" && class_available("gosaSupportDaemon") && class_available("DaemonEvent")){ + $o = new gosaSupportDaemon(); + $e_types = DaemonEvent::get_event_types(USER_EVENT | SYSTEM_EVENT | HIDDEN_EVENT); + $evts = $o->get_entries_by_mac(array($this->netConfigDNS->macAddress)); + foreach($evts as $evt){ + if(isset($e_types['QUEUED'][$evt['HEADERTAG']]) && $evt['STATUS'] == "processing" && + $e_types['QUEUED'][$evt['HEADERTAG']] == "DaemonEvent_reinstall"){ + $this->currently_installing =TRUE; + } + } } - } + + /* Save dn for later references */ + $this->orig_dn = $this->dn; + $this->orig_cn = $this->cn; + $this->orig_base = $this->base; + + /* Instanciate base selector */ + $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base); + $this->baseSelector->setSubmitButton(false); + $this->baseSelector->setHeight(300); + $this->baseSelector->update(true); } - - /* Save dn for later references */ - $this->orig_dn = $this->dn; - $this->orig_cn = $this->cn; - $this->orig_base = $this->base; - /* Instanciate base selector */ - $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base); - $this->baseSelector->setSubmitButton(false); - $this->baseSelector->setHeight(300); - $this->baseSelector->update(true); - } + function set_acl_base($base) + { + plugin::set_acl_base($base); + $this->netConfigDNS->set_acl_base($base); + } - function set_acl_base($base) - { - plugin::set_acl_base($base); - $this->netConfigDNS->set_acl_base($base); - } + function set_acl_category($cat) + { + plugin::set_acl_category($cat); + $this->netConfigDNS->set_acl_category($cat); + } - function set_acl_category($cat) - { - plugin::set_acl_category($cat); - $this->netConfigDNS->set_acl_category($cat); - } + function execute() + { - function execute() - { - - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + plugin::execute(); - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","server/".get_class($this),$this->dn); - } + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","server/".get_class($this),$this->dn); + } - /* Do we represent a valid server? */ - if (!$this->is_account && $this->parent === NULL){ - $display= "\"\" ". - msgPool::noValidExtension(_("server")).""; - return($display); - } + /* Do we represent a valid server? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + msgPool::noValidExtension(_("server")).""; + return($display); + } - if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->mapActions[$_POST['saction']]) ){ - $action = $_POST['saction']; - - /* Check if we have an DaemonEvent for this action */ - if(class_available("DaemonEvent")){ - $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); - if(isset($events['TRIGGERED']["DaemonEvent_".$action])){ - $evt = $events['TRIGGERED']["DaemonEvent_".$action]; - $tmp = new $evt['CLASS_NAME']($this->config); - $tmp->add_targets(array($this->netConfigDNS->macAddress)); - $tmp->set_type(TRIGGERED_EVENT); - $o_queue = new gosaSupportDaemon(); - if(!$o_queue->append($tmp)){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - } + if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->mapActions[$_POST['saction']]) ){ + $action = get_post('saction'); + + /* Check if we have an DaemonEvent for this action */ + if(class_available("DaemonEvent")){ + $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); + if(isset($events['TRIGGERED']["DaemonEvent_".$action])){ + $evt = $events['TRIGGERED']["DaemonEvent_".$action]; + $tmp = new $evt['CLASS_NAME']($this->config); + $tmp->add_targets(array($this->netConfigDNS->macAddress)); + $tmp->set_type(TRIGGERED_EVENT); + $o_queue = new gosaSupportDaemon(); + if(!$o_queue->append($tmp)){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + } + } + }else{ + msg_dialog::display(_("Event error"), + sprintf(_("Event '%s' is not available!"),$action),ERROR_DIALOG); + } } - }else{ - msg_dialog::display(_("Event error"), - sprintf(_("Event '%s' is not available!"),$action),ERROR_DIALOG); - } - } - /* Fill templating stuff */ - $smarty= get_smarty(); + /* Fill templating stuff */ + $smarty= get_smarty(); - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $smarty->assign($name."ACL",$this->getacl($name)); - } + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $smarty->assign($name."ACL",$this->getacl($name)); + } - /* Assign base ACL */ - $smarty->assign("base", $this->baseSelector->render()); + /* Assign base ACL */ + $smarty->assign("base", $this->baseSelector->render()); - /* Assign attributes */ - foreach ($this->attributes as $attr){ - $smarty->assign("$attr", $this->$attr); - } + /* Assign attributes */ + foreach ($this->attributes as $attr){ + $smarty->assign("$attr", set_post($this->$attr)); + } - /* Assign status */ - if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){ - $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"), - "update" => _("System update"), - "reinstall" => _("Reinstall"), - "rescan" => _("Rescan hardware"), - "memcheck" => _("Memory test"), - "localboot" => _("Force localboot"), - "sysinfo" => _("System analysis"))); - } else { - $smarty->assign("actions", array("wakeup" => _("Wake up"), - "reinstall" => _("Reinstall"), - "update" => _("System update"), - "memcheck" => _("Memory test"), - "localboot" => _("Force localboot"), - "sysinfo" => _("System analysis"))); - } + /* Assign status */ + if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){ + $smarty->assign("actions", + set_post( + array( + "halt" => _("Switch off"), + "reboot" => _("Reboot"), + "update" => _("System update"), + "reinstall" => _("Reinstall"), + "rescan" => _("Rescan hardware"), + "memcheck" => _("Memory test"), + "localboot" => _("Force localboot"), + "sysinfo" => _("System analysis")))); + } else { + $smarty->assign("actions", + set_post( + array( + "wakeup" => _("Wake up"), + "reinstall" => _("Reinstall"), + "update" => _("System update"), + "memcheck" => _("Memory test"), + "localboot" => _("Force localboot"), + "sysinfo" => _("System analysis")))); + } - /* Show main page */ - $smarty->assign("fai_activated",$this->fai_activated); + /* Show main page */ + $smarty->assign("fai_activated",$this->fai_activated); - $str = $this->netConfigDNS->execute(); - $this->dialog = $this->is_modal_dialog(); - if(is_object($this->netConfigDNS->dialog)){ - return($str); - } - $smarty->assign("netconfig", $str); - $smarty->assign("modes", $this->modes); - $smarty->assign("currently_installing", $this->currently_installing); + $str = $this->netConfigDNS->execute(); + $this->dialog = $this->is_modal_dialog(); + if(is_object($this->netConfigDNS->dialog)){ + return($str); + } + $smarty->assign("netconfig", $str); + $smarty->assign("modes", $this->modes); + $smarty->assign("currently_installing", $this->currently_installing); - $smarty->assign("host_key",""); - if(is_object($this->kerberos_key_service)){ - $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/")); + $smarty->assign("host_key",""); + if(is_object($this->kerberos_key_service)){ + $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/")); + } + + return($smarty->fetch (get_template_path('server.tpl', TRUE))); } - return($smarty->fetch (get_template_path('server.tpl', TRUE))); - } + function remove_from_parent() + { + /* Cancel if there's nothing to do here */ + if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){ + return; + } - function remove_from_parent() - { - /* Cancel if there's nothing to do here */ - if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){ - return; - } + /* Remove kerberos key dependencies too */ + if(is_object($this->kerberos_key_service)){ + $this->kerberos_key_service->remove_from_parent_by_prefix("host/"); + } - /* Remove kerberos key dependencies too */ - if(is_object($this->kerberos_key_service)){ - $this->kerberos_key_service->remove_from_parent_by_prefix("host/"); - } + $this->netConfigDNS->remove_from_parent(); + $ldap= $this->config->get_ldap_link(); + $ldap->rmdir($this->dn); - $this->netConfigDNS->remove_from_parent(); - $ldap= $this->config->get_ldap_link(); - $ldap->rmdir($this->dn); + update_accessTo($this->orig_cn,""); - update_accessTo($this->orig_cn,""); + new log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - new log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class())); + } - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class())); - } + /* Delete references to object groups */ + $ldap->cd ($this->config->current['BASE']); + $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 (); + } - /* Delete references to object groups */ - $ldap->cd ($this->config->current['BASE']); - $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 (); + /* Clean queue form entries with this mac + */ + if(class_available("gosaSupportDaemon") && tests::is_mac($this->netConfigDNS->orig_macAddress)){ + $q = new gosaSupportDaemon(); + $q->clean_queue_from_mac($this->netConfigDNS->orig_macAddress); + } + $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); } - /* Clean queue form entries with this mac - */ - if(class_available("gosaSupportDaemon") && tests::is_mac($this->netConfigDNS->orig_macAddress)){ - $q = new gosaSupportDaemon(); - $q->clean_queue_from_mac($this->netConfigDNS->orig_macAddress); - } - $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - } - - - /* Save data to object */ - function save_object() - { - /* Save current base, to be able to revert to last base, - if new base is invalid or not allowed to be selected */ - $base_tmp = $this->base; - plugin::save_object(); - $this->netConfigDNS->save_object(); - - /* Refresh base */ - if ($this->acl_is_moveable($this->base)){ - if (!$this->baseSelector->update()) { - msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG); - } - if ($this->base != $this->baseSelector->getBase()) { - $this->base= $this->baseSelector->getBase(); - $this->is_modified= TRUE; - } - } + /* Save data to object */ + function save_object() + { + /* Save current base, to be able to revert to last base, + if new base is invalid or not allowed to be selected */ + $base_tmp = $this->base; + plugin::save_object(); + $this->netConfigDNS->save_object(); - /* Hanle kerberos host key plugin */ - if(is_object($this->kerberos_key_service)){ - $this->kerberos_key_service->save_object_by_prefix("host/"); + /* Refresh base */ + if ($this->acl_is_moveable($this->base)){ + if (!$this->baseSelector->update()) { + msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG); + } + if ($this->base != $this->baseSelector->getBase()) { + $this->base= $this->baseSelector->getBase(); + $this->is_modified= TRUE; + } + } + + + /* Hanle kerberos host key plugin */ + if(is_object($this->kerberos_key_service)){ + $this->kerberos_key_service->save_object_by_prefix("host/"); + } } - } - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - $message= array_merge($message, $this->netConfigDNS->check()); - $this->dn= "cn=".$this->cn.",".get_ou("servgeneric", "serverRDN").$this->base; + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + $message= array_merge($message, $this->netConfigDNS->check()); + $this->dn= "cn=".$this->cn.",".get_ou("servgeneric", "serverRDN").$this->base; - /* must: cn */ - if ($this->cn == ""){ - msgPool::required(_("Server name")); - } - - /* Check if given name is a valid host/dns name */ - if(!tests::is_dns_name($this->cn)){ - $message[]= msgPool::invalid(_("Server name"), $this->cn, "/[a-z0-9\.\-]/i"); - } + /* must: cn */ + if ($this->cn == ""){ + msgPool::required(_("Server name")); + } - // Check if a wrong base was supplied - if(!$this->baseSelector->checkLastBaseUpdate()){ - $message[]= msgPool::check_base();; - } + /* Check if given name is a valid host/dns name */ + if(!tests::is_dns_name($this->cn)){ + $message[]= msgPool::invalid(_("Server name"), $this->cn, "/[a-z0-9\.\-]/i"); + } - if ($this->orig_dn != $this->dn){ - $ldap= $this->config->get_ldap_link(); - $ldap->cd ($this->base); - $ldap->search ("(cn=".$this->cn.")", array("cn")); - if ($ldap->count() != 0){ - while ($attrs= $ldap->fetch()){ - if ($attrs['dn'] != $this->orig_dn){ - if(!preg_match("/cn=dhcp,/",$attrs['dn']) && !preg_match("/,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$attrs['dn']) && preg_match("/,".preg_quote(get_ou("servgeneric", "serverRDN"), '/')."/i",$attrs['dn'])){ - $message[]= msgPool::duplicated(_("Server name")); - break; + // Check if a wrong base was supplied + if(!$this->baseSelector->checkLastBaseUpdate()){ + $message[]= msgPool::check_base();; + } + + if ($this->orig_dn != $this->dn){ + $ldap= $this->config->get_ldap_link(); + $ldap->cd ($this->base); + $ldap->search ("(cn=".$this->cn.")", array("cn")); + if ($ldap->count() != 0){ + while ($attrs= $ldap->fetch()){ + if ($attrs['dn'] != $this->orig_dn){ + if(!preg_match("/cn=dhcp,/",$attrs['dn']) && !preg_match("/,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$attrs['dn']) && preg_match("/,".preg_quote(get_ou("servgeneric", "serverRDN"), '/')."/i",$attrs['dn'])){ + $message[]= msgPool::duplicated(_("Server name")); + break; + } + } + } } - } } - } - } - /* Warn the user, that this host is currently installing */ - if($this->currently_installing && !$this->currently_installing_warned && !preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$this->orig_dn)){ + /* Warn the user, that this host is currently installing */ + if($this->currently_installing && !$this->currently_installing_warned && !preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$this->orig_dn)){ - /* Force aborting without message dialog */ - $message[] = ""; - $this->currently_installing_warned = TRUE; - msg_dialog::display(_("Software deployment"), - _("This host is currently installing, if you really want to save it, press 'OK'."), - CONFIRM_DIALOG); - } + /* Force aborting without message dialog */ + $message[] = ""; + $this->currently_installing_warned = TRUE; + msg_dialog::display(_("Software deployment"), + _("This host is currently installing, if you really want to save it, press 'OK'."), + CONFIRM_DIALOG); + } - /* Check if we are allowed to create or move this object - */ - if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){ - $message[] = msgPool::permCreate(); - }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){ - $message[] = msgPool::permMove(); - } + /* Check if we are allowed to create or move this object + */ + if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){ + $message[] = msgPool::permCreate(); + }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){ + $message[] = msgPool::permMove(); + } - return ($message); - } + return ($message); + } - /* Save to LDAP */ - function save() - { - /* Detect mode changes */ - $activate= (isset($this->saved_attributes['gotoMode']) && - $this->gotoMode != $this->saved_attributes['gotoMode'] && - $this->gotoMode == "active" && - tests::is_ip($this->netConfigDNS->ipHostNumber)); + /* Save to LDAP */ + function save() + { + /* Detect mode changes */ + $activate= (isset($this->saved_attributes['gotoMode']) && + $this->gotoMode != $this->saved_attributes['gotoMode'] && + $this->gotoMode == "active" && + tests::is_ip($this->netConfigDNS->ipHostNumber)); + + plugin::save(); + + /* Remove all empty values */ + if ($this->orig_dn == 'new'){ + $attrs= array(); + foreach ($this->attrs as $key => $val){ + if (is_array($val) && count($val) == 0){ + continue; + } + $attrs[$key]= $val; + } + $this->attrs= $attrs; + } - plugin::save(); + /* 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); + $ldap->add($this->attrs); + new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + $mode= "add"; + } else { + + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + + /* Update all accessTo/trust dependencies */ + if($this->orig_cn != $this->cn){ + update_accessTo($this->orig_cn,$this->cn); + } - /* Remove all empty values */ - if ($this->orig_dn == 'new'){ - $attrs= array(); - foreach ($this->attrs as $key => $val){ - if (is_array($val) && count($val) == 0){ - continue; + $mode= "modify"; + } + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class())); + } + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->save(); + + /* Optionally execute a command after we're done */ + $this->handle_post_events($mode,array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + + if ($activate){ + + /* Send installation activation + */ + $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); + $o_queue = new gosaSupportDaemon(); + if(isset($events['TRIGGERED']['DaemonEvent_installation_activation'])){ + $evt = $events['TRIGGERED']['DaemonEvent_installation_activation']; + $tmp = new $evt['CLASS_NAME']($this->config); + $tmp->set_type(TRIGGERED_EVENT); + $tmp->add_targets(array($this->netConfigDNS->macAddress)); + if(!$o_queue->append($tmp)){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + } + } } - $attrs[$key]= $val; - } - $this->attrs= $attrs; - } - /* 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); - $ldap->add($this->attrs); - new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - $mode= "add"; - } else { - - $ldap->cd($this->dn); - $this->cleanup(); - $ldap->modify ($this->attrs); - new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - - /* Update all accessTo/trust dependencies */ - if($this->orig_cn != $this->cn){ - update_accessTo($this->orig_cn,$this->cn); - } - - $mode= "modify"; } - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class())); + + + /* Display generic part for server copy & paste */ + function getCopyDialog() + { + $vars = array("cn"); + + $smarty = get_smarty(); + $smarty->assign("cn", set_post($this->cn)); + $smarty->assign("object","server"); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); } - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->save(); - - /* Optionally execute a command after we're done */ - $this->handle_post_events($mode,array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - - if ($activate){ - - /* Send installation activation - */ - $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); - $o_queue = new gosaSupportDaemon(); - if(isset($events['TRIGGERED']['DaemonEvent_installation_activation'])){ - $evt = $events['TRIGGERED']['DaemonEvent_installation_activation']; - $tmp = new $evt['CLASS_NAME']($this->config); - $tmp->set_type(TRIGGERED_EVENT); - $tmp->add_targets(array($this->netConfigDNS->macAddress)); - if(!$o_queue->append($tmp)){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + + + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = get_post('cn'); } - } } - } + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + if(isset($source['macAddress'][0])){ + $this->netConfigDNS->macAddress = $source['macAddress'][0]; + } + if(isset($source['ipHostNumber'][0])){ + $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0]; + } - /* Display generic part for server copy & paste */ - function getCopyDialog() - { - $vars = array("cn"); + } - $smarty = get_smarty(); - $smarty->assign("cn" ,$this->cn); - $smarty->assign("object","server"); - $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); - $ret = array(); - $ret['string'] = $str; - $ret['status'] = ""; - return($ret); - } - function saveCopyDialog() - { - if(isset($_POST['cn'])){ - $this->cn = $_POST['cn']; - } - } - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - if(isset($source['macAddress'][0])){ - $this->netConfigDNS->macAddress = $source['macAddress'][0]; - } - if(isset($source['ipHostNumber'][0])){ - $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0]; + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Generic"), + "plDescription" => _("Server generic"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 1, + "plSection" => array("administration"), + "plRequirements"=> array( + 'ldapSchema' => array('goServer' => '>=2.7'), + 'onFailureDisablePlugin' => array(get_class()) + ), + "plCategory" => array("server" => array("description" => _("Server"), + "objectClass" => "goServer")), + "plProperties" => + array( + array( + "name" => "serverRDN", + "type" => "rdn", + "default" => "ou=servers,ou=systems,", + "description" => _("The 'serverRDN' statement defines the location where new servers will be created. The default is 'ou=servers,ou=systems,'."), + "check" => "gosaProperty::isRdn", + "migrate" => "migrate_serverRDN", + "group" => "plugin", + "mandatory" => FALSE + ) + ), + + "plProvidedAcls"=> array( + "cn" => _("Name"), + "description" => _("Description"), + "base" => _("Base"), + + "gotoMode" => _("Goto mode"), + "userPassword"=> _("Root password"), + "FAIstate" => _("Action flag")) + )); } - } - - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Generic"), - "plDescription" => _("Server generic"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 1, - "plSection" => array("administration"), - "plRequirements"=> array( - 'ldapSchema' => array('goServer' => '>=2.7'), - 'onFailureDisablePlugin' => array(get_class()) - ), - "plCategory" => array("server" => array("description" => _("Server"), - "objectClass" => "goServer")), - "plProperties" => - array( - array( - "name" => "serverRDN", - "type" => "rdn", - "default" => "ou=servers,ou=systems,", - "description" => _("The 'serverRDN' statement defines the location where new servers will be created. The default is 'ou=servers,ou=systems,'."), - "check" => "gosaProperty::isRdn", - "migrate" => "migrate_serverRDN", - "group" => "plugin", - "mandatory" => FALSE - ) - ), - - "plProvidedAcls"=> array( - "cn" => _("Name"), - "description" => _("Description"), - "base" => _("Base"), - - "gotoMode" => _("Goto mode"), - "userPassword"=> _("Root password"), - "FAIstate" => _("Action flag")) - )); - } - - - function is_modal_dialog() - { - return((isset($this->dialog) && $this->dialog) || (isset($this->netConfigDNS->dialog) && $this->netConfigDNS->dialog)); - } + + function is_modal_dialog() + { + return((isset($this->dialog) && $this->dialog) || (isset($this->netConfigDNS->dialog) && $this->netConfigDNS->dialog)); + } } diff --git a/gosa-plugins/systems/admin/systems/class_systemManagement.inc b/gosa-plugins/systems/admin/systems/class_systemManagement.inc index 215dd1f94..9f6084c8f 100644 --- a/gosa-plugins/systems/admin/systems/class_systemManagement.inc +++ b/gosa-plugins/systems/admin/systems/class_systemManagement.inc @@ -57,1394 +57,1394 @@ # class systemManagement extends management { - var $plHeadline = "Systems"; - var $plDescription = "Manage systems, their services and prepare them for use with GOsa"; - var $plIcon = "plugins/systems/images/plugin.png"; - - // Tab definition - protected $tabClass = ""; - protected $tabType = ""; - protected $aclCategory = ""; - protected $aclPlugin = ""; - protected $objectName = "system"; - protected $objectInfo = array(); - protected $opsi = NULL; - protected $activationQueue = array(); - - function __construct($config,$ui) - { - $this->config = $config; - $this->ui = $ui; - - // Set storage points - $tD = $this->getObjectDefinitions(); - $sP = array(); - foreach($tD as $entry){ - if(!empty($entry['ou'])) - $sP[] = $entry['ou']; - } - - $this->storagePoints = array_unique($sP); - - // Build filter - if (session::global_is_set(get_class($this)."_filter")){ - $filter= session::global_get(get_class($this)."_filter"); - } else { - $filter = new filter(get_template_path("system-filter.xml", true)); - $filter->setObjectStorage($this->storagePoints); - } - $this->setFilter($filter); - - // Build headpage - $headpage = new listing(get_template_path("system-list.xml", true)); - $headpage->registerElementFilter("systemRelease", "systemManagement::systemRelease"); - $headpage->registerElementFilter("filterSystemDescription", "systemManagement::filterSystemDescription"); - $headpage->setFilter($filter); - $filter->setConverter('systemManagement::incomingFilterConverter'); - - // Register Daemon Events - if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){ - $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); - foreach($events['TRIGGERED'] as $name => $data){ - $this->registerAction("T_".$name,"handleEvent"); - $this->registerAction("S_".$name,"handleEvent"); - } - $this->registerAction("activateMultiple","activateMultiple"); - } - $this->registerAction("saveEvent","saveEventDialog"); - $this->registerAction("createISO","createISO"); - $this->registerAction("initiateISOcreation","initiateISOcreation"); - $this->registerAction("performIsoCreation","performIsoCreation"); - $this->registerAction("systemTypeChosen","systemTypeChosen"); - $this->registerAction("handleActivationQueue","handleActivationQueue"); - - $this->registerAction("new_goServer", "newEntry"); - $this->registerAction("new_gotoWorkstation", "newEntry"); - $this->registerAction("new_gotoTerminal", "newEntry"); - $this->registerAction("new_gotoPrinter", "newEntry"); - $this->registerAction("new_goFonHardware", "newEntry"); - $this->registerAction("new_ieee802Device", "newEntry"); - $this->registerAction("new_FAKE_OC_OpsiHost", "newEntry"); - - $this->registerAction("setPassword", "setPassword"); - $this->registerAction("passwordChangeConfirmed", "passwordChangeConfirmed"); - - // Add copy&paste and snapshot handler. - if ($this->config->boolValueIsTrue("core", "copyPaste")){ - $this->cpHandler = new CopyPasteHandler($this->config); - } - if($this->config->get_cfg_value("core","enableSnapshots") == "true"){ - $this->snapHandler = new SnapshotHandler($this->config); - } + var $plHeadline = "Systems"; + var $plDescription = "Manage systems, their services and prepare them for use with GOsa"; + var $plIcon = "plugins/systems/images/plugin.png"; + + // Tab definition + protected $tabClass = ""; + protected $tabType = ""; + protected $aclCategory = ""; + protected $aclPlugin = ""; + protected $objectName = "system"; + protected $objectInfo = array(); + protected $opsi = NULL; + protected $activationQueue = array(); + + function __construct($config,$ui) + { + $this->config = $config; + $this->ui = $ui; + + // Set storage points + $tD = $this->getObjectDefinitions(); + $sP = array(); + foreach($tD as $entry){ + if(!empty($entry['ou'])) + $sP[] = $entry['ou']; + } - // Check if we are able to communicate with the GOsa supprot daemon - if(class_available("gosaSupportDaemon")){ - $o = new gosaSupportDaemon(); - $this->si_active = $o->connect() && class_available("DaemonEvent"); - } + $this->storagePoints = array_unique($sP); - // Check if we are able to communicate with the GOsa supprot daemon - if(class_available("opsi")){ - $this->opsi = new opsi($this->config); - } - parent::__construct($config, $ui, "systems", $headpage); - } - - - /*! \brief Act on password change requests. - */ - function setPassword($action,$target) - { - if(count($target) == 1){ - $tDefs= $this->getObjectDefinitions(); - $headpage = $this->getHeadpage(); - $dn = array_pop($target); - $type = $headpage->getType($dn); - $entry = $headpage->getEntry($dn); - $ui = get_userinfo(); - $smarty = get_smarty(); - if(in_array("FAKE_OC_PWD_changeAble", $entry['objectClass'])){ - $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass']; - $tabacl = $ui->get_permissions($dn,$acl,"userPassword"); - if(preg_match("/w/",$tabacl)){ - $this->dn= $dn; - set_object_info($this->dn); - return ($smarty->fetch(get_template_path('password.tpl', TRUE))); - }else{ - msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG); + // Build filter + if (session::global_is_set(get_class($this)."_filter")){ + $filter= session::global_get(get_class($this)."_filter"); + } else { + $filter = new filter(get_template_path("system-filter.xml", true)); + $filter->setObjectStorage($this->storagePoints); } - } - } - } - - - /*! \brief This method is used to queue and process copy&paste actions. - * Allows to copy, cut and paste mutliple entries at once. - * @param String 'action' The name of the action which was the used as trigger. - * @param Array 'target' A list of object dns, which should be affected by this method. - * @param Array 'all' A combination of both 'action' and 'target'. - */ - function copyPasteHandler($action="",$target=array(),$all=array(), - $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="") - { - // Return without any actions while copy&paste handler is disabled. - if(!is_object($this->cpHandler)) return(""); - - // Save user input - $this->cpHandler->save_object(); - - // Add entries to queue - if($action == "copy" || $action == "cut"){ - - $tDefs= $this->getObjectDefinitions(); - $headpage = $this->getHeadpage(); - $ui = get_userinfo(); - $this->cpHandler->cleanup_queue(); - foreach($target as $dn){ - - $type = $headpage->getType($dn); - $entry = $headpage->getEntry($dn); - - $aclCategory = $tDefs[$type]['aclCategory']; - $aclPlugin = $tDefs[$type]['aclClass']; - $tabClass = $tDefs[$type]['tabClass']; - $tabType = $tDefs[$type]['tabDesc']; - - if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){ - $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!"); + $this->setFilter($filter); + + // Build headpage + $headpage = new listing(get_template_path("system-list.xml", true)); + $headpage->registerElementFilter("systemRelease", "systemManagement::systemRelease"); + $headpage->registerElementFilter("filterSystemDescription", "systemManagement::filterSystemDescription"); + $headpage->setFilter($filter); + $filter->setConverter('systemManagement::incomingFilterConverter'); + + // Register Daemon Events + if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){ + $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); + foreach($events['TRIGGERED'] as $name => $data){ + $this->registerAction("T_".$name,"handleEvent"); + $this->registerAction("S_".$name,"handleEvent"); + } + $this->registerAction("activateMultiple","activateMultiple"); } - if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){ - $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!"); + $this->registerAction("saveEvent","saveEventDialog"); + $this->registerAction("createISO","createISO"); + $this->registerAction("initiateISOcreation","initiateISOcreation"); + $this->registerAction("performIsoCreation","performIsoCreation"); + $this->registerAction("systemTypeChosen","systemTypeChosen"); + $this->registerAction("handleActivationQueue","handleActivationQueue"); + + $this->registerAction("new_goServer", "newEntry"); + $this->registerAction("new_gotoWorkstation", "newEntry"); + $this->registerAction("new_gotoTerminal", "newEntry"); + $this->registerAction("new_gotoPrinter", "newEntry"); + $this->registerAction("new_goFonHardware", "newEntry"); + $this->registerAction("new_ieee802Device", "newEntry"); + $this->registerAction("new_FAKE_OC_OpsiHost", "newEntry"); + + $this->registerAction("setPassword", "setPassword"); + $this->registerAction("passwordChangeConfirmed", "passwordChangeConfirmed"); + + // Add copy&paste and snapshot handler. + if ($this->config->boolValueIsTrue("core", "copyPaste")){ + $this->cpHandler = new CopyPasteHandler($this->config); + } + if($this->config->get_cfg_value("core","enableSnapshots") == "true"){ + $this->snapHandler = new SnapshotHandler($this->config); } - } - } - // Initiate pasting - if($action == "paste"){ - $this->cpPastingStarted = TRUE; - } + // Check if we are able to communicate with the GOsa supprot daemon + if(class_available("gosaSupportDaemon")){ + $o = new gosaSupportDaemon(); + $this->si_active = $o->connect() && class_available("DaemonEvent"); + } - // Display any c&p dialogs, eg. object modifications required before pasting. - if($this->cpPastingStarted && $this->cpHandler->entries_queued()){ - $headpage = $this->getHeadpage(); - $this->cpHandler->SetVar("base",$headpage->getBase()); - $data = $this->cpHandler->execute(); - if(!empty($data)){ - return($data); - } + // Check if we are able to communicate with the GOsa supprot daemon + if(class_available("opsi")){ + $this->opsi = new opsi($this->config); + } + parent::__construct($config, $ui, "systems", $headpage); } - // Automatically disable pasting process since there is no entry left to paste. - if(!$this->cpHandler->entries_queued()){ - $this->cpPastingStarted = FALSE; + + /*! \brief Act on password change requests. + */ + function setPassword($action,$target) + { + if(count($target) == 1){ + $tDefs= $this->getObjectDefinitions(); + $headpage = $this->getHeadpage(); + $dn = array_pop($target); + $type = $headpage->getType($dn); + $entry = $headpage->getEntry($dn); + $ui = get_userinfo(); + $smarty = get_smarty(); + if(in_array("FAKE_OC_PWD_changeAble", $entry['objectClass'])){ + $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass']; + $tabacl = $ui->get_permissions($dn,$acl,"userPassword"); + if(preg_match("/w/",$tabacl)){ + $this->dn= $dn; + set_object_info($this->dn); + return ($smarty->fetch(get_template_path('password.tpl', TRUE))); + }else{ + msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG); + } + } + } } - return(""); - } - - - /*! \brief Password change confirmed, now try to change the systems pwd. - */ - function passwordChangeConfirmed() - { - $tDefs= $this->getObjectDefinitions(); - $headpage = $this->getHeadpage(); - $type = $headpage->getType($this->dn); - $entry = $headpage->getEntry($this->dn); - $ui = get_userinfo(); - $smarty = get_smarty(); - - if(!in_array('FAKE_OC_PWD_changeAble', $entry['objectClass'])){ - trigger_error("Tried to change pwd, for invalid object!"); - }elseif ($_POST['new_password'] != $_POST['repeated_password']){ - msg_dialog::display(_("Error"), - _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG); - return($smarty->fetch(get_template_path('password.tpl', TRUE))); - }else{ - $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass']; - $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword"); - - // Check acls - if(!preg_match("/w/",$tabacl)){ - msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG); - }else{ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $ldap->cat($this->dn); - $old_attrs = $ldap->fetch(); - - $attrs= array(); - if ($_POST['new_password'] == ""){ - - /* Remove password attribute - */ - if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){ - $attrs['objectClass'] = array(); - for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){ - if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){ - $attrs['objectClass'][] = $old_attrs['objectClass'][$i]; - } + + + /*! \brief This method is used to queue and process copy&paste actions. + * Allows to copy, cut and paste mutliple entries at once. + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + function copyPasteHandler($action="",$target=array(),$all=array(), + $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="") + { + // Return without any actions while copy&paste handler is disabled. + if(!is_object($this->cpHandler)) return(""); + + // Save user input + $this->cpHandler->save_object(); + + // Add entries to queue + if($action == "copy" || $action == "cut"){ + + $tDefs= $this->getObjectDefinitions(); + $headpage = $this->getHeadpage(); + $ui = get_userinfo(); + $this->cpHandler->cleanup_queue(); + foreach($target as $dn){ + + $type = $headpage->getType($dn); + $entry = $headpage->getEntry($dn); + + $aclCategory = $tDefs[$type]['aclCategory']; + $aclPlugin = $tDefs[$type]['aclClass']; + $tabClass = $tDefs[$type]['tabClass']; + $tabType = $tDefs[$type]['tabDesc']; + + if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){ + $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!"); + } + if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){ + $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!"); + } } - } - $attrs['userPassword']= array(); - } else { + } - /* Add/modify password attribute - */ - if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){ - $attrs['objectClass'] = array(); - for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){ - $attrs['objectClass'][] = $old_attrs['objectClass'][$i]; + // Initiate pasting + if($action == "paste"){ + $this->cpPastingStarted = TRUE; + } + + // Display any c&p dialogs, eg. object modifications required before pasting. + if($this->cpPastingStarted && $this->cpHandler->entries_queued()){ + $headpage = $this->getHeadpage(); + $this->cpHandler->SetVar("base",$headpage->getBase()); + $data = $this->cpHandler->execute(); + if(!empty($data)){ + return($data); } - $attrs['objectClass'][] = "simpleSecurityObject"; - } - - if(class_available("passwordMethodCrypt")){ - $pwd_m = new passwordMethodCrypt($this->config); - $pwd_m->set_hash("crypt/md5"); - $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']); - }else{ - msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password.")); - $attrs = array(); - } } - $ldap->modify($attrs); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type)); + + // Automatically disable pasting process since there is no entry left to paste. + if(!$this->cpHandler->entries_queued()){ + $this->cpPastingStarted = FALSE; + } + return(""); + } + + + /*! \brief Password change confirmed, now try to change the systems pwd. + */ + function passwordChangeConfirmed() + { + $tDefs= $this->getObjectDefinitions(); + $headpage = $this->getHeadpage(); + $type = $headpage->getType($this->dn); + $entry = $headpage->getEntry($this->dn); + $ui = get_userinfo(); + $smarty = get_smarty(); + + if(!in_array('FAKE_OC_PWD_changeAble', $entry['objectClass'])){ + trigger_error("Tried to change pwd, for invalid object!"); + }elseif (get_post('new_password') != get_post('repeated_password')){ + msg_dialog::display(_("Error"), + _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG); + return($smarty->fetch(get_template_path('password.tpl', TRUE))); }else{ - if(class_available($tDefs[$type]['plugClass'])){ - $plug = $tDefs[$type]['plugClass']; - $p = new $plug($this->config,$this->dn); - $p->handle_post_events("modify"); - } + $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass']; + $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword"); + + // Check acls + if(!preg_match("/w/",$tabacl)){ + msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG); + }else{ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $ldap->cat($this->dn); + $old_attrs = $ldap->fetch(); + + $attrs= array(); + if ($_POST['new_password'] == ""){ + + /* Remove password attribute + */ + if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){ + $attrs['objectClass'] = array(); + for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){ + if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){ + $attrs['objectClass'][] = $old_attrs['objectClass'][$i]; + } + } + } + $attrs['userPassword']= array(); + } else { + + /* Add/modify password attribute + */ + if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){ + $attrs['objectClass'] = array(); + for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){ + $attrs['objectClass'][] = $old_attrs['objectClass'][$i]; + } + $attrs['objectClass'][] = "simpleSecurityObject"; + } + + if(class_available("passwordMethodCrypt")){ + $pwd_m = new passwordMethodCrypt($this->config); + $pwd_m->set_hash("crypt/md5"); + $attrs['userPassword'] = $pwd_m->generate_hash(get_post('new_password')); + }else{ + msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password.")); + $attrs = array(); + } + } + $ldap->modify($attrs); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type)); + }else{ + if(class_available($tDefs[$type]['plugClass'])){ + $plug = $tDefs[$type]['plugClass']; + $p = new $plug($this->config,$this->dn); + $p->handle_post_events("modify"); + } + } + new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error()); + } + set_object_info(); } - new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error()); - } - set_object_info(); } - } - /*! \brief The method gets called when somebody clicked the CD icon - * in the system listing. - * A confirmation will be shown to acknowledge the creation. - */ - function createISO($action,$target) - { - if(count($target) == 1){ - $smarty = get_smarty(); - $this->dn= array_pop($target); - set_object_info($this->dn); - return ($smarty->fetch(get_template_path('goto/gencd.tpl', TRUE))); + /*! \brief The method gets called when somebody clicked the CD icon + * in the system listing. + * A confirmation will be shown to acknowledge the creation. + */ + function createISO($action,$target) + { + if(count($target) == 1){ + $smarty = get_smarty(); + $this->dn= array_pop($target); + set_object_info($this->dn); + return ($smarty->fetch(get_template_path('goto/gencd.tpl', TRUE))); - } - } - - - /*! \brief Once the user has confirmed the ISO creation in 'createISO', - * this method gets called. - * An iFrame is shown which then used 'performIsoCreation' as contents. - */ - function initiateISOcreation() - { - $smarty = get_smarty(); - $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation"); - return ($smarty->fetch(get_template_path('goto/gencd_frame.tpl', TRUE))); - } - - - /*! \brief ISO creation confirmed and iFrame is visible, now create the ISO - * and display the status to fill the iFrame. - */ - function performIsoCreation() - { - $return_button = "
- - -
"; - - $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); - - /* Get and check command */ - $command= $this->config->get_cfg_value("workgeneric", "systemIsoHook"); - if (check_command($command)){ - @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute"); - - /* Print out html introduction */ - echo ' - - - - - - - -
';
-
-      /* Open process handle and check if it is a valid process */
-      $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
-      if (is_resource($process)) {
-        fclose($pipes[0]);
-
-        /* Print out returned lines && write JS to scroll down each line */
-        while (!feof($pipes[1])){
-          $cur_dat = fgets($pipes[1], 1024);
-          echo $cur_dat;
-          echo '' ;
-          flush();
         }
-      }
-
-      /* Get error string && close streams */
-      $buffer= stream_get_contents($pipes[2]);
-
-      fclose($pipes[1]);
-      fclose($pipes[2]);
-      echo "
"; - - /* Check return code */ - $ret= proc_close($process); - if ($ret != 0){ - echo "

"._("Creating the image failed. Please see the report below.")."

"; - echo "
$buffer
"; - } - echo $return_button."
"; - } else { - $tmp= "

".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."

"; - echo $tmp; - echo $return_button."
"; } - /* Scroll down completly */ - echo '' ; - echo ''; - flush(); - exit; - } - - - /*! \brief Handle GOsa-si events - * All schedules and triggered events are handled here. - */ - function handleEvent($action="",$target=array(),$all=array()) - { - // Detect whether this event is scheduled or triggered. - $triggered = TRUE; - if(preg_match("/^S_/",$action)){ - $triggered = FALSE; + + /*! \brief Once the user has confirmed the ISO creation in 'createISO', + * this method gets called. + * An iFrame is shown which then used 'performIsoCreation' as contents. + */ + function initiateISOcreation() + { + $smarty = get_smarty(); + $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation"); + return ($smarty->fetch(get_template_path('goto/gencd_frame.tpl', TRUE))); } - // Detect triggere or scheduled actions - $headpage = $this->getHeadpage(); - $event = preg_replace("/^[TS]_/","",$action); - if(preg_match("/^[TS]_/", $action)){ - - // Send special reinstall action for opsi hosts - if($event == "DaemonEvent_reinstall" && $this->si_active && $this->opsi){ - foreach($target as $key => $dn){ - $type = $headpage->getType($dn); - - // Send Reinstall event for opsi hosts - if($type == "FAKE_OC_OpsiHost"){ - $obj = $headpage->getEntry($dn); - $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]); - unset($target[$key]); - } + + /*! \brief ISO creation confirmed and iFrame is visible, now create the ISO + * and display the status to fill the iFrame. + */ + function performIsoCreation() + { + $return_button = "
+ + +
"; + + $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); + + /* Get and check command */ + $command= $this->config->get_cfg_value("workgeneric", "systemIsoHook"); + if (check_command($command)){ + @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute"); + + /* Print out html introduction */ + echo ' + + + + + + + +
';
+
+            /* Open process handle and check if it is a valid process */
+            $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
+            if (is_resource($process)) {
+                fclose($pipes[0]);
+
+                /* Print out returned lines && write JS to scroll down each line */
+                while (!feof($pipes[1])){
+                    $cur_dat = fgets($pipes[1], 1024);
+                    echo $cur_dat;
+                    echo '' ;
+                    flush();
+                }
+            }
+
+            /* Get error string && close streams */
+            $buffer= stream_get_contents($pipes[2]);
+
+            fclose($pipes[1]);
+            fclose($pipes[2]);
+            echo "
"; + + /* Check return code */ + $ret= proc_close($process); + if ($ret != 0){ + echo "

"._("Creating the image failed. Please see the report below.")."

"; + echo "
$buffer
"; + } + echo $return_button."
"; + } else { + $tmp= "

".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."

"; + echo $tmp; + echo $return_button."
"; } - } - } - - // Now send remaining FAI/GOsa-si events here. - if(count($target) && $this->si_active){ - $mac= array(); - - // Collect target mac addresses - $ldap = $this->config->get_ldap_link(); - $tD = $this->getObjectDefinitions(); - $events = DaemonEvent::get_event_types(SYSTEM_EVENT); - $o_queue = new gosaSupportDaemon(); - foreach($target as $dn){ - $type = $headpage->getType($dn); - if($tD[$type]['sendEvents']){ - $obj = $headpage->getEntry($dn); - if(isset($obj['macAddress'][0])){ - $mac[] = $obj['macAddress'][0]; - } + + /* Scroll down completly */ + echo '' ; + echo ''; + flush(); + exit; + } + + + /*! \brief Handle GOsa-si events + * All schedules and triggered events are handled here. + */ + function handleEvent($action="",$target=array(),$all=array()) + { + // Detect whether this event is scheduled or triggered. + $triggered = TRUE; + if(preg_match("/^S_/",$action)){ + $triggered = FALSE; } - } - - /* Skip installation or update trigerred events, - * if this entry is currently processing. - */ - if($triggered && in_array($event,array("DaemonEvent_reinstall","DaemonEvent_update"))){ - foreach($mac as $key => $mac_address){ - foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){ - $entry['STATUS'] = strtoupper($entry['STATUS']); - if($entry['STATUS'] == "PROCESSING" && - isset($events['QUEUED'][$entry['HEADERTAG']]) && - in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){ - unset($mac[$key]); - - new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress."); - break; + + // Detect triggere or scheduled actions + $headpage = $this->getHeadpage(); + $event = preg_replace("/^[TS]_/","",$action); + if(preg_match("/^[TS]_/", $action)){ + + // Send special reinstall action for opsi hosts + if($event == "DaemonEvent_reinstall" && $this->si_active && $this->opsi){ + foreach($target as $key => $dn){ + $type = $headpage->getType($dn); + + // Send Reinstall event for opsi hosts + if($type == "FAKE_OC_OpsiHost"){ + $obj = $headpage->getEntry($dn); + $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]); + unset($target[$key]); + } + } + } + } + + // Now send remaining FAI/GOsa-si events here. + if(count($target) && $this->si_active){ + $mac= array(); + + // Collect target mac addresses + $ldap = $this->config->get_ldap_link(); + $tD = $this->getObjectDefinitions(); + $events = DaemonEvent::get_event_types(SYSTEM_EVENT); + $o_queue = new gosaSupportDaemon(); + foreach($target as $dn){ + $type = $headpage->getType($dn); + if($tD[$type]['sendEvents']){ + $obj = $headpage->getEntry($dn); + if(isset($obj['macAddress'][0])){ + $mac[] = $obj['macAddress'][0]; + } + } + } + + /* Skip installation or update trigerred events, + * if this entry is currently processing. + */ + if($triggered && in_array($event,array("DaemonEvent_reinstall","DaemonEvent_update"))){ + foreach($mac as $key => $mac_address){ + foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){ + $entry['STATUS'] = strtoupper($entry['STATUS']); + if($entry['STATUS'] == "PROCESSING" && + isset($events['QUEUED'][$entry['HEADERTAG']]) && + in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){ + unset($mac[$key]); + + new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress."); + break; + } + } + } + } + + // Prepare event to be added + if(count($mac) && isset($events['BY_CLASS'][$event]) && $this->si_active){ + $event = $events['BY_CLASS'][$event]; + $this->dialogObject = new $event['CLASS_NAME']($this->config); + $this->dialogObject->add_targets($mac); + + if($triggered){ + $this->dialogObject->set_type(TRIGGERED_EVENT); + $o_queue->append($this->dialogObject); + if($o_queue->is_error()){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + }else{ + $this->closeDialogs(); + } + }else{ + $this->dialogObject->set_type(SCHEDULED_EVENT); + } } - } - } - } - - // Prepare event to be added - if(count($mac) && isset($events['BY_CLASS'][$event]) && $this->si_active){ - $event = $events['BY_CLASS'][$event]; - $this->dialogObject = new $event['CLASS_NAME']($this->config); - $this->dialogObject->add_targets($mac); - - if($triggered){ - $this->dialogObject->set_type(TRIGGERED_EVENT); - $o_queue->append($this->dialogObject); - if($o_queue->is_error()){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - }else{ - $this->closeDialogs(); - } - }else{ - $this->dialogObject->set_type(SCHEDULED_EVENT); } - } } - } - - - /*! \brief Close all dialogs and reset the activationQueue. - */ - function cancelEdit() - { - management::cancelEdit(); - $this->activationQueue = array(); - } - - - /*! \brief Save event dialogs. - * And append the new GOsa-si event. - */ - function saveEventDialog() - { - $o_queue = new gosaSupportDaemon(); - $o_queue->append($this->dialogObject); - if($o_queue->is_error()){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - }else{ - $this->closeDialogs(); + + + /*! \brief Close all dialogs and reset the activationQueue. + */ + function cancelEdit() + { + management::cancelEdit(); + $this->activationQueue = array(); } - } - - - /*! \brief Update filter part for INCOMING. - * Allows us to search for "systemIncomingRDN". - */ - static function incomingFilterConverter($filter) - { - $rdn = preg_replace("/^[^=]*=/", "", get_ou("ArpNewDevice", "systemIncomingRDN")); - $rdn = preg_replace("/,.*$/","",$rdn); - return(preg_replace("/%systemIncomingRDN/", $rdn,$filter)); - } - - - /*! \brief Queue selected objects to be removed. - * Checks ACLs, Locks and ask for confirmation. - */ - protected function removeEntryRequested($action="",$target=array(),$all=array()) - { - // Close dialogs and remove locks for currently handled dns - $this->cancelEdit(); - - $disallowed = array(); - $this->dns = array(); - - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!"); - - // Check permissons for each target - $tInfo = $this->getObjectDefinitions(); - $headpage = $this->getHeadpage(); - foreach($target as $dn){ - $type = $headpage->getType($dn); - if(!isset($tInfo[$type])){ - trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!"); - }else{ - $info = $tInfo[$type]; - $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']); - if(preg_match("/d/",$acl)){ - $this->dns[] = $dn; + + + /*! \brief Save event dialogs. + * And append the new GOsa-si event. + */ + function saveEventDialog() + { + $o_queue = new gosaSupportDaemon(); + $o_queue->append($this->dialogObject); + if($o_queue->is_error()){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); }else{ - $disallowed[] = $dn; + $this->closeDialogs(); } - } } - if(count($disallowed)){ - msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG); + + + /*! \brief Update filter part for INCOMING. + * Allows us to search for "systemIncomingRDN". + */ + static function incomingFilterConverter($filter) + { + $rdn = preg_replace("/^[^=]*=/", "", get_ou("ArpNewDevice", "systemIncomingRDN")); + $rdn = preg_replace("/,.*$/","",$rdn); + return(preg_replace("/%systemIncomingRDN/", $rdn,$filter)); } - // We've at least one entry to delete. - if(count($this->dns)){ - // check locks - if ($user= get_multiple_locks($this->dns)){ - return(gen_locked_message($user,$this->dns)); - } + /*! \brief Queue selected objects to be removed. + * Checks ACLs, Locks and ask for confirmation. + */ + protected function removeEntryRequested($action="",$target=array(),$all=array()) + { + // Close dialogs and remove locks for currently handled dns + $this->cancelEdit(); + + $disallowed = array(); + $this->dns = array(); + + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!"); + + // Check permissons for each target + $tInfo = $this->getObjectDefinitions(); + $headpage = $this->getHeadpage(); + foreach($target as $dn){ + $type = $headpage->getType($dn); + if(!isset($tInfo[$type])){ + trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!"); + }else{ + $info = $tInfo[$type]; + $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']); + if(preg_match("/d/",$acl)){ + $this->dns[] = $dn; + }else{ + $disallowed[] = $dn; + } + } + } + if(count($disallowed)){ + msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG); + } - // Add locks - $dns_names = array(); - $types = array(); - $h = $this->getHeadpage(); + // We've at least one entry to delete. + if(count($this->dns)){ - // Build list of object -labels - foreach($h->objectTypes as $type){ - $map[$type['objectClass']]= $type['label']; - } + // check locks + if ($user= get_multiple_locks($this->dns)){ + return(gen_locked_message($user,$this->dns)); + } - foreach($this->dns as $dn){ - $tmp = $h->getType($dn); - if(isset($map[$tmp])){ - $dns_names[] = '('._($map[$tmp]).') - '.LDAP::fix($dn); - }else{ - $dns_names[] =LDAP::fix($dn); - } - } - add_lock ($this->dns, $this->ui->dn); + // Add locks + $dns_names = array(); + $types = array(); + $h = $this->getHeadpage(); - // Display confirmation dialog. - $smarty = get_smarty(); - $smarty->assign("info", msgPool::deleteInfo($dns_names)); - return($smarty->fetch(get_template_path('removeEntries.tpl'))); - } - } - - - /*! \brief Object removal was confirmed, now remove the requested entries. - * - * @param String 'action' The name of the action which was the used as trigger. - * @param Array 'target' A list of object dns, which should be affected by this method. - * @param Array 'all' A combination of both 'action' and 'target'. - */ - function removeEntryConfirmed($action="",$target=array(),$all=array(), - $altTabClass="",$altTabType="",$altAclCategory="", $aclPlugin="") - { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!"); - - // Check permissons for each target - $tInfo = $this->getObjectDefinitions(); - $headpage = $this->getHeadpage(); - $disallowed = array(); - foreach($this->dns as $key => $dn){ - $type = $headpage->getType($dn); - if(!isset($tInfo[$type])){ - trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!"); - }else{ - - $info = $tInfo[$type]; - $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']); - if(preg_match("/d/",$acl)){ - - // Delete the object - $this->dn = $dn; - if($info['tabClass'] == "phonetabs"){ - $this->tabObject= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type); - $this->tabObject->set_acl_base($dn); - $this->tabObject->by_object['phoneGeneric']->remove_from_parent (); - }else{ - $this->tabObject= new $info['tabClass']($this->config,$this->config->data['TABS'][$info['tabDesc']], - $this->dn, $info['aclCategory'], true, true); - $this->tabObject->set_acl_base($this->dn); - $this->tabObject->parent = &$this; - $this->tabObject->delete (); - } + // Build list of object -labels + foreach($h->objectTypes as $type){ + $map[$type['objectClass']]= $type['label']; + } - // Remove the lock for the current object. - del_lock($this->dn); + foreach($this->dns as $dn){ + $tmp = $h->getType($dn); + if(isset($map[$tmp])){ + $dns_names[] = '('._($map[$tmp]).') - '.LDAP::fix($dn); + }else{ + $dns_names[] =LDAP::fix($dn); + } + } + add_lock ($this->dns, $this->ui->dn); - }else{ - $disallowed[] = $dn; - new log("security","system/".get_class($this),$dn,array(),"Tried to trick deletion."); + // Display confirmation dialog. + $smarty = get_smarty(); + $smarty->assign("info", msgPool::deleteInfo($dns_names)); + return($smarty->fetch(get_template_path('removeEntries.tpl'))); } - } - } - if(count($disallowed)){ - msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG); } - // Cleanup - $this->remove_lock(); - $this->closeDialogs(); - } - - - /*! \brief Edit the selected system type. - * NewDevice and ArpNewDevice are handled here separately - */ - function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="") - { - if(count($target) == 1){ - $tInfo = $this->getObjectDefinitions(); - $headpage = $this->getHeadpage(); - $dn = $target[0]; - $type =$headpage->getType($dn); - $tData = $tInfo[$type]; - - if($type == "FAKE_OC_ArpNewDevice"){ - if(!class_available("ArpNewDeviceTabs")){ - msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG); - }else{ - return(management::editEntry($action,$target,$all,"ArpNewDeviceTabs","ARPNEWDEVICETABS","incoming")); + + /*! \brief Object removal was confirmed, now remove the requested entries. + * + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + function removeEntryConfirmed($action="",$target=array(),$all=array(), + $altTabClass="",$altTabType="",$altAclCategory="", $aclPlugin="") + { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!"); + + // Check permissons for each target + $tInfo = $this->getObjectDefinitions(); + $headpage = $this->getHeadpage(); + $disallowed = array(); + foreach($this->dns as $key => $dn){ + $type = $headpage->getType($dn); + if(!isset($tInfo[$type])){ + trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!"); + }else{ + + $info = $tInfo[$type]; + $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']); + if(preg_match("/d/",$acl)){ + + // Delete the object + $this->dn = $dn; + if($info['tabClass'] == "phonetabs"){ + $this->tabObject= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type); + $this->tabObject->set_acl_base($dn); + $this->tabObject->by_object['phoneGeneric']->remove_from_parent (); + }else{ + $this->tabObject= new $info['tabClass']($this->config,$this->config->data['TABS'][$info['tabDesc']], + $this->dn, $info['aclCategory'], true, true); + $this->tabObject->set_acl_base($this->dn); + $this->tabObject->parent = &$this; + $this->tabObject->delete (); + } + + // Remove the lock for the current object. + del_lock($this->dn); + + }else{ + $disallowed[] = $dn; + new log("security","system/".get_class($this),$dn,array(),"Tried to trick deletion."); + } + } } - }elseif($type == "FAKE_OC_NewDevice"){ - if(!class_available("SelectDeviceType")){ - msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG); - }else{ - $this->activationQueue[$dn] = array(); - $this->dialogObject = new SelectDeviceType($this->config,$dn); - $this->dialogObject->set_acl_category("incoming"); - $this->skipFooter = TRUE; - $this->displayApplyBtn = FALSE; - // see condition -$s_action == "::systemTypeChosen"- for further handling + if(count($disallowed)){ + msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG); } - }else{ - return(management::editEntry($action,$target,$all,$tData['tabClass'],$tData['tabDesc'],$tData['aclCategory'])); - } - } - } - - - /*! \brief Edit the selected system type. - * - * @param String 'action' The name of the action which was the used as trigger. - * @param Array 'target' A list of object dns, which should be affected by this method. - * @param Array 'all' A combination of both 'action' and 'target'. - */ - function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="") - { - $tInfo = $this->getObjectDefinitions(); - $info = preg_replace("/^new_/","",$action); - if(!isset($tInfo[$info])){ - trigger_error("Unknown action type '".$action."' cant create a new system!"); - }else{ - return(management::newEntry($action,$target,$all, - $tInfo[$info]['tabClass'], - $tInfo[$info]['tabDesc'], - $tInfo[$info]['aclCategory'])); + + // Cleanup + $this->remove_lock(); + $this->closeDialogs(); } - } - - - /*! \brief Activates all selcted 'NewDevices' at once. - * Enqueues the selected Devices in the activation queue. - */ - function activateMultiple($action,$target) - { - $headpage = $this->getHeadpage(); - foreach($target as $dn) { - if($headpage->getType($dn) == "FAKE_OC_NewDevice"){ - $this->activationQueue[$dn] = array(); - } + + + /*! \brief Edit the selected system type. + * NewDevice and ArpNewDevice are handled here separately + */ + function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="") + { + if(count($target) == 1){ + $tInfo = $this->getObjectDefinitions(); + $headpage = $this->getHeadpage(); + $dn = $target[0]; + $type =$headpage->getType($dn); + $tData = $tInfo[$type]; + + if($type == "FAKE_OC_ArpNewDevice"){ + if(!class_available("ArpNewDeviceTabs")){ + msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG); + }else{ + return(management::editEntry($action,$target,$all,"ArpNewDeviceTabs","ARPNEWDEVICETABS","incoming")); + } + }elseif($type == "FAKE_OC_NewDevice"){ + if(!class_available("SelectDeviceType")){ + msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG); + }else{ + $this->activationQueue[$dn] = array(); + $this->dialogObject = new SelectDeviceType($this->config,$dn); + $this->dialogObject->set_acl_category("incoming"); + $this->skipFooter = TRUE; + $this->displayApplyBtn = FALSE; + // see condition -$s_action == "::systemTypeChosen"- for further handling + } + }else{ + return(management::editEntry($action,$target,$all,$tData['tabClass'],$tData['tabDesc'],$tData['aclCategory'])); + } + } } - if(count($this->activationQueue)){ - $this->dialogObject = new SelectDeviceType($this->config, array_keys($this->activationQueue)); - $this->skipFooter = TRUE; + + + /*! \brief Edit the selected system type. + * + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="") + { + $tInfo = $this->getObjectDefinitions(); + $info = preg_replace("/^new_/","",$action); + if(!isset($tInfo[$info])){ + trigger_error("Unknown action type '".$action."' cant create a new system!"); + }else{ + return(management::newEntry($action,$target,$all, + $tInfo[$info]['tabClass'], + $tInfo[$info]['tabDesc'], + $tInfo[$info]['aclCategory'])); + } } - } - - - /*! \brief The system selection dialog was closed. - * We will now queue the given entry to be activated. - */ - function systemTypeChosen() - { - // Detect the systems target type - $tInfo = $this->getObjectDefinitions(); - $selected_group = "none"; - if(isset($_POST['ObjectGroup'])){ - $selected_group = $_POST['ObjectGroup']; + + + /*! \brief Activates all selcted 'NewDevices' at once. + * Enqueues the selected Devices in the activation queue. + */ + function activateMultiple($action,$target) + { + $headpage = $this->getHeadpage(); + foreach($target as $dn) { + if($headpage->getType($dn) == "FAKE_OC_NewDevice"){ + $this->activationQueue[$dn] = array(); + } + } + if(count($this->activationQueue)){ + $this->dialogObject = new SelectDeviceType($this->config, array_keys($this->activationQueue)); + $this->skipFooter = TRUE; + } } - $selected_system = $_POST['SystemType']; - $tmp = array(); - foreach($this->activationQueue as $dn => $data){ - $tmp[$dn]['OG'] = $selected_group; - $tmp[$dn]['SS'] = $selected_system; + + + /*! \brief The system selection dialog was closed. + * We will now queue the given entry to be activated. + */ + function systemTypeChosen() + { + // Detect the systems target type + $tInfo = $this->getObjectDefinitions(); + $selected_group = "none"; + if(isset($_POST['ObjectGroup'])){ + $selected_group = get_post('ObjectGroup'); + } + $selected_system = get_post('SystemType'); + $tmp = array(); + foreach($this->activationQueue as $dn => $data){ + $tmp[$dn]['OG'] = $selected_group; + $tmp[$dn]['SS'] = $selected_system; + } + $this->closeDialogs(); + $this->activationQueue = $tmp; + return($this->handleActivationQueue()); } - $this->closeDialogs(); - $this->activationQueue = $tmp; - return($this->handleActivationQueue()); - } - - - /*! \brief Activate queued goto systems. - */ - function handleActivationQueue() - { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - 'Entries left: '.count($this->activationQueue), "Handling system activation queue!"); - - if(!count($this->activationQueue)) return(""); - - $ldap = $this->config->get_ldap_link(); - $pInfo = $this->getObjectDefinitions(); - $ui = get_userinfo(); - $headpage = $this->getHeadpage(); - $ldap->cd($this->config->current['BASE']); - - // Walk through systems to activate - while(count($this->activationQueue)){ - - // Get next entry - reset($this->activationQueue); - $dn = key($this->activationQueue); - $data= $this->activationQueue[$dn]; - - // Validate the given system type. - if(!isset($data['SS'])) continue; - $sysType = $data['SS']; - if(!isset($pInfo[$sysType])){ - trigger_error('Unknown type \''.$sysType.'\'!'); - continue; - } - $type = $pInfo[$sysType]; - - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $dn, "Try to activate:"); - - // Get target type definition - $plugClass = $type["plugClass"]; - $tabClass = $type["tabClass"]; - $aclCategory = $type["aclCategory"]; - $tabDesc = $type["tabDesc"]; - - if(!class_available($tabClass)){ - msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG); - unset($this->activationQueue[$dn]); - continue; - }else{ + + /*! \brief Activate queued goto systems. + */ + function handleActivationQueue() + { @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $sysType, "System type:"); + 'Entries left: '.count($this->activationQueue), "Handling system activation queue!"); + + if(!count($this->activationQueue)) return(""); + + $ldap = $this->config->get_ldap_link(); + $pInfo = $this->getObjectDefinitions(); + $ui = get_userinfo(); + $headpage = $this->getHeadpage(); + $ldap->cd($this->config->current['BASE']); + + // Walk through systems to activate + while(count($this->activationQueue)){ + + // Get next entry + reset($this->activationQueue); + $dn = key($this->activationQueue); + $data= $this->activationQueue[$dn]; + + // Validate the given system type. + if(!isset($data['SS'])) continue; + $sysType = $data['SS']; + if(!isset($pInfo[$sysType])){ + trigger_error('Unknown type \''.$sysType.'\'!'); + continue; + } + $type = $pInfo[$sysType]; - // Load permissions for selected 'dn' and check if we're allowed to create this 'dn' - $this->dn = $dn; - $acls = $ui->get_permissions($this->dn,$aclCategory."/".$plugClass); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $dn, "Try to activate:"); - // Check permissions - if(!preg_match("/c/",$acls)){ - unset($this->activationQueue[$dn]); - msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG); + // Get target type definition + $plugClass = $type["plugClass"]; + $tabClass = $type["tabClass"]; + $aclCategory = $type["aclCategory"]; + $tabDesc = $type["tabDesc"]; - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $acls, "Insufficient permissions!"); - continue; - }else{ + if(!class_available($tabClass)){ + msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG); + unset($this->activationQueue[$dn]); + continue; + }else{ - // Open object an preset some values like the objects base - del_lock($dn); - management::editEntry('editEntry',array($dn),array(),$tabClass,$tabDesc, $aclCategory); - $this->displayApplyBtn = FALSE; - $this->tabObject->set_acl_base($headpage->getBase()); - - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $data['OG'], "Selected ogroup:"); - - if($data['OG'] != "none"){ - $this->tabObject->base = preg_replace("/^[^,]+,".preg_quote(get_ou("group", "ogroupRDN"), '/')."/i", "", $data['OG']); - $this->tabObject->by_object[$plugClass]->baseSelector->setBase($this->tabObject->base); - } else { - $this->tabObject->by_object[$plugClass]->baseSelector->setBase($headpage->getBase()); - $this->tabObject->base = $headpage->getBase(); - } - - // Assign some default values for opsi hosts - if($this->tabObject instanceOf opsi_tabs){ - $ldap = $this->config->get_ldap_link(); - $ldap->cat($dn); - $source_attrs = $ldap->fetch(); - foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){ - if(isset($source_attrs[$src][0])){ - $this->tabObject->by_object['opsiGeneric']->$attr = $source_attrs[$src][0]; - } - } - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - "", "OPSI attributes adapted"); - } - - // Queue entry to be activated, when it is saved. - if($data['OG'] != "none"){ - - // Set gotoMode to active if there was an ogroup selected. - $found = false; - foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){ - if(isset($this->tabObject->by_object[$tab]->gotoMode)) { - $found = true; - $this->tabObject->by_object[$tab]->gotoMode = $value; @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $tab."->gotoMode = {$value}", "Setting gotoMode to: "); - } - } - if(!$found){ - msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG); + $sysType, "System type:"); + + // Load permissions for selected 'dn' and check if we're allowed to create this 'dn' + $this->dn = $dn; + $acls = $ui->get_permissions($this->dn,$aclCategory."/".$plugClass); + + // Check permissions + if(!preg_match("/c/",$acls)){ + unset($this->activationQueue[$dn]); + msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG); + + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $acls, "Insufficient permissions!"); + continue; + }else{ + + // Open object an preset some values like the objects base + del_lock($dn); + management::editEntry('editEntry',array($dn),array(),$tabClass,$tabDesc, $aclCategory); + $this->displayApplyBtn = FALSE; + $this->tabObject->set_acl_base($headpage->getBase()); + + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $data['OG'], "Selected ogroup:"); + + if($data['OG'] != "none"){ + $this->tabObject->base = preg_replace("/^[^,]+,".preg_quote(get_ou("group", "ogroupRDN"), '/')."/i", "", $data['OG']); + $this->tabObject->by_object[$plugClass]->baseSelector->setBase($this->tabObject->base); + } else { + $this->tabObject->by_object[$plugClass]->baseSelector->setBase($headpage->getBase()); + $this->tabObject->base = $headpage->getBase(); + } + + // Assign some default values for opsi hosts + if($this->tabObject instanceOf opsi_tabs){ + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + $source_attrs = $ldap->fetch(); + foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){ + if(isset($source_attrs[$src][0])){ + $this->tabObject->by_object['opsiGeneric']->$attr = $source_attrs[$src][0]; + } + } + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + "", "OPSI attributes adapted"); + } + + // Queue entry to be activated, when it is saved. + if($data['OG'] != "none"){ + + // Set gotoMode to active if there was an ogroup selected. + $found = false; + foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){ + if(isset($this->tabObject->by_object[$tab]->gotoMode)) { + $found = true; + $this->tabObject->by_object[$tab]->gotoMode = $value; + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $tab."->gotoMode = {$value}", "Setting gotoMode to: "); + } + } + if(!$found){ + msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG); + } + + // Update object group membership + $og = new ogroup($this->config,$data['OG']); + if($og){ + $og->AddDelMembership($this->tabObject->dn); + $og->save(); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $og->dn, "Adding system to ogroup"); + } + + // Set default system specific attributes + foreach (array("workgeneric", "termgeneric") as $cls){ + if (isset($this->tabObject->by_object[$cls])){ + $this->tabObject->by_object[$cls]->set_everything_to_inherited(); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $og->dn, "Calling {$cls}->set_everything_to_inherited()"); + } + } + + // Enable activation + foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){ + if (isset($this->tabObject->by_object[$cls])){ + $this->tabObject->by_object[$cls]->auto_activate= TRUE; + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $cls, "Setting auto_activate=TRUE for"); + } + } + + // Enable sending of LDAP events + if (isset($this->tabObject->by_object["workstartup"])){ + $this->tabObject->by_object["workstartup"]->gotoLdap_inherit= TRUE; + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + "", "Setting workstartup->gotoLdap_inherit=TRUE"); + } + } + + // Try to inherit everythin from the selected object group and then save + // the entry, normally this should work without any problems. + // But if there is any, then display the dialogs. + if($data['OG'] != "none"){ + $str = $this->saveChanges(); + + // There was a problem, skip activation here and allow to fix the problems.. + if(is_object($this->tabObject)){ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + "", "Automatic saving failed, let the user fix the issues now."); + return; + } + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + "", "System activated!"); + }else{ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + "", "Open dialogs now"); + return; + } + } } + } + } - // Update object group membership - $og = new ogroup($this->config,$data['OG']); - if($og){ - $og->AddDelMembership($this->tabObject->dn); - $og->save(); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $og->dn, "Adding system to ogroup"); - } - // Set default system specific attributes - foreach (array("workgeneric", "termgeneric") as $cls){ - if (isset($this->tabObject->by_object[$cls])){ - $this->tabObject->by_object[$cls]->set_everything_to_inherited(); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $og->dn, "Calling {$cls}->set_everything_to_inherited()"); - } + /*! \brief Save object modifications here and any dialogs too. + * After a successfull update of the object data, close + * the dialogs. + */ + protected function saveChanges() + { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + get_class($this->tabObject).": ".$this->tabObject->dn, "Save"); + + // Handle 'New Unknown Devices' here. + if($this->tabObject instanceOf ArpNewDeviceTabs){ + $this->tabObject->save_object(); + + if($this->tabObject->by_object['ArpNewDevice']->gotoIntegration){ + $message = $this->tabObject->check(); + if(count($message)){ + msg_dialog::displayChecks($message); + }else{ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + get_class($this->tabObject).": ".$this->tabObject->dn, "Queued for goto activation"); + $this->tabObject->save(); + $this->activationQueue[$this->tabObject->dn]=array(); + $this->closeDialogs(); + $this->systemTypeChosen(); + } + return; } + } - // Enable activation - foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){ - if (isset($this->tabObject->by_object[$cls])){ - $this->tabObject->by_object[$cls]->auto_activate= TRUE; - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $cls, "Setting auto_activate=TRUE for"); - } - } + // Try to save changes here. + $str = management::saveChanges(); + if($this->tabObject) return(""); - // Enable sending of LDAP events - if (isset($this->tabObject->by_object["workstartup"])){ - $this->tabObject->by_object["workstartup"]->gotoLdap_inherit= TRUE; - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - "", "Setting workstartup->gotoLdap_inherit=TRUE"); - } - } - - // Try to inherit everythin from the selected object group and then save - // the entry, normally this should work without any problems. - // But if there is any, then display the dialogs. - if($data['OG'] != "none"){ - $str = $this->saveChanges(); - - // There was a problem, skip activation here and allow to fix the problems.. - if(is_object($this->tabObject)){ - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - "", "Automatic saving failed, let the user fix the issues now."); - return; - } - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - "", "System activated!"); - }else{ - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - "", "Open dialogs now"); - return; - } + // Activate system if required.. + if(isset($this->activationQueue[$this->last_dn])){ + $dn = $this->last_tabObject->dn; + $this->activate_new_device($dn); + unset($this->activationQueue[$this->last_dn]); } - } - } - } - - - /*! \brief Save object modifications here and any dialogs too. - * After a successfull update of the object data, close - * the dialogs. - */ - protected function saveChanges() - { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - get_class($this->tabObject).": ".$this->tabObject->dn, "Save"); - - // Handle 'New Unknown Devices' here. - if($this->tabObject instanceOf ArpNewDeviceTabs){ - $this->tabObject->save_object(); - - if($this->tabObject->by_object['ArpNewDevice']->gotoIntegration){ - $message = $this->tabObject->check(); - if(count($message)){ - msg_dialog::displayChecks($message); - }else{ - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - get_class($this->tabObject).": ".$this->tabObject->dn, "Queued for goto activation"); - $this->tabObject->save(); - $this->activationQueue[$this->tabObject->dn]=array(); - $this->closeDialogs(); - $this->systemTypeChosen(); + + /* Post handling for activated systems + target opsi -> Remove source. + target gosa -> Activate system. + */ + if($this->last_tabObject instanceOf opsi_tabs){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->rmdir ($this->last_tabObject->dn); + @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__, + "Source removed: ".$this->tabObject->dn,"Opsi host activated"); + + $hostId = $this->last_tabObject->by_object['opsiGeneric']->hostId; + $mac = $this->last_tabObject->by_object['opsiGeneric']->mac; + $this->opsi->job_opsi_activate_client($hostId,$mac); + + }elseif(isset($this->last_tabObject->was_activated) && $this->last_tabObject->was_activated){ + $this->activate_new_device($this->last_tabObject->dn); } - return; - } + + // Avoid using values from an older input dialog + $_POST = array(); + $this->handleActivationQueue(); } - // Try to save changes here. - $str = management::saveChanges(); - if($this->tabObject) return(""); - // Activate system if required.. - if(isset($this->activationQueue[$this->last_dn])){ - $dn = $this->last_tabObject->dn; - $this->activate_new_device($dn); - unset($this->activationQueue[$this->last_dn]); + /*! \brief Save object modifications here and any dialogs too. + * Keep dialogs opened. + */ + protected function applyChanges() + { + $str = management::applyChanges(); + if($str) return($str); + + /* Post handling for activated systems + target opsi -> Remove source. + target gosa -> Activate system. + */ + if($this->tabObject instanceOf opsi_tabs){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->rmdir ($this->tabObject->dn); + @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__, + "Source removed: ".$this->tabObject->dn,"Opsi host activated"); + + $hostId = $this->tabObject->by_object['opsiGeneric']->hostId; + $mac = $this->tabObject->by_object['opsiGeneric']->mac; + $this->opsi->job_opsi_activate_client($hostId,$mac); + $this->tabObject->set_acl_base($this->dn); + + }elseif(isset($this->tabObject->was_activated) && $this->tabObject->was_activated){ + $this->activate_new_device($this->tabObject->dn); + } } - /* Post handling for activated systems - target opsi -> Remove source. - target gosa -> Activate system. + + /*! \brief Sets FAIstate to "install" for "New Devices". + This function is some kind of "Post handler" for activated systems, + it is called directly after the object (workstabs,servtabs) gets saved. + @param String $dn The dn of the newly activated object. + @return Boolean TRUE if activated else FALSE */ - if($this->last_tabObject instanceOf opsi_tabs){ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->rmdir ($this->last_tabObject->dn); - @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__, - "Source removed: ".$this->tabObject->dn,"Opsi host activated"); - - $hostId = $this->last_tabObject->by_object['opsiGeneric']->hostId; - $mac = $this->last_tabObject->by_object['opsiGeneric']->mac; - $this->opsi->job_opsi_activate_client($hostId,$mac); - - }elseif(isset($this->last_tabObject->was_activated) && $this->last_tabObject->was_activated){ - $this->activate_new_device($this->last_tabObject->dn); + function activate_new_device($dn) + { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $dn, "Activating system:"); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->cat($dn); + if($ldap->count()){ + $attrs = $ldap->fetch(); + if(count(array_intersect(array('goServer','gotoWorkstation'), $attrs['objectClass']))){ + $ocs = $attrs['objectClass']; + unset($ocs['count']); + $new_attrs = array(); + if(!in_array("FAIobject",$ocs)){ + $ocs[] = "FAIobject"; + $new_attrs['objectClass'] = $ocs; + } + $new_attrs['FAIstate'] = "install"; + $ldap->cd($dn); + $ldap->modify($new_attrs); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, + LDAP_MOD, "activate_new_device($dn)")); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $dn, "Failed!"); + }else{ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $dn, "Success"); + return(TRUE); + } + }else{ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, + $dn, "FAIstate not set to install, this is only done for gotoWorkstation/goServer!"); + } + } + return(FALSE); } - // Avoid using values from an older input dialog - $_POST = array(); - $this->handleActivationQueue(); - } + /*! \brief Opens the snapshot creation dialog for the given target. + * + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + function createSnapshotDialog($action="",$target=array(),$all=array()) + { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!"); + + $pInfo = $this->getObjectDefinitions(); + $headpage = $this->getHeadpage(); + foreach($target as $dn){ + + $entry = $headpage->getEntry($dn); + $type = $headpage->getType($dn); + if(!isset($pInfo[$type])) { + trigger_error('Unknown system type \''.$type.'\'!'); + return; + } - /*! \brief Save object modifications here and any dialogs too. - * Keep dialogs opened. - */ - protected function applyChanges() - { - $str = management::applyChanges(); - if($str) return($str); + if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){ + $this->dialogObject = new SnapShotDialog($this->config,$dn,$this); + $this->dialogObject->aclCategories = array($pInfo[$type]['aclCategory']); + $this->dialogObject->parent = &$this; - /* Post handling for activated systems - target opsi -> Remove source. - target gosa -> Activate system. - */ - if($this->tabObject instanceOf opsi_tabs){ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->rmdir ($this->tabObject->dn); - @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__, - "Source removed: ".$this->tabObject->dn,"Opsi host activated"); - - $hostId = $this->tabObject->by_object['opsiGeneric']->hostId; - $mac = $this->tabObject->by_object['opsiGeneric']->mac; - $this->opsi->job_opsi_activate_client($hostId,$mac); - $this->tabObject->set_acl_base($this->dn); - - }elseif(isset($this->tabObject->was_activated) && $this->tabObject->was_activated){ - $this->activate_new_device($this->tabObject->dn); + }else{ + msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$dn), + ERROR_DIALOG); + } + } } - } - - - /*! \brief Sets FAIstate to "install" for "New Devices". - This function is some kind of "Post handler" for activated systems, - it is called directly after the object (workstabs,servtabs) gets saved. - @param String $dn The dn of the newly activated object. - @return Boolean TRUE if activated else FALSE - */ - function activate_new_device($dn) - { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $dn, "Activating system:"); - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->cat($dn); - if($ldap->count()){ - $attrs = $ldap->fetch(); - if(count(array_intersect(array('goServer','gotoWorkstation'), $attrs['objectClass']))){ - $ocs = $attrs['objectClass']; - unset($ocs['count']); - $new_attrs = array(); - if(!in_array("FAIobject",$ocs)){ - $ocs[] = "FAIobject"; - $new_attrs['objectClass'] = $ocs; + + + /*! \brief Displays the "Restore snapshot dialog" for a given target. + * If no target is specified, open the restore removed object + * dialog. + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + function restoreSnapshotDialog($action="",$target=array(),$all=array()) + { + // Set current restore base for snapshot handling. + $headpage = $this->getHeadpage(); + $pInfo = $this->getObjectDefinitions(); + if(is_object($this->snapHandler)){ + $bases = array(); + foreach($this->storagePoints as $sp){ + $bases[] = $sp.$headpage->getBase(); + } } - $new_attrs['FAIstate'] = "install"; - $ldap->cd($dn); - $ldap->modify($new_attrs); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, - LDAP_MOD, "activate_new_device($dn)")); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $dn, "Failed!"); + + // No bases specified? Try base + if(!count($bases)) $bases[] = $this->headpage->getBase(); + + // No target, open the restore removed object dialog. + if(!count($target)){ + + $cats = array(); + foreach($pInfo as $data){ + $cats[] = $data['aclCategory']; + } + $cats = array_unique($cats); + + $entry = $headpage->getBase(); + if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$cats)){ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!"); + $this->dialogObject = new SnapShotDialog($this->config,$entry,$this); + $this->dialogObject->set_snapshot_bases($bases); + $this->dialogObject->display_all_removed_objects = true; + $this->dialogObject->display_restore_dialog = true; + $this->dialogObject->parent = &$this; + }else{ + msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry), + ERROR_DIALOG); + } }else{ - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $dn, "Success"); - return(TRUE); + + // Display the restore points for a given object. + $dn = array_pop($target); + $entry = $headpage->getEntry($dn); + $type = $headpage->getType($dn); + if(!isset($pInfo[$type])) { + trigger_error('Unknown system type \''.$type.'\'!'); + return; + } + + if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restoring initiated!"); + $this->dialogObject = new SnapShotDialog($this->config,$dn,$this); + $this->dialogObject->set_snapshot_bases($bases); + $this->dialogObject->display_restore_dialog = true; + $this->dialogObject->parent = &$this; + }else{ + msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$dn), + ERROR_DIALOG); + } } - }else{ - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, - $dn, "FAIstate not set to install, this is only done for gotoWorkstation/goServer!"); - } - } - return(FALSE); - } - - - /*! \brief Opens the snapshot creation dialog for the given target. - * - * @param String 'action' The name of the action which was the used as trigger. - * @param Array 'target' A list of object dns, which should be affected by this method. - * @param Array 'all' A combination of both 'action' and 'target'. - */ - function createSnapshotDialog($action="",$target=array(),$all=array()) - { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!"); - - $pInfo = $this->getObjectDefinitions(); - $headpage = $this->getHeadpage(); - foreach($target as $dn){ - - $entry = $headpage->getEntry($dn); - $type = $headpage->getType($dn); - if(!isset($pInfo[$type])) { - trigger_error('Unknown system type \''.$type.'\'!'); - return; - } - - if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){ - $this->dialogObject = new SnapShotDialog($this->config,$dn,$this); - $this->dialogObject->aclCategories = array($pInfo[$type]['aclCategory']); - $this->dialogObject->parent = &$this; - - }else{ - msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$dn), - ERROR_DIALOG); - } - } - } - - - /*! \brief Displays the "Restore snapshot dialog" for a given target. - * If no target is specified, open the restore removed object - * dialog. - * @param String 'action' The name of the action which was the used as trigger. - * @param Array 'target' A list of object dns, which should be affected by this method. - * @param Array 'all' A combination of both 'action' and 'target'. - */ - function restoreSnapshotDialog($action="",$target=array(),$all=array()) - { - // Set current restore base for snapshot handling. - $headpage = $this->getHeadpage(); - $pInfo = $this->getObjectDefinitions(); - if(is_object($this->snapHandler)){ - $bases = array(); - foreach($this->storagePoints as $sp){ - $bases[] = $sp.$headpage->getBase(); - } } - // No bases specified? Try base - if(!count($bases)) $bases[] = $this->headpage->getBase(); - - // No target, open the restore removed object dialog. - if(!count($target)){ - - $cats = array(); - foreach($pInfo as $data){ - $cats[] = $data['aclCategory']; - } - $cats = array_unique($cats); - - $entry = $headpage->getBase(); - if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$cats)){ - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!"); - $this->dialogObject = new SnapShotDialog($this->config,$entry,$this); - $this->dialogObject->set_snapshot_bases($bases); - $this->dialogObject->display_all_removed_objects = true; - $this->dialogObject->display_restore_dialog = true; - $this->dialogObject->parent = &$this; - }else{ - msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry), - ERROR_DIALOG); - } - }else{ - - // Display the restore points for a given object. - $dn = array_pop($target); - $entry = $headpage->getEntry($dn); - $type = $headpage->getType($dn); - if(!isset($pInfo[$type])) { - trigger_error('Unknown system type \''.$type.'\'!'); - return; - } - - if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){ - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restoring initiated!"); - $this->dialogObject = new SnapShotDialog($this->config,$dn,$this); - $this->dialogObject->set_snapshot_bases($bases); - $this->dialogObject->display_restore_dialog = true; - $this->dialogObject->parent = &$this; - }else{ - msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$dn), - ERROR_DIALOG); - } + + /*! \brief Restores a snapshot object. + * The dn of the snapshot entry has to be given as ['target'] parameter. + * + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + function restoreSnapshot($action="",$target=array(),$all=array()) + { + $dn = array_pop($target); + $this->snapHandler->restore_snapshot($dn); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restored!"); + $this->closeDialogs(); } - } - - - /*! \brief Restores a snapshot object. - * The dn of the snapshot entry has to be given as ['target'] parameter. - * - * @param String 'action' The name of the action which was the used as trigger. - * @param Array 'target' A list of object dns, which should be affected by this method. - * @param Array 'all' A combination of both 'action' and 'target'. - */ - function restoreSnapshot($action="",$target=array(),$all=array()) - { - $dn = array_pop($target); - $this->snapHandler->restore_snapshot($dn); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restored!"); - $this->closeDialogs(); - } - - - /*! \brief Detects actions/events send by the ui - * and the corresponding targets. - */ - function detectPostActions() - { - $action= management::detectPostActions(); - if(isset($_POST['abort_event_dialog'])) $action['action'] = "cancel"; - if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEvent"; - if(isset($_POST['cd_create'])) $action['action'] = "initiateISOcreation"; - if(isset($_GET['PerformIsoCreation'])) $action['action'] = "performIsoCreation"; - if(isset($_POST['SystemTypeAborted'])) $action['action'] = "cancel"; - if(isset($_POST['password_cancel'])) $action['action'] = "cancel"; - if(isset($_POST['password_finish'])) $action['action'] = "passwordChangeConfirmed"; - - if(isset($_POST['new_goServer'])) $action['action'] = "new_goServer"; - if(isset($_POST['new_gotoWorkstation'])) $action['action'] = "new_gotoWorkstation"; - if(isset($_POST['new_gotoTerminal'])) $action['action'] = "new_gotoTerminal"; - if(isset($_POST['new_gotoPrinter'])) $action['action'] = "new_gotoPrinter"; - if(isset($_POST['new_goFonHardware'])) $action['action'] = "new_goFonHardware"; - if(isset($_POST['new_ieee802Device'])) $action['action'] = "new_ieee802Device"; - if(isset($_POST['new_FAKE_OC_OpsiHost'])) $action['action'] = "new_FAKE_OC_OpsiHost"; - - if(!is_object($this->tabObject) && !is_object($this->dialogObject)){ - if(count($this->activationQueue)) $action['action'] = "handleActivationQueue"; + + + /*! \brief Detects actions/events send by the ui + * and the corresponding targets. + */ + function detectPostActions() + { + $action= management::detectPostActions(); + if(isset($_POST['abort_event_dialog'])) $action['action'] = "cancel"; + if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEvent"; + if(isset($_POST['cd_create'])) $action['action'] = "initiateISOcreation"; + if(isset($_GET['PerformIsoCreation'])) $action['action'] = "performIsoCreation"; + if(isset($_POST['SystemTypeAborted'])) $action['action'] = "cancel"; + if(isset($_POST['password_cancel'])) $action['action'] = "cancel"; + if(isset($_POST['password_finish'])) $action['action'] = "passwordChangeConfirmed"; + + if(isset($_POST['new_goServer'])) $action['action'] = "new_goServer"; + if(isset($_POST['new_gotoWorkstation'])) $action['action'] = "new_gotoWorkstation"; + if(isset($_POST['new_gotoTerminal'])) $action['action'] = "new_gotoTerminal"; + if(isset($_POST['new_gotoPrinter'])) $action['action'] = "new_gotoPrinter"; + if(isset($_POST['new_goFonHardware'])) $action['action'] = "new_goFonHardware"; + if(isset($_POST['new_ieee802Device'])) $action['action'] = "new_ieee802Device"; + if(isset($_POST['new_FAKE_OC_OpsiHost'])) $action['action'] = "new_FAKE_OC_OpsiHost"; + + if(!is_object($this->tabObject) && !is_object($this->dialogObject)){ + if(count($this->activationQueue)) $action['action'] = "handleActivationQueue"; + } + + if(isset($_POST['systemTypeChosen'])) $action['action'] = "systemTypeChosen"; + + return($action); } - if(isset($_POST['systemTypeChosen'])) $action['action'] = "systemTypeChosen"; - return($action); - } + /*! \brief Overridden render method of class management. + * this allows us to add a release selection box. + */ + function renderList() + { + $headpage = $this->getHeadpage(); + $headpage->update(); + + $tD = $this->getObjectDefinitions(); + $smarty = get_smarty(); + foreach($tD as $name => $obj){ + $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME']))); + } + $display = $headpage->render(); + return($this->getHeader().$display); + } - /*! \brief Overridden render method of class management. - * this allows us to add a release selection box. - */ - function renderList() - { - $headpage = $this->getHeadpage(); - $headpage->update(); - $tD = $this->getObjectDefinitions(); - $smarty = get_smarty(); - foreach($tD as $name => $obj){ - $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME']))); + public function getObjectDefinitions() + { + $tabs = array( + "FAKE_OC_OpsiHost" => array( + "ou" => "", + "plugClass" => "opsiGeneric", + "tabClass" => "opsi_tabs", + "tabDesc" => "OPSITABS", + "aclClass" => "opsiGeneric", + "sendEvents" => TRUE, + "aclCategory" => "opsi"), + + "goServer" => array( + "ou" => get_ou("servgeneric", "serverRDN"), + "plugClass" => "servgeneric", + "tabClass" => "servtabs", + "tabDesc" => "SERVTABS", + "aclClass" => "servgeneric", + "sendEvents" => TRUE, + "aclCategory" => "server"), + + "gotoWorkstation" => array( + "ou" => get_ou("workgeneric", "workstationRDN"), + "plugClass" => "workgeneric", + "tabClass" => "worktabs", + "tabDesc" => "WORKTABS", + "aclClass" => "workgeneric", + "sendEvents" => TRUE, + "aclCategory" => "workstation"), + + "gotoTerminal" => array( + "ou" => get_ou("termgeneric", "terminalRDN"), + "plugClass" => "termgeneric", + "tabClass" => "termtabs", + "sendEvents" => TRUE, + "tabDesc" => "TERMTABS", + "aclClass" => "termgeneric", + "aclCategory" => "terminal"), + + "gotoPrinter" => array( + "ou" => get_ou("printgeneric", "printerRDN"), + "plugClass" => "printgeneric", + "tabClass" => "printtabs", + "tabDesc" => "PRINTTABS", + "aclClass" => "printgeneric", + "sendEvents" => FALSE, + "aclCategory" => "printer"), + + "FAKE_OC_NewDevice" => array( + "ou" => get_ou("ArpNewDevice", "systemIncomingRDN"), + "plugClass" => "termgeneric", + "tabClass" => "termtabs", + "sendEvents" => TRUE, + "tabDesc" => "TERMTABS", + "aclClass" => "termgeneric", + "aclCategory" => "terminal"), + + "goFonHardware" => array( + "ou" => get_ou("phoneGeneric", "phoneRDN"), + "plugClass" => "phoneGeneric", + "tabClass" => "phonetabs", + "tabDesc" => "PHONETABS", + "sendEvents" => FALSE, + "aclClass" => "phoneGeneric", + "aclCategory" => "phone"), + + "FAKE_OC_winstation" => array( + "ou" => get_winstations_ou(), + "plugClass" => "wingeneric", + "sendEvents" => TRUE, + "tabClass" => "wintabs", + "tabDesc" => "WINTABS", + "aclClass" => "wingeneric", + "aclCategory" => "winworkstation"), + + "ieee802Device" => array( + "ou" => get_ou("componentGeneric", "componentRDN"), + "plugClass" => "componentGeneric", + "sendEvents" => FALSE, + "tabClass" => "componenttabs", + "tabDesc" => "COMPONENTTABS", + "aclClass" => "componentGeneric", + "aclCategory" => "component"), + ); + + // Now map some special types + $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation']; + $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal']; + $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation']; + $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation']; + $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation']; + $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation']; + $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal']; + $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal']; + $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal']; + $tabs['FAKE_OC_TerminalTemplate'] = &$tabs['gotoTerminal']; + $tabs['FAKE_OC_WorkstationTemplate'] = &$tabs['gotoTerminal']; + $tabs['goServer__IS_BUSY'] = &$tabs['goServer']; + $tabs['goServer__IS_ERROR'] = &$tabs['goServer']; + $tabs['goServer__IS_LOCKED'] = &$tabs['goServer']; + + $tabs['FAKE_OC_ArpNewDevice'] = &$tabs['FAKE_OC_NewDevice']; + + return($tabs); } - $display = $headpage->render(); - return($this->getHeader().$display); - } - - - public function getObjectDefinitions() - { - $tabs = array( - "FAKE_OC_OpsiHost" => array( - "ou" => "", - "plugClass" => "opsiGeneric", - "tabClass" => "opsi_tabs", - "tabDesc" => "OPSITABS", - "aclClass" => "opsiGeneric", - "sendEvents" => TRUE, - "aclCategory" => "opsi"), - - "goServer" => array( - "ou" => get_ou("servgeneric", "serverRDN"), - "plugClass" => "servgeneric", - "tabClass" => "servtabs", - "tabDesc" => "SERVTABS", - "aclClass" => "servgeneric", - "sendEvents" => TRUE, - "aclCategory" => "server"), - - "gotoWorkstation" => array( - "ou" => get_ou("workgeneric", "workstationRDN"), - "plugClass" => "workgeneric", - "tabClass" => "worktabs", - "tabDesc" => "WORKTABS", - "aclClass" => "workgeneric", - "sendEvents" => TRUE, - "aclCategory" => "workstation"), - - "gotoTerminal" => array( - "ou" => get_ou("termgeneric", "terminalRDN"), - "plugClass" => "termgeneric", - "tabClass" => "termtabs", - "sendEvents" => TRUE, - "tabDesc" => "TERMTABS", - "aclClass" => "termgeneric", - "aclCategory" => "terminal"), - - "gotoPrinter" => array( - "ou" => get_ou("printgeneric", "printerRDN"), - "plugClass" => "printgeneric", - "tabClass" => "printtabs", - "tabDesc" => "PRINTTABS", - "aclClass" => "printgeneric", - "sendEvents" => FALSE, - "aclCategory" => "printer"), - - "FAKE_OC_NewDevice" => array( - "ou" => get_ou("ArpNewDevice", "systemIncomingRDN"), - "plugClass" => "termgeneric", - "tabClass" => "termtabs", - "sendEvents" => TRUE, - "tabDesc" => "TERMTABS", - "aclClass" => "termgeneric", - "aclCategory" => "terminal"), - - "goFonHardware" => array( - "ou" => get_ou("phoneGeneric", "phoneRDN"), - "plugClass" => "phoneGeneric", - "tabClass" => "phonetabs", - "tabDesc" => "PHONETABS", - "sendEvents" => FALSE, - "aclClass" => "phoneGeneric", - "aclCategory" => "phone"), - - "FAKE_OC_winstation" => array( - "ou" => get_winstations_ou(), - "plugClass" => "wingeneric", - "sendEvents" => TRUE, - "tabClass" => "wintabs", - "tabDesc" => "WINTABS", - "aclClass" => "wingeneric", - "aclCategory" => "winworkstation"), - - "ieee802Device" => array( - "ou" => get_ou("componentGeneric", "componentRDN"), - "plugClass" => "componentGeneric", - "sendEvents" => FALSE, - "tabClass" => "componenttabs", - "tabDesc" => "COMPONENTTABS", - "aclClass" => "componentGeneric", - "aclCategory" => "component"), - ); - - // Now map some special types - $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation']; - $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal']; - $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation']; - $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation']; - $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation']; - $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation']; - $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal']; - $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal']; - $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal']; - $tabs['FAKE_OC_TerminalTemplate'] = &$tabs['gotoTerminal']; - $tabs['FAKE_OC_WorkstationTemplate'] = &$tabs['gotoTerminal']; - $tabs['goServer__IS_BUSY'] = &$tabs['goServer']; - $tabs['goServer__IS_ERROR'] = &$tabs['goServer']; - $tabs['goServer__IS_LOCKED'] = &$tabs['goServer']; - - $tabs['FAKE_OC_ArpNewDevice'] = &$tabs['FAKE_OC_NewDevice']; - - return($tabs); - } - - - static function filterSystemDescription($row,$dn,$pid,$state,$description=array()) - { - $dn= LDAP::fix(func_get_arg(1)); - $desc = isset($description[0])?$description[0]:" "; - $rc = ""; - switch($state){ - case 'locked' : $rc = ""; break; - case 'error' : $rc = ""; break; - case 'busy' : $rc = ""; break; - case 'warning' : $rc = ""; break; - } - return("{$desc}{$rc}"); - } - - static function systemRelease($a,$b,$c,$objectclasses= null,$class= null) - { - global $config; - - // No objectclasses set - go ahead - if(!$objectclasses) return(" "); - - // Skip non fai objects - if (!in_array_ics("FAIobject", $objectclasses)) { - return " "; + + static function filterSystemDescription($row,$dn,$pid,$state,$description=array()) + { + $dn= LDAP::fix(func_get_arg(1)); + $desc = isset($description[0])?$description[0]:" "; + $rc = ""; + switch($state){ + case 'locked' : $rc = ""; break; + case 'error' : $rc = ""; break; + case 'busy' : $rc = ""; break; + case 'warning' : $rc = ""; break; + } + return("".set_post($desc)."{$rc}"); } - // If we've an own fai class, just use this - if ($class && is_array($class)) { - foreach (explode(' ', $class[0]) as $element) { - if ($element[0] == ":") { - return " ".image('images/empty.png')." ".mb_substr($element, 1); + static function systemRelease($a,$b,$c,$objectclasses= null,$class= null) + { + global $config; + + // No objectclasses set - go ahead + if(!$objectclasses) return(" "); + + // Skip non fai objects + if (!in_array_ics("FAIobject", $objectclasses)) { + return " "; + } + + // If we've an own fai class, just use this + if ($class && is_array($class)) { + foreach (explode(' ', $class[0]) as $element) { + if ($element[0] == ":") { + return " ".image('images/empty.png')." ".mb_substr($element, 1); + } + } + } + + // Load information if needed + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $ldap->search("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=".$b."))",array('FAIclass','cn')); + while($attrs = $ldap->fetch()){ + $rel = preg_replace("/^.*:/","",$attrs['FAIclass'][0]); + $sys = sprintf(_("Inherited from %s"),$attrs['cn'][0]); + $str = " ".image('plugins/ogroups/images/ogroup.png', "", $sys)." ".$rel; + return($str); } - } + + return(" "); } - // Load information if needed - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - $ldap->search("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=".$b."))",array('FAIclass','cn')); - while($attrs = $ldap->fetch()){ - $rel = preg_replace("/^.*:/","",$attrs['FAIclass'][0]); - $sys = sprintf(_("Inherited from %s"),$attrs['cn'][0]); - $str = " ".image('plugins/ogroups/images/ogroup.png', "", $sys)." ".$rel; - return($str); + + /*! \brief !! Incoming dummy acls, required to defined acls for incoming objects + */ + static function plInfo() + { + return (array( + "plShortName" => _("Incoming objects"), + "plDescription" => _("Incoming objects"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 99, + "plSection" => array("administration"), + + "plProperties" => + array( + array( + "name" => "systemRDN", + "type" => "rdn", + "default" => "ou=systems,", + "description" => _("The 'systemRDN' statement defines the location where new systems will be created. The default is 'ou=systems,'."), + "check" => "gosaProperty::isRdn", + "migrate" => "migrate_systemRDN", + "group" => "plugin", + "mandatory" => FALSE + ) + ), + + + "plCategory" => array("incoming" => array( "description" => _("Incoming"))), + "plProvidedAcls"=> array() + )); } - - return(" "); - } - - - /*! \brief !! Incoming dummy acls, required to defined acls for incoming objects - */ - static function plInfo() - { - return (array( - "plShortName" => _("Incoming objects"), - "plDescription" => _("Incoming objects"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 99, - "plSection" => array("administration"), - - "plProperties" => - array( - array( - "name" => "systemRDN", - "type" => "rdn", - "default" => "ou=systems,", - "description" => _("The 'systemRDN' statement defines the location where new systems will be created. The default is 'ou=systems,'."), - "check" => "gosaProperty::isRdn", - "migrate" => "migrate_systemRDN", - "group" => "plugin", - "mandatory" => FALSE - ) - ), - - - "plCategory" => array("incoming" => array( "description" => _("Incoming"))), - "plProvidedAcls"=> array() - )); - } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/gosa-plugins/systems/admin/systems/class_termDNS.inc b/gosa-plugins/systems/admin/systems/class_termDNS.inc index 9c1fc70cc..31d166893 100644 --- a/gosa-plugins/systems/admin/systems/class_termDNS.inc +++ b/gosa-plugins/systems/admin/systems/class_termDNS.inc @@ -22,1218 +22,1218 @@ class termDNS extends plugin { - /* attribute list for save action */ - var $ignore_account = true; - - /* Basic informations - */ - var $attributes = array("ipHostNumber","macAddress"); - var $objectclasses = array("whatever"); - - var $ipHostNumber = ""; // IP address - var $additionalHostNumbers = array(); - var $macAddress = ""; // Mac address - - // Used in manufacturer detection - var $last_macAddress = ""; - var $manufacturer = ""; - - var $orig_ipHostNumber = ""; // IP address - var $orig_macAddress = ""; // Mac address - - var $cn = ""; // CN of currently edited device - var $OrigCn = ""; // Initial cn - var $IPisMust = false; - var $MACisMust = false; - var $dialog = false; - - /* DCHP Attributes - */ - var $dhcpAttributes = array("dhcpParentNode"); - var $dhcpEnabled = FALSE; - var $dhcp_is_Account = FALSE; - var $dhcpParentNodes = array(); - var $dhcpParentNode = ""; - var $dhcpHostEntry = array(); - var $initial_dhcpParentNode = ""; - var $initial_dhcpHostEntry = array(); - var $initial_dhcp_is_Account = FALSE; - - var $used_ip_mac = array(); - - /* DNS attributes - */ - var $DNSattributes = array("zoneName","dNSTTL"); - var $DNS_is_account = false; - var $initially_was_account = false; - var $dnsEntry = array(); - var $DNSenabled = false; - var $hide_dns_check_box = FALSE; - var $namingAttr = "cn"; - - /* Terminal dns - */ - function termDNS (&$config, $parent,$objectClasses,$IPisMust = false,$namingAttr = "cn") - { - /* We need to know which objectClasses are used, to store the ip/mac - * Because of different type of devices - */ - $this->parent = $parent; - $this->objectclasses = $objectClasses; - $this->IPisMust = $IPisMust; - $this->namingAttr = $namingAttr; - - plugin::plugin ($config, $parent->dn, $this->parent); - - $this->attrs = &$this->parent->attrs; - - if(isset($this->attrs[$namingAttr][0])){ - $this->OrigCn = preg_replace("/\\\$\$/","",$this->attrs[$namingAttr][0]); - $this->cn = preg_replace("/\\\$\$/","",$this->attrs[$namingAttr][0]); - } + /* attribute list for save action */ + var $ignore_account = true; - /* Create list of additional ipHostNumber. + /* Basic informations */ - $this->additionalHostNumbers = array(); - if(isset($this->attrs['ipHostNumber']) && $this->attrs['ipHostNumber']['count'] > 1){ - for($i = 1 ; $i < $this->attrs['ipHostNumber']['count']; $i ++){ - $this->additionalHostNumbers[] = $this->attrs['ipHostNumber'][$i]; - } - } - - /************ - * DHCP - ************/ - - /* Hide all dhcp specific code, if dhcp plugin is not present in config */ - $this->dhcpEnabled = FALSE; - if($this->config->pluginEnabled("servdhcp")){ - $this->dhcpEnabled = TRUE; - } - - if(!class_available("dhcpHost")){ - $this->dhcpEnabled = FALSE; - } + var $attributes = array("ipHostNumber","macAddress"); + var $objectclasses = array("whatever"); - if($this->dhcpEnabled){ - $this->dhcpParentNodes = $this->get_dhcp_parent_nodes(); - $this->dhcpParentNode = $this->get_dhcp_parent_node(); - if($this->dhcpParentNode){ - $this->dhcp_is_Account = TRUE; - $this->initial_dhcp_is_Account = TRUE; - $this->dhcpHostEntry = $this->get_dhcp_host_entry(); - } - $this->initial_dhcpHostEntry = $this->dhcpHostEntry; - $this->initial_dhcpParentNode= $this->dhcpParentNode; - } + var $ipHostNumber = ""; // IP address + var $additionalHostNumbers = array(); + var $macAddress = ""; // Mac address + + // Used in manufacturer detection + var $last_macAddress = ""; + var $manufacturer = ""; + + var $orig_ipHostNumber = ""; // IP address + var $orig_macAddress = ""; // Mac address + var $cn = ""; // CN of currently edited device + var $OrigCn = ""; // Initial cn + var $IPisMust = false; + var $MACisMust = false; + var $dialog = false; - /************ - * DNS - ************/ - - /* Hide all dns specific code, if dns is not available + /* DCHP Attributes */ - $DNSenabled = false; - foreach($this->config->data['TABS']['SERVERSERVICE'] as $tab){ - if(preg_match("/^servdns$/",$tab['CLASS'])){ - $this->DNSenabled = true; - } - } + var $dhcpAttributes = array("dhcpParentNode"); + var $dhcpEnabled = FALSE; + var $dhcp_is_Account = FALSE; + var $dhcpParentNodes = array(); + var $dhcpParentNode = ""; + var $dhcpHostEntry = array(); + var $initial_dhcpParentNode = ""; + var $initial_dhcpHostEntry = array(); + var $initial_dhcp_is_Account = FALSE; + + var $used_ip_mac = array(); + + /* DNS attributes + */ + var $DNSattributes = array("zoneName","dNSTTL"); + var $DNS_is_account = false; + var $initially_was_account = false; + var $dnsEntry = array(); + var $DNSenabled = false; + var $hide_dns_check_box = FALSE; + var $namingAttr = "cn"; + + /* Terminal dns + */ + function termDNS (&$config, $parent,$objectClasses,$IPisMust = false,$namingAttr = "cn") + { + /* We need to know which objectClasses are used, to store the ip/mac + * Because of different type of devices + */ + $this->parent = $parent; + $this->objectclasses = $objectClasses; + $this->IPisMust = $IPisMust; + $this->namingAttr = $namingAttr; + + plugin::plugin ($config, $parent->dn, $this->parent); + + $this->attrs = &$this->parent->attrs; + + if(isset($this->attrs[$namingAttr][0])){ + $this->OrigCn = preg_replace("/\\\$\$/","",$this->attrs[$namingAttr][0]); + $this->cn = preg_replace("/\\\$\$/","",$this->attrs[$namingAttr][0]); + } - if(!class_available("DNS")){ - $this->DNSenabled = FALSE; - } - - if(!$this->DNSenabled){ - $this->DNS_is_account = false; - return; - } + /* Create list of additional ipHostNumber. + */ + $this->additionalHostNumbers = array(); + if(isset($this->attrs['ipHostNumber']) && $this->attrs['ipHostNumber']['count'] > 1){ + for($i = 1 ; $i < $this->attrs['ipHostNumber']['count']; $i ++){ + $this->additionalHostNumbers[] = $this->attrs['ipHostNumber'][$i]; + } + } - if($this->DNSenabled){ + /************ + * DHCP + ************/ - /* Get Zones - */ - $this->Zones = DNS::getAvailableZones($config); + /* Hide all dhcp specific code, if dhcp plugin is not present in config */ + $this->dhcpEnabled = FALSE; + if($this->config->pluginEnabled("servdhcp")){ + $this->dhcpEnabled = TRUE; + } - /* Get Entry - */ - $this->dnsEntry = DNS::getDNSHostEntries($config,$this->OrigCn); + if(!class_available("dhcpHost")){ + $this->dhcpEnabled = FALSE; + } - $ptr = DNS::FlipIp($this->get_pTRRecord()); + if($this->dhcpEnabled){ + $this->dhcpParentNodes = $this->get_dhcp_parent_nodes(); + $this->dhcpParentNode = $this->get_dhcp_parent_node(); + if($this->dhcpParentNode){ + $this->dhcp_is_Account = TRUE; + $this->initial_dhcp_is_Account = TRUE; + $this->dhcpHostEntry = $this->get_dhcp_host_entry(); + } + $this->initial_dhcpHostEntry = $this->dhcpHostEntry; + $this->initial_dhcpParentNode= $this->dhcpParentNode; + } - /* Remove A record which equals $this->ipHostNumber - */ - foreach($this->dnsEntry['RECORDS'] as $key => $rec){ - if(($rec['type'] == "aRecord") && ($rec['value'] == $this->ipHostNumber)){ - unset($this->dnsEntry['RECORDS'][$key]); + + /************ + * DNS + ************/ + + /* Hide all dns specific code, if dns is not available + */ + $DNSenabled = false; + foreach($this->config->data['TABS']['SERVERSERVICE'] as $tab){ + if(preg_match("/^servdns$/",$tab['CLASS'])){ + $this->DNSenabled = true; + } } - if(($rec['type'] == "pTRRecord") && ($rec['value'] == $ptr)){ - unset($this->dnsEntry['RECORDS'][$key]); + + if(!class_available("DNS")){ + $this->DNSenabled = FALSE; } - } - - /* Get Record types - */ - $this->RecordTypes = DNS::getDnsRecordTypes(); - - /* If there is at least one entry in this -> types, we have DNS enabled - */ - if($this->dnsEntry['exists']){ - $this->DNS_is_account = true; - }else{ - $this->DNS_is_account = false; - } - } - /* Create a list of used mac and ip addresses. + if(!$this->DNSenabled){ + $this->DNS_is_account = false; + return; + } - ! We use this optically huge amount of code to fetch all - Mac and IP addresses, because a simple search for mac and IP - over the whole ldap server was 10 to 20 times slower. - */ - $deps = array(); - $ou = preg_replace("/,.*$/","",get_ou("systemManagement", "systemRDN")); - $a_ous = array(get_ou("servgeneric", "serverRDN"), - get_ou("termgeneric", "terminalRDN"), - get_ou("workgeneric", "workstationRDN"), - get_ou("printgeneric", "printerRDN"), - get_ou("phoneGeneric", "phoneRDN"), - get_ou("componentGeneric", "componentRDN")); - - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(objectClass=organizationalUnit)(".$ou."))",array("dn")); - while($attrs = $ldap->fetch()){ - foreach($a_ous as $allowed){ - $deps[] = $allowed.$attrs['dn']; - } - } + if($this->DNSenabled){ + + /* Get Zones + */ + $this->Zones = DNS::getAvailableZones($config); + + /* Get Entry + */ + $this->dnsEntry = DNS::getDNSHostEntries($config,$this->OrigCn); + + $ptr = DNS::FlipIp($this->get_pTRRecord()); + + /* Remove A record which equals $this->ipHostNumber + */ + foreach($this->dnsEntry['RECORDS'] as $key => $rec){ + if(($rec['type'] == "aRecord") && ($rec['value'] == $this->ipHostNumber)){ + unset($this->dnsEntry['RECORDS'][$key]); + } + if(($rec['type'] == "pTRRecord") && ($rec['value'] == $ptr)){ + unset($this->dnsEntry['RECORDS'][$key]); + } + } + + /* Get Record types + */ + $this->RecordTypes = DNS::getDnsRecordTypes(); + + /* If there is at least one entry in this -> types, we have DNS enabled + */ + if($this->dnsEntry['exists']){ + $this->DNS_is_account = true; + }else{ + $this->DNS_is_account = false; + } + } + + /* Create a list of used mac and ip addresses. - foreach($deps as $dep){ - $ldap->cd($dep); - $ldap->search("(|(macAddress=*)(ipHostNumber=*))",array("macAddress","ipHostNumber")); - while($attrs = $ldap->fetch()){ - if(isset($attrs['ipHostNumber'][0])){ - $this->used_ip_mac["ip:".$attrs['ipHostNumber'][0]] = "ip:".$attrs['ipHostNumber'][0]; + ! We use this optically huge amount of code to fetch all + Mac and IP addresses, because a simple search for mac and IP + over the whole ldap server was 10 to 20 times slower. + */ + $deps = array(); + $ou = preg_replace("/,.*$/","",get_ou("systemManagement", "systemRDN")); + $a_ous = array(get_ou("servgeneric", "serverRDN"), + get_ou("termgeneric", "terminalRDN"), + get_ou("workgeneric", "workstationRDN"), + get_ou("printgeneric", "printerRDN"), + get_ou("phoneGeneric", "phoneRDN"), + get_ou("componentGeneric", "componentRDN")); + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=organizationalUnit)(".$ou."))",array("dn")); + while($attrs = $ldap->fetch()){ + foreach($a_ous as $allowed){ + $deps[] = $allowed.$attrs['dn']; + } } - if(isset($attrs['macAddress'][0])){ - $this->used_ip_mac["mac:".$attrs['macAddress'][0]] = "mac:".$attrs['macAddress'][0]; + + foreach($deps as $dep){ + $ldap->cd($dep); + $ldap->search("(|(macAddress=*)(ipHostNumber=*))",array("macAddress","ipHostNumber")); + while($attrs = $ldap->fetch()){ + if(isset($attrs['ipHostNumber'][0])){ + $this->used_ip_mac["ip:".$attrs['ipHostNumber'][0]] = "ip:".$attrs['ipHostNumber'][0]; + } + if(isset($attrs['macAddress'][0])){ + $this->used_ip_mac["mac:".$attrs['macAddress'][0]] = "mac:".$attrs['macAddress'][0]; + } + } } - } - } - /* Save initial ip and mac values, to be able - check if the used values are already in use */ - $this->orig_ipHostNumber = $this->ipHostNumber; - $this->orig_macAddress = $this->macAddress; - - /* Store initally account settings - */ - $this->initially_was_account = $this->DNS_is_account; + /* Save initial ip and mac values, to be able + check if the used values are already in use */ + $this->orig_ipHostNumber = $this->ipHostNumber; + $this->orig_macAddress = $this->macAddress; + + /* Store initally account settings + */ + $this->initially_was_account = $this->DNS_is_account; - if($this->DNS_is_account){ - new log("view","unknown/".get_class($this),$this->dn); + if($this->DNS_is_account){ + new log("view","unknown/".get_class($this),$this->dn); + } } - } - function netmaskIsCoherent($idZone) - { - $netmask = DNS::FlipIp(str_replace(".in-addr.arpa.","",DNS::getNameFromMix($idZone))); - if(!strstr($this->ipHostNumber, $netmask)){ - return false; - }else{ - return true; + function netmaskIsCoherent($idZone) + { + $netmask = DNS::FlipIp(str_replace(".in-addr.arpa.","",DNS::getNameFromMix($idZone))); + if(!strstr($this->ipHostNumber, $netmask)){ + return false; + }else{ + return true; + } } - } - function getVarsForSaving($attrs) - { - foreach($this->attributes as $attr){ - if(!empty($this->$attr)){ - $attrs[$attr] = $this->$attr; - } + function getVarsForSaving($attrs) + { + foreach($this->attributes as $attr){ + if(!empty($this->$attr)){ + $attrs[$attr] = $this->$attr; + } + } + return($attrs); } - return($attrs); - } - function execute() - { - plugin::execute(); + function execute() + { + plugin::execute(); - /* Call parent execute */ - $smarty= get_smarty(); - $smarty->assign("autonetACL",$this->acl_is_writeable("macAddress") && $this->acl_is_writeable("ipHostNumber")?"rw":""); + /* Call parent execute */ + $smarty= get_smarty(); + $smarty->assign("autonetACL",$this->acl_is_writeable("macAddress") && $this->acl_is_writeable("ipHostNumber")?"rw":""); - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL",$this->getacl($name)); - } + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } - $display= ""; - - /********** - * Additional ipHostNumber handling - **********/ - - /* Add a new one */ - if($this->acl_is_writeable("ipHostNumber")){ - foreach($_POST as $name => $value){ - if(preg_match("/^additionalHostNumbers_add/",$name)){ - $this->additionalHostNumbers[] = ""; - break; + $display= ""; + + /********** + * Additional ipHostNumber handling + **********/ + + /* Add a new one */ + if($this->acl_is_writeable("ipHostNumber")){ + foreach($_POST as $name => $value){ + if(preg_match("/^additionalHostNumbers_add/",$name)){ + $this->additionalHostNumbers[] = ""; + break; + } + + /* Delete given entry */ + if(preg_match("/^additionalHostNumbers_del_/",$name)){ + $id = preg_replace("/^^additionalHostNumbers_del_([0-9]*)$/","\\1",$name); + if(isset($this->additionalHostNumbers[$id])){ + unset($this->additionalHostNumbers[$id]); + $this->additionalHostNumbers = array_values($this->additionalHostNumbers); + } + break; + } + } } - /* Delete given entry */ - if(preg_match("/^additionalHostNumbers_del_/",$name)){ - $id = preg_replace("/^^additionalHostNumbers_del_([0-9]*)$/","\\1",$name); - if(isset($this->additionalHostNumbers[$id])){ - unset($this->additionalHostNumbers[$id]); - $this->additionalHostNumbers = array_values($this->additionalHostNumbers); - } - break; - } - } - } - - $smarty->assign("additionalHostNumbers",$this->additionalHostNumbers); - - /********** - * Autonet completion - **********/ - - /* Check for autonet button */ - if (isset($_POST['autonet']) && ($this->acl_is_writeable("ipHostNumber") || $this->acl_is_writeable("macAddress"))){ - - if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){ - $rpc = $this->config->getRpcHandle(); - $res = $rpc->networkCompletion($this->cn); - if(isset($res['ip']) && tests::is_ip($res['ip'])) $this->ipHostNumber= $res['ip']; - if(isset($res['mac']) && tests::is_mac($res['mac'])) $this->macAddress= $res['mac']; + $smarty->assign("additionalHostNumbers",$this->additionalHostNumbers); - }elseif ($config->get_cfg_value("core","gosaSupportURI") != ""){ + /********** + * Autonet completion + **********/ - $d= new gosaSupportDaemon(TRUE, 0.5); - $res= $d->_send("
gosa_network_completition
". - "GOSAGOSA".$this->cn."
", TRUE); - if (isset($res['XML']['IP']) && $this->acl_is_writeable("ipHostNumber")){ - $this->ipHostNumber= $res['XML']['IP']; - } - if (isset($res['XML']['MAC']) && $this->acl_is_writeable("macAddress")){ - $this->macAddress= $res['XML']['MAC']; + /* Check for autonet button */ + if (isset($_POST['autonet']) && ($this->acl_is_writeable("ipHostNumber") || $this->acl_is_writeable("macAddress"))){ + + if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){ + $rpc = $this->config->getRpcHandle(); + $res = $rpc->networkCompletion($this->cn); + if(isset($res['ip']) && tests::is_ip($res['ip'])) $this->ipHostNumber= $res['ip']; + if(isset($res['mac']) && tests::is_mac($res['mac'])) $this->macAddress= $res['mac']; + + }elseif ($config->get_cfg_value("core","gosaSupportURI") != ""){ + + $d= new gosaSupportDaemon(TRUE, 0.5); + $res= $d->_send("
gosa_network_completition
". + "GOSAGOSA".$this->cn."
", TRUE); + if (isset($res['XML']['IP']) && $this->acl_is_writeable("ipHostNumber")){ + $this->ipHostNumber= $res['XML']['IP']; + } + if (isset($res['XML']['MAC']) && $this->acl_is_writeable("macAddress")){ + $this->macAddress= $res['XML']['MAC']; + } } } - } - - /********** - * DHCP Handling - **********/ - - if(isset($_POST['dhcpEditOptions']) && $this->acl_is_readable("dhcpSetup")){ - if(count($this->dhcpHostEntry) == 0){ - $this->dialog = new dhcpHost($this->parent,$this->dhcpParentNode,TRUE); - }else{ - $this->dialog = new dhcpHost($this->parent,$this->dhcpHostEntry,TRUE); - } - $this->dialog->cn = $this->cn; - $this->dialog->read_only = !$this->acl_is_writeable("dhcpSetup"); - $this->dialog->dhcpHWAddress = "ethernet ".$this->macAddress; - if(!empty($this->ipHostNumber)){ - $this->dialog->statements->set('fixed-address', $this->ipHostNumber); - } - } - if(isset($_POST['cancel_dhcp'])){ - $this->dialog = FALSE; - } + /********** + * DHCP Handling + **********/ - if(isset($_POST['save_dhcp']) && $this->acl_is_writeable("dhcpSetup") && is_object($this->dialog)){ - $this->dialog->save_object(); - $msgs = $this->dialog->check(array()); - if(count($msgs)){ - foreach($msgs as $msg){ - msg_dialog::display(_("Error"), $msg, ERROR_DIALOG); + if(isset($_POST['dhcpEditOptions']) && $this->acl_is_readable("dhcpSetup")){ + if(count($this->dhcpHostEntry) == 0){ + $this->dialog = new dhcpHost($this->parent,$this->dhcpParentNode,TRUE); + }else{ + $this->dialog = new dhcpHost($this->parent,$this->dhcpHostEntry,TRUE); + } + $this->dialog->cn = $this->cn; + $this->dialog->read_only = !$this->acl_is_writeable("dhcpSetup"); + $this->dialog->dhcpHWAddress = "ethernet ".$this->macAddress; + if(!empty($this->ipHostNumber)){ + $this->dialog->statements->set('fixed-address', $this->ipHostNumber); + } } - }else{ - $this->dhcpHostEntry = $this->dialog->save(); - $this->dialog = FALSE; - } - } - if(is_object($this->dialog)){ - $this->dialog->save_object(); - return($this->dialog->execute()); - } - - $smarty->assign("dhcpEnabled", $this->dhcpEnabled && $this->acl_is_readable("dhcpSetup")); - $smarty->assign("dhcp_is_Account",$this->dhcp_is_Account); - $smarty->assign("dhcpParentNode", $this->dhcpParentNode); - $smarty->assign("dhcpParentNodes",$this->dhcpParentNodes); - $smarty->assign("dhcpParentNodeCnt",count($this->dhcpParentNodes)); - - // Assign network card manufacturer string - if ($this->config->get_cfg_value("core","gosaRpcServer") != "" && - $this->macAddress != $this->last_macAddress){ - $rpc = $this->config->getRpcHandle(); - $res = $rpc->getMacManufacturer($this->macAddress); - if($rpc->success()){ - $this->manufacturer = $rpc->getMacManufacturer($this->macAddress); + if(isset($_POST['cancel_dhcp'])){ + $this->dialog = FALSE; } - } - $smarty->assign("macManufacturer", $this->manufacturer); - /********** - * DNS Handling - **********/ + if(isset($_POST['save_dhcp']) && $this->acl_is_writeable("dhcpSetup") && is_object($this->dialog)){ + $this->dialog->save_object(); + $msgs = $this->dialog->check(array()); + if(count($msgs)){ + foreach($msgs as $msg){ + msg_dialog::display(_("Error"), $msg, ERROR_DIALOG); + } + }else{ + $this->dhcpHostEntry = $this->dialog->save(); + $this->dialog = FALSE; + } + } - /* There is no dns available - */ - $smarty->assign("DNS_is_account",$this->DNS_is_account); - $smarty->assign("DNSenabled",$this->DNSenabled && $this->acl_is_readable("dnsSetup")); + if(is_object($this->dialog)){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } - if($this->DNSenabled == false){ + $smarty->assign("dhcpEnabled", $this->dhcpEnabled && $this->acl_is_readable("dhcpSetup")); + $smarty->assign("dhcp_is_Account",$this->dhcp_is_Account); + $smarty->assign("dhcpParentNode", $this->dhcpParentNode); + $smarty->assign("dhcpParentNodes",$this->dhcpParentNodes); + $smarty->assign("dhcpParentNodeCnt",count($this->dhcpParentNodes)); - /* Is IP address must ? */ -# $smarty->assign("DNS_is_account",false); - $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account))); - - /* Assign smarty all non DNs attributes */ - foreach($this->attributes as $attr){ - $smarty->assign($attr,$this->$attr); - } - - $display.= $smarty->fetch(get_template_path('network.tpl', TRUE)); - }else{ - # $smarty->assign("DNS_is_account",true); - - /* Add new empty array to our record list */ - if(isset($_POST['AddNewRecord']) && $this->acl_is_writeable("dnsSetup")){ - $this->dnsEntry['RECORDS'][] =array("type"=>"aRecord","value"=>""); - } - - /* propose_ip */ - if(isset($_POST['propose_ip']) && $this->acl_is_writeable("ipHostNumber")){ - foreach($this->Zones as $key => $name){ - if($name == $this->dnsEntry['zoneName']){ - $net = DNS::FlipIp(str_replace(".in-addr.arpa.","",DNS::getNameFromMix($key))); - $this->ipHostNumber = $this->generateRandomIP($net); - } + // Assign network card manufacturer string + if ($this->config->get_cfg_value("core","gosaRpcServer") != "" && + $this->macAddress != $this->last_macAddress){ + $rpc = $this->config->getRpcHandle(); + $res = $rpc->getMacManufacturer($this->macAddress); + if($rpc->success()){ + $this->manufacturer = $rpc->getMacManufacturer($this->macAddress); + } } - } + $smarty->assign("macManufacturer", set_post($this->manufacturer)); - /* Handle all posts */ - $only_once =true; - if($this->acl_is_writeable("dnsSetup")){ - foreach($_POST as $name => $value){ + /********** + * DNS Handling + **********/ - /* Check if we have to delete a record entry */ - if((preg_match("/RemoveRecord_/",$name))&&($only_once)) { + /* There is no dns available + */ + $smarty->assign("DNS_is_account",$this->DNS_is_account); + $smarty->assign("DNSenabled",$this->DNSenabled && $this->acl_is_readable("dnsSetup")); - /* Avoid performing this once again */ - $only_once = false; + if($this->DNSenabled == false){ - /* Extract id for specified entry */ - $id = preg_replace("/RemoveRecord_/","",$name); - $id = preg_replace("/_.*$/","",$id); + /* Is IP address must ? */ +# $smarty->assign("DNS_is_account",false); + $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account))); - /* Delete this record, mark edited entries to be able to delete them */ - if(isset($this->dnsEntry['RECORDS'][$id])){ - unset($this->dnsEntry['RECORDS'][$id]); + /* Assign smarty all non DNs attributes */ + foreach($this->attributes as $attr){ + $smarty->assign($attr,set_post($this->$attr)); } - } - } - } - /* Assign smarty all non DNs attributes */ - foreach($this->attributes as $attr){ - $smarty->assign($attr,$this->$attr); - } - - /* Assign smarty all DNS attributes */ - foreach($this->DNSattributes as $attr){ - $smarty->assign($attr,htmlentities($this->dnsEntry[$attr])); - } - - /* Assign all needed vars */ - # $smarty->assign("DNSAccount",$this->DNS_is_account); - $smarty->assign("hide_dns_check_box",$this->hide_dns_check_box); - - $smarty->assign("Zones",$this->Zones); - $smarty->assign("ZoneCnt",count($this->Zones)); - $smarty->assign("ZoneKeys",($this->Zones)); - $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account))); - - /* Create zone array */ - $idZones = array(); - foreach($this->Zones as $id => $zone){ - if($this->netmaskIsCoherent($id)) { - $idZones[$id] = $zone; + + $display.= $smarty->fetch(get_template_path('network.tpl', TRUE)); }else{ - $idZones[$id] = $zone." ("._("Not matching").")"; - } - } - $smarty->assign("Zones",$idZones); - $smarty->assign("ZoneKeys", $this->Zones); +# $smarty->assign("DNS_is_account",true); + + /* Add new empty array to our record list */ + if(isset($_POST['AddNewRecord']) && $this->acl_is_writeable("dnsSetup")){ + $this->dnsEntry['RECORDS'][] =array("type"=>"aRecord","value"=>""); + } + + /* propose_ip */ + if(isset($_POST['propose_ip']) && $this->acl_is_writeable("ipHostNumber")){ + foreach($this->Zones as $key => $name){ + if($name == $this->dnsEntry['zoneName']){ + $net = DNS::FlipIp(str_replace(".in-addr.arpa.","",DNS::getNameFromMix($key))); + $this->ipHostNumber = $this->generateRandomIP($net); + } + } + } + + /* Handle all posts */ + $only_once =true; + if($this->acl_is_writeable("dnsSetup")){ + foreach($_POST as $name => $value){ - $tmp = $this->generateRecordsList(); + /* Check if we have to delete a record entry */ + if((preg_match("/RemoveRecord_/",$name))&&($only_once)) { - $changeStateForRecords = $tmp['changeStateForRecords']; + /* Avoid performing this once again */ + $only_once = false; - $smarty->assign("records",$tmp['str']); - $smarty->assign("changeStateForRecords",$changeStateForRecords); + /* Extract id for specified entry */ + $id = preg_replace("/RemoveRecord_/","",$name); + $id = preg_replace("/_.*$/","",$id); - $smarty->assign("autonetACL",$this->acl_is_writeable("macAddress") && $this->acl_is_writeable("ipHostNumber")?"rw":""); - $display.= $smarty->fetch(get_template_path('network.tpl', TRUE)); + /* Delete this record, mark edited entries to be able to delete them */ + if(isset($this->dnsEntry['RECORDS'][$id])){ + unset($this->dnsEntry['RECORDS'][$id]); + } + } + } + } + /* Assign smarty all non DNs attributes */ + foreach($this->attributes as $attr){ + $smarty->assign($attr,set_post($this->$attr)); + } + + /* Assign smarty all DNS attributes */ + foreach($this->DNSattributes as $attr){ + $smarty->assign($attr,set_post($this->dnsEntry[$attr])); + } + + /* Assign all needed vars */ +# $smarty->assign("DNSAccount",$this->DNS_is_account); + $smarty->assign("hide_dns_check_box",$this->hide_dns_check_box); + + $smarty->assign("Zones",$this->Zones); + $smarty->assign("ZoneCnt",count($this->Zones)); + $smarty->assign("ZoneKeys",($this->Zones)); + $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account))); + + /* Create zone array */ + $idZones = array(); + foreach($this->Zones as $id => $zone){ + if($this->netmaskIsCoherent($id)) { + $idZones[$id] = $zone; + }else{ + $idZones[$id] = $zone." ("._("Not matching").")"; + } + } + $smarty->assign("Zones",$idZones); + $smarty->assign("ZoneKeys", $this->Zones); + + $tmp = $this->generateRecordsList(); + + $changeStateForRecords = $tmp['changeStateForRecords']; + + $smarty->assign("records",$tmp['str']); + $smarty->assign("changeStateForRecords",$changeStateForRecords); + + $smarty->assign("autonetACL",$this->acl_is_writeable("macAddress") && $this->acl_is_writeable("ipHostNumber")?"rw":""); + $display.= $smarty->fetch(get_template_path('network.tpl', TRUE)); + } + + return($display); } - return($display); - } + function remove_from_parent() + { + if($this->DNS_is_account){ - function remove_from_parent() - { - if($this->DNS_is_account){ + $ldap = $this->config->get_ldap_link(); - $ldap = $this->config->get_ldap_link(); + $tmp = array(); + $this->dnsEntry['exists'] = false; + $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn); - $tmp = array(); - $this->dnsEntry['exists'] = false; - $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn); - - /* Delete dns */ - foreach($tmp['del'] as $dn => $del){ - $ldap->cd($dn); - $ldap->rmdir_recursive($dn); - new log("remove","unknown/".get_class($this),$dn); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class())); + /* Delete dns */ + foreach($tmp['del'] as $dn => $del){ + $ldap->cd($dn); + $ldap->rmdir_recursive($dn); + new log("remove","unknown/".get_class($this),$dn); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class())); + } + } } - } } - } - /* Save data to object */ - function save_object() - { + /* Save data to object */ + function save_object() + { - if(isset($_POST['network_tpl_posted'])){ + if(isset($_POST['network_tpl_posted'])){ - $this->last_macAddress = $this->macAddress; + $this->last_macAddress = $this->macAddress; - /* Save all posted vars */ - plugin::save_object(); + /* Save all posted vars */ + plugin::save_object(); - /****** - Additional IP Host Numbers - ******/ + /****** + Additional IP Host Numbers + ******/ - /* Get posts for all additionally added ipHostNumbers */ - if($this->acl_is_writeable("ipHostNumber")){ - foreach($this->additionalHostNumbers as $id => $value){ - if(isset($_POST['additionalHostNumbers_'.$id])){ - $this->additionalHostNumbers[$id] = get_post('additionalHostNumbers_'.$id); - } - } - } - - - /****** - DHCP posts - ******/ - - if($this->acl_is_writeable("dhcpSetup") && $this->dhcpEnabled && isset($_POST['network_tpl_posted'])){ - foreach($this->dhcpAttributes as $attr){ - if(isset($_POST[$attr])){ - $this->$attr = $_POST[$attr]; - } - } - if(isset($_POST['dhcp_is_Account'])){ - $this->dhcp_is_Account = TRUE; - }else{ - $this->dhcp_is_Account = FALSE; - } - } + /* Get posts for all additionally added ipHostNumbers */ + if($this->acl_is_writeable("ipHostNumber")){ + foreach($this->additionalHostNumbers as $id => $value){ + if(isset($_POST['additionalHostNumbers_'.$id])){ + $this->additionalHostNumbers[$id] = get_post('additionalHostNumbers_'.$id); + } + } + } - /* Ge all non dns attributes (IP/MAC)*/ - foreach($this->attributes as $attr){ - if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){ - $this->$attr = $_POST[$attr]; - } - } + /****** + DHCP posts + ******/ - /****** - DNS posts - ******/ + if($this->acl_is_writeable("dhcpSetup") && $this->dhcpEnabled && isset($_POST['network_tpl_posted'])){ + foreach($this->dhcpAttributes as $attr){ + if(isset($_POST[$attr])){ + $this->$attr = get_post($attr); + } + } + if(isset($_POST['dhcp_is_Account'])){ + $this->dhcp_is_Account = TRUE; + }else{ + $this->dhcp_is_Account = FALSE; + } + } + + /* Ge all non dns attributes (IP/MAC)*/ + foreach($this->attributes as $attr){ + if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){ + $this->$attr = get_post($attr); + } + } + + + /****** + DNS posts + ******/ + + /* Check if DNS should be enabled / disabled + * -skip this, if the dns account is enforced. + */ + if(!$this->hide_dns_check_box){ + if($this->DNS_is_account && $this->acl_is_writeable("dnsSetup") && !isset($_POST['DNS_is_account'])){ + $this->DNS_is_account = false; + }elseif(!$this->DNS_is_account && $this->acl_is_writeable("dnsSetup") && isset($_POST['DNS_is_account'])){ + $this->DNS_is_account = true; + } + } - /* Check if DNS should be enabled / disabled - * -skip this, if the dns account is enforced. - */ - if(!$this->hide_dns_check_box){ - if($this->DNS_is_account && $this->acl_is_writeable("dnsSetup") && !isset($_POST['DNS_is_account'])){ - $this->DNS_is_account = false; - }elseif(!$this->DNS_is_account && $this->acl_is_writeable("dnsSetup") && isset($_POST['DNS_is_account'])){ - $this->DNS_is_account = true; + /* Get dns attributes */ + if(($this->DNSenabled) && (isset($_POST['network_tpl_posted'])) && $this->acl_is_writeable("dnsSetup")){ + + /* Check for posted record changes */ + if(is_array($this->dnsEntry['RECORDS'])){ + foreach($this->dnsEntry['RECORDS'] as $key => $value){ + + /* Check if type has changed */ + if(isset($_POST['RecordTypeSelectedFor_'.$key])){ + $this->dnsEntry['RECORDS'][$key]['type'] = get_post('RecordTypeSelectedFor_'.$key); + } + /* Check if value has changed */ + if(isset($_POST['RecordValue_'.$key])){ + $this->dnsEntry['RECORDS'][$key]['value'] = get_post('RecordValue_'.$key); + } + } + } + + /* Get all basic DNS attributes (TTL, Clas ..)*/ + foreach($this->DNSattributes as $attr){ + if(isset($_POST[$attr])){ + $this->dnsEntry[$attr] = get_post($attr); + } + } + } + if($this->hide_dns_check_box){ + $this->DNS_is_account = true; + } } - } + } - /* Get dns attributes */ - if(($this->DNSenabled) && (isset($_POST['network_tpl_posted'])) && $this->acl_is_writeable("dnsSetup")){ - /* Check for posted record changes */ - if(is_array($this->dnsEntry['RECORDS'])){ - foreach($this->dnsEntry['RECORDS'] as $key => $value){ + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); - /* Check if type has changed */ - if(isset($_POST['RecordTypeSelectedFor_'.$key])){ - $this->dnsEntry['RECORDS'][$key]['type'] = $_POST['RecordTypeSelectedFor_'.$key]; + /****** + check additional IP Host Numbers + ******/ + + foreach($this->additionalHostNumbers as $id => $value){ + if(!tests::is_ip($value)){ + $message[]= msgPool::invalid(sprintf(_("IP address %s"),($id +2)), "", "", "192.168.1.10"); } - /* Check if value has changed */ - if(isset($_POST['RecordValue_'.$key])){ - $this->dnsEntry['RECORDS'][$key]['value'] = get_post('RecordValue_'.$key); + } + + + /* Check if mac and ip are already used */ + if(!empty($this->ipHostNumber) && $this->DNS_is_account && + $this->ipHostNumber != $this->orig_ipHostNumber && + in_array("ip:".$this->ipHostNumber,$this->used_ip_mac)){ + $message[]= msgPool::duplicated(_("IP address")); + } + if(!empty($this->macAddress) && $this->dhcp_is_Account && + $this->macAddress != $this->orig_macAddress && + in_array("mac:".$this->macAddress,$this->used_ip_mac)){ + $message[]= msgPool::duplicated(_("MAC address")); + } + + /* Check if ip must be given + */ + if(($this->IPisMust)||($this->DNS_is_account)){ + if (empty($this->ipHostNumber)){ + $message[]= msgPool::required(_("IP address")); + }elseif (!tests::is_ip($this->ipHostNumber)){ + $message[]= msgPool::invalid(_("IP address"), "", "", "192.168.1.10"); } - } } - /* Get all basic DNS attributes (TTL, Clas ..)*/ - foreach($this->DNSattributes as $attr){ - if(isset($_POST[$attr])){ - $this->dnsEntry[$attr] = get_post($attr); - } + /* Check if mac is empty + */ + if($this->MACisMust || $this->dhcp_is_Account){ + if ($this->macAddress == "" ){ + $message[]= msgPool::required(_("MAC address")); + }elseif(!tests::is_mac($this->macAddress)){ + $message[]= msgPool::invalid(_("MAC address"), "", "", "00:0C:7F:31:33:F1"); + } } - } - if($this->hide_dns_check_box){ - $this->DNS_is_account = true; - } - } - } + /* only perfrom this checks if this is a valid DNS account */ + if($this->DNS_is_account){ - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); + $checkArray = array(); + $onlyOnce = array(); - /****** - check additional IP Host Numbers - ******/ + // $onlyOnce['cNAMERecord'] = 0; + $tmp = array_flip($this->Zones); + $tmp2 = $tmp[$this->dnsEntry['zoneName']]; + if(!$this->netmaskIsCoherent($tmp2)){ //this->dnsEntry['zoneName'])){ + $tmp2 = preg_replace("/^.*\//","",$tmp2); + $message[] =sprintf(_("The IP address '%s' is not part of the selected reverse zone '%s'!"),$this->ipHostNumber,$tmp2); + } - foreach($this->additionalHostNumbers as $id => $value){ - if(!tests::is_ip($value)){ - $message[]= msgPool::invalid(sprintf(_("IP address %s"),($id +2)), "", "", "192.168.1.10"); - } - } + /* Walk through all entries and detect duplicates or mismatches + */ + foreach($this->dnsEntry['RECORDS'] as $name => $values){ + + /* Count record values, to detect duplicate entries for a specific record + */ + if(!isset($checkArray[$values['type']][$values['value']])){ + $checkArray[$values['type']][$values['value']] = 0; + }else{ + $message[] = sprintf(_("Record type '%s' is duplicated!"),$values['type']); + } + + /* Check if given entries in $onlyOnce are used more than once + */ + if(isset($onlyOnce[$values['type']])){ + $onlyOnce[$values['type']] ++; + if($onlyOnce[$values['type']] > 1){ + $message[] = sprintf(_("Uniq record type '%s' is duplicated!"),$values['type']); + } + } + + /* Skip txt record ... + */ + if($values['type'] == "tXTRecord") continue; + + /* Check if there is an aRecord defined which uses the same IP as used in IPhostAddress + */ + if(($values['type'] == "aRecord")&&($values['value'] == $this->ipHostNumber)){ +#TODO: Where's the problem here? + $message[]=sprintf(_("The IP address '%s' will be added as 'A Record', this will be done automatically, please remove the record."), + $this->ipHostNumber); + } + + /* only lower-case is allowed in record entries ... + */ + if($values['value'] != strtolower($values['value'])){ +#TODO: What's in values['value']? Something for a propper message? + $message[] = sprintf(_("Only lowercase records are allowed, please check your '%ss'."),$values['type']); + } + } + } + return ($message); + } - /* Check if mac and ip are already used */ - if(!empty($this->ipHostNumber) && $this->DNS_is_account && - $this->ipHostNumber != $this->orig_ipHostNumber && - in_array("ip:".$this->ipHostNumber,$this->used_ip_mac)){ - $message[]= msgPool::duplicated(_("IP address")); - } - if(!empty($this->macAddress) && $this->dhcp_is_Account && - $this->macAddress != $this->orig_macAddress && - in_array("mac:".$this->macAddress,$this->used_ip_mac)){ - $message[]= msgPool::duplicated(_("MAC address")); - } + /* Save to LDAP */ + function save() + { + $ldap= $this->config->get_ldap_link(); - /* Check if ip must be given - */ - if(($this->IPisMust)||($this->DNS_is_account)){ - if (empty($this->ipHostNumber)){ - $message[]= msgPool::required(_("IP address")); - }elseif (!tests::is_ip($this->ipHostNumber)){ - $message[]= msgPool::invalid(_("IP address"), "", "", "192.168.1.10"); - } - } + $dn = $this->parent->dn; - /* Check if mac is empty - */ - if($this->MACisMust || $this->dhcp_is_Account){ - if ($this->macAddress == "" ){ - $message[]= msgPool::required(_("MAC address")); - }elseif(!tests::is_mac($this->macAddress)){ - $message[]= msgPool::invalid(_("MAC address"), "", "", "00:0C:7F:31:33:F1"); - } - } + /*******************/ + /* IP-MAC HANDLING */ + /*******************/ - /* only perfrom this checks if this is a valid DNS account */ - if($this->DNS_is_account){ + /* $dn was posted as parameter */ + $this->dn = $dn; - $checkArray = array(); - $onlyOnce = array(); + /* Save DNS setting & ip/Mac*/ + plugin::save(); - // $onlyOnce['cNAMERecord'] = 0; - $tmp = array_flip($this->Zones); - $tmp2 = $tmp[$this->dnsEntry['zoneName']]; - if(!$this->netmaskIsCoherent($tmp2)){ //this->dnsEntry['zoneName'])){ - $tmp2 = preg_replace("/^.*\//","",$tmp2); - $message[] =sprintf(_("The IP address '%s' is not part of the selected reverse zone '%s'!"),$this->ipHostNumber,$tmp2); - } + /* Add all additional ipHostNumbers now + */ + if(!empty($this->ipHostNumber)){ + $this->attrs['ipHostNumber'] = array($this->ipHostNumber); + } + foreach($this->additionalHostNumbers as $value){ + $this->attrs['ipHostNumber'][] = $value; + } - /* Walk through all entries and detect duplicates or mismatches - */ - foreach($this->dnsEntry['RECORDS'] as $name => $values){ + /* Do not add the objectClass ipHost if no ip address is given */ + if(!isset($this->attrs['ipHostNumber'])){ + $this->attrs['objectClass'] = array_remove_entries(array("ipHost"),$this->attrs['objectClass']); + } - /* Count record values, to detect duplicate entries for a specific record - */ - if(!isset($checkArray[$values['type']][$values['value']])){ - $checkArray[$values['type']][$values['value']] = 0; - }else{ - $message[] = sprintf(_("Record type '%s' is duplicated!"),$values['type']); + /* Write back to ldap */ + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + + /****************/ + /* DHCP HANDLING */ + /****************/ + + /* New entry */ + if($this->dhcpEnabled && $this->acl_is_writeable("dhcpSetup")) { + + if(count($this->dhcpHostEntry) == 0){ + $this->dialog = new dhcpHost($this->parent,$this->dhcpParentNode,TRUE); + $this->dialog->cn = $this->cn; + $this->dialog->dhcpHWAddress = "ethernet ".$this->macAddress; + if(!empty($this->ipHostNumber)){ + $this->dialog->statements->set('fixed-address', $this->ipHostNumber); + } + $this->dialog->execute(); + $this->dialog->save_object(); + $this->dhcpHostEntry = $this->dialog->save(); + if(count($this->dhcpHostEntry['dhcpOption']) == 0){ + $this->dhcpHostEntry['dhcpOption']= array("host-name ".$this->cn); + } + }else{ + + // Updated Host-Name entry + foreach($this->dhcpHostEntry['dhcpOption'] as $key => $entry){ + if(preg_match("/^host-name/", $entry)){ + $this->dhcpHostEntry['dhcpOption'][$key] = "host-name ".$this->cn; + break; + } + } + } + + /* Write mac address to dhcp settings */ + if($this->dhcp_is_Account){ + if(!isset($this->dhcpHostEntry['dhcpHWAddress'][0]) || + !preg_match("/ethernet ".$this->macAddress."/",$this->dhcpHostEntry['dhcpHWAddress'][0])){ + $this->dhcpHostEntry['dhcpHWAddress'] = array("ethernet ".$this->macAddress); + $this->dhcpHostEntry['MODIFIED'] = TRUE; + } + } + + /* Updated IP host number */ + if($this->dhcp_is_Account && $this->dhcpHostEntry['dhcpStatements']){ + foreach($this->dhcpHostEntry['dhcpStatements'] as $id => $value){ + if(preg_match("/^fixed-address/",$value)){ + $this->dhcpHostEntry['dhcpStatements'][$id] = "fixed-address ".$this->ipHostNumber; + $this->dhcpHostEntry['MODIFIED'] = TRUE; + } + } + } + + /* Unset dhcpStatements if this attribute is empty */ + if(isset($this->dhcpHostEntry['dhcpStatements']) && + ($this->dhcpHostEntry['dhcpStatements'] == "" || count($this->dhcpHostEntry['dhcpStatements']) == 0) ){ + unset($this->dhcpHostEntry['dhcpStatements']); + } + + /* DHCP removed */ + if($this->initial_dhcp_is_Account && !$this->dhcp_is_Account){ + $ldap->rmdir_recursive($this->dhcpHostEntry['dn']); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dhcpHostEntry['dn'], LDAP_DEL, get_class())); + } + + $tmp = new servdhcp($this->config,$this->dhcpParentNode); + $tmp->handle_post_events("remove"); + } + + /* DHCP Added */ + if(!$this->initial_dhcp_is_Account && $this->dhcp_is_Account){ + $attrs = $this->dhcpHostEntry; + unset($attrs['MODIFIED']); + unset($attrs['dn']); + $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode); + $res = $ldap->add($attrs); + + $tmp = new servdhcp($this->config,$this->dhcpParentNode); + $tmp->handle_post_events("add"); + + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "cn=".$this->cn.",".$this->dhcpParentNode, LDAP_ADD, get_class())); + } + } + + /* DHCP still activated */ + if($this->initial_dhcp_is_Account && $this->dhcp_is_Account){ + + /* DHCP node changed */ + if(($this->initial_dhcpParentNode != $this->dhcpParentNode) || + ($this->cn != $this->OrigCn)){ + $attrs = $this->dhcpHostEntry; + $attrs[$this->namingAttr] = $this->cn; + unset($attrs['dn']); + unset($attrs['MODIFIED']); + $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode); + $res = $ldap->add($attrs); + + $tmp = new servdhcp($this->config,$this->dhcpParentNode); + $tmp->handle_post_events("modify"); + + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "cn=".$this->cn.",".$this->dhcpParentNode, LDAP_ADD, get_class())); + } + if($res){ + $ldap->rmdir_recursive($this->dhcpHostEntry['dn']); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dhcpHostEntry['dn'], LDAP_DEL, get_class())); + } + } + } + + /* SAME node but modified */ + if(isset($this->dhcpHostEntry['MODIFIED']) && $this->dhcpHostEntry['MODIFIED'] == 1 && + $this->initial_dhcpParentNode == $this->dhcpParentNode){ + $attrs = $this->dhcpHostEntry; + unset($attrs['dn']); + unset($attrs['MODIFIED']); + $ldap->cd($this->dhcpHostEntry['dn']); + $ldap->modify($attrs); + + $tmp = new servdhcp($this->config,$this->dhcpParentNode); + $tmp->handle_post_events("modify"); + + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dhcpHostEntry['dn'], LDAP_MOD, get_class())); + } + } + } + } + $this->dialog = FALSE; + + /****************/ + /* DNS HANDLING */ + /****************/ + + /* If isn't DNS account but initially was DNS account + remove all DNS entries + */ + if((!$this->DNSenabled) || ((!$this->DNS_is_account)&&(!$this->initially_was_account))){ + return; + }elseif($this->acl_is_writeable("dnsSetup")){ + + /* Add ipHostNumber to aRecords + */ + $backup_dnsEntry = $this->dnsEntry; + if(!empty($this->ipHostNumber)){ + $this->dnsEntry['RECORDS'][] = array("type"=>"aRecord","value"=>$this->ipHostNumber); + $ptr = $this->get_pTRRecord(); + if(!empty($ptr)){ + $this->dnsEntry['RECORDS'][] = array("type"=>"pTRRecord","value"=>$ptr); + } + } + + /* Create diff and follow instructions + * If Account was disabled, remove account by setting exists to false + */ + if((!$this->DNS_is_account)&&($this->initially_was_account)){ + $this->dnsEntry['exists'] = false; + $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn); + }else{ + $this->dnsEntry['exists'] = $this->DNS_is_account; + $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn); + } + + /* Update SOA record if needed + */ + $this->updateSOARecord(); + + /* move follwoing entries + */ + foreach($tmp['move'] as $src => $dst){ + $this->recursive_move($src,$dst); + } + + /* Delete dns */ + foreach($tmp['del'] as $dn => $del){ + $ldap->cd($dn); + $ldap->rmdir_recursive($dn); + new log("modify","unknown/".get_class($this),$dn,array("*"),$ldap->get_error()); + } + + /* Add || Update new DNS entries + */ + foreach($tmp['add'] as $dn => $attrs){ + $ldap->cd($dn); + $ldap->cat($dn, array('dn')); + if(count($ldap->fetch())){ + $ldap->cd($dn); + $ldap->modify ($attrs); + }else{ + $ldap->cd($dn); + $ldap->add($attrs); + } + new log("modify","unknown/".get_class($this),$dn,array_keys($attrs),$ldap->get_error()); + } + + + /* Display errors + */ + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, 0, get_class())); + } + + $tmp2 = new servdns($this->config,$this->dn); + $tmp2->handle_post_events("modify"); + + $this->dnsEntry = $backup_dnsEntry; + } } - /* Check if given entries in $onlyOnce are used more than once + /* Create html table with all used record types */ - if(isset($onlyOnce[$values['type']])){ - $onlyOnce[$values['type']] ++; - if($onlyOnce[$values['type']] > 1){ - $message[] = sprintf(_("Uniq record type '%s' is duplicated!"),$values['type']); - } - } + function generateRecordsList() + { + $changeStateForRecords = ""; - /* Skip txt record ... - */ - if($values['type'] == "tXTRecord") continue; + if(!$this->DNS_is_account) { + $str = ""; + return(array("str" => $str, "changeStateForRecords"=> "")); + } - /* Check if there is an aRecord defined which uses the same IP as used in IPhostAddress - */ - if(($values['type'] == "aRecord")&&($values['value'] == $this->ipHostNumber)){ - #TODO: Where's the problem here? - $message[]=sprintf(_("The IP address '%s' will be added as 'A Record', this will be done automatically, please remove the record."), - $this->ipHostNumber); + $str = ""; + foreach($this->dnsEntry['RECORDS'] as $key => $entry){ + + $changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n"; + $changeStateForRecords.= "changeState('RecordValue_".$key."');\n"; + $changeStateForRecords.= "changeState('RemoveRecord_".$key."');\n"; + + $str.=" ". + " ". + " ". + " "; + } + + $str.= " ". + " ". + " ". + "
".$this->generateRecordListBox($entry['type'],"RecordTypeSelectedFor_".$key).""; + "
". + " ". + "
"; + $ret = array("str" => $str, "changeStateForRecords" => $changeStateForRecords); + + return($ret); } - /* only lower-case is allowed in record entries ... + + /* Create a html select box which allows us to select different types of records */ - if($values['value'] != strtolower($values['value'])){ - #TODO: What's in values['value']? Something for a propper message? - $message[] = sprintf(_("Only lowercase records are allowed, please check your '%ss'."),$values['type']); + function generateRecordListBox($selected,$name) + { + $str = ""; + return($str); } - } - } - return ($message); - } - - - /* Save to LDAP */ - function save() - { - $ldap= $this->config->get_ldap_link(); - - $dn = $this->parent->dn; - - /*******************/ - /* IP-MAC HANDLING */ - /*******************/ - - /* $dn was posted as parameter */ - $this->dn = $dn; - - /* Save DNS setting & ip/Mac*/ - plugin::save(); - - /* Add all additional ipHostNumbers now - */ - if(!empty($this->ipHostNumber)){ - $this->attrs['ipHostNumber'] = array($this->ipHostNumber); - } - foreach($this->additionalHostNumbers as $value){ - $this->attrs['ipHostNumber'][] = $value; - } - /* Do not add the objectClass ipHost if no ip address is given */ - if(!isset($this->attrs['ipHostNumber'])){ - $this->attrs['objectClass'] = array_remove_entries(array("ipHost"),$this->attrs['objectClass']); - } - /* Write back to ldap */ - $ldap->cd($this->dn); - $this->cleanup(); - $ldap->modify ($this->attrs); - - /****************/ - /* DHCP HANDLING */ - /****************/ - - /* New entry */ - if($this->dhcpEnabled && $this->acl_is_writeable("dhcpSetup")) { - - if(count($this->dhcpHostEntry) == 0){ - $this->dialog = new dhcpHost($this->parent,$this->dhcpParentNode,TRUE); - $this->dialog->cn = $this->cn; - $this->dialog->dhcpHWAddress = "ethernet ".$this->macAddress; - if(!empty($this->ipHostNumber)){ - $this->dialog->statements->set('fixed-address', $this->ipHostNumber); - } - $this->dialog->execute(); - $this->dialog->save_object(); - $this->dhcpHostEntry = $this->dialog->save(); - if(count($this->dhcpHostEntry['dhcpOption']) == 0){ - $this->dhcpHostEntry['dhcpOption']= array("host-name ".$this->cn); - } - }else{ - - // Updated Host-Name entry - foreach($this->dhcpHostEntry['dhcpOption'] as $key => $entry){ - if(preg_match("/^host-name/", $entry)){ - $this->dhcpHostEntry['dhcpOption'][$key] = "host-name ".$this->cn; - break; - } - } - } - - /* Write mac address to dhcp settings */ - if($this->dhcp_is_Account){ - if(!isset($this->dhcpHostEntry['dhcpHWAddress'][0]) || - !preg_match("/ethernet ".$this->macAddress."/",$this->dhcpHostEntry['dhcpHWAddress'][0])){ - $this->dhcpHostEntry['dhcpHWAddress'] = array("ethernet ".$this->macAddress); - $this->dhcpHostEntry['MODIFIED'] = TRUE; - } - } - - /* Updated IP host number */ - if($this->dhcp_is_Account && $this->dhcpHostEntry['dhcpStatements']){ - foreach($this->dhcpHostEntry['dhcpStatements'] as $id => $value){ - if(preg_match("/^fixed-address/",$value)){ - $this->dhcpHostEntry['dhcpStatements'][$id] = "fixed-address ".$this->ipHostNumber; - $this->dhcpHostEntry['MODIFIED'] = TRUE; - } - } - } - - /* Unset dhcpStatements if this attribute is empty */ - if(isset($this->dhcpHostEntry['dhcpStatements']) && - ($this->dhcpHostEntry['dhcpStatements'] == "" || count($this->dhcpHostEntry['dhcpStatements']) == 0) ){ - unset($this->dhcpHostEntry['dhcpStatements']); - } - - /* DHCP removed */ - if($this->initial_dhcp_is_Account && !$this->dhcp_is_Account){ - $ldap->rmdir_recursive($this->dhcpHostEntry['dn']); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dhcpHostEntry['dn'], LDAP_DEL, get_class())); + /* Return plugin informations for acl handling */ + static function plInfo() + { + $tmp = array( + "plShortName" => _("DNS"), + "plDescription" => _("DNS settings"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 5, + "plSection" => array("administration"), + "plCategory" => array("workstation","terminal","phone","server","component","printer","winworkstation","opsi"), + + "plProvidedAcls"=> array( + "ipHostNumber" => _("IP address"), + "macAddress" => _("MAC address")) + ); + + /* Hide all dns/dhcp configurations if not available + */ + if(class_available("servdns")){ + $tmp['plProvidedAcls']["dnsSetup"] = _("DNS configuration"); + } + if(class_available("servdhcp")){ + $tmp['plProvidedAcls']["dhcpSetup"] = _("DHCP configuration"); + } + return($tmp); } - $tmp = new servdhcp($this->config,$this->dhcpParentNode); - $tmp->handle_post_events("remove"); - } - /* DHCP Added */ - if(!$this->initial_dhcp_is_Account && $this->dhcp_is_Account){ - $attrs = $this->dhcpHostEntry; - unset($attrs['MODIFIED']); - unset($attrs['dn']); - $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode); - $res = $ldap->add($attrs); + function get_dhcp_host_entry() + { + $attrs = array(); + $dn = $this->get_dhcp_host_entry_dn(); + if($dn){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->cat($dn,array("*")); + if($ldap->count()){ + $attrs = $ldap->fetch(); + foreach($attrs as $key => $value){ + if(is_numeric($key) || ($key == "count")){ + unset($attrs[$key]); + } + if(is_array($value) && isset($value['count'])){ + unset($attrs[$key]['count']); + } + } + } + } + return($attrs); + } + - $tmp = new servdhcp($this->config,$this->dhcpParentNode); - $tmp->handle_post_events("add"); + function get_dhcp_host_entry_dn() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search ("(&(objectClass=dhcpHost)(cn=".$this->cn."))",array("uid","cn","dn")); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "cn=".$this->cn.",".$this->dhcpParentNode, LDAP_ADD, get_class())); - } - } - - /* DHCP still activated */ - if($this->initial_dhcp_is_Account && $this->dhcp_is_Account){ - - /* DHCP node changed */ - if(($this->initial_dhcpParentNode != $this->dhcpParentNode) || - ($this->cn != $this->OrigCn)){ - $attrs = $this->dhcpHostEntry; - $attrs[$this->namingAttr] = $this->cn; - unset($attrs['dn']); - unset($attrs['MODIFIED']); - $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode); - $res = $ldap->add($attrs); - - $tmp = new servdhcp($this->config,$this->dhcpParentNode); - $tmp->handle_post_events("modify"); - - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "cn=".$this->cn.",".$this->dhcpParentNode, LDAP_ADD, get_class())); - } - if($res){ - $ldap->rmdir_recursive($this->dhcpHostEntry['dn']); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dhcpHostEntry['dn'], LDAP_DEL, get_class())); + if($ldap->count()){ + $attr = $ldap->fetch(); + return($attr['dn']); + }else{ + return(""); } - } - } - - /* SAME node but modified */ - if(isset($this->dhcpHostEntry['MODIFIED']) && $this->dhcpHostEntry['MODIFIED'] == 1 && - $this->initial_dhcpParentNode == $this->dhcpParentNode){ - $attrs = $this->dhcpHostEntry; - unset($attrs['dn']); - unset($attrs['MODIFIED']); - $ldap->cd($this->dhcpHostEntry['dn']); - $ldap->modify($attrs); - - $tmp = new servdhcp($this->config,$this->dhcpParentNode); - $tmp->handle_post_events("modify"); - - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dhcpHostEntry['dn'], LDAP_MOD, get_class())); - } - } - } - } - $this->dialog = FALSE; - - /****************/ - /* DNS HANDLING */ - /****************/ - - /* If isn't DNS account but initially was DNS account - remove all DNS entries - */ - if((!$this->DNSenabled) || ((!$this->DNS_is_account)&&(!$this->initially_was_account))){ - return; - }elseif($this->acl_is_writeable("dnsSetup")){ - - /* Add ipHostNumber to aRecords - */ - $backup_dnsEntry = $this->dnsEntry; - if(!empty($this->ipHostNumber)){ - $this->dnsEntry['RECORDS'][] = array("type"=>"aRecord","value"=>$this->ipHostNumber); - $ptr = $this->get_pTRRecord(); - if(!empty($ptr)){ - $this->dnsEntry['RECORDS'][] = array("type"=>"pTRRecord","value"=>$ptr); - } - } - - /* Create diff and follow instructions - * If Account was disabled, remove account by setting exists to false - */ - if((!$this->DNS_is_account)&&($this->initially_was_account)){ - $this->dnsEntry['exists'] = false; - $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn); - }else{ - $this->dnsEntry['exists'] = $this->DNS_is_account; - $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn); - } - - /* Update SOA record if needed - */ - $this->updateSOARecord(); - - /* move follwoing entries - */ - foreach($tmp['move'] as $src => $dst){ - $this->recursive_move($src,$dst); - } - - /* Delete dns */ - foreach($tmp['del'] as $dn => $del){ - $ldap->cd($dn); - $ldap->rmdir_recursive($dn); - new log("modify","unknown/".get_class($this),$dn,array("*"),$ldap->get_error()); - } - - /* Add || Update new DNS entries - */ - foreach($tmp['add'] as $dn => $attrs){ - $ldap->cd($dn); - $ldap->cat($dn, array('dn')); - if(count($ldap->fetch())){ - $ldap->cd($dn); - $ldap->modify ($attrs); - }else{ - $ldap->cd($dn); - $ldap->add($attrs); + } + + + function get_dhcp_parent_node() + { + return(preg_replace("/^cn=".preg_quote($this->cn, '/').",/","",$this->get_dhcp_host_entry_dn())); } - new log("modify","unknown/".get_class($this),$dn,array_keys($attrs),$ldap->get_error()); - } - /* Display errors - */ - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, 0, get_class())); - } + function get_dhcp_parent_nodes() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(objectClass=dhcpService)",array("dhcpPrimaryDN")); - $tmp2 = new servdns($this->config,$this->dn); - $tmp2->handle_post_events("modify"); + $dhcp_dns = array(); + while($attr = $ldap->fetch()){ + $dhcp_dns[$attr['dn']] = $attr['dhcpPrimaryDN'][0]; + } - $this->dnsEntry = $backup_dnsEntry; - } - } - - /* Create html table with all used record types - */ - function generateRecordsList() - { - $changeStateForRecords = ""; - - if(!$this->DNS_is_account) { - $str = ""; - return(array("str" => $str, "changeStateForRecords"=> "")); - } - - $str = ""; - foreach($this->dnsEntry['RECORDS'] as $key => $entry){ - - $changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n"; - $changeStateForRecords.= "changeState('RecordValue_".$key."');\n"; - $changeStateForRecords.= "changeState('RemoveRecord_".$key."');\n"; - - $str.=" ". - " ". - " ". - " "; - } + foreach($dhcp_dns as $key => $pri_dns){ + $ldap->cat($pri_dns,array("cn")); + $tmp = $ldap->fetch(); + if(isset($tmp['cn'][0])){ + $dhcp_dns[$key] = $tmp['cn'][0]; + }else{ + unset($dhcp_dns[$key]); + } + } - $str.= " ". - " ". - " ". - "
".$this->generateRecordListBox($entry['type'],"RecordTypeSelectedFor_".$key).""; - "
". - " ". - "
"; - $ret = array("str" => $str, "changeStateForRecords" => $changeStateForRecords); - - return($ret); - } - - - /* Create a html select box which allows us to select different types of records - */ - function generateRecordListBox($selected,$name) - { - $str = ""; - return($str); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - $tmp = array( - "plShortName" => _("DNS"), - "plDescription" => _("DNS settings"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 5, - "plSection" => array("administration"), - "plCategory" => array("workstation","terminal","phone","server","component","printer","winworkstation","opsi"), - - "plProvidedAcls"=> array( - "ipHostNumber" => _("IP address"), - "macAddress" => _("MAC address")) - ); - - /* Hide all dns/dhcp configurations if not available - */ - if(class_available("servdns")){ - $tmp['plProvidedAcls']["dnsSetup"] = _("DNS configuration"); - } - if(class_available("servdhcp")){ - $tmp['plProvidedAcls']["dhcpSetup"] = _("DHCP configuration"); - } - return($tmp); - } - - - function get_dhcp_host_entry() - { - $attrs = array(); - $dn = $this->get_dhcp_host_entry_dn(); - if($dn){ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->cat($dn,array("*")); - if($ldap->count()){ - $attrs = $ldap->fetch(); - foreach($attrs as $key => $value){ - if(is_numeric($key) || ($key == "count")){ - unset($attrs[$key]); - } - if(is_array($value) && isset($value['count'])){ - unset($attrs[$key]['count']); - } + $tmp = $tmp2 = array(); + foreach($dhcp_dns as $dn => $cn){ + $ldap->cd($dn); + $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpGroup)". + "(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork))",array("cn")); + while($attr = $ldap->fetch()){ + $tmp[$attr['dn']] = $attr['cn'][0]; + } + $tmp2 = array_merge($tmp2,$this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.") ")); + } + return($tmp2); } - } - } - return($attrs); - } - function get_dhcp_host_entry_dn() - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search ("(&(objectClass=dhcpHost)(cn=".$this->cn."))",array("uid","cn","dn")); + /* this function returns the default ptr record entry */ + function get_pTRRecord() + { + if(!empty($this->ipHostNumber) && isset($this->dnsEntry['zoneName']) && !empty($this->dnsEntry['zoneName'])){ + $ldap = $this->config->get_ldap_link(); + $ldap->cat(DNS::getDNSZoneDN($this->config,$this->dnsEntry['zoneName'])); + $attrs = $ldap->fetch(); + $tmp = array_flip($this->Zones); + $tmp = preg_replace("/^[^\/]*+\//","",$tmp[$this->dnsEntry['zoneName']]); + $tmp = trim(preg_replace("/\.in-addr.arpa\.$/","",$tmp)); + $ptr = preg_replace("/^".preg_quote(DNS::FlipIp($tmp), '/')."\./","",$this->ipHostNumber); + return($ptr); + }else{ + return(FALSE); + } + } - if($ldap->count()){ - $attr = $ldap->fetch(); - return($attr['dn']); - }else{ - return(""); - } - } + function generateRandomIP($net = "") + { + $str = $net; + $cnt = 4; + + // first gather all IPs + $ldap = $this->config->get_ldap_link(); + $ocs = + "(objectClass=goFonHardware)". + "(objectClass=goServer)". + "(objectClass=GOhard)". + "(objectClass=gotoTerminal)". + "(objectClass=gotoWorkstation)". + "(objectClass=gotoPrinter)". + "(objectClass=ipHost)"; + $list = array(); + $ldap->search("(&(|{$ocs})(ipHostNumber=*))",array("ipHostNumber")); + while($attrs = $ldap->fetch()){ + if (preg_match("/^$net\./", $attrs['ipHostNumber'][0])) { + $list[] = $attrs['ipHostNumber'][0]; + } + } - function get_dhcp_parent_node() - { - return(preg_replace("/^cn=".preg_quote($this->cn, '/').",/","",$this->get_dhcp_host_entry_dn())); - } + // Set starting ip. + $ip_data = preg_split("/\./",$net); + for($i=0;$i<4;$i++){ + if(!isset($ip_data[$i])) $ip_data[$i] = 0; + } + // Search the next free and valid ip. + while(in_array(implode(".",$ip_data),$list) || $ip_data[3] <= 1){ + $ip_data[3] ++ ; + if($ip_data[3] > 255){ + $ip_data[3] = 1 ; + $ip_data[2] ++ ; + } + if($ip_data[2] > 255){ + $ip_data[2] = 1 ; + $ip_data[1] ++ ; + } + if($ip_data[1] > 255){ + $ip_data[1] = 1 ; + $ip_data[0] ++ ; + } + if($ip_data[0] > 255) break; + } - function get_dhcp_parent_nodes() - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(objectClass=dhcpService)",array("dhcpPrimaryDN")); - - $dhcp_dns = array(); - while($attr = $ldap->fetch()){ - $dhcp_dns[$attr['dn']] = $attr['dhcpPrimaryDN'][0]; - } - - foreach($dhcp_dns as $key => $pri_dns){ - $ldap->cat($pri_dns,array("cn")); - $tmp = $ldap->fetch(); - if(isset($tmp['cn'][0])){ - $dhcp_dns[$key] = $tmp['cn'][0]; - }else{ - unset($dhcp_dns[$key]); - } - } + return(implode(".",$ip_data)); + } - $tmp = $tmp2 = array(); - foreach($dhcp_dns as $dn => $cn){ - $ldap->cd($dn); - $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpGroup)". - "(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork))",array("cn")); - while($attr = $ldap->fetch()){ - $tmp[$attr['dn']] = $attr['cn'][0]; - } - $tmp2 = array_merge($tmp2,$this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.") ")); - } - return($tmp2); - } - - - /* this function returns the default ptr record entry */ - function get_pTRRecord() - { - if(!empty($this->ipHostNumber) && isset($this->dnsEntry['zoneName']) && !empty($this->dnsEntry['zoneName'])){ - $ldap = $this->config->get_ldap_link(); - $ldap->cat(DNS::getDNSZoneDN($this->config,$this->dnsEntry['zoneName'])); - $attrs = $ldap->fetch(); - $tmp = array_flip($this->Zones); - $tmp = preg_replace("/^[^\/]*+\//","",$tmp[$this->dnsEntry['zoneName']]); - $tmp = trim(preg_replace("/\.in-addr.arpa\.$/","",$tmp)); - $ptr = preg_replace("/^".preg_quote(DNS::FlipIp($tmp), '/')."\./","",$this->ipHostNumber); - return($ptr); - }else{ - return(FALSE); - } - } - - - function generateRandomIP($net = "") - { - $str = $net; - $cnt = 4; - - // first gather all IPs - $ldap = $this->config->get_ldap_link(); - $ocs = - "(objectClass=goFonHardware)". - "(objectClass=goServer)". - "(objectClass=GOhard)". - "(objectClass=gotoTerminal)". - "(objectClass=gotoWorkstation)". - "(objectClass=gotoPrinter)". - "(objectClass=ipHost)"; - $list = array(); - $ldap->search("(&(|{$ocs})(ipHostNumber=*))",array("ipHostNumber")); - while($attrs = $ldap->fetch()){ - if (preg_match("/^$net\./", $attrs['ipHostNumber'][0])) { - $list[] = $attrs['ipHostNumber'][0]; - } - } - // Set starting ip. - $ip_data = preg_split("/\./",$net); - for($i=0;$i<4;$i++){ - if(!isset($ip_data[$i])) $ip_data[$i] = 0; - } + function create_tree($arr,$base,$current = "") + { + $ret = array(); + foreach($arr as $r => $name){ + $base_part = str_replace($base,"",$r); + if(preg_match("/^[a-z]*=".preg_quote($name, '/')."(|,)$/i",$base_part)){ + $ret[$r] = $current.$name; + $tmp = $this->create_tree($arr,$r,$current.". "); + foreach($tmp as $sub_key => $sub_name){ + $ret[$sub_key] = $sub_name; + } + } + } + return($ret); + } - // Search the next free and valid ip. - while(in_array(implode(".",$ip_data),$list) || $ip_data[3] <= 1){ - $ip_data[3] ++ ; - if($ip_data[3] > 255){ - $ip_data[3] = 1 ; - $ip_data[2] ++ ; - } - if($ip_data[2] > 255){ - $ip_data[2] = 1 ; - $ip_data[1] ++ ; - } - if($ip_data[1] > 255){ - $ip_data[1] = 1 ; - $ip_data[0] ++ ; - } - if($ip_data[0] > 255) break; - } + function force_dns() + { + if($this->DNSenabled){ - return(implode(".",$ip_data)); - } - - - function create_tree($arr,$base,$current = "") - { - $ret = array(); - foreach($arr as $r => $name){ - $base_part = str_replace($base,"",$r); - if(preg_match("/^[a-z]*=".preg_quote($name, '/')."(|,)$/i",$base_part)){ - $ret[$r] = $current.$name; - $tmp = $this->create_tree($arr,$r,$current.". "); - foreach($tmp as $sub_key => $sub_name){ - $ret[$sub_key] = $sub_name; + /* Only force DNS account, if we have at least on dns Zone */ + if(count($this->Zones)){ + $this->DNS_is_account = TRUE; + $this->hide_dns_check_box = TRUE; + } + } + } + + function updateSOARecord() + { + $oldEntries = DNS::getDNSHostEntries($this->config,$this->OrigCn); + $newEntries = $this->dnsEntry; + if(array_differs($newEntries['RECORDS'],$oldEntries['RECORDS'])){ + DNS::touchDNSZone($this->config,$this->dnsEntry['zoneName']); + } } - } - } - return($ret); - } - - function force_dns() - { - if($this->DNSenabled){ - - /* Only force DNS account, if we have at least on dns Zone */ - if(count($this->Zones)){ - $this->DNS_is_account = TRUE; - $this->hide_dns_check_box = TRUE; - } - } - } - - function updateSOARecord() - { - $oldEntries = DNS::getDNSHostEntries($this->config,$this->OrigCn); - $newEntries = $this->dnsEntry; - if(array_differs($newEntries['RECORDS'],$oldEntries['RECORDS'])){ - DNS::touchDNSZone($this->config,$this->dnsEntry['zoneName']); } - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> + // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: + ?> -- 2.30.2