summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 062e0cd)
raw | patch | inline | side by side (parent: 062e0cd)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 24 Oct 2007 08:53:52 +0000 (08:53 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 24 Oct 2007 08:53:52 +0000 (08:53 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7637 594d385d-05f5-0310-b6e9-bd551577e9d8
include/class_hostActionQueue.inc | [new file with mode: 0644] | patch | blob |
include/class_location.inc | patch | blob | history | |
plugins/addons/gotomasses/class_gotomasses.inc | patch | blob | history |
diff --git a/include/class_hostActionQueue.inc b/include/class_hostActionQueue.inc
--- /dev/null
@@ -0,0 +1,260 @@
+<?php
+/*
+ This code is part of GOsa (https://gosa.gonicus.de)
+ Copyright (C) 2007 Fabian Hickert
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*!
+ \brief This class represents the host action queue.
+ \author Fabian Hickert <hickert@gonicus.de>
+ \version 2.6
+ \date 24.10.2007
+
+ This class is a queue handler, which allows adding,removing,
+ priority settings,stop and resume actions... for each queue entry
+ */
+class hostActionQueue {
+
+ private $o_config = NULL;
+ private $s_queue_file = "";
+ private $s_error = "";
+ private $b_error = FALSE;
+
+ private $a_queue = array();
+ private $i_pointer = 0;
+ private $b_queue_loaded = false;
+ private $i_fileversion = 0;
+
+ public function __construct($config)
+ {
+ $this->o_config= $config;
+
+ /* Define source file */
+ $this->s_queue_file = CONFIG_DIR."/gotomasses_machines";
+
+ $file = $this->o_config->search("gotomasses", "STORAGE_FILE",array('menu'));
+ if(!empty($file)){
+ $this->s_queue_file = $file;
+ }
+ }
+
+ private function _reload_queue()
+ {
+ $this->_reset_error();
+ $this->b_queue_loaded = FALSE;
+ $this->b_error = FALSE;
+ $this->s_error = "";
+ $this->i_pointer = 0;
+
+ /* Check file accessibility */
+ if(!file_exists($this->s_queue_file)){
+ $this->set_error(sprintf(_("Can't locate gotomasses queue file '%s'."),$this->s_queue_file));
+ return(FALSE);
+ }
+ if(!is_readable($this->s_queue_file)){
+ $this->set_error(sprintf(_("Can't read gotomasses queue file '%s'."),$this->s_queue_file));
+ return(FALSE);
+ }
+
+ /* Check if file contents could be read */
+ $fp = @fopen($this->s_queue_file,"r");
+ if(!$fp){
+ $this->set_error(sprintf(_("Can't read gotomasses storage file '%s'."),$this->s_queue_file));
+ return(FALSE);
+ }
+ $this->i_fileversion = filemtime($this->s_queue_file);
+ echo $this->i_fileversion."reload<br>";
+
+ /* Get file contents */
+ $data ="";
+ while(!feof($fp)){
+ $data.= fread($fp,512);
+ }
+
+ /* Get lines from file */
+ $this->a_queue = array();
+ $comment = "";
+ $rows = split("\n",$data);
+
+ /* Walk trough rows and parse data */
+ foreach($rows as $row){
+
+ /* Skip empty lines */
+ $row = trim($row);
+ if(empty($row)){
+ continue;
+ }
+
+ /* Get comment, if available */
+ if(preg_match("/^#/",$row)){
+ $comment = preg_replace("/^#/","",$row);
+ continue;
+ }
+
+ /* Split row into minutes/ hours ...*/
+ $row = preg_replace('/[\t ]/umi'," ",$row);
+ $row = preg_replace('/ */umi'," ",$row);
+ $parts = split(" ",$row);
+
+ if(count($parts) != 10){
+ print_red(_("Entry broken, skipped."));
+ }else{
+
+ $entry = array();
+ $entry['Minute'] = $parts[0];
+ $entry['Hour'] = $parts[1];
+ $entry['Day'] = $parts[2];
+ $entry['Month'] = $parts[3];
+ $entry['Weekday'] = $parts[4];
+ $entry['Action'] = $parts[5];
+ $entry['OGroup'] = $parts[6];
+ $entry['Zone'] = $parts[7];
+ $entry['Section'] = $parts[8];
+ if($entry['Action'] == "initial_install"){
+ $tmp2 = split(";",$parts[9]);
+ foreach($tmp2 as $target){
+ $tmp = split(",",$target);
+ $entry['Initial_Target'][] = array(
+ "MAC" => $tmp[0],
+ "IP" => $tmp[1],
+ "NAME" => $tmp[2]);
+ }
+ $entry['Target'] = array();
+ }else{
+ $entry['Initial_Target'] = array();
+ $entry['Target'] = split(";",$parts[7]);
+ }
+ $entry['Comment'] = $comment;
+ $this->a_queue[] = $entry;
+ }
+ }
+ return(TRUE);
+ }
+
+
+ private function _save_data()
+ {
+ $this->_reset_error();
+
+ /* Check file accessibility */
+ if(!file_exists($this->s_queue_file)){
+ $this->set_error(sprintf(_("Can't locate gotomasses queue file '%s'."),$this->s_queue_file));
+ return(FALSE);
+ }
+ if(!is_writeable($this->s_queue_file)){
+ $this->set_error(sprintf(_("Can't write gotomasses queue file '%s'."),$this->s_queue_file));
+ return(FALSE);
+ }
+ if($this->i_fileversion != filemtime($this->s_queue_file)){
+ $this->set_error(_("The queue file was modified since last reload. Can't save changes."));
+ return(FALSE);
+ }
+ $fp = @fopen($this->s_queue_file,"w");
+ if(!$fp){
+ $this->set_error(sprintf(_("Can't write gotomasses queue file '%s'."),$this->s_queue_file));
+ return(FALSE);
+ }
+
+ $str = "#GOsa generated file, please just modify if you really know what you do.";
+ foreach($this->a_queue as $task){
+ $str .= "\n#".trim($task['Comment']);
+ $str .= "\n";
+ if($task['Action'] == "initial_install"){
+ $str .= "* * * * * ";
+ }else{
+ $str .= str_pad($task['Minute'] ,5," ")." ";
+ $str .= str_pad($task['Hour'] ,5," ")." ";
+ $str .= str_pad($task['Day'] ,5," ")." ";
+ $str .= str_pad($task['Month'] ,5," ")." ";
+ $str .= str_pad($task['Weekday'],5," ")." ";
+ }
+ $str .= str_pad($task['Action'] ,5," ")." ";
+ $str .= str_pad($task['OGroup'] ,5," ")." ";
+ $str .= str_pad($task['Zone'] ,5," ")." ";
+ $str .= str_pad($task['Section'],5," ")." ";
+ if($task['Action'] == "initial_install"){
+ foreach($task['Initial_Target'] as $target){
+ $str .= trim($target['MAC']).",".trim($target['IP']).",".trim($target['NAME']).";";
+ }
+ }else{
+ foreach($task['Target'] as $target){
+ $str .= $target.";";
+ }
+ }
+ $str = preg_replace("/;$/","",$str);
+ }
+
+ /* Write contents */
+ $str .= "\n";
+ fwrite($fp,$str);
+ fclose($fp);
+ $this->i_fileversion = filemtime($this->s_queue_file);
+ return(TRUE);
+ }
+
+ public function add($entry)
+ {
+ $this->a_queue[] = $entry;
+ return($this->_save_data());
+ }
+
+ public function fetch()
+ {
+ if(isset($this->a_queue[$this->i_pointer])){
+ $p = $this->a_queue[$this->i_pointer];
+ $this->i_pointer ++;
+ return($p);
+ }
+ return(FALSE);
+ }
+
+ public function load()
+ {
+ return($this->_reload_queue());
+ }
+
+ public function save()
+ {
+ return($this->_save_data());
+ }
+
+ private function _reset_error()
+ {
+ $this->b_error = FALSE;
+ $this->s_error = "";
+ }
+
+ private function set_error($str)
+ {
+ $this->b_error = TRUE;
+ $this->s_error = $str;
+ }
+
+ public function is_error()
+ {
+ return($this->b_error);
+ }
+
+ public function get_error()
+ {
+ return($this->s_error);
+ }
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 9540071eaa2aec1b16b02a34585b260c635150d9..a614a33c92bc10115f872994bd7392040df4e28c 100644 (file)
"dfsgeneric" => "plugins/addons/godfs/class_dfsgeneric.inc",
"dfstabs" => "plugins/addons/godfs/tabs_dfs.inc",
"gotomasses" => "plugins/addons/gotomasses/class_gotomasses.inc",
+ "divListMasses" => "plugins/addons/gotomasses/class_divListMasses.inc",
"goto_task" => "plugins/addons/gotomasses/class_goto_task.inc",
"target_list" => "plugins/addons/gotomasses/class_target_list.inc",
- "divListMasses" => "plugins/addons/gotomasses/class_divListMasses.inc",
"parseMailQueue" => "plugins/addons/mailqueue/class_parseMailQueue.inc",
"mailqueue" => "plugins/addons/mailqueue/class_mailqueue.inc",
"msgplug" => "plugins/addons/notifications/class_msgplug.inc",
"gosa_cache" => "include/class_cache_handler.inc",
"passwordMethodCrypt" => "include/class_password-methods-crypt.inc",
"passwordMethod" => "include/class_password-methods.inc",
+ "passwordMethodheimdal" => "include/class_password-methods-heimdal.inc",
+ "msg_dialog" => "include/class_msg_dialog.inc",
"mailMethodGolab" => "include/class_mail-methods-golab.inc",
"pgre_sql" => "include/class_pgsql_opengw.inc",
- "passwordMethodheimdal" => "include/class_password-methods-heimdal.inc",
"mailMethodKolab" => "include/class_mail-methods-kolab.inc",
"passwordMethodsha" => "include/class_password-methods-sha.inc",
- "msg_dialog" => "include/class_msg_dialog.inc",
"passwordMethodkerberos" => "include/class_password-methods-kerberos.inc",
"parseXml" => "include/functions_helpviewer.inc",
"divlist" => "include/class_divlist.inc",
"ppdManager" => "include/class_ppdManager.inc",
+ "multi_plug" => "include/class_multi_plug.inc",
"MultiSelectWindow" => "include/class_MultiSelectWindow.inc",
"certificate" => "include/class_certificate.inc",
"passwordMethodMd5" => "include/class_password-methods-md5.inc",
"tabs" => "include/class_tabs.inc",
"Print_a_class" => "include/functions_debug.inc",
"divSelectBox" => "include/class_divSelectBox.inc",
- "passwordMethodssha" => "include/class_password-methods-ssha.inc",
+ "dhcpPlugin" => "include/class_dhcpPlugin.inc",
"ogw" => "include/class_opengw.inc",
"acl" => "include/class_acl.inc",
+ "passwordMethodssha" => "include/class_password-methods-ssha.inc",
"pluglist" => "include/class_pluglist.inc",
"CopyPasteHandler" => "include/class_CopyPasteHandler.inc",
"config" => "include/class_config.inc",
"mailMethodSendmailCyrus" => "include/class_mail-methods-sendmail-cyrus.inc",
"LDAP" => "include/class_ldap.inc",
"log" => "include/class_log.inc",
- "dhcpPlugin" => "include/class_dhcpPlugin.inc",
- "multi_plug" => "include/class_multi_plug.inc",
+ "hostActionQueue" => "include/class_hostActionQueue.inc",
"Step_Ldap" => "setup/class_setupStep_Ldap.inc",
"Step_Finish" => "setup/class_setupStep_Finish.inc",
"setup_step" => "setup/class_setupStep.inc",
diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc
index 1dc2d9fc08ce739ee5e329f988d54173bed3d388..9fb3c9769c231ed37b2611600d5462f7f88ca088 100644 (file)
var $attributes= array();
var $objectclasses= array();
- /* Source file that contains the gotomasses data */
- var $data_file = "Undefined"; #Set in constructor
-
/* Queue tasks */
- var $tasks = array();
var $current =false;
var $dialog = FALSE;
var $ids_to_remove = array();
{
/* Include config object */
$this->config= &$config;
-
- /* Define source file */
- $this->data_file = CONFIG_DIR."/gotomasses_machines";
- $file = $this->config->search("gotomasses", "STORAGE_FILE",array('menu'));
- if(!empty($file)){
- $this->data_file = $file;
- }
$this->divlist = new divListMasses($this->config,$this);
- $this->load_gotomasses_data();
+ $this->o_queue = new hostActionQueue(&$config);
}
}
/************
- * List posts
+ * REMOVE
************/
/* Remove multiple */
/* Remove specified tasks */
if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
foreach($this->ids_to_remove as $id){
- if(isset($this->tasks[$id])){
- unset($this->tasks[$id]);
- }
+ $this->o_queue->remove($id);
}
$this->save();
}
- /* Remove entry from list */
- if($s_action == "remove" && isset($this->tasks[$s_entry])){
- if(!$this->acl_is_removeable()){
- print_red(_("You are not allowed to remove a task."));
- }else{
- $entry = $this->tasks[$s_entry];
- $this->current = $s_entry;
- $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),
- "<pre>".$this->target_to_string($entry)."</pre>"));
- $smarty->assign("multiple", FALSE);
- return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
- }
- }
-
- /* Remove entry, remove is confirmed */
- if($this->current != -1 && isset($_POST['delete_confirm'])){
- unset($this->tasks[$this->current]);
- $this->current = -1;
- $this->save();
- }
-
/* Remove aborted */
if(isset($_POST['delete_cancel'])){
$this->ids_to_remove = array();;
}
+
+ /************
+ * EDIT
+ ************/
+
/* Edit selected entry */
if($s_action == "edit" && isset($this->tasks[$s_entry])){
$entry = $this->tasks[$s_entry];
if(isset($this->tasks[$this->current]) && $this->current != -1){
$this->tasks[$this->current] = $this->dialog->save();
}else{
- $this->tasks[] = $this->dialog->save();
+ $tmp = $this->dialog->save();
+
+ $targets =$tmp['Target'];
+ foreach($targets as $target){
+ $tmp['Target'] = array($target);
+ if(!$this->o_queue->add($tmp)){
+ print_red($this->o_queue->get_error());
+ }
+ }
}
if(!isset($_POST['apply_goto_task'])){
$this->dialog = FALSE;
************/
$this->divlist->execute();
- $this->divlist->SetEntries($this->tasks);
+ $this->divlist->SetEntries($this->get_queue_entries());
return($this->divlist->Draw());
}
-
+
+ function get_queue_entries()
+ {
+ if(!$this->o_queue->load()){
+ print_red("ERROR:".$this->o_queue->get_error());
+ return(FALSE);
+ }
+ $ret = array();
+ while($entry = $this->o_queue->fetch()){
+ $ret[] = $entry;
+ }
+ return($ret);
+ }
+
+
+
+
+
+
+
+
+
+
+
function target_to_string($data)
{
$ret = "";
}
- function load_gotomasses_data()
- {
- $ui = get_userinfo();
-
- /* Check file existence */
- if(!file_exists($this->data_file) || !is_readable($this->data_file)){
- print_red(sprintf(_("Can't locate or read gotomasses storage file '%s'."),$this->data_file));
- return(FALSE);
- }
-
- /* check if file is readable */
- $fp = @fopen($this->data_file,"r");
- if(!$fp){
- print_red(sprintf(_("Can't read gotomasses storage file '%s'."),$this->data_file));
- return(FALSE);
- }
-
- /* Get file contents */
- $data ="";
- while(!feof($fp)){
- $data.= fread($fp,512);
- }
-
- /* Get lines from file */
- $this->tasks = array();
- $comment = "";
- $rows = split("\n",$data);
-
- /* Walk trough rows and parse data */
- foreach($rows as $row){
-
- /* Skip empty lines */
- $row = trim($row);
- if(empty($row)){
- continue;
- }
-
- /* Get comment, if available */
- if(preg_match("/^#/",$row)){
- $comment = preg_replace("/^#/","",$row);
- continue;
- }
-
- /* Split row into minutes/ hours ...*/
- $row = preg_replace('/[\t ]/umi'," ",$row);
- $row = preg_replace('/ */umi'," ",$row);
- $parts = split(" ",$row);
-
- if(count($parts) != 10){
- print_red(_("Entry broken, skipped."));
- }else{
-
- $entry = array();
- $entry['Minute'] = $parts[0];
- $entry['Hour'] = $parts[1];
- $entry['Day'] = $parts[2];
- $entry['Month'] = $parts[3];
- $entry['Weekday'] = $parts[4];
- $entry['Action'] = $parts[5];
- $entry['OGroup'] = $parts[6];
- $entry['Zone'] = $parts[7];
- $entry['Section'] = $parts[8];
- if($entry['Action'] == "initial_install"){
- $tmp2 = split(";",$parts[9]);
- foreach($tmp2 as $target){
- $tmp = split(",",$target);
- $entry['Initial_Target'][] = array(
- "MAC" => $tmp[0],
- "IP" => $tmp[1],
- "NAME" => $tmp[2]);
- }
- $entry['Target'] = array();
- }else{
- $entry['Initial_Target'] = array();
- $entry['Target'] = split(";",$parts[7]);
- }
- $entry['Comment'] = $comment;
- $this->tasks [] = $entry;
- }
- }
- }
-
-
- function save_gotomasses_data()
- {
- $str = "#GOsa generated file, please just modify if you really know what you do.";
- foreach($this->tasks as $task){
- $str .= "\n#".trim($task['Comment']);
- $str .= "\n";
- if($task['Action'] == "initial_install"){
- $str .= "* * * * * ";
- }else{
- $str .= str_pad($task['Minute'] ,5," ")." ";
- $str .= str_pad($task['Hour'] ,5," ")." ";
- $str .= str_pad($task['Day'] ,5," ")." ";
- $str .= str_pad($task['Month'] ,5," ")." ";
- $str .= str_pad($task['Weekday'],5," ")." ";
- }
- $str .= str_pad($task['Action'] ,5," ")." ";
- $str .= str_pad($task['OGroup'] ,5," ")." ";
- $str .= str_pad($task['Zone'] ,5," ")." ";
- $str .= str_pad($task['Section'],5," ")." ";
- if($task['Action'] == "initial_install"){
- foreach($task['Initial_Target'] as $target){
- $str .= trim($target['MAC']).",".trim($target['IP']).",".trim($target['NAME']).";";
- }
- }else{
- foreach($task['Target'] as $target){
- $str .= $target.";";
- }
- }
- $str = preg_replace("/;$/","",$str);
- }
-
- /* check file existence*/
- $ui = get_userinfo();
- if(!file_exists($this->data_file) || !is_writeable($this->data_file)){
- print_red(sprintf(_("Can't locate or write gotomasses storage file '%s'."),$this->data_file));
- return(FALSE);
- }
-
- /* check permissions */
- $fp = @fopen($this->data_file,"w");
- if(!$fp){
- print_red(sprintf(_("Can't read gotomasses storage file '%s'."),$this->data_file));
- return(FALSE);
- }
-
- /* Write contents */
- $str .= "\n";
- fwrite($fp,$str);
- fclose($fp);
- }
-
-
function save_object()
{
$this->divlist->save_object();
function save()
{
- $this->save_gotomasses_data();
}