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