aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPim van den Berg2014-08-10 14:36:23 +0200
committerPim van den Berg2014-08-10 14:36:23 +0200
commit9d27dfc35d1890877d9f18cfa2c6e75ba0720fdf (patch)
treecb3b7032aba48b52203163aad0bf4683e54476cb
parentjsrrdgraph: Fix parsing of rrdfiles containing escapes (diff)
parentSupport customized RRD URLs (diff)
downloadapt-panopticon_cgp-9d27dfc35d1890877d9f18cfa2c6e75ba0720fdf.zip
apt-panopticon_cgp-9d27dfc35d1890877d9f18cfa2c6e75ba0720fdf.tar.gz
apt-panopticon_cgp-9d27dfc35d1890877d9f18cfa2c6e75ba0720fdf.tar.bz2
apt-panopticon_cgp-9d27dfc35d1890877d9f18cfa2c6e75ba0720fdf.tar.xz
Merge remote-tracking branch 'lekensteyn/custom-urls'
-rw-r--r--conf/config.php5
-rw-r--r--rrd.php11
-rw-r--r--type/Base.class.php12
3 files changed, 23 insertions, 5 deletions
diff --git a/conf/config.php b/conf/config.php
index 66b5d0e..157012a 100644
--- a/conf/config.php
+++ b/conf/config.php
@@ -65,6 +65,11 @@ $CONFIG['graph_smooth'] = false;
65# draw min/max spikes in a lighter color in graphs with type default 65# draw min/max spikes in a lighter color in graphs with type default
66$CONFIG['graph_minmax'] = false; 66$CONFIG['graph_minmax'] = false;
67 67
68# The URL that provides RRD files for the "canvas" graph type. Examples:
69# 'rrd/{file}' is replaced by 'rrd/example.com/load/load.rrd'
70# 'rrd.php?path={file_escaped}' becomes 'rrd.php?path=host%3Fload%3Fload.rrd'
71$CONFIG['rrd_url'] = 'rrd.php?path={file_escaped}';
72
68# browser cache time for the graphs (in seconds) 73# browser cache time for the graphs (in seconds)
69$CONFIG['cache'] = 90; 74$CONFIG['cache'] = 90;
70 75
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';
4require_once 'inc/functions.inc.php'; 4require_once 'inc/functions.inc.php';
5require_once 'inc/html.inc.php'; 5require_once 'inc/html.inc.php';
6 6
7if ( $file = validateRRDPath($CONFIG['datadir'], urldecode($_SERVER["QUERY_STRING"])) ) { 7$path = filter_input(INPUT_GET, 'path');
8if (!$path) {
9 // legacy option: rrd.php?some.host/load/load.rrd
10 $path = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING'));
11}
12
13if ( $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
24EOT; 31EOT;
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() {