opsi = new opsi($config); $this->is_account =TRUE; /* Check if we are are part of a windows workstation */ $this->parent = $parent; if($parent instanceof wingeneric){ $this->parent_mode = FALSE; } /* Get hostId */ if($hostId != "new"){ if(preg_match("/^opsi:/",$hostId)){ $this->hostId = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$hostId); }elseif($this->parent instanceof wingeneric){ $this->hostId = $this->parent->cn; $this->hostId = preg_replace('/\$$/',"",$this->hostId); } } /* Try to plugin */ $this->init(); } private function init() { $err = FALSE; $this->init_failed = FALSE; $this->initially_was_account = FALSE; if($this->hostId != "new"){ $list = $this->opsi->list_clients($this->hostId); $err |= $this->opsi->is_error(); foreach($list as $entry){ if(preg_match("/^".normalizePreg($this->hostId)."$/i",$entry['NAME'][0]['VALUE'])){ $this->initially_was_account = TRUE; foreach(array("description" => "DESCRIPTION","mac" => "MAC", "note" => "NOTES") as $des => $src){ $this->$des = $entry[$src][0]['VALUE']; } break; } } } /* Get product settings */ if(!$err){ $this->a_availableNetbootProducts = $this->opsi->get_netboot_products(); $err |= $this->opsi->is_error(); } if(!$err) { $this->a_availableLocalProducts = $this->opsi->get_local_products(); $err |= $this->opsi->is_error(); } /* Get selected products */ if(!$err && !empty($this->hostId)) { $tmp = array_keys($this->opsi->get_netboot_products($this->hostId)); if(count($tmp)){ $this->s_selectedNetbootProduct = $tmp[0]; } $err |= $this->opsi->is_error(); } if(!$err && !empty($this->hostId)) { $tmp = $this->opsi->get_local_products($this->hostId); $err |= $this->opsi->is_error(); $this->a_selectedLocalProducts = $tmp; } /* Load product configuration */ if(!$err && !empty($this->hostId)) { foreach($this->a_selectedLocalProducts as $name => $data){ $CFG = $this->opsi->get_product_properties($name,$this->hostId); $err |= $this->opsi->is_error(); $this->a_selectedLocalProducts[$name]['CFG'] = $CFG; } } /* Check if everything went fine else reset everything and display a retry button */ if($err){ $this->a_availableNetbootProducts = array(); $this->s_selectedNetbootProduct = ""; $this->s_initial_selectedNetbootProduct = ""; $this->a_availableLocalProducts = array(); $this->a_selectedLocalProducts = array(); $this->a_initial_selectedLocalProducts = array(); $this->init_failed = TRUE; }else{ /* Remember initial settings */ $this->is_account = $this->initially_was_account; $this->a_initial_selectedLocalProducts = $this->a_selectedLocalProducts; $this->s_initial_selectedNetbootProduct = $this->s_selectedNetbootProduct; } } public function check() { return(array()); $messages = plugin::check(); if(!preg_match("/\./",$this->hostId)){ $messages[] = msgPool::invalid(_("Name"),$this->hostId,"",_("The client name must contain a domain part (e.g. '.company.de').")); } if(!tests::is_mac($this->mac) || empty($this->mac)){ $messages[] = msgPool::invalid(_("MAC address"),$this->mac,"","00:0C:7F:31:33:F1"); } return($messages); } public function execute() { $display =""; /* The pluign initialization failed due to communication problems with the gosa daemon. A retry button will be displayed here. */ if($this->init_failed){ $smarty = get_smarty(); $smarty->assign("init_failed",TRUE); $smarty->assign("message",$this->opsi->get_error()); return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); } /* If we are not a stand alone opsi client, we must be a samba client which has the opsi tab enabled. Check if the opsi is added or removed and display state buttons. */ if(!$this->parent_mode){ if(isset($_POST['modify_state'])){ if($this->is_account){ $this->is_account= FALSE; }elseif(!$this->is_account){ $this->is_account= TRUE; } } if($this->is_account){ $display = $this->show_disable_header(msgPool::removeFeaturesButton(_("Opsi")), msgPool::featuresEnabled(_("Opsi"))); }else{ $display = $this->show_enable_header(msgPool::addFeaturesButton(_("Opsi")), msgPool::featuresDisabled(_("Opsi"))); return($display); } } /* Check if we have a sub dialog opened */ if(is_object($this->dialog)){ $this->dialog->save_object(); return($this->dialog->execute()); } /* Create HTML output of this plugin */ $smarty = get_smarty(); foreach($this->attributes as $attr){ $smarty->assign($attr,$this->$attr); } $smarty->assign("parent_mode", $this->parent_mode); $smarty->assign("is_installed", $this->is_installed); $smarty->assign("init_failed",FALSE); $divSLP = new divSelectBox(); $divALP = new divSelectBox(); /* Create list of available local products */ ksort($this->a_availableLocalProducts); foreach($this->a_availableLocalProducts as $name => $data){ if(isset($this->a_selectedLocalProducts[$name])) continue; $add_tab = array("string" => ""); $name_tab = array("string" => $name); $desc_tab = array("string" => "
", "attach" => "title='".$data['DESC']."' style='border-right:0px;'"); $divALP->AddEntry(array($add_tab,$name_tab,$desc_tab)); } /* Create list of selected local products */ ksort($this->a_selectedLocalProducts); foreach($this->a_selectedLocalProducts as $name => $data){ $name_tab = array("string" => $name); $desc_tab = array( "string" => " ", "attach" => "title='".$data['DESC']."'"); /* Only display edit button, if there is something to edit */ $edit = ""; if(count($data['CFG'])){ $edit = ""; } $del = ""; $opt_tab = array("string" => $edit.$del, "attach" => "style='border-right:0px; width: 40px; text-align:right;'"); $divSLP->AddEntry(array($name_tab,$desc_tab,$opt_tab)); } ksort($this->a_availableNetbootProducts); $smarty->assign("hostId", $this->hostId); $smarty->assign("divSLP", $divSLP->DrawList()); $smarty->assign("divALP", $divALP->DrawList()); $smarty->assign("SNP", $this->s_selectedNetbootProduct); $smarty->assign("ANP", $this->a_availableNetbootProducts); return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); } public function save() { if(!$this->initially_was_account && $this->is_account){ $res = $this->opsi->add_client($this->hostId,$this->mac,$this->note,$this->description); if($this->opsi->is_error()){ msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG); return; } } $this->opsi->modify_client($this->hostId,$this->mac,$this->note,$this->description); if($this->opsi->is_error()){ msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG); return; } $add = array_diff_assoc($this->a_selectedLocalProducts,$this->a_initial_selectedLocalProducts); $del = array_diff_assoc($this->a_initial_selectedLocalProducts,$this->a_selectedLocalProducts); foreach($del as $name => $data){ $this->opsi->del_product_from_client($name,$this->hostId); if($this->opsi->is_error()){ msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG); return; } } foreach($add as $name => $data){ echo "Adding '$name' to ".$this->hostId."