Skip to content

Commit

Permalink
Merge pull request #8 from geoffreyanderson/issue6
Browse files Browse the repository at this point in the history
Allow download of individual collections and fix a few typos
  • Loading branch information
gtowey committed Sep 24, 2012
2 parents cb14dc3 + 1406157 commit 39b2d1a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
collected/*
!collected/index.html
*~
2 changes: 1 addition & 1 deletion conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
28 changes: 27 additions & 1 deletion lib/RainGauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
}

?>
?>
17 changes: 17 additions & 0 deletions lib/RainGaugeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
7 changes: 5 additions & 2 deletions views/server_list_samples.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
<?php if (get_var('sort') == 'timestamp') { ?>
Date
<?php } else { ?>
<a href="<?php echo site_url()."?action=sample&server=".urlencode($server)."&sort=timestamp" ?>">Date</a>
<a href="<?php echo site_url()."?action=server&server=".urlencode($server)."&sort=timestamp" ?>">Date</a>
<?php } ?>
</th>
<th>
<?php if (get_var('sort') == 'size') { ?>
Size
<?php } else { ?>
<a href="<?php echo site_url()."?action=sample&server=".urlencode($server)."&sort=size" ?>">Size</a>
<a href="<?php echo site_url()."?action=server&server=".urlencode($server)."&sort=size" ?>">Size</a>
<?php } ?>
</th>
<th></th>
<th></th>
</tr>

<?php foreach ($samples as $s) { ?>
Expand All @@ -24,6 +26,7 @@
<a href="<?php echo site_url()."?action=sample&server=".urlencode($server)."&sample=".urlencode($s['name']); ?>"><?php echo date("r", $s['timestamp']); ?></a>
</td>
<td><?php echo $s['size'] ?></td>
<td><a href="<?php echo site_url()."?action=download&server=".urlencode($server)."&file=".urlencode($s['name']); ?>" class="btn">Download</a> </td>
</tr>
<?php } ?>
</table>
Expand Down

0 comments on commit 39b2d1a

Please sign in to comment.