r3904 lookupEntityByString(): move to mainstream source
[racktables-contribs] / oneshot.php
1 <?php
2 /*
3 This is a version of local.php file, which implements 'oneshot'
4 extension for RackTables. This extension makes it possible to
5 forward a user to a RackTables object page without knowing the
6 internal ID of that object. This is mainly intended to be used
7 together with other systems like Nagios, which only share
8 object's name in common with RackTables. For example:
9
10 http://example.com/racktables/index.php?page=oneshot&q=myserver
11
12 (This would instantly redirect the user to myserver's page in
13 RackTables, if "myserver" exists.)
14
15 This revision of extension has been tested to work with RackTables 0.18.x.
16
17 */
18
19 function handleOneShotRequest ()
20 {
21 assertStringArg ('realm');
22 assertStringArg ('q');
23 switch ($_REQUEST['realm'])
24 {
25 case 'object':
26 if (NULL === ($id = lookupEntityByString ($_REQUEST['realm'], $_REQUEST['q'])))
27 echo "<h2>Nothing found for '${_REQUEST['q']}'</h2>";
28 else
29 echo "<script language='Javascript'>document.location='index.php?page=object&object_id=${id}';//</script>";
30 break;
31 default:
32 dragon();
33 break;
34 }
35 }
36
37 ?>