r1304 + new feature: reset UI configuration to defaults
[racktables] / inc / pagehandlers.php
CommitLineData
b325120a 1<?php
e673ee24
DO
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.
10function 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.
36function 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
55function 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
74function 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
90function 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
113function 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;
5681ac08
DO
136 case 'switchvlans':
137 renderVLANMembership($_REQUEST['object_id']);
138 break;
9c67f713
DO
139 case 'snmpportfinder':
140 renderSNMPPortFinder($_REQUEST['object_id']);
141 break;
e673ee24
DO
142 default:
143 showError ("Invalid tab '${tabno}' requested in handler_object().");
144 }
145}
146
147function 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
165function handler_objgroup ()
166{
167 assertUIntArg ('group_id');
168 renderObjectGroup ($_REQUEST['group_id']);
169}
170
171function handler_rackspace ($tabno)
172{
173 switch ($tabno)
174 {
175 case 'default':
176 renderRackspace();
177 break;
178 case 'history':
179 renderRackspaceHistory ();
180 break;
181 default:
182 showError ("Invalid tab '${tabno}' requested in handler_rackspace().");
183 }
184}
185
186function handler_ipv4space ($tabno)
187{
188 switch ($tabno)
189 {
190 case 'default':
191 renderAddressspace();
192 break;
193 case 'newrange':
194 renderAddNewRange();
195 break;
196 default:
197 showError ("Invalid tab '${tabno}' requested in handler_ipv4space().");
198 }
199}
200
201function handler_iprange ($tabno)
202{
203 switch ($tabno)
204 {
205 case 'default':
206 renderIPRange();
207 break;
208 case 'properties':
209 renderIPRangeProperties();
210 break;
211 default:
212 showError ("Invalid tab '${tabno}' requested in handler_iprange().");
213 }
214}
215
216function handler_ipaddress ($tabno)
217{
218 switch ($tabno)
219 {
220 case 'default':
221 renderIPAddress();
222 break;
223 case 'properties':
224 renderIPAddressProperties();
225 break;
226 case 'assignment':
227 renderIPAddressAssignment();
228 break;
229 default:
230 showError ("Invalid tab '${tabno}' requested in handler_ipaddress().");
231 }
232}
233
234function handler_search ($tabno)
235{
236 renderSearchResults();
237}
238
239function handler_config ($tabno)
240{
241 switch ($tabno)
242 {
243 case 'default':
244 renderConfigMainpage();
245 break;
246 default:
247 showError ("Invalid tab '${tabno}' requested in handler_config().");
248 }
249}
250
251function handler_accounts ($tabno)
252{
253 switch ($tabno)
254 {
255 case 'default':
256 renderAccounts();
257 break;
258 case 'edit':
259 renderAccountsEditForm();
260 break;
261 default:
262 showError ("Invalid tab '${tabno}' requested in handler_accounts().");
263 }
264}
265
266function handler_perms ($tabno)
267{
268 switch ($tabno)
269 {
270 case 'default':
271 renderPermissions();
272 break;
273 case 'edit':
274 renderPermissionsEditForm();
275 break;
276 default:
277 showError ("Invalid tab '${tabno}' requested in handler_perms().");
278 }
279}
280
e673ee24
DO
281function handler_ui ($tabno)
282{
283 switch ($tabno)
284 {
285 case 'default':
286 renderUIConfig();
287 break;
4fe32e78
DY
288 case 'edit':
289 renderUIConfigEditForm();
290 break;
b07f617c
DO
291 case 'reset':
292 renderUIResetForm();
293 break;
e673ee24
DO
294 default:
295 showError ("Invalid tab '${tabno}' requested in handler_ui().");
296 }
297}
298
299function handler_portmap ($tabno)
300{
301 switch ($tabno)
302 {
303 case 'default':
304 renderPortMap (FALSE);
305 break;
306 case 'edit':
307 renderPortMap (TRUE);
308 break;
309 default:
310 showError ("Invalid tab '${tabno}' requested in handler_portmap().");
311 }
312}
313
314function handler_dict ($tabno)
315{
316 switch ($tabno)
317 {
318 case 'default':
319 renderDictionary();
320 break;
321 case 'edit':
322 renderDictionaryEditor();
323 break;
324 case 'chapters':
325 renderChaptersEditor();
326 break;
327 default:
328 showError ("Invalid tab '${tabno}' requested in handler_dict().");
329 }
330}
331
332function handler_attrs ($tabno)
333{
334 switch ($tabno)
335 {
336 case 'default':
337 renderAttributes();
338 break;
339 case 'editattrs':
340 renderEditAttributesForm ();
341 break;
342 case 'editmap':
343 renderEditAttrMapForm ();
344 break;
345 default:
346 showError ("Invalid tab '${tabno}' requested in handler_attrs().");
347 }
348}
349
350function handler_reports ($tabno)
351{
352 switch ($tabno)
353 {
354 case 'default':
355 renderReportSummary();
356 break;
357 default:
358 showError ("Invalid tab '${tabno}' requested in handler_reports().");
359 }
360}
361
ae545907
DO
362function handler_help ($tabno)
363{
e3758526 364 renderHelpTab ($tabno);
ae545907
DO
365}
366
e673ee24 367?>