aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/type
diff options
context:
space:
mode:
authorPeter Wu2014-08-10 11:41:20 +0200
committerPeter Wu2014-08-10 12:42:51 +0200
commit57f657ddc06324416cef912dc691fffde6753206 (patch)
tree73a02a6cc49e063abeda98e3d81e061be8fb42be /type
parentMerge (a)sync code, reformat CGP.js (diff)
downloadapt-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 'type')
-rw-r--r--type/Base.class.php12
1 files changed, 9 insertions, 3 deletions
diff --git a/type/Base.class.php b/type/Base.class.php
index 90056cf..c47aba2 100644
--- a/type/Base.class.php
+++ b/type/Base.class.php
@@ -6,6 +6,7 @@ class Type_Base {
6 var $datadir; 6 var $datadir;
7 var $rrdtool; 7 var $rrdtool;
8 var $rrdtool_opts = array(); 8 var $rrdtool_opts = array();
9 var $rrd_url;
9 var $cache; 10 var $cache;
10 var $args; 11 var $args;
11 var $seconds; 12 var $seconds;
@@ -44,6 +45,7 @@ class Type_Base {
44 $config['rrdtool_opts']); 45 $config['rrdtool_opts']);
45 } 46 }
46 } 47 }
48 $this->rrd_url = $config['rrd_url'];
47 $this->cache = $config['cache']; 49 $this->cache = $config['cache'];
48 $this->parse_get($_get); 50 $this->parse_get($_get);
49 $this->rrd_title = sprintf( 51 $this->rrd_title = sprintf(
@@ -137,6 +139,9 @@ class Type_Base {
137 } 139 }
138 140
139 function rrd_escape($value) { 141 function rrd_escape($value) {
142 # In case people have really bizarre URLs in $CONFIG['rrd_url'],
143 # it should not be dropped.
144 return str_replace('\\', '\\\\', $value);
140 # http://oss.oetiker.ch/rrdtool/doc/rrdgraph_graph.en.html#IEscaping_the_colon 145 # http://oss.oetiker.ch/rrdtool/doc/rrdgraph_graph.en.html#IEscaping_the_colon
141 return str_replace(':', '\:', $value); 146 return str_replace(':', '\:', $value);
142 } 147 }
@@ -144,10 +149,11 @@ class Type_Base {
144 function parse_filename($file) { 149 function parse_filename($file) {
145 if ($this->graph_type == 'canvas') { 150 if ($this->graph_type == 'canvas') {
146 $file = str_replace($this->datadir . '/', '', $file); 151 $file = str_replace($this->datadir . '/', '', $file);
147 # rawurlencode all but / 152 $rrd_url = str_replace('{file}', $file, $this->rrd_url);
148 $file = 'rrd.php?' . str_replace('%2F', '/', rawurlencode($file)); 153 $rrd_url = str_replace('{file_escaped}',
154 urlencode($file), $rrd_url);
149 } 155 }
150 return $this->rrd_escape($file); 156 return $this->rrd_escape($rrd_url);
151 } 157 }
152 158
153 function rrd_files() { 159 function rrd_files() {