r1812 + generalise tag storage and handling; prepare to introduce tags for other...
[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 $page['iprange']['autotagloader'] = 'loadIPv4PrefixAutoTags';
136 $page['iprange']['tagloader'] = 'loadIPv4PrefixTags';
137 $tab['iprange']['default'] = 'Browse';
138 $tab['iprange']['properties'] = 'Properties';
139 $tab['iprange']['liveptr'] = 'Live PTR';
140 $tabhandler['iprange']['default'] = 'renderIPRange';
141 $tabhandler['iprange']['properties'] = 'renderIPRangeProperties';
142 $tabhandler['iprange']['liveptr'] = 'renderLivePTR';
143 $ophandler['iprange']['properties']['editRange'] = 'editRange';
144 $ophandler['iprange']['liveptr']['import'] = 'importPTRData';
145
146 $page['ipaddress']['title_handler'] = 'dynamic_title_ipaddress';
147 $page['ipaddress']['parent'] = 'iprange';
148 $page['ipaddress']['bypass'] = 'ip';
149 $tab['ipaddress']['default'] = 'Browse';
150 $tab['ipaddress']['properties'] = 'Properties';
151 $tab['ipaddress']['assignment'] = 'Allocation';
152 $tab['ipaddress']['editrslist'] = '[SLB real servers]';
153 $tabhandler['ipaddress']['default'] = 'renderIPAddress';
154 $tabhandler['ipaddress']['properties'] = 'renderIPAddressProperties';
155 $tabhandler['ipaddress']['assignment'] = 'renderIPAddressAssignment';
156 $ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
157 $ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
158 $ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
159 $ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
160
161 $page['ipv4slb']['title'] = 'IPv4 SLB';
162 $page['ipv4slb']['parent'] = 'index';
163 $page['ipv4slb']['handler'] = 'renderIPv4SLB';
164
165 $page['vservices']['title'] = 'Virtual services';
166 $page['vservices']['parent'] = 'ipv4slb';
167 $tab['vservices']['default'] = 'View';
168 $tab['vservices']['edit'] = 'Edit';
169 $tabhandler['vservices']['default'] = 'renderVSList';
170 $tabhandler['vservices']['edit'] = 'renderVSListEditForm';
171 $ophandler['vservices']['edit']['add'] = 'addVService';
172 $ophandler['vservices']['edit']['del'] = 'deleteVService';
173 $ophandler['vservices']['edit']['upd'] = 'updateVService';
174
175 $page['vservice']['title_handler'] = 'dynamic_title_vservice';
176 $page['vservice']['parent'] = 'vservices';
177 $page['vservice']['bypass'] = 'id';
178 $page['vservice']['bypass_type'] = 'uint';
179 $tab['vservice']['default'] = 'View';
180 $tab['vservice']['edit'] = '[Edit]';
181 $tab['vservice']['editlblist'] = '[Load balancers]';
182 $tabhandler['vservice']['default'] = 'renderVirtualService';
183
184 $page['rspools']['title'] = 'RS pools';
185 $page['rspools']['parent'] = 'ipv4slb';
186 $tab['rspools']['default'] = 'View';
187 $tab['rspools']['edit'] = 'Edit';
188 $tabhandler['rspools']['default'] = 'renderRSPoolList';
189 $tabhandler['rspools']['edit'] = 'editRSPools';
190 $ophandler['rspools']['edit']['add'] = 'addRSPool';
191 $ophandler['rspools']['edit']['del'] = 'deleteRSPool';
192 $ophandler['rspools']['edit']['upd'] = 'updateRSPool';
193
194 $page['rspool']['title_handler'] = 'dynamic_title_rspool';
195 $page['rspool']['parent'] = 'rspools';
196 $page['rspool']['bypass'] = 'id';
197 $page['rspool']['bypass_type'] = 'uint';
198 $tab['rspool']['default'] = 'View';
199 $tab['rspool']['edit'] = '[Edit]';
200 $tab['rspool']['editlblist'] = 'Load Balancers';
201 $tab['rspool']['editrslist'] = 'RS list';
202 $tab['rspool']['rsinservice'] = 'RS in service';
203 $trigger['rspool']['rsinservice'] = 'trigger_poolrscount';
204 $tabhandler['rspool']['default'] = 'renderRSPool';
205 $tabhandler['rspool']['editrslist'] = 'renderRSPoolServerForm';
206 $tabhandler['rspool']['editlblist'] = 'renderRSPoolLBForm';
207 $tabhandler['rspool']['rsinservice'] = 'renderRSPoolRSInServiceForm';
208 $ophandler['rspool']['editrslist']['addRS'] = 'addRealServer';
209 $ophandler['rspool']['editrslist']['delRS'] = 'deleteRealServer';
210 $ophandler['rspool']['editrslist']['updRS'] = 'updateRealServer';
211 $ophandler['rspool']['editrslist']['addMany'] = 'addRealServers';
212 $ophandler['rspool']['editlblist']['addLB'] = 'addLoadBalancer';
213 $ophandler['rspool']['editlblist']['delLB'] = 'deleteLoadBalancer';
214 $ophandler['rspool']['editlblist']['updLB'] = 'updateLoadBalancer';
215 $ophandler['rspool']['rsinservice']['upd'] = 'updateRSInService';
216
217 $page['rservers']['title'] = 'Real servers';
218 $page['rservers']['parent'] = 'ipv4slb';
219 $page['rservers']['handler'] = 'renderRealServerList';
220
221 $page['lbs']['title'] = 'Load balancers';
222 $page['lbs']['parent'] = 'ipv4slb';
223 $page['lbs']['handler'] = 'renderLBList';
224
225 $page['search']['title_handler'] = 'dynamic_title_search';
226 $page['search']['handler'] = 'renderSearchResults';
227 $page['search']['parent'] = 'index';
228 $page['search']['bypass'] = 'q';
229
230 $page['config']['title'] = 'Configuration';
231 $page['config']['handler'] = 'renderConfigMainpage';
232 $page['config']['parent'] = 'index';
233
234 $page['accounts']['title'] = 'Accounts';
235 $page['accounts']['parent'] = 'config';
236 $tab['accounts']['default'] = 'View';
237 $tab['accounts']['edit'] = 'Change';
238 $tabhandler['accounts']['default'] = 'renderAccounts';
239 $tabhandler['accounts']['edit'] = 'renderAccountsEditForm';
240 $ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
241 $ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
242 $ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
243 $ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
244
245 $page['perms']['title'] = 'Permissions';
246 $page['perms']['parent'] = 'config';
247 $tab['perms']['default'] = 'View';
248 $tab['perms']['edit'] = 'Change';
249 $tabhandler['perms']['default'] = 'renderPermissions';
250 $tabhandler['perms']['edit'] = 'renderPermissionsEditForm';
251 $ophandler['perms']['edit']['revoke'] = 'revokePermission';
252 $ophandler['perms']['edit']['grant'] = 'grantPermission';
253
254 $page['portmap']['title'] = 'Port compatibility map';
255 $page['portmap']['parent'] = 'config';
256 $tab['portmap']['default'] = 'View';
257 $tab['portmap']['edit'] = 'Change';
258 $tabhandler['portmap']['default'] = 'renderPortMapViewer';
259 $tabhandler['portmap']['edit'] = 'renderPortMapEditor';
260 $ophandler['portmap']['edit']['save'] = 'savePortMap';
261
262 $page['attrs']['title'] = 'Attributes';
263 $page['attrs']['parent'] = 'config';
264 $tab['attrs']['default'] = 'View';
265 $tab['attrs']['editattrs'] = 'Edit attributes';
266 $tab['attrs']['editmap'] = 'Edit map';
267 $tabhandler['attrs']['default'] = 'renderAttributes';
268 $tabhandler['attrs']['editattrs'] = 'renderEditAttributesForm';
269 $tabhandler['attrs']['editmap'] = 'renderEditAttrMapForm';
270 $ophandler['attrs']['editattrs']['add'] = 'createAttribute';
271 $ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
272 $ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
273 $ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
274 $ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
275
276 $page['dict']['title'] = 'Dictionary';
277 $page['dict']['parent'] = 'config';
278 $tab['dict']['default'] = 'View';
279 $tab['dict']['edit'] = 'Edit words';
280 $tab['dict']['chapters'] = 'Manage chapters';
281 $tabhandler['dict']['default'] = 'renderDictionary';
282 $tabhandler['dict']['edit'] = 'renderDictionaryEditor';
283 $tabhandler['dict']['chapters'] = 'renderChaptersEditor';
284 $ophandler['dict']['edit']['del'] = 'reduceDictionary';
285 $ophandler['dict']['edit']['upd'] = 'updateDictionary';
286 $ophandler['dict']['edit']['add'] = 'supplementDictionary';
287 $ophandler['dict']['chapters']['del'] = 'delChapter';
288 $ophandler['dict']['chapters']['upd'] = 'updateChapter';
289 $ophandler['dict']['chapters']['add'] = 'addChapter';
290
291 $page['ui']['title'] = 'User interface';
292 $page['ui']['parent'] = 'config';
293 $tab['ui']['default'] = 'View';
294 $tab['ui']['edit'] = 'Change';
295 $tab['ui']['reset'] = 'Reset';
296 $tabhandler['ui']['default'] = 'renderUIConfig';
297 $tabhandler['ui']['edit'] = 'renderUIConfigEditForm';
298 $tabhandler['ui']['reset'] = 'renderUIResetForm';
299 $ophandler['ui']['edit']['upd'] = 'updateUI';
300 $ophandler['ui']['reset']['go'] = 'resetUIConfig';
301
302 $page['tagtree']['title'] = 'Tag tree';
303 $page['tagtree']['parent'] = 'config';
304 $tab['tagtree']['default'] = 'View';
305 $tab['tagtree']['edit'] = 'Change';
306 $tabhandler['tagtree']['default'] = 'renderTagTree';
307 $tabhandler['tagtree']['edit'] = 'renderTagTreeEditor';
308 $ophandler['tagtree']['edit']['destroyTag'] = 'destroyTag';
309 $ophandler['tagtree']['edit']['createTag'] = 'createTag';
310 $ophandler['tagtree']['edit']['updateTag'] = 'updateTag';
311
312 $page['reports']['title'] = 'Reports';
313 $page['reports']['parent'] = 'index';
314 $tab['reports']['default'] = 'View';
315 $tabhandler['reports']['default'] = 'renderReportSummary';
316
317 // This function returns array if page numbers leading to the target page
318 // plus page number of target page itself. The first element is the target
319 // page number and the last element is the index page number.
320 function getPath ($targetno)
321 {
322 global $page;
323 $path = array();
324 // Recursion breaks at first parentless page.
325 if (!isset ($page[$targetno]['parent']))
326 $path = array ($targetno);
327 else
328 {
329 $path = getPath ($page[$targetno]['parent']);
330 $path[] = $targetno;
331 }
332 return $path;
333 }
334
335 function showPathAndSearch ($pageno)
336 {
337 global $root, $page;
338 // Path.
339 echo "<td class=activemenuitem width='99%'>" . getConfigVar ('enterprise');
340 $path = getPath ($pageno);
341 foreach ($path as $no)
342 {
343 $title['params'] = array();
344 if (isset ($page[$no]['title']))
345 $title['name'] = $page[$no]['title'];
346 elseif (isset ($page[$no]['title_handler']))
347 $title = $page[$no]['title_handler']($no);
348 else
349 $title['name'] = '[N/A]';
350 echo ": <a href='${root}?page=${no}";
351 foreach ($title['params'] as $param_name => $param_value)
352 echo "&${param_name}=${param_value}";
353 echo "'>" . $title['name'] . "</a>";
354 }
355 echo "</td>";
356 // Search form.
357 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
358 echo "<form method=get action='${root}'><td>";
359 echo '<input type=hidden name=page value=search>';
360 // This input will be the first, if we don't add ports or addresses.
361 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
362 }
363
364 function getTitle ($pageno, $tabno)
365 {
366 global $page;
367 if (isset ($page[$pageno]['title']))
368 return $page[$pageno]['title'];
369 elseif (isset ($page[$pageno]['title_handler']))
370 {
371 $tmp = $page[$pageno]['title_handler']($pageno);
372 return $tmp['name'];
373 }
374 else
375 return getConfigVar ('enterprise');
376 }
377
378 function showTabs ($pageno, $tabno)
379 {
380 global $tab, $root, $page, $remote_username, $trigger, $tabextraclass;
381 if (!isset ($tab[$pageno]['default']))
382 return;
383 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
384 foreach ($tab[$pageno] as $tabidx => $tabtitle)
385 {
386 // Hide forbidden tabs.
387 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
388 continue;
389 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
390 if
391 (
392 isset ($trigger[$pageno][$tabidx]) &&
393 $trigger[$pageno][$tabidx] () != TRUE
394 )
395 continue;
396 $class = ($tabidx == $tabno) ? 'current' : 'std';
397 $extra = (isset ($tabextraclass[$pageno][$tabidx])) ? $tabextraclass[$pageno][$tabidx] : '';
398 echo "<li><a class=${class}{$extra}";
399 echo " href='${root}?page=${pageno}&tab=${tabidx}";
400 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
401 {
402 $bpname = $page[$pageno]['bypass'];
403 $bpval = $_REQUEST[$bpname];
404 echo "&${bpname}=${bpval}";
405 }
406 echo "'>${tabtitle}</a></li>\n";
407 }
408 echo "</ul></div></td>\n";
409 }
410
411 // This function returns pages, which are direct children of the requested
412 // page and are accessible by the current user.
413 function getDirectChildPages ($pageno)
414 {
415 global $page, $remote_username;
416 $children = array();
417 foreach ($page as $cpageno => $cpage)
418 if
419 (
420 isset ($cpage['parent']) and
421 $cpage['parent'] == $pageno and
422 authorized ($remote_username, $cpageno, 'default') == TRUE
423 )
424 $children[$cpageno] = $cpage;
425 return $children;
426 }
427
428 function getAllChildPages ($parent)
429 {
430 global $page;
431 // Array pointer is global, so if we don't create local copies of
432 // the global array, we can't advance any more after nested call
433 // of getAllChildPages returns.
434 $mypage = $page;
435 $mykids = array();
436 foreach ($mypage as $ctitle => $cpage)
437 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
438 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
439 return $mykids;
440 }
441
442 ?>