From: hickert Date: Wed, 24 Oct 2007 08:53:52 +0000 (+0000) Subject: Updated queue handling for gotomasses. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a490c5433fd95272cf4bd93b371e023edef50027;p=gosa.git Updated queue handling for gotomasses. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7637 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/class_hostActionQueue.inc b/include/class_hostActionQueue.inc new file mode 100644 index 000000000..d01d05511 --- /dev/null +++ b/include/class_hostActionQueue.inc @@ -0,0 +1,260 @@ + + \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
"; + + /* 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: +?> diff --git a/include/class_location.inc b/include/class_location.inc index 9540071ea..a614a33c9 100644 --- a/include/class_location.inc +++ b/include/class_location.inc @@ -34,9 +34,9 @@ $class_mapping= array( "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", @@ -246,25 +246,27 @@ $class_mapping= array( "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", @@ -274,8 +276,7 @@ $class_mapping= array( "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 1dc2d9fc0..9fb3c9769 100644 --- a/plugins/addons/gotomasses/class_gotomasses.inc +++ b/plugins/addons/gotomasses/class_gotomasses.inc @@ -10,11 +10,7 @@ class gotomasses extends plugin 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(); @@ -24,15 +20,8 @@ class gotomasses extends plugin { /* 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); } @@ -63,7 +52,7 @@ class gotomasses extends plugin } /************ - * List posts + * REMOVE ************/ /* Remove multiple */ @@ -91,39 +80,21 @@ class gotomasses extends plugin /* 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"), - "
".$this->target_to_string($entry)."
")); - $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]; @@ -155,7 +126,15 @@ class gotomasses extends plugin 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; @@ -177,11 +156,34 @@ class gotomasses extends plugin ************/ $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 = ""; @@ -215,141 +217,6 @@ class gotomasses extends plugin } - 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(); @@ -372,7 +239,6 @@ class gotomasses extends plugin function save() { - $this->save_gotomasses_data(); }