r1803 + move assertion functions to where they are mostly used (ophandlers.php)
[racktables] / inc / navigation.php
1 <?php
2 /*
3 *
4 * This file implements generic navigation for RackTables.
5 *
6 */
7
8 $page = array();
9 $tab = array();
10 $trigger = array();
11 $ophandler = array();
12 $tabhandler = array();
13
14 $page['index']['title'] = 'Main page';
15 $page['index']['handler'] = 'renderIndex';
16
17 $page['rackspace']['title'] = 'Rackspace';
18 $page['rackspace']['parent'] = 'index';
19 $tab['rackspace']['default'] = 'Browse';
20 $tab['rackspace']['history'] = 'History';
21 $tab['rackspace']['firstrow'] = 'Click me!';
22 $trigger['rackspace']['firstrow'] = 'trigger_emptyRackspace';
23 $tabhandler['rackspace']['default'] = 'renderRackspace';
24 $tabhandler['rackspace']['history'] = 'renderRackspaceHistory';
25 $tabhandler['rackspace']['firstrow'] = 'renderFirstRowForm';
26 $tabextraclass['rackspace']['firstrow'] = 'attn';
27
28 $page['objects']['title'] = 'Objects';
29 $page['objects']['parent'] = 'index';
30 $tab['objects']['default'] = 'View';
31 $tab['objects']['newobj'] = 'Add an object';
32 $tab['objects']['newmulti'] = 'Add multiple objects';
33 $tabhandler['objects']['default'] = 'renderObjectGroupSummary';
34 $tabhandler['objects']['newobj'] = 'renderNewObjectForm';
35 $tabhandler['objects']['newmulti'] = 'renderAddMultipleObjectsForm';
36
37 $page['row']['title_handler'] = 'dynamic_title_row';
38 $page['row']['bypass'] = 'row_id';
39 $page['row']['bypass_type'] = 'uint';
40 $page['row']['parent'] = 'rackspace';
41 $tab['row']['default'] = 'View';
42 $tab['row']['newrack'] = 'Add new rack';
43 $tabhandler['row']['default'] = 'renderRow';
44 $tabhandler['row']['newrack'] = 'renderNewRackForm';
45
46 $page['rack']['title_handler'] = 'dynamic_title_rack';
47 $page['rack']['bypass'] = 'rack_id';
48 $page['rack']['bypass_type'] = 'uint';
49 $page['rack']['parent'] = 'row';
50 $tab['rack']['default'] = 'View';
51 $tab['rack']['edit'] = 'Properties';
52 $tab['rack']['design'] = 'Design';
53 $tab['rack']['problems'] = 'Problems';
54 $tabhandler['rack']['default'] = 'renderRackPage';
55 $tabhandler['rack']['edit'] = 'renderEditRackForm';
56 $tabhandler['rack']['design'] = 'renderRackDesign';
57 $tabhandler['rack']['problems'] = 'renderRackProblems';
58
59 $page['objgroup']['title_handler'] = 'dynamic_title_objgroup';
60 $page['objgroup']['handler'] = 'renderObjectGroup';
61 $page['objgroup']['bypass'] = 'group_id';
62 $page['objgroup']['bypass_type'] = 'uint';
63 $page['objgroup']['parent'] = 'objects';
64
65 $page['object']['title_handler'] = 'dynamic_title_object';
66 $page['object']['bypass'] = 'object_id';
67 $page['object']['bypass_type'] = 'uint';
68 $page['object']['parent'] = 'objgroup';
69 $page['object']['tagloader'] = 'loadRackObjectTags';
70 $page['object']['autotagloader'] = 'loadRackObjectAutoTags';
71 $tab['object']['default'] = 'View';
72 $tab['object']['edit'] = 'Properties';
73 $tab['object']['rackspace'] = 'Rackspace';
74 $tab['object']['ports'] = 'Ports';
75 $tab['object']['network'] = 'IPv4';
76 $tab['object']['portfwrd'] = 'NATv4';
77 $tab['object']['switchvlans'] = 'Live VLANs';
78 $tab['object']['snmpportfinder'] = 'SNMP port finder';
79 $tab['object']['slb'] = '[SLB]';
80 $tab['object']['lvsconfig'] = 'LVS configuration';
81 $tab['object']['autoports'] = 'AutoPorts';
82 $tab['object']['tags'] = 'Tags';
83 $tabhandler['object']['default'] = 'renderRackObject';
84 $tabhandler['object']['edit'] = 'renderEditObjectForm';
85 $tabhandler['object']['rackspace'] = 'renderRackSpaceForObject';
86 $tabhandler['object']['ports'] = 'renderPortsForObject';
87 $tabhandler['object']['network'] = 'renderNetworkForObject';
88 $tabhandler['object']['portfwrd'] = 'renderIPAddressPortForwarding';
89 $tabhandler['object']['switchvlans'] = 'renderVLANMembership';
90 $tabhandler['object']['snmpportfinder'] = 'renderSNMPPortFinder';
91 $tabhandler['object']['lvsconfig'] = 'renderLVSConfig';
92 $tabhandler['object']['autoports'] = 'renderAutoPortsForm';
93 $tabhandler['object']['tags'] = 'renderObjectTags';
94 $tabextraclass['object']['snmpportfinder'] = 'attn';
95 $tabextraclass['object']['autoports'] = 'attn';
96 $trigger['object']['network'] = 'trigger_ipv4';
97 $trigger['object']['portfwrd'] = 'trigger_natv4';
98 $trigger['object']['switchvlans'] = 'trigger_switchvlans';
99 $trigger['object']['snmpportfinder'] = 'trigger_snmpportfinder';
100 $trigger['object']['slb'] = 'trigger_natv4';
101 $trigger['object']['lvsconfig'] = 'trigger_lvsconfig';
102 $trigger['object']['autoports'] = 'trigger_autoports';
103 $trigger['object']['tags'] = 'trigger_tags';
104 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
105 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
106 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
107 $ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
108 $ophandler['object']['ports']['unlinkPort'] = 'unlinkPortForObject';
109 $ophandler['object']['ports']['addMultiPorts'] = 'addMultiPorts';
110 $ophandler['object']['ports']['useup'] = 'useupPort';
111 $ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObject';
112 $ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
113 $ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
114 $ophandler['object']['edit']['del'] = 'resetAttrValue';
115 $ophandler['object']['edit']['upd'] = 'updateAttrValues';
116 $ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
117 $ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
118 $ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
119 $ophandler['object']['autoports']['generate'] = 'generateAutoPorts';
120 $ophandler['object']['tags']['save'] = 'saveObjectTags';
121
122 $page['ipv4space']['title'] = 'IPv4 space';
123 $page['ipv4space']['parent'] = 'index';
124 $tab['ipv4space']['default'] = 'Browse';
125 $tab['ipv4space']['newrange'] = 'Manage';
126 $tabhandler['ipv4space']['default'] = 'renderAddressspace';
127 $tabhandler['ipv4space']['newrange'] = 'renderAddNewRange';
128 $ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
129 $ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
130
131 $page['iprange']['title_handler'] = 'dynamic_title_iprange';
132 $page['iprange']['parent'] = 'ipv4space';
133 $page['iprange']['bypass'] = 'id';
134 $page['iprange']['bypass_type'] = 'uint';
135 $tab['iprange']['default'] = 'Browse';
136 $tab['iprange']['properties'] = 'Properties';
137 $tab['iprange']['liveptr'] = 'Live PTR';
138 $tabhandler['iprange']['default'] = 'renderIPRange';
139 $tabhandler['iprange']['properties'] = 'renderIPRangeProperties';
140 $tabhandler['iprange']['liveptr'] = 'renderLivePTR';
141 $ophandler['iprange']['properties']['editRange'] = 'editRange';
142 $ophandler['iprange']['liveptr']['import'] = 'importPTRData';
143
144 $page['ipaddress']['title_handler'] = 'dynamic_title_ipaddress';
145 $page['ipaddress']['parent'] = 'iprange';
146 $page['ipaddress']['bypass'] = 'ip';
147 $tab['ipaddress']['default'] = 'Browse';
148 $tab['ipaddress']['properties'] = 'Properties';
149 $tab['ipaddress']['assignment'] = 'Allocation';
150 $tab['ipaddress']['editrslist'] = '[SLB real servers]';
151 $tabhandler['ipaddress']['default'] = 'renderIPAddress';
152 $tabhandler['ipaddress']['properties'] = 'renderIPAddressProperties';
153 $tabhandler['ipaddress']['assignment'] = 'renderIPAddressAssignment';
154 $ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
155 $ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
156 $ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
157 $ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
158
159 $page['ipv4slb']['title'] = 'IPv4 SLB';
160 $page['ipv4slb']['parent'] = 'index';
161 $page['ipv4slb']['handler'] = 'renderIPv4SLB';
162
163 $page['vservices']['title'] = 'Virtual services';
164 $page['vservices']['parent'] = 'ipv4slb';
165 $tab['vservices']['default'] = 'View';
166 $tab['vservices']['edit'] = 'Edit';
167 $tabhandler['vservices']['default'] = 'renderVSList';
168 $tabhandler['vservices']['edit'] = 'renderVSListEditForm';
169 $ophandler['vservices']['edit']['add'] = 'addVService';
170 $ophandler['vservices']['edit']['del'] = 'deleteVService';
171 $ophandler['vservices']['edit']['upd'] = 'updateVService';
172
173 $page['vservice']['title_handler'] = 'dynamic_title_vservice';
174 $page['vservice']['parent'] = 'vservices';
175 $page['vservice']['bypass'] = 'id';
176 $page['vservice']['bypass_type'] = 'uint';
177 $tab['vservice']['default'] = 'View';
178 $tab['vservice']['edit'] = '[Edit]';
179 $tab['vservice']['editlblist'] = '[Load balancers]';
180 $tabhandler['vservice']['default'] = 'renderVirtualService';
181
182 $page['rspools']['title'] = 'RS pools';
183 $page['rspools']['parent'] = 'ipv4slb';
184 $tab['rspools']['default'] = 'View';
185 $tab['rspools']['edit'] = 'Edit';
186 $tabhandler['rspools']['default'] = 'renderRSPoolList';
187 $tabhandler['rspools']['edit'] = 'editRSPools';
188 $ophandler['rspools']['edit']['add'] = 'addRSPool';
189 $ophandler['rspools']['edit']['del'] = 'deleteRSPool';
190 $ophandler['rspools']['edit']['upd'] = 'updateRSPool';
191
192 $page['rspool']['title_handler'] = 'dynamic_title_rspool';
193 $page['rspool']['parent'] = 'rspools';
194 $page['rspool']['bypass'] = 'id';
195 $page['rspool']['bypass_type'] = 'uint';
196 $tab['rspool']['default'] = 'View';
197 $tab['rspool']['edit'] = '[Edit]';
198 $tab['rspool']['editlblist'] = 'Load Balancers';
199 $tab['rspool']['editrslist'] = 'RS list';
200 $tab['rspool']['rsinservice'] = 'RS in service';
201 $trigger['rspool']['rsinservice'] = 'trigger_poolrscount';
202 $tabhandler['rspool']['default'] = 'renderRSPool';
203 $tabhandler['rspool']['editrslist'] = 'renderRSPoolServerForm';
204 $tabhandler['rspool']['editlblist'] = 'renderRSPoolLBForm';
205 $tabhandler['rspool']['rsinservice'] = 'renderRSPoolRSInServiceForm';
206 $ophandler['rspool']['editrslist']['addRS'] = 'addRealServer';
207 $ophandler['rspool']['editrslist']['delRS'] = 'deleteRealServer';
208 $ophandler['rspool']['editrslist']['updRS'] = 'updateRealServer';
209 $ophandler['rspool']['editrslist']['addMany'] = 'addRealServers';
210 $ophandler['rspool']['editlblist']['addLB'] = 'addLoadBalancer';
211 $ophandler['rspool']['editlblist']['delLB'] = 'deleteLoadBalancer';
212 $ophandler['rspool']['editlblist']['updLB'] = 'updateLoadBalancer';
213 $ophandler['rspool']['rsinservice']['upd'] = 'updateRSInService';
214
215 $page['rservers']['title'] = 'Real servers';
216 $page['rservers']['parent'] = 'ipv4slb';
217 $page['rservers']['handler'] = 'renderRealServerList';
218
219 $page['lbs']['title'] = 'Load balancers';
220 $page['lbs']['parent'] = 'ipv4slb';
221 $page['lbs']['handler'] = 'renderLBList';
222
223 $page['search']['title_handler'] = 'dynamic_title_search';
224 $page['search']['handler'] = 'renderSearchResults';
225 $page['search']['parent'] = 'index';
226 $page['search']['bypass'] = 'q';
227
228 $page['config']['title'] = 'Configuration';
229 $page['config']['handler'] = 'renderConfigMainpage';
230 $page['config']['parent'] = 'index';
231
232 $page['accounts']['title'] = 'Accounts';
233 $page['accounts']['parent'] = 'config';
234 $tab['accounts']['default'] = 'View';
235 $tab['accounts']['edit'] = 'Change';
236 $tabhandler['accounts']['default'] = 'renderAccounts';
237 $tabhandler['accounts']['edit'] = 'renderAccountsEditForm';
238 $ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
239 $ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
240 $ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
241 $ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
242
243 $page['perms']['title'] = 'Permissions';
244 $page['perms']['parent'] = 'config';
245 $tab['perms']['default'] = 'View';
246 $tab['perms']['edit'] = 'Change';
247 $tabhandler['perms']['default'] = 'renderPermissions';
248 $tabhandler['perms']['edit'] = 'renderPermissionsEditForm';
249 $ophandler['perms']['edit']['revoke'] = 'revokePermission';
250 $ophandler['perms']['edit']['grant'] = 'grantPermission';
251
252 $page['portmap']['title'] = 'Port compatibility map';
253 $page['portmap']['parent'] = 'config';
254 $tab['portmap']['default'] = 'View';
255 $tab['portmap']['edit'] = 'Change';
256 $tabhandler['portmap']['default'] = 'renderPortMapViewer';
257 $tabhandler['portmap']['edit'] = 'renderPortMapEditor';
258 $ophandler['portmap']['edit']['save'] = 'savePortMap';
259
260 $page['attrs']['title'] = 'Attributes';
261 $page['attrs']['parent'] = 'config';
262 $tab['attrs']['default'] = 'View';
263 $tab['attrs']['editattrs'] = 'Edit attributes';
264 $tab['attrs']['editmap'] = 'Edit map';
265 $tabhandler['attrs']['default'] = 'renderAttributes';
266 $tabhandler['attrs']['editattrs'] = 'renderEditAttributesForm';
267 $tabhandler['attrs']['editmap'] = 'renderEditAttrMapForm';
268 $ophandler['attrs']['editattrs']['add'] = 'createAttribute';
269 $ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
270 $ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
271 $ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
272 $ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
273
274 $page['dict']['title'] = 'Dictionary';
275 $page['dict']['parent'] = 'config';
276 $tab['dict']['default'] = 'View';
277 $tab['dict']['edit'] = 'Edit words';
278 $tab['dict']['chapters'] = 'Manage chapters';
279 $tabhandler['dict']['default'] = 'renderDictionary';
280 $tabhandler['dict']['edit'] = 'renderDictionaryEditor';
281 $tabhandler['dict']['chapters'] = 'renderChaptersEditor';
282 $ophandler['dict']['edit']['del'] = 'reduceDictionary';
283 $ophandler['dict']['edit']['upd'] = 'updateDictionary';
284 $ophandler['dict']['edit']['add'] = 'supplementDictionary';
285 $ophandler['dict']['chapters']['del'] = 'delChapter';
286 $ophandler['dict']['chapters']['upd'] = 'updateChapter';
287 $ophandler['dict']['chapters']['add'] = 'addChapter';
288
289 $page['ui']['title'] = 'User interface';
290 $page['ui']['parent'] = 'config';
291 $tab['ui']['default'] = 'View';
292 $tab['ui']['edit'] = 'Change';
293 $tab['ui']['reset'] = 'Reset';
294 $tabhandler['ui']['default'] = 'renderUIConfig';
295 $tabhandler['ui']['edit'] = 'renderUIConfigEditForm';
296 $tabhandler['ui']['reset'] = 'renderUIResetForm';
297 $ophandler['ui']['edit']['upd'] = 'updateUI';
298 $ophandler['ui']['reset']['go'] = 'resetUIConfig';
299
300 $page['tagtree']['title'] = 'Tag tree';
301 $page['tagtree']['parent'] = 'config';
302 $tab['tagtree']['default'] = 'View';
303 $tab['tagtree']['edit'] = 'Change';
304 $tabhandler['tagtree']['default'] = 'renderTagTree';
305 $tabhandler['tagtree']['edit'] = 'renderTagTreeEditor';
306
307 $page['reports']['title'] = 'Reports';
308 $page['reports']['parent'] = 'index';
309 $tab['reports']['default'] = 'View';
310 $tabhandler['reports']['default'] = 'renderReportSummary';
311
312 // This function returns array if page numbers leading to the target page
313 // plus page number of target page itself. The first element is the target
314 // page number and the last element is the index page number.
315 function getPath ($targetno)
316 {
317 global $page;
318 $path = array();
319 // Recursion breaks at first parentless page.
320 if (!isset ($page[$targetno]['parent']))
321 $path = array ($targetno);
322 else
323 {
324 $path = getPath ($page[$targetno]['parent']);
325 $path[] = $targetno;
326 }
327 return $path;
328 }
329
330 function showPathAndSearch ($pageno)
331 {
332 global $root, $page;
333 // Path.
334 echo "<td class=activemenuitem width='99%'>" . getConfigVar ('enterprise');
335 $path = getPath ($pageno);
336 foreach ($path as $no)
337 {
338 $title['params'] = array();
339 if (isset ($page[$no]['title']))
340 $title['name'] = $page[$no]['title'];
341 elseif (isset ($page[$no]['title_handler']))
342 $title = $page[$no]['title_handler']($no);
343 else
344 $title['name'] = '[N/A]';
345 echo ": <a href='${root}?page=${no}";
346 foreach ($title['params'] as $param_name => $param_value)
347 echo "&${param_name}=${param_value}";
348 echo "'>" . $title['name'] . "</a>";
349 }
350 echo "</td>";
351 // Search form.
352 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
353 echo "<form method=get action='${root}'><td>";
354 echo '<input type=hidden name=page value=search>';
355 // This input will be the first, if we don't add ports or addresses.
356 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
357 }
358
359 function getTitle ($pageno, $tabno)
360 {
361 global $page;
362 if (isset ($page[$pageno]['title']))
363 return $page[$pageno]['title'];
364 elseif (isset ($page[$pageno]['title_handler']))
365 {
366 $tmp = $page[$pageno]['title_handler']($pageno);
367 return $tmp['name'];
368 }
369 else
370 return getConfigVar ('enterprise');
371 }
372
373 function showTabs ($pageno, $tabno)
374 {
375 global $tab, $root, $page, $remote_username, $trigger, $tabextraclass;
376 if (!isset ($tab[$pageno]['default']))
377 return;
378 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
379 foreach ($tab[$pageno] as $tabidx => $tabtitle)
380 {
381 // Hide forbidden tabs.
382 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
383 continue;
384 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
385 if
386 (
387 isset ($trigger[$pageno][$tabidx]) &&
388 $trigger[$pageno][$tabidx] () != TRUE
389 )
390 continue;
391 $class = ($tabidx == $tabno) ? 'current' : 'std';
392 $extra = (isset ($tabextraclass[$pageno][$tabidx])) ? $tabextraclass[$pageno][$tabidx] : '';
393 echo "<li><a class=${class}{$extra}";
394 echo " href='${root}?page=${pageno}&tab=${tabidx}";
395 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
396 {
397 $bpname = $page[$pageno]['bypass'];
398 $bpval = $_REQUEST[$bpname];
399 echo "&${bpname}=${bpval}";
400 }
401 echo "'>${tabtitle}</a></li>\n";
402 }
403 echo "</ul></div></td>\n";
404 }
405
406 // This function returns pages, which are direct children of the requested
407 // page and are accessible by the current user.
408 function getDirectChildPages ($pageno)
409 {
410 global $page, $remote_username;
411 $children = array();
412 foreach ($page as $cpageno => $cpage)
413 if
414 (
415 isset ($cpage['parent']) and
416 $cpage['parent'] == $pageno and
417 authorized ($remote_username, $cpageno, 'default') == TRUE
418 )
419 $children[$cpageno] = $cpage;
420 return $children;
421 }
422
423 function getAllChildPages ($parent)
424 {
425 global $page;
426 // Array pointer is global, so if we don't create local copies of
427 // the global array, we can't advance any more after nested call
428 // of getAllChildPages returns.
429 $mypage = $page;
430 $mykids = array();
431 foreach ($mypage as $ctitle => $cpage)
432 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
433 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
434 return $mykids;
435 }
436
437 ?>