d4d220a7f4c6aeede0bff412d883d172102b1789
[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.");
15 die();
16 }
17 if (!is_numeric ($_REQUEST[$argname]))
18 {
19 showError ("Parameter '${argname}' is not a number.");
20 die();
21 }
22 if ($_REQUEST[$argname] < 0)
23 {
24 showError ("Parameter '${argname}' is less than zero.");
25 die();
26 }
27 if (!$allow_zero and $_REQUEST[$argname] == 0)
28 {
29 showError ("Parameter '${argname}' is equal to zero.");
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.");
41 die();
42 }
43 if (!is_string ($_REQUEST[$argname]))
44 {
45 showError ("Parameter '${argname}' is not a string.");
46 die();
47 }
48 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
49 {
50 showError ("Parameter '${argname}' is an empty string.");
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.");
60 die();
61 }
62 if (!is_string ($_REQUEST[$argname]) or $_REQUEST[$argname] != 'on')
63 {
64 showError ("Parameter '${argname}' is not a string.");
65 die();
66 }
67 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
68 {
69 showError ("Parameter '${argname}' is an empty string.");
70 die();
71 }
72 }
73
74 function handler_row ($tabno)
75 {
76 assertUIntArg ('row_id');
77 switch ($tabno)
78 {
79 case 'default':
80 renderRow ($_REQUEST['row_id']);
81 break;
82 case 'newrack':
83 renderNewRackForm ($_REQUEST['row_id']);
84 break;
85 default:
86 showError ("Invalid tab '${tabno}' requested in handler_row().");
87 }
88 }
89
90 function handler_rack ($tabno)
91 {
92 assertUIntArg ('rack_id');
93 switch ($tabno)
94 {
95 case 'default':
96 // FIXME: add tab renderer instead of table generator
97 renderRackPage ($_REQUEST['rack_id']);
98 break;
99 case 'problems':
100 renderRackProblems ($_REQUEST['rack_id']);
101 break;
102 case 'design':
103 renderRackDesign ($_REQUEST['rack_id']);
104 break;
105 case 'edit':
106 renderEditRackForm ($_REQUEST['rack_id']);
107 break;
108 default:
109 showError ("Invalid tab '${tabno}' requested in handler_rack().");
110 }
111 }
112
113 function handler_object ($tabno)
114 {
115 assertUIntArg ('object_id');
116 switch ($tabno)
117 {
118 case 'default':
119 renderRackObject ($_REQUEST['object_id']);
120 break;
121 case 'rackspace':
122 renderRackSpaceForObject ($_REQUEST['object_id']);
123 break;
124 case 'ports':
125 renderPortsForObject ($_REQUEST['object_id']);
126 break;
127 case 'network':
128 renderNetworkForObject ($_REQUEST['object_id']);
129 break;
130 case 'edit':
131 renderEditObjectForm ($_REQUEST['object_id']);
132 break;
133 case 'portfwrd':
134 renderIPAddressPortForwarding($_REQUEST['object_id']);
135 break;
136 case 'switchvlans':
137 renderVLANMembership($_REQUEST['object_id']);
138 break;
139 case 'snmpportfinder':
140 renderSNMPPortFinder($_REQUEST['object_id']);
141 break;
142 default:
143 showError ("Invalid tab '${tabno}' requested in handler_object().");
144 }
145 }
146
147 function handler_objects ($tabno)
148 {
149 switch ($tabno)
150 {
151 case 'default':
152 renderObjectGroupSummary();
153 break;
154 case 'newobj':
155 renderNewObjectForm();
156 break;
157 case 'newmulti':
158 renderAddMultipleObjectsForm();
159 break;
160 default:
161 showError ("Invalid tab '${tabno}' requested in handler_objects().");
162 }
163 }
164
165 function handler_objgroup ()
166 {
167 assertUIntArg ('group_id');
168 renderObjectGroup ($_REQUEST['group_id']);
169 }
170
171 function handler_rackspace ($tabno)
172 {
173 switch ($tabno)
174 {
175 case 'default':
176 renderRackspace();
177 break;
178 case 'history':
179 renderRackspaceHistory ();
180 break;
181 case 'firstrow':
182 renderFirstRowForm ();
183 break;
184 default:
185 showError ("Invalid tab '${tabno}' requested in handler_rackspace().");
186 }
187 }
188
189 function handler_ipv4space ($tabno)
190 {
191 switch ($tabno)
192 {
193 case 'default':
194 renderAddressspace();
195 break;
196 case 'newrange':
197 renderAddNewRange();
198 break;
199 default:
200 showError ("Invalid tab '${tabno}' requested in handler_ipv4space().");
201 }
202 }
203
204 function handler_iprange ($tabno)
205 {
206 switch ($tabno)
207 {
208 case 'default':
209 renderIPRange();
210 break;
211 case 'properties':
212 renderIPRangeProperties();
213 break;
214 default:
215 showError ("Invalid tab '${tabno}' requested in handler_iprange().");
216 }
217 }
218
219 function handler_ipaddress ($tabno)
220 {
221 switch ($tabno)
222 {
223 case 'default':
224 renderIPAddress();
225 break;
226 case 'properties':
227 renderIPAddressProperties();
228 break;
229 case 'assignment':
230 renderIPAddressAssignment();
231 break;
232 default:
233 showError ("Invalid tab '${tabno}' requested in handler_ipaddress().");
234 }
235 }
236
237 function handler_search ($tabno)
238 {
239 renderSearchResults();
240 }
241
242 function handler_config ($tabno)
243 {
244 switch ($tabno)
245 {
246 case 'default':
247 renderConfigMainpage();
248 break;
249 default:
250 showError ("Invalid tab '${tabno}' requested in handler_config().");
251 }
252 }
253
254 function handler_accounts ($tabno)
255 {
256 switch ($tabno)
257 {
258 case 'default':
259 renderAccounts();
260 break;
261 case 'edit':
262 renderAccountsEditForm();
263 break;
264 default:
265 showError ("Invalid tab '${tabno}' requested in handler_accounts().");
266 }
267 }
268
269 function handler_perms ($tabno)
270 {
271 switch ($tabno)
272 {
273 case 'default':
274 renderPermissions();
275 break;
276 case 'edit':
277 renderPermissionsEditForm();
278 break;
279 default:
280 showError ("Invalid tab '${tabno}' requested in handler_perms().");
281 }
282 }
283
284 function handler_ui ($tabno)
285 {
286 switch ($tabno)
287 {
288 case 'default':
289 renderUIConfig();
290 break;
291 case 'edit':
292 renderUIConfigEditForm();
293 break;
294 case 'reset':
295 renderUIResetForm();
296 break;
297 default:
298 showError ("Invalid tab '${tabno}' requested in handler_ui().");
299 }
300 }
301
302 function handler_portmap ($tabno)
303 {
304 switch ($tabno)
305 {
306 case 'default':
307 renderPortMap (FALSE);
308 break;
309 case 'edit':
310 renderPortMap (TRUE);
311 break;
312 default:
313 showError ("Invalid tab '${tabno}' requested in handler_portmap().");
314 }
315 }
316
317 function handler_dict ($tabno)
318 {
319 switch ($tabno)
320 {
321 case 'default':
322 renderDictionary();
323 break;
324 case 'edit':
325 renderDictionaryEditor();
326 break;
327 case 'chapters':
328 renderChaptersEditor();
329 break;
330 default:
331 showError ("Invalid tab '${tabno}' requested in handler_dict().");
332 }
333 }
334
335 function handler_attrs ($tabno)
336 {
337 switch ($tabno)
338 {
339 case 'default':
340 renderAttributes();
341 break;
342 case 'editattrs':
343 renderEditAttributesForm ();
344 break;
345 case 'editmap':
346 renderEditAttrMapForm ();
347 break;
348 default:
349 showError ("Invalid tab '${tabno}' requested in handler_attrs().");
350 }
351 }
352
353 function handler_reports ($tabno)
354 {
355 switch ($tabno)
356 {
357 case 'default':
358 renderReportSummary();
359 break;
360 default:
361 showError ("Invalid tab '${tabno}' requested in handler_reports().");
362 }
363 }
364
365 function handler_help ($tabno)
366 {
367 renderHelpTab ($tabno);
368 }
369
370 ?>