aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/functions.inc.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--inc/functions.inc.php70
1 files changed, 54 insertions, 16 deletions
diff --git a/inc/functions.inc.php b/inc/functions.inc.php
index abe0763..9e56868 100644
--- a/inc/functions.inc.php
+++ b/inc/functions.inc.php
@@ -2,28 +2,66 @@
2 2
3# global functions 3# global functions
4 4
5function GET($index) { 5function GET($index = NULL, $value = NULL) {
6 if (isset($_GET[$index])) 6 # parse all values from $_GET when no index is given
7 return $_GET[$index]; 7 if ($index === NULL) {
8 return null; 8 $arr = array();
9} 9 foreach($_GET as $i => $v) {
10 $arr[$i] = GET($i);
11 }
12 return $arr;
13 }
14
15 if (!isset($_GET[$index]))
16 return NULL;
17
18 if ($value === NULL)
19 $value = $_GET[$index];
10 20
11function validate_get($value, $type) { 21 $desc = array(
12 switch($type) { 22 'h' => 'host',
13 case 'host': 23 'p' => 'plugin',
14 if (!preg_match('/^[\w-.]+$/u', $value)) 24 'c' => 'category',
25 't' => 'type',
26 'pi' => 'plugin instance',
27 'ti' => 'type instance',
28 's' => 'seconds',
29 'x' => 'x-axis',
30 'y' => 'y-axis',
31 );
32
33 switch($index) {
34 case 'h': # host
35 if (!preg_match('/^[\w-.]+$/u', $value)) {
36 error_log(sprintf('Invalid %s in $_GET["%s"]: "%s"', $desc[$index], $index, $value));
37 return NULL;
38 }
39 break;
40 case 'p': # plugin
41 case 'c': # category
42 case 't': # type
43 if (!preg_match('/^\w+$/u', $value)) {
44 error_log(sprintf('Invalid %s in $_GET["%s"]: "%s"', $desc[$index], $index, $value));
15 return NULL; 45 return NULL;
46 }
16 break; 47 break;
17 case 'plugin': 48 case 'pi': # plugin instance
18 case 'category': 49 case 'ti': # type instance
19 case 'type': 50 if (!preg_match('/^[\w-]+$/u', $value)) {
20 if (!preg_match('/^\w+$/u', $value)) 51 error_log(sprintf('Invalid %s in $_GET["%s"]: "%s"', $desc[$index], $index, $value));
21 return NULL; 52 return NULL;
53 }
22 break; 54 break;
23 case 'pinstance': 55 case 's': # seconds
24 case 'tinstance': 56 case 'x': # x-axis
25 if (!preg_match('/^[\w-]+$/u', $value)) 57 case 'y': # y-axis
58 if (!is_numeric($value)) {
59 error_log(sprintf('Invalid %s in $_GET["%s"]: "%s"', $desc[$index], $index, $value));
26 return NULL; 60 return NULL;
61 }
62 break;
63 default:
64 return NULL;
27 break; 65 break;
28 } 66 }
29 67