diff options
| author | Peter Wu | 2014-08-10 11:41:20 +0200 |
|---|---|---|
| committer | Peter Wu | 2014-08-10 12:42:51 +0200 |
| commit | 57f657ddc06324416cef912dc691fffde6753206 (patch) | |
| tree | 73a02a6cc49e063abeda98e3d81e061be8fb42be /rrd.php | |
| parent | Merge (a)sync code, reformat CGP.js (diff) | |
| download | apt-panopticon_cgp-57f657ddc06324416cef912dc691fffde6753206.zip apt-panopticon_cgp-57f657ddc06324416cef912dc691fffde6753206.tar.gz apt-panopticon_cgp-57f657ddc06324416cef912dc691fffde6753206.tar.bz2 apt-panopticon_cgp-57f657ddc06324416cef912dc691fffde6753206.tar.xz | |
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 '='.
Diffstat (limited to '')
| -rw-r--r-- | rrd.php | 11 |
1 files changed, 9 insertions, 2 deletions
| @@ -4,7 +4,13 @@ require_once 'conf/common.inc.php'; | |||
| 4 | require_once 'inc/functions.inc.php'; | 4 | require_once 'inc/functions.inc.php'; |
| 5 | require_once 'inc/html.inc.php'; | 5 | require_once 'inc/html.inc.php'; |
| 6 | 6 | ||
| 7 | if ( $file = validateRRDPath($CONFIG['datadir'], urldecode($_SERVER["QUERY_STRING"])) ) { | 7 | $path = filter_input(INPUT_GET, 'path'); |
| 8 | if (!$path) { | ||
| 9 | // legacy option: rrd.php?some.host/load/load.rrd | ||
| 10 | $path = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING')); | ||
| 11 | } | ||
| 12 | |||
| 13 | if ( $file = validateRRDPath($CONFIG['datadir'], $path) ) { | ||
| 8 | header('Content-Type: application/octet-stream'); | 14 | header('Content-Type: application/octet-stream'); |
| 9 | header('Content-Disposition: attachment; filename='.basename($file)); | 15 | header('Content-Disposition: attachment; filename='.basename($file)); |
| 10 | header("Expires: " .date(DATE_RFC822,strtotime($CONFIG['cache']." seconds"))); | 16 | header("Expires: " .date(DATE_RFC822,strtotime($CONFIG['cache']." seconds"))); |
| @@ -15,10 +21,11 @@ if ( $file = validateRRDPath($CONFIG['datadir'], urldecode($_SERVER["QUERY_STRIN | |||
| 15 | header('HTTP/1.0 403 Forbidden'); | 21 | header('HTTP/1.0 403 Forbidden'); |
| 16 | 22 | ||
| 17 | html_start(); | 23 | html_start(); |
| 24 | $html_weburl = htmlentities($CONFIG['weburl']); | ||
| 18 | echo <<<EOT | 25 | echo <<<EOT |
| 19 | <fieldset id="forbidden"> | 26 | <fieldset id="forbidden"> |
| 20 | <legend>forbidden</legend> | 27 | <legend>forbidden</legend> |
| 21 | <p><a href="{$CONFIG['weburl']}">Return home...</a></p> | 28 | <p><a href="{$html_weburl}">Return home...</a></p> |
| 22 | </fieldset> | 29 | </fieldset> |
| 23 | 30 | ||
| 24 | EOT; | 31 | EOT; |
