r4452 Make VLAN switch templates one of "generic" realms:
[racktables] / wwwroot / inc / triggers.php
CommitLineData
b325120a 1<?php
641fe9b0
DO
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
913e0ebf 10// the trigger returned CSS class name. In certain cases, a key is necessary
641fe9b0
DO
11// to decide (the 'bypass' hint of a page), and in some cases,
12// other data can be used.
13
29de85b6
DO
14// APC "switched rack PDU" stands for a number of part numbers:
15// http://www.apc.com/products/family/index.cfm?id=70
16$known_APC_SKUs = array
17(
18 // 100V input
19 1151 => 'AP7902J',
20 1152 => 'AP7930J',
21 1153 => 'AP7932J',
22 // 120V input
23 1154 => 'AP7900',
24 1155 => 'AP7901',
25 1156 => 'AP7902',
26 1157 => 'AP7930',
27 1158 => 'AP7931',
28 1159 => 'AP7932',
29 // 208V input
30 1160 => 'AP7911',
31 1161 => 'AP7940',
32 1162 => 'AP7941',
33 // 208V 3 phases input
34 1163 => 'AP7960',
35 1164 => 'AP7961',
36 1165 => 'AP7968',
37 1166 => 'AP7990',
38 1167 => 'AP7991',
39 1168 => 'AP7998',
40 // 230V input
41 1137 => 'AP7920',
42 1138 => 'AP7921',
43 1139 => 'AP7922',
44 1140 => 'AP7950',
45 1141 => 'AP7951',
46 1142 => 'AP7952',
47 1143 => 'AP7953',
48 1144 => 'AP7954',
49 // 400V 3 phases input
50 1154 => 'AP7957',
51);
52
38e05b77
DO
53// Return 'std', if the object belongs to specified type and has
54// specified attribute belonging to the given set of values.
4848a7e3 55function checkTypeAndAttribute ($object_id, $type_id, $attr_id, $values, $hit = 'std')
38e05b77
DO
56{
57 $object = spotEntity ('object', $object_id);
58 if ($object['objtype_id'] != $type_id)
59 return '';
60 foreach (getAttrValues ($object_id) as $record)
61 if ($record['id'] == $attr_id and in_array ($record['key'], $values))
4848a7e3 62 return $hit;
38e05b77
DO
63 return '';
64}
65
641fe9b0
DO
66// This trigger filters out everything except switches with known-good
67// software.
46f92ff7 68function trigger_livevlans ()
641fe9b0 69{
38e05b77
DO
70 return checkTypeAndAttribute
71 (
72 $_REQUEST['object_id'],
73 8, // network switch
74 4, // SW type
dce5a9e7
DO
75 // Cisco IOS 12.0
76 // Cisco IOS 12.1
77 // Cisco IOS 12.2
38e05b77
DO
78 array (244, 251, 252)
79 );
80}
81
65e557dd
AA
82// This trigger is on when any of the (get_mac_list, get_link_status) ops permitted
83function trigger_liveports ()
84{
457008d2
DO
85 global $gwrxlator;
86 $breed = detectDeviceBreed (getBypassValue());
87 foreach (array ('getportstatus', 'getmaclist') as $command)
88 if
89 (
90 array_key_exists ($command, $gwrxlator) and
91 array_key_exists ($breed, $gwrxlator[$command]) and
92 permitted (NULL, 'liveports', $command)
93 )
94 return 'std';
65e557dd
AA
95 return '';
96}
97
4848a7e3
DO
98// SNMP port finder tab trigger. At the moment we decide on showing it
99// for pristine switches/PDUs only. Once a user has begun
100// filling the data in, we stop showing the tab.
101function trigger_snmpportfinder ()
38e05b77 102{
641fe9b0 103
0cc24e9a 104 assertUIntArg ('object_id');
b179c07c 105 $object = spotEntity ('object', $_REQUEST['object_id']);
4848a7e3
DO
106 switch ($object['objtype_id'])
107 {
7d69a266
DO
108 case 7: // any router
109 case 8: // or switch would suffice
4848a7e3
DO
110 return $object['nports'] ? '' : 'attn';
111 case 2: // but only selected PDUs
112 if ($object['nports'])
113 return '';
29de85b6 114 global $known_APC_SKUs;
4848a7e3
DO
115 return checkTypeAndAttribute
116 (
117 $object['id'],
118 2, // PDU
119 2, // HW type
120 array_keys ($known_APC_SKUs),
121 'attn'
122 );
123 default:
913e0ebf 124 return '';
4848a7e3 125 }
9c67f713
DO
126}
127
a0527aef 128function trigger_isloadbalancer ()
3ee1252b 129{
0cc24e9a 130 assertUIntArg ('object_id');
212c9d8a 131 return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4LB_LISTSRC') ? 'std' : '';
6dbdc7c7
DO
132}
133
134function trigger_ipv4 ()
135{
0cc24e9a 136 assertUIntArg ('object_id');
aa90450a 137 if (count (getObjectIPv4Allocations ($_REQUEST['object_id'])))
913e0ebf 138 return 'std';
aa90450a 139 // Only hide the tab, if there are no addresses allocated.
212c9d8a 140 return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4OBJ_LISTSRC') ? 'std' : '';
6dbdc7c7
DO
141}
142
21ee3351
AA
143function trigger_ipv6 ()
144{
145 assertUIntArg ('object_id');
146 if (count (getObjectIPv6Allocations ($_REQUEST['object_id'])))
147 return 'std';
148 // Only hide the tab, if there are no addresses allocated.
149 return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4OBJ_LISTSRC') ? 'std' : '';
150}
151
6dbdc7c7
DO
152function trigger_natv4 ()
153{
0cc24e9a 154 assertUIntArg ('object_id');
9a8c797a
DO
155 if (!count (getObjectIPv4Allocations ($_REQUEST['object_id'])))
156 return '';
212c9d8a 157 return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4NAT_LISTSRC') ? 'std' : '';
3ee1252b
DO
158}
159
a785988f
DO
160function trigger_poolrscount ()
161{
0cc24e9a 162 assertUIntArg ('pool_id');
a6e91ac2
DO
163 $poolInfo = spotEntity ('ipv4rspool', $_REQUEST['pool_id']);
164 amplifyCell ($poolInfo);
913e0ebf 165 return count ($poolInfo['rslist']) ? 'std' : '';
a785988f
DO
166}
167
118e4c38
DO
168function trigger_autoports ()
169{
0cc24e9a 170 assertUIntArg ('object_id');
9f75e165
DO
171 $object = spotEntity ('object', $_REQUEST['object_id']);
172 amplifyCell ($object);
173 if (count ($object['ports']))
913e0ebf 174 return '';
9f75e165 175 return count (getAutoPorts ($object['objtype_id'])) ? 'attn' : '';
118e4c38
DO
176}
177
91dbb8a3
DO
178function trigger_tags ()
179{
20c901a7 180 global $taglist;
913e0ebf 181 return count ($taglist) ? 'std' : '';
91dbb8a3
DO
182}
183
0ac7e4b3
DO
184function trigger_passwdchange ()
185{
204284ba 186 global $user_auth_src;
913e0ebf 187 return $user_auth_src == 'database' ? 'std' : '';
0ac7e4b3
DO
188}
189
e5c4506d
DO
190function trigger_localreports ()
191{
192 global $localreports;
913e0ebf 193 return count ($localreports) ? 'std' : '';
e5c4506d
DO
194}
195
8628ae44
DO
196function trigger_file_editText ()
197{
0cc24e9a 198 assertUIntArg ('file_id');
d3b5008b 199 $fileInfo = spotEntity ('file', $_REQUEST['file_id']);
913e0ebf 200 return ($fileInfo['type'] == 'text/plain') ? 'std' : '';
8628ae44
DO
201}
202
c0a322d1
DY
203function trigger_rackspace ()
204{
2c2ea5f6
AD
205 global $virtual_obj_types;
206
207 // Hide the tab if the object type is virtual
0682218d 208 assertUIntArg ('object_id');
2c2ea5f6
AD
209 $object = spotEntity ('object', $_REQUEST['object_id']);
210 if (in_array($object['objtype_id'], $virtual_obj_types))
0682218d
AD
211 return '';
212
c0a322d1
DY
213 $rackspace = getRackspaceStats();
214 if ($rackspace['Racks'] > 0) return 'std';
215 return '';
216}
217
0682218d
AD
218function trigger_ports ()
219{
220 assertUIntArg ('object_id');
221 // Hide the tab if the object type exists in the exclusion config option
222 if (considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'PORT_EXCLUSION_LISTSRC'))
223 return '';
224
225 return 'std';
226}
227
8198f2c6
DO
228// Offer the generic VLAN setup tab for every object, which already
229// has a VLAN domain associated or at least can have one (in the latter
230// case additionally heat the tab, if no domain is set.
38cd7704 231function trigger_object_8021qorder ()
8198f2c6 232{
2996cbbb 233 if (NULL !== getVLANSwitchInfo ($_REQUEST['object_id']))
8198f2c6 234 return 'std';
b72fabda 235 if (!count (getVLANDomainOptions()) or !count (getVSTOptions()))
cbf78395 236 return '';
b72fabda
DO
237 if (considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'VLANSWITCH_LISTSRC'))
238 return 'attn';
239 return '';
cbf78395
DO
240}
241
bd0191f7
DO
242function trigger_8021q_configured ()
243{
244 if (!count (getVLANDomainOptions()) or !count (getVSTOptions()))
245 return '';
246 return 'std';
247}
248
cbf78395
DO
249// implement similar logic for IPv4 networks
250function trigger_ipv4net_vlanconfig ()
251{
e00f8fdd
DO
252 if (!count (getVLANDomainOptions())) // no domains -- no VLANs to bind with
253 return '';
cbf78395 254 $netinfo = spotEntity ('ipv4net', $_REQUEST['id']);
a5f9d1ca 255 if ($netinfo['vlanc'])
cbf78395
DO
256 return 'std';
257 elseif (considerConfiguredConstraint ($netinfo, 'VLANIPV4NET_LISTSRC'))
8198f2c6
DO
258 return 'attn';
259 else
260 return '';
261}
262
21ee3351
AA
263// implement similar logic for IPv6 networks
264function trigger_ipv6net_vlanconfig ()
265{
266 if (!count (getVLANDomainOptions())) // no domains -- no VLANs to bind with
267 return '';
268 $netinfo = spotEntity ('ipv6net', $_REQUEST['id']);
269 if ($netinfo['vlanc'])
270 return 'std';
271 elseif (considerConfiguredConstraint ($netinfo, 'VLANIPV4NET_LISTSRC'))
272 return 'attn';
273 else
274 return '';
275}
276
277function trigger_vlan_ipv4net ()
278{
279 $vlan_info = getVLANInfo ($_REQUEST['vlan_ck']);
280 return count ($vlan_info['ipv4nets']) ? 'std' : 'attn';
281}
282
283function trigger_vlan_ipv6net ()
284{
285 $vlan_info = getVLANInfo ($_REQUEST['vlan_ck']);
286 return count ($vlan_info['ipv6nets']) ? 'std' : 'attn';
287}
288
be28b696 289function trigger_object_8021qports ()
8198f2c6 290{
be28b696
DO
291 global $sic;
292 if (NULL === getVLANSwitchInfo ($sic['object_id']))
293 return '';
294 return count (getStored8021QConfig ($sic['object_id'], 'desired')) ? 'std' : '';
295}
296
297function trigger_object_8021qsync ()
298{
299 global $sic;
d973196a 300 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id']))
be28b696 301 return '';
d973196a 302 return $vswitch['out_of_sync'] == 'yes' ? 'attn' : 'std';
8198f2c6 303}
be28b696 304
e9d357e1
DO
305function trigger_LiveCDP ()
306{
b49a479e
DO
307 return trigger_anyDP ('getcdpstatus', 'CDP_RUNNERS_LISTSRC');
308}
309
310function trigger_LiveLLDP ()
311{
312 return trigger_anyDP ('getlldpstatus', 'LLDP_RUNNERS_LISTSRC');
313}
314
0328f6d6
DO
315function trigger_LiveHNDP ()
316{
317 return trigger_anyDP ('gethndp', 'HNDP_RUNNERS_LISTSRC');
318}
319
b49a479e
DO
320function trigger_anyDP ($command, $constraint)
321{
322 global $gwrxlator;
323 if (!array_key_exists ($command, $gwrxlator))
324 return '';
325 if (!array_key_exists (detectDeviceBreed ($_REQUEST['object_id']), $gwrxlator[$command]))
326 return '';
327 $object = spotEntity ('object', $_REQUEST['object_id']);
328 if (considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), $constraint))
329 return 'std';
330 return '';
e9d357e1
DO
331}
332
eb51ceff
DO
333// tease rules editor tab, when the VST has no rules
334function trigger_vst_editrules()
335{
cc3d6915
DO
336 $vst = spotEntity ('vst', getBypassValue());
337 return $vst['rulec'] ? 'std' : 'attn';
eb51ceff
DO
338}
339
641fe9b0 340?>