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