From 14061570ae46b87af4459c3078d602dacc5c2e69 Mon Sep 17 00:00:00 2001 From: Geoffrey Anderson Date: Thu, 13 Sep 2012 00:18:48 -0700 Subject: [PATCH] Allow download of individual collections and fix a few typos --- .gitignore | 1 + conf/config.inc.php | 2 +- lib/RainGauge.php | 28 +++++++++++++++++++++++++++- lib/RainGaugeModel.php | 17 +++++++++++++++++ views/server_list_samples.php | 7 +++++-- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 1a59d9a..049f60c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ collected/* !collected/index.html +*~ diff --git a/conf/config.inc.php b/conf/config.inc.php index 52c3268..0313710 100644 --- a/conf/config.inc.php +++ b/conf/config.inc.php @@ -9,7 +9,7 @@ 'Bandwidth' => array( 'Bytes_sent', 'Bytes_received' ), 'Threads' => array( 'Threads_connected', 'Threads_running'), 'DML' => array( 'Questions', 'Com_select', 'Com_insert','Com_update','Com_delete', 'Com_replace'), - 'Select_Types' => array('Select_full_join', 'Select_full_range_join','Select_range','Select_range_check','Select_scan'), + 'Select_Types' => array( 'Select_full_join', 'Select_full_range_join','Select_range','Select_range_check','Select_scan'), 'Os_Waits' => array( 'Innodb_mutex_os_waits', 'Innodb_x_lock_os_waits', 'Innodb_s_lock_os_waits'), 'LSN' => array( 'Innodb_lsn_current', 'Innodb_lsn_flushed', 'Innodb_lsn_last_checkpoint'), 'Log' => array( 'Innodb_log_writes','Innodb_log_write_requests', 'Innodb_log_waits'), diff --git a/lib/RainGauge.php b/lib/RainGauge.php index 448195e..0009f66 100644 --- a/lib/RainGauge.php +++ b/lib/RainGauge.php @@ -435,6 +435,32 @@ private function get_timestamp_from_file($file) { return 0; } + /** + * given a server and name of a sample, allow the user to download the file. + * + * @return int + */ + public function download() { + // ask model for path to file + $server = get_var('server'); + $file = get_var('file'); + $filename = $this->model->get_collection_filename($server, $file); + + // stream file + header('Pragma: public'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Cache-Control: private',false); + header('Content-type: "application/octet-stream"'); + header('Content-Disposition: attachment; filename="' . basename($filename) . '";' ); + header('Content-Transfer-Encoding: binary'); + header('Content-Length: '. filesize($filename) ); + ob_clean(); + flush(); + readfile($filename); + return 0; + + } } -?> \ No newline at end of file +?> diff --git a/lib/RainGaugeModel.php b/lib/RainGaugeModel.php index 4ff0fb0..82454f4 100644 --- a/lib/RainGaugeModel.php +++ b/lib/RainGaugeModel.php @@ -152,6 +152,23 @@ public function get_sample_percent($hostname, $sample) { return $n / count($samples) * 100; } + /** + * given a server and filename, get a valid full path to a collection archive file. + * + * @param string $server + * @param string $file + * @return mixed the string representation of the full file path if the file exists. Otherwise, false. + */ + public function get_collection_filename($server, $file) { + // TODO: (ganderson) this is horribly insecure. We need to make sure the path doesn't step out of this directory. + $file = $this->collection_dir() . '/' . $server . '/' . $file; + if (file_exists($file)) { + return $file; + } + return false; + } + + /** * return the contents of a specific file in a sample. * diff --git a/views/server_list_samples.php b/views/server_list_samples.php index 28b0433..1cb3f3c 100644 --- a/views/server_list_samples.php +++ b/views/server_list_samples.php @@ -6,16 +6,18 @@ Date - ">Date + ">Date Size - ">Size + ">Size + + @@ -24,6 +26,7 @@ "> + " class="btn">Download