diff options
Diffstat (limited to '')
-rw-r--r-- | inc/functions.inc.php | 58 |
1 files changed, 48 insertions, 10 deletions
diff --git a/inc/functions.inc.php b/inc/functions.inc.php index f667772..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 | ||
5 | function GET($index) { | 5 | function 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 | ||
11 | function validate_get($value, $type) { | 21 | $desc = array( |
12 | switch($type) { | 22 | 'h' => 'host', |
23 | 'p' => 'plugin', | ||
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) { | ||
13 | case 'h': # host | 34 | case 'h': # host |
14 | if (!preg_match('/^[\w-.]+$/u', $value)) | 35 | if (!preg_match('/^[\w-.]+$/u', $value)) { |
36 | error_log(sprintf('Invalid %s in $_GET["%s"]: "%s"', $desc[$index], $index, $value)); | ||
15 | return NULL; | 37 | return NULL; |
38 | } | ||
16 | break; | 39 | break; |
17 | case 'p': # plugin | 40 | case 'p': # plugin |
18 | case 'c': # category | 41 | case 'c': # category |
19 | case 't': # type | 42 | case 't': # type |
20 | if (!preg_match('/^\w+$/u', $value)) | 43 | if (!preg_match('/^\w+$/u', $value)) { |
44 | error_log(sprintf('Invalid %s in $_GET["%s"]: "%s"', $desc[$index], $index, $value)); | ||
21 | return NULL; | 45 | return NULL; |
46 | } | ||
22 | break; | 47 | break; |
23 | case 'pi': # plugin instance | 48 | case 'pi': # plugin instance |
24 | case 'ti': # type instance | 49 | case 'ti': # type instance |
25 | if (!preg_match('/^[\w-]+$/u', $value)) | 50 | if (!preg_match('/^[\w-]+$/u', $value)) { |
51 | error_log(sprintf('Invalid %s in $_GET["%s"]: "%s"', $desc[$index], $index, $value)); | ||
52 | return NULL; | ||
53 | } | ||
54 | break; | ||
55 | case 's': # seconds | ||
56 | case 'x': # x-axis | ||
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 | ||