From 57f657ddc06324416cef912dc691fffde6753206 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 10 Aug 2014 11:41:20 +0200 Subject: Support customized RRD URLs Use case: I would like to bypass PHP for serving the RRD files and allow the webserver (nginx) to compress it to reduce load on the Raspberry Pi. I could go through all kinds of URL rewriting, but it is much easier to set `$CONFIG['rrd_url'] = 'rrd/{file}';` instead and add a corresponding location + alias directive to the nginx configuration. This depends on https://github.com/manuelluis/jsrrdgraph/pull/17 to avoid breaking on '='. --- rrd.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'rrd.php') diff --git a/rrd.php b/rrd.php index b4c7f68..d4f29ee 100644 --- a/rrd.php +++ b/rrd.php @@ -4,7 +4,13 @@ require_once 'conf/common.inc.php'; require_once 'inc/functions.inc.php'; require_once 'inc/html.inc.php'; -if ( $file = validateRRDPath($CONFIG['datadir'], urldecode($_SERVER["QUERY_STRING"])) ) { +$path = filter_input(INPUT_GET, 'path'); +if (!$path) { + // legacy option: rrd.php?some.host/load/load.rrd + $path = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING')); +} + +if ( $file = validateRRDPath($CONFIG['datadir'], $path) ) { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header("Expires: " .date(DATE_RFC822,strtotime($CONFIG['cache']." seconds"))); @@ -15,10 +21,11 @@ if ( $file = validateRRDPath($CONFIG['datadir'], urldecode($_SERVER["QUERY_STRIN header('HTTP/1.0 403 Forbidden'); html_start(); + $html_weburl = htmlentities($CONFIG['weburl']); echo << forbidden -

Return home...

+

Return home...

EOT; -- cgit v1.1