r1422 + check bypass arg type before calling the tab handler
[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();
13
e673ee24
DO
14$page['index']['title'] = 'static_title';
15$page['index']['handler'] = 'renderIndex';
16
17$page['rackspace']['title'] = 'static_title';
18$page['rackspace']['handler'] = 'handler_rackspace';
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';
e673ee24
DO
24
25$page['objects']['title'] = 'static_title';
26$page['objects']['handler'] = 'handler_objects';
27$page['objects']['parent'] = 'index';
28$tab['objects']['default'] = 'View';
29$tab['objects']['newobj'] = 'Add an object';
30$tab['objects']['newmulti'] = 'Add multiple objects';
31
32$page['row']['title'] = 'dynamic_title_row';
33$page['row']['handler'] = 'handler_row';
34$page['row']['bypass'] = 'row_id';
35$page['row']['parent'] = 'rackspace';
36$tab['row']['default'] = 'View';
37$tab['row']['newrack'] = 'Add new rack';
38
39$page['rack']['title'] = 'dynamic_title_rack';
40$page['rack']['handler'] = 'handler_rack';
41$page['rack']['bypass'] = 'rack_id';
42$page['rack']['parent'] = 'row';
43$tab['rack']['default'] = 'View';
44$tab['rack']['edit'] = 'Properties';
45$tab['rack']['design'] = 'Design';
46$tab['rack']['problems'] = 'Problems';
beee6141
DO
47$helptab['rack']['design'] = 'rackspace';
48$helptab['rack']['problems'] = 'rackspace';
e673ee24
DO
49
50$page['objgroup']['title'] = 'dynamic_title_objgroup';
51$page['objgroup']['handler'] = 'handler_objgroup';
52$page['objgroup']['bypass'] = 'group_id';
53$page['objgroup']['parent'] = 'objects';
54
55$page['object']['title'] = 'dynamic_title_object';
e673ee24 56$page['object']['bypass'] = 'object_id';
3bebaebd 57$page['object']['bypass_type'] = 'uint';
e673ee24
DO
58$page['object']['parent'] = 'objgroup';
59$tab['object']['default'] = 'View';
60$tab['object']['edit'] = 'Properties';
61$tab['object']['rackspace'] = 'Rackspace';
62$tab['object']['ports'] = 'Ports';
63$tab['object']['network'] = 'IPv4';
737f9ac1 64$tab['object']['portfwrd'] = 'NATv4';
a684aa6f 65$tab['object']['switchvlans'] = 'Live VLANs';
9c67f713 66$tab['object']['snmpportfinder'] = 'SNMP port finder';
e45a78d7
DO
67$tabhandler['object']['default'] = 'renderRackObject';
68$tabhandler['object']['edit'] = 'renderEditObjectForm';
69$tabhandler['object']['rackspace'] = 'renderRackSpaceForObject';
70$tabhandler['object']['ports'] = 'renderPortsForObject';
71$tabhandler['object']['network'] = 'renderNetworkForObject';
72$tabhandler['object']['portfwrd'] = 'renderIPAddressPortForwarding';
73$tabhandler['object']['switchvlans'] = 'renderVLANMembership';
74$tabhandler['object']['snmpportfinder'] = 'renderSNMPPortFinder';
bdd05c5d 75$helptab['object']['network'] = 'nets';
150fdd66 76$helptab['object']['ports'] = 'ports';
bdd05c5d
DO
77$helptab['object']['portfwrd'] = 'nets';
78$helptab['object']['rackspace'] = 'rackspace';
641fe9b0 79$trigger['object']['switchvlans'] = 'trigger_switchvlans';
9c67f713 80$trigger['object']['snmpportfinder'] = 'trigger_snmpportfinder';
e673ee24
DO
81$ophandler['object']['ports']['addPort'] = 'addPortForObject';
82$ophandler['object']['ports']['delPort'] = 'delPortFromObject';
83$ophandler['object']['ports']['editPort'] = 'editPortForObject';
84$ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
85$ophandler['object']['ports']['unlinkPort'] = 'unlinkPortForObject';
86$ophandler['object']['ports']['addMultiPorts'] = 'addMultiPorts';
87$ophandler['object']['ports']['useup'] = 'useupPort';
88$ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObject';
89$ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
90$ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
91$ophandler['object']['edit']['del'] = 'resetAttrValue';
0dfb8a2a 92$ophandler['object']['edit']['upd'] = 'updateAttrValues';
e673ee24
DO
93$ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
94$ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
95$ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
641fe9b0 96$ophandler['object']['switchvlans']['submit'] = 'updateVLANMembership';
e673ee24
DO
97
98$page['ipv4space']['title'] = 'static_title';
99$page['ipv4space']['handler'] = 'handler_ipv4space';
100$page['ipv4space']['parent'] = 'index';
101$tab['ipv4space']['default'] = 'Browse';
102$tab['ipv4space']['newrange'] = 'Manage ranges';
bdd05c5d
DO
103$helptab['ipv4space']['default'] = 'nets';
104$helptab['ipv4space']['newrange'] = 'nets';
e673ee24
DO
105$ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
106$ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
107
108$page['iprange']['title'] = 'dynamic_title_iprange';
109$page['iprange']['handler'] = 'handler_iprange';
110$page['iprange']['parent'] = 'ipv4space';
111$page['iprange']['bypass'] = 'id';
112$tab['iprange']['default'] = 'Browse';
113$tab['iprange']['properties'] = 'Properties';
bdd05c5d
DO
114$helptab['iprange']['default'] = 'nets';
115$helptab['iprange']['properties'] = 'nets';
e673ee24
DO
116$ophandler['iprange']['properties']['editRange'] = 'editRange';
117
118$page['ipaddress']['title'] = 'dynamic_title_ipaddress';
119$page['ipaddress']['handler'] = 'handler_ipaddress';
120$page['ipaddress']['parent'] = 'iprange';
121$page['ipaddress']['bypass'] = 'ip';
122$tab['ipaddress']['default'] = 'Browse';
123$tab['ipaddress']['properties'] = 'Properties';
124$tab['ipaddress']['assignment'] = 'Allocation';
bdd05c5d
DO
125$helptab['ipaddress']['default'] = 'nets';
126$helptab['ipaddress']['properties'] = 'nets';
127$helptab['ipaddress']['assignment'] = 'nets';
e673ee24
DO
128$ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
129$ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
130$ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
131$ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
132
133$page['search']['title'] = 'dynamic_title_search';
134$page['search']['handler'] = 'handler_search';
135$page['search']['parent'] = 'index';
136$page['search']['bypass'] = 'q';
137
138$page['config']['title'] = 'static_title';
139$page['config']['handler'] = 'handler_config';
140$page['config']['parent'] = 'index';
141
142$page['accounts']['title'] = 'static_title';
143$page['accounts']['handler'] = 'handler_accounts';
144$page['accounts']['parent'] = 'config';
145$tab['accounts']['default'] = 'View';
146$tab['accounts']['edit'] = 'Change';
147$ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
148$ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
149$ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
150$ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
151
152$page['perms']['title'] = 'static_title';
153$page['perms']['handler'] = 'handler_perms';
154$page['perms']['parent'] = 'config';
155$tab['perms']['default'] = 'View';
156$tab['perms']['edit'] = 'Change';
157$ophandler['perms']['edit']['revoke'] = 'revokePermission';
158$ophandler['perms']['edit']['grant'] = 'grantPermission';
159
160$page['portmap']['title'] = 'static_title';
161$page['portmap']['handler'] = 'handler_portmap';
162$page['portmap']['parent'] = 'config';
163$tab['portmap']['default'] = 'View';
164$tab['portmap']['edit'] = 'Change';
165$ophandler['portmap']['edit']['save'] = 'savePortMap';
166
167$page['attrs']['title'] = 'static_title';
168$page['attrs']['handler'] = 'handler_attrs';
169$page['attrs']['parent'] = 'config';
170$tab['attrs']['default'] = 'View';
171$tab['attrs']['editattrs'] = 'Edit attributes';
172$tab['attrs']['editmap'] = 'Edit map';
173$ophandler['attrs']['editattrs']['add'] = 'createAttribute';
174$ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
175$ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
176$ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
177$ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
178
179$page['dict']['title'] = 'static_title';
180$page['dict']['handler'] = 'handler_dict';
181$page['dict']['parent'] = 'config';
182$tab['dict']['default'] = 'View';
183$tab['dict']['edit'] = 'Edit words';
184$tab['dict']['chapters'] = 'Manage chapters';
185$ophandler['dict']['edit']['del'] = 'reduceDictionary';
186$ophandler['dict']['edit']['upd'] = 'updateDictionary';
187$ophandler['dict']['edit']['add'] = 'supplementDictionary';
188$ophandler['dict']['chapters']['del'] = 'delChapter';
189$ophandler['dict']['chapters']['upd'] = 'updateChapter';
190$ophandler['dict']['chapters']['add'] = 'addChapter';
191
192$page['ui']['title'] = 'static_title';
193$page['ui']['handler'] = 'handler_ui';
194$page['ui']['parent'] = 'config';
0a1b1268 195$tab['ui']['default'] = 'View';
4fe32e78 196$tab['ui']['edit'] = 'Change';
b07f617c 197$tab['ui']['reset'] = 'Reset';
4fe32e78 198$ophandler['ui']['edit']['upd'] = 'updateUI';
b07f617c 199$ophandler['ui']['reset']['go'] = 'resetUIConfig';
e673ee24
DO
200
201$page['reports']['title'] = 'static_title';
202$page['reports']['handler'] = 'handler_reports';
203$page['reports']['parent'] = 'index';
204$tab['reports']['default'] = 'View';
205
ae545907
DO
206$page['help']['title'] = 'static_title';
207$page['help']['handler'] = 'handler_help';
208$page['help']['parent'] = 'index';
beee6141 209$tab['help']['default'] = 'Welcome';
51ef5041 210$tab['help']['quickstart'] = 'Quick start';
beee6141
DO
211$tab['help']['workflow'] = 'Workflow';
212$tab['help']['rackspace'] = 'Rackspace';
213$tab['help']['objects'] = 'Objects';
bdd05c5d 214$tab['help']['nets'] = 'Networking';
0a1b1268
DO
215$tab['help']['auth'] = '[ User accounts & permissions ]';
216$tab['help']['dict'] = '[ Dictionary ]';
beee6141 217$tab['help']['ports'] = 'Ports and links';
0a1b1268 218$tab['help']['hacking'] = '[ Hacker\'s guide ]';
ae545907 219
e673ee24
DO
220// This function returns array if page numbers leading to the target page
221// plus page number of target page itself. The first element is the target
222// page number and the last element is the index page number.
223function getPath ($targetno)
224{
225 global $page;
226 $path = array();
227 // Recursion breaks at first parentless page.
228 if (!isset ($page[$targetno]['parent']))
229 $path = array ($targetno);
230 else
231 {
232 $path = getPath ($page[$targetno]['parent']);
233 $path[] = $targetno;
234 }
235 return $path;
236}
237
238function showPathAndSearch ($pageno)
239{
9c0b0016 240 global $root, $page;
e673ee24 241 // Path.
73635d32 242 echo "<td class=activemenuitem width='99%'>" . getConfigVar ('enterprise');
e673ee24
DO
243 if (isset ($page[$pageno]['title']))
244 {
245 $path = getPath ($pageno);
246 foreach ($path as $dummy => $no)
247 {
248 $title = $page[$no]['title']($no);
249 echo ": <a href='${root}?page=${no}";
250 foreach ($title['params'] as $param_name => $param_value)
251 echo "&${param_name}=${param_value}";
252 echo "'>" .$title['name'] . "</a>";
253 }
254 }
255 echo "</td>";
256 // Search form.
257 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
258 echo "<form method=get action='${root}'><td>";
259 echo '<input type=hidden name=page value=search>';
260 // This input will be the first, if we don't add ports or addresses.
261 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
262}
263
264function getTitle ($pageno, $tabno)
265{
9c0b0016
DO
266 global $page;
267 if (!isset ($page[$pageno]['title']))
268 return getConfigVar ('enterprise');
269 $tmp = $page[$pageno]['title']($pageno);
270 return $tmp['name'];
e673ee24
DO
271}
272
273function showTabs ($pageno, $tabno)
274{
641fe9b0 275 global $tab, $root, $page, $remote_username, $trigger;
e673ee24
DO
276 if (!isset ($tab[$pageno]['default']))
277 return;
278 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
279 foreach ($tab[$pageno] as $tabidx => $tabtitle)
280 {
281 // Hide forbidden tabs.
282 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
283 continue;
641fe9b0
DO
284 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
285 if
286 (
287 isset ($trigger[$pageno][$tabidx]) &&
288 $trigger[$pageno][$tabidx] () != TRUE
289 )
290 continue;
e673ee24
DO
291 echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
292 echo " href='${root}?page=${pageno}&tab=${tabidx}";
293 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
294 {
295 $bpname = $page[$pageno]['bypass'];
296 $bpval = $_REQUEST[$bpname];
297 echo "&${bpname}=${bpval}";
298 }
299 echo "'>${tabtitle}</a></li>\n";
300 }
ae9a3784 301 lookupHelpTopic ($pageno, $tabno);
e673ee24
DO
302 echo "</ul></div></td>\n";
303}
304
305// This function returns pages, which are direct children of the requested
306// page and are accessible by the current user.
307function getDirectChildPages ($pageno)
308{
309 global $page, $remote_username;
310 $children = array();
311 foreach ($page as $cpageno => $cpage)
312 if
313 (
314 isset ($cpage['parent']) and
315 $cpage['parent'] == $pageno and
316 authorized ($remote_username, $cpageno, 'default') == TRUE
317 )
318 $children[$cpageno] = $cpage;
319 return $children;
320}
321
322function getAllChildPages ($parent)
323{
324 global $page;
325 // Array pointer is global, so if we don't create local copies of
326 // the global array, we can't advance any more after nested call
327 // of getAllChildPages returns.
328 $mypage = $page;
329 $mykids = array();
330 foreach ($mypage as $ctitle => $cpage)
331 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
332 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
333 return $mykids;
334}
335
336?>