r1802 + remove the last ends of help code and data
[racktables] / inc / pagehandlers.php
1 <?php
2 /*
3 *
4 * This file is a library of page handlers for RackTables.
5 *
6 */
7
8 // This function assures that specified argument was passed
9 // and is a number greater than zero.
10 function assertUIntArg ($argname, $allow_zero = FALSE)
11 {
12 if (!isset ($_REQUEST[$argname]))
13 {
14 showError ("Parameter '${argname}' is missing.", __FUNCTION__);
15 die();
16 }
17 if (!is_numeric ($_REQUEST[$argname]))
18 {
19 showError ("Parameter '${argname}' is not a number.", __FUNCTION__);
20 die();
21 }
22 if ($_REQUEST[$argname] < 0)
23 {
24 showError ("Parameter '${argname}' is less than zero.", __FUNCTION__);
25 die();
26 }
27 if (!$allow_zero and $_REQUEST[$argname] == 0)
28 {
29 showError ("Parameter '${argname}' is equal to zero.", __FUNCTION__);
30 die();
31 }
32 }
33
34 // This function assures that specified argument was passed
35 // and is a non-empty string.
36 function assertStringArg ($argname, $ok_if_empty = FALSE)
37 {
38 if (!isset ($_REQUEST[$argname]))
39 {
40 showError ("Parameter '${argname}' is missing.", __FUNCTION__);
41 die();
42 }
43 if (!is_string ($_REQUEST[$argname]))
44 {
45 showError ("Parameter '${argname}' is not a string.", __FUNCTION__);
46 die();
47 }
48 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
49 {
50 showError ("Parameter '${argname}' is an empty string.", __FUNCTION__);
51 die();
52 }
53 }
54
55 function assertBoolArg ($argname, $ok_if_empty = FALSE)
56 {
57 if (!isset ($_REQUEST[$argname]))
58 {
59 showError ("Parameter '${argname}' is missing.", __FUNCTION__);
60 die();
61 }
62 if (!is_string ($_REQUEST[$argname]) or $_REQUEST[$argname] != 'on')
63 {
64 showError ("Parameter '${argname}' is not a string.", __FUNCTION__);
65 die();
66 }
67 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
68 {
69 showError ("Parameter '${argname}' is an empty string.", __FUNCTION__);
70 die();
71 }
72 }
73
74 function assertIPv4Arg ($argname, $ok_if_empty = FALSE)
75 {
76 assertStringArg ($argname, $ok_if_empty);
77 if (!empty ($_REQUEST[$argname]) and long2ip (ip2long ($_REQUEST[$argname])) !== $_REQUEST[$argname])
78 {
79 showError ("IPv4 address validation failed for value '" . $_REQUEST[$argname] . "'", __FUNCTION__);
80 die();
81 }
82 }
83
84 function handler_portmap ($tabno)
85 {
86 switch ($tabno)
87 {
88 case 'default':
89 renderPortMap (FALSE);
90 break;
91 case 'edit':
92 renderPortMap (TRUE);
93 break;
94 default:
95 showError ("Invalid tab '${tabno}' requested.", __FUNCTION__);
96 }
97 }
98
99 ?>