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