From: hickert Date: Mon, 26 Jul 2010 08:56:35 +0000 (+0000) Subject: Updated goto plugins and extensions X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9dff687a99532063121c4ddc609bad7a10736a2a;p=gosa.git Updated goto plugins and extensions - Fixed post usage - fixed handling of incoming ACLs git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19100 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/goto/admin/systems/goto/class_ArpNewDevice.inc b/gosa-plugins/goto/admin/systems/goto/class_ArpNewDevice.inc index 000812a3c..a3887d8dd 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_ArpNewDevice.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_ArpNewDevice.inc @@ -1,168 +1,168 @@ netConfigDNS = new termDNS($this->config,$this,$this->objectclasses); - $this->acl = "#all#"; - $this->netConfigDNS->acl = $this->acl; - $this->netConfigDNS->force_dns(); - - /* Get object groups */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->config->current['BASE']); - $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn")); - $tmp= array(); - while($attrs = $ldap->fetch()){ - $tmp[$attrs['dn']]= $attrs['cn'][0]; - } - asort($tmp, SORT_LOCALE_STRING); - $this->ObjectGroups= $tmp; + var $cn= ""; + var $description = ""; + var $netConfigDNS = NULL; + var $attributes= array("cn","description"); + var $objectclasses = array("gotoHard"); + var $ignore_account = TRUE; + + var $ObjectGroups = array(); + var $SystemTypes = array(); + + var $ObjectGroup = "none"; + var $SystemType = "gotoWorkstation"; + + var $gotoIntegration = FALSE; + + function ArpNewDevice ($config, $dn= NULL, $parent= NULL) + { + plugin :: plugin($config,$dn); + $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses); + $this->acl = "#all#"; + $this->netConfigDNS->acl = $this->acl; + $this->netConfigDNS->force_dns(); + + /* Get object groups */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn")); + $tmp= array(); + while($attrs = $ldap->fetch()){ + $tmp[$attrs['dn']]= $attrs['cn'][0]; + } + asort($tmp, SORT_LOCALE_STRING); + $this->ObjectGroups= $tmp; - $this->SystemTypes =array("gotoWorkstation"=>_("Workstation"), "gotoTermminal"=>_("Terminal"), "goServer"=>_("Server")); - if(class_available("opsi")){ - $this->SystemTypes["FAKE_OC_OpsiHost"]= _("Windows workstation"); + $this->SystemTypes =array("gotoWorkstation"=>_("Workstation"), "gotoTermminal"=>_("Terminal"), "goServer"=>_("Server")); + if(class_available("opsi")){ + $this->SystemTypes["FAKE_OC_OpsiHost"]= _("Windows workstation"); + } } - } - - function execute() - { - plugin::execute(); - - /* Get object groups */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->config->current['BASE']); - $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("gosaGroupObjects","cn")); - $tmp= array("W" => array(),"T" => array(), "S" => array(),"O" => array()); - while($attrs = $ldap->fetch()){ - $tmp[preg_replace("/[\[\] ]/","",$attrs['gosaGroupObjects'][0])][$attrs['dn']] = $attrs['cn'][0]; + + function execute() + { + plugin::execute(); + + /* Get object groups */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("gosaGroupObjects","cn")); + $tmp= array("W" => array(),"T" => array(), "S" => array(),"O" => array()); + while($attrs = $ldap->fetch()){ + $tmp[preg_replace("/[\[\] ]/","",$attrs['gosaGroupObjects'][0])][$attrs['dn']] = $attrs['cn'][0]; + } + + $smarty = get_smarty(); + foreach($this->attributes as $attr){ + $smarty->assign($attr, set_post($this->$attr)); + } + $this->netConfigDNS->cn= $this->cn; + + $map = array("gotoWorkstation" => "W","gotoTerminal" => "T","goServer" => "S", "FAKE_OC_OpsiHost" => "O"); + $smarty->assign("netconfig", $this->netConfigDNS->execute()); + $smarty->assign("ogroups", set_post($tmp[$map[$this->SystemType]])); + $smarty->assign("SystemTypes", set_post($this->SystemTypes)); + $smarty->assign("SystemTypeKeys", set_post(array_flip($this->SystemTypes))); + $smarty->assign("ObjectGroup", set_post($this->ObjectGroup)); + $smarty->assign("SystemType", set_post($this->SystemType)); + + $smarty->assign("gotoIntegration",$this->gotoIntegration); + + /* Display sub dialog from network settings */ + $this->netConfigDNS->acl = $this->acl; + if($this->netConfigDNS->dialog){ + $this->dialog = TRUE; + return($this->netConfigDNS->execute()); + }else{ + $this->dialog = FALSE; + } + + return($smarty->fetch (get_template_path('ArpNewDevice.tpl', TRUE,dirname(__FILE__)))); } - $smarty = get_smarty(); - foreach($this->attributes as $attr){ - $smarty->assign($attr,$this->$attr); + function check() + { + $message= plugin::check(); + $message= array_merge($message, $this->netConfigDNS->check()); + if(empty($this->cn)){ + $message[] = msgPool::required(_("Name")); + } + return($message); } - $this->netConfigDNS->cn= $this->cn; - - $map = array("gotoWorkstation" => "W","gotoTerminal" => "T","goServer" => "S", "FAKE_OC_OpsiHost" => "O"); - $smarty->assign("netconfig", $this->netConfigDNS->execute()); - $smarty->assign("ogroups", $tmp[$map[$this->SystemType]]); - $smarty->assign("SystemTypes" ,$this->SystemTypes); - $smarty->assign("SystemTypeKeys" ,array_flip($this->SystemTypes)); - $smarty->assign("ObjectGroup",$this->ObjectGroup); - $smarty->assign("SystemType",$this->SystemType); - - $smarty->assign("gotoIntegration",$this->gotoIntegration); - - /* Display sub dialog from network settings */ - $this->netConfigDNS->acl = $this->acl; - if($this->netConfigDNS->dialog){ - $this->dialog = TRUE; - return($this->netConfigDNS->execute()); - }else{ - $this->dialog = FALSE; + + function save_object() + { + if(isset($_POST['ArpNewDevice_posted'])){ + plugin::save_object(); + $this->netConfigDNS->save_object(); + + $this->gotoIntegration = isset($_POST['gotoIntegration']); + if($this->gotoIntegration){ + if(isset($_POST['SystemType'])){ + $this->SystemType = get_post('SystemType'); + } + if(isset($_POST['ObjectGroup'])){ + $this->ObjectGroup = get_post('ObjectGroup'); + } + } + } } - return($smarty->fetch (get_template_path('ArpNewDevice.tpl', TRUE,dirname(__FILE__)))); - } + function save() + { - function check() - { - $message= plugin::check(); - $message= array_merge($message, $this->netConfigDNS->check()); - if(empty($this->cn)){ - $message[] = msgPool::required(_("Name")); - } - return($message); - } - - function save_object() - { - if(isset($_POST['ArpNewDevice_posted'])){ - plugin::save_object(); - $this->netConfigDNS->save_object(); - - $this->gotoIntegration = isset($_POST['gotoIntegration']); - if($this->gotoIntegration){ - if(isset($_POST['SystemType'])){ - $this->SystemType = get_post('SystemType'); - } - if(isset($_POST['ObjectGroup'])){ - $this->ObjectGroup = get_post('ObjectGroup'); + $this->netConfigDNS->acl = $this->acl; + plugin::save(); + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->save($this->dn); + + // Do not remove this Arp-Device if gotoIntegration was selected. + if(!$this->gotoIntegration){ + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->rmdir_recursive($this->dn); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $key->dn, LDAP_DEL, get_class())); + } } - } } - } - - function save() - { - - $this->netConfigDNS->acl = $this->acl; - plugin::save(); - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->save($this->dn); - - // Do not remove this Arp-Device if gotoIntegration was selected. - if(!$this->gotoIntegration){ - - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->rmdir_recursive($this->dn); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $key->dn, LDAP_DEL, get_class())); - } + + + /*! \brief !! Incoming dummy acls, required to defined acls for incoming objects + */ + static function plInfo() + { + return (array( + "plShortName" => _("Unknown incoming objects"), + "plDescription" => _("Unknown incoming objects"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 99, + "plSection" => array("administration"), + + "plProperties" => + array( + array( + "name" => "systemIncomingRDN", + "type" => "rdn", + "default" => "ou=incoming,", + "description" => _("The 'systemIncomingRDN' statement defines the location where incoming systems are stored. The default is 'ou=incoming,'."), + "check" => "gosaProperty::isRdn", + "migrate" => "migrate_systemIncomingRDN", + "group" => "plugin", + "mandatory" => FALSE)), + + "plCategory" => array("incoming" => array( "description" => _("Incoming"))), + "plProvidedAcls"=> array( + "cn" => _("Name"), + "description" => _("Description") + + ) + )); } - } - - - /*! \brief !! Incoming dummy acls, required to defined acls for incoming objects - */ - static function plInfo() - { - return (array( - "plShortName" => _("Unknown incoming objects"), - "plDescription" => _("Unknown incoming objects"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 99, - "plSection" => array("administration"), - - "plProperties" => - array( - array( - "name" => "systemIncomingRDN", - "type" => "rdn", - "default" => "ou=incoming,", - "description" => _("The 'systemIncomingRDN' statement defines the location where incoming systems are stored. The default is 'ou=incoming,'."), - "check" => "gosaProperty::isRdn", - "migrate" => "migrate_systemIncomingRDN", - "group" => "plugin", - "mandatory" => FALSE)), - - "plCategory" => array("incoming" => array( "description" => _("Incoming"))), - "plProvidedAcls"=> array( - "cn" => _("Name"), - "description" => _("Description") - - ) - )); - } } diff --git a/gosa-plugins/goto/admin/systems/goto/class_SelectDeviceType.inc b/gosa-plugins/goto/admin/systems/goto/class_SelectDeviceType.inc index 9132f1f35..d99aba8c8 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_SelectDeviceType.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_SelectDeviceType.inc @@ -2,106 +2,106 @@ class SelectDeviceType extends plugin { - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes= array("ObjectGroup","SystemType"); - var $objectclasses= array("whatever"); - - var $ObjectGroups = array(); - var $SystemTypes = array(); - - var $ObjectGroup = "none"; - var $SystemType = "gotoWorkstation"; - - var $dn; - - function SelectDeviceType (&$config, $dn= NULL) - { - if(!is_array($dn)){ - $this->dns = array($dn); - }else{ - $this->dns = $dn; + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes= array("ObjectGroup","SystemType"); + var $objectclasses= array("whatever"); + + var $ObjectGroups = array(); + var $SystemTypes = array(); + + var $ObjectGroup = "none"; + var $SystemType = "gotoWorkstation"; + + var $dn; + + function SelectDeviceType (&$config, $dn= NULL) + { + if(!is_array($dn)){ + $this->dns = array($dn); + }else{ + $this->dns = $dn; + } + plugin::plugin ($config, NULL); + + /* Get object groups */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn")); + $tmp= array(); + while($attrs = $ldap->fetch()){ + $tmp[$attrs['dn']]= $attrs['cn'][0]; + } + asort($tmp, SORT_LOCALE_STRING); + $this->ObjectGroups= $tmp; + + $this->SystemTypes =array("gotoWorkstation"=>_("Workstation"), "gotoTerminal"=>_("Terminal"), "goServer"=>_("Server")); + if(class_available("opsi")){ + $this->SystemTypes["FAKE_OC_OpsiHost"]= _("Windows workstation"); + } } - plugin::plugin ($config, NULL); - - /* Get object groups */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->config->current['BASE']); - $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn")); - $tmp= array(); - while($attrs = $ldap->fetch()){ - $tmp[$attrs['dn']]= $attrs['cn'][0]; + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + + /* Get object groups */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("gosaGroupObjects","cn")); + $tmp= array("W" => array(),"T" => array(), "S" => array(),"O" => array()); + while($attrs = $ldap->fetch()){ + $tmp[preg_replace("/[\[\] ]/","",$attrs['gosaGroupObjects'][0])][$attrs['dn']] = $attrs['cn'][0]; + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + $map = array("gotoWorkstation" => "W","gotoTerminal" => "T","goServer" => "S", "FAKE_OC_OpsiHost" => "O"); + $smarty->assign("dns_cnt" , set_post(count($this->dns))); + $smarty->assign("ogroups", set_post($tmp[$map[$this->SystemType]])); + $smarty->assign("SystemTypes" ,set_post($this->SystemTypes)); + $smarty->assign("SystemTypeKeys" ,set_post(array_flip($this->SystemTypes))); + $smarty->assign("ObjectGroup", set_post($this->ObjectGroup)); + $smarty->assign("SystemType", set_post($this->SystemType)); + $display.= $smarty->fetch(get_template_path('SelectDeviceType.tpl', TRUE,dirname(__FILE__))); + return($display); } - asort($tmp, SORT_LOCALE_STRING); - $this->ObjectGroups= $tmp; - $this->SystemTypes =array("gotoWorkstation"=>_("Workstation"), "gotoTerminal"=>_("Terminal"), "goServer"=>_("Server")); - if(class_available("opsi")){ - $this->SystemTypes["FAKE_OC_OpsiHost"]= _("Windows workstation"); + /* Save data to object */ + function save_object() + { + plugin::save_object(); + foreach($this->attributes as $attr){ + if(isset($_POST[$attr])){ + $this->$attr = get_post($attr); + } + } } - } - function execute() - { - /* Call parent execute */ - plugin::execute(); + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + return ($message); + } - /* Get object groups */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->config->current['BASE']); - $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("gosaGroupObjects","cn")); - $tmp= array("W" => array(),"T" => array(), "S" => array(),"O" => array()); - while($attrs = $ldap->fetch()){ - $tmp[preg_replace("/[\[\] ]/","",$attrs['gosaGroupObjects'][0])][$attrs['dn']] = $attrs['cn'][0]; + /* Save to LDAP */ + function save() + { } - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - - $map = array("gotoWorkstation" => "W","gotoTerminal" => "T","goServer" => "S", "FAKE_OC_OpsiHost" => "O"); - $smarty->assign("dns_cnt" , count($this->dns)); - $smarty->assign("ogroups", $tmp[$map[$this->SystemType]]); - $smarty->assign("SystemTypes" ,$this->SystemTypes); - $smarty->assign("SystemTypeKeys" ,array_flip($this->SystemTypes)); - $smarty->assign("ObjectGroup",$this->ObjectGroup); - $smarty->assign("SystemType",$this->SystemType); - $display.= $smarty->fetch(get_template_path('SelectDeviceType.tpl', TRUE,dirname(__FILE__))); - return($display); - } - - /* Save data to object */ - function save_object() - { - plugin::save_object(); - foreach($this->attributes as $attr){ - if(isset($_POST[$attr])){ - $this->$attr = $_POST[$attr]; - } + function acl_is_writeable($attribute,$skip_write = FALSE) + { + if($this->read_only) return(FALSE); + $ui= get_userinfo(); + return preg_match('/w/', $ui->get_permissions($this->acl_base, $this->acl_category."systemManagement", "", $skip_write)); } - } - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - /* Save to LDAP */ - function save() - { - } - - function acl_is_writeable($attribute,$skip_write = FALSE) - { - if($this->read_only) return(FALSE); - $ui= get_userinfo(); - return preg_match('/w/', $ui->get_permissions($this->acl_base, $this->acl_category."systemManagement", $attribute, $skip_write)); - } } diff --git a/gosa-plugins/goto/admin/systems/goto/class_gotoLpdEnabled.inc b/gosa-plugins/goto/admin/systems/goto/class_gotoLpdEnabled.inc index ba5a17af6..19562795f 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_gotoLpdEnabled.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_gotoLpdEnabled.inc @@ -2,304 +2,304 @@ class gotoLpdEnable extends plugin { - public $parent; - - protected $DevID = 0; - private $data = array(); - private $default_entry = array(); - - protected $s_Type = "U"; - protected $s_Device = "/dev/usb/lp"; - protected $i_Port = 9100; - protected $s_Options = ""; - protected $s_WriteOnly = "Y"; - - protected $s_Speed = 9600; - protected $s_FlowControl = "S"; - protected $s_Parity = "E"; - protected $i_Bit = 5; - - /* Option predefinition */ - private $a_Types = array(); - private $a_FlowControls = array(); // - private $a_Parities = array(); // - private $a_Speeds = array(); // - private $a_Bits = array(); // - private $a_Devices = array(); - public $attributes = array("s_Type","s_Device","i_Port","s_Options","s_WriteOnly", - "s_Speed","s_FlowControl","s_Parity","i_Bit"); - - /*! \brief Create gotoLpdEnable dialog, allows to edit printer settings. + public $parent; + + protected $DevID = 0; + private $data = array(); + private $default_entry = array(); + + protected $s_Type = "U"; + protected $s_Device = "/dev/usb/lp"; + protected $i_Port = 9100; + protected $s_Options = ""; + protected $s_WriteOnly = "Y"; + + protected $s_Speed = 9600; + protected $s_FlowControl = "S"; + protected $s_Parity = "E"; + protected $i_Bit = 5; + + /* Option predefinition */ + private $a_Types = array(); + private $a_FlowControls = array(); // + private $a_Parities = array(); // + private $a_Speeds = array(); // + private $a_Bits = array(); // + private $a_Devices = array(); + public $attributes = array("s_Type","s_Device","i_Port","s_Options","s_WriteOnly", + "s_Speed","s_FlowControl","s_Parity","i_Bit"); + + /*! \brief Create gotoLpdEnable dialog, allows to edit printer settings. @param Object $config The GOsa configuration object. @param Array $data The values for attribute 'gotoLpdEnable' - e.g. array("U:/dev/usb/lp0:9100:9600:S:E:0:Y:options", - "U:/dev/usb/lp1:9101:9600:S:E:5:Y:", ...) + e.g. array("U:/dev/usb/lp0:9100:9600:S:E:0:Y:options", + "U:/dev/usb/lp1:9101:9600:S:E:5:Y:", ...) @param Object $parent A reference to the parent plugin-object. @return Object gotoLpdEnable (plugin) - */ - public function __construct($config,$data,&$parent) - { - plugin::plugin($config,NULL); - $this->parent = $parent; - $this->DevID = 0; - - /* Predefine selectable values - */ - $this->a_Types = array( - "U" => _("USB"), - "P" => _("Parallel port"), - "S" => _("Serial")); - $this->a_FlowControl = array( - "S" => _("Software"), - "H" => _("Hardware")); - $this->a_Parities = array( - "E" => _("Even"), - "O" => _("Odd"), - "N" => _("None")); - $this->a_Speeds = array( - "4800" => "4.800 "._("bit/s"), - "9600" => "9.600 "._("bit/s"), - "19200" => "19.200 "._("bit/s"), - "38400" => "38.400 "._("bit/s"), - "57600" => "57.600 "._("bit/s"), - "115200"=> "115.200 "._("bit/s"), - "230400"=> "230.400 "._("bit/s"), - "460800"=> "460.800 "._("bit/s")); - $this->a_Bits = array( - 5,6,7,8); - $this->a_Devices = array( - "U" => "/dev/usb/lp", - "P" => "/dev/lp", - "S" => "/dev/ttyS"); - - /* Create default entry */ - foreach($this->attributes as $attr){ - $this->default_entry[$attr] = $this->$attr; - } - - /* Load current settings - */ - if(count($data) == 0){ - $this->is_account = FALSE; - }else{ - foreach($data as $dat){ - if(substr_count($dat,":") < 8) continue; - list($s_Type,$s_Device,$i_Port,$s_Speed,$s_FlowControl,$s_Parity,$i_Bit,$s_WriteOnly,$s_Options) = explode(":",$dat); - $entry = array(); + public function __construct($config,$data,&$parent) + { + plugin::plugin($config,NULL); + $this->parent = $parent; + $this->DevID = 0; + + /* Predefine selectable values + */ + $this->a_Types = array( + "U" => _("USB"), + "P" => _("Parallel port"), + "S" => _("Serial")); + $this->a_FlowControl = array( + "S" => _("Software"), + "H" => _("Hardware")); + $this->a_Parities = array( + "E" => _("Even"), + "O" => _("Odd"), + "N" => _("None")); + $this->a_Speeds = array( + "4800" => "4.800 "._("bit/s"), + "9600" => "9.600 "._("bit/s"), + "19200" => "19.200 "._("bit/s"), + "38400" => "38.400 "._("bit/s"), + "57600" => "57.600 "._("bit/s"), + "115200"=> "115.200 "._("bit/s"), + "230400"=> "230.400 "._("bit/s"), + "460800"=> "460.800 "._("bit/s")); + $this->a_Bits = array( + 5,6,7,8); + $this->a_Devices = array( + "U" => "/dev/usb/lp", + "P" => "/dev/lp", + "S" => "/dev/ttyS"); + + /* Create default entry + */ foreach($this->attributes as $attr){ - $entry[$attr] = $$attr; + $this->default_entry[$attr] = $this->$attr; } - $this->data[] = $entry; - } - /* Set first entry values - From "$this->data[0]" to "$this->" - */ - if(count($this->data)){ - foreach($this->attributes as $attr){ - $this->$attr = $this->data[$this->DevID][$attr]; + /* Load current settings + */ + if(count($data) == 0){ + $this->is_account = FALSE; + }else{ + foreach($data as $dat){ + if(substr_count($dat,":") < 8) continue; + list($s_Type,$s_Device,$i_Port,$s_Speed,$s_FlowControl,$s_Parity,$i_Bit,$s_WriteOnly,$s_Options) = explode(":",$dat); + $entry = array(); + foreach($this->attributes as $attr){ + $entry[$attr] = $$attr; + } + $this->data[] = $entry; + } + + /* Set first entry values + From "$this->data[0]" to "$this->" + */ + if(count($this->data)){ + foreach($this->attributes as $attr){ + $this->$attr = $this->data[$this->DevID][$attr]; + } + $this->is_account = TRUE; + } } - $this->is_account = TRUE; - } + $this->initially_was_account = $this->is_account; } - $this->initially_was_account = $this->is_account; - } - /*! \brief Create HTML output of this plugin. - Depending on the current plugin status, there is a - 'create' and a 'remove'account button displayed on top - followed by the gotoLpdEnable options. + /*! \brief Create HTML output of this plugin. + Depending on the current plugin status, there is a + 'create' and a 'remove'account button displayed on top + followed by the gotoLpdEnable options. @param . @return String HTML content - */ - public function execute() - { - plugin::execute(); + */ + public function execute() + { + plugin::execute(); - $display = ""; + $display = ""; - /* Set smarty variables - */ - $smarty = get_smarty(); - $smarty->assign("acl",$this->parent->getacl("gotoLpdEnable")); - foreach($this->attributes as $attr){ - $smarty->assign($attr,$this->$attr); - } - foreach(array("DevID","a_Types","a_FlowControl","a_Parities","a_Speeds","a_Bits") as $attr){ - $smarty->assign($attr,$this->$attr); + /* Set smarty variables + */ + $smarty = get_smarty(); + $smarty->assign("acl",$this->parent->getacl("gotoLpdEnable")); + foreach($this->attributes as $attr){ + $smarty->assign($attr,$this->$attr); + } + foreach(array("DevID","a_Types","a_FlowControl","a_Parities","a_Speeds","a_Bits") as $attr){ + $smarty->assign($attr,$this->$attr); + } + ksort($this->data); + $smarty->assign("data_cnt",count($this->data)); + $smarty->assign("data",$this->data); + $smarty->assign("a_DevIDs",array_keys($this->data)); + $smarty->assign("is_account",$this->is_account); + return($display.$smarty->fetch(get_template_path("gotoLpdEnable.tpl",TRUE,dirname(__FILE__)))); } - ksort($this->data); - $smarty->assign("data_cnt",count($this->data)); - $smarty->assign("data",$this->data); - $smarty->assign("a_DevIDs",array_keys($this->data)); - $smarty->assign("is_account",$this->is_account); - return($display.$smarty->fetch(get_template_path("gotoLpdEnable.tpl",TRUE,dirname(__FILE__)))); - } - /*! \brief Checks the given informations and returns an array - with the error messages or an empty array if everything went fine. + /*! \brief Checks the given informations and returns an array + with the error messages or an empty array if everything went fine. @param . @return Array of Strings Error messages. - */ - public function check() - { - $messages = plugin::check(); - if(!$this->is_account){ - return($messages); - } - foreach($this->data as $id => $entry){ - if(!tests::is_id($entry['i_Port'])){ - $messages[] = msgPool::invalid(_("Port")); - } - if(preg_match("/:/",$entry['s_Options'])){ - $messages[] = msgPool::invalid(_("Options")); - } - } - return($messages); - } + */ + public function check() + { + $messages = plugin::check(); + if(!$this->is_account){ + return($messages); + } + foreach($this->data as $id => $entry){ + if(!tests::is_id($entry['i_Port'])){ + $messages[] = msgPool::invalid(_("Port")); + } + if(preg_match("/:/",$entry['s_Options'])){ + $messages[] = msgPool::invalid(_("Options")); + } + } + return($messages); + } - /*! \brief Save all ui inputs. + /*! \brief Save all ui inputs. @param . @return . - */ - public function save_object() - { - if(!$this->parent->acl_is_writeable("gotoLpdEnable")){ - return; - } + */ + public function save_object() + { + if(!$this->parent->acl_is_writeable("gotoLpdEnable")){ + return; + } - if(!isset($_POST['gotoLpdEnable_entry_posted'])){ - return; - } + if(!isset($_POST['gotoLpdEnable_entry_posted'])){ + return; + } - /* Handle account add/remove - */ - if(isset($_POST['gotoLpdEnable_enabled'])){ - $this->is_account = TRUE; - }else{ - $this->is_account = FALSE; - } + /* Handle account add/remove + */ + if(isset($_POST['gotoLpdEnable_enabled'])){ + $this->is_account = TRUE; + }else{ + $this->is_account = FALSE; + } - /* Check if we have to propose device settings - (current device info is empty and the printer type has changed) - */ - $propose_device = ""; - if(isset($_POST['s_Device']) && empty($_POST['s_Device']) && - isset($_POST['s_Type']) && $_POST['s_Type'] != $this->s_Type){ - $propose_device = $this->a_Devices[$_POST['s_Type']].$this->DevID; - } + /* Check if we have to propose device settings + (current device info is empty and the printer type has changed) + */ + $propose_device = ""; + if(isset($_POST['s_Device']) && empty($_POST['s_Device']) && + isset($_POST['s_Type']) && $_POST['s_Type'] != $this->s_Type){ + $propose_device = $this->a_Devices[$_POST['s_Type']].$this->DevID; + } - plugin::save_object(); + plugin::save_object(); - if(!empty($propose_device)){ - $this->s_Device = $propose_device; - } + if(!empty($propose_device)){ + $this->s_Device = $propose_device; + } - /* Get checkbox changes - */ - if(isset($_POST['s_WriteOnly'])){ - $this->s_WriteOnly = "Y"; - }else{ - $this->s_WriteOnly = "N"; - } + /* Get checkbox changes + */ + if(isset($_POST['s_WriteOnly'])){ + $this->s_WriteOnly = "Y"; + }else{ + $this->s_WriteOnly = "N"; + } - /* Write back attributes to data array ($this->data) - */ - foreach($this->attributes as $attr){ - $this->data[$this->DevID][$attr] = $this->$attr; - } - - /* Device ID has changed another printer was selected * / - if(isset($_POST['DevID']) && $_POST['DevID'] != $this->DevID){ - $this->DevID = $_POST['DevID']; - foreach($this->attributes as $attr){ - $this->$attr = $this->data[$this->DevID][$attr]; - } - } - */ - - /* Add and remove additional printer settings - if(isset($_POST['del_printer'])){ - unset($this->data[$this->DevID]); - $this->data = array_values($this->data); - if(count($this->data) == 0){ - $this->is_account = FALSE; - } - $this->DevID = key($this->data); - } - if(isset($_POST['add_printer'])){ - if(count($this->data) < 3){ - $entry = $this->default_entry; - $entry['i_Port'] = $entry['i_Port'] + count($this->data); - $entry['s_Device'] = $entry['s_Device'].count($this->data); - $this->DevID = count($this->data); - $this->data[] = $entry; + /* Write back attributes to data array ($this->data) + */ foreach($this->attributes as $attr){ - $this->$attr = $this->data[$this->DevID][$attr]; - } - } + $this->data[$this->DevID][$attr] = $this->$attr; + } + + /* Device ID has changed another printer was selected * / + if(isset($_POST['DevID']) && $_POST['DevID'] != $this->DevID){ + $this->DevID = $_POST['DevID']; + foreach($this->attributes as $attr){ + $this->$attr = $this->data[$this->DevID][$attr]; + } + } + */ + + /* Add and remove additional printer settings + if(isset($_POST['del_printer'])){ + unset($this->data[$this->DevID]); + $this->data = array_values($this->data); + if(count($this->data) == 0){ + $this->is_account = FALSE; + } + $this->DevID = key($this->data); + } + if(isset($_POST['add_printer'])){ + if(count($this->data) < 3){ + $entry = $this->default_entry; + $entry['i_Port'] = $entry['i_Port'] + count($this->data); + $entry['s_Device'] = $entry['s_Device'].count($this->data); + $this->DevID = count($this->data); + $this->data[] = $entry; + foreach($this->attributes as $attr){ + $this->$attr = $this->data[$this->DevID][$attr]; + } + } + } + */ } - */ - } - /*! \brief Creates an array containing all gotoLpdEnabled values, - see constructor for more details. + /*! \brief Creates an array containing all gotoLpdEnabled values, + see constructor for more details. @param . @return Array of gotoLpdEnabled Strings. - */ - public function save() - { - $ret = array(); - $serial_only = array("s_Speed","s_FlowControl","s_Parity","i_Bit"); - $attrs = array("s_Type","s_Device","i_Port","s_Speed","s_FlowControl","s_Parity","i_Bit","s_WriteOnly","s_Options"); - foreach($this->data as $entry){ - $str = ""; - foreach($attrs as $attr){ - if(in_array($attr,$serial_only) && $entry['s_Type'] != "Serial"){ - $str .= ":"; - }else{ - $str .= $entry[$attr].":"; + */ + public function save() + { + $ret = array(); + $serial_only = array("s_Speed","s_FlowControl","s_Parity","i_Bit"); + $attrs = array("s_Type","s_Device","i_Port","s_Speed","s_FlowControl","s_Parity","i_Bit","s_WriteOnly","s_Options"); + foreach($this->data as $entry){ + $str = ""; + foreach($attrs as $attr){ + if(in_array($attr,$serial_only) && $entry['s_Type'] != "Serial"){ + $str .= ":"; + }else{ + $str .= $entry[$attr].":"; + } + } + $ret[] = preg_replace("/:$/","",$str); } - } - $ret[] = preg_replace("/:$/","",$str); + return($ret); } - return($ret); - } - /*! \brief . + /*! \brief . @param . @return . - */ - public function acl_is_writeable($attr,$skip_write = FALSE) - { - return(TRUE); - } + */ + public function acl_is_writeable($attr,$skip_write = FALSE) + { + return(TRUE); + } - /*! \brief . + /*! \brief . @param . @return . - */ - public function acl_is_removeable($skip_write = FALSE) - { - return(TRUE); - } + */ + public function acl_is_removeable($skip_write = FALSE) + { + return(TRUE); + } - /*! \brief . + /*! \brief . @param . @return . - */ - public function acl_is_createable($skip_write = FALSE) - { - return(TRUE); - } + */ + public function acl_is_createable($skip_write = FALSE) + { + return(TRUE); + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc b/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc index 3f288484e..e3663950c 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc @@ -2,1166 +2,1166 @@ class printgeneric extends plugin { - /* Generic terminal attributes */ - var $interfaces = array(); - var $ignore_account = FALSE; - - /* Needed values and lists */ - var $base = ""; - var $cn = ""; - var $l = ""; - var $description = ""; - var $labeledURI = ""; - var $gotoPrinterPPD = ""; - var $initial_PPD = ""; - var $orig_dn = ""; - var $orig_cn = ""; - var $orig_base = ""; - - var $UserMember =""; - var $UserMembers =array(); - var $UserMemberKeys =array(); - - var $AdminMember =""; - var $AdminMembers =array(); - var $AdminMemberKeys =array(); - - var $ppdServerPart = ""; - - var $PPDdialogToSave = NULL; - var $BelongsTo = "unknown"; // Specifies if this is a standalone printer, or belongs to a terminal / WS - - var $member =array(); - var $strings = ""; - var $netConfigDNS; - var $baseSelection = false; - var $macAddress = ""; - - var $gotoUserAdminPrinter; - var $gotoGroupAdminPrinter ; - var $gotoGroupPrinter; - var $gotoUserPrinter ; - var $baseSelector; - - /* attribute list for save action */ - var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress", - "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter","gosaUnitTag"); - var $objectclasses = array("top", "gotoPrinter"); - var $view_logged = FALSE; - var $parent; - - - // Memeber dialog object - var $userSelect; - var $adminUserSelect; - - function printgeneric (&$config, $dn,$parent_init,$parent) - { - $this->config = &$config; - $this->dn = $dn; - - /* If parent was posted(the tabs object) we can detect the printer type. */ - if($parent){ - $this->parent = $parent; - $this->getTypeOfPrinter(); - }else{ - $this->BelongsTo = "unknown"; - return; - } + /* Generic terminal attributes */ + var $interfaces = array(); + var $ignore_account = FALSE; + + /* Needed values and lists */ + var $base = ""; + var $cn = ""; + var $l = ""; + var $description = ""; + var $labeledURI = ""; + var $gotoPrinterPPD = ""; + var $initial_PPD = ""; + var $orig_dn = ""; + var $orig_cn = ""; + var $orig_base = ""; + + var $UserMember =""; + var $UserMembers =array(); + var $UserMemberKeys =array(); + + var $AdminMember =""; + var $AdminMembers =array(); + var $AdminMemberKeys =array(); + + var $ppdServerPart = ""; + + var $PPDdialogToSave = NULL; + var $BelongsTo = "unknown"; // Specifies if this is a standalone printer, or belongs to a terminal / WS + + var $member =array(); + var $strings = ""; + var $netConfigDNS; + var $baseSelection = false; + var $macAddress = ""; + + var $gotoUserAdminPrinter; + var $gotoGroupAdminPrinter ; + var $gotoGroupPrinter; + var $gotoUserPrinter ; + var $baseSelector; + + /* attribute list for save action */ + var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress", + "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter","gosaUnitTag"); + var $objectclasses = array("top", "gotoPrinter"); + var $view_logged = FALSE; + var $parent; + + + // Memeber dialog object + var $userSelect; + var $adminUserSelect; + + function printgeneric (&$config, $dn,$parent_init,$parent) + { + $this->config = &$config; + $this->dn = $dn; + + /* If parent was posted(the tabs object) we can detect the printer type. */ + if($parent){ + $this->parent = $parent; + $this->getTypeOfPrinter(); + }else{ + $this->BelongsTo = "unknown"; + return; + } - /* Update dn, to ensure storing as printer instead of WS / terminal */ - if(preg_match("/Terminal/i",$this->BelongsTo) || preg_match("/TerminalTemplate/i",$this->BelongsTo)){ - $this->dn= preg_replace("/".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); - } + /* Update dn, to ensure storing as printer instead of WS / terminal */ + if(preg_match("/Terminal/i",$this->BelongsTo) || preg_match("/TerminalTemplate/i",$this->BelongsTo)){ + $this->dn= preg_replace("/".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); + } - if(preg_match("/Workstation/i",$this->BelongsTo) || preg_match("/WorkstationTemplate/i",$this->BelongsTo)){ - $this->dn= preg_replace("/".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); - } + if(preg_match("/Workstation/i",$this->BelongsTo) || preg_match("/WorkstationTemplate/i",$this->BelongsTo)){ + $this->dn= preg_replace("/".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); + } - $this->orig_dn = $this->dn; + $this->orig_dn = $this->dn; - /* Get printer settings, possibly dn has changed */ - plugin::plugin ($config, $this->dn); + /* Get printer settings, possibly dn has changed */ + plugin::plugin ($config, $this->dn); - /* Get is_account initially_was_account status */ - $this->getTypeOfPrinter(true); + /* Get is_account initially_was_account status */ + $this->getTypeOfPrinter(true); - /* set orig dn to new if object is new */ - $ldap= $this->config->get_ldap_link(); - $ldap->cat($this->dn, array('dn')); - if(!$ldap->count()){ - $this->orig_dn = "new"; - } - - /* create dns object */ - $this->netConfigDNS = new termDNS($this->config, $this,$this->objectclasses); - - /* 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 { - - /* Set base and check if the extracted base exists */ - if(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$this->dn)){ - $this->base= preg_replace("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i","",dn2base($this->dn)); - }else{ - $this->base= preg_replace("/".preg_quote(get_ou("printgeneric", "printerRDN"), '/')."/i","",dn2base($this->dn)); - } - - if(!isset($this->config->idepartments[$this->base])){ - msg_dialog::display(_("Internal error"), sprintf(_("Cannot determine a valid department for this object. Setting base to '%s'!"), session::get('CurrentMainBase')) , WARNING_DIALOG); - $this->base = session::get('CurrentMainBase'); - } + /* set orig dn to new if object is new */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($this->dn, array('dn')); + if(!$ldap->count()){ + $this->orig_dn = "new"; + } + + /* create dns object */ + $this->netConfigDNS = new termDNS($this->config, $this,$this->objectclasses); + + /* 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 { + + /* Set base and check if the extracted base exists */ + if(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$this->dn)){ + $this->base= preg_replace("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i","",dn2base($this->dn)); + }else{ + $this->base= preg_replace("/".preg_quote(get_ou("printgeneric", "printerRDN"), '/')."/i","",dn2base($this->dn)); + } + + if(!isset($this->config->idepartments[$this->base])){ + msg_dialog::display(_("Internal error"), sprintf(_("Cannot determine a valid department for this object. Setting base to '%s'!"), session::get('CurrentMainBase')) , WARNING_DIALOG); + $this->base = session::get('CurrentMainBase'); + } + } + + /* If no ppd is selected, remove this attribute */ + if(!empty($this->gotoPrinterPPD) && $this->initially_was_account) { + $this->ppdServerPart = preg_replace("/^(http.*ppd)\/.*$/i","\\1",$this->gotoPrinterPPD); + }else{ + + /* Detect PPD server part */ + if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){ + $method="https://"; + }else{ + $method="http://"; + } + + /* Get servername */ + $server = $_SERVER['SERVER_NAME']; + if(tests::is_ip($server)){ + $server_name = @gethostbyaddr($server); + }else{ + $server_name = @gethostbyaddr(gethostbyname($server)); + } + $this->ppdServerPart = $method.str_replace("//","/",$server_name."/ppd"); + } + + /* Extract selected ppd */ + if(isset($this->gotoPrinterPPD)){ + $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD); + } + + $this->initial_PPD = $this->gotoPrinterPPD; + + /* Prepare different member types */ + foreach(array("AddUser" =>"gotoUserPrinter", + "AddGroup" =>"gotoGroupPrinter", + "AddAdminUser" =>"gotoUserAdminPrinter", + "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){ + + /* $this->members contains all members */ + $this->member[$type]=array(); + + if(isset($this->attrs[$attr])){ + $ldap->cd($this->config->current['BASE']) ; + for($i = 0 ; $i < $this->attrs[$attr]['count']; $i++){ + + $mem = $this->attrs[$attr][$i]; + if(preg_match("/Group/",$type)){ + $ldap->search("(&(|(objectClass=posixGroup)(objectClass=gosaGroupOfNames))(cn=".$mem."))",array("cn","description")); + if($ldap->count()){ + $entry = $ldap->fetch(); + $this->member[$type][$entry['cn'][0]]=$entry; + } + }else{ + $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid")); + if($ldap->count()){ + $entry = $ldap->fetch(); + $this->member[$type][$entry['uid'][0]]=$entry; + } + } + } + } + } + $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); } - /* If no ppd is selected, remove this attribute */ - if(!empty($this->gotoPrinterPPD) && $this->initially_was_account) { - $this->ppdServerPart = preg_replace("/^(http.*ppd)\/.*$/i","\\1",$this->gotoPrinterPPD); - }else{ - - /* Detect PPD server part */ - if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){ - $method="https://"; - }else{ - $method="http://"; - } - - /* Get servername */ - $server = $_SERVER['SERVER_NAME']; - if(tests::is_ip($server)){ - $server_name = @gethostbyaddr($server); - }else{ - $server_name = @gethostbyaddr(gethostbyname($server)); - } - $this->ppdServerPart = $method.str_replace("//","/",$server_name."/ppd"); + function set_acl_base($base) + { + plugin::set_acl_base($base); + if(is_object($this->netConfigDNS)){ + $this->netConfigDNS->set_acl_base($base); + } } - /* Extract selected ppd */ - if(isset($this->gotoPrinterPPD)){ - $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD); + function set_acl_category($cat) + { + plugin::set_acl_category($cat); + if(is_object($this->netConfigDNS)){ + $this->netConfigDNS->set_acl_category($cat); + } } - $this->initial_PPD = $this->gotoPrinterPPD; + /* Detect type of printer. + * Printer can be stand alone, belong to a workstation or belong to a terminal. + * We can detect the type printer type when comparing the tabs objects + */ + function getTypeOfPrinter($UpdateAccountStatus = false) + { + /* Disable account as default + */ + $this->is_account = $this->initially_was_account = false; + + /* Detect type of printer via parent tabs. + */ + + $class = get_class($this->parent); + if(isset($this->parent->by_object['workgeneric'])){ + + /* Exclude templates + */ + $this->cn = $this->parent->by_object['workgeneric']->cn; + if($this->parent->by_object['workgeneric']->cn == "wdefault"){ + $this->BelongsTo = "WorkstationTemplate"; + }else{ + $this->BelongsTo = "Workstation"; + } + }elseif(isset($this->parent->by_object['termgeneric'])){ + + /* Exclude templates + */ + $this->cn = $this->parent->by_object['termgeneric']->cn; + if($this->parent->by_object['termgeneric']->cn == "default"){ + $this->BelongsTo = "TerminalTemplate"; + }else{ + $this->BelongsTo = "Terminal"; + } + }elseif(isset($this->parent->by_name['printgeneric'])){ + $this->BelongsTo = "Printer"; + } - /* Prepare different member types */ - foreach(array("AddUser" =>"gotoUserPrinter", - "AddGroup" =>"gotoGroupPrinter", - "AddAdminUser" =>"gotoUserAdminPrinter", - "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){ + if($UpdateAccountStatus){ - /* $this->members contains all members */ - $this->member[$type]=array(); + /* Set is_account / was account + */ + if($this->dn == "new"){ + $this->initially_was_account = false; + } - if(isset($this->attrs[$attr])){ - $ldap->cd($this->config->current['BASE']) ; - for($i = 0 ; $i < $this->attrs[$attr]['count']; $i++){ - - $mem = $this->attrs[$attr][$i]; - if(preg_match("/Group/",$type)){ - $ldap->search("(&(|(objectClass=posixGroup)(objectClass=gosaGroupOfNames))(cn=".$mem."))",array("cn","description")); - if($ldap->count()){ - $entry = $ldap->fetch(); - $this->member[$type][$entry['cn'][0]]=$entry; + /* If is printer it must be a true account. + */ + if(preg_match("/printer/i",$this->BelongsTo)){ + $this->is_account = true; + } + + /* Update dn, to ensure storing as printer instead of WS / terminal + */ + if(preg_match("/terminal/i",$this->BelongsTo)){ + $this->dn= preg_replace("/".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); + } + + if(preg_match("/workstation/i",$this->BelongsTo)){ + $this->dn= preg_replace("/".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); } - }else{ - $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid")); + + /* Detect if this is a valid printer account; + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cat($this->dn, array('objectClass')); + if($ldap->count()){ - $entry = $ldap->fetch(); - $this->member[$type][$entry['uid'][0]]=$entry; + $attrs = $ldap->fetch(); + if(in_array("gotoPrinter",$attrs['objectClass'])){ + $this->initially_was_account = true; + $this->is_account = true; + }else{ + $this->is_account = false; + } } - } } - } } - $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); - if(is_object($this->netConfigDNS)){ - $this->netConfigDNS->set_acl_base($base); - } - } - function set_acl_category($cat) - { - plugin::set_acl_category($cat); - if(is_object($this->netConfigDNS)){ - $this->netConfigDNS->set_acl_category($cat); - } - } - - /* Detect type of printer. - * Printer can be stand alone, belong to a workstation or belong to a terminal. - * We can detect the type printer type when comparing the tabs objects - */ - function getTypeOfPrinter($UpdateAccountStatus = false) - { - /* Disable account as default - */ - $this->is_account = $this->initially_was_account = false; - - /* Detect type of printer via parent tabs. - */ + function execute() + { + /* Call parent execute */ + plugin::execute(); - $class = get_class($this->parent); - if(isset($this->parent->by_object['workgeneric'])){ - - /* Exclude templates - */ - $this->cn = $this->parent->by_object['workgeneric']->cn; - if($this->parent->by_object['workgeneric']->cn == "wdefault"){ - $this->BelongsTo = "WorkstationTemplate"; - }else{ - $this->BelongsTo = "Workstation"; - } - }elseif(isset($this->parent->by_object['termgeneric'])){ - - /* Exclude templates - */ - $this->cn = $this->parent->by_object['termgeneric']->cn; - if($this->parent->by_object['termgeneric']->cn == "default"){ - $this->BelongsTo = "TerminalTemplate"; - }else{ - $this->BelongsTo = "Terminal"; - } - }elseif(isset($this->parent->by_name['printgeneric'])){ - $this->BelongsTo = "Printer"; - } + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","printer/".get_class($this),$this->dn); + } - if($UpdateAccountStatus){ - - /* Set is_account / was account - */ - if($this->dn == "new"){ - $this->initially_was_account = false; - } - - /* If is printer it must be a true account. - */ - if(preg_match("/printer/i",$this->BelongsTo)){ - $this->is_account = true; - } - - /* Update dn, to ensure storing as printer instead of WS / terminal - */ - if(preg_match("/terminal/i",$this->BelongsTo)){ - $this->dn= preg_replace("/".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); - } - - if(preg_match("/workstation/i",$this->BelongsTo)){ - $this->dn= preg_replace("/".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); - } - - /* Detect if this is a valid printer account; - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cat($this->dn, array('objectClass')); - - if($ldap->count()){ - $attrs = $ldap->fetch(); - if(in_array("gotoPrinter",$attrs['objectClass'])){ - $this->initially_was_account = true; - $this->is_account = true; - }else{ - $this->is_account = false; + /* If type of printer couldn't be detected (because of missing parent object in construction) + * hide this tab. + */ + if(preg_match("/unknown/i",$this->BelongsTo)){ + $display= $this->show_enable_header(_("Add printer extension"), + _("Could not initialize printer tab, parameter parent was missing while construction."),TRUE,TRUE); + return($display); } - } - } - } - function execute() - { - /* Call parent execute */ - plugin::execute(); + /* Templates can't have printer extensions + */ + if(preg_match("/WorkstationTemplate/i",$this->BelongsTo)){ + $display= $this->show_enable_header(_("Add printer extension"), + _("This is a workstation template, printer tab is disabled."),TRUE,TRUE); + return($display); + } + if(preg_match("/TerminalTemplate/i",$this->BelongsTo)){ + $display= $this->show_enable_header(_("Add printer extension"), + _("This is a terminal template, printer tab is disabled."),TRUE,TRUE); + return($display); + } - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","printer/".get_class($this),$this->dn); - } + /* Get cn from base object */ + if(preg_match("/^Workstation$/i",$this->BelongsTo)){ + $this->cn = $this->parent->by_object['workgeneric']->cn; + } + if(preg_match("/^Terminal$/i",$this->BelongsTo)){ + $this->cn = $this->parent->by_object['termgeneric']->cn; + } - /* If type of printer couldn't be detected (because of missing parent object in construction) - * hide this tab. - */ - if(preg_match("/unknown/i",$this->BelongsTo)){ - $display= $this->show_enable_header(_("Add printer extension"), - _("Could not initialize printer tab, parameter parent was missing while construction."),TRUE,TRUE); - return($display); - } + $smarty= get_smarty(); - /* Templates can't have printer extensions - */ - if(preg_match("/WorkstationTemplate/i",$this->BelongsTo)){ - $display= $this->show_enable_header(_("Add printer extension"), - _("This is a workstation template, printer tab is disabled."),TRUE,TRUE); - return($display); - } - if(preg_match("/TerminalTemplate/i",$this->BelongsTo)){ - $display= $this->show_enable_header(_("Add printer extension"), - _("This is a terminal template, printer tab is disabled."),TRUE,TRUE); - return($display); - } - /* Get cn from base object */ - if(preg_match("/^Workstation$/i",$this->BelongsTo)){ - $this->cn = $this->parent->by_object['workgeneric']->cn; - } - if(preg_match("/^Terminal$/i",$this->BelongsTo)){ - $this->cn = $this->parent->by_object['termgeneric']->cn; - } + /* Assign acls */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL", $this->getacl($name)); + } - $smarty= get_smarty(); + $display=""; + /* Tell smarty if this is a standalone object or a terminal / WS depending printer */ + if(preg_match("/^Printer$/i",$this->BelongsTo)){ + $smarty->assign("StandAlone",true); + }else{ + $smarty->assign("StandAlone",false); + } - /* Assign acls */ - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL", $this->getacl($name)); - } + /* Do we need to flip is_account state? */ + if(isset($_POST['modify_state'])){ + if($this->is_account && $this->acl_is_removeable()){ + $this->is_account= FALSE; + }elseif(!$this->is_account && $this->acl_is_createable()){ + $this->is_account= TRUE; + } + } - $display=""; + /* Do we represent a valid printer? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + msgPool::noValidExtension(_("printer")).""; + return($display); + } - /* Tell smarty if this is a standalone object or a terminal / WS depending printer */ - if(preg_match("/^Printer$/i",$this->BelongsTo)){ - $smarty->assign("StandAlone",true); - }else{ - $smarty->assign("StandAlone",false); - } + /* If this is a WS / Terminal depending printer, display account state button */ + if(!preg_match("/^Printer$/i",$this->BelongsTo)){ + if($this->cn == "" && ($this->dn != "new")){ + $display= $this->show_enable_header(_("Add printer extension"), + msgPool::featuresDisabled(_("printer"))._("You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template."),TRUE,TRUE); + $this->is_account= false; + return $display; + } - /* Do we need to flip is_account state? */ - if(isset($_POST['modify_state'])){ - if($this->is_account && $this->acl_is_removeable()){ - $this->is_account= FALSE; - }elseif(!$this->is_account && $this->acl_is_createable()){ - $this->is_account= TRUE; - } - } + if (($this->is_account)){ + if(preg_match("/^Workstation$/i",$this->BelongsTo)){ + $display= $this->show_disable_header(_("Remove printer extension"), + msgPool::featuresEnabled(_("printer"))); + }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){ + $display= $this->show_disable_header(_("Remove printer extension"), + msgPool::featuresDisabled(_("printer"))); + } + }else{ + if(preg_match("/^Workstation$/i",$this->BelongsTo)){ + $display= $this->show_enable_header(_("Add printer extension"), + msgPool::featuresEnabled(_("printer"))); + }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){ + $display= $this->show_enable_header(_("Add printer extension"), + msgPool::featuresDisabled(_("printer"))); + } + return ($display); + } + } - /* Do we represent a valid printer? */ - if (!$this->is_account && $this->parent === NULL){ - $display= "\"\" ". - msgPool::noValidExtension(_("printer")).""; - return($display); - } + /* Assign attributes */ + foreach ($this->attributes as $attr){ + $smarty->assign("$attr", $this->$attr); + } - /* If this is a WS / Terminal depending printer, display account state button */ - if(!preg_match("/^Printer$/i",$this->BelongsTo)){ - if($this->cn == "" && ($this->dn != "new")){ - $display= $this->show_enable_header(_("Add printer extension"), - msgPool::featuresDisabled(_("printer"))._("You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template."),TRUE,TRUE); - $this->is_account= false; - return $display; - } + $smarty->assign("base", $this->baseSelector->render()); - if (($this->is_account)){ - if(preg_match("/^Workstation$/i",$this->BelongsTo)){ - $display= $this->show_disable_header(_("Remove printer extension"), - msgPool::featuresEnabled(_("printer"))); - }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){ - $display= $this->show_disable_header(_("Remove printer extension"), - msgPool::featuresDisabled(_("printer"))); + // Act on add user/grouo requests + if(isset($_POST['AddUser'])){ + $this->userSelect = new userGroupSelect($this->config, get_userinfo()); + $this->dialog = TRUE; + } + if(isset($_POST['AddAdminUser'])){ + $this->adminUserSelect = new userGroupSelect($this->config, get_userinfo()); + $this->dialog = TRUE; } - }else{ - if(preg_match("/^Workstation$/i",$this->BelongsTo)){ - $display= $this->show_enable_header(_("Add printer extension"), - msgPool::featuresEnabled(_("printer"))); - }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){ - $display= $this->show_enable_header(_("Add printer extension"), - msgPool::featuresDisabled(_("printer"))); - } - return ($display); - } - } - /* Assign attributes */ - foreach ($this->attributes as $attr){ - $smarty->assign("$attr", $this->$attr); - } + /* Display ppd configure/select dialog */ + if(isset($_POST['EditDriver'])){ + if($this->PPDdialogToSave && is_object($this->PPDdialogToSave)){ + $this->dialog = $this->PPDdialogToSave; + }else{ + + if(is_array($this->gotoPrinterPPD)){ + $this->dialog = new printerPPDDialog($this->config, $this->dn,""); + }else{ + $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD); + } + $this->dialog->cn= $this->cn; + } - $smarty->assign("base", $this->baseSelector->render()); + // Detect edit acl base + $ldap = $this->config->get_ldap_link(); + if($ldap->dn_exists($this->dn)){ + $acl_base = $this->dn; + }else{ + $acl_base = $this->base; + } - // Act on add user/grouo requests - if(isset($_POST['AddUser'])){ - $this->userSelect = new userGroupSelect($this->config, get_userinfo()); - $this->dialog = TRUE; - } - if(isset($_POST['AddAdminUser'])){ - $this->adminUserSelect = new userGroupSelect($this->config, get_userinfo()); - $this->dialog = TRUE; - } + $this->dialog->set_acl_base($acl_base); + } - /* Display ppd configure/select dialog */ - if(isset($_POST['EditDriver'])){ - if($this->PPDdialogToSave && is_object($this->PPDdialogToSave)){ - $this->dialog = $this->PPDdialogToSave; - }else{ - - if(is_array($this->gotoPrinterPPD)){ - $this->dialog = new printerPPDDialog($this->config, $this->dn,""); - }else{ - $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD); + /* remove ppd */ + if(isset($_POST['RemoveDriver'])){ + /* Detect PPD server part */ + if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){ + $method="https://"; + }else{ + $method="http://"; + } + + /* Get servername */ + $server = $_SERVER['SERVER_NAME']; + if(tests::is_ip($server)){ + $server_name = @gethostbyaddr($server); + }else{ + $server_name = @gethostbyaddr(gethostbyname($server)); + } + $this->ppdServerPart = $method.str_replace("//","/",$server_name."/ppd"); + $this->gotoPrinterPPD = array(); + $this->PPDdialogToSave = NULL; } - $this->dialog->cn= $this->cn; - } - // Detect edit acl base - $ldap = $this->config->get_ldap_link(); - if($ldap->dn_exists($this->dn)){ - $acl_base = $this->dn; - }else{ - $acl_base = $this->base; - } + /* Close ppd dialog */ + if(isset($_POST['ClosePPD'])){ + unset($this->dialog); + $this->dialog=FALSE; + } - $this->dialog->set_acl_base($acl_base); - } + /* Save selected ppd */ + if(isset($_POST['SavePPD'])){ + $this->dialog->save_object(); + if(count($this->dialog->check())){ + foreach($this->dialog->check() as $msg){ + msg_dialog::display(_("Error"), $msg, ERROR_DIALOG); + } + }else{ + $this->gotoPrinterPPD = array(); + $this->gotoPrinterPPD = $this->dialog->save(); + $this->PPDdialogToSave = $this->dialog; + unset($this->dialog); + $this->dialog=FALSE; + } + } - /* remove ppd */ - if(isset($_POST['RemoveDriver'])){ - /* Detect PPD server part */ - if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){ - $method="https://"; - }else{ - $method="http://"; - } - - /* Get servername */ - $server = $_SERVER['SERVER_NAME']; - if(tests::is_ip($server)){ - $server_name = @gethostbyaddr($server); - }else{ - $server_name = @gethostbyaddr(gethostbyname($server)); - } - $this->ppdServerPart = $method.str_replace("//","/",$server_name."/ppd"); - $this->gotoPrinterPPD = array(); - $this->PPDdialogToSave = NULL; - } + /* Member management, delete user / group / admin ..*/ + if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ + foreach($_POST['UserMember'] as $mem){ + $this->DelMember('AddUser',$mem); + } + } - /* Close ppd dialog */ - if(isset($_POST['ClosePPD'])){ - unset($this->dialog); - $this->dialog=FALSE; - } + if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ + foreach($_POST['UserMember'] as $mem){ + $this->DelMember('AddGroup',$mem); + } + } - /* Save selected ppd */ - if(isset($_POST['SavePPD'])){ - $this->dialog->save_object(); - if(count($this->dialog->check())){ - foreach($this->dialog->check() as $msg){ - msg_dialog::display(_("Error"), $msg, ERROR_DIALOG); - } - }else{ - $this->gotoPrinterPPD = array(); - $this->gotoPrinterPPD = $this->dialog->save(); - $this->PPDdialogToSave = $this->dialog; - unset($this->dialog); - $this->dialog=FALSE; - } - } + if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ + foreach($_POST['AdminMember'] as $mem){ + $this->DelMember('AddAdminUser',$mem); + } + } - /* Member management, delete user / group / admin ..*/ - if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ - foreach($_POST['UserMember'] as $mem){ - $this->DelMember('AddUser',$mem); - } - } + if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ + foreach($_POST['AdminMember'] as $mem){ + $this->DelMember('AddAdminGroup',$mem); + } + } - if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ - foreach($_POST['UserMember'] as $mem){ - $this->DelMember('AddGroup',$mem); - } - } + // Abort user / group adding dialog + if(isset($_POST['userGroupSelect_cancel'])){ + $this->dialog=FALSE; + $this->userSelect = NULL; + $this->adminUserSelect = NULL; + } - if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ - foreach($_POST['AdminMember'] as $mem){ - $this->DelMember('AddAdminUser',$mem); - } - } + // Save selected users / groups + if(isset($_POST['userGroupSelect_save'])){ + $users = array(); + if($this->userSelect instanceOf userGroupSelect){ + $users = $this->userSelect->save(); + $add = ''; + }elseif($this->adminUserSelect instanceOf userGroupSelect){ + $users = $this->adminUserSelect->save(); + $add = 'Admin'; + } + foreach($users as $user){ + if(in_array('gosaAccount', $user['objectClass'])){ + $type = 'Add'.$add.'User'; + }else{ + $type = 'Add'.$add.'Group'; + } + $this->AddMember($type, $user['dn']); + } + $this->dialog=FALSE; + $this->userSelect = NULL; + $this->adminUserSelect = NULL; + } - if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ - foreach($_POST['AdminMember'] as $mem){ - $this->DelMember('AddAdminGroup',$mem); - } - } + // Display add user/group dialogs + if($this->userSelect instanceOf userGroupSelect || $this->adminUserSelect instanceOf userGroupSelect){ - // Abort user / group adding dialog - if(isset($_POST['userGroupSelect_cancel'])){ - $this->dialog=FALSE; - $this->userSelect = NULL; - $this->adminUserSelect = NULL; - } + // Build up blocklist + $used = array(); + foreach($this->member as $type => $members){ + foreach($members as $member){ + $used['dn'][] = $member['dn']; + } + } + session::set('filterBlacklist', $used); + if($this->userSelect instanceOf userGroupSelect){ + return($this->userSelect->execute()); + }elseif($this->adminUserSelect instanceOf userGroupSelect){ + return($this->adminUserSelect->execute()); + } + } - // Save selected users / groups - if(isset($_POST['userGroupSelect_save'])){ - $users = array(); - if($this->userSelect instanceOf userGroupSelect){ - $users = $this->userSelect->save(); - $add = ''; - }elseif($this->adminUserSelect instanceOf userGroupSelect){ - $users = $this->adminUserSelect->save(); - $add = 'Admin'; - } - foreach($users as $user){ - if(in_array('gosaAccount', $user['objectClass'])){ - $type = 'Add'.$add.'User'; + + /* Display dialog, if there is currently one open*/ + if(is_object($this->dialog)){ + $this->dialog->save_object(); + $display = $this->dialog->execute(); + return $display; + } + + /* Parse selected ppd file */ + $config = session::get('config'); + if ($config->get_cfg_value("core","ppdPath") != ""){ + $path = $config->get_cfg_value("core","ppdPath"); + if(!preg_match("/\/$/",$path)){ + $path = $path."/"; + } + + $ppdManager= new ppdManager($path); + $smarty->assign("displayServerPath",true); + if(!empty($this->gotoPrinterPPD)){ + if((!file_exists($path.$this->gotoPrinterPPD))){ + $smarty->assign("driverInfo", "".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD).""); + }else{ + $ppdDesc = $ppdManager->loadDescription($path.$this->gotoPrinterPPD); + $smarty->assign("driverInfo", $ppdDesc['name']); + } + }else{ + $smarty->assign("driverInfo", _("Not defined")); + $smarty->assign("displayServerPath",false); + } }else{ - $type = 'Add'.$add.'Group'; + $smarty->assign("driverInfo",_("Can't get ppd informations.")); + $smarty->assign("displayServerPath",true); } - $this->AddMember($type, $user['dn']); - } - $this->dialog=FALSE; - $this->userSelect = NULL; - $this->adminUserSelect = NULL; - } + $smarty->assign("ppdServerPart",$this->ppdServerPart); - // Display add user/group dialogs - if($this->userSelect instanceOf userGroupSelect || $this->adminUserSelect instanceOf userGroupSelect){ - - // Build up blocklist - $used = array(); - foreach($this->member as $type => $members){ - foreach($members as $member){ - $used['dn'][] = $member['dn']; - } - } - session::set('filterBlacklist', $used); - if($this->userSelect instanceOf userGroupSelect){ - return($this->userSelect->execute()); - }elseif($this->adminUserSelect instanceOf userGroupSelect){ - return($this->adminUserSelect->execute()); - } - } + /* Create user & admin user list */ + $list=$this->generateList(); + $userlist = array_merge($list['AddUser'],$list['AddGroup']); + $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']); - /* Display dialog, if there is currently one open*/ - if(is_object($this->dialog)){ - $this->dialog->save_object(); - $display = $this->dialog->execute(); - return $display; - } + asort($userlist); + asort($adminlist); - /* Parse selected ppd file */ - $config = session::get('config'); - if ($config->get_cfg_value("core","ppdPath") != ""){ - $path = $config->get_cfg_value("core","ppdPath"); - if(!preg_match("/\/$/",$path)){ - $path = $path."/"; - } - - $ppdManager= new ppdManager($path); - $smarty->assign("displayServerPath",true); - if(!empty($this->gotoPrinterPPD)){ - if((!file_exists($path.$this->gotoPrinterPPD))){ - $smarty->assign("driverInfo", "".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD).""); + if(!preg_match("/Printer/i",$this->BelongsTo)){ + if(preg_match("/Terminal/i",$this->BelongsTo)){ + $smarty->assign("desc" ,sprintf(_("This printer belongs to %s. You can't rename this printer."),_("terminal"),"".$this->cn."")); + }else{ + $smarty->assign("desc" ,sprintf(_("This printer belongs to %s. You can't rename this printer."),_("workstation"),"".$this->cn."")); + } + $smarty->assign("cnACL" , $this->getacl("cn",true)); }else{ - $ppdDesc = $ppdManager->loadDescription($path.$this->gotoPrinterPPD); - $smarty->assign("driverInfo", $ppdDesc['name']); - } - }else{ - $smarty->assign("driverInfo", _("Not defined")); - $smarty->assign("displayServerPath",false); - } - }else{ - $smarty->assign("driverInfo",_("Can't get ppd informations.")); - $smarty->assign("displayServerPath",true); - } - $smarty->assign("ppdServerPart",$this->ppdServerPart); - - - /* Create user & admin user list */ - $list=$this->generateList(); - $userlist = array_merge($list['AddUser'],$list['AddGroup']); - $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']); - - asort($userlist); - asort($adminlist); - - if(!preg_match("/Printer/i",$this->BelongsTo)){ - if(preg_match("/Terminal/i",$this->BelongsTo)){ - $smarty->assign("desc" ,sprintf(_("This printer belongs to %s. You can't rename this printer."),_("terminal"),"".$this->cn."")); - }else{ - $smarty->assign("desc" ,sprintf(_("This printer belongs to %s. You can't rename this printer."),_("workstation"),"".$this->cn."")); - } - $smarty->assign("cnACL" , $this->getacl("cn",true)); - }else{ - $smarty->assign("desc" ,""); - } - $smarty->assign("UserMember" ,$this->UserMember); - $smarty->assign("UserMembers" ,$userlist); - $smarty->assign("UserMemberKeys",array_flip($userlist)); - - $smarty->assign("AdminMember" ,$this->AdminMember); - $smarty->assign("AdminMembers" ,$adminlist); - $smarty->assign("AdminMemberKeys",array_flip($adminlist)); - if(preg_match("/Printer/i",$this->BelongsTo)){ - - /* Show main page */ - $str = $this->netConfigDNS->execute(); - if(is_object($this->netConfigDNS->dialog)){ - return($str); - } - $smarty->assign("netconfig", $str); - } else { - $smarty->assign("netconfig", ""); - } + $smarty->assign("desc" ,""); + } + $smarty->assign("UserMember" ,$this->UserMember); + $smarty->assign("UserMembers" ,$userlist); + $smarty->assign("UserMemberKeys",array_flip($userlist)); + + $smarty->assign("AdminMember" ,$this->AdminMember); + $smarty->assign("AdminMembers" ,$adminlist); + $smarty->assign("AdminMemberKeys",array_flip($adminlist)); + if(preg_match("/Printer/i",$this->BelongsTo)){ + + /* Show main page */ + $str = $this->netConfigDNS->execute(); + if(is_object($this->netConfigDNS->dialog)){ + return($str); + } + $smarty->assign("netconfig", $str); + } else { + $smarty->assign("netconfig", ""); + } - return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE, dirname(__FILE__)))); - } - - function remove_from_parent() - { - /* Only remove if there was initially an account */ - if($this->initially_was_account){ - - /* Update dn, to ensure storing as printer instead of WS / terminal - */ - if(preg_match("/terminal/i",$this->BelongsTo)){ - $this->dn= preg_replace("/".preg_quote(get_ou("termgeneric", "terminalRDN"), '/').",/i",get_ou("printgeneric", "printerRDN"),$this->dn); - } - - if(preg_match("/workstation/i",$this->BelongsTo)){ - $this->dn= preg_replace("/".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); - } - - /* Check if this dn points to a printer, to avoid deleting something else */ - $ldap= $this->config->get_ldap_link(); - $ldap->cat($this->dn, array('dn',"objectClass")); - if(!$ldap->count()){ - msg_dialog::display(_("Error"), _("Object is no printer!"), ERROR_DIALOG); - return; - } - - /* Check if obejct is a printer */ - $CheckPrinter = $ldap->fetch(); - if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){ - msg_dialog::display(_("Error"), _("Object is no printer!"), ERROR_DIALOG); - return; - } - - /* Remove account & dns extension */ - $this->netConfigDNS->remove_from_parent(); - $ldap->rmdir($this->dn); - - new log("remove","printer/".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_DEL, get_class())); - } - $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - - /* Delete references to object groups */ - $ldap->cd ($this->config->current['BASE']); - $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn")); - while ($ldap->fetch()){ - $og= new ogroup($this->config, $ldap->getDN()); - unset($og->member[$this->dn]); - $og->save (); - } - - /* Remove previously selected ppd file.*/ - if(!empty($this->initial_PPD)){ - $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD); - $tmp->removeModifiedPPD(); - } + return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE, dirname(__FILE__)))); } - } + function remove_from_parent() + { + /* Only remove if there was initially an account */ + if($this->initially_was_account){ - /* 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; - - if(isset($_POST['ppdServerPart'])){ - $this->ppdServerPart = get_post('ppdServerPart'); - } + /* Update dn, to ensure storing as printer instead of WS / terminal + */ + if(preg_match("/terminal/i",$this->BelongsTo)){ + $this->dn= preg_replace("/".preg_quote(get_ou("termgeneric", "terminalRDN"), '/').",/i",get_ou("printgeneric", "printerRDN"),$this->dn); + } - if(is_object($this->netConfigDNS)){ - $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; - } - } + if(preg_match("/workstation/i",$this->BelongsTo)){ + $this->dn= preg_replace("/".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); + } - } + /* Check if this dn points to a printer, to avoid deleting something else */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($this->dn, array('dn',"objectClass")); + if(!$ldap->count()){ + msg_dialog::display(_("Error"), _("Object is no printer!"), ERROR_DIALOG); + return; + } - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - if (preg_match("/printer/i",$this->BelongsTo)){ - $message= array_merge($message, $this->netConfigDNS->check()); - } + /* Check if obejct is a printer */ + $CheckPrinter = $ldap->fetch(); + if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){ + msg_dialog::display(_("Error"), _("Object is no printer!"), ERROR_DIALOG); + return; + } - /* Don't display check messages if this is a template object */ - if(isset($this->parent->by_object['workgeneric'])){ - if($this->parent->by_object['workgeneric']->cn == "wdefault"){ - return $message; - } - }elseif(isset($this->parent->by_object['termgeneric'])){ - if($this->parent->by_object['termgeneric']->cn == "default"){ - return $message; - } - } + /* Remove account & dns extension */ + $this->netConfigDNS->remove_from_parent(); + $ldap->rmdir($this->dn); - $dn= "cn=".$this->cn.get_ou("printgeneric", "printerRDN").",".$this->base; + new log("remove","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - /* must: cn */ - if(($this->BelongsTo == "Printer") && $this->cn == ""){ - $message[]= msgPool::required(_("Name")); - } + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class())); + } + $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + + /* Delete references to object groups */ + $ldap->cd ($this->config->current['BASE']); + $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn")); + while ($ldap->fetch()){ + $og= new ogroup($this->config, $ldap->getDN()); + unset($og->member[$this->dn]); + $og->save (); + } - // Check if a wrong base was supplied - if(!$this->baseSelector->checkLastBaseUpdate()){ - $message[]= msgPool::check_base(); + /* Remove previously selected ppd file.*/ + if(!empty($this->initial_PPD)){ + $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD); + $tmp->removeModifiedPPD(); + } + } } - /* must: cn */ - if(($this->BelongsTo == "Printer") && !tests::is_dns_name($this->cn)){ - $message[]= msgPool::invalid(_("Name")); - } - /* must: labeledURI */ - if(empty($this->labeledURI)){ - $message[]= msgPool::required(_("Printer URL")); - } - - /* Check if there is already an entry with this cn*/ - if (($this->orig_dn != $dn)&&( preg_match("/printer/i",$this->BelongsTo))){ - $ldap= $this->config->get_ldap_link(); - $ldap->cd ($this->base); - $ldap->ls("(cn=".$this->cn.")",get_ou("printgeneric", "printerRDN").$this->base, array("cn")); - if ($ldap->count() != 0){ - while ($attrs= $ldap->fetch()){ - if(preg_match("/cn=dhcp,/",$attrs['dn'])){ - continue; - } - if ($attrs['dn'] != $this->orig_dn){ - $message[]= msgPool::duplicated(_("Name")); - break; - } - } - } - } + /* 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; - /* 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(); - } + if(isset($_POST['ppdServerPart'])){ + $this->ppdServerPart = get_post('ppdServerPart'); + } - return ($message); - } + if(is_object($this->netConfigDNS)){ + $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 to LDAP */ - function save() - { - /* Update dn, to ensure storing as printer instead of WS / terminal - */ - if(preg_match("/terminal/i",$this->BelongsTo)){ - $this->dn= preg_replace("/".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); } - if(preg_match("/workstation/i",$this->BelongsTo)){ - $this->dn= preg_replace("/".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); - } - - if(!$this->is_account) return; - if(isset($this->parent->by_object['workgeneric'])){ - if($this->parent->by_object['workgeneric']->cn == "wdefault"){ - return; - } - - /* Adapt IP & mac from parent object */ - $this->netConfigDNS->ipHostNumber = $this->parent->by_object['workgeneric']->netConfigDNS->ipHostNumber; - $this->netConfigDNS->macAddress = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; - - }elseif(isset($this->parent->by_object['termgeneric'])){ - if($this->parent->by_object['termgeneric']->cn == "default"){ - return; - } - - /* Adapt IP & mac from parent object */ - $this->netConfigDNS->ipHostNumber = $this->parent->by_object['termgeneric']->netConfigDNS->ipHostNumber; - $this->netConfigDNS->macAddress = $this->parent->by_object['termgeneric']->netConfigDNS->macAddress; - } + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + if (preg_match("/printer/i",$this->BelongsTo)){ + $message= array_merge($message, $this->netConfigDNS->check()); + } - /* If type is still unknown, the initialisation of this printer failed, abort. */ - if(preg_match("/unknown/i",$this->BelongsTo)){ - return; - } + /* Don't display check messages if this is a template object */ + if(isset($this->parent->by_object['workgeneric'])){ + if($this->parent->by_object['workgeneric']->cn == "wdefault"){ + return $message; + } + }elseif(isset($this->parent->by_object['termgeneric'])){ + if($this->parent->by_object['termgeneric']->cn == "default"){ + return $message; + } + } - /* save ppd configuration */ - if($this->PPDdialogToSave && is_object($this->PPDdialogToSave)){ - - $this->PPDdialogToSave->save_ppd(); - - /* Rename the generated ppd to match the gzip ending '.gz', if necessary. - */ - $path = $this->config->get_cfg_value("core","ppdPath"); - if(!preg_match("/\/$/",$path)){ - $path = $path."/"; - } - $ppdManager= new ppdManager($path); - if($ppdManager->useGzip && !preg_match('/\.gz$/',$this->gotoPrinterPPD)){ - if(rename($path.$this->gotoPrinterPPD,$path.$this->gotoPrinterPPD.'.gz')){ - $this->gotoPrinterPPD .= '.gz'; - } - }elseif(!$ppdManager->useGzip && preg_match('/\.gz$/',$this->gotoPrinterPPD)){ - $new_ppd = preg_replace('/\.gz$/','',$this->gotoPrinterPPD); - if(rename($path.$this->gotoPrinterPPD,$path.$new_ppd)){ - $this->gotoPrinterPPD = $new_ppd; - } - } - } - if($this->orig_dn != $this->dn && $this->orig_dn != "new"){ - if(!empty($this->gotoPrinterPPD)) { - $this->PPDdialogToSave = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD); - $this->PPDdialogToSave->cn = $this->cn; - $this->PPDdialogToSave->generateProperties(); - $this->gotoPrinterPPD = $this->PPDdialogToSave->update_ppd_url(); - } - } + $dn= "cn=".$this->cn.get_ou("printgeneric", "printerRDN").",".$this->base; - /* Remove previously selected ppd file.*/ - if($this->initial_PPD != $this->gotoPrinterPPD && $this->initially_was_account){ - if(!empty($this->initial_PPD)){ - $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD); - $tmp->removeModifiedPPD(); - } - } + /* must: cn */ + if(($this->BelongsTo == "Printer") && $this->cn == ""){ + $message[]= msgPool::required(_("Name")); + } - /* If no ppd is selected, remove this attribute */ - if(!empty($this->gotoPrinterPPD)) { - $this->gotoPrinterPPD = $this->ppdServerPart.'/'.$this->gotoPrinterPPD; - }else{ - $this->gotoPrinterPPD = array(); - } + // Check if a wrong base was supplied + if(!$this->baseSelector->checkLastBaseUpdate()){ + $message[]= msgPool::check_base(); + } - $dn= $this->dn; + /* must: cn */ + if(($this->BelongsTo == "Printer") && !tests::is_dns_name($this->cn)){ + $message[]= msgPool::invalid(_("Name")); + } - /* reduce objectClasses to minimun */ - $this->attrs['objectClass']= $this->objectclasses; + /* must: labeledURI */ + if(empty($this->labeledURI)){ + $message[]= msgPool::required(_("Printer URL")); + } - plugin::save(); - $ldap= $this->config->get_ldap_link(); + /* Check if there is already an entry with this cn*/ + if (($this->orig_dn != $dn)&&( preg_match("/printer/i",$this->BelongsTo))){ + $ldap= $this->config->get_ldap_link(); + $ldap->cd ($this->base); + $ldap->ls("(cn=".$this->cn.")",get_ou("printgeneric", "printerRDN").$this->base, array("cn")); + if ($ldap->count() != 0){ + while ($attrs= $ldap->fetch()){ + if(preg_match("/cn=dhcp,/",$attrs['dn'])){ + continue; + } + if ($attrs['dn'] != $this->orig_dn){ + $message[]= msgPool::duplicated(_("Name")); + break; + } + } + } + } - /* 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; + /* 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(); } - $attrs[$key]= $val; - } - $this->attrs= $attrs; - } - /* Append printer user - */ - $this->attrs['gotoUserPrinter']=array(); - foreach($this->member['AddUser'] as $mem){ - $this->attrs['gotoUserPrinter'][]=$mem['uid'][0]; + return ($message); } - /* Append printer group - */ - $this->attrs['gotoGroupPrinter'] = array(); - foreach($this->member['AddGroup'] as $mem){ - $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0]; - } - /* Append printer admin user - */ - $this->attrs['gotoUserAdminPrinter'] = array(); - foreach($this->member['AddAdminUser'] as $mem){ - $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0]; - } + /* Save to LDAP */ + function save() + { + /* Update dn, to ensure storing as printer instead of WS / terminal + */ + if(preg_match("/terminal/i",$this->BelongsTo)){ + $this->dn= preg_replace("/".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); + } - /* Append printer admin group - */ - $this->attrs['gotoGroupAdminPrinter']= array(); - foreach($this->member['AddAdminGroup'] as $mem){ - $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0]; - } + if(preg_match("/workstation/i",$this->BelongsTo)){ + $this->dn= preg_replace("/".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i",get_ou("printgeneric", "printerRDN"),$this->dn); + } - if($this->orig_dn == 'new'){ - foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){ - if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){ - unset($this->attrs[$checkVar]); + if(!$this->is_account) return; + if(isset($this->parent->by_object['workgeneric'])){ + if($this->parent->by_object['workgeneric']->cn == "wdefault"){ + return; + } + + /* Adapt IP & mac from parent object */ + $this->netConfigDNS->ipHostNumber = $this->parent->by_object['workgeneric']->netConfigDNS->ipHostNumber; + $this->netConfigDNS->macAddress = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; + + }elseif(isset($this->parent->by_object['termgeneric'])){ + if($this->parent->by_object['termgeneric']->cn == "default"){ + return; + } + + /* Adapt IP & mac from parent object */ + $this->netConfigDNS->ipHostNumber = $this->parent->by_object['termgeneric']->netConfigDNS->ipHostNumber; + $this->netConfigDNS->macAddress = $this->parent->by_object['termgeneric']->netConfigDNS->macAddress; } - } - } - /* Ensure to create a new object */ - if(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$this->orig_dn)){ - $this->orig_dn = "new"; - } + /* If type is still unknown, the initialisation of this printer failed, abort. */ + if(preg_match("/unknown/i",$this->BelongsTo)){ + return; + } - /* Move object in necessary*/ - if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){ - $this->move($this->orig_dn, $this->dn); - } + /* save ppd configuration */ + if($this->PPDdialogToSave && is_object($this->PPDdialogToSave)){ - /* Write back to ldap */ - $ldap= $this->config->get_ldap_link(); - $ldap->cat($this->dn); - if(!$ldap->count()){ - $ldap->cd($this->config->current['BASE']); - $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); - $ldap->cd($this->dn); - - /* Remove empty values */ - foreach($this->attrs as $name => $value){ - if(empty($value)){ - unset($this->attrs[$name]); - } - } - - $ldap->add($this->attrs); - $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - new log("create","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - } else { - $ldap->cd($this->dn); - $this->cleanup(); - $ldap->modify ($this->attrs); - $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - new log("modify","printer/".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, 0, get_class())); - } + $this->PPDdialogToSave->save_ppd(); - #if(preg_match("/printer/i",$this->BelongsTo)){ - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->dn = $this->dn; - $this->netConfigDNS->save(); - #} - } - - function generateList(){ - $a_return=array(); - - foreach($this->member as $type => $values){ - $a_return[$type]=array(); - foreach($values as $value){ - if((preg_match("/Group/i",$type))){ - if(!isset($value['description'])){ - $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]; - }else{ - $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]"; - } + /* Rename the generated ppd to match the gzip ending '.gz', if necessary. + */ + $path = $this->config->get_cfg_value("core","ppdPath"); + if(!preg_match("/\/$/",$path)){ + $path = $path."/"; + } + $ppdManager= new ppdManager($path); + if($ppdManager->useGzip && !preg_match('/\.gz$/',$this->gotoPrinterPPD)){ + if(rename($path.$this->gotoPrinterPPD,$path.$this->gotoPrinterPPD.'.gz')){ + $this->gotoPrinterPPD .= '.gz'; + } + }elseif(!$ppdManager->useGzip && preg_match('/\.gz$/',$this->gotoPrinterPPD)){ + $new_ppd = preg_replace('/\.gz$/','',$this->gotoPrinterPPD); + if(rename($path.$this->gotoPrinterPPD,$path.$new_ppd)){ + $this->gotoPrinterPPD = $new_ppd; + } + } + } + if($this->orig_dn != $this->dn && $this->orig_dn != "new"){ + if(!empty($this->gotoPrinterPPD)) { + $this->PPDdialogToSave = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD); + $this->PPDdialogToSave->cn = $this->cn; + $this->PPDdialogToSave->generateProperties(); + $this->gotoPrinterPPD = $this->PPDdialogToSave->update_ppd_url(); + } + } + + /* Remove previously selected ppd file.*/ + if($this->initial_PPD != $this->gotoPrinterPPD && $this->initially_was_account){ + if(!empty($this->initial_PPD)){ + $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD); + $tmp->removeModifiedPPD(); + } + } + + /* If no ppd is selected, remove this attribute */ + if(!empty($this->gotoPrinterPPD)) { + $this->gotoPrinterPPD = $this->ppdServerPart.'/'.$this->gotoPrinterPPD; }else{ - $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0]; + $this->gotoPrinterPPD = array(); } - } - } - return($a_return); - } - - /* Return plugin informations for acl handling - #FIXME FAIscript seams to ununsed within this class... */ - static function plInfo() - { - return (array( - "plShortName" => _("Generic"), - "plDescription" => _("Print generic"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 4, - "plSection" => array("administration"), - "plRequirements"=> array( - 'ldapSchema' => array('gotoPrinter' => '>=2.7'), - 'onFailureDisablePlugin' => array(get_class()) - ), - "plCategory" => array("printer" => array("description" => _("Printer"), - "objectClass" => "gotoPrinter"),"workstation","terminal"), - "plProperties" => - array( - array( - "name" => "printerRDN", - "type" => "rdn", - "default" => "ou=printers,ou=systems,", - "description" => _("The 'printerRDN' statement defines the location where new printers will be created. The default is 'ou=printers,ou=systems,'."), - "check" => "gosaProperty::isRdn", - "migrate" => "migrate_printerRDN", - "group" => "plugin", - "mandatory" => FALSE - ) - ), - - "plProvidedAcls"=> array( - "cn" => _("Name"), - "base" => _("Base") , - "description" => _("Description"), - "l" => _("Location"), - "labeledURI" => _("LabeledURL"), - "macAddress" => _("Mac address"), - "gotoPrinterPPD" => _("Printer PPD"), - "gotoUserPrinter" => _("Permissions")) - )); - } - - - /* Delete member */ - function DelMember($type,$id) - { - /* Check if there was a printer "dn" given, or the "cn" */ - foreach($this->member[$type] as $key => $printer){ - if($printer['dn'] == $id) { - $id = $key; - } - } - - if(!$this->acl_is_writeable("gotoUserPrinter")){ - msg_dialog::display(_("Permission error"), msgPool::permDelete(_("printer user"), $id), INFO_DIALOG); - return(FALSE); - } - - if(isset($this->member[$type][$id])){ - unset($this->member[$type][$id]); - return(TRUE); - } - return(FALSE); - } + $dn= $this->dn; - /* Add given obejct to members */ - function AddMember($type,$dn) - { - $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup"); - if(!in_array_ics($type, $types)){ - msg_dialog::display(_("Internal error"), sprintf(_("Illegal member type '%s'!"), $type), ERROR_DIALOG); - return(FALSE); - } + /* reduce objectClasses to minimun */ + $this->attrs['objectClass']= $this->objectclasses; - if(!$this->acl_is_writeable("gotoUserPrinter")){ - msg_dialog::display(_("Permission error"), msgPool::permModify(_("printer user"), $this->dn), INFO_DIALOG); - return(FALSE); - } + plugin::save(); + $ldap= $this->config->get_ldap_link(); - /* Get name of index attributes */ - if(preg_match("/user/i",$type)){ - $var = "uid"; - }else{ - $var = "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; + } + $attrs[$key]= $val; + } + $this->attrs= $attrs; + } - $ldap = $this->config->get_ldap_link(); - $ldap->cd($dn); - $ldap->cat($dn,array($var,"cn")); - if($ldap->count()){ + /* Append printer user + */ + $this->attrs['gotoUserPrinter']=array(); + foreach($this->member['AddUser'] as $mem){ + $this->attrs['gotoUserPrinter'][]=$mem['uid'][0]; + } - $attrs = $ldap->fetch(); + /* Append printer group + */ + $this->attrs['gotoGroupPrinter'] = array(); + foreach($this->member['AddGroup'] as $mem){ + $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0]; + } - if(isset($attrs[$var][0])){ - $name = $attrs[$var][0]; + /* Append printer admin user + */ + $this->attrs['gotoUserAdminPrinter'] = array(); + foreach($this->member['AddAdminUser'] as $mem){ + $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0]; + } - /* Check if this uid/cn is already assigned to any permission */ - foreach($types as $ctype){ + /* Append printer admin group + */ + $this->attrs['gotoGroupAdminPrinter']= array(); + foreach($this->member['AddAdminGroup'] as $mem){ + $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0]; + } - /* If we want to add a user, only check user/userAdmin members */ - if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){ - continue; - } + if($this->orig_dn == 'new'){ + foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){ + if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){ + unset($this->attrs[$checkVar]); + } + } + } + + /* Ensure to create a new object */ + if(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$this->orig_dn)){ + $this->orig_dn = "new"; + } + + /* Move object in necessary*/ + if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){ + $this->move($this->orig_dn, $this->dn); + } + + /* Write back to ldap */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($this->dn); + if(!$ldap->count()){ + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + $ldap->cd($this->dn); + + /* Remove empty values */ + foreach($this->attrs as $name => $value){ + if(empty($value)){ + unset($this->attrs[$name]); + } + } - /* If we want to add a group, only check groups/adminGroups .. */ - if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){ - continue; - } + $ldap->add($this->attrs); + $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + new log("create","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + } else { + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + new log("modify","printer/".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, 0, get_class())); + } + +#if(preg_match("/printer/i",$this->BelongsTo)){ + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->dn = $this->dn; + $this->netConfigDNS->save(); +#} + } + + function generateList(){ + $a_return=array(); + + foreach($this->member as $type => $values){ + $a_return[$type]=array(); + foreach($values as $value){ + if((preg_match("/Group/i",$type))){ + if(!isset($value['description'])){ + $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]; + }else{ + $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]"; + } + }else{ + $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0]; + } + } + } + return($a_return); + } + + /* Return plugin informations for acl handling +#FIXME FAIscript seams to ununsed within this class... */ + static function plInfo() + { + return (array( + "plShortName" => _("Generic"), + "plDescription" => _("Print generic"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 4, + "plSection" => array("administration"), + "plRequirements"=> array( + 'ldapSchema' => array('gotoPrinter' => '>=2.7'), + 'onFailureDisablePlugin' => array(get_class()) + ), + "plCategory" => array("printer" => array("description" => _("Printer"), + "objectClass" => "gotoPrinter"),"workstation","terminal"), + "plProperties" => + array( + array( + "name" => "printerRDN", + "type" => "rdn", + "default" => "ou=printers,ou=systems,", + "description" => _("The 'printerRDN' statement defines the location where new printers will be created. The default is 'ou=printers,ou=systems,'."), + "check" => "gosaProperty::isRdn", + "migrate" => "migrate_printerRDN", + "group" => "plugin", + "mandatory" => FALSE + ) + ), + + "plProvidedAcls"=> array( + "cn" => _("Name"), + "base" => _("Base") , + "description" => _("Description"), + "l" => _("Location"), + "labeledURI" => _("LabeledURL"), + "macAddress" => _("Mac address"), + "gotoPrinterPPD" => _("Printer PPD"), + "gotoUserPrinter" => _("Permissions")) + )); + } + + + /* Delete member */ + function DelMember($type,$id) + { + /* Check if there was a printer "dn" given, or the "cn" */ + foreach($this->member[$type] as $key => $printer){ + if($printer['dn'] == $id) { + $id = $key; + } + } - if(isset( $this->member[$ctype][$name])){ - msg_dialog::display(_("Error"), sprintf(_("'%s' is already used!"), $attrs[$var][0]), ERROR_DIALOG); + if(!$this->acl_is_writeable("gotoUserPrinter")){ + msg_dialog::display(_("Permission error"), msgPool::permDelete(_("printer user"), $id), INFO_DIALOG); return(FALSE); - } } - /* Everything is fine. So add the given object to members */ - $this->member[$type][$attrs[$var][0]] = $attrs ; - }else{ - print_a($attrs); - } - }else{ - msg_dialog::display(_("Error"), sprintf(_("'%s' does not exist!"), $dn), ERROR_DIALOG); - return(FALSE); - } - return(TRUE); - } - - - /* Display generic part for server copy & paste */ - function getCopyDialog() - { - $vars = array("cn"); - $smarty = get_smarty(); - $smarty->assign("cn" ,$this->cn); - $smarty->assign("object","printer"); - $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']; + if(isset($this->member[$type][$id])){ + unset($this->member[$type][$id]); + return(TRUE); + } + return(FALSE); } - } - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - if(isset($source['macAddress'][0])){ - $this->netConfigDNS->macAddress = $source['macAddress'][0]; + + /* Add given obejct to members */ + function AddMember($type,$dn) + { + $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup"); + if(!in_array_ics($type, $types)){ + msg_dialog::display(_("Internal error"), sprintf(_("Illegal member type '%s'!"), $type), ERROR_DIALOG); + return(FALSE); + } + + if(!$this->acl_is_writeable("gotoUserPrinter")){ + msg_dialog::display(_("Permission error"), msgPool::permModify(_("printer user"), $this->dn), INFO_DIALOG); + return(FALSE); + } + + /* Get name of index attributes */ + if(preg_match("/user/i",$type)){ + $var = "uid"; + }else{ + $var = "cn"; + } + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($dn); + $ldap->cat($dn,array($var,"cn")); + if($ldap->count()){ + + $attrs = $ldap->fetch(); + + if(isset($attrs[$var][0])){ + $name = $attrs[$var][0]; + + /* Check if this uid/cn is already assigned to any permission */ + foreach($types as $ctype){ + + /* If we want to add a user, only check user/userAdmin members */ + if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){ + continue; + } + + /* If we want to add a group, only check groups/adminGroups .. */ + if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){ + continue; + } + + if(isset( $this->member[$ctype][$name])){ + msg_dialog::display(_("Error"), sprintf(_("'%s' is already used!"), $attrs[$var][0]), ERROR_DIALOG); + return(FALSE); + } + } + + /* Everything is fine. So add the given object to members */ + $this->member[$type][$attrs[$var][0]] = $attrs ; + }else{ + print_a($attrs); + } + }else{ + msg_dialog::display(_("Error"), sprintf(_("'%s' does not exist!"), $dn), ERROR_DIALOG); + return(FALSE); + } + return(TRUE); } - 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","printer"); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); } - $source_o = new printgeneric($this->config,$source['dn'],NULL,$this->parent); - foreach($this->attributes as $attr){ - $this->$attr = $source_o->$attr; + + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = $_POST['cn']; + } } - $this->member = $source_o -> member; - $this->gotoPrinterPPD = ""; - } + 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]; + } + + $source_o = new printgeneric($this->config,$source['dn'],NULL,$this->parent); + foreach($this->attributes as $attr){ + $this->$attr = $source_o->$attr; + } + $this->member = $source_o -> member; + + $this->gotoPrinterPPD = ""; + } - 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/goto/admin/systems/goto/class_terminalGeneric.inc b/gosa-plugins/goto/admin/systems/goto/class_terminalGeneric.inc index d650dcb1e..3ac55b867 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_terminalGeneric.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_terminalGeneric.inc @@ -2,747 +2,747 @@ class termgeneric extends plugin { - /* Generic terminal attributes */ - var $gotoMode= "locked"; - var $gotoTerminalPath= ""; - var $gotoSwapServer= ""; - var $gotoSyslogServer= ""; - var $gotoSyslogServers = array(); - var $gotoNtpServer= array(); - var $gotoNtpServers= array(); - var $gotoSndModule= ""; - var $gotoFloppyEnable= ""; - var $gotoCdromEnable= ""; - var $ghCpuType= "-"; - var $ghMemSize= "-"; - var $ghUsbSupport= "-"; - var $ghNetNic= array(); - var $ghIdeDev= array(); - var $ghScsiDev= array(); - var $ghGfxAdapter= "-"; - var $ghSoundAdapter= "-"; - var $gotoLastUser= "-"; - var $netConfigDNS; - var $auto_activate= FALSE; - - /* Needed values and lists */ - var $base= ""; - var $cn= ""; - var $description= ""; - var $orig_dn= ""; - var $orig_cn= ""; - var $orig_base= ""; - - var $inheritTimeServer = true; - - /* Plugin side filled */ - var $modes= array(); - var $baseSelector; - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes= array("gotoMode", "gotoTerminalPath", - "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer", - "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule", - "ghCpuType", "ghMemSize","ghUsbSupport", "description", - "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser"); - var $objectclasses= array("top", "gotoTerminal", "GOhard"); - - var $validActions = array("reboot" => "", "rescan" => "", "wake" => "", "memcheck" => "", "sysinfo" => ""); - - var $fai_activated = FALSE; - var $view_logged = FALSE; - - var $member_of_ogroup = FALSE; - - var $kerberos_key_service = NULL; - - - function termgeneric (&$config, $dn= NULL, $parent= NULL) - { - /* Check if FAI is activated */ - $this->fai_activated = $config->pluginEnabled("faiManagement"); - - plugin::plugin ($config, $dn, $parent); - - if(class_available("krbHostKeys")){ - $this->kerberos_key_service = new krbHostKeys($this->config,$this); - } + /* Generic terminal attributes */ + var $gotoMode= "locked"; + var $gotoTerminalPath= ""; + var $gotoSwapServer= ""; + var $gotoSyslogServer= ""; + var $gotoSyslogServers = array(); + var $gotoNtpServer= array(); + var $gotoNtpServers= array(); + var $gotoSndModule= ""; + var $gotoFloppyEnable= ""; + var $gotoCdromEnable= ""; + var $ghCpuType= "-"; + var $ghMemSize= "-"; + var $ghUsbSupport= "-"; + var $ghNetNic= array(); + var $ghIdeDev= array(); + var $ghScsiDev= array(); + var $ghGfxAdapter= "-"; + var $ghSoundAdapter= "-"; + var $gotoLastUser= "-"; + var $netConfigDNS; + var $auto_activate= FALSE; + + /* Needed values and lists */ + var $base= ""; + var $cn= ""; + var $description= ""; + var $orig_dn= ""; + var $orig_cn= ""; + var $orig_base= ""; + + var $inheritTimeServer = true; + + /* Plugin side filled */ + var $modes= array(); + var $baseSelector; + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes= array("gotoMode", "gotoTerminalPath", + "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer", + "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule", + "ghCpuType", "ghMemSize","ghUsbSupport", "description", + "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser"); + var $objectclasses= array("top", "gotoTerminal", "GOhard"); + + var $validActions = array("reboot" => "", "rescan" => "", "wake" => "", "memcheck" => "", "sysinfo" => ""); + + var $fai_activated = FALSE; + var $view_logged = FALSE; + + var $member_of_ogroup = FALSE; + + var $kerberos_key_service = NULL; + + + function termgeneric (&$config, $dn= NULL, $parent= NULL) + { + /* Check if FAI is activated */ + $this->fai_activated = $config->pluginEnabled("faiManagement"); + + plugin::plugin ($config, $dn, $parent); + + if(class_available("krbHostKeys")){ + $this->kerberos_key_service = new krbHostKeys($this->config,$this); + } - if(!isset($this->parent->by_object['ogroup'])){ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->config->current['BASE']); - $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))",array("cn")); - $this->member_of_ogroup = $ldap->count() >= 1; - } + if(!isset($this->parent->by_object['ogroup'])){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))",array("cn")); + $this->member_of_ogroup = $ldap->count() >= 1; + } - $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses); - $this->netConfigDNS->MACisMust =TRUE; - - /* Read arrays */ - foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){ - if (!isset($this->attrs[$val])){ - continue; - } - for ($i= 0; $i<$this->attrs[$val]['count']; $i++){ - array_push($this->$val, $this->attrs[$val][$i]); - } - } + $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses); + $this->netConfigDNS->MACisMust =TRUE; - /* Create used ntp server array */ - $this->gotoNtpServer= array(); - if(isset($this->attrs['gotoNtpServer'])){ - $this->inheritTimeServer = false; - for($i = 0 ; $i < $this->attrs['gotoNtpServer']['count']; $i++ ){ - $server = $this->attrs['gotoNtpServer'][$i]; - $this->gotoNtpServer[$server] = $server; - } - } + /* Read arrays */ + foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){ + if (!isset($this->attrs[$val])){ + continue; + } + for ($i= 0; $i<$this->attrs[$val]['count']; $i++){ + array_push($this->$val, $this->attrs[$val][$i]); + } + } - /* Set inherit checkbox state */ - if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){ - $this->inheritTimeServer = true; - $this->gotoNtpServer=array(); - } + /* Create used ntp server array */ + $this->gotoNtpServer= array(); + if(isset($this->attrs['gotoNtpServer'])){ + $this->inheritTimeServer = false; + for($i = 0 ; $i < $this->attrs['gotoNtpServer']['count']; $i++ ){ + $server = $this->attrs['gotoNtpServer'][$i]; + $this->gotoNtpServer[$server] = $server; + } + } - /* You can't inherit the NTP service, if we are not member in an object group */ - if(!$this->member_of_ogroup){ - $this->inheritTimeServer = FALSE; - } + /* Set inherit checkbox state */ + if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){ + $this->inheritTimeServer = true; + $this->gotoNtpServer=array(); + } - /* Create available ntp options */ - $this->gotoNtpServers = $this->config->data['SERVERS']['NTP']; - foreach($this->gotoNtpServers as $key => $server){ - if($server == "default"){ - unset($this->gotoNtpServers[$key]); - } - } + /* You can't inherit the NTP service, if we are not member in an object group */ + if(!$this->member_of_ogroup){ + $this->inheritTimeServer = FALSE; + } - $this->modes["locked"]= _("Locked"); - $this->modes["active"]= _("Activated"); - - /* 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); - } 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("termgeneric", "terminalRDN"), '/')."/i", "", $this->dn); - } + /* Create available ntp options */ + $this->gotoNtpServers = $this->config->data['SERVERS']['NTP']; + foreach($this->gotoNtpServers as $key => $server){ + if($server == "default"){ + unset($this->gotoNtpServers[$key]); + } + } + + $this->modes["locked"]= _("Locked"); + $this->modes["active"]= _("Activated"); + + /* 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); + } 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("termgeneric", "terminalRDN"), '/')."/i", "", $this->dn); + } - /* Create an array of all Syslog servers */ - $tmp = $this->config->data['SERVERS']['SYSLOG']; - foreach($tmp as $server){ - $visible = $server; - if($server == "default" && $this->member_of_ogroup) { - $visible = "["._("inherited")."]"; - } - $this->gotoSyslogServers[$server] = $visible; + /* Create an array of all Syslog servers */ + $tmp = $this->config->data['SERVERS']['SYSLOG']; + foreach($tmp as $server){ + $visible = $server; + if($server == "default" && $this->member_of_ogroup) { + $visible = "["._("inherited")."]"; + } + $this->gotoSyslogServers[$server] = $visible; + } + + $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); } - $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_category($cat) - { - plugin::set_acl_category($cat); - $this->netConfigDNS->set_acl_category($cat); - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","terminal/".get_class($this),$this->dn); + function set_acl_base($base) + { + plugin::set_acl_base($base); + $this->netConfigDNS->set_acl_base($base); } - /* Do we need to flip is_account state? */ - if (isset($_POST['modify_state'])){ - $this->is_account= !$this->is_account; + function set_acl_category($cat) + { + plugin::set_acl_category($cat); + $this->netConfigDNS->set_acl_category($cat); } - if (isset($_POST['action']) && $this->acl_is_writeable("FAIstate") && isset($this->validActions[$_POST['saction']])){ - $action = $_POST['saction']; - - /* Check if we have an DaemonEvent for this action */ - if(class_available("DaemonEvent_".$action)){ - $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); - } + function execute() + { + /* Call parent execute */ + plugin::execute(); - } + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","terminal/".get_class($this),$this->dn); + } - /* Do we represent a valid terminal? */ - if (!$this->is_account && $this->parent === NULL){ - $display= "\"\" ". - msgPool::noValidExtension(_("terminal")).""; - return($display); - } + /* Do we need to flip is_account state? */ + if (isset($_POST['modify_state'])){ + $this->is_account= !$this->is_account; + } - /* Add new ntp Server to our list */ - if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers'])) && $this->acl_is_writeable("gotoNtpServer")){ - $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers']; - } + if (isset($_POST['action']) && $this->acl_is_writeable("FAIstate") && isset($this->validActions[$_POST['saction']])){ + $action = $_POST['saction']; + + /* Check if we have an DaemonEvent for this action */ + if(class_available("DaemonEvent_".$action)){ + $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); + } - /* Delete selected NtpServer for list of used servers */ - if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected'])) && $this->acl_is_writeable("gotoNtpServer")){ - foreach($_POST['gotoNtpServerSelected'] as $name){ - unset($this->gotoNtpServer[$name]); - } - } + } - /* Fill templating stuff */ - $smarty= get_smarty(); + /* Do we represent a valid terminal? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + msgPool::noValidExtension(_("terminal")).""; + return($display); + } - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL",$this->getacl($name)); - } + /* Add new ntp Server to our list */ + if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers'])) && $this->acl_is_writeable("gotoNtpServer")){ + $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers']; + } - $smarty->assign("cn", $this->cn); - $smarty->assign("description", $this->description); - - /* tell smarty the inherit checkbox state */ - $smarty->assign("inheritTimeServer",$this->inheritTimeServer); - - /* Check if terminal is online */ - if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){ - $smarty->assign("actions", array( "halt" => _("Switch off"), - "reboot" => _("Reboot"), - #"memcheck" => _("Memory test"), - #"sysinfo" => _("System analysis") - )); - } else { - $smarty->assign("actions", array("wake" => _("Wake up"), - #"memcheck" => _("Memory test"), - #"sysinfo" => _("System analysis") - )); - } + /* Delete selected NtpServer for list of used servers */ + if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected'])) && $this->acl_is_writeable("gotoNtpServer")){ + foreach($_POST['gotoNtpServerSelected'] as $name){ + unset($this->gotoNtpServer[$name]); + } + } - /* Arrays */ - $smarty->assign("modes", $this->modes); + /* Fill templating stuff */ + $smarty= get_smarty(); - $tmp2 = array(); - $tmp2['!']= _("Local swap"); - foreach($this->config->data['SERVERS']['NBD'] as $server){ - if($server != "default"){ - $tmp2[$server]= $server; - }else{ - if($this->member_of_ogroup){ - $tmp2[$server]="["._("inherited")."]"; + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); } - } - } - - $smarty->assign("swapservers", $tmp2); - $tmp2 = array(); - foreach($this->config->data['SERVERS']['NFS'] as $server){ - if($server != "default"){ - $tmp2[$server]= $server; - }else{ - if($this->member_of_ogroup){ - $tmp2[$server]="["._("inherited")."]"; - } - } - } - - $smarty->assign("nfsservers", $tmp2); - $smarty->assign("syslogservers", $this->gotoSyslogServers); - - $tmp = array(); - foreach($this->gotoNtpServers as $server){ - if(!in_array($server,$this->gotoNtpServer)){ - $tmp[$server] = $server; - } - } - - $smarty->assign("ntpservers", $tmp); - $smarty->assign("fai_activated",$this->fai_activated); - /* Variables */ - foreach(array("gotoMode", "gotoTerminalPath", "gotoSwapServer","gotoSyslogServer", "gotoNtpServer") as $val){ - $smarty->assign($val."_select", $this->$val); - } - $smarty->assign("base", $this->baseSelector->render()); + $smarty->assign("cn", $this->cn); + $smarty->assign("description", $this->description); + + /* tell smarty the inherit checkbox state */ + $smarty->assign("inheritTimeServer",$this->inheritTimeServer); + + /* Check if terminal is online */ + if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){ + $smarty->assign("actions", array( "halt" => _("Switch off"), + "reboot" => _("Reboot"), +#"memcheck" => _("Memory test"), +#"sysinfo" => _("System analysis") + )); + } else { + $smarty->assign("actions", array("wake" => _("Wake up"), +#"memcheck" => _("Memory test"), +#"sysinfo" => _("System analysis") + )); + } - $smarty->assign("member_of_ogroup",$this->member_of_ogroup); + /* Arrays */ + $smarty->assign("modes", $this->modes); + + $tmp2 = array(); + $tmp2['!']= _("Local swap"); + foreach($this->config->data['SERVERS']['NBD'] as $server){ + if($server != "default"){ + $tmp2[$server]= $server; + }else{ + if($this->member_of_ogroup){ + $tmp2[$server]="["._("inherited")."]"; + } + } + } - /* Show main page */ - $str = $this->netConfigDNS->execute(); - if(is_object($this->netConfigDNS->dialog)){ - return($str); - } - $smarty->assign("netconfig", $str); + $smarty->assign("swapservers", $tmp2); + $tmp2 = array(); + foreach($this->config->data['SERVERS']['NFS'] as $server){ + if($server != "default"){ + $tmp2[$server]= $server; + }else{ + if($this->member_of_ogroup){ + $tmp2[$server]="["._("inherited")."]"; + } + } + } - /* Display kerberos host key options */ - $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("nfsservers", $tmp2); + $smarty->assign("syslogservers", $this->gotoSyslogServers); - return($smarty->fetch (get_template_path('terminal.tpl', TRUE, dirname(__FILE__)))); - } - - function remove_from_parent() - { - if($this->acl_is_removeable()){ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $ldap->cat($this->dn, array('dn')); - if($ldap->count()){ - $this->netConfigDNS->remove_from_parent(); - $ldap->rmDir($this->dn); - - new log("remove","terminal/".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_DEL, get_class())); + $tmp = array(); + foreach($this->gotoNtpServers as $server){ + if(!in_array($server,$this->gotoNtpServer)){ + $tmp[$server] = $server; + } } - /* Remove kerberos key dependencies too */ - if(is_object($this->kerberos_key_service)){ - $this->kerberos_key_service->remove_from_parent_by_prefix("host/"); + $smarty->assign("ntpservers", $tmp); + $smarty->assign("fai_activated",$this->fai_activated); + + /* Variables */ + foreach(array("gotoMode", "gotoTerminalPath", "gotoSwapServer","gotoSyslogServer", "gotoNtpServer") as $val){ + $smarty->assign($val."_select", $this->$val); } + $smarty->assign("base", $this->baseSelector->render()); - /* Optionally execute a command after we're done */ - $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + $smarty->assign("member_of_ogroup",$this->member_of_ogroup); - /* 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 (); + /* Show main page */ + $str = $this->netConfigDNS->execute(); + if(is_object($this->netConfigDNS->dialog)){ + return($str); } + $smarty->assign("netconfig", $str); - /* Remove all accessTo/trust dependencies */ - update_accessTo($this->cn,""); - } + /* Display kerberos host key options */ + $smarty->assign("host_key",""); + if(is_object($this->kerberos_key_service)){ + $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/")); + } - /* 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); - } - } - } - - - /* 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; - - /* 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; - } + return($smarty->fetch (get_template_path('terminal.tpl', TRUE, dirname(__FILE__)))); } - - $this->netConfigDNS->save_object(); - /* Save terminal path to parent since it is used by termstartup, too */ - if(isset($this->parent->by_object['termstartup'])){ - $this->parent->by_object['termstartup']->gotoTerminalPath= $this->gotoTerminalPath; - } - - if(isset($_POST['termgeneric_posted'])){ - if(isset($_POST["inheritTimeServer"]) && $this->member_of_ogroup){ - $this->inheritTimeServer = true; - }else{ - $this->inheritTimeServer = false; - } - } - - if(isset($_POST["inheritAll"])){ - $this->set_everything_to_inherited(); - } + function remove_from_parent() + { + if($this->acl_is_removeable()){ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $ldap->cat($this->dn, array('dn')); + if($ldap->count()){ + $this->netConfigDNS->remove_from_parent(); + $ldap->rmDir($this->dn); - /* Hanle kerberos host key plugin */ - if(is_object($this->kerberos_key_service)){ - $this->kerberos_key_service->save_object_by_prefix("host/"); - } - } + new log("remove","terminal/".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_DEL, get_class())); + } - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); + /* Remove kerberos key dependencies too */ + if(is_object($this->kerberos_key_service)){ + $this->kerberos_key_service->remove_from_parent_by_prefix("host/"); + } - /* Skip IP & Mac checks if this is a template */ - if($this->cn != "default"){ - $message= array_merge($message, $this->netConfigDNS->check()); - } + /* Optionally execute a command after we're done */ + $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - /* Permissions for that base? */ - $this->dn= "cn=".$this->cn.",".get_ou("termgeneric", "terminalRDN").$this->base; + /* 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 ($this->cn == ""){ - $message[]= msgPool::required(_("Name")); - } + /* Remove all accessTo/trust dependencies */ + update_accessTo($this->cn,""); + } - // Check if a wrong base was supplied - if(!$this->baseSelector->checkLastBaseUpdate()){ - $message[]= msgPool::check_base(); + /* 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); + } + } } - /* Check if given name is a valid host/dns name */ - if(!tests::is_dns_name($this->cn) ){ - $message[] = msgPool::invalid(_("Name")); - } - if ($this->orig_dn == 'new'){ - $ldap= $this->config->get_ldap_link(); - $ldap->cd ($this->base); - - /* It is possible to have a 'default' terminal on every base */ - if($this->cn == "default"){ - $ldap->cat($this->dn); - }else{ - $ldap->search ("(&(objectClass=gotoTerminal)(cn=".$this->cn."))", array("cn")); - } - if ($ldap->count() != 0){ - while ($attrs= $ldap->fetch()){ - if (preg_match("/cn=dhcp,/",$attrs['dn']) || preg_match ("/,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $ldap->getDN())){ - continue; - } else { - if ($attrs['dn'] != $this->orig_dn){ - $message[]= msgPool::duplicated(_("Name")); - break; + /* 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; + + /* 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 for valid ntpServer selection */ - if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){ - $message[]= msgPool::required(_("NTP server")); - } + $this->netConfigDNS->save_object(); + + /* Save terminal path to parent since it is used by termstartup, too */ + if(isset($this->parent->by_object['termstartup'])){ + $this->parent->by_object['termstartup']->gotoTerminalPath= $this->gotoTerminalPath; + } + + if(isset($_POST['termgeneric_posted'])){ + if(isset($_POST["inheritTimeServer"]) && $this->member_of_ogroup){ + $this->inheritTimeServer = true; + }else{ + $this->inheritTimeServer = false; + } + } - /* 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(); + if(isset($_POST["inheritAll"])){ + $this->set_everything_to_inherited(); + } + + /* Hanle kerberos host key plugin */ + if(is_object($this->kerberos_key_service)){ + $this->kerberos_key_service->save_object_by_prefix("host/"); + } } - return ($message); - } + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); - /* 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)) || $this->auto_activate; + /* Skip IP & Mac checks if this is a template */ + if($this->cn != "default"){ + $message= array_merge($message, $this->netConfigDNS->check()); + } - /* Find proper terminal path for tftp configuration - FIXME: This is suboptimal when the default has changed to - another location! */ - if ($this->gotoTerminalPath == "default"){ - $ldap= $this->config->get_ldap_link(); + /* Permissions for that base? */ + $this->dn= "cn=".$this->cn.",".get_ou("termgeneric", "terminalRDN").$this->base; - /* Strip relevant part from dn, keep trailing ',' */ - $tmp= preg_replace("/^cn=[^,]+,".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i", "", $this->dn); - $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp); + if ($this->cn == ""){ + $message[]= msgPool::required(_("Name")); + } - /* Walk from top to base and try to load default values for - 'gotoTerminalPath'. Abort when an entry is found. */ - while (TRUE){ - $tmp= preg_replace ("/^[^,]+,/", "", $tmp); + // Check if a wrong base was supplied + if(!$this->baseSelector->checkLastBaseUpdate()){ + $message[]= msgPool::check_base(); + } - $ldap->cat("cn=default,".get_ou("termgeneric", "terminalRDN").$tmp. - $this->config->current['BASE'], array('gotoTerminalPath')); - $attrs= $ldap->fetch(); - if (isset($attrs['gotoTerminalPath'])){ - $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0]; - break; + /* Check if given name is a valid host/dns name */ + if(!tests::is_dns_name($this->cn) ){ + $message[] = msgPool::invalid(_("Name")); } - /* Nothing left? */ - if ($tmp == ""){ - break; + if ($this->orig_dn == 'new'){ + $ldap= $this->config->get_ldap_link(); + $ldap->cd ($this->base); + + /* It is possible to have a 'default' terminal on every base */ + if($this->cn == "default"){ + $ldap->cat($this->dn); + }else{ + $ldap->search ("(&(objectClass=gotoTerminal)(cn=".$this->cn."))", array("cn")); + } + if ($ldap->count() != 0){ + while ($attrs= $ldap->fetch()){ + if (preg_match("/cn=dhcp,/",$attrs['dn']) || preg_match ("/,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $ldap->getDN())){ + continue; + } else { + if ($attrs['dn'] != $this->orig_dn){ + $message[]= msgPool::duplicated(_("Name")); + break; + } + } + } + } } - } - } - plugin::save(); + /* Check for valid ntpServer selection */ + if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){ + $message[]= msgPool::required(_("NTP server")); + } - /* Strip out 'default' values */ - foreach (array("gotoTerminalPath", "gotoSwapServer", "gotoSyslogServer") as $val){ - if(isset($this->attrs[$val])){ - if ($this->attrs[$val] == "default"){ - $this->attrs[$val]= array(); + /* 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(); } - } - } - /* Add missing arrays */ - foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){ - if (isset ($this->$val) && count ($this->$val) != 0){ - $this->attrs["$val"]= $this->$val; - } - } + 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)) || $this->auto_activate; + + /* Find proper terminal path for tftp configuration +FIXME: This is suboptimal when the default has changed to +another location! */ + if ($this->gotoTerminalPath == "default"){ + $ldap= $this->config->get_ldap_link(); + + /* Strip relevant part from dn, keep trailing ',' */ + $tmp= preg_replace("/^cn=[^,]+,".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i", "", $this->dn); + $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp); + + /* Walk from top to base and try to load default values for + 'gotoTerminalPath'. Abort when an entry is found. */ + while (TRUE){ + $tmp= preg_replace ("/^[^,]+,/", "", $tmp); + + $ldap->cat("cn=default,".get_ou("termgeneric", "terminalRDN").$tmp. + $this->config->current['BASE'], array('gotoTerminalPath')); + $attrs= $ldap->fetch(); + if (isset($attrs['gotoTerminalPath'])){ + $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0]; + break; + } + + /* Nothing left? */ + if ($tmp == ""){ + break; + } + } + } - /* 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; + plugin::save(); + + /* Strip out 'default' values */ + foreach (array("gotoTerminalPath", "gotoSwapServer", "gotoSyslogServer") as $val){ + if(isset($this->attrs[$val])){ + if ($this->attrs[$val] == "default"){ + $this->attrs[$val]= array(); + } + } } - $attrs[$key]= $val; - } - $this->attrs= $attrs; - } - /* Set ntpServers */ - $this->attrs['gotoNtpServer'] = array(); - if(!$this->inheritTimeServer){ - foreach($this->gotoNtpServer as $server){ - $this->attrs['gotoNtpServer'][] = $server; - } - } + /* Add missing arrays */ + foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){ + if (isset ($this->$val) && count ($this->$val) != 0){ + $this->attrs["$val"]= $this->$val; + } + } - /* cn=default and macAddress=- indicates that this is a template */ - if($this->cn == "default"){ - $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; + } + $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); - if (!count($this->attrs['gotoNtpServer'])){ - unset($this->attrs['gotoNtpServer']); - } - $ldap->add($this->attrs); - new log("create","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->save(); - - $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","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->save(); - - $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - - /* Update all accessTo/trust dependencies */ - if($this->orig_cn != $this->cn){ - update_accessTo($this->orig_cn,$this->cn); - } - } - - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class())); - } + /* Set ntpServers */ + $this->attrs['gotoNtpServer'] = array(); + if(!$this->inheritTimeServer){ + foreach($this->gotoNtpServer as $server){ + $this->attrs['gotoNtpServer'][] = $server; + } + } - /* Send installation activation - */ - if ($activate && class_available("DaemonEvent")){ - $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); - } - } - } - } - - - /* Display generic part for server copy & paste */ - function getCopyDialog() - { - $vars = array("cn"); - $smarty = get_smarty(); - $smarty->assign("cn" ,$this->cn); - $smarty->assign("object","terminal"); - $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']; - } - } + /* cn=default and macAddress=- indicates that this is a template */ + if($this->cn == "default"){ + $this->netConfigDNS->macAddress = "-"; + } + /* 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); + if (!count($this->attrs['gotoNtpServer'])){ + unset($this->attrs['gotoNtpServer']); + } + $ldap->add($this->attrs); + new log("create","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - 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]; + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->save(); + + $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","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->save(); + + $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + + /* Update all accessTo/trust dependencies */ + if($this->orig_cn != $this->cn){ + update_accessTo($this->orig_cn,$this->cn); + } + } + + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class())); + } + + /* Send installation activation + */ + if ($activate && class_available("DaemonEvent")){ + $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); + } + } + } } - /* Create used ntp server array */ - $this->gotoNtpServer= array(); - if(isset($source['gotoNtpServer'])){ - $this->inheritTimeServer = false; - unset($source['gotoNtpServer']['count']); - foreach($source['gotoNtpServer'] as $server){ - $this->gotoNtpServer[$server] = $server; - } + + /* Display generic part for server copy & paste */ + function getCopyDialog() + { + $vars = array("cn"); + $smarty = get_smarty(); + $smarty->assign("cn" ,$this->cn); + $smarty->assign("object","terminal"); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); } - /* Set inherit checkbox state */ - if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){ - $this->inheritTimeServer = true; - $this->gotoNtpServer=array(); + + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = $_POST['cn']; + } } - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Terminal"), - "plDescription" => _("Terminal generic"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 1, - "plSection" => array("administration"), - "plRequirements"=> array( - 'ldapSchema' => array('gotoTerminal' => '>=2.7'), - 'onFailureDisablePlugin' => array(get_class()) - ), - "plCategory" => array("terminal" => array( "description" => _("Terminal"), - "objectClass" => "gotoTerminal")), - "plProperties" => - array( - array( - "name" => "terminalRDN", - "type" => "rdn", - "default" => "ou=terminals,ou=systems,", - "description" => _("The 'terminalRDN' statement defines the location where new terminals will be created. The default is 'ou=terminals,ou=systems,'."), - "check" => "gosaProperty::isRdn", - "migrate" => "migrate_terminalRDN", - "group" => "plugin", - "mandatory" => FALSE - ) - ), - - "plProvidedAcls"=> array( - "cn" => _("Name"), - "description" => _("Description"), - "base" => _("Base"), - - "gotoMode" => _("Mode"), - "gotoSyslogServer" => _("Syslog server enabled"), - - "gotoTerminalPath" => _("Root server"), - "gotoSwapServer" => _("Swap server"), - - "gotoNtpServer" => _("Ntp server settings"), - "userPassword" => _("Root password"), - - "FAIstate" => _("Action flag")) - )); - } - - - function set_everything_to_inherited() - { - $this->gotoTerminalPath = "default"; - $this->gotoSwapServer = "default" ; - $this->gotoSyslogServer = "default"; - $this->inheritTimeServer = TRUE; - - /* Set workstation service attributes to inherited */ - if($this->member_of_ogroup && isset($this->parent->by_object['termservice'])){ - foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant","gotoXDriver", - "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){ - $this->parent->by_object['termservice']->$name = "default"; - } + + + 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]; + } + + /* Create used ntp server array */ + $this->gotoNtpServer= array(); + if(isset($source['gotoNtpServer'])){ + $this->inheritTimeServer = false; + unset($source['gotoNtpServer']['count']); + foreach($source['gotoNtpServer'] as $server){ + $this->gotoNtpServer[$server] = $server; + } + } + + /* Set inherit checkbox state */ + if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){ + $this->inheritTimeServer = true; + $this->gotoNtpServer=array(); + } } - /* Set workstation startup attributes to inherited */ - if($this->member_of_ogroup && isset($this->parent->by_object['termstartup'])){ - $this->parent->by_object['termstartup']->gotoBootKernel = "default-inherited"; - $this->parent->by_object['termstartup']->gotoLdapServer = "default-inherited"; - $this->parent->by_object['termstartup']->gotoLdap_inherit = TRUE; - $this->parent->by_object['termstartup']->gotoLdapServers = array(); + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Terminal"), + "plDescription" => _("Terminal generic"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 1, + "plSection" => array("administration"), + "plRequirements"=> array( + 'ldapSchema' => array('gotoTerminal' => '>=2.7'), + 'onFailureDisablePlugin' => array(get_class()) + ), + "plCategory" => array("terminal" => array( "description" => _("Terminal"), + "objectClass" => "gotoTerminal")), + "plProperties" => + array( + array( + "name" => "terminalRDN", + "type" => "rdn", + "default" => "ou=terminals,ou=systems,", + "description" => _("The 'terminalRDN' statement defines the location where new terminals will be created. The default is 'ou=terminals,ou=systems,'."), + "check" => "gosaProperty::isRdn", + "migrate" => "migrate_terminalRDN", + "group" => "plugin", + "mandatory" => FALSE + ) + ), + + "plProvidedAcls"=> array( + "cn" => _("Name"), + "description" => _("Description"), + "base" => _("Base"), + + "gotoMode" => _("Mode"), + "gotoSyslogServer" => _("Syslog server enabled"), + + "gotoTerminalPath" => _("Root server"), + "gotoSwapServer" => _("Swap server"), + + "gotoNtpServer" => _("Ntp server settings"), + "userPassword" => _("Root password"), + + "FAIstate" => _("Action flag")) + )); + } + + + function set_everything_to_inherited() + { + $this->gotoTerminalPath = "default"; + $this->gotoSwapServer = "default" ; + $this->gotoSyslogServer = "default"; + $this->inheritTimeServer = TRUE; + + /* Set workstation service attributes to inherited */ + if($this->member_of_ogroup && isset($this->parent->by_object['termservice'])){ + foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant","gotoXDriver", + "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){ + $this->parent->by_object['termservice']->$name = "default"; + } + } + + /* Set workstation startup attributes to inherited */ + if($this->member_of_ogroup && isset($this->parent->by_object['termstartup'])){ + $this->parent->by_object['termstartup']->gotoBootKernel = "default-inherited"; + $this->parent->by_object['termstartup']->gotoLdapServer = "default-inherited"; + $this->parent->by_object['termstartup']->gotoLdap_inherit = TRUE; + $this->parent->by_object['termstartup']->gotoLdapServers = array(); + } } - } - 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/goto/admin/systems/goto/class_terminalInfo.inc b/gosa-plugins/goto/admin/systems/goto/class_terminalInfo.inc index e16f90999..74ae843db 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_terminalInfo.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_terminalInfo.inc @@ -2,274 +2,274 @@ class terminfo extends plugin { - /* Generic terminal attributes */ - var $ghCpuType= "-"; - var $ghMemSize= "-"; - var $macAddress= "-"; - var $ghUsbSupport= "-"; - var $ghNetNic= array(); - var $ghIdeDev= array(); - var $ghScsiDev= array(); - var $ghGfxAdapter= "-"; - var $ghSoundAdapter= "-"; - var $ghInventoryNumber= "-"; - var $gotoLastUser= "-"; - var $gotoFloppyEnable= ""; - var $gotoCdromEnable= ""; - - /* Needed values and lists */ - var $base= ""; - var $cn= ""; - var $view_logged = FALSE; - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes= array("cn", "gotoMode", "gotoTerminalPath", "gotoFloppyEnable", - "gotoCdromEnable", "ghInventoryNumber", - "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer", - "ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport", - "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser"); - var $objectclasses= array("GOhard"); - - function terminfo (&$config, $dn= NULL, $parent= NULL) - { - plugin::plugin ($config,$dn); - - /* Read arrays */ - foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){ - if (!isset($this->attrs[$val])){ - continue; - } - for ($i= 0; $i<$this->attrs[$val]['count']; $i++){ - array_push($this->$val, $this->attrs[$val][$i]); - } - } + /* Generic terminal attributes */ + var $ghCpuType= "-"; + var $ghMemSize= "-"; + var $macAddress= "-"; + var $ghUsbSupport= "-"; + var $ghNetNic= array(); + var $ghIdeDev= array(); + var $ghScsiDev= array(); + var $ghGfxAdapter= "-"; + var $ghSoundAdapter= "-"; + var $ghInventoryNumber= "-"; + var $gotoLastUser= "-"; + var $gotoFloppyEnable= ""; + var $gotoCdromEnable= ""; + + /* Needed values and lists */ + var $base= ""; + var $cn= ""; + var $view_logged = FALSE; + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes= array("cn", "gotoMode", "gotoTerminalPath", "gotoFloppyEnable", + "gotoCdromEnable", "ghInventoryNumber", + "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer", + "ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport", + "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser"); + var $objectclasses= array("GOhard"); + + function terminfo (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config,$dn); + + /* Read arrays */ + foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){ + if (!isset($this->attrs[$val])){ + continue; + } + for ($i= 0; $i<$this->attrs[$val]['count']; $i++){ + array_push($this->$val, $this->attrs[$val][$i]); + } + } - /* Fix USB entry */ - if ($this->ghUsbSupport == "true"){ - $this->ghUsbSupport= _("present"); + /* Fix USB entry */ + if ($this->ghUsbSupport == "true"){ + $this->ghUsbSupport= _("present"); + } } - } - function execute() - { - /* Call parent execute */ - plugin::execute(); + function execute() + { + /* Call parent execute */ + plugin::execute(); - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","terminal/".get_class($this),$this->dn); - } + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","terminal/".get_class($this),$this->dn); + } - /* Do we represent a valid terminal? */ - if (!$this->is_account && $this->parent === NULL){ - return("\"\" ". - msgPool::noValidExtension(_("terminal")).""); - } + /* Do we represent a valid terminal? */ + if (!$this->is_account && $this->parent === NULL){ + return("\"\" ". + msgPool::noValidExtension(_("terminal")).""); + } - $smarty= get_smarty(); - $display= ""; - $smarty->assign("ACL",TRUE); - if(!preg_match("/r/",$this->getacl(""))){ - $smarty->assign("ACL",FALSE); - }elseif(!is_callable("snmpget")){ - - $smarty->assign("load", progressbar(0,100,15,true)); - $smarty->assign("mem", progressbar(0,100,15,true)); - $smarty->assign("swap", progressbar(0,100,15,true)); - foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd","status","ghNetNic", "ghIdeDev", "ghScsiDev","FloppyDevice", "CdromDevice","active") as $val){ - $smarty->assign("$val", ""._("unknown status, SNMP support missing").""); - } - - - $display =""; - }else - /* Default entry? */ - if ($this->cn == "default"){ - $display= "

"; - $display.= _("This is a virtual terminal which has no properties to show here."); - $display.= "
"; - } else { - - /* Get template object */ - - /* Prevent undefined variable .... */ - $smarty->assign("load", progressbar(0,100,15,true)); - $smarty->assign("mem", progressbar(0,100,15,true)); - $smarty->assign("swap", progressbar(0,100,15,true)); - - /* Check if terminal is online */ - if (gosaSupportDaemon::ping($this->macAddress)){ - $smarty->assign("status", _("online")); - $smarty->assign("active", "true"); - - /* Fill data if we have snmp */ - $host= $this->cn; - - /* Use 'goto' as snmp community or the configured value from the config */ - $community= 'goto'; - $str= $this->config->get_cfg_value("terminfo", "snmpCommunity"); - if(!empty($str)){ - $community = $str; - } - - /* Get memory informations */ - if(!is_callable("snmpget")){ - $MemFree = false; - }else{ - $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0"); - } - if ($MemFree != FALSE){ - $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree); - $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0"); - $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal); - if ($MemTotal != 0){ - $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true)); - ; + $smarty= get_smarty(); + $display= ""; + $smarty->assign("ACL",TRUE); + if(!preg_match("/r/",$this->getacl(""))){ + $smarty->assign("ACL",FALSE); + }elseif(!is_callable("snmpget")){ + + $smarty->assign("load", progressbar(0,100,15,true)); + $smarty->assign("mem", progressbar(0,100,15,true)); + $smarty->assign("swap", progressbar(0,100,15,true)); + foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd","status","ghNetNic", "ghIdeDev", "ghScsiDev","FloppyDevice", "CdromDevice","active") as $val){ + $smarty->assign("$val", ""._("unknown status, SNMP support missing").""); } - $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0"); - $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree); - $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0"); - $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal); - if ($SwapTotal != 0){ + + + $display =""; + }else + /* Default entry? */ + if ($this->cn == "default"){ + $display= "

"; + $display.= _("This is a virtual terminal which has no properties to show here."); + $display.= "
"; + } else { + + /* Get template object */ + + /* Prevent undefined variable .... */ + $smarty->assign("load", progressbar(0,100,15,true)); + $smarty->assign("mem", progressbar(0,100,15,true)); + $smarty->assign("swap", progressbar(0,100,15,true)); + + /* Check if terminal is online */ + if (gosaSupportDaemon::ping($this->macAddress)){ + $smarty->assign("status", _("online")); + $smarty->assign("active", "true"); + + /* Fill data if we have snmp */ + $host= $this->cn; + + /* Use 'goto' as snmp community or the configured value from the config */ + $community= 'goto'; + $str= $this->config->get_cfg_value("terminfo", "snmpCommunity"); + if(!empty($str)){ + $community = $str; + } + + /* Get memory informations */ + if(!is_callable("snmpget")){ + $MemFree = false; + }else{ + $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0"); + } + if ($MemFree != FALSE){ + $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree); + $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0"); + $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal); + if ($MemTotal != 0){ + $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true)); + ; + } + $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0"); + $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree); + $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0"); + $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal); + if ($SwapTotal != 0){ #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal)); - $smarty->assign("swap", progressbar(0,100,15,true)); - } + $smarty->assign("swap", progressbar(0,100,15,true)); + } + + /* Get system uptime */ + $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0"); + $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup)); + + /* Get system load */ + $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2"); + $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload); + + $smarty->assign("load", progressbar($sysload*100,100,15,true)); + + /* Get status for key processes */ + $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames"); + $check4= array("sshd", "cupsd", "artsd", "X", "saned"); + foreach ($check4 as $pname){ + $eflag= -1; + foreach ($processes as $key => $val){ + $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val); + if ($process == $pname){ + $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val); + $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index"); + $eflag= preg_replace('/^.*[:=] /', '', $res); + break; + } + } + switch ($eflag){ + case 0: + $smarty->assign("$pname", "\""._("running")."\""); + break; + case 1: + $smarty->assign("$pname", "\""._("not"); + break; + default: + $smarty->assign("$pname", _("not defined")); + } + } + } else { + foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){ + $smarty->assign("$val", ""._("unknown status").""); + } + } + /* Check for mounted partitions (show max 8 partitions) */ + $partitions= ""; + for ($n= 1; $n<9; $n++){ + $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n"); + if ($device == ""){ + break; + } + $device= preg_replace('/^STRING: */', '', $device); + $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n"); + $usage= preg_replace('/^INTEGER: */', '', $usage); + $partitions.= "$device".progressbar($usage,100,16,true)."\n"; + } + $smarty->assign("partitions", $partitions); + } else { + $smarty->assign("status", _("offline")); + $smarty->assign("active", "false"); + } - /* Get system uptime */ - $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0"); - $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup)); - - /* Get system load */ - $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2"); - $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload); - - $smarty->assign("load", progressbar($sysload*100,100,15,true)); - - /* Get status for key processes */ - $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames"); - $check4= array("sshd", "cupsd", "artsd", "X", "saned"); - foreach ($check4 as $pname){ - $eflag= -1; - foreach ($processes as $key => $val){ - $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val); - if ($process == $pname){ - $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val); - $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index"); - $eflag= preg_replace('/^.*[:=] /', '', $res); - break; + /* Set floppy and cdrom status */ + foreach(array("Floppy", "Cdrom") as $val){ + $name= "goto".$val."Enable"; + if ($this->$name == "YES"){ + $status= _("present"); + } else { + $status= "-"; + } + $smarty->assign($val."Device", $status); + } + + /* Show main page */ + foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){ + if (!count($this->$val)){ + $this->$val= "-"; + } + $smarty->assign($val, $this->$val); } - } - switch ($eflag){ - case 0: - $smarty->assign("$pname", "\""._("running")."\""); - break; - case 1: - $smarty->assign("$pname", "\""._("not"); - break; - default: - $smarty->assign("$pname", _("not defined")); - } - } - } else { - foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){ - $smarty->assign("$val", ""._("unknown status").""); - } - } - /* Check for mounted partitions (show max 8 partitions) */ - $partitions= ""; - for ($n= 1; $n<9; $n++){ - $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n"); - if ($device == ""){ - break; } - $device= preg_replace('/^STRING: */', '', $device); - $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n"); - $usage= preg_replace('/^INTEGER: */', '', $usage); - $partitions.= "$device".progressbar($usage,100,16,true)."\n"; - } - $smarty->assign("partitions", $partitions); - } else { - $smarty->assign("status", _("offline")); - $smarty->assign("active", "false"); - } + foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport", + "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){ - /* Set floppy and cdrom status */ - foreach(array("Floppy", "Cdrom") as $val){ - $name= "goto".$val."Enable"; - if ($this->$name == "YES"){ - $status= _("present"); - } else { - $status= "-"; - } - $smarty->assign($val."Device", $status); + $smarty->assign($val, $this->$val); } + $display= $smarty->fetch (get_template_path('info.tpl', TRUE, dirname(__FILE__))); - /* Show main page */ - foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){ - if (!count($this->$val)){ - $this->$val= "-"; - } - $smarty->assign($val, $this->$val); - } - } - foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport", - "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){ - - $smarty->assign($val, $this->$val); - } - $display= $smarty->fetch (get_template_path('info.tpl', TRUE, dirname(__FILE__))); - - return ($display); - } - - function remove_from_parent() - { - } - - - /* Save data to object */ - function save_object() - { - plugin::save_object(); - } - - - /* Save to LDAP */ - function save() - { - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("System info"), - "plDescription" => _("System informations"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 33, - "plSection" => array("administration"), - "plCategory" => array("workstation","server","terminal"), - - "plProperties" => array( - array( - "name" => "snmpCommunity", - "type" => "string", - "default" => "", - "description" => _("In order to make use of SNMP information, you can set the 'snmpCommunity'."), - "check" => "gosaProperty::isString", - "migrate" => "", - "group" => "plugin", - "mandatory" => FALSE - ) - ), - - "plProvidedAcls"=> array() - )); - } + return ($display); + } + + function remove_from_parent() + { + } + + + /* Save data to object */ + function save_object() + { + plugin::save_object(); + } + + + /* Save to LDAP */ + function save() + { + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("System info"), + "plDescription" => _("System informations"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 33, + "plSection" => array("administration"), + "plCategory" => array("workstation","server","terminal"), + + "plProperties" => array( + array( + "name" => "snmpCommunity", + "type" => "string", + "default" => "", + "description" => _("In order to make use of SNMP information, you can set the 'snmpCommunity'."), + "check" => "gosaProperty::isString", + "migrate" => "", + "group" => "plugin", + "mandatory" => FALSE + ) + ), + + "plProvidedAcls"=> array() + )); + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-plugins/goto/admin/systems/goto/class_terminalService.inc b/gosa-plugins/goto/admin/systems/goto/class_terminalService.inc index f72145316..c85802900 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_terminalService.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_terminalService.inc @@ -2,733 +2,733 @@ class termservice extends plugin { - /* Generic terminal attributes */ - var $gotoXMonitor= ""; - var $gotoXMethod= "default"; - var $gotoXdmcpServer= ""; - var $gotoXDriver= ""; - var $gotoXResolution= ""; - var $gotoXColordepth= ""; - var $gotoXHsync= ""; - var $gotoXVsync= ""; - var $gotoXKbModel= ""; - var $gotoXKbLayout= ""; - var $gotoXKbVariant= ""; - var $gotoXMouseType= ""; - var $gotoXMouseport= ""; - var $gotoLpdServer= ""; - var $gotoScannerEnable= ""; - var $gotoScannerModel= ""; - var $gotoScannerClients= ""; - var $gotoScannerBackend= ""; - var $goFonHardware= "automatic"; - - var $gotoLpdEnable = array(); - - var $AutoSync = false; - var $view_logged = FALSE; - - /* Needed values and lists */ - var $ignore_account= TRUE; - var $base= ""; - var $cn= ""; - var $orig_dn= ""; - var $XMethods= array(); - var $XDrivers= array(); - var $XResolutions= array(); - var $XColordepths= array(); - var $XKbModels= array (); - var $XKbLayouts= array (); - var $XKbVariants= array (); - var $MouseTypes= array(); - var $MousePorts= array(); - var $hardware_list= array(); - var $used_hardware= array(); - - - /* attribute list for save action */ - var $attributes= array("gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer", - "gotoXDriver", "gotoXResolution", "gotoXColordepth", - "gotoXHsync", "gotoXVsync", "gotoLpdServer", - "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients", - "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant", - "gotoXMouseType", "gotoXMouseport", "goFonHardware"); - var $objectclasses= array("GOhard"); - - var $is_ogroup = FALSE; - var $is_ogroup_member = FALSE; - - var $selected_xdmcp_servers = array(); - var $inherited_xdmcp_servers = array(); - - function termservice (&$config, $dn= NULL, $parent= NULL) - { - plugin::plugin ($config, $dn, $parent); - $this->orig_dn= $this->dn; - - /* Check if we are a part of an ogroup. - * In this case, we have to hide all the inherit stuff. - */ - if(isset($parent) && get_class($parent) == "ogroup"){ - $this->is_ogroup = TRUE; - } + /* Generic terminal attributes */ + var $gotoXMonitor= ""; + var $gotoXMethod= "default"; + var $gotoXdmcpServer= ""; + var $gotoXDriver= ""; + var $gotoXResolution= ""; + var $gotoXColordepth= ""; + var $gotoXHsync= ""; + var $gotoXVsync= ""; + var $gotoXKbModel= ""; + var $gotoXKbLayout= ""; + var $gotoXKbVariant= ""; + var $gotoXMouseType= ""; + var $gotoXMouseport= ""; + var $gotoLpdServer= ""; + var $gotoScannerEnable= ""; + var $gotoScannerModel= ""; + var $gotoScannerClients= ""; + var $gotoScannerBackend= ""; + var $goFonHardware= "automatic"; + + var $gotoLpdEnable = array(); + + var $AutoSync = false; + var $view_logged = FALSE; + + /* Needed values and lists */ + var $ignore_account= TRUE; + var $base= ""; + var $cn= ""; + var $orig_dn= ""; + var $XMethods= array(); + var $XDrivers= array(); + var $XResolutions= array(); + var $XColordepths= array(); + var $XKbModels= array (); + var $XKbLayouts= array (); + var $XKbVariants= array (); + var $MouseTypes= array(); + var $MousePorts= array(); + var $hardware_list= array(); + var $used_hardware= array(); + + + /* attribute list for save action */ + var $attributes= array("gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer", + "gotoXDriver", "gotoXResolution", "gotoXColordepth", + "gotoXHsync", "gotoXVsync", "gotoLpdServer", + "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients", + "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant", + "gotoXMouseType", "gotoXMouseport", "goFonHardware"); + var $objectclasses= array("GOhard"); + + var $is_ogroup = FALSE; + var $is_ogroup_member = FALSE; + + var $selected_xdmcp_servers = array(); + var $inherited_xdmcp_servers = array(); + + function termservice (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config, $dn, $parent); + $this->orig_dn= $this->dn; + + /* Check if we are a part of an ogroup. + * In this case, we have to hide all the inherit stuff. + */ + if(isset($parent) && get_class($parent) == "ogroup"){ + $this->is_ogroup = TRUE; + } - /* Check if we are member of an object group. - */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))"); - if($ldap->count()){ - $this->is_ogroup_member = TRUE; - } + /* Check if we are member of an object group. + */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))"); + if($ldap->count()){ + $this->is_ogroup_member = TRUE; + } - /* Load gotoLpdEnable - */ - $this->gotoLpdEnable = array(); - if(isset($this->attrs['gotoLpdEnable']['count'])){ - for($i = 0 ; $i < $this->attrs['gotoLpdEnable']['count']; $i ++){ - $this->gotoLpdEnable[] = $this->attrs['gotoLpdEnable'][$i]; - } - } - $this->gotoLpdEnable_dialog = new gotoLpdEnable($this->config,$this->gotoLpdEnable,$this); - - /* Get list of available xdrivers */ - $this->XDrivers = $this->getListOfXDrivers(); - - /* Create a list of available resolutions. - */ - $this->XResolutions= array( - "640x480" => "640x480", - "800x600" => "800x600", - "1024x768" => "1024x768", - "1152x864" => "1152x864", - "1280x1024" => "1280x1024", - "1400x1050" => "1400x1050", - "1600x1200" => "1600x1200"); - - if($this->config->get_cfg_value("environment","resolutions") != ""){ - $file = $this->config->get_cfg_value("environment","resolutions"); - if(is_readable($file)){ - $str = file_get_contents($file); - $lines = preg_split("/\n/",$str); - foreach($lines as $line){ - $line = trim($line); - if(!empty($line)){ - $this->XResolutions[$line]=$line; - } - } - }else{ - msg_dialog::display(_("Configuration error"), msgPool::cannotReadFile($file), WARNING_DIALOG); - } - } + /* Load gotoLpdEnable + */ + $this->gotoLpdEnable = array(); + if(isset($this->attrs['gotoLpdEnable']['count'])){ + for($i = 0 ; $i < $this->attrs['gotoLpdEnable']['count']; $i ++){ + $this->gotoLpdEnable[] = $this->attrs['gotoLpdEnable'][$i]; + } + } + $this->gotoLpdEnable_dialog = new gotoLpdEnable($this->config,$this->gotoLpdEnable,$this); + + /* Get list of available xdrivers */ + $this->XDrivers = $this->getListOfXDrivers(); + + /* Create a list of available resolutions. + */ + $this->XResolutions= array( + "640x480" => "640x480", + "800x600" => "800x600", + "1024x768" => "1024x768", + "1152x864" => "1152x864", + "1280x1024" => "1280x1024", + "1400x1050" => "1400x1050", + "1600x1200" => "1600x1200"); + + if($this->config->get_cfg_value("environment","resolutions") != ""){ + $file = $this->config->get_cfg_value("environment","resolutions"); + if(is_readable($file)){ + $str = file_get_contents($file); + $lines = preg_split("/\n/",$str); + foreach($lines as $line){ + $line = trim($line); + if(!empty($line)){ + $this->XResolutions[$line]=$line; + } + } + }else{ + msg_dialog::display(_("Configuration error"), msgPool::cannotReadFile($file), WARNING_DIALOG); + } + } - /* Create a set of selectable color depths - */ - $this->XColordepths= array( - "8" => "8 " ._("bit"), - "15" => "15 "._("bit"), - "16" => "16 "._("bit"), - "24" => "24 "._("bit")); - - - /* Create a set of selectable keyboard models - */ - $this->XKbModels = array(); - foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex", - "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless", - "logiinetnav", "logiinternet", "macintosh", "microsoft", - "microsoftpro", "omnikey101", "pc101", "pc102", "pc104", - "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){ - $this->XKbModels[$type] = $type; - } + /* Create a set of selectable color depths + */ + $this->XColordepths= array( + "8" => "8 " ._("bit"), + "15" => "15 "._("bit"), + "16" => "16 "._("bit"), + "24" => "24 "._("bit")); - /* Additional values will be extracted from CONFIG_DIR.keyboardLayouts */ - $this->XKbLayouts = array("de"=> "de","en" =>"en", "es" => "es", "us" =>"us", "fr" => "fr"); - $this->XKbVariants= array("nodeadkeys"=>"nodeadkeys", "basic"=>"basic"); - - $this->MouseTypes= array("auto" => "auto", - "explorerps/2" => "explorerps/2", - "ImPS/2" => "ImPS/2", - "PS/2" => "PS/2", - "Microsoft" => "Microsoft", - "Logitech" => "Logitech",); - - $this->MousePorts= array("/dev/input/mice" => "/dev/input/mice", - "/dev/mouse" => "/dev/mouse", - "/dev/psaux" => "/dev/psaux", - "/dev/ttyS0" => "/dev/ttyS0", - "/dev/ttyS1" => "/dev/ttyS1"); - - /* Try to read additional keyboard layouts - */ - if(file_exists(CONFIG_DIR."/keyboardLayouts")){ - if(is_readable(CONFIG_DIR."/keyboardLayouts")){ - $str = file_get_contents(CONFIG_DIR."/keyboardLayouts"); - $tmp = preg_split("/\n/",$str); - foreach($tmp as $entry){ - if((!empty($entry)) && (!preg_match("/^#/",$entry))){ - $entry = trim($entry); - $tmp2 = explode(":",$entry); - $la = trim($tmp2[0]); // What would be saved to ldap - $da = trim($tmp2[1]); // This wis displayed in the listbox - $this->XKbLayouts [ $la] = $da; - } - } - } - } - /* Terminal server methods supported by LTSP */ - if($this->is_ogroup_member){ - $this->XMethods["default"]= _("inherited"); - } - $this->XMethods["xdmcp"] = _("XDMCP"); - $this->XMethods["ldm"] = _("LDM"); - $this->XMethods["shell"] = _("Shell"); - $this->XMethods["telnet"] = _("Telnet"); - $this->XMethods["rdp"] = _("Windows RDP"); - #$this->XMethods["citrix"] = _("ICA client"); - - /* Get selected gotoXdmcpServer */ - $this->selected_xdmcp_servers = array(); - if(isset($this->attrs['gotoXdmcpServer'])){ - for($i = 0 ; $i < $this->attrs['gotoXdmcpServer']['count'] ; $i++){ - $this->selected_xdmcp_servers[] = $this->attrs['gotoXdmcpServer'][$i]; - } - } + /* Create a set of selectable keyboard models + */ + $this->XKbModels = array(); + foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex", + "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless", + "logiinetnav", "logiinternet", "macintosh", "microsoft", + "microsoftpro", "omnikey101", "pc101", "pc102", "pc104", + "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){ + $this->XKbModels[$type] = $type; + } - /* Load phone hardware list - */ - $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneGeneric", "phoneRDN")), - $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK); - foreach($tmp as $attrs){ - $cn= $attrs['cn'][0]; - $description= ""; - if (isset($attrs['description'])){ - $description= " - ".$attrs['description'][0]; - } - $this->hardware_list[$cn]= "$cn$description"; - } - $this->hardware_list["automatic"]= _("automatic"); - ksort($this->hardware_list); - - /* These departments may contain objects that have - goFonHardware set. - */ - $deps_a = array( - get_people_ou(), - get_ou("group", "ogroupRDN"), - get_ou("servgeneric", "serverRDN"), - get_ou("termgeneric", "terminalRDN"), - get_ou("workgeneric", "workstationRDN"), - get_ou("printgeneric", "printerRDN"), - get_ou("componentGeneric", "componentRDN"), - get_ou("phoneGeneric", "phoneRDN")); - - $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'], - array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK); - foreach($tmp as $attrs){ - $cn = $attrs['goFonHardware'][0]; - if(isset($this->hardware_list[$cn])){ - $this->used_hardware[$cn]= $cn; - } - } + /* Additional values will be extracted from CONFIG_DIR.keyboardLayouts */ + $this->XKbLayouts = array("de"=> "de","en" =>"en", "es" => "es", "us" =>"us", "fr" => "fr"); + $this->XKbVariants= array("nodeadkeys"=>"nodeadkeys", "basic"=>"basic"); + + $this->MouseTypes= array("auto" => "auto", + "explorerps/2" => "explorerps/2", + "ImPS/2" => "ImPS/2", + "PS/2" => "PS/2", + "Microsoft" => "Microsoft", + "Logitech" => "Logitech",); + + $this->MousePorts= array("/dev/input/mice" => "/dev/input/mice", + "/dev/mouse" => "/dev/mouse", + "/dev/psaux" => "/dev/psaux", + "/dev/ttyS0" => "/dev/ttyS0", + "/dev/ttyS1" => "/dev/ttyS1"); - /* Load hardware list */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $map= array( - "gotoXResolution", - "gotoXColordepth", - "gotoXKbModel", - "gotoXKbLayout", - "gotoXDriver", - "gotoXdmcpServer", - "gotoXKbVariant", - "gotoXMouseType", - "gotoXMethod", - "gotoXMouseport"); - $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))",$map); - if ($ldap->count() == 1){ - $attrs= $ldap->fetch(); - foreach ($map as $name){ - if (!isset($attrs[$name][0])){ - continue; - } - - switch ($name){ - case 'gotoXDriver': - $this->XDrivers = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers; - break; - case 'gotoXMethod': - $this->XMethods = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XMethods; - if(isset($attrs['gotoXdmcpServer'])){ - for($i = 0 ; $i < $attrs['gotoXdmcpServer']['count'] ; $i++){ - $this->inherited_xdmcp_servers[] = $attrs['gotoXdmcpServer'][$i]; - } + /* Try to read additional keyboard layouts + */ + if(file_exists(CONFIG_DIR."/keyboardLayouts")){ + if(is_readable(CONFIG_DIR."/keyboardLayouts")){ + $str = file_get_contents(CONFIG_DIR."/keyboardLayouts"); + $tmp = preg_split("/\n/",$str); + foreach($tmp as $entry){ + if((!empty($entry)) && (!preg_match("/^#/",$entry))){ + $entry = trim($entry); + $tmp2 = explode(":",$entry); + $la = trim($tmp2[0]); // What would be saved to ldap + $da = trim($tmp2[1]); // This wis displayed in the listbox + $this->XKbLayouts [ $la] = $da; + } + } } - break; - case 'gotoXResolution': - $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions; - break; - case 'gotoXColordepth': - $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths; - break; - case 'gotoXKbModel': - $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels; - break; - case 'gotoXKbLayout': - $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts; - break; - case 'gotoXKbVariant': - $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants; - break; - case 'gotoXMouseType': - $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes; - break; - case 'gotoXMouseport': - $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts; - break; - } - } - } + } - if(preg_match("/\+/",$this->gotoXHsync)){ - $this->AutoSync = true; - $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync); - $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync); - } - } + /* Terminal server methods supported by LTSP */ + if($this->is_ogroup_member){ + $this->XMethods["default"]= _("inherited"); + } + $this->XMethods["xdmcp"] = _("XDMCP"); + $this->XMethods["ldm"] = _("LDM"); + $this->XMethods["shell"] = _("Shell"); + $this->XMethods["telnet"] = _("Telnet"); + $this->XMethods["rdp"] = _("Windows RDP"); +#$this->XMethods["citrix"] = _("ICA client"); + + /* Get selected gotoXdmcpServer */ + $this->selected_xdmcp_servers = array(); + if(isset($this->attrs['gotoXdmcpServer'])){ + for($i = 0 ; $i < $this->attrs['gotoXdmcpServer']['count'] ; $i++){ + $this->selected_xdmcp_servers[] = $this->attrs['gotoXdmcpServer'][$i]; + } + } + /* Load phone hardware list + */ + $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneGeneric", "phoneRDN")), + $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK); + foreach($tmp as $attrs){ + $cn= $attrs['cn'][0]; + $description= ""; + if (isset($attrs['description'])){ + $description= " - ".$attrs['description'][0]; + } + $this->hardware_list[$cn]= "$cn$description"; + } + $this->hardware_list["automatic"]= _("automatic"); + ksort($this->hardware_list); - function execute() - { - /* Call parent execute */ - plugin::execute(); + /* These departments may contain objects that have + goFonHardware set. + */ + $deps_a = array( + get_people_ou(), + get_ou("group", "ogroupRDN"), + get_ou("servgeneric", "serverRDN"), + get_ou("termgeneric", "terminalRDN"), + get_ou("workgeneric", "workstationRDN"), + get_ou("printgeneric", "printerRDN"), + get_ou("componentGeneric", "componentRDN"), + get_ou("phoneGeneric", "phoneRDN")); + + $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'], + array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK); + foreach($tmp as $attrs){ + $cn = $attrs['goFonHardware'][0]; + if(isset($this->hardware_list[$cn])){ + $this->used_hardware[$cn]= $cn; + } + } - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","terminal/".get_class($this),$this->dn); - } + /* Load hardware list */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $map= array( + "gotoXResolution", + "gotoXColordepth", + "gotoXKbModel", + "gotoXKbLayout", + "gotoXDriver", + "gotoXdmcpServer", + "gotoXKbVariant", + "gotoXMouseType", + "gotoXMethod", + "gotoXMouseport"); + $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))",$map); + if ($ldap->count() == 1){ + $attrs= $ldap->fetch(); + foreach ($map as $name){ + if (!isset($attrs[$name][0])){ + continue; + } + + switch ($name){ + case 'gotoXDriver': + $this->XDrivers = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers; + break; + case 'gotoXMethod': + $this->XMethods = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XMethods; + if(isset($attrs['gotoXdmcpServer'])){ + for($i = 0 ; $i < $attrs['gotoXdmcpServer']['count'] ; $i++){ + $this->inherited_xdmcp_servers[] = $attrs['gotoXdmcpServer'][$i]; + } + } + break; + case 'gotoXResolution': + $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions; + break; + case 'gotoXColordepth': + $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths; + break; + case 'gotoXKbModel': + $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels; + break; + case 'gotoXKbLayout': + $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts; + break; + case 'gotoXKbVariant': + $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants; + break; + case 'gotoXMouseType': + $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes; + break; + case 'gotoXMouseport': + $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts; + break; + } + } + } - /* Do we need to flip is_account state? */ - if (isset($_POST['modify_state'])){ - $this->is_account= !$this->is_account; + if(preg_match("/\+/",$this->gotoXHsync)){ + $this->AutoSync = true; + $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync); + $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync); + } } - /* Do we represent a valid terminal? */ - if (!$this->is_account && $this->parent === NULL){ - $display= "\"\" ". - _("This 'dn' has no terminal features.").""; - return ($display); - } - /* Show main page */ - $smarty= get_smarty(); - $smarty->assign("gotoLpdEnable_dialog", $this->gotoLpdEnable_dialog->execute()); + function execute() + { + /* Call parent execute */ + plugin::execute(); - /* Assign acls */ - $tmp= $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL",$this->getacl($name)); - } + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","terminal/".get_class($this),$this->dn); + } - if(isset($_POST['gotoXdmcpServer_add']) && isset($_POST['XdmcpAddServer'])){ - if(!in_array($_POST['gotoXdmcpServer_add'],$this->selected_xdmcp_servers)){ - $this->selected_xdmcp_servers[] = $_POST['gotoXdmcpServer_add']; - } - } + /* Do we need to flip is_account state? */ + if (isset($_POST['modify_state'])){ + $this->is_account= !$this->is_account; + } - if(isset($_POST['selected_xdmcp_servers']) && isset($_POST['XdmcpDelServer'])){ - $tmp = array(); - foreach($this->selected_xdmcp_servers as $name){ - if(!in_array($name,$_POST['selected_xdmcp_servers'])){ - $tmp[] = $name; + /* Do we represent a valid terminal? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + _("This 'dn' has no terminal features.").""; + return ($display); } - } - $this->selected_xdmcp_servers = $tmp; - } - /* Arrays */ - foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths", - "XKbModels","XKbVariants","MouseTypes", "MousePorts") as $val){ - $smarty->assign("$val", $this->$val); - } - $smarty->assign("XKbLayouts", $this->XKbLayouts); - $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts)); - $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']); - - - /* Create a list of useable servers for the currently selected - * connection type. - */ - $xdmcp_types = $this->config->data['SERVERS']['TERMINAL_SESSION_TYPES']; - $available_servers = array(); - foreach($xdmcp_types as $servername =>$supported_types){ - if(in_array(strtoupper($this->gotoXMethod),$supported_types)){ - $available_servers[] = $servername; - } - } + /* Show main page */ + $smarty= get_smarty(); + $smarty->assign("gotoLpdEnable_dialog", $this->gotoLpdEnable_dialog->execute()); - /* Append additional information to invalid server selections. - */ - $tmp = array(); - foreach($this->selected_xdmcp_servers as $server){ - if(in_array($server,$available_servers)){ - $tmp[$server] = $server; - }else{ - $tmp[$server] = $server." - "._("Unsupported"); - } - } + /* Assign acls */ + $tmp= $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } - /* Remove already selected servers from available list. - */ - foreach($available_servers as $key => $server){ - if(isset($tmp[$server])){ - unset($available_servers[$key]); - } - } + if(isset($_POST['gotoXdmcpServer_add']) && isset($_POST['XdmcpAddServer'])){ + if(!in_array($_POST['gotoXdmcpServer_add'],$this->selected_xdmcp_servers)){ + $this->selected_xdmcp_servers[] =get_post('gotoXdmcpServer_add'); + } + } - $smarty->assign("selected_xdmcp_servers", $tmp); - $smarty->assign("inherited_xdmcp_servers", $this->inherited_xdmcp_servers); - $smarty->assign("available_xdmcp_servers", $available_servers); + if(isset($_POST['selected_xdmcp_servers']) && isset($_POST['XdmcpDelServer'])){ + $tmp = array(); + foreach($this->selected_xdmcp_servers as $name){ + if(!in_array($name,$_POST['selected_xdmcp_servers'])){ + $tmp[] = $name; + } + } + $this->selected_xdmcp_servers = $tmp; + } - /* Variables - select */ - foreach(array("gotoXMethod","gotoXDriver", "gotoXResolution", "gotoXColordepth", - "gotoLpdServer", "gotoXKbModel", "gotoXKbLayout", - "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){ + /* Arrays */ + foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths", + "XKbModels","XKbVariants","MouseTypes", "MousePorts") as $val){ + $smarty->assign("$val", set_post($this->$val)); + } + $smarty->assign("XKbLayouts", set_post($this->XKbLayouts)); + $smarty->assign("XKbLayoutKeys",set_post(array_flip($this->XKbLayouts))); + $smarty->assign("nfsservers", set_post($this->config->data['SERVERS']['NFS'])); + + + /* Create a list of useable servers for the currently selected + * connection type. + */ + $xdmcp_types = $this->config->data['SERVERS']['TERMINAL_SESSION_TYPES']; + $available_servers = array(); + foreach($xdmcp_types as $servername =>$supported_types){ + if(in_array(strtoupper($this->gotoXMethod),$supported_types)){ + $available_servers[] = $servername; + } + } - $smarty->assign($val."_select", $this->$val); - } + /* Append additional information to invalid server selections. + */ + $tmp = array(); + foreach($this->selected_xdmcp_servers as $server){ + if(in_array($server,$available_servers)){ + $tmp[$server] = $server; + }else{ + $tmp[$server] = $server." - "._("Unsupported"); + } + } - /* Variables */ - foreach(array("gotoXHsync", "gotoXVsync") as $val){ - $smarty->assign($val, $this->$val); - } + /* Remove already selected servers from available list. + */ + foreach($available_servers as $key => $server){ + if(isset($tmp[$server])){ + unset($available_servers[$key]); + } + } - /* Checkboxes */ - foreach(array("gotoScannerEnable") as $val){ - if ($this->$val == TRUE) { - $smarty->assign("$val", "checked"); - } else { - $smarty->assign("$val", ""); - } - } + $smarty->assign("selected_xdmcp_servers", set_post($tmp)); + $smarty->assign("inherited_xdmcp_servers",set_post($this->inherited_xdmcp_servers)); + $smarty->assign("available_xdmcp_servers",set_post($available_servers)); - /* Phone stuff */ - $smarty->assign ("goFonHardware", $this->goFonHardware); - $hl= "\n"; - $smarty->assign ("hardware_list", $hl); - $smarty->assign ("gotoXMonitor", $this->gotoXMonitor); + /* Variables - select */ + foreach(array("gotoXMethod","gotoXDriver", "gotoXResolution", "gotoXColordepth", + "gotoLpdServer", "gotoXKbModel", "gotoXKbLayout", + "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){ - $smarty->assign("AutoSyncACL",$this->getacl("AutoSync")); + $smarty->assign($val."_select", set_post($this->$val)); + } - $smarty->assign("AutoSyncCHK"," "); - if($this->AutoSync){ - $smarty->assign("AutoSyncCHK"," checked "); - $smarty->assign("gotoXVsyncACL", preg_replace("/w/","",$this->getacl("gotoXVsync"))); - $smarty->assign("gotoXHsyncACL", preg_replace("/w/","",$this->getacl("gotoXHsync"))); - } + /* Variables */ + foreach(array("gotoXHsync", "gotoXVsync") as $val){ + $smarty->assign($val, set_post($this->$val)); + } - /* Show main page */ - return($smarty->fetch (get_template_path('terminalService.tpl', TRUE,dirname(__FILE__)))); - } + /* Checkboxes */ + foreach(array("gotoScannerEnable") as $val){ + if ($this->$val == TRUE) { + $smarty->assign("$val", "checked"); + } else { + $smarty->assign("$val", ""); + } + } - function remove_from_parent() - { - new log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs)); - $this->handle_post_events("remove"); - } + /* Phone stuff */ + $smarty->assign ("goFonHardware", set_post($this->goFonHardware)); + $hl= "\n"; + $smarty->assign ("hardware_list", set_post($hl)); + $smarty->assign ("gotoXMonitor", set_post($this->gotoXMonitor)); + $smarty->assign("AutoSyncACL",$this->getacl("AutoSync")); - /* Save data to object */ - function save_object() - { - plugin::save_object(); + $smarty->assign("AutoSyncCHK"," "); + if($this->AutoSync){ + $smarty->assign("AutoSyncCHK"," checked "); + $smarty->assign("gotoXVsyncACL", preg_replace("/w/","",$this->getacl("gotoXVsync"))); + $smarty->assign("gotoXHsyncACL", preg_replace("/w/","",$this->getacl("gotoXHsync"))); + } - $this->gotoLpdEnable_dialog->save_object(); - if($this->gotoLpdEnable_dialog->is_account){ - $this->gotoLpdEnable = $this->gotoLpdEnable_dialog->save(); - }else{ - $this->gotoLpdEnable = array(); + /* Show main page */ + return($smarty->fetch (get_template_path('terminalService.tpl', TRUE,dirname(__FILE__)))); } - /* Save checkbox state */ - if (isset ($_POST['gotoXMethod'])){ - foreach (array("gotoScannerEnable") as $val){ - - if($this->acl_is_writeable($val)){ - if (!isset ($_POST["$val"])){ - $this->$val= FALSE; - } else { - $this->$val= TRUE; - } - } - } - } - - if(isset($_POST['gotoXDriver'])){ - if(isset($_POST['AutoSync'])){ - $this->AutoSync = true; - }else{ - $this->AutoSync = false; - } + function remove_from_parent() + { + new log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs)); + $this->handle_post_events("remove"); } - /* Default entries can use blank hsync/vsync entries */ - if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){ - - /* But only if no auto sync is enabled... */ - if (!$this->AutoSync){ - - /* Check vsync for correct usage */ - $val= preg_replace ("/\s/", "", $this->gotoXVsync); - if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXVsync")){ - $message[]= msgPool::invalid(_("VSync range")); - } elseif ($this->acl_is_writeable("gotoXVsync")){ - list($v1,$v2)= preg_split ("/[-+]/", $val); - if ($v2 != ""){ - if ($v1 > $v2){ - $message[]= msgPool::invalid(_("VSync range")); + + /* Save data to object */ + function save_object() + { + plugin::save_object(); + + $this->gotoLpdEnable_dialog->save_object(); + if($this->gotoLpdEnable_dialog->is_account){ + $this->gotoLpdEnable = $this->gotoLpdEnable_dialog->save(); + }else{ + $this->gotoLpdEnable = array(); + } + + /* Save checkbox state */ + if (isset ($_POST['gotoXMethod'])){ + foreach (array("gotoScannerEnable") as $val){ + + if($this->acl_is_writeable($val)){ + if (!isset ($_POST["$val"])){ + $this->$val= FALSE; + } else { + $this->$val= TRUE; + } + } } - } - } - - /* Check hsync for correct usage */ - $val= preg_replace ("/\s/", "", $this->gotoXHsync); - if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXHsync")){ - $message[]= msgPool::invalid(_("HSync range")); - } elseif ($this->acl_is_writeable("gotoXHsync")){ - list($v1,$v2)= preg_split ("/[-+]/", $val); - if ($v2 != ""){ - if ($v1 > $v2){ - $message[]= msgPool::invalid(_("HSync range")); + } + + if(isset($_POST['gotoXDriver'])){ + if(isset($_POST['AutoSync'])){ + $this->AutoSync = true; + }else{ + $this->AutoSync = false; + } + } + + /* Default entries can use blank hsync/vsync entries */ + if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){ + + /* But only if no auto sync is enabled... */ + if (!$this->AutoSync){ + + /* Check vsync for correct usage */ + $val= preg_replace ("/\s/", "", $this->gotoXVsync); + if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXVsync")){ + $message[]= msgPool::invalid(_("VSync range")); + } elseif ($this->acl_is_writeable("gotoXVsync")){ + list($v1,$v2)= preg_split ("/[-+]/", $val); + if ($v2 != ""){ + if ($v1 > $v2){ + $message[]= msgPool::invalid(_("VSync range")); + } + } + } + + /* Check hsync for correct usage */ + $val= preg_replace ("/\s/", "", $this->gotoXHsync); + if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXHsync")){ + $message[]= msgPool::invalid(_("HSync range")); + } elseif ($this->acl_is_writeable("gotoXHsync")){ + list($v1,$v2)= preg_split ("/[-+]/", $val); + if ($v2 != ""){ + if ($v1 > $v2){ + $message[]= msgPool::invalid(_("HSync range")); + } + } + } } - } } - } - } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - $message = array_merge($message,$this->gotoLpdEnable_dialog->check()); - - if($this->gotoXMethod != "default"){ - $xdmcp_types = $this->config->data['SERVERS']['TERMINAL_SESSION_TYPES']; - $available_servers = array(); - foreach($xdmcp_types as $servername =>$supported_types){ - if(in_array(strtoupper($this->gotoXMethod),$supported_types)){ - $available_servers[] = $servername; - } - } - foreach($this->selected_xdmcp_servers as $server){ - if(!in_array($server,$available_servers)){ - $message[] = _("Remote desktop settings contains servers that do not support the selected connection method."); - break; - } - } } - return ($message); - } + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + $message = array_merge($message,$this->gotoLpdEnable_dialog->check()); + + if($this->gotoXMethod != "default"){ + $xdmcp_types = $this->config->data['SERVERS']['TERMINAL_SESSION_TYPES']; + $available_servers = array(); + foreach($xdmcp_types as $servername =>$supported_types){ + if(in_array(strtoupper($this->gotoXMethod),$supported_types)){ + $available_servers[] = $servername; + } + } + foreach($this->selected_xdmcp_servers as $server){ + if(!in_array($server,$available_servers)){ + $message[] = _("Remote desktop settings contains servers that do not support the selected connection method."); + break; + } + } + } - /* Save to LDAP */ - function save() - { - /* remove objectclass GOhard if this is an ogroup tab */ - if(isset($this->parent->by_object['ogroup'])){ - $this->objectclasses = array(); + return ($message); } - plugin::save(); - /* Strip out 'default' values */ - foreach(array("gotoXMethod","gotoXDriver", "gotoXResolution", "gotoXColordepth", - "gotoLpdServer", "gotoXKbModel", "gotoXKbLayout", - "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){ + /* Save to LDAP */ + function save() + { + /* remove objectclass GOhard if this is an ogroup tab */ + if(isset($this->parent->by_object['ogroup'])){ + $this->objectclasses = array(); + } - if ($this->attrs[$val] == "default"){ - $this->attrs[$val]= array(); - } - } + plugin::save(); - if($this->gotoXMethod == "default"){ - $this->attrs['gotoXdmcpServer'] = array(); - $this->attrs['gotoXMethod'] = array(); - }else{ - $this->attrs['gotoXdmcpServer'] = array_values($this->selected_xdmcp_servers); - } + /* Strip out 'default' values */ + foreach(array("gotoXMethod","gotoXDriver", "gotoXResolution", "gotoXColordepth", + "gotoLpdServer", "gotoXKbModel", "gotoXKbLayout", + "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){ + if ($this->attrs[$val] == "default"){ + $this->attrs[$val]= array(); + } + } - if($this->AutoSync){ - $this->attrs['gotoXHsync'] = "30+55"; - $this->attrs['gotoXVsync'] = "50+70"; - } + if($this->gotoXMethod == "default"){ + $this->attrs['gotoXdmcpServer'] = array(); + $this->attrs['gotoXMethod'] = array(); + }else{ + $this->attrs['gotoXdmcpServer'] = array_values($this->selected_xdmcp_servers); + } - /* Write back to ldap */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $this->cleanup(); - $ldap->modify ($this->attrs); - new log("modify","terminal/".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())); - } - $this->handle_post_events("modify"); + if($this->AutoSync){ + $this->attrs['gotoXHsync'] = "30+55"; + $this->attrs['gotoXVsync'] = "50+70"; + } - /* Send goto reload event to gosaSupportDaemon */ - if(count($this->attrs)){ - $this->send_goto_reload(); - } - } - - - function getListOfXDrivers() - { - $drivers = array("default" => "["._("unknown")."]"); - - /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */ - if (file_exists(CONFIG_DIR.'/xdrivers')){ - $xdrivers = file (CONFIG_DIR.'/xdrivers'); - foreach ($xdrivers as $line){ - if (!preg_match ("/^#/", $line)){ - $drivers[]= trim($line); - } - } - } else { - foreach( array( - "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx", - "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia", - "r128", "radeonhd", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion", - "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware") as $driver){ - $drivers[] = $driver; - } - } + /* Write back to ldap */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + new log("modify","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - $tmp = array(); - foreach($drivers as $name){ - $tmp[$name] = $name; + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class())); + } + $this->handle_post_events("modify"); + + /* Send goto reload event to gosaSupportDaemon */ + if(count($this->attrs)){ + $this->send_goto_reload(); + } } - return($tmp); - } - - function send_goto_reload() - { - if(count($this->attrs) && class_available("DaemonEvent")){ - $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); - $o_queue = new gosaSupportDaemon(); - if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){ - $evt = $events['TRIGGERED']['DaemonEvent_goto_reload']; - $macs = array(); - - /* Get list of macAddresses - */ - if(isset($this->parent->by_object['ogroup'])){ - /* If we are an object group, add all member macs - */ - $p = $this->parent->by_object['ogroup']; - foreach($p->memberList as $dn => $obj){ - if(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/",$dn)) continue; - if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){ - $macs[] = $p->objcache[$dn]['macAddress']; - } - } - }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){ - /* We are a workstation. Add current mac. - */ - $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; - if(!empty($mac) && !preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/",$this->orig_dn)){ - $macs[] = $mac; - } + function getListOfXDrivers() + { + $drivers = array("default" => "["._("unknown")."]"); + + /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */ + if (file_exists(CONFIG_DIR.'/xdrivers')){ + $xdrivers = file (CONFIG_DIR.'/xdrivers'); + foreach ($xdrivers as $line){ + if (!preg_match ("/^#/", $line)){ + $drivers[]= trim($line); + } + } + } else { + foreach( array( + "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx", + "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia", + "r128", "radeonhd", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion", + "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware") as $driver){ + $drivers[] = $driver; + } } - /* Trigger event for all member objects - */ - if(count($macs)){ - $tmp = new $evt['CLASS_NAME']($this->config); - $tmp->set_type(TRIGGERED_EVENT); - $target = $o_queue->get_host().":".$o_queue->get_port(); - $tmp->add_targets(array($target)); - $tmp->set_macs($macs); - if(!$o_queue->append($tmp,TRUE)){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - } - } - } + $tmp = array(); + foreach($drivers as $name){ + $tmp[$name] = $name; + } + return($tmp); + } + + function send_goto_reload() + { + if(count($this->attrs) && class_available("DaemonEvent")){ + $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); + $o_queue = new gosaSupportDaemon(); + if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){ + $evt = $events['TRIGGERED']['DaemonEvent_goto_reload']; + $macs = array(); + + /* Get list of macAddresses + */ + if(isset($this->parent->by_object['ogroup'])){ + + /* If we are an object group, add all member macs + */ + $p = $this->parent->by_object['ogroup']; + foreach($p->memberList as $dn => $obj){ + if(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/",$dn)) continue; + if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){ + $macs[] = $p->objcache[$dn]['macAddress']; + } + } + }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){ + + /* We are a workstation. Add current mac. + */ + $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; + if(!empty($mac) && !preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/",$this->orig_dn)){ + $macs[] = $mac; + } + } + + /* Trigger event for all member objects + */ + if(count($macs)){ + $tmp = new $evt['CLASS_NAME']($this->config); + $tmp->set_type(TRIGGERED_EVENT); + $target = $o_queue->get_host().":".$o_queue->get_port(); + $tmp->add_targets(array($target)); + $tmp->set_macs($macs); + if(!$o_queue->append($tmp,TRUE)){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + } + } + } + } } - } - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + $source_o = new termservice ($this->config, $source['dn']); + + foreach(array("gotoXdmcpServer","selected_xdmcp_servers") as $attr){ + $this->$attr = $source_o->$attr; + } + } + - $source_o = new termservice ($this->config, $source['dn']); - foreach(array("gotoXdmcpServer","selected_xdmcp_servers") as $attr){ - $this->$attr = $source_o->$attr; + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Service"), + "plDescription" => _("Terminal service"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 3, + "plSection" => array("administration"), + "plCategory" => array("terminal"), + + "plProvidedAcls"=> array( + + "gotoXMonitor" => _("Monitor"), + "gotoXMethod" => _("Method"), + "gotoXdmcpServer" => _("Remote desktop"), + "gotoXDriver" => _("Gfx driver"), + "gotoXResolution" => _("Gfx resolution"), + "gotoXColordepth" => _("Gfx color depth"), + "gotoXHsync" => _("HSync"), + "gotoXVsync" => _("VSync"), + "AutoSync" => _("Auto-Sync"), + "gotoScannerEnable" => _("Scanner enabled"), + "gotoLpdEnable" => _("Printer enabled"), + "gotoXKbModel" => _("Keyboard model"), + "gotoXKbLayout" => _("Keyboard layout"), + "gotoXKbVariant" => _("Keyboard variant"), + "gotoXMouseType" => _("Mouse type"), + "gotoXMouseport" => _("Mouse port"), + "gotoLpdEnable" => _("Printer enabled"), + "goFonHardware" => _("Telephone hardware")) + )); } - } - - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Service"), - "plDescription" => _("Terminal service"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 3, - "plSection" => array("administration"), - "plCategory" => array("terminal"), - - "plProvidedAcls"=> array( - - "gotoXMonitor" => _("Monitor"), - "gotoXMethod" => _("Method"), - "gotoXdmcpServer" => _("Remote desktop"), - "gotoXDriver" => _("Gfx driver"), - "gotoXResolution" => _("Gfx resolution"), - "gotoXColordepth" => _("Gfx color depth"), - "gotoXHsync" => _("HSync"), - "gotoXVsync" => _("VSync"), - "AutoSync" => _("Auto-Sync"), - "gotoScannerEnable" => _("Scanner enabled"), - "gotoLpdEnable" => _("Printer enabled"), - "gotoXKbModel" => _("Keyboard model"), - "gotoXKbLayout" => _("Keyboard layout"), - "gotoXKbVariant" => _("Keyboard variant"), - "gotoXMouseType" => _("Mouse type"), - "gotoXMouseport" => _("Mouse port"), - "gotoLpdEnable" => _("Printer enabled"), - "goFonHardware" => _("Telephone hardware")) - )); - } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-plugins/goto/admin/systems/goto/class_terminalStartup.inc b/gosa-plugins/goto/admin/systems/goto/class_terminalStartup.inc index fa8a22210..7eb4196c1 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_terminalStartup.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_terminalStartup.inc @@ -1,538 +1,538 @@ gotoBootKernels = array("default"=> ("default")); - - /* Get arrays */ - foreach (array("gotoModules") as $val){ - $this->$val = array(); - if (isset($this->attrs["$val"]["count"])){ - for ($i= 0; $i<$this->attrs["count"]; $i++){ - if (isset($this->attrs["$val"][$i])){ - array_push($this->$val, $this->attrs["$val"][$i]); - } - } - } - sort ($this->$val); - $this->$val= array_unique($this->$val); - } - - /* Prepare Shares */ - if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){ - unset($this->attrs['gotoShare']['count']); - foreach($this->attrs['gotoShare'] as $share){ - $tmp = $tmp2 = array(); - $tmp = explode("|",$share); - $tmp2['server'] =$tmp[0]; - $tmp2['name'] =$tmp[1]; - $tmp2['mountPoint'] =$tmp[2]; - $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2; - } - } - - $this->gotoShareSelections= $config->getShareList(true); - $this->gotoAvailableShares= $config->getShareList(false); + /* Generic terminal attributes */ + var $goLdapServerList= array(); + var $gotoBootKernel= "default-inherited"; + var $gotoKernelParameters= ""; + var $gotoLdapServer= "default-inherited"; + var $gotoModules= array(); + var $gotoTerminalPath= ""; + var $gotoBootKernels= array(); + + /* Ldap server list */ + var $gotoLdapServers = array(); + var $gotoLdapServerList = array(); + var $gotoLdap_inherit = FALSE; + + /* Share */ + var $gotoShares = array();// Currently Share Option + var $gotoShare = ""; // currently selected Share Option + var $gotoShareSelections= array();// Available Shares for this account in Listbox format + var $gotoAvailableShares= array();// Available Shares for this account + + + /* attribute list for save action */ + var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters","gotoModules"); + var $objectclasses= array("GOhard"); + var $view_logged = FALSE; + var $member_of_ogroup = FALSE; + var $o_group_dn = ""; + + /* Helper */ + var $orig_dn= ""; + var $ignore_account= TRUE; + + function termstartup (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config, $dn, $parent); + + $this->gotoBootKernels = array("default"=> ("default")); + + /* Get arrays */ + foreach (array("gotoModules") as $val){ + $this->$val = array(); + if (isset($this->attrs["$val"]["count"])){ + for ($i= 0; $i<$this->attrs["count"]; $i++){ + if (isset($this->attrs["$val"][$i])){ + array_push($this->$val, $this->attrs["$val"][$i]); + } + } + } + sort ($this->$val); + $this->$val= array_unique($this->$val); + } - $this->orig_dn= $this->dn; + /* Prepare Shares */ + if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){ + unset($this->attrs['gotoShare']['count']); + foreach($this->attrs['gotoShare'] as $share){ + $tmp = $tmp2 = array(); + $tmp = explode("|",$share); + $tmp2['server'] =$tmp[0]; + $tmp2['name'] =$tmp[1]; + $tmp2['mountPoint'] =$tmp[2]; + $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2; + } + } - /* Creating a list of valid Mirrors - * none will not be saved to ldap. - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ui = get_userinfo(); - foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){ - if($ui->get_category_permissions($data['dn'],"server",TRUE)){ - for($i = 0; $i < $data['goLdapBase']['count']; $i ++){ - $name = $data["cn"][0].":".$data["goLdapBase"][$i]; - $this->gotoLdapServerList[]= $name; - } - } - } + $this->gotoShareSelections= $config->getShareList(true); + $this->gotoAvailableShares= $config->getShareList(false); + + $this->orig_dn= $this->dn; + + /* Creating a list of valid Mirrors + * none will not be saved to ldap. + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ui = get_userinfo(); + foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){ + if($ui->get_category_permissions($data['dn'],"server",TRUE)){ + for($i = 0; $i < $data['goLdapBase']['count']; $i ++){ + $name = $data["cn"][0].":".$data["goLdapBase"][$i]; + $this->gotoLdapServerList[]= $name; + } + } + } - if(isset($this->attrs['gotoLdapServer'])){ - unset($this->attrs['gotoLdapServer']['count']); - sort($this->attrs['gotoLdapServer']); - foreach($this->attrs['gotoLdapServer'] as $value){ - $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value); - } - } - natcasesort($this->gotoLdapServerList); - - /* Load hardware list */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))"); - if ($ldap->count() == 1){ - $map= array("gotoLdapServer","gotoBootKernel"); - $attrs= $ldap->fetch(); - $this->member_of_ogroup = TRUE; - $this->o_group_dn = $attrs['dn']; - - foreach ($map as $name){ - if (!isset($attrs[$name][0])){ - continue; - } - switch ($name){ - case 'gotoBootKernel': - /* Handle inheritance value "default" */ - if ($this->member_of_ogroup){ - $this->gotoBootKernels["default-inherited"]= _("inherited")." [".$attrs['gotoBootKernel'][0]."]"; - } - break; - case 'gotoLdapServer': - $this->goLdapServerList= array_merge(array('default-inherit' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList); - break; - } - } - } + if(isset($this->attrs['gotoLdapServer'])){ + unset($this->attrs['gotoLdapServer']['count']); + sort($this->attrs['gotoLdapServer']); + foreach($this->attrs['gotoLdapServer'] as $value){ + $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value); + } + } + natcasesort($this->gotoLdapServerList); + + /* Load hardware list */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))"); + if ($ldap->count() == 1){ + $map= array("gotoLdapServer","gotoBootKernel"); + $attrs= $ldap->fetch(); + $this->member_of_ogroup = TRUE; + $this->o_group_dn = $attrs['dn']; + + foreach ($map as $name){ + if (!isset($attrs[$name][0])){ + continue; + } + switch ($name){ + case 'gotoBootKernel': + /* Handle inheritance value "default" */ + if ($this->member_of_ogroup){ + $this->gotoBootKernels["default-inherited"]= _("inherited")." [".$attrs['gotoBootKernel'][0]."]"; + } + break; + case 'gotoLdapServer': + $this->goLdapServerList= array_merge(array('default-inherit' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList); + break; + } + } + } - if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ - $this->gotoLdap_inherit = TRUE; - } + if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ + $this->gotoLdap_inherit = TRUE; + } - /* Get list of boot kernels */ - if (isset($this->config->data['TABS'])){ - $command= $this->config->get_cfg_value('termstartup', "systemKernelsHook"); - - if (!check_command($command)){ - $message[]= sprintf(_("Command '%s', specified as systemKernelsHook for plugin '%s' doesn't seem to exist."), $command, - get_class($this)); - } else { - $fh= popen($command, "r"); - while (!feof($fh)) { - $buffer= trim(fgets($fh, 256)); - - if(!empty($buffer)){ - - $name=$value = $buffer; - - if(preg_match("/:/",$buffer)){ - $name = preg_replace("/:.*$/","",$buffer); - $value= preg_replace("/^.*:/","",$buffer); - $this->gotoBootKernels[$name]= $name.":".$value; - }else{ - $this->gotoBootKernels[$name]= $value; + /* Get list of boot kernels */ + if (isset($this->config->data['TABS'])){ + $command= $this->config->get_cfg_value('termstartup', "systemKernelsHook"); + + if (!check_command($command)){ + $message[]= sprintf(_("Command '%s', specified as systemKernelsHook for plugin '%s' doesn't seem to exist."), $command, + get_class($this)); + } else { + $fh= popen($command, "r"); + while (!feof($fh)) { + $buffer= trim(fgets($fh, 256)); + + if(!empty($buffer)){ + + $name=$value = $buffer; + + if(preg_match("/:/",$buffer)){ + $name = preg_replace("/:.*$/","",$buffer); + $value= preg_replace("/^.*:/","",$buffer); + $this->gotoBootKernels[$name]= $name.":".$value; + }else{ + $this->gotoBootKernels[$name]= $value; + } + } + } + pclose($fh); } - } + } - pclose($fh); - } - } + // Prepare lists + $this->ldapList = new sortableListing(array(),array(), TRUE); + $this->ldapList->setDeleteable(true); + $this->ldapList->setEditable(false); + $this->ldapList->setWidth("100%"); + $this->ldapList->setHeight("100px"); + $this->ldapList->setHeader(array(_("LDAP server"))); + $this->ldapList->setDefaultSortColumn(0); - // Prepare lists - $this->ldapList = new sortableListing(array(),array(), TRUE); - $this->ldapList->setDeleteable(true); - $this->ldapList->setEditable(false); - $this->ldapList->setWidth("100%"); - $this->ldapList->setHeight("100px"); - $this->ldapList->setHeader(array(_("LDAP server"))); - $this->ldapList->setDefaultSortColumn(0); - - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","terminal/".get_class($this),$this->dn); } - /* Do we need to flip is_account state? */ - if (isset($_POST['modify_state'])){ - $this->is_account= !$this->is_account; - } + function execute() + { + /* Call parent execute */ + plugin::execute(); - /* Do we represent a valid terminal? */ - if (!$this->is_account && $this->parent === NULL){ - $display= "\"\" ". - msgPool::noValidExtension(_("terminal")).""; - return ($display); - } + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","terminal/".get_class($this),$this->dn); + } - /* Add module */ - if (isset ($_POST['add_module'])){ - if ($_POST['module'] != "" && $this->acl_is_writeable("gotoMode")){ - $this->add_list ($this->gotoModules, $_POST['module']); - } - } + /* Do we need to flip is_account state? */ + if (isset($_POST['modify_state'])){ + $this->is_account= !$this->is_account; + } - /* Delete module */ - if (isset ($_POST['delete_module'])){ - if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoMode")){ - $this->del_list ($this->gotoModules, $_POST['modules_list']); - } - } + /* Do we represent a valid terminal? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + msgPool::noValidExtension(_("terminal")).""; + return ($display); + } - /* Show main page */ - $smarty= get_smarty(); + /* Add module */ + if (isset ($_POST['add_module'])){ + if ($_POST['module'] != "" && $this->acl_is_writeable("gotoMode")){ + $this->add_list ($this->gotoModules, $_POST['module']); + } + } - /* Assign acls */ - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL",$this->getacl($name)); - } + /* Delete module */ + if (isset ($_POST['delete_module'])){ + if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoMode")){ + $this->del_list ($this->gotoModules, $_POST['modules_list']); + } + } - $smarty->assign("member_of_ogroup",$this->member_of_ogroup); + /* Show main page */ + $smarty= get_smarty(); - /* In this section server shares will be defined - * A user can select one of the given shares and a mount point - * and attach this combination to his setup. - */ - $smarty->assign("gotoShareSelections", $this->gotoShareSelections); - $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections)); - $smarty->assign("gotoBootKernels",$this->gotoBootKernels); + /* Assign acls */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } - /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry - * This entry will be, a combination of mountPoint and sharedefinitions - */ - if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){ - /* We assign a share to this user, if we don't know where to mount the share */ - if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){ - msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), WARNING_DIALOG); - }elseif(isset($_POST['gotoShareSelection']) && isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){ - $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']]; - $s_mount = $_POST['gotoShareMountPoint']; - /* Preparing the new assignment */ - $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share; - $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount; - } - } + $smarty->assign("member_of_ogroup",$this->member_of_ogroup); + + /* In this section server shares will be defined + * A user can select one of the given shares and a mount point + * and attach this combination to his setup. + */ + $smarty->assign("gotoShareSelections", $this->gotoShareSelections); + $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections)); + $smarty->assign("gotoBootKernels",$this->gotoBootKernels); + + /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry + * This entry will be, a combination of mountPoint and sharedefinitions + */ + if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){ + /* We assign a share to this user, if we don't know where to mount the share */ + if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){ + msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), WARNING_DIALOG); + }elseif(isset($_POST['gotoShareSelection']) && isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){ + $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']]; + $s_mount = $_POST['gotoShareMountPoint']; + /* Preparing the new assignment */ + $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share; + $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount; + } + } - /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected) - * If there is no defined share selected, we will abort the deletion without any message - */ - if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare'])) && $this->acl_is_writeable("gotoShare")){ - unset($this->gotoShares[$_POST['gotoShare']]); - } + /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected) + * If there is no defined share selected, we will abort the deletion without any message + */ + if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare'])) && $this->acl_is_writeable("gotoShare")){ + unset($this->gotoShares[$_POST['gotoShare']]); + } - $smarty->assign("gotoShares",$this->printOutAssignedShares()); - $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares())); - $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares())); + $smarty->assign("gotoShares",$this->printOutAssignedShares()); + $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares())); + $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares())); - /* Add new ldap server to the list */ - if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){ - if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){ - $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']]; - if(!in_array($to_add,$this->gotoLdapServers)){ - $this->gotoLdapServers[] = $to_add; + /* Add new ldap server to the list */ + if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){ + if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){ + $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']]; + if(!in_array($to_add,$this->gotoLdapServers)){ + $this->gotoLdapServers[] = $to_add; + } + } } - } - } - - /* Move ldap servers up and down */ - $this->ldapList->save_object(); - $action = $this->ldapList->getAction(); - if($action['action'] == 'reorder'){ - $this->gotoLdapServers = array_values($this->ldapList->getMaintainedData()); - } - if($action['action'] == 'delete'){ - $id = $this->ldapList->getKey($action['targets'][0]); - $value = $this->gotoLdapServers[$id]; - $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers); - } - $this->ldapList->setAcl($this->getacl('gotoLdapServer')); + /* Move ldap servers up and down */ + $this->ldapList->save_object(); + $action = $this->ldapList->getAction(); + if($action['action'] == 'reorder'){ + $this->gotoLdapServers = array_values($this->ldapList->getMaintainedData()); + } + if($action['action'] == 'delete'){ + $id = $this->ldapList->getKey($action['targets'][0]); + $value = $this->gotoLdapServers[$id]; + $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers); + } - /* Add Entries */ - $data = $lData = array(); - foreach($this->gotoLdapServers as $key => $server){ - $data[$key]=$server; + $this->ldapList->setAcl($this->getacl('gotoLdapServer')); - /* Announce missing entries */ - if(!in_array($server,$this->gotoLdapServerList)){ - $server = $server." (missing)"; - } + /* Add Entries */ + $data = $lData = array(); + foreach($this->gotoLdapServers as $key => $server){ + $data[$key]=$server; - /* Convert old style entry */ - if (!preg_match('%:ldaps?://%', $server)){ - $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server); + /* Announce missing entries */ + if(!in_array($server,$this->gotoLdapServerList)){ + $server = $server." (missing)"; + } + + /* Convert old style entry */ + if (!preg_match('%:ldaps?://%', $server)){ + $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server); } else { $server= preg_replace("/^[^:]+:/", "", $server); $lData[$key] = array('data'=>array($server)); } - } - $this->ldapList->setListData($data,$lData); - $this->ldapList->update(); + } + $this->ldapList->setListData($data,$lData); + $this->ldapList->update(); - if($this->gotoLdap_inherit){ - $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));; - }else{ - $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer")); - } + if($this->gotoLdap_inherit){ + $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));; + }else{ + $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer")); + } - $list = array(); - foreach($this->gotoLdapServerList as $key => $entry){ - if(!in_array($entry,$this->gotoLdapServers)){ - $list[$key] = $entry; - } - } - $smarty->assign("gotoLdapServers", $this->ldapList->render()); - $smarty->assign("gotoLdapServerList", $list); - $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit); - $smarty->assign("JS", session::get('js')); + $list = array(); + foreach($this->gotoLdapServerList as $key => $entry){ + if(!in_array($entry,$this->gotoLdapServers)){ + $list[$key] = $entry; + } + } + $smarty->assign("gotoLdapServers", $this->ldapList->render()); + $smarty->assign("gotoLdapServerList", $list); + $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit); + $smarty->assign("JS", session::get('js')); + + foreach (array("gotoModules" ) as $val){ + $smarty->assign("$val", $this->$val); + } + + /* Values */ + foreach(array("gotoBootKernel", "gotoKernelParameters") as $val){ + $smarty->assign($val, $this->$val); + } - foreach (array("gotoModules" ) as $val){ - $smarty->assign("$val", $this->$val); + /* Show main page */ + return($smarty->fetch (get_template_path('terminalStartup.tpl', TRUE,dirname(__FILE__)))); } - /* Values */ - foreach(array("gotoBootKernel", "gotoKernelParameters") as $val){ - $smarty->assign($val, $this->$val); + function remove_from_parent() + { + if($this->acl_is_removeable()){ + $this->handle_post_events("remove"); + new log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs)); + } } - /* Show main page */ - return($smarty->fetch (get_template_path('terminalStartup.tpl', TRUE,dirname(__FILE__)))); - } - function remove_from_parent() - { - if($this->acl_is_removeable()){ - $this->handle_post_events("remove"); - new log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs)); + /* Save data to object */ + function save_object() + { + plugin::save_object(); + + if(isset($_POST['TerminalStarttabPosted'])){ + if(isset($_POST['gotoLdap_inherit'])){ + $this->gotoLdap_inherit = TRUE; + }else{ + $this->gotoLdap_inherit = FALSE; + } + } } - } - /* Save data to object */ - function save_object() - { - plugin::save_object(); + /* Save to LDAP */ + function save() + { + /* Depending on the baseobject (Ogroup / WS) we + * use another set of objectClasses + * In case of TS itself, we use "array("GOhard");" + * if we are currently editing from ogroup menu we use (array("goTerminalTemplate")) + */ + if(isset($this->parent->by_object['ogroup'])){ + $this->objectclasses = array("gotoTerminalTemplate"); + }elseif(isset($this->parent->by_object['termgeneric'])){ + $this->objectclasses = array("GOhard"); + }else{ + msg_dialog::display(_("Fatal error"), + "Object Type Configuration is unknown. Please contact the GOsa developers.", + FATAL_ERROR_DIALOG); + exit(); + } - if(isset($_POST['TerminalStarttabPosted'])){ - if(isset($_POST['gotoLdap_inherit'])){ - $this->gotoLdap_inherit = TRUE; - }else{ - $this->gotoLdap_inherit = FALSE; - } - } - } + plugin::save(); - /* Save to LDAP */ - function save() - { - /* Depending on the baseobject (Ogroup / WS) we - * use another set of objectClasses - * In case of TS itself, we use "array("GOhard");" - * if we are currently editing from ogroup menu we use (array("goTerminalTemplate")) - */ - if(isset($this->parent->by_object['ogroup'])){ - $this->objectclasses = array("gotoTerminalTemplate"); - }elseif(isset($this->parent->by_object['termgeneric'])){ - $this->objectclasses = array("GOhard"); - }else{ - msg_dialog::display(_("Fatal error"), - "Object Type Configuration is unknown. Please contact the GOsa developers.", - FATAL_ERROR_DIALOG); - exit(); - } + /* Add missing arrays */ + foreach (array("gotoModules") as $val){ + if (isset ($this->$val) && count ($this->$val) != 0){ - - plugin::save(); - - /* Add missing arrays */ - foreach (array("gotoModules") as $val){ - if (isset ($this->$val) && count ($this->$val) != 0){ - - $this->attrs["$val"]= array_unique($this->$val); - } - if(!isset($this->attrs["$val"])){ - $this->attrs["$val"]=array(); - } - } + $this->attrs["$val"]= array_unique($this->$val); + } + if(!isset($this->attrs["$val"])){ + $this->attrs["$val"]=array(); + } + } - /* Prepare list of ldap servers */ - $this->attrs['gotoLdapServer'] = array(); - if(!$this->gotoLdap_inherit){ - $i = 0; - foreach($this->gotoLdapServers as $server){ - $i ++; - $this->attrs['gotoLdapServer'][] = $i.":".$server; - } - } + /* Prepare list of ldap servers */ + $this->attrs['gotoLdapServer'] = array(); + if(!$this->gotoLdap_inherit){ + $i = 0; + foreach($this->gotoLdapServers as $server){ + $i ++; + $this->attrs['gotoLdapServer'][] = $i.":".$server; + } + } - /* Strip out 'default' values */ - if ($this->attrs['gotoBootKernel'] == "default-inherited"){ - $this->attrs['gotoBootKernel']= array(); - } + /* Strip out 'default' values */ + if ($this->attrs['gotoBootKernel'] == "default-inherited"){ + $this->attrs['gotoBootKernel']= array(); + } - /* prepare share settings */ - $tmp = array(); - foreach($this->gotoShares as $name => $settings){ - $tmp2 = explode("|",$name); - $name = $tmp2[0]; - $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint']; - } - $this->attrs['gotoShare']=$tmp; + /* prepare share settings */ + $tmp = array(); + foreach($this->gotoShares as $name => $settings){ + $tmp2 = explode("|",$name); + $name = $tmp2[0]; + $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint']; + } + $this->attrs['gotoShare']=$tmp; - /* Write back to ldap */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - - $this->cleanup(); - $ldap->modify ($this->attrs); + /* Write back to ldap */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->dn); - new log("modify","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + $this->cleanup(); + $ldap->modify ($this->attrs); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class())); + new log("modify","terminal/".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())); + } + $this->handle_post_events("modify"); } - $this->handle_post_events("modify"); - } - - /* Add value to array, check if unique */ - function add_list (&$array, $value) - { - if ($value != ""){ - $array[]= $value; - sort($array); - array_unique ($array); + + /* Add value to array, check if unique */ + function add_list (&$array, $value) + { + if ($value != ""){ + $array[]= $value; + sort($array); + array_unique ($array); + } } - } - /* Delete value to array, check if unique */ - function del_list (&$array, $list) - { - $tmp= array(); - foreach ($array as $mod){ - if (!in_array($mod, $list)){ - $tmp[]= $mod; - } + /* Delete value to array, check if unique */ + function del_list (&$array, $list) + { + $tmp= array(); + foreach ($array as $mod){ + if (!in_array($mod, $list)){ + $tmp[]= $mod; + } + } + $array= $tmp; } - $array= $tmp; - } - - /* Generate ListBox frindly output for the defined shares - * Possibly Add or remove an attribute here, - */ - function printOutAssignedShares() - { - $a_return = array(); - if(is_array($this->gotoShares)){ - foreach($this->gotoShares as $share){ - $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]"; - } + + /* Generate ListBox frindly output for the defined shares + * Possibly Add or remove an attribute here, + */ + function printOutAssignedShares() + { + $a_return = array(); + if(is_array($this->gotoShares)){ + foreach($this->gotoShares as $share){ + $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]"; + } + } + return($a_return); } - return($a_return); - } - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); - $source_o = new termstartup ($this->config, $source['dn']); + $source_o = new termstartup ($this->config, $source['dn']); - foreach(array("gotoModules", "gotoKernelParameters","gotoShare", - "gotoKernelParameters","gotoShares", - "goLdapServerList","gotoBootKernel","gotoLdapServer", - "gotoBootKernels","gotoLdapServers","gotoLdapServers", - "gotoLdapServerList","gotoLdap_inherit","gotoShareSelections", - "gotoAvailableShares") as $attr){ - $this->$attr = $source_o->$attr; + foreach(array("gotoModules", "gotoKernelParameters","gotoShare", + "gotoKernelParameters","gotoShares", + "goLdapServerList","gotoBootKernel","gotoLdapServer", + "gotoBootKernels","gotoLdapServers","gotoLdapServers", + "gotoLdapServerList","gotoLdap_inherit","gotoShareSelections", + "gotoAvailableShares") as $attr){ + $this->$attr = $source_o->$attr; + } } - } - function array_switch_item($ar,$from,$to) - { - if(!is_array($ar)){ - return(false); - } - if(!isset($ar[$from])){ - return(false); - } - if(!isset($ar[$to])){ - return(false); - } + function array_switch_item($ar,$from,$to) + { + if(!is_array($ar)){ + return(false); + } + if(!isset($ar[$from])){ + return(false); + } + if(!isset($ar[$to])){ + return(false); + } - $tmp = $ar[$from]; - $ar[$from] = $ar[$to]; - $ar[$to] = $tmp; - return($ar); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Startup"), - "plDescription" => _("Terminal startup"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 5, - "plSection" => array("administration"), - "plCategory" => array("terminal"), - - "plProperties" => array( - - array( - "name" => "systemKernelsHook", - "type" => "command", - "default" => "", - "description" => _("For the workstations and terminals, you can define the 'systemKernelsHook' keyword. It can load additional kernels that are not retrieveable by standard GOsa/FAI mechanisms."), - "check" => "gosaProperty::isCommand", - "migrate" => "", - "group" => "system", - "mandatory" => FALSE) - ), - - "plProvidedAcls"=> array( - "gotoLdapServer" => _("Ldap server"), - "gotoShare" => _("Shares"), - "gotoModules" => _("Kernel modules"), - "gotoBootKernel" => _("Boot kernel"), - "gotoKernelParameters"=> _("Kernel parameter")) - )); - } + $tmp = $ar[$from]; + $ar[$from] = $ar[$to]; + $ar[$to] = $tmp; + return($ar); + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Startup"), + "plDescription" => _("Terminal startup"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 5, + "plSection" => array("administration"), + "plCategory" => array("terminal"), + + "plProperties" => array( + + array( + "name" => "systemKernelsHook", + "type" => "command", + "default" => "", + "description" => _("For the workstations and terminals, you can define the 'systemKernelsHook' keyword. It can load additional kernels that are not retrieveable by standard GOsa/FAI mechanisms."), + "check" => "gosaProperty::isCommand", + "migrate" => "", + "group" => "system", + "mandatory" => FALSE) + ), + + "plProvidedAcls"=> array( + "gotoLdapServer" => _("Ldap server"), + "gotoShare" => _("Shares"), + "gotoModules" => _("Kernel modules"), + "gotoBootKernel" => _("Boot kernel"), + "gotoKernelParameters"=> _("Kernel parameter")) + )); + } } diff --git a/gosa-plugins/goto/admin/systems/goto/class_workstationGeneric.inc b/gosa-plugins/goto/admin/systems/goto/class_workstationGeneric.inc index a4136b859..dd4a9ead8 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_workstationGeneric.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_workstationGeneric.inc @@ -2,772 +2,779 @@ class workgeneric extends plugin { - /* Generic terminal attributes */ - var $gotoMode= "locked"; - var $initial_gotoMode= "locked"; - var $gotoSyslogServer= ""; - var $gotoSyslogServers= array(); - var $gotoNtpServer= array(); - var $gotoNtpServers= array(); - var $gotoSndModule= ""; - var $gotoFloppyEnable= ""; - var $gotoCdromEnable= ""; - var $description= ""; - var $ghCpuType= "-"; - var $ghMemSize= "-"; - var $ghUsbSupport= "-"; - var $ghNetNic= array(); - var $ghIdeDev= array(); - var $ghScsiDev= array(); - var $ghGfxAdapter= "-"; - var $ghSoundAdapter= "-"; - var $gotoLastUser= "-"; - var $FAIscript= ""; - var $view_logged = FALSE; - var $auto_activate= FALSE; - - /* Needed values and lists */ - var $base= ""; - var $cn= ""; - var $l= ""; - var $orig_dn= ""; - var $orig_cn= ""; - var $orig_base= ""; - - /* Plugin side filled */ - var $modes= array(); - - var $netConfigDNS; - var $baseSelector; - - var $inheritTimeServer = true; - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes= array("gotoMode", "gotoSyslogServer", "gotoNtpServer", - "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule", - "ghCpuType", "ghMemSize", "ghUsbSupport", "description", - "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l","FAIscript"); - var $objectclasses= array("top", "gotoWorkstation", "GOhard"); - - var $validActions = array("reboot" => "", "localboot" => "", "halt" => "", "update" => "", "reinstall" => "", - "rescan" => "", "wakeup" => "", "memcheck" => "", "sysinfo" => ""); - - var $fai_activated = FALSE; - - var $member_of_ogroup = FALSE; - - var $currently_installing = FALSE; - var $currently_installing_warned = FALSE; - - var $kerberos_key_service = NULL; - - function workgeneric (&$config, $dn= NULL, $parent= NULL) - { - $this->fai_activated = $config->pluginEnabled("faiManagement"); - - plugin::plugin ($config, $dn, $parent); - - if(class_available("krbHostKeys")){ - $this->kerberos_key_service = new krbHostKeys($this->config,$this); - } + /* Generic terminal attributes */ + var $gotoMode= "locked"; + var $initial_gotoMode= "locked"; + var $gotoSyslogServer= ""; + var $gotoSyslogServers= array(); + var $gotoNtpServer= array(); + var $gotoNtpServers= array(); + var $gotoSndModule= ""; + var $gotoFloppyEnable= ""; + var $gotoCdromEnable= ""; + var $description= ""; + var $ghCpuType= "-"; + var $ghMemSize= "-"; + var $ghUsbSupport= "-"; + var $ghNetNic= array(); + var $ghIdeDev= array(); + var $ghScsiDev= array(); + var $ghGfxAdapter= "-"; + var $ghSoundAdapter= "-"; + var $gotoLastUser= "-"; + var $FAIscript= ""; + var $view_logged = FALSE; + var $auto_activate= FALSE; + + /* Needed values and lists */ + var $base= ""; + var $cn= ""; + var $l= ""; + var $orig_dn= ""; + var $orig_cn= ""; + var $orig_base= ""; + + /* Plugin side filled */ + var $modes= array(); + + var $netConfigDNS; + var $baseSelector; + + var $inheritTimeServer = true; + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes= array("gotoMode", "gotoSyslogServer", "gotoNtpServer", + "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule", + "ghCpuType", "ghMemSize", "ghUsbSupport", "description", + "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l","FAIscript"); + var $objectclasses= array("top", "gotoWorkstation", "GOhard"); + + var $validActions = array("reboot" => "", "localboot" => "", "halt" => "", "update" => "", "reinstall" => "", + "rescan" => "", "wakeup" => "", "memcheck" => "", "sysinfo" => ""); + + var $fai_activated = FALSE; + + var $member_of_ogroup = FALSE; + + var $currently_installing = FALSE; + var $currently_installing_warned = FALSE; + + var $kerberos_key_service = NULL; + + function workgeneric (&$config, $dn= NULL, $parent= NULL) + { + $this->fai_activated = $config->pluginEnabled("faiManagement"); + + plugin::plugin ($config, $dn, $parent); + + if(class_available("krbHostKeys")){ + $this->kerberos_key_service = new krbHostKeys($this->config,$this); + } - if(!isset($this->parent->by_object['ogroup'])){ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->config->current['BASE']); - $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn")); - $this->member_of_ogroup = $ldap->count() >= 1; - } + if(!isset($this->parent->by_object['ogroup'])){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn")); + $this->member_of_ogroup = $ldap->count() >= 1; + } - $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses); - $this->netConfigDNS->MACisMust =TRUE; + $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses); + $this->netConfigDNS->MACisMust =TRUE; + + /* Check if this host is currently in installation process*/ + if(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(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; + /* Read arrays */ + foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){ + if (!isset($this->attrs[$val])){ + continue; + } + for ($i= 0; $i<$this->attrs[$val]['count']; $i++){ + array_push($this->$val, $this->attrs[$val][$i]); + } } - } - } - /* Read arrays */ - foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){ - if (!isset($this->attrs[$val])){ - continue; - } - for ($i= 0; $i<$this->attrs[$val]['count']; $i++){ - array_push($this->$val, $this->attrs[$val][$i]); - } - } + /* Create used ntp server array */ + $this->gotoNtpServer= array(); + if(isset($this->attrs['gotoNtpServer'])){ + $this->inheritTimeServer = false; + unset($this->attrs['gotoNtpServer']['count']); + foreach($this->attrs['gotoNtpServer'] as $server){ + $this->gotoNtpServer[$server] = $server; + } + } - /* Create used ntp server array */ - $this->gotoNtpServer= array(); - if(isset($this->attrs['gotoNtpServer'])){ - $this->inheritTimeServer = false; - unset($this->attrs['gotoNtpServer']['count']); - foreach($this->attrs['gotoNtpServer'] as $server){ - $this->gotoNtpServer[$server] = $server; - } - } + /* Set inherit checkbox state */ + if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer) == 0)){ + $this->inheritTimeServer = true; + $this->gotoNtpServer=array(); + } - /* Set inherit checkbox state */ - if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer) == 0)){ - $this->inheritTimeServer = true; - $this->gotoNtpServer=array(); - } + /* You can't inherit the NTP service, if we are not member in an object group */ + if(!$this->member_of_ogroup){ + $this->inheritTimeServer = FALSE; + } - /* You can't inherit the NTP service, if we are not member in an object group */ - if(!$this->member_of_ogroup){ - $this->inheritTimeServer = FALSE; - } + /* Create available ntp options */ + $tmp = $this->config->data['SERVERS']['NTP']; + $this->gotoNtpServers = array(); + foreach($tmp as $key => $server){ + if($server == "default") continue; + $this->gotoNtpServers[$server] = $server; + } - /* Create available ntp options */ - $tmp = $this->config->data['SERVERS']['NTP']; - $this->gotoNtpServers = array(); - foreach($tmp as $key => $server){ - if($server == "default") continue; - $this->gotoNtpServers[$server] = $server; - } + $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); + } 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("workgeneric", "workstationRDN"), '/')."/i", "", $this->dn); + } - $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); - } 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("workgeneric", "workstationRDN"), '/')."/i", "", $this->dn); - } + /* Create an array of all Syslog servers */ + $tmp = $this->config->data['SERVERS']['SYSLOG']; + foreach($tmp as $server){ + $visible = $server; + if($server == "default" && $this->member_of_ogroup) { + $visible = "["._("inherited")."]"; + } + $this->gotoSyslogServers[$server] = $visible; + } + + $this->initial_gotoMode = $this->gotoMode; + + /* Save 'dn' for later referal */ + $this->orig_dn= $this->dn; + $this->orig_cn= $this->cn; + $this->orig_base= $this->base; - /* Create an array of all Syslog servers */ - $tmp = $this->config->data['SERVERS']['SYSLOG']; - foreach($tmp as $server){ - $visible = $server; - if($server == "default" && $this->member_of_ogroup) { - $visible = "["._("inherited")."]"; - } - $this->gotoSyslogServers[$server] = $visible; + /* 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->initial_gotoMode = $this->gotoMode; - - /* Save 'dn' for later referal */ - $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_category($cat) - { - plugin::set_acl_category($cat); - $this->netConfigDNS->set_acl_category($cat); - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","workstation/".get_class($this),$this->dn); + + function set_acl_base($base) + { + plugin::set_acl_base($base); + $this->netConfigDNS->set_acl_base($base); } - /* Do we need to flip is_account state? */ - if(isset($_POST['modify_state'])){ - if($this->is_account && $this->acl_is_removeable()){ - $this->is_account= FALSE; - }elseif(!$this->is_account && $this->acl_is_createable()){ - $this->is_account= TRUE; - } + function set_acl_category($cat) + { + plugin::set_acl_category($cat); + $this->netConfigDNS->set_acl_category($cat); } - if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->validActions[$_POST['saction']]) ){ - $action= $_POST['saction']; + function execute() + { + /* Call parent execute */ + plugin::execute(); - /* 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($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","workstation/".get_class($this),$this->dn); } - } else { - msg_dialog::display(_("Event error"), - sprintf(_("Event '%s' is not available!"),$action),ERROR_DIALOG); - } + /* Do we need to flip is_account state? */ + if(isset($_POST['modify_state'])){ + if($this->is_account && $this->acl_is_removeable()){ + $this->is_account= FALSE; + }elseif(!$this->is_account && $this->acl_is_createable()){ + $this->is_account= TRUE; + } + } - } + if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->validActions[$_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); + } - /* Do we represent a valid terminal? */ - if (!$this->is_account && $this->parent === NULL){ - $display= "\"\" ". - msgPool::noValidExtension(_("workstation")).""; - return($display); - } - /* Add new ntp Server to our list */ - if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers'])) && $this->acl_is_writeable("gotoNtpServer")){ - $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers']; - } + } - /* Delete selected NtpServer for list of used servers */ - if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected'])) && $this->acl_is_writeable("gotoNtpServer")){ - foreach($_POST['gotoNtpServerSelected'] as $name){ - unset($this->gotoNtpServer[$name]); - } - } + /* Do we represent a valid terminal? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + msgPool::noValidExtension(_("workstation")).""; + return($display); + } - /* Fill templating stuff */ - $smarty= get_smarty(); + /* Add new ntp Server to our list */ + if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers'])) && $this->acl_is_writeable("gotoNtpServer")){ + $this->gotoNtpServer[$_POST['gotoNtpServers']] = get_post('gotoNtpServers'); + } + /* Delete selected NtpServer for list of used servers */ + if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected'])) && $this->acl_is_writeable("gotoNtpServer")){ + foreach($_POST['gotoNtpServerSelected'] as $name){ + unset($this->gotoNtpServer[$name]); + } + } - /* Set acls */ - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL",$this->getacl($name)); - } + /* Fill templating stuff */ + $smarty= get_smarty(); - $smarty->assign("cn", $this->cn); - $smarty->assign("description", $this->description); - $smarty->assign("l", $this->l); - $tmp = array(); - foreach($this->gotoNtpServers as $server){ - if(!in_array($server,$this->gotoNtpServer)){ - $tmp[$server] = $server; - } - } - $smarty->assign("gotoNtpServers",$tmp); - - /* Check if workstation is online */ - if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){ - $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"), - "update" => _("Software 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" => _("Software update"), - #"memcheck" => _("Memory test"), - "localboot" => _("Force localboot"), - #"sysinfo" => _("System analysis") - )); - } - /* Arrays */ - $smarty->assign("modes", $this->modes); - $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']); - $smarty->assign("syslogservers", $this->gotoSyslogServers); - $smarty->assign("fai_activated",$this->fai_activated); - - $ntpser = array(); - foreach($this->gotoNtpServers as $server){ - if(!in_array($server,$this->gotoNtpServer)){ - $ntpser[$server] = $server; - } - } - $smarty->assign("gotoNtpServers", $ntpser); + /* Set acls */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } - /* Variables */ - foreach(array("gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){ - $smarty->assign($val."_select", $this->$val); - } - $smarty->assign("base", $this->baseSelector->render()); + $smarty->assign("cn", set_post($this->cn)); + $smarty->assign("description", set_post($this->description)); + $smarty->assign("l", set_post($this->l)); - /* tell smarty the inherit checkbox state */ - $smarty->assign("inheritTimeServer",$this->inheritTimeServer); - $smarty->assign("member_of_ogroup",$this->member_of_ogroup); + $tmp = array(); + foreach($this->gotoNtpServers as $server){ + if(!in_array($server,$this->gotoNtpServer)){ + $tmp[$server] = $server; + } + } + $smarty->assign("gotoNtpServers", set_post($tmp)); + + /* Check if workstation is online */ + if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){ + $smarty->assign("actions", + set_post( + array( + "halt" => _("Switch off"), + "reboot" => _("Reboot"), + "update" => _("Software update"), + "reinstall" => _("Reinstall"), + "rescan" => _("Rescan hardware"), + "localboot" => _("Force localboot"), + ) + ) + ); + } else { + $smarty->assign("actions", + set_post( + array( + "wakeup" => _("Wake up"), + "reinstall" => _("Reinstall"), + "update" => _("Software update"), + "localboot" => _("Force localboot"), + ) + ) + ); + } + /* Arrays */ + $smarty->assign("modes", set_post($this->modes)); + $smarty->assign("nfsservers", set_post($this->config->data['SERVERS']['NFS'])); + $smarty->assign("syslogservers",set_post($this->gotoSyslogServers)); + $smarty->assign("fai_activated",set_post($this->fai_activated)); + + $ntpser = array(); + foreach($this->gotoNtpServers as $server){ + if(!in_array($server,$this->gotoNtpServer)){ + $ntpser[$server] = set_post($server); + } + } + $smarty->assign("gotoNtpServers", $ntpser); - $str = $this->netConfigDNS->execute(); - if(is_object($this->netConfigDNS->dialog)){ - return($str); - } - $smarty->assign("netconfig", $str); + /* Variables */ + foreach(array("gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){ + $smarty->assign($val."_select", set_post($this->$val)); + } + $smarty->assign("base", $this->baseSelector->render()); - /* Display kerberos host key options */ - $smarty->assign("host_key",""); - if(is_object($this->kerberos_key_service)){ - $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/")); - } + /* tell smarty the inherit checkbox state */ + $smarty->assign("inheritTimeServer",$this->inheritTimeServer); + $smarty->assign("member_of_ogroup", $this->member_of_ogroup); - /* Show main page */ - $smarty->assign("currently_installing", $this->currently_installing); - return($smarty->fetch (get_template_path('workstation.tpl', TRUE, dirname(__FILE__)))); - } - - function remove_from_parent() - { - if($this->acl_is_removeable()){ - - $this->netConfigDNS->remove_from_parent(); - $ldap= $this->config->get_ldap_link(); - $ldap->rmdir($this->dn); - new log("remove","workstation/".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_DEL, get_class())); - } - - /* Remove kerberos key dependencies too */ - if(is_object($this->kerberos_key_service)){ - $this->kerberos_key_service->remove_from_parent_by_prefix("host/"); - } - - /* Optionally execute a command after we're done */ - $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - - /* Delete references to object groups */ - $ldap->cd ($this->config->current['BASE']); - $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn")); - while ($ldap->fetch()){ - $og= new ogroup($this->config, $ldap->getDN()); - unset($og->member[$this->dn]); - $og->save (); - } - - /* Remove all accessTo/trust dependencies */ - update_accessTo($this->cn,""); - } + $str = $this->netConfigDNS->execute(); + if(is_object($this->netConfigDNS->dialog)){ + return($str); + } + $smarty->assign("netconfig", $str); - /* 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); - } + /* Display kerberos host key options */ + $smarty->assign("host_key",""); + if(is_object($this->kerberos_key_service)){ + $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/")); + } - if(isset($_POST["inheritAll"])){ - $this->set_everything_to_inherited(); - } - } - - - /* 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; - - /* 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; - } + /* Show main page */ + $smarty->assign("currently_installing", $this->currently_installing); + return($smarty->fetch (get_template_path('workstation.tpl', TRUE, dirname(__FILE__)))); } - $this->netConfigDNS->save_object(); + function remove_from_parent() + { + if($this->acl_is_removeable()){ - /* Set inherit mode */ - if((isset($_POST['workgeneric_posted'])) && ($this->acl_is_writeable("gotoNtpServer"))){ - if(isset($_POST["inheritTimeServer"]) && $this->member_of_ogroup){ - $this->inheritTimeServer = true; - }else{ - $this->inheritTimeServer = false; - } - } - - if(isset($_POST["inheritAll"])){ - $this->set_everything_to_inherited(); - } + $this->netConfigDNS->remove_from_parent(); + $ldap= $this->config->get_ldap_link(); + $ldap->rmdir($this->dn); + new log("remove","workstation/".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_DEL, get_class())); + } - /* 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(); - - /* Skip IP & Mac checks if this is a template */ - if($this->cn != "wdefault"){ - $message= array_merge($message, $this->netConfigDNS->check()); - } + /* Remove kerberos key dependencies too */ + if(is_object($this->kerberos_key_service)){ + $this->kerberos_key_service->remove_from_parent_by_prefix("host/"); + } - $this->dn= "cn=".$this->cn.",".get_ou("workgeneric", "workstationRDN").$this->base; + /* Optionally execute a command after we're done */ + $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - if ($this->cn == ""){ - $message[]= msgPool::required(_("Name")); - } + /* 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 (); + } - /* Check if given name is a valid host/dns name */ - if(!tests::is_dns_name($this->cn)){ - $message[] = msgPool::invalid(_("Name")); - } + /* Remove all accessTo/trust dependencies */ + update_accessTo($this->cn,""); + } - // Check if a wrong base was supplied - if(!$this->baseSelector->checkLastBaseUpdate()){ - $message[]= msgPool::check_base(); - } + /* 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); + } - if ($this->orig_dn != $this->dn){ - $ldap= $this->config->get_ldap_link(); - $ldap->cd ($this->base); - - if($this->cn == "wdefault"){ - $ldap->cat($this->dn); - }else{ - $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn")); - } - if ($ldap->count() != 0){ - while ($attrs= $ldap->fetch()){ - if (preg_match("/cn=dhcp,/",$attrs['dn']) || preg_match ("/,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $ldap->getDN())){ - continue; - } else { - if ($attrs['dn'] != $this->orig_dn){ - $message[]= msgPool::duplicated(_("Name")); - break; - } - } - } - } + if(isset($_POST["inheritAll"])){ + $this->set_everything_to_inherited(); + } } - /* Check for valid ntpServer selection */ - if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){ - $message[]= msgPool::required(_("NTP server")); - } - /* Only systems with a valid ldap handle can be activated - */ - if($this->gotoMode == "active" && $this->initial_gotoMode != "active"){ - - if(isset($this->parent->by_object['workstartup']) && - !count($this->parent->by_object['workstartup']->gotoLdapServers) && - !$this->parent->by_object['workstartup']->gotoLdap_inherit){ - - $message[] = _("A valid LDAP server assignement is missing!"); - } - }else{ - /* 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 want to save it, press 'OK'."), - CONFIRM_DIALOG); - } - } + /* Save data to object */ + function save_object() + { - /* 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); - } - - - /* 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)) || $this->auto_activate; - plugin::save(); - - /* Strip out 'default' values */ - foreach (array("gotoSyslogServer") as $val){ - - if (isset($this->attrs[$val]) && $this->attrs[$val] == "default"){ - $this->attrs[$val]= array(); - } - } + /* 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; - /* Add missing arrays */ - foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){ - if (isset ($this->$val) && count ($this->$val) != 0){ - $this->attrs["$val"]= $this->$val; - } - } + /* 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; + } + } + + $this->netConfigDNS->save_object(); - /* 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; + /* Set inherit mode */ + if((isset($_POST['workgeneric_posted'])) && ($this->acl_is_writeable("gotoNtpServer"))){ + if(isset($_POST["inheritTimeServer"]) && $this->member_of_ogroup){ + $this->inheritTimeServer = true; + }else{ + $this->inheritTimeServer = false; + } } - $attrs[$key]= $val; - } - $this->attrs= $attrs; - } - /* Update ntp server settings */ - if($this->inheritTimeServer){ - if($this->is_new){ - if(isset($this->attrs['gotoNtpServer'])){ - unset($this->attrs['gotoNtpServer']); - } - }else{ - $this->attrs['gotoNtpServer'] = array(); - } - }else{ - /* Set ntpServers */ - $this->attrs['gotoNtpServer'] = array(); - foreach($this->gotoNtpServer as $server){ - $this->attrs['gotoNtpServer'][] = $server; - } - } + if(isset($_POST["inheritAll"])){ + $this->set_everything_to_inherited(); + } - /* cn=default and macAddress=- indicates that this is a template */ - if($this->cn == "wdefault"){ - $this->netConfigDNS->macAddress = "-"; + /* Hanle kerberos host key plugin */ + if(is_object($this->kerberos_key_service)){ + $this->kerberos_key_service->save_object_by_prefix("host/"); + } } - /* 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","workstation/".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, 0, get_class())); - } - - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->save(); - - $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - } else { - if ($this->orig_dn != $this->dn){ - - /* Remove all accessTo/trust dependencies */ - update_accessTo($this->orig_cn,$this->cn); - } - $ldap->cd($this->dn); - $this->cleanup(); - $ldap->modify ($this->attrs); - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class())); - } - new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - - $this->netConfigDNS->cn = $this->cn; - $this->netConfigDNS->save(); - - $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); - } - if ($activate && class_available("DaemonEvent")){ - - /* 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); - } - } - } - } - - - /* Display generic part for server copy & paste */ - function getCopyDialog() - { - $vars = array("cn"); - $smarty = get_smarty(); - $smarty->assign("cn" ,$this->cn); - $smarty->assign("object","workstation"); - $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']; - } - } + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + /* Skip IP & Mac checks if this is a template */ + if($this->cn != "wdefault"){ + $message= array_merge($message, $this->netConfigDNS->check()); + } + $this->dn= "cn=".$this->cn.",".get_ou("workgeneric", "workstationRDN").$this->base; + + if ($this->cn == ""){ + $message[]= msgPool::required(_("Name")); + } - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - if(isset($source['macAddress'][0])){ - $this->netConfigDNS->macAddress = $source['macAddress'][0]; + /* Check if given name is a valid host/dns name */ + if(!tests::is_dns_name($this->cn)){ + $message[] = msgPool::invalid(_("Name")); + } + + // 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); + + if($this->cn == "wdefault"){ + $ldap->cat($this->dn); + }else{ + $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn")); + } + if ($ldap->count() != 0){ + while ($attrs= $ldap->fetch()){ + if (preg_match("/cn=dhcp,/",$attrs['dn']) || preg_match ("/,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $ldap->getDN())){ + continue; + } else { + if ($attrs['dn'] != $this->orig_dn){ + $message[]= msgPool::duplicated(_("Name")); + break; + } + } + } + } + } + + /* Check for valid ntpServer selection */ + if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){ + $message[]= msgPool::required(_("NTP server")); + } + + /* Only systems with a valid ldap handle can be activated + */ + if($this->gotoMode == "active" && $this->initial_gotoMode != "active"){ + + if(isset($this->parent->by_object['workstartup']) && + !count($this->parent->by_object['workstartup']->gotoLdapServers) && + !$this->parent->by_object['workstartup']->gotoLdap_inherit){ + + $message[] = _("A valid LDAP server assignement is missing!"); + } + }else{ + /* 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 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(); + } + + return ($message); } - if(isset($source['ipHostNumber'][0])){ - $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0]; + + + /* 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)) || $this->auto_activate; + plugin::save(); + + /* Strip out 'default' values */ + foreach (array("gotoSyslogServer") as $val){ + + if (isset($this->attrs[$val]) && $this->attrs[$val] == "default"){ + $this->attrs[$val]= array(); + } + } + + /* Add missing arrays */ + foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){ + if (isset ($this->$val) && count ($this->$val) != 0){ + $this->attrs["$val"]= $this->$val; + } + } + + /* 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; + } + + /* Update ntp server settings */ + if($this->inheritTimeServer){ + if($this->is_new){ + if(isset($this->attrs['gotoNtpServer'])){ + unset($this->attrs['gotoNtpServer']); + } + }else{ + $this->attrs['gotoNtpServer'] = array(); + } + }else{ + /* Set ntpServers */ + $this->attrs['gotoNtpServer'] = array(); + foreach($this->gotoNtpServer as $server){ + $this->attrs['gotoNtpServer'][] = $server; + } + } + + /* cn=default and macAddress=- indicates that this is a template */ + if($this->cn == "wdefault"){ + $this->netConfigDNS->macAddress = "-"; + } + + /* 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","workstation/".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, 0, get_class())); + } + + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->save(); + + $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + } else { + if ($this->orig_dn != $this->dn){ + + /* Remove all accessTo/trust dependencies */ + update_accessTo($this->orig_cn,$this->cn); + } + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class())); + } + new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->save(); + + $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber)); + } + + if ($activate && class_available("DaemonEvent")){ + + /* 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); + } + } + } } - /* Create used ntp server array */ - $this->gotoNtpServer= array(); - if(isset($source['gotoNtpServer'])){ - $this->inheritTimeServer = false; - unset($source['gotoNtpServer']['count']); - foreach($source['gotoNtpServer'] as $server){ - $this->gotoNtpServer[$server] = $server; - } + + /* 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","workstation"); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); } - /* Set inherit checkbox state */ - if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){ - $this->inheritTimeServer = true; - $this->gotoNtpServer=array(); + + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = get_post('cn'); + } } - } - - - /* Return plugin informations for acl handling - #FIXME FAIscript seams to ununsed within this class... */ - static function plInfo() - { - return (array( - "plShortName" => _("Generic"), - "plDescription" => _("Workstation generic"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 0, - "plSection" => array("administration"), - "plRequirements"=> array( - 'ldapSchema' => array('gotoWorkstation' => '>=2.7'), - 'onFailureDisablePlugin' => array(get_class()) - ), - "plCategory" => array("workstation" => array("description" => _("Workstation"), - "objectClass" => "gotoWorkstation")), - "plProperties" => - array( - array( - "name" => "workstationRDN", - "type" => "rdn", - "default" => "ou=workstations,ou=systems,", - "description" => _("The 'workstationRDN' statement defines the location where new workstations will be created. The default is 'ou=workstations,ou=systems,'."), - "check" => "gosaProperty::isRdn", - "migrate" => "migrate_workstationRDN", - "group" => "plugin", - "mandatory" => FALSE - ), - array( - "name" => "systemIsoHook", - "type" => "command", - "default" => "", - "description" => _("To enable the burn CD image function, you can specify the 'systemIsoHook'. You will get a CD symbol in the systems list - which calls the hook if pressed."), - "check" => "gosaProperty::isCommand", - "migrate" => "", - "group" => "plugin", - "mandatory" => FALSE - ) - ), - - "plProvidedAcls"=> array( - "cn" => _("Workstation name"), - "description" => _("Description") , - "l" => _("Location") , - "base" => _("Base") , - "gotoMode" => _("Goto mode"), - "gotoSyslogServer" => _("Syslog server"), - "gotoNtpServer" => _("Ntp server"), - "userPassword" => _("Root password"), - "createFAICD" => _("Create FAI CD"), - "FAIstate" => _("Action flag")) - )); - } - - function set_everything_to_inherited() - { - $this->gotoSyslogServer = "default"; - $this->inheritTimeServer = TRUE; - - /* Set workstation service attributes to inherited */ - if($this->member_of_ogroup && isset($this->parent->by_object['workservice'])){ - foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant","gotoXDriver", - "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){ - if($this->parent->by_object['workservice']->acl_is_writeable($name)){ - $this->parent->by_object['workservice']->$name = "default"; - } - } + + + 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]; + } + + /* Create used ntp server array */ + $this->gotoNtpServer= array(); + if(isset($source['gotoNtpServer'])){ + $this->inheritTimeServer = false; + unset($source['gotoNtpServer']['count']); + foreach($source['gotoNtpServer'] as $server){ + $this->gotoNtpServer[$server] = $server; + } + } + + /* Set inherit checkbox state */ + if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){ + $this->inheritTimeServer = true; + $this->gotoNtpServer=array(); + } } - /* Set workstation startup attributes to inherited */ - if($this->member_of_ogroup && isset($this->parent->by_object['workstartup'])){ - $obj = $this->parent->by_object['workstartup']; - if($obj->acl_is_writeable("gotoBootKernel")){ - $this->parent->by_object['workstartup']->gotoBootKernel = "default-inherited"; - } - if($obj->acl_is_writeable("gotoLdapServer")){ - $this->parent->by_object['workstartup']->gotoLdapServer = "default-inherited"; - $this->parent->by_object['workstartup']->gotoLdap_inherit = TRUE; - $this->parent->by_object['workstartup']->gotoLdapServers = array(); - } - if($obj->acl_is_writeable("FAIdebianMirror")){ - $this->parent->by_object['workstartup']->FAIdebianMirror= "inherited"; - } + + /* Return plugin informations for acl handling +#FIXME FAIscript seams to ununsed within this class... */ + static function plInfo() + { + return (array( + "plShortName" => _("Generic"), + "plDescription" => _("Workstation generic"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("administration"), + "plRequirements"=> array( + 'ldapSchema' => array('gotoWorkstation' => '>=2.7'), + 'onFailureDisablePlugin' => array(get_class()) + ), + "plCategory" => array("workstation" => array("description" => _("Workstation"), + "objectClass" => "gotoWorkstation")), + "plProperties" => + array( + array( + "name" => "workstationRDN", + "type" => "rdn", + "default" => "ou=workstations,ou=systems,", + "description" => _("The 'workstationRDN' statement defines the location where new workstations will be created. The default is 'ou=workstations,ou=systems,'."), + "check" => "gosaProperty::isRdn", + "migrate" => "migrate_workstationRDN", + "group" => "plugin", + "mandatory" => FALSE + ), + array( + "name" => "systemIsoHook", + "type" => "command", + "default" => "", + "description" => _("To enable the burn CD image function, you can specify the 'systemIsoHook'. You will get a CD symbol in the systems list - which calls the hook if pressed."), + "check" => "gosaProperty::isCommand", + "migrate" => "", + "group" => "plugin", + "mandatory" => FALSE + ) + ), + + "plProvidedAcls"=> array( + "cn" => _("Workstation name"), + "description" => _("Description") , + "l" => _("Location") , + "base" => _("Base") , + "gotoMode" => _("Goto mode"), + "gotoSyslogServer" => _("Syslog server"), + "gotoNtpServer" => _("Ntp server"), + "userPassword" => _("Root password"), + "createFAICD" => _("Create FAI CD"), + "FAIstate" => _("Action flag")) + )); + } + + function set_everything_to_inherited() + { + $this->gotoSyslogServer = "default"; + $this->inheritTimeServer = TRUE; + + /* Set workstation service attributes to inherited */ + if($this->member_of_ogroup && isset($this->parent->by_object['workservice'])){ + foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant","gotoXDriver", + "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){ + if($this->parent->by_object['workservice']->acl_is_writeable($name)){ + $this->parent->by_object['workservice']->$name = "default"; + } + } + } + + /* Set workstation startup attributes to inherited */ + if($this->member_of_ogroup && isset($this->parent->by_object['workstartup'])){ + $obj = $this->parent->by_object['workstartup']; + if($obj->acl_is_writeable("gotoBootKernel")){ + $this->parent->by_object['workstartup']->gotoBootKernel = "default-inherited"; + } + if($obj->acl_is_writeable("gotoLdapServer")){ + $this->parent->by_object['workstartup']->gotoLdapServer = "default-inherited"; + $this->parent->by_object['workstartup']->gotoLdap_inherit = TRUE; + $this->parent->by_object['workstartup']->gotoLdapServers = array(); + } + if($obj->acl_is_writeable("FAIdebianMirror")){ + $this->parent->by_object['workstartup']->FAIdebianMirror= "inherited"; + } + } } - } - 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)); + } } - // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/gosa-plugins/goto/admin/systems/goto/class_workstationService.inc b/gosa-plugins/goto/admin/systems/goto/class_workstationService.inc index 1bee31287..f64272722 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_workstationService.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_workstationService.inc @@ -2,590 +2,589 @@ class workservice extends plugin { - var $gotoScannerEnable; - - /* Generic terminal attributes */ - var $gotoXMonitor= ""; - var $gotoXDriver= ""; - var $gotoXResolution= ""; - var $gotoXColordepth= ""; - var $gotoXHsync= ""; - var $gotoXVsync= ""; - var $AutoSync = false; - var $gotoXKbModel= ""; - var $gotoXKbLayout= ""; - var $gotoXKbVariant= ""; - var $gotoXMouseType= ""; - var $gotoXMouseport= ""; - var $gotoScannerClients= ""; - var $gotoScannerBackend= ""; - var $goFonHardware= "automatic"; - var $view_logged = FALSE; - - /* Needed values and lists */ - var $ignore_account= TRUE; - var $base= ""; - var $cn= ""; - var $orig_dn= ""; - var $XDrivers= array(); - var $XResolutions = array(); - var $MouseTypes= array(); - var $MousePorts= array(); - var $hardware_list= array(); - var $used_hardware= array(); - - - /* attribute list for save action */ - var $attributes= array("gotoXMonitor", "gotoXDriver", "gotoXResolution", "gotoXColordepth", - "gotoXHsync", "gotoXVsync", - "gotoScannerEnable", "gotoScannerClients", - "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant", - "gotoXMouseType", "gotoXMouseport", "goFonHardware"); - var $objectclasses= array("GOhard"); - - var $XColordepths =array(); - var $XKbModels =array(); - var $XKbLayouts =array(); - var $XKbVariants =array(); - - function workservice (&$config, $dn= NULL, $parent= NULL) - { - plugin::plugin ($config, $dn, $parent); - - $this->XResolutions= array( - "640x480" => "640x480", - "800x600" => "800x600", - "1024x768" => "1024x768", - "1152x864" => "1152x864", - "1280x1024" => "1280x1024", - "1400x1050" => "1400x1050", - "1600x1200" => "1600x1200"); - - if($this->config->get_cfg_value("environment","resolutions") != ""){ - $file = $this->config->get_cfg_value("environment","resolutions"); - - if(is_readable($file)){ - $str = file_get_contents($file); - $lines = preg_split("/\n/",$str); - foreach($lines as $line){ - $line = trim($line); - if(!empty($line)){ - $this->XResolutions[$line]=$line; - } + var $gotoScannerEnable; + + /* Generic terminal attributes */ + var $gotoXMonitor= ""; + var $gotoXDriver= ""; + var $gotoXResolution= ""; + var $gotoXColordepth= ""; + var $gotoXHsync= ""; + var $gotoXVsync= ""; + var $AutoSync = false; + var $gotoXKbModel= ""; + var $gotoXKbLayout= ""; + var $gotoXKbVariant= ""; + var $gotoXMouseType= ""; + var $gotoXMouseport= ""; + var $gotoScannerClients= ""; + var $gotoScannerBackend= ""; + var $goFonHardware= "automatic"; + var $view_logged = FALSE; + + /* Needed values and lists */ + var $ignore_account= TRUE; + var $base= ""; + var $cn= ""; + var $orig_dn= ""; + var $XDrivers= array(); + var $XResolutions = array(); + var $MouseTypes= array(); + var $MousePorts= array(); + var $hardware_list= array(); + var $used_hardware= array(); + + + /* attribute list for save action */ + var $attributes= array("gotoXMonitor", "gotoXDriver", "gotoXResolution", "gotoXColordepth", + "gotoXHsync", "gotoXVsync", + "gotoScannerEnable", "gotoScannerClients", + "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant", + "gotoXMouseType", "gotoXMouseport", "goFonHardware"); + var $objectclasses= array("GOhard"); + + var $XColordepths =array(); + var $XKbModels =array(); + var $XKbLayouts =array(); + var $XKbVariants =array(); + + function workservice (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config, $dn, $parent); + + $this->XResolutions= array( + "640x480" => "640x480", + "800x600" => "800x600", + "1024x768" => "1024x768", + "1152x864" => "1152x864", + "1280x1024" => "1280x1024", + "1400x1050" => "1400x1050", + "1600x1200" => "1600x1200"); + + if($this->config->get_cfg_value("environment","resolutions") != ""){ + $file = $this->config->get_cfg_value("environment","resolutions"); + + if(is_readable($file)){ + $str = file_get_contents($file); + $lines = preg_split("/\n/",$str); + foreach($lines as $line){ + $line = trim($line); + if(!empty($line)){ + $this->XResolutions[$line]=$line; + } + } + //natcasesort($this->gotoXResolutions); + }else{ + msg_dialog::display(_("Configuration error"), msgPool::cannotReadFile($file), WARNING_DIALOG); + } } - //natcasesort($this->gotoXResolutions); - }else{ - msg_dialog::display(_("Configuration error"), msgPool::cannotReadFile($file), WARNING_DIALOG); - } - } - /* Get list of available xdrivers */ - $this->XDrivers = $this->getListOfXDrivers(); - - array_unshift($this->XDrivers, "["._("unknown")."]"); - - $this->XColordepths= array( - "8" => "8 " ._("bit"), - "15" => "15 "._("bit"), - "16" => "16 "._("bit"), - "24" => "24 "._("bit")); - - foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex", - "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless", - "logiinetnav", "logiinternet", "macintosh", "microsoft", - "microsoftpro", "omnikey101", "pc101", "pc102", "pc104", - "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){ - $this->XKbModels[$type] = $type; - } - - $this->MouseTypes= array("auto" => "auto", - "explorerps/2" => "explorerps/2", - "ImPS/2" => "ImPS/2", - "PS/2" => "PS/2", - "Microsoft" => "Microsoft", - "Logitech" => "Logitech"); + /* Get list of available xdrivers */ + $this->XDrivers = $this->getListOfXDrivers(); - $this->MousePorts= array("/dev/input/mice" => "/dev/input/mice", - "/dev/mouse" => "/dev/mouse", - "/dev/psaux" => "/dev/psaux", - "/dev/ttyS0" => "/dev/ttyS0", - "/dev/ttyS1" => "/dev/ttyS1"); + array_unshift($this->XDrivers, "["._("unknown")."]"); - /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */ - $this->XKbLayouts = array("de"=> "de","en" =>"en", "es" => "es", "us" =>"us", "fr" => "fr"); - $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic"); + $this->XColordepths= array( + "8" => "8 " ._("bit"), + "15" => "15 "._("bit"), + "16" => "16 "._("bit"), + "24" => "24 "._("bit")); - /* try to read additional keyboard layouts - */ - if(file_exists(CONFIG_DIR."/keyboardLayouts")){ - if(is_readable(CONFIG_DIR."/keyboardLayouts")){ - $str = file_get_contents(CONFIG_DIR."/keyboardLayouts"); - $tmp = preg_split("/\n/",$str); - foreach($tmp as $entry){ - if((!empty($entry)) && (!preg_match("/^#/",$entry))){ - $entry = trim($entry); - $tmp2 = explode(":",$entry); - $la = trim($tmp2[0]); // What would be saved to ldap - $da = trim($tmp2[1]); // This wis displayed in the listbox - $this->XKbLayouts [ $la] = $da; - } + foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex", + "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless", + "logiinetnav", "logiinternet", "macintosh", "microsoft", + "microsoftpro", "omnikey101", "pc101", "pc102", "pc104", + "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){ + $this->XKbModels[$type] = $type; } - } - } - - $this->orig_dn= $this->dn; - /* Load phone hardware list - */ - $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneGeneric", "phoneRDN")), - $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK); - foreach($tmp as $attrs){ - $cn= $attrs['cn'][0]; - $description= ""; - if (isset($attrs['description'])){ - $description= " - ".$attrs['description'][0]; - } - $this->hardware_list[$cn]= "$cn$description"; - } - $this->hardware_list["automatic"]= _("automatic"); - ksort($this->hardware_list); + $this->MouseTypes= array("auto" => "auto", + "explorerps/2" => "explorerps/2", + "ImPS/2" => "ImPS/2", + "PS/2" => "PS/2", + "Microsoft" => "Microsoft", + "Logitech" => "Logitech"); - /* These departments may contain objects that have - goFonHardware set. - */ - $deps_a = array( - get_people_ou(), - get_ou("group", "ogroupRDN"), - get_ou("servgeneric", "serverRDN"), - get_ou("termgeneric", "terminalRDN"), - get_ou("workgeneric", "workstationRDN"), - get_ou("printgeneric", "printerRDN"), - get_ou("componentGeneric", "componentRDN"), - get_ou("phoneGeneric", "phoneRDN")); - - $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'], - array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK); - foreach($tmp as $attrs){ - $cn = $attrs['goFonHardware'][0]; - if(isset($this->hardware_list[$cn])){ - $this->used_hardware[$cn]= $cn; - } - } + $this->MousePorts= array("/dev/input/mice" => "/dev/input/mice", + "/dev/mouse" => "/dev/mouse", + "/dev/psaux" => "/dev/psaux", + "/dev/ttyS0" => "/dev/ttyS0", + "/dev/ttyS1" => "/dev/ttyS1"); - if(preg_match("/\+/",$this->gotoXHsync)){ - $this->AutoSync = true; - $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync); - $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync); - } + /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */ + $this->XKbLayouts = array("de"=> "de","en" =>"en", "es" => "es", "us" =>"us", "fr" => "fr"); + $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic"); - /* Load hardware list */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))"); - if ($ldap->count() == 1){ - $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout", - "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport", "gotoXDriver"); - $attrs= $ldap->fetch(); - - foreach ($map as $name){ - if (!isset($attrs[$name][0])){ - continue; + /* try to read additional keyboard layouts + */ + if(file_exists(CONFIG_DIR."/keyboardLayouts")){ + if(is_readable(CONFIG_DIR."/keyboardLayouts")){ + $str = file_get_contents(CONFIG_DIR."/keyboardLayouts"); + $tmp = preg_split("/\n/",$str); + foreach($tmp as $entry){ + if((!empty($entry)) && (!preg_match("/^#/",$entry))){ + $entry = trim($entry); + $tmp2 = explode(":",$entry); + $la = trim($tmp2[0]); // What would be saved to ldap + $da = trim($tmp2[1]); // This wis displayed in the listbox + $this->XKbLayouts [ $la] = $da; + } + } + } } - - switch ($name){ - case 'gotoXDriver': - $this->XDrivers= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers; - break; - case 'gotoXResolution': - $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions; - break; - case 'gotoXColordepth': - $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths; - break; - case 'gotoXKbModel': - $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels; - break; - case 'gotoXKbLayout': - $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts; - break; - case 'gotoXKbVariant': - $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants; - break; - case 'gotoXMouseType': - $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes; - break; - case 'gotoXMouseport': - $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts; - break; + + $this->orig_dn= $this->dn; + + /* Load phone hardware list + */ + $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneGeneric", "phoneRDN")), + $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK); + foreach($tmp as $attrs){ + $cn= $attrs['cn'][0]; + $description= ""; + if (isset($attrs['description'])){ + $description= " - ".$attrs['description'][0]; + } + $this->hardware_list[$cn]= "$cn$description"; } + $this->hardware_list["automatic"]= _("automatic"); + ksort($this->hardware_list); - } + /* These departments may contain objects that have + goFonHardware set. + */ + $deps_a = array( + get_people_ou(), + get_ou("group", "ogroupRDN"), + get_ou("servgeneric", "serverRDN"), + get_ou("termgeneric", "terminalRDN"), + get_ou("workgeneric", "workstationRDN"), + get_ou("printgeneric", "printerRDN"), + get_ou("componentGeneric", "componentRDN"), + get_ou("phoneGeneric", "phoneRDN")); + + $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'], + array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK); + foreach($tmp as $attrs){ + $cn = $attrs['goFonHardware'][0]; + if(isset($this->hardware_list[$cn])){ + $this->used_hardware[$cn]= $cn; + } + } - } + if(preg_match("/\+/",$this->gotoXHsync)){ + $this->AutoSync = true; + $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync); + $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync); + } - /* Workaround to fill in inherited values if we've specified an objectclass */ - $SelectedSystemType = session::get("SelectedSystemType"); - if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){ - $this->XResolutions= array('default' => _("inherited")); - $this->XColordepths= array('default' => _("inherited")); - $this->XKbModels= array('default' => _("inherited")); - $this->XKbLayouts= array('default' => _("inherited")); - $this->XKbVariants= array('default' => _("inherited")); - $this->MouseTypes= array('default' => _("inherited")); - $this->MousePorts= array('default' => _("inherited")); - } - } + /* Load hardware list */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))"); + if ($ldap->count() == 1){ + $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout", + "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport", "gotoXDriver"); + $attrs= $ldap->fetch(); + + foreach ($map as $name){ + if (!isset($attrs[$name][0])){ + continue; + } - function execute() - { - /* Call parent execute */ - plugin::execute(); + switch ($name){ + case 'gotoXDriver': + $this->XDrivers= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers; + break; + case 'gotoXResolution': + $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions; + break; + case 'gotoXColordepth': + $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths; + break; + case 'gotoXKbModel': + $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels; + break; + case 'gotoXKbLayout': + $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts; + break; + case 'gotoXKbVariant': + $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants; + break; + case 'gotoXMouseType': + $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes; + break; + case 'gotoXMouseport': + $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts; + break; + } - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","workstation/".get_class($this),$this->dn); - } + } - /* Do we need to flip is_account state? */ - if (isset($_POST['modify_state'])){ - $this->is_account= !$this->is_account; - } + } - /* Do we need to flip is_account state? */ - if(isset($_POST['modify_state'])){ - if($this->is_account && $this->acl_is_removeable()){ - $this->is_account= FALSE; - }elseif(!$this->is_account && $this->acl_is_createable()){ - $this->is_account= TRUE; - } + /* Workaround to fill in inherited values if we've specified an objectclass */ + $SelectedSystemType = session::get("SelectedSystemType"); + if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){ + $this->XResolutions= array('default' => _("inherited")); + $this->XColordepths= array('default' => _("inherited")); + $this->XKbModels= array('default' => _("inherited")); + $this->XKbLayouts= array('default' => _("inherited")); + $this->XKbVariants= array('default' => _("inherited")); + $this->MouseTypes= array('default' => _("inherited")); + $this->MousePorts= array('default' => _("inherited")); + } } - /* Show main page */ - $smarty= get_smarty(); + function execute() + { + /* Call parent execute */ + plugin::execute(); - /* Assign ACLs */ - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $smarty->assign($name."ACL",$this->getacl($name)); - } + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","workstation/".get_class($this),$this->dn); + } - /* Arrays */ - foreach(array("XDrivers", "XResolutions", "XColordepths", - "XKbModels", "XKbVariants", - "MouseTypes", "MousePorts") as $val){ - $smarty->assign("$val", $this->$val); - } - $smarty->assign("XKbLayouts" ,$this->XKbLayouts); - $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts)); + /* Do we need to flip is_account state? */ + if (isset($_POST['modify_state'])){ + $this->is_account= !$this->is_account; + } - $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']); - $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']); - $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']); + /* Do we need to flip is_account state? */ + if(isset($_POST['modify_state'])){ + if($this->is_account && $this->acl_is_removeable()){ + $this->is_account= FALSE; + }elseif(!$this->is_account && $this->acl_is_createable()){ + $this->is_account= TRUE; + } + } - /* Variables - select */ - foreach(array( - "gotoXDriver", "gotoXResolution", "gotoXColordepth", - "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable", - "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){ + /* Show main page */ + $smarty= get_smarty(); - $smarty->assign($val."_select", $this->$val); - } + /* Assign ACLs */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $smarty->assign($name."ACL",$this->getacl($name)); + } - /* Variables */ - foreach(array("gotoXHsync", "gotoXVsync") as $val){ - $smarty->assign($val, $this->$val); - } + /* Arrays */ + foreach(array("XDrivers", "XResolutions", "XColordepths", + "XKbModels", "XKbVariants", + "MouseTypes", "MousePorts") as $val){ + $smarty->assign("$val", set_post($this->$val)); + } + $smarty->assign("XKbLayouts" ,set_post($this->XKbLayouts)); + $smarty->assign("XKbLayoutKeys" ,set_post(array_flip($this->XKbLayouts))); - /* Checkboxes */ - foreach(array("gotoScannerEnable") as $val){ - if ($this->$val == TRUE) { - $smarty->assign("$val", "checked"); - } else { - $smarty->assign("$val", ""); - } - } + $smarty->assign("xdmcpservers",set_post($this->config->data['SERVERS']['TERMINAL'])); + $smarty->assign("nfsservers", set_post($this->config->data['SERVERS']['NFS'])); - /* Phone stuff */ - $smarty->assign ("goFonHardware", $this->goFonHardware); + /* Variables - select */ + foreach(array( + "gotoXDriver", "gotoXResolution", "gotoXColordepth", + "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable", + "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){ - $perms = ""; - if(!$this->acl_is_writeable("goFonHardware")){ - $perms = " disabled "; - } + $smarty->assign($val."_select", set_post($this->$val)); + } - $hl= "\n"; - $smarty->assign ("hardware_list", $hl); - $smarty->assign ("gotoXMonitor", $this->gotoXMonitor); - - if($this->AutoSync){ - $smarty->assign("AutoSyncCHK"," checked "); - $smarty->assign("hiddenState"," disabled "); - }else{ - $smarty->assign("AutoSyncCHK"," "); - $smarty->assign("hiddenState",""); - } + /* Variables */ + foreach(array("gotoXHsync", "gotoXVsync") as $val){ + $smarty->assign($val, set_post($this->$val)); + } - /* Show main page */ - return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__)))); - } - - function remove_from_parent() - { - $this->handle_post_events("remove"); - new log("remove","workstation/".get_class($this),$this->dn); - } - - /* Save data to object */ - function save_object() - { - plugin::save_object(); - - if((isset($_POST['workservicePosted'])) && $this->acl_is_writeable("AutoSync")) { - if(isset($_POST['AutoSync'])){ - $this->AutoSync = true; - }else{ - $this->AutoSync = false; - } - } - } - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - /* Default entries can use blank hsync/vsync entries */ - if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){ - - /* But only if no auto sync is enabled... */ - if (!$this->AutoSync){ - - /* Check vsync for correct usage */ - $val= preg_replace ("/\s/", "", $this->gotoXVsync); - - if($this->acl_is_writeable("gotoXVsync")){ - if(empty($val)){ - $message[]= msgPool::required(_("VSync")); - }elseif (!preg_match ("/^\d+(\.\d+)?([+-]\d+(\.\d+)?)?$/", $val)){ - $message[]= msgPool::invalid(_("VSync")); - } else{ - if (!preg_match('/^\d+$/', $val)){ - list($v1,$v2)= preg_split ("/[-+]/", $val); - if ($v2 != ""){ - if ($v1 > $v2){ - $message[]= msgPool::invalid(_("VSync")); - } - } + /* Checkboxes */ + foreach(array("gotoScannerEnable") as $val){ + if ($this->$val == TRUE) { + $smarty->assign("$val", "checked"); + } else { + $smarty->assign("$val", ""); } - } } - /* Check hsync for correct usage */ - $val= preg_replace ("/\s/", "", $this->gotoXHsync); - if($this->acl_is_writeable("gotoXHsync")){ - if(empty($val)){ - $message[]= msgPool::required(_("HSync")); - }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){ - $message[]= msgPool::invalid(_("HSync")); - } else{ - if (!preg_match('/^\d+$/', $val)){ - list($v1,$v2)= preg_split ("/[-+]/", $val); - if ($v2 != ""){ - if ($v1 > $v2){ - $message[]= msgPool::invalid(_("HSync")); - } - } + /* Phone stuff */ + $smarty->assign ("goFonHardware", $this->goFonHardware); + + $perms = ""; + if(!$this->acl_is_writeable("goFonHardware")){ + $perms = " disabled "; + } + + $hl= "\n"; + $smarty->assign ("hardware_list", $hl); + $smarty->assign ("gotoXMonitor", set_post($this->gotoXMonitor)); + + if($this->AutoSync){ + $smarty->assign("AutoSyncCHK"," checked "); + $smarty->assign("hiddenState"," disabled "); + }else{ + $smarty->assign("AutoSyncCHK"," "); + $smarty->assign("hiddenState",""); + } + + /* Show main page */ + return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__)))); } - return ($message); - } + function remove_from_parent() + { + $this->handle_post_events("remove"); + new log("remove","workstation/".get_class($this),$this->dn); + } + /* Save data to object */ + function save_object() + { + plugin::save_object(); - /* Save to LDAP */ - function save() - { - /* remove objectclass GOhard if this is an ogroup tab */ - if(isset($this->parent->by_object['ogroup'])){ - $this->objectclasses = array(); + if((isset($_POST['workservicePosted'])) && $this->acl_is_writeable("AutoSync")) { + if(isset($_POST['AutoSync'])){ + $this->AutoSync = true; + }else{ + $this->AutoSync = false; + } + } } - plugin::save(); + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + /* Default entries can use blank hsync/vsync entries */ + if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){ + + /* But only if no auto sync is enabled... */ + if (!$this->AutoSync){ + + /* Check vsync for correct usage */ + $val= preg_replace ("/\s/", "", $this->gotoXVsync); + + if($this->acl_is_writeable("gotoXVsync")){ + if(empty($val)){ + $message[]= msgPool::required(_("VSync")); + }elseif (!preg_match ("/^\d+(\.\d+)?([+-]\d+(\.\d+)?)?$/", $val)){ + $message[]= msgPool::invalid(_("VSync")); + } else{ + if (!preg_match('/^\d+$/', $val)){ + list($v1,$v2)= preg_split ("/[-+]/", $val); + if ($v2 != ""){ + if ($v1 > $v2){ + $message[]= msgPool::invalid(_("VSync")); + } + } + } + } + } - /* Strip out 'default' values */ - foreach(array( - "gotoXDriver", "gotoXResolution", "gotoXColordepth", - "gotoXKbModel", "gotoXKbLayout", - "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){ + /* Check hsync for correct usage */ + $val= preg_replace ("/\s/", "", $this->gotoXHsync); + if($this->acl_is_writeable("gotoXHsync")){ + if(empty($val)){ + $message[]= msgPool::required(_("HSync")); + }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){ + $message[]= msgPool::invalid(_("HSync")); + } else{ + if (!preg_match('/^\d+$/', $val)){ + list($v1,$v2)= preg_split ("/[-+]/", $val); + if ($v2 != ""){ + if ($v1 > $v2){ + $message[]= msgPool::invalid(_("HSync")); + } + } + } + } + } + } + } - if ($this->attrs[$val] == "default"){ - $this->attrs[$val]= array(); - } + return ($message); } - if($this->AutoSync){ - $this->attrs['gotoXHsync'] = "30+55"; - $this->attrs['gotoXVsync'] = "50+70"; - } - /* Write back to ldap */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $this->cleanup(); + /* Save to LDAP */ + function save() + { + /* remove objectclass GOhard if this is an ogroup tab */ + if(isset($this->parent->by_object['ogroup'])){ + $this->objectclasses = array(); + } + plugin::save(); - $ldap->modify ($this->attrs); - new log("modify","workstation/".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())); - } - $this->handle_post_events("modify"); + /* Strip out 'default' values */ + foreach(array( + "gotoXDriver", "gotoXResolution", "gotoXColordepth", + "gotoXKbModel", "gotoXKbLayout", + "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){ - /* Send goto reload event to gosaSupportDaemon */ - if(count($this->attrs)){ - $this->send_goto_reload(); - } + if ($this->attrs[$val] == "default"){ + $this->attrs[$val]= array(); + } + } + + if($this->AutoSync){ + $this->attrs['gotoXHsync'] = "30+55"; + $this->attrs['gotoXVsync'] = "50+70"; + } + + /* Write back to ldap */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $this->cleanup(); - } + $ldap->modify ($this->attrs); + new log("modify","workstation/".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())); + } + $this->handle_post_events("modify"); - function getListOfXDrivers() - { - /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */ - $drivers = array(); - if (file_exists(CONFIG_DIR.'/xdrivers')){ - $xdrivers = file (CONFIG_DIR.'/xdrivers'); - foreach ($xdrivers as $line){ - if (!preg_match ("/^#/", $line)){ - $drivers[]= trim($line); + /* Send goto reload event to gosaSupportDaemon */ + if(count($this->attrs)){ + $this->send_goto_reload(); } - } - } else { - $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx", - "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia", - "r128", "radeonhd", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion", - "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware"); - } - $tmp = array(); - foreach($drivers as $name){ - $tmp[$name] = $name; + } - return($tmp); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Service"), - "plDescription" => _("Workstation service"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 10, - "plSection" => array("administration"), - "plCategory" => array("workstation","ogroups"), - - "plProvidedAcls"=> array( - "gotoXMonitor" => _("Monitor"), - "gotoXDriver" => _("Gfx driver"), - "gotoXResolution" => _("Gfx resolution"), - "gotoXColordepth" => _("Gfx color depth"), - "gotoXHsync" => _("HSync"), - "gotoXVsync" => _("VSync"), - "AutoSync" => _("Use DDC"), - "gotoScannerEnable" => _("Scanner enabled"), - "gotoXKbModel" => _("Keyboard model"), - "gotoXKbLayout" => _("Keyboard layout"), - "gotoXKbVariant" => _("Keyboard variant"), - "gotoXMouseType" => _("Mouse type"), - "gotoXMouseport" => _("Mouse port"), - "goFonHardware" => _("Telephone hardware")) - )); - } - - - /*! \brief Send goto_reload event to support daemon - */ - function send_goto_reload() - { - if(count($this->attrs) && class_available("DaemonEvent")){ - $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); - $o_queue = new gosaSupportDaemon(); - if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){ - $evt = $events['TRIGGERED']['DaemonEvent_goto_reload']; - $macs = array(); - - /* Get list of macAddresses - */ - if(isset($this->parent->by_object['ogroup'])){ - /* If we are an object group, add all member macs - */ - $p = $this->parent->by_object['ogroup']; - foreach($p->memberList as $dn => $obj){ - if(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/",$dn)) continue; - if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){ - $macs[] = $p->objcache[$dn]['macAddress']; + function getListOfXDrivers() + { + /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */ + $drivers = array(); + if (file_exists(CONFIG_DIR.'/xdrivers')){ + $xdrivers = file (CONFIG_DIR.'/xdrivers'); + foreach ($xdrivers as $line){ + if (!preg_match ("/^#/", $line)){ + $drivers[]= trim($line); + } } - } - }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){ - - /* We are a workstation. Add current mac. - */ - $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; - if(!empty($mac) && !preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/",$this->orig_dn)){ - $macs[] = $mac; - } + } else { + $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx", + "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia", + "r128", "radeonhd", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion", + "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware"); + } + $tmp = array(); + foreach($drivers as $name){ + $tmp[$name] = $name; } - /* Trigger event for all member objects - */ - if(count($macs)){ - $tmp = new $evt['CLASS_NAME']($this->config); - $tmp->set_type(TRIGGERED_EVENT); - $target = $o_queue->get_host().":".$o_queue->get_port(); - $tmp->add_targets(array($target)); - $tmp->set_macs($macs); - if(!$o_queue->append($tmp,TRUE)){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - } + return($tmp); + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Service"), + "plDescription" => _("Workstation service"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 10, + "plSection" => array("administration"), + "plCategory" => array("workstation","ogroups"), + + "plProvidedAcls"=> array( + "gotoXMonitor" => _("Monitor"), + "gotoXDriver" => _("Gfx driver"), + "gotoXResolution" => _("Gfx resolution"), + "gotoXColordepth" => _("Gfx color depth"), + "gotoXHsync" => _("HSync"), + "gotoXVsync" => _("VSync"), + "AutoSync" => _("Use DDC"), + "gotoScannerEnable" => _("Scanner enabled"), + "gotoXKbModel" => _("Keyboard model"), + "gotoXKbLayout" => _("Keyboard layout"), + "gotoXKbVariant" => _("Keyboard variant"), + "gotoXMouseType" => _("Mouse type"), + "gotoXMouseport" => _("Mouse port"), + "goFonHardware" => _("Telephone hardware")) + )); + } + + + /*! \brief Send goto_reload event to support daemon + */ + function send_goto_reload() + { + if(count($this->attrs) && class_available("DaemonEvent")){ + $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); + $o_queue = new gosaSupportDaemon(); + if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){ + $evt = $events['TRIGGERED']['DaemonEvent_goto_reload']; + $macs = array(); + + /* Get list of macAddresses + */ + if(isset($this->parent->by_object['ogroup'])){ + + /* If we are an object group, add all member macs + */ + $p = $this->parent->by_object['ogroup']; + foreach($p->memberList as $dn => $obj){ + if(preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/",$dn)) continue; + if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){ + $macs[] = $p->objcache[$dn]['macAddress']; + } + } + }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){ + + /* We are a workstation. Add current mac. + */ + $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; + if(!empty($mac) && !preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/",$this->orig_dn)){ + $macs[] = $mac; + } + } + + /* Trigger event for all member objects + */ + if(count($macs)){ + $tmp = new $evt['CLASS_NAME']($this->config); + $tmp->set_type(TRIGGERED_EVENT); + $target = $o_queue->get_host().":".$o_queue->get_port(); + $tmp->add_targets(array($target)); + $tmp->set_macs($macs); + if(!$o_queue->append($tmp,TRUE)){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + } + } + } } - } } - } - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); - if(preg_match("/\+/",$this->gotoXHsync)){ - $this->AutoSync = true; - $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync); - $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync); + if(preg_match("/\+/",$this->gotoXHsync)){ + $this->AutoSync = true; + $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync); + $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync); + } } - } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-plugins/goto/admin/systems/goto/class_workstationStartup.inc b/gosa-plugins/goto/admin/systems/goto/class_workstationStartup.inc index 8f5e874be..589c24625 100644 --- a/gosa-plugins/goto/admin/systems/goto/class_workstationStartup.inc +++ b/gosa-plugins/goto/admin/systems/goto/class_workstationStartup.inc @@ -1,1237 +1,1236 @@ pluginEnabled("faiManagement")){ - $this->fai_activated = TRUE; - }else{ - $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare"); - $this->objectclasses = array("GOhard"); - } + /* Ldap server list */ + var $gotoLdapServers = array(); + var $gotoLdapServerList = array(); + var $gotoLdap_inherit = FALSE; + + /* Generic terminal attributes */ +# This is disabled as long there is no possiblilty to set these parameters + var $gotoBootKernel = "default-inherited"; + var $gotoKernelParameters = ""; + var $gotoLdapServer = "default-inherited"; + var $gotoModules = array(); + var $gotoAutoFs = array(); + var $gotoFilesystem = array(); + var $gotoTerminalPath = ""; + var $gotoBootKernels = array(); + + /* attribute list for save action */ + var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", + "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease"); + var $objectclasses = array("GOhard", "FAIobject"); + + /* Share */ + var $gotoShares = array();// Currently Share Option + var $gotoShare = ""; // currently selected Share Option + var $gotoShareSelections= array();// Available Shares for this account in Listbox format + var $gotoAvailableShares= array();// Available Shares for this account + + /* Helper */ + var $orig_dn = ""; + var $ignore_account = TRUE; + + /* FAI class selection */ + var $FAIclass = array(); // The currently selected classes + var $FAIrelease = ""; + var $FAIdebianMirror = "auto"; + var $si_active = FALSE; + var $si_fai_action_failed = FALSE; + + var $cache = array(); // Used as cache in fai mehtods + + var $FAIstatus = ""; + var $FAIclasses = array(); + + var $view_logged = FALSE; + + /* FAI class selection */ + var $InheritedFAIclass = array(); + var $InheritedFAIrelease = ""; + var $InheritedFAIdebianMirror= "auto"; + + var $CopyPasteVars = array("gotoModules","gotoShares"); + var $fai_activated = FALSE; + var $o_group_dn = ""; + var $member_of_ogroup = FALSE; + + function workstartup (&$config, $dn= NULL, $parent= NULL) + { + /* Check if FAI is active */ + if($config->pluginEnabled("faiManagement")){ + $this->fai_activated = TRUE; + }else{ + $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare"); + $this->objectclasses = array("GOhard"); + } - plugin::plugin ($config, $dn, $parent); - - /* Check for si daemon */ - $this->si_active = $this->config->get_cfg_value("core","gosaSupportURI") != ""; - - /* Check object group membership */ - if(!isset($this->parent->by_object['ogroup'])){ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->config->current['BASE']); - $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn")); - if($ldap->count()){ - $this->member_of_ogroup = TRUE; - $attrs = $ldap->fetch(); - $this->o_group_dn = $attrs['dn']; - } - } + plugin::plugin ($config, $dn, $parent); - /* Creating a list of valid Mirrors - * none will not be saved to ldap. - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ui = get_userinfo(); - foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){ - if($ui->get_category_permissions($data['dn'],"server",TRUE)){ - for($i = 0; $i < $data['goLdapBase']['count']; $i ++){ - $name = $data["cn"][0].":".$data["goLdapBase"][$i]; - $this->gotoLdapServerList[]= $name; + /* Check for si daemon */ + $this->si_active = $this->config->get_cfg_value("core","gosaSupportURI") != ""; + + /* Check object group membership */ + if(!isset($this->parent->by_object['ogroup'])){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn")); + if($ldap->count()){ + $this->member_of_ogroup = TRUE; + $attrs = $ldap->fetch(); + $this->o_group_dn = $attrs['dn']; + } } - } - } - /* Get list of assigned ldap servers - */ - if(isset($this->attrs['gotoLdapServer'])){ - unset($this->attrs['gotoLdapServer']['count']); - sort($this->attrs['gotoLdapServer']); - foreach($this->attrs['gotoLdapServer'] as $value){ - $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value); - } - } - natcasesort($this->gotoLdapServerList); - - if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ - $this->gotoLdap_inherit = TRUE; - } + /* Creating a list of valid Mirrors + * none will not be saved to ldap. + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ui = get_userinfo(); + foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){ + if($ui->get_category_permissions($data['dn'],"server",TRUE)){ + for($i = 0; $i < $data['goLdapBase']['count']; $i ++){ + $name = $data["cn"][0].":".$data["goLdapBase"][$i]; + $this->gotoLdapServerList[]= $name; + } + } + } - /* FAI Initialization - Skip this if FAI is not activated - */ - if($this->fai_activated) { - - /* Parse used FAIclasses (stored as string). - * The single classes are seperated by ' '. - * There is also the release type given, after first - * occurrence of ':'. - */ - $this->FAIclass =array(); - if(isset($this->attrs['FAIclass'][0])){ - $tmp = explode(" ",$this->attrs['FAIclass'][0]); - $tmp2 =array(); - - foreach($tmp as $class){ - if( ":" == $class[0] ) { - $this->FAIrelease = trim(substr($class, 1)); - }else{ - $tmp2[$class] = $class; - } + /* Get list of assigned ldap servers + */ + if(isset($this->attrs['gotoLdapServer'])){ + unset($this->attrs['gotoLdapServer']['count']); + sort($this->attrs['gotoLdapServer']); + foreach($this->attrs['gotoLdapServer'] as $value){ + $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value); + } + } + natcasesort($this->gotoLdapServerList); + + if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ + $this->gotoLdap_inherit = TRUE; } - $this->FAIclass = $tmp2; - } - } - /* Get arrays */ - foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){ - if (isset($this->attrs["$val"]["count"])){ - for ($i= 0; $i<$this->attrs["count"]; $i++){ - if (isset($this->attrs["$val"][$i])){ - array_push($this->$val, $this->attrs["$val"][$i]); - } + /* FAI Initialization + Skip this if FAI is not activated + */ + if($this->fai_activated) { + + /* Parse used FAIclasses (stored as string). + * The single classes are seperated by ' '. + * There is also the release type given, after first + * occurrence of ':'. + */ + $this->FAIclass =array(); + if(isset($this->attrs['FAIclass'][0])){ + $tmp = explode(" ",$this->attrs['FAIclass'][0]); + $tmp2 =array(); + + foreach($tmp as $class){ + if( ":" == $class[0] ) { + $this->FAIrelease = trim(substr($class, 1)); + }else{ + $tmp2[$class] = $class; + } + } + $this->FAIclass = $tmp2; + } } - } - sort ($this->$val); - $this->$val= array_unique($this->$val); - } - /* Prepare Shares */ - if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){ - unset($this->attrs['gotoShare']['count']); - foreach($this->attrs['gotoShare'] as $share){ - $tmp = $tmp2 = array(); - $tmp = explode("|",$share); - $tmp2['server'] =$tmp[0]; - $tmp2['name'] =$tmp[1]; - $tmp2['mountPoint'] =$tmp[2]; - $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2; - } - } + /* Get arrays */ + foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){ + if (isset($this->attrs["$val"]["count"])){ + for ($i= 0; $i<$this->attrs["count"]; $i++){ + if (isset($this->attrs["$val"][$i])){ + array_push($this->$val, $this->attrs["$val"][$i]); + } + } + } + sort ($this->$val); + $this->$val= array_unique($this->$val); + } - $this->gotoShareSelections= $config->getShareList(true); - $this->gotoAvailableShares= $config->getShareList(false); - $tmp2 = array(); - + /* Prepare Shares */ + if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){ + unset($this->attrs['gotoShare']['count']); + foreach($this->attrs['gotoShare'] as $share){ + $tmp = $tmp2 = array(); + $tmp = explode("|",$share); + $tmp2['server'] =$tmp[0]; + $tmp2['name'] =$tmp[1]; + $tmp2['mountPoint'] =$tmp[2]; + $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2; + } + } - $this->orig_dn= $this->dn; + $this->gotoShareSelections= $config->getShareList(true); + $this->gotoAvailableShares= $config->getShareList(false); + $tmp2 = array(); - /* Handle inheritance value "default" */ - if ($this->member_of_ogroup){ - $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']'); - } - /* If we are member in an object group, - * we have to handle inherited values. - * So you can see what is inherited. - */ - if ($this->member_of_ogroup){ + $this->orig_dn= $this->dn; + + /* Handle inheritance value "default" */ + if ($this->member_of_ogroup){ + $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']'); + } - if(count($this->FAIclass)==0 && $this->FAIrelease == ""){ - $this->FAIdebianMirror = "inherited"; - } + /* If we are member in an object group, + * we have to handle inherited values. + * So you can see what is inherited. + */ + if ($this->member_of_ogroup){ + + if(count($this->FAIclass)==0 && $this->FAIrelease == ""){ + $this->FAIdebianMirror = "inherited"; + } + + if($this->fai_activated){ + $map= array("gotoBootKernel","FAIclass","FAIdebianMirror"); + }else{ + $map= array("gotoBootKernel"); + } + + $ldap = $this->config->get_ldap_link(); + $ldap->cat($this->o_group_dn); + $attrs= $ldap->fetch(); + + foreach ($map as $name){ + if (!isset($attrs[$name][0])){ + continue; + } - if($this->fai_activated){ - $map= array("gotoBootKernel","FAIclass","FAIdebianMirror"); - }else{ - $map= array("gotoBootKernel"); - } + switch ($name){ + case 'gotoBootKernel': + $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ; + break; - $ldap = $this->config->get_ldap_link(); - $ldap->cat($this->o_group_dn); - $attrs= $ldap->fetch(); + case 'FAIclass': + $str = explode(":",$attrs[$name][0]); + $this->InheritedFAIclass = explode(" ",trim($str[0])); + $this->InheritedFAIrelease = trim($str[1]); + break; - foreach ($map as $name){ - if (!isset($attrs[$name][0])){ - continue; + case 'FAIdebianMirror': + $this->InheritedFAIdebianMirror = $attrs[$name][0]; + break; + } + } } - switch ($name){ - case 'gotoBootKernel': - $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ; - break; + $this->update_fai_cache(); + + if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){ - case 'FAIclass': - $str = explode(":",$attrs[$name][0]); - $this->InheritedFAIclass = explode(" ",trim($str[0])); - $this->InheritedFAIrelease = trim($str[1]); - break; + /* Check if the current mirror is available + */ + if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){ + if(count($this->FAIclass)){ + msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG); + } + $this->FAIdebianMirror = "auto"; + $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]); + $this->cache['CLASSES'] = array(); + $this->update_fai_cache(); + } - case 'FAIdebianMirror': - $this->InheritedFAIdebianMirror = $attrs[$name][0]; - break; + /* Check if the current mirror is available + */ + if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){ + $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]); + if(count($this->FAIclass)){ + msg_dialog::display(_("Error"), sprintf(_("FAI release '%s' is not available on mirror '%s' - setting to release '%s'!"), $this->FAIrelease, $this->FAIdebianMirror,$new_release), ERROR_DIALOG); + } + $this->FAIrelease = $new_release; + $this->cache['CLASSES'] = array(); + $this->update_fai_cache(); + } } - } + + + // Prepare lists + $this->ldapList = new sortableListing(array(),array(), TRUE); + $this->ldapList->setDeleteable(true); + $this->ldapList->setEditable(false); + $this->ldapList->setWidth("100%"); + $this->ldapList->setHeight("100px"); + $this->ldapList->setHeader(array(_("LDAP server"))); + $this->ldapList->setDefaultSortColumn(0); + + $this->faiList = new sortableListing(array(),array(), TRUE); + $this->faiList->setDeleteable(true); + $this->faiList->setEditable(false); + $this->faiList->setWidth("100%"); + $this->faiList->setHeight("160px"); + $this->faiList->setColspecs(array('50%','50%')); + $this->faiList->setHeader(array(_("Name"),_("Classes"))); + $this->faiList->setDefaultSortColumn(0); + } - $this->update_fai_cache(); - if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){ + function check() + { + $messages = array(); - /* Check if the current mirror is available - */ - if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){ - if(count($this->FAIclass)){ - msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG); - } - $this->FAIdebianMirror = "auto"; - $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]); - $this->cache['CLASSES'] = array(); - $this->update_fai_cache(); - } - - /* Check if the current mirror is available - */ - if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){ - $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]); - if(count($this->FAIclass)){ - msg_dialog::display(_("Error"), sprintf(_("FAI release '%s' is not available on mirror '%s' - setting to release '%s'!"), $this->FAIrelease, $this->FAIdebianMirror,$new_release), ERROR_DIALOG); + /* Call common method to give check the hook */ + $messages= plugin::check(); + + /* If there are packages selected, but no mirror show error */ + if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){ + $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'."); } - $this->FAIrelease = $new_release; - $this->cache['CLASSES'] = array(); - $this->update_fai_cache(); - } + + return($messages); } + function execute() + { + /* Call parent execute */ + plugin::execute(); - // Prepare lists - $this->ldapList = new sortableListing(array(),array(), TRUE); - $this->ldapList->setDeleteable(true); - $this->ldapList->setEditable(false); - $this->ldapList->setWidth("100%"); - $this->ldapList->setHeight("100px"); - $this->ldapList->setHeader(array(_("LDAP server"))); - $this->ldapList->setDefaultSortColumn(0); - - $this->faiList = new sortableListing(array(),array(), TRUE); - $this->faiList->setDeleteable(true); - $this->faiList->setEditable(false); - $this->faiList->setWidth("100%"); - $this->faiList->setHeight("160px"); - $this->faiList->setColspecs(array('50%','50%')); - $this->faiList->setHeader(array(_("Name"),_("Classes"))); - $this->faiList->setDefaultSortColumn(0); - - } - - - function check() - { - $messages = array(); - - /* Call common method to give check the hook */ - $messages= plugin::check(); - - /* If there are packages selected, but no mirror show error */ - if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){ - $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'."); - } + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","workstation/".get_class($this),$this->dn); + } - return($messages); - } + /* Do we represent a valid terminal? */ + if (!$this->is_account && $this->parent === NULL){ + $display= image("images/small-error.png")."".msgPool::noValidExtension(_("workstation")).""; + return ($display); + } - function execute() - { - /* Call parent execute */ - plugin::execute(); + /* Add module */ + if (isset ($_POST['add_module'])){ + if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){ + $this->add_list ($this->gotoModules, $_POST['module']); + } + } - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","workstation/".get_class($this),$this->dn); - } + /* Delete module */ + if (isset ($_POST['delete_module'])){ + if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){ + $this->del_list ($this->gotoModules, $_POST['modules_list']); + } + } - /* Do we represent a valid terminal? */ - if (!$this->is_account && $this->parent === NULL){ - $display= image("images/small-error.png")."".msgPool::noValidExtension(_("workstation")).""; - return ($display); - } + /* FAI class management */ + if($this->fai_activated){ + if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){ + $found = 0 ; + + /* If this new class/profile will attach a second partition table + * to our list of classes, abort and show a message. + */ + foreach($this->FAIclass as $name){ + if(isset($this->FAIclassInfo[$name])){ + foreach($this->FAIclassInfo[$name] as $atr){ + if(isset($atr['obj'])){ + if($atr['obj'] == "FAIpartitionTable"){ + $found ++ ; + } + } + } + } + } - /* Add module */ - if (isset ($_POST['add_module'])){ - if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){ - $this->add_list ($this->gotoModules, $_POST['module']); - } - } + if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){ + msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG); + }else{ + $this->FAIclass[$_POST['FAIclassesSel']]=get_post('FAIclassesSel'); + } + } + + + $this->faiList->save_object(); + $action = $this->faiList->getAction(); + if($action['action'] == 'delete'){ + $id = $this->faiList->getKey($action['targets'][0]); + unset($this->FAIclass[$id]); + } + if($action['action'] == 'reorder'){ + $this->FAIclass= $this->faiList->getMaintainedData(); + } + + /* Move one used class class one position up or down */ + if($this->acl_is_writeable("FAIclass")){ + foreach($_POST as $name => $val){ - /* Delete module */ - if (isset ($_POST['delete_module'])){ - if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){ - $this->del_list ($this->gotoModules, $_POST['modules_list']); - } - } - /* FAI class management */ - if($this->fai_activated){ - if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){ - $found = 0 ; + if(preg_match("/fai_remove/i",$name)){ + $value = postDecode(preg_replace("/fai_remove_/i","",$name)); + unset($this->FAIclass[$value]); + } + } + } - /* If this new class/profile will attach a second partition table - * to our list of classes, abort and show a message. + /* Delete selected class from our list */ + if($this->acl_is_writeable("FAIclass")){ + if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){ + if(isset($this->FAIclass[$_POST['FAIclassSel']])){ + unset($this->FAIclass[$_POST['FAIclassSel']]); + } + } + } + }// END fai handling + + /* Show main page */ + $smarty= get_smarty(); + + /* Assign ACLs to smarty */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + + $smarty->assign("member_of_ogroup",$this->member_of_ogroup); + + /* In this section server shares will be defined + * A user can select one of the given shares and a mount point + * and attach this combination to his setup. */ - foreach($this->FAIclass as $name){ - if(isset($this->FAIclassInfo[$name])){ - foreach($this->FAIclassInfo[$name] as $atr){ - if(isset($atr['obj'])){ - if($atr['obj'] == "FAIpartitionTable"){ - $found ++ ; + $smarty->assign("gotoShareSelections", set_post($this->gotoShareSelections)); + $smarty->assign("gotoShareSelectionKeys", set_post(array_flip($this->gotoShareSelections))); + + /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry + * This entry will be, a combination of mountPoint and sharedefinitions + */ + if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) { + /* We assign a share to this user, if we don't know where to mount the share */ + if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){ + msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG); + }else{ + + if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){ + $a_share = $this->gotoAvailableShares[get_post('gotoShareSelection')]; + $s_mount = get_post('gotoShareMountPoint'); + /* Preparing the new assignment */ + $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share; + $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount; } - } } - } } - if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){ - msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG); - }else{ - $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel']; + /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected) + * If there is no defined share selected, we will abort the deletion without any message + */ + if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){ + unset($this->gotoShares[$_POST['gotoShare']]); } - } - - $this->faiList->save_object(); - $action = $this->faiList->getAction(); - if($action['action'] == 'delete'){ - $id = $this->faiList->getKey($action['targets'][0]); - unset($this->FAIclass[$id]); + $smarty->assign("gotoShares", set_post($this->printOutAssignedShares())); + $smarty->assign("gotoSharesCount", count($this->printOutAssignedShares())); + $smarty->assign("gotoShareKeys", set_post(array_flip($this->printOutAssignedShares()))); + $smarty->assign("gotoBootKernels", set_post($this->gotoBootKernels)); + + $this->ldapList->setAcl($this->getacl('gotoLdapServer')); + + /* Add new ldap server to the list */ + if($this->acl_is_writeable("gotoLdapServer") && + !$this->gotoLdap_inherit && + isset($_POST['add_ldap_server']) && + isset($_POST['ldap_server_to_add'])){ + if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){ + $to_add = $this->gotoLdapServerList[get_post('ldap_server_to_add')]; + if(!in_array($to_add,$this->gotoLdapServers)){ + $this->gotoLdapServers[] = $to_add; + } + } } + + /* Move ldap servers up and down */ + $this->ldapList->save_object(); + $action = $this->ldapList->getAction(); if($action['action'] == 'reorder'){ - $this->FAIclass= $this->faiList->getMaintainedData(); + $this->gotoLdapServers = array_values($this->ldapList->getMaintainedData()); + } + if($action['action'] == 'delete'){ + $id = $this->ldapList->getKey($action['targets'][0]); + $value = $this->gotoLdapServers[$id]; + $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers); } - /* Move one used class class one position up or down */ - if($this->acl_is_writeable("FAIclass")){ - foreach($_POST as $name => $val){ + /* Add Entries */ + $data = $lData = array(); + foreach($this->gotoLdapServers as $key => $server){ + $data[$key]=$server; + /* Announce missing entries */ + if(!in_array($server,$this->gotoLdapServerList)){ + $server = $server." (missing)"; + } - if(preg_match("/fai_remove/i",$name)){ - $value = postDecode(preg_replace("/fai_remove_/i","",$name)); - unset($this->FAIclass[$value]); - } - } - } - - /* Delete selected class from our list */ - if($this->acl_is_writeable("FAIclass")){ - if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){ - if(isset($this->FAIclass[$_POST['FAIclassSel']])){ - unset($this->FAIclass[$_POST['FAIclassSel']]); - } + /* Convert old style entry */ + if (!preg_match('%:ldaps?://%', $server)){ + $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server); + } else { + $server= preg_replace("/^[^:]+:/", "", $server); + $lData[$key] = array('data'=>array($server)); + } } - } - }// END fai handling + $this->ldapList->setListData($data,$lData); + $this->ldapList->update(); - /* Show main page */ - $smarty= get_smarty(); - /* Assign ACLs to smarty */ - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL",$this->getacl($name)); - } + if($this->gotoLdap_inherit){ + $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));; + }else{ + $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer")); + } + + $list = array(); + foreach($this->gotoLdapServerList as $key => $entry){ + if(!in_array($entry,$this->gotoLdapServers)){ - $smarty->assign("member_of_ogroup",$this->member_of_ogroup); + /* Convert old style entry */ + if (!preg_match('%:ldap[s]*://%', $entry)){ + $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry); - /* In this section server shares will be defined - * A user can select one of the given shares and a mount point - * and attach this combination to his setup. - */ - $smarty->assign("gotoShareSelections", $this->gotoShareSelections); - $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections)); + /* Beautify new style entries */ + } else { + $entry= preg_replace("/^[^:]+:/", "", $entry); + } - /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry - * This entry will be, a combination of mountPoint and sharedefinitions - */ - if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) { - /* We assign a share to this user, if we don't know where to mount the share */ - if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){ - msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG); - }else{ - - if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){ - $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']]; - $s_mount = $_POST['gotoShareMountPoint']; - /* Preparing the new assignment */ - $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share; - $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount; + $list[$key] = $entry; + } } - } - } + $smarty->assign("gotoLdapServers", $this->ldapList->render()); + $smarty->assign("gotoLdapServerList", $list); + $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit); - /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected) - * If there is no defined share selected, we will abort the deletion without any message - */ - if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){ - unset($this->gotoShares[$_POST['gotoShare']]); - } + foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){ + $smarty->assign("$val", set_post($this->$val)); + } - $smarty->assign("gotoShares",$this->printOutAssignedShares()); - $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares())); - $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares())); - $smarty->assign("gotoBootKernels",$this->gotoBootKernels); - - $this->ldapList->setAcl($this->getacl('gotoLdapServer')); - - /* Add new ldap server to the list */ - if($this->acl_is_writeable("gotoLdapServer") && - !$this->gotoLdap_inherit && - isset($_POST['add_ldap_server']) && - isset($_POST['ldap_server_to_add'])){ - if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){ - $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']]; - if(!in_array($to_add,$this->gotoLdapServers)){ - $this->gotoLdapServers[] = $to_add; + /* Values */ + foreach(array("gotoBootKernel","gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){ + $smarty->assign($val, set_post($this->$val)); } - } - } - - /* Move ldap servers up and down */ - $this->ldapList->save_object(); - $action = $this->ldapList->getAction(); - if($action['action'] == 'reorder'){ - $this->gotoLdapServers = array_values($this->ldapList->getMaintainedData()); - } - if($action['action'] == 'delete'){ - $id = $this->ldapList->getKey($action['targets'][0]); - $value = $this->gotoLdapServers[$id]; - $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers); - } - /* Add Entries */ - $data = $lData = array(); - foreach($this->gotoLdapServers as $key => $server){ - $data[$key]=$server; + $smarty->assign("fai_activated",$this->fai_activated); - /* Announce missing entries */ - if(!in_array($server,$this->gotoLdapServerList)){ - $server = $server." (missing)"; - } + /* Create FAI output */ + $this->update_fai_cache(); + $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed); + $smarty->assign("si_active",$this->si_active); + + if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){ + + $smarty->assign("FAIservers" , set_post($this->cache['SERVERS'])); + $smarty->assign("FAIdebianMirror", set_post($this->FAIdebianMirror)); + $smarty->assign("FAIrelease" , set_post($this->FAIrelease)); + $smarty->assign("FAIclasses" , set_post($this->selectable_classes())); + + /* Get classes for release from cache. + * Or build cache + */ + if($this->FAIdebianMirror == "inherited"){ + $release = $this->InheritedFAIrelease; + }else{ + $release = $this->FAIrelease; + } - /* Convert old style entry */ - if (!preg_match('%:ldaps?://%', $server)){ - $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server); - } else { - $server= preg_replace("/^[^:]+:/", "", $server); - $lData[$key] = array('data'=>array($server)); - } + $smarty->assign("gotoBootKernels", set_post($this->cache['KERNELS'][$release])); + $smarty->assign("InheritedFAIrelease", set_post($this->InheritedFAIrelease)); + + /* Get classes */ + if($this->FAIdebianMirror == "inherited"){ + $tmp = $this->InheritedFAIclass; + }else{ + $tmp = $this->FAIclass; + } + + /* Get invalid classes */ + $invalid = $this->get_invalid_classes($tmp); + $data = $lData = array(); + + /* Draw every single entry */ + $i = 1; + if($this->acl_is_readable("FAIclass")){ + foreach($tmp as $class){ + + /* Mark invalid classes. (Not in selected release) + */ + $marker = ""; + if(in_array_ics($class,$invalid)){ + $marker = " ("._("Not available in current setup").")"; + } + + $i ++ ; + + /* Get Description tag + * There may be several FAI objects with the same class name, + * use the description from FAIprofile, if possible. + */ + $desc = ""; + + $objects = array( + "Pl" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png"), + "Pt" => array("IMG"=> "plugins/fai/images/fai_packages.png"), + "S" => array("IMG"=> "plugins/fai/images/fai_script.png"), + "V" => array("IMG"=> "plugins/fai/images/fai_variable.png"), + "H" => array("IMG"=> "plugins/fai/images/fai_hook.png"), + "P" => array("IMG"=> "plugins/fai/images/fai_profile.png"), + "T" => array("IMG"=> "plugins/fai/images/fai_template.png")); + + if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){ + $desc =""; + foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){ + if(isset($types['Abbr'])){ + $desc.= image($objects[$types['Abbr']]['IMG']); + if($types['Type'] == "FAIprofile"){ + break; + } + } + } + } + if(!empty($desc)){ + $desc = " ".trim($desc).""; + } + + $data[$class] = $class; + $lData[$class] = array('data' => array($class,$desc)); + } + }// END FAI output generation + }// END FAI output generation + + $this->faiList->setAcl('rwcdm'); + $this->faiList->setReorderable($this->FAIdebianMirror != "inherited"); + $this->faiList->setListData($data,$lData); + $this->faiList->update(); + + $smarty->assign("FAIScriptlist", $this->faiList->render()); + + /* Show main page */ + $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters); + return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__)))); } - $this->ldapList->setListData($data,$lData); - $this->ldapList->update(); - if($this->gotoLdap_inherit){ - $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));; - }else{ - $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer")); + function remove_from_parent() + { + $this->handle_post_events("remove"); + new log("remove","workstation/".get_class($this),$this->dn); } - - $list = array(); - foreach($this->gotoLdapServerList as $key => $entry){ - if(!in_array($entry,$this->gotoLdapServers)){ - /* Convert old style entry */ - if (!preg_match('%:ldap[s]*://%', $entry)){ - $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry); - /* Beautify new style entries */ - } else { - $entry= preg_replace("/^[^:]+:/", "", $entry); + /* Save data to object */ + function save_object() + { + $old_mirror = $this->FAIdebianMirror; + plugin::save_object(); + + /* Update release */ + if($old_mirror != $this->FAIdebianMirror){ + if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){ + $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]); + } } - $list[$key] = $entry; - } + if(isset($_POST['WorkstationStarttabPosted'])){ + if(isset($_POST['gotoLdap_inherit'])){ + $this->gotoLdap_inherit = TRUE; + }else{ + $this->gotoLdap_inherit = FALSE; + } + } } - $smarty->assign("gotoLdapServers", $this->ldapList->render()); - $smarty->assign("gotoLdapServerList", $list); - $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit); - $smarty->assign("JS", session::get('js')); - foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){ - $smarty->assign("$val", $this->$val); - } - /* Values */ - foreach(array("gotoBootKernel","gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){ - $smarty->assign($val, $this->$val); - } + /* Save to LDAP */ + function save() + { + + /* Depending on the baseobject (Ogroup / WS) we + * use another set of objectClasses + * In case of WS itself, we use "array("GOhard", "FAIobject");" + * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject")) + */ + if(isset($this->parent->by_object['ogroup'])){ + $this->objectclasses = array("gotoWorkstationTemplate"); + }elseif(isset($this->parent->by_object['workgeneric'])){ + $this->objectclasses = array("GOhard"); + }elseif(isset($this->parent->by_object['servgeneric'])){ + $this->objectclasses = array("GOhard","gotoWorkstationTemplate"); + }else{ + msg_dialog::display(_("Fatal error"), + "Object Type Configuration is unknown. Please contact the GOsa developers.", + FATAL_ERROR_DIALOG); + exit(); + } + + /* Append FAI class */ + if($this->fai_activated){ + $this->objectclasses[] = "FAIobject"; + } + + /* Find proper terminal path for tftp configuration +FIXME: This is suboptimal when the default has changed to +another location! */ + if (($this->gotoTerminalPath == "default")){ + $ldap= $this->config->get_ldap_link(); + + /* Strip relevant part from dn, keep trailing ',' */ + $tmp= preg_replace("/^cn=[^,]+,".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i", "", $this->dn); + $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp); + + /* Walk from top to base and try to load default values for + 'gotoTerminalPath'. Abort when an entry is found. */ + while (TRUE){ + $tmp= preg_replace ("/^[^,]+,/", "", $tmp); + + $ldap->cat("cn=default,".get_ou("termgeneric", "terminalRDN").$tmp. + $this->config->current['BASE'], array('gotoTerminalPath')); + $attrs= $ldap->fetch(); + if (isset($attrs['gotoTerminalPath'])){ + $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0]; + break; + } - $smarty->assign("fai_activated",$this->fai_activated); - - /* Create FAI output */ - $this->update_fai_cache(); - $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed); - $smarty->assign("si_active",$this->si_active); - - if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){ - - $smarty->assign("FAIservers" , $this->cache['SERVERS']); - $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror); - $smarty->assign("FAIrelease" , $this->FAIrelease); - $smarty->assign("FAIclasses" , $this->selectable_classes()); - - /* Get classes for release from cache. - * Or build cache - */ - if($this->FAIdebianMirror == "inherited"){ - $release = $this->InheritedFAIrelease; - }else{ - $release = $this->FAIrelease; - } - - $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]); - $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease); - - /* Get classes */ - if($this->FAIdebianMirror == "inherited"){ - $tmp = $this->InheritedFAIclass; - }else{ - $tmp = $this->FAIclass; - } - - /* Get invalid classes */ - $invalid = $this->get_invalid_classes($tmp); - $data = $lData = array(); - - /* Draw every single entry */ - $i = 1; - if($this->acl_is_readable("FAIclass")){ - foreach($tmp as $class){ - - /* Mark invalid classes. (Not in selected release) - */ - $marker = ""; - if(in_array_ics($class,$invalid)){ - $marker = " ("._("Not available in current setup").")"; - } - - $i ++ ; - - /* Get Description tag - * There may be several FAI objects with the same class name, - * use the description from FAIprofile, if possible. - */ - $desc = ""; - - $objects = array( - "Pl" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png"), - "Pt" => array("IMG"=> "plugins/fai/images/fai_packages.png"), - "S" => array("IMG"=> "plugins/fai/images/fai_script.png"), - "V" => array("IMG"=> "plugins/fai/images/fai_variable.png"), - "H" => array("IMG"=> "plugins/fai/images/fai_hook.png"), - "P" => array("IMG"=> "plugins/fai/images/fai_profile.png"), - "T" => array("IMG"=> "plugins/fai/images/fai_template.png")); - - if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){ - $desc =""; - foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){ - if(isset($types['Abbr'])){ - $desc.= image($objects[$types['Abbr']]['IMG']); - if($types['Type'] == "FAIprofile"){ - break; + /* Nothing left? */ + if ($tmp == ""){ + break; } - } } - } - if(!empty($desc)){ - $desc = " ".trim($desc).""; - } - - $data[$class] = $class; - $lData[$class] = array('data' => array($class,$desc)); - } - }// END FAI output generation - }// END FAI output generation - - $this->faiList->setAcl('rwcdm'); - $this->faiList->setReorderable($this->FAIdebianMirror != "inherited"); - $this->faiList->setListData($data,$lData); - $this->faiList->update(); - - $smarty->assign("FAIScriptlist", $this->faiList->render()); - - /* Show main page */ - $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters); - return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__)))); - } - - - function remove_from_parent() - { - $this->handle_post_events("remove"); - new log("remove","workstation/".get_class($this),$this->dn); - } - - - /* Save data to object */ - function save_object() - { - $old_mirror = $this->FAIdebianMirror; - plugin::save_object(); - - /* Update release */ - if($old_mirror != $this->FAIdebianMirror){ - if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){ - $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]); - } - } + } - if(isset($_POST['WorkstationStarttabPosted'])){ - if(isset($_POST['gotoLdap_inherit'])){ - $this->gotoLdap_inherit = TRUE; - }else{ - $this->gotoLdap_inherit = FALSE; - } - } - } + plugin::save(); + unset( $this->attrs['FAIrelease'] ); + $str = ""; - /* Save to LDAP */ - function save() - { + /* Skip FAI attribute handling if not necessary */ + if($this->fai_activated && !$this->si_fai_action_failed){ + if($this->FAIdebianMirror == "inherited"){ + $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array(); + }else{ + foreach($this->FAIclass as $class){ + $str .= $class." "; + } + $str = trim($str); + if(empty($this->attrs['FAIclass'])){ + $this->attrs['FAIclass'] = array(); + }else{ + $this->attrs['FAIclass']= $str." :".$this->FAIrelease; + } + } + } - /* Depending on the baseobject (Ogroup / WS) we - * use another set of objectClasses - * In case of WS itself, we use "array("GOhard", "FAIobject");" - * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject")) - */ - if(isset($this->parent->by_object['ogroup'])){ - $this->objectclasses = array("gotoWorkstationTemplate"); - }elseif(isset($this->parent->by_object['workgeneric'])){ - $this->objectclasses = array("GOhard"); - }elseif(isset($this->parent->by_object['servgeneric'])){ - $this->objectclasses = array("GOhard","gotoWorkstationTemplate"); - }else{ - msg_dialog::display(_("Fatal error"), - "Object Type Configuration is unknown. Please contact the GOsa developers.", - FATAL_ERROR_DIALOG); - exit(); - } + /* Add missing arrays */ + foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){ + if (isset ($this->$val) && count ($this->$val) != 0){ - /* Append FAI class */ - if($this->fai_activated){ - $this->objectclasses[] = "FAIobject"; - } + $this->attrs["$val"]= array_unique($this->$val); + } + if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array(); + } - /* Find proper terminal path for tftp configuration - FIXME: This is suboptimal when the default has changed to - another location! */ - if (($this->gotoTerminalPath == "default")){ - $ldap= $this->config->get_ldap_link(); - - /* Strip relevant part from dn, keep trailing ',' */ - $tmp= preg_replace("/^cn=[^,]+,".preg_quote(get_ou("termgeneric", "terminalRDN"), '/')."/i", "", $this->dn); - $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp); - - /* Walk from top to base and try to load default values for - 'gotoTerminalPath'. Abort when an entry is found. */ - while (TRUE){ - $tmp= preg_replace ("/^[^,]+,/", "", $tmp); - - $ldap->cat("cn=default,".get_ou("termgeneric", "terminalRDN").$tmp. - $this->config->current['BASE'], array('gotoTerminalPath')); - $attrs= $ldap->fetch(); - if (isset($attrs['gotoTerminalPath'])){ - $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0]; - break; + /* Prepare list of ldap servers */ + $this->attrs['gotoLdapServer'] = array(); + if(!$this->gotoLdap_inherit){ + $i = 0; + foreach($this->gotoLdapServers as $server){ + $i ++; + $this->attrs['gotoLdapServer'][] = $i.":".$server; + } } - /* Nothing left? */ - if ($tmp == ""){ - break; + if ($this->attrs['gotoBootKernel'] == "default-inherited"){ + $this->attrs['gotoBootKernel']= array(); } - } - } - plugin::save(); + /* if mirror == none stop saving this attribute */ + if($this->FAIdebianMirror == "none"){ + $this->FAIdebianMirror = ""; + } - unset( $this->attrs['FAIrelease'] ); - $str = ""; + /* Get FAIstate from object, the generic tab could have changed it during execute */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->dn); - /* Skip FAI attribute handling if not necessary */ - if($this->fai_activated && !$this->si_fai_action_failed){ - if($this->FAIdebianMirror == "inherited"){ - $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array(); - }else{ - foreach($this->FAIclass as $class){ - $str .= $class." "; - } - $str = trim($str); - if(empty($this->attrs['FAIclass'])){ - $this->attrs['FAIclass'] = array(); + + /* Skip FAI attribute handling if not necessary */ + if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){ + $ldap->cat($this->dn,array("FAIstate")); + $checkFAIstate = $ldap->fetch(); + + /* Remove FAI objects if no FAI class is selected */ + if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){ + $this->attrs['FAIclass'] = array(); + $this->attrs['FAIdebianMirror'] = array(); + } }else{ - $this->attrs['FAIclass']= $str." :".$this->FAIrelease; + + /* Don't touch FAI objects if something went wrong with the si daemon. + */ + if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']); + if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']); } - } - } - /* Add missing arrays */ - foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){ - if (isset ($this->$val) && count ($this->$val) != 0){ - - $this->attrs["$val"]= array_unique($this->$val); - } - if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array(); + /* prepare share settings */ + $tmp = array(); + foreach($this->gotoShares as $name => $settings){ + $tmp2= explode("|",$name); + $name = $tmp2[0]; + $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint']; + } + $this->attrs['gotoShare']=$tmp; + $this->cleanup(); + $ldap->modify ($this->attrs); + new log("modify","workstation/".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())); + } + $this->handle_post_events("modify"); + + /* Check if LDAP server has changed */ + if ($this->si_active && (isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent") || $this->gotoLdap_inherit)){ + $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); + $o_queue = new gosaSupportDaemon(); + if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){ + $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config']; + $macs = array(); + + /* Get list of macAddresses + */ + if(isset($this->parent->by_object['ogroup'])){ + + /* If we are an object group, add all member macs + */ + $p = $this->parent->by_object['ogroup']; + foreach($p->memberList as $dn => $obj){ + if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){ + $macs[] = $p->objcache[$dn]['macAddress']; + } + } + }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){ + + /* We are a workstation. Add current mac. + */ + $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; + if(!empty($mac)){ + $macs[] = $mac; + } + }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){ + + /* We are a server. Add current mac. + */ + $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress; + if(!empty($mac)){ + $macs[] = $mac; + } + } + + /* Trigger event for all member objects + */ + foreach($macs as $mac){ + $tmp = new $evt['CLASS_NAME']($this->config); + $tmp->set_type(TRIGGERED_EVENT); + $tmp->add_targets(array($mac)); + if(!$o_queue->append($tmp)){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + } + } + } + } } - /* Prepare list of ldap servers */ - $this->attrs['gotoLdapServer'] = array(); - if(!$this->gotoLdap_inherit){ - $i = 0; - foreach($this->gotoLdapServers as $server){ - $i ++; - $this->attrs['gotoLdapServer'][] = $i.":".$server; - } + + /* Add value to array, check if unique */ + function add_list (&$array, $value) + { + if ($value != ""){ + $array[]= $value; + sort($array); + array_unique ($array); + } } - if ($this->attrs['gotoBootKernel'] == "default-inherited"){ - $this->attrs['gotoBootKernel']= array(); + + /* Delete value to array, check if unique */ + function del_list (&$array, $list) + { + $tmp= array(); + foreach ($array as $mod){ + if (!in_array($mod, $list)){ + $tmp[]= $mod; + } + } + $array= $tmp; } - /* if mirror == none stop saving this attribute */ - if($this->FAIdebianMirror == "none"){ - $this->FAIdebianMirror = ""; + /* Generate ListBox frindly output for the defined shares + * Possibly Add or remove an attribute here, + */ + function printOutAssignedShares() + { + $a_return = array(); + if(is_array($this->gotoShares)){ + foreach($this->gotoShares as $share){ + $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]"; + } + } + return($a_return); } - - /* Get FAIstate from object, the generic tab could have changed it during execute */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - - - /* Skip FAI attribute handling if not necessary */ - if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){ - $ldap->cat($this->dn,array("FAIstate")); - $checkFAIstate = $ldap->fetch(); - - /* Remove FAI objects if no FAI class is selected */ - if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){ - $this->attrs['FAIclass'] = array(); - $this->attrs['FAIdebianMirror'] = array(); - } - }else{ - - /* Don't touch FAI objects if something went wrong with the si daemon. - */ - if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']); - if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']); + + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + $source_o = new workstartup ($this->config, $source['dn']); + foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem", + "gotoKernelParameters","gotoShares","gotoLdapServers","gotoLdapServerList", + "gotoLdap_inherit") as $attr){ + $this->$attr = $source_o->$attr; + } } - /* prepare share settings */ - $tmp = array(); - foreach($this->gotoShares as $name => $settings){ - $tmp2= explode("|",$name); - $name = $tmp2[0]; - $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint']; + + function array_switch_item($ar,$from,$to) + { + if(!is_array($ar)){ + return(false); + } + if(!isset($ar[$from])){ + return(false); + } + if(!isset($ar[$to])){ + return(false); + } + + $tmp = $ar[$from]; + $ar[$from] = $ar[$to]; + $ar[$to] = $tmp; + return($ar); } - $this->attrs['gotoShare']=$tmp; - $this->cleanup(); - $ldap->modify ($this->attrs); - new log("modify","workstation/".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())); + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Startup"), + "plDescription" => _("System startup"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 9, + "plSection" => array("administration"), + "plCategory" => array("workstation","server","ogroups"), + + "plProvidedAcls"=> array( + "gotoLdapServer" => _("Ldap server"), + "gotoBootKernel" => _("Boot kernel"), + "gotoKernelParameters" => _("Kernel parameter"), + + "gotoModules" => _("Kernel modules"), + "gotoShare" => _("Shares"), + + "FAIclass" => _("FAI classes"), + "FAIdebianMirror" => _("Debian mirror"), + "FAIrelease" => _("Debian release"), + + "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ? + )); } - $this->handle_post_events("modify"); - - /* Check if LDAP server has changed */ - if ($this->si_active && (isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent") || $this->gotoLdap_inherit)){ - $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT); - $o_queue = new gosaSupportDaemon(); - if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){ - $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config']; - $macs = array(); - - /* Get list of macAddresses + + + /* Updates release dns + * and reads all classes for the current release, + * if not already done ($this->cache). + */ + function update_fai_cache($first_call = FALSE) + { + $force = FALSE; + if(!$this->si_active) return; + $start = microtime(TRUE); + + if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return; + + $this->si_fai_action_failed = FALSE; + + /* Get the list of available servers and their releases. */ - if(isset($this->parent->by_object['ogroup'])){ - - /* If we are an object group, add all member macs - */ - $p = $this->parent->by_object['ogroup']; - foreach($p->memberList as $dn => $obj){ - if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){ - $macs[] = $p->objcache[$dn]['macAddress']; + if($force || !isset($this->cache['SERVERS'])){ + + $o_queue = new gosaSupportDaemon(); + $tmp = $o_queue->FAI_get_server(); + if($o_queue->is_error()){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + $this->si_fai_action_failed = TRUE; + $this->cache = array(); + return; + }else{ + + foreach($tmp as $entry){ + $rel = $entry['FAI_RELEASE']; + $this->cache['SERVERS']['auto'][$rel] = $rel; + $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel; + uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp'); + uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp'); + } } - } - }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){ - - /* We are a workstation. Add current mac. - */ - $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress; - if(!empty($mac)){ - $macs[] = $mac; - } - }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){ - - /* We are a server. Add current mac. - */ - $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress; - if(!empty($mac)){ - $macs[] = $mac; - } } - /* Trigger event for all member objects + /* Ensure that our selection is valid, else we get several PHP warnings + if there is no FAI configuration at all. */ - foreach($macs as $mac){ - $tmp = new $evt['CLASS_NAME']($this->config); - $tmp->set_type(TRIGGERED_EVENT); - $tmp->add_targets(array($mac)); - if(!$o_queue->append($tmp)){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - } + if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){ + $this->cache['SERVERS'][$this->FAIdebianMirror][''] =''; } - } - } - } - - /* Add value to array, check if unique */ - function add_list (&$array, $value) - { - if ($value != ""){ - $array[]= $value; - sort($array); - array_unique ($array); - } - } + /* Build up arrays, without checks */ + if(!$first_call){ + /* Check if the selected mirror is available */ + if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){ + $this->FAIdebianMirror = "auto"; + $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]); + trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available"); + } - /* Delete value to array, check if unique */ - function del_list (&$array, $list) - { - $tmp= array(); - foreach ($array as $mod){ - if (!in_array($mod, $list)){ - $tmp[]= $mod; - } - } - $array= $tmp; - } - - /* Generate ListBox frindly output for the defined shares - * Possibly Add or remove an attribute here, - */ - function printOutAssignedShares() - { - $a_return = array(); - if(is_array($this->gotoShares)){ - foreach($this->gotoShares as $share){ - $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]"; - } - } - return($a_return); - } + /* Check if the selected release is available */ + if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){ + if($this->FAIrelease != ""){ + trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available"); + } + $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]); + } + } + /* Get classes for release from cache. + * Or build cache + */ + if($this->FAIdebianMirror == "inherited"){ + $release = $this->InheritedFAIrelease; + }else{ + $release = $this->FAIrelease; + } - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - $source_o = new workstartup ($this->config, $source['dn']); - foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem", - "gotoKernelParameters","gotoShares","gotoLdapServers","gotoLdapServerList", - "gotoLdap_inherit") as $attr){ - $this->$attr = $source_o->$attr; - } - } + if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){ + + /* Get the list of available servers and their releases. + */ + $o_queue = new gosaSupportDaemon(); + $tmp = $o_queue->FAI_get_classes($release); + + $this->cache['CLASSES'][$release] = array(); + if($o_queue->is_error()){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + $this->si_fai_action_failed = TRUE; + $this->cache=array(); + return; + }else{ + foreach($tmp as $entry){ + $class = $entry['CLASS']; + $this->cache['CLASSES'][$release][$class][] = $this->analyse_fai_object($entry); + } + } - - function array_switch_item($ar,$from,$to) - { - if(!is_array($ar)){ - return(false); - } - if(!isset($ar[$from])){ - return(false); - } - if(!isset($ar[$to])){ - return(false); - } + /* Add object caught from external hook + */ + $lines= $this->GetHookElements(); + foreach ($lines as $hline){ + $entries= explode(";", $hline); + $server = $entries['0']; + $url = $entries['1']; + if (!empty($url)){ + + /* Split releases */ + if (isset($entries[2])){ + $releases= explode(",", $entries[2]); + + foreach ($releases as $release_data){ + $release_c = preg_replace('/:.*$/', '', $release_data); + $sections_c = explode(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data)); + $classes_c = explode('|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data)); + + if($release_c == $release){ + $this->cache['SERVERS'][$url][$release_c]=$release_c; + $this->cache['SERVERS']['auto'][$release_c]=$release_c; + foreach ($classes_c as $class){ + if ($class != ""){ + $this->cache['CLASSES'][$release_c][$class]= array(); + } + } + } + } + } + } + } + uksort($this->cache['SERVERS'], 'strnatcasecmp'); - $tmp = $ar[$from]; - $ar[$from] = $ar[$to]; - $ar[$to] = $tmp; - return($ar); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Startup"), - "plDescription" => _("System startup"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 9, - "plSection" => array("administration"), - "plCategory" => array("workstation","server","ogroups"), - - "plProvidedAcls"=> array( - "gotoLdapServer" => _("Ldap server"), - "gotoBootKernel" => _("Boot kernel"), - "gotoKernelParameters" => _("Kernel parameter"), - - "gotoModules" => _("Kernel modules"), - "gotoShare" => _("Shares"), - - "FAIclass" => _("FAI classes"), - "FAIdebianMirror" => _("Debian mirror"), - "FAIrelease" => _("Debian release"), - - "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ? - )); - } - - - /* Updates release dns - * and reads all classes for the current release, - * if not already done ($this->cache). - */ - function update_fai_cache($first_call = FALSE) - { - $force = FALSE; - if(!$this->si_active) return; - $start = microtime(TRUE); - - if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return; - - $this->si_fai_action_failed = FALSE; - - /* Get the list of available servers and their releases. - */ - if($force || !isset($this->cache['SERVERS'])){ - - $o_queue = new gosaSupportDaemon(); - $tmp = $o_queue->FAI_get_server(); - if($o_queue->is_error()){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - $this->si_fai_action_failed = TRUE; - $this->cache = array(); - return; - }else{ - - foreach($tmp as $entry){ - $rel = $entry['FAI_RELEASE']; - $this->cache['SERVERS']['auto'][$rel] = $rel; - $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel; - uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp'); - uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp'); + /* Only add inherit option, if we are part in an object group + */ + if($this->member_of_ogroup){ + $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']); + } } - } - } - /* Ensure that our selection is valid, else we get several PHP warnings - if there is no FAI configuration at all. - */ - if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){ - $this->cache['SERVERS'][$this->FAIdebianMirror][''] =''; + /* Get list of available kernel for this release + */ + if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array(); + + if($force || !isset($this->cache['KERNELS'][$release])){ + $o_queue = new gosaSupportDaemon(); + $tmp = $o_queue->FAI_get_kernels($release); + $this->cache['KERNELS'][$release] = array(); + foreach($this->gotoBootKernels as $name => $default){ + $this->cache['KERNELS'][$release][$name] = $default; + } + foreach($tmp as $kernel){ + if(empty($kernel)) continue; + $this->cache['KERNELS'][$release][$kernel]=$kernel; + } + ksort($this->cache['KERNELS'][$release]); + } } - /* Build up arrays, without checks */ - if(!$first_call){ - /* Check if the selected mirror is available */ - if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){ - $this->FAIdebianMirror = "auto"; - $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]); - trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available"); - } + /* This function return an array containing all + * invalid classes for the selected server/release + */ + function get_invalid_classes($classes) + { + $this->update_fai_cache(); + if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){ + $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease]; + }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){ + $release_classes = $this->cache['CLASSES'][$this->FAIrelease]; + }else{ + $release_classes = array(); + } - /* Check if the selected release is available */ - if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){ - if($this->FAIrelease != ""){ - trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available"); + /* Detect all classes that are not valid + * for the selected release + */ + $NA = array(); + foreach($classes as $class){ + if(!isset($release_classes[$class])){ + $NA[] = $class; + } } - $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]); - } - } + return($NA); + } - /* Get classes for release from cache. - * Or build cache + + /* Get all selectable classes for the ui select box */ - if($this->FAIdebianMirror == "inherited"){ - $release = $this->InheritedFAIrelease; - }else{ - $release = $this->FAIrelease; - } + function selectable_classes() + { + $this->update_fai_cache(); - if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){ - - /* Get the list of available servers and their releases. - */ - $o_queue = new gosaSupportDaemon(); - $tmp = $o_queue->FAI_get_classes($release); - - $this->cache['CLASSES'][$release] = array(); - if($o_queue->is_error()){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - $this->si_fai_action_failed = TRUE; - $this->cache=array(); - return; - }else{ - foreach($tmp as $entry){ - $class = $entry['CLASS']; - $this->cache['CLASSES'][$release][$class][] = $this->analyse_fai_object($entry); + if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){ + $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease]; + }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){ + $classes = $this->cache['CLASSES'][$this->FAIrelease]; + }else{ + $classes = array(); } - } - - /* Add object caught from external hook - */ - $lines= $this->GetHookElements(); - foreach ($lines as $hline){ - $entries= explode(";", $hline); - $server = $entries['0']; - $url = $entries['1']; - if (!empty($url)){ - - /* Split releases */ - if (isset($entries[2])){ - $releases= explode(",", $entries[2]); - - foreach ($releases as $release_data){ - $release_c = preg_replace('/:.*$/', '', $release_data); - $sections_c = explode(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data)); - $classes_c = explode('|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data)); - - if($release_c == $release){ - $this->cache['SERVERS'][$url][$release_c]=$release_c; - $this->cache['SERVERS']['auto'][$release_c]=$release_c; - foreach ($classes_c as $class){ - if ($class != ""){ - $this->cache['CLASSES'][$release_c][$class]= array(); - } + + $Abbr =""; + $ret= array(); + foreach($classes as $class_name => $class_types){ + if(!in_array($class_name,$this->FAIclass)){ + $Abbr = ""; + foreach($class_types as $type){ + if(!preg_match("/".$type['Abbr']."/",$Abbr)){ + $Abbr .= $type['Abbr']." "; + } } - } + $ret[$class_name] = trim($Abbr); } - } } - } - uksort($this->cache['SERVERS'], 'strnatcasecmp'); - - /* Only add inherit option, if we are part in an object group - */ - if($this->member_of_ogroup){ - $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']); - } + uksort($ret, 'strnatcasecmp'); + return($ret); } - /* Get list of available kernel for this release + + /* Analyse FAI object and return an array with usefull informations like + * FAIobject type. */ - if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array(); - - if($force || !isset($this->cache['KERNELS'][$release])){ - $o_queue = new gosaSupportDaemon(); - $tmp = $o_queue->FAI_get_kernels($release); - $this->cache['KERNELS'][$release] = array(); - foreach($this->gotoBootKernels as $name => $default){ - $this->cache['KERNELS'][$release][$name] = $default; - } - foreach($tmp as $kernel){ - if(empty($kernel)) continue; - $this->cache['KERNELS'][$release][$kernel]=$kernel; - } - ksort($this->cache['KERNELS'][$release]); - } - } - - - /* This function return an array containing all - * invalid classes for the selected server/release - */ - function get_invalid_classes($classes) - { - $this->update_fai_cache(); - if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){ - $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease]; - }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){ - $release_classes = $this->cache['CLASSES'][$this->FAIrelease]; - }else{ - $release_classes = array(); + function analyse_fai_object($attr) + { + $tmp = array(); + switch($attr['TYPE']){ + + case 'FAIpackageList': + $tmp["Type"]= 'FAIpackageList'; + $tmp["Abbr"]= 'Pl'; + break; + case 'FAItemplate': + $tmp["Type"]= 'FAItemplate'; + $tmp["Abbr"]= 'T'; + break; + case 'FAIvariable': + $tmp["Type"]= 'FAIvariable'; + $tmp["Abbr"]= 'V'; + break; + case 'FAIscript': + $tmp["Type"]= 'FAIscript'; + $tmp["Abbr"]= 'S'; + break; + case 'FAIhook': + $tmp["Type"]= 'FAIhook'; + $tmp["Abbr"]= 'H'; + break; + case 'FAIpartitionTable': + $tmp["Type"]= 'FAIpartitionTable'; + $tmp["Abbr"]= 'Pt'; + break; + case 'FAIprofile': + $tmp["Type"]= 'FAIprofile'; + $tmp["Abbr"]= 'P'; + break; + default: trigger_error("Unknown FAI object type!");; + } + return($tmp); } - /* Detect all classes that are not valid - * for the selected release + /* Return repository hook output, if possible. */ - $NA = array(); - foreach($classes as $class){ - if(!isset($release_classes[$class])){ - $NA[] = $class; - } - } - return($NA); - } - - - /* Get all selectable classes for the ui select box - */ - function selectable_classes() - { - $this->update_fai_cache(); - - if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){ - $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease]; - }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){ - $classes = $this->cache['CLASSES'][$this->FAIrelease]; - }else{ - $classes = array(); - } - - $Abbr =""; - $ret= array(); - foreach($classes as $class_name => $class_types){ - if(!in_array($class_name,$this->FAIclass)){ - $Abbr = ""; - foreach($class_types as $type){ - if(!preg_match("/".$type['Abbr']."/",$Abbr)){ - $Abbr .= $type['Abbr']." "; - } + function GetHookElements() + { + $ret = array(); + $cmd= $this->config->get_cfg_value("servrepository", "repositoryBranchHook"); + if(!empty($cmd)){ + $res = shell_exec($cmd); + $res2 = trim($res); + if((!$res)){ + msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG); + }elseif(empty($res2)){ + msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG); + }else{ + $tmp = preg_split("/\n/",$res); + foreach($tmp as $line){ + if(empty($line)) continue; + $ret[]= $line; + } + } } - $ret[$class_name] = trim($Abbr); - } + return($ret); } - uksort($ret, 'strnatcasecmp'); - return($ret); - } - - - /* Analyse FAI object and return an array with usefull informations like - * FAIobject type. - */ - function analyse_fai_object($attr) - { - $tmp = array(); - switch($attr['TYPE']){ - - case 'FAIpackageList': - $tmp["Type"]= 'FAIpackageList'; - $tmp["Abbr"]= 'Pl'; - break; - case 'FAItemplate': - $tmp["Type"]= 'FAItemplate'; - $tmp["Abbr"]= 'T'; - break; - case 'FAIvariable': - $tmp["Type"]= 'FAIvariable'; - $tmp["Abbr"]= 'V'; - break; - case 'FAIscript': - $tmp["Type"]= 'FAIscript'; - $tmp["Abbr"]= 'S'; - break; - case 'FAIhook': - $tmp["Type"]= 'FAIhook'; - $tmp["Abbr"]= 'H'; - break; - case 'FAIpartitionTable': - $tmp["Type"]= 'FAIpartitionTable'; - $tmp["Abbr"]= 'Pt'; - break; - case 'FAIprofile': - $tmp["Type"]= 'FAIprofile'; - $tmp["Abbr"]= 'P'; - break; - default: trigger_error("Unknown FAI object type!");; - } - return($tmp); - } - - - /* Return repository hook output, if possible. - */ - function GetHookElements() - { - $ret = array(); - $cmd= $this->config->get_cfg_value("servrepository", "repositoryBranchHook"); - if(!empty($cmd)){ - $res = shell_exec($cmd); - $res2 = trim($res); - if((!$res)){ - msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG); - }elseif(empty($res2)){ - msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG); - }else{ - $tmp = preg_split("/\n/",$res); - foreach($tmp as $line){ - if(empty($line)) continue; - $ret[]= $line; + + + /* This function creates the release name out of a dn + * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2" + */ + function dn_to_release_name($dn) + { + $relevant = preg_replace("/,".preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/').".*$/i","",$dn); + $parts = array_reverse(explode(",",$relevant)); + $str =""; + foreach($parts as $part){ + $str .= preg_replace("/^ou=/","",$part)."/"; } - } - } - return($ret); - } - - - /* This function creates the release name out of a dn - * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2" - */ - function dn_to_release_name($dn) - { - $relevant = preg_replace("/,".preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/').".*$/i","",$dn); - $parts = array_reverse(explode(",",$relevant)); - $str =""; - foreach($parts as $part){ - $str .= preg_replace("/^ou=/","",$part)."/"; + return(preg_replace("/\/$/","",$str)); } - return(preg_replace("/\/$/","",$str)); - } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-plugins/goto/admin/systems/goto/migration/class_migrate_printerRDN.inc b/gosa-plugins/goto/admin/systems/goto/migration/class_migrate_printerRDN.inc index 444145945..a8fd04c25 100644 --- a/gosa-plugins/goto/admin/systems/goto/migration/class_migrate_printerRDN.inc +++ b/gosa-plugins/goto/admin/systems/goto/migration/class_migrate_printerRDN.inc @@ -1,6 +1,6 @@ diff --git a/gosa-plugins/goto/admin/systems/goto/migration/class_migrate_terminalRDN.inc b/gosa-plugins/goto/admin/systems/goto/migration/class_migrate_terminalRDN.inc index b33881322..2505f6467 100644 --- a/gosa-plugins/goto/admin/systems/goto/migration/class_migrate_terminalRDN.inc +++ b/gosa-plugins/goto/admin/systems/goto/migration/class_migrate_terminalRDN.inc @@ -1,6 +1,6 @@