r2124 - split builting and local reports
[racktables] / inc / triggers.php
1 <?php
2 /*
3 *
4 * This file is a library of tab triggers for RackTables.
5 *
6 */
7
8 // Triggers may be optionally referred by some tabs of a page.
9 // In case they are defined, the given tab is only displayed if
10 // the trigger returned true. In certain cases, a key is necessary
11 // to decide (the 'bypass' hint of a page), and in some cases,
12 // other data can be used.
13
14 // This trigger filters out everything except switches with known-good
15 // software.
16 // FIXME: That's a bit of hardcoding at the moment, but
17 // let's thinks about fixing it later.
18 function trigger_livevlans ()
19 {
20 assertUIntArg ('object_id', __FUNCTION__);
21 $object_id = $_REQUEST['object_id'];
22 $object = getObjectInfo ($object_id);
23 if ($object['objtype_id'] != 8)
24 return FALSE;
25 $values = getAttrValues ($object_id);
26 foreach ($values as $record)
27 {
28 if ($record['id'] != 4) // SW type
29 continue;
30 // Cisco IOS 12.0
31 // Cisco IOS 12.1
32 // Cisco IOS 12.2
33 if (in_array ($record['key'], array (244, 251, 252)))
34 return TRUE;
35 else
36 return FALSE;
37 }
38 return FALSE;
39 }
40
41 // SNMP port finder tab trigger. At the moment we decide on showing it
42 // for pristine switches only. Once a user has begun
43 // filling the data in, we stop showing the tab.
44 function trigger_snmpportfinder ()
45 {
46 assertUIntArg ('object_id', __FUNCTION__);
47 $object_id = $_REQUEST['object_id'];
48 $object = getObjectInfo ($object_id);
49 if ($object['objtype_id'] != 8)
50 return FALSE;
51 if (!objectIsPortless ($_REQUEST['object_id']))
52 return FALSE;
53 return TRUE;
54 }
55
56 // Output "click me" in an empty rackspace.
57 function trigger_emptyRackspace ()
58 {
59 return (count (readChapter ('RackRow')) == 0);
60 }
61
62 function trigger_lvsconfig ()
63 {
64 assertUIntArg ('object_id', __FUNCTION__);
65 return count (getRSPoolsForObject ($_REQUEST['object_id'])) > 0;
66 }
67
68 function trigger_ipv4 ()
69 {
70 assertUIntArg ('object_id', __FUNCTION__);
71 $info = getObjectInfo ($_REQUEST['object_id']);
72 return in_array ($info['objtype_id'], explode (',', getConfigVar ('IPV4_PERFORMERS')));
73 }
74
75 function trigger_natv4 ()
76 {
77 assertUIntArg ('object_id', __FUNCTION__);
78 $info = getObjectInfo ($_REQUEST['object_id']);
79 return in_array ($info['objtype_id'], explode (',', getConfigVar ('NATV4_PERFORMERS')));
80 }
81
82 function trigger_poolrscount ()
83 {
84 assertUIntArg ('pool_id', __FUNCTION__);
85 $poolInfo = getRSPoolInfo ($_REQUEST['pool_id']);
86 return count ($poolInfo['rslist']) > 0;
87 }
88
89 function trigger_autoports ()
90 {
91 assertUIntArg ('object_id', __FUNCTION__);
92 if (!objectIsPortless ($_REQUEST['object_id']))
93 return FALSE;
94 $info = getObjectInfo ($_REQUEST['object_id']);
95 return count (getAutoPorts ($info['objtype_id'])) != 0;
96 }
97
98 function trigger_tags ()
99 {
100 global $taglist;
101 return count ($taglist) > 0;
102 }
103
104 function trigger_passwdchange ()
105 {
106 return getConfigVar ('USER_AUTH_SRC') == 'database';
107 }
108
109 function trigger_localreports ()
110 {
111 global $localreports;
112 return count ($localreports) > 0;
113 }
114
115 ?>