r4182 commitUpdateVSTRules(): change to generate "soft" error
[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 CSS class name. 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 // 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
53 // Return 'std', if the object belongs to specified type and has
54 // specified attribute belonging to the given set of values.
55 function checkTypeAndAttribute ($object_id, $type_id, $attr_id, $values, $hit = 'std')
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))
62 return $hit;
63 return '';
64 }
65
66 // This trigger filters out everything except switches with known-good
67 // software.
68 function trigger_livevlans ()
69 {
70 return checkTypeAndAttribute
71 (
72 $_REQUEST['object_id'],
73 8, // network switch
74 4, // SW type
75 // Cisco IOS 12.0
76 // Cisco IOS 12.1
77 // Cisco IOS 12.2
78 array (244, 251, 252)
79 );
80 }
81
82 // This trigger is on when any of the (get_mac_list, get_link_status) ops permitted
83 function trigger_liveports ()
84 {
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';
95 return '';
96 }
97
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.
101 function trigger_snmpportfinder ()
102 {
103
104 assertUIntArg ('object_id');
105 $object = spotEntity ('object', $_REQUEST['object_id']);
106 switch ($object['objtype_id'])
107 {
108 case 7: // any router
109 case 8: // or switch would suffice
110 return $object['nports'] ? '' : 'attn';
111 case 2: // but only selected PDUs
112 if ($object['nports'])
113 return '';
114 global $known_APC_SKUs;
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:
124 return '';
125 }
126 }
127
128 function trigger_isloadbalancer ()
129 {
130 assertUIntArg ('object_id');
131 return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4LB_LISTSRC') ? 'std' : '';
132 }
133
134 function trigger_ipv4 ()
135 {
136 assertUIntArg ('object_id');
137 if (count (getObjectIPv4Allocations ($_REQUEST['object_id'])))
138 return 'std';
139 // Only hide the tab, if there are no addresses allocated.
140 return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4OBJ_LISTSRC') ? 'std' : '';
141 }
142
143 function 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
152 function trigger_natv4 ()
153 {
154 assertUIntArg ('object_id');
155 if (!count (getObjectIPv4Allocations ($_REQUEST['object_id'])))
156 return '';
157 return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4NAT_LISTSRC') ? 'std' : '';
158 }
159
160 function trigger_poolrscount ()
161 {
162 assertUIntArg ('pool_id');
163 $poolInfo = spotEntity ('ipv4rspool', $_REQUEST['pool_id']);
164 amplifyCell ($poolInfo);
165 return count ($poolInfo['rslist']) ? 'std' : '';
166 }
167
168 function trigger_autoports ()
169 {
170 assertUIntArg ('object_id');
171 $object = spotEntity ('object', $_REQUEST['object_id']);
172 amplifyCell ($object);
173 if (count ($object['ports']))
174 return '';
175 return count (getAutoPorts ($object['objtype_id'])) ? 'attn' : '';
176 }
177
178 function trigger_tags ()
179 {
180 global $taglist;
181 return count ($taglist) ? 'std' : '';
182 }
183
184 function trigger_passwdchange ()
185 {
186 global $user_auth_src;
187 return $user_auth_src == 'database' ? 'std' : '';
188 }
189
190 function trigger_localreports ()
191 {
192 global $localreports;
193 return count ($localreports) ? 'std' : '';
194 }
195
196 function trigger_file_editText ()
197 {
198 assertUIntArg ('file_id');
199 $fileInfo = spotEntity ('file', $_REQUEST['file_id']);
200 return ($fileInfo['type'] == 'text/plain') ? 'std' : '';
201 }
202
203 function trigger_rackspace ()
204 {
205 // Hide the tab if the object type exists in the virtual config option
206 assertUIntArg ('object_id');
207 if (considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'VIRTUAL_OBJ_LISTSRC'))
208 return '';
209
210 $rackspace = getRackspaceStats();
211 if ($rackspace['Racks'] > 0) return 'std';
212 return '';
213 }
214
215 function trigger_ports ()
216 {
217 assertUIntArg ('object_id');
218 // Hide the tab if the object type exists in the exclusion config option
219 if (considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'PORT_EXCLUSION_LISTSRC'))
220 return '';
221
222 return 'std';
223 }
224
225 // Offer the generic VLAN setup tab for every object, which already
226 // has a VLAN domain associated or at least can have one (in the latter
227 // case additionally heat the tab, if no domain is set.
228 function trigger_object_8021qorder ()
229 {
230 if (NULL !== getVLANSwitchInfo ($_REQUEST['object_id']))
231 return 'std';
232 if (!count (getVLANDomainOptions()) or !count (getVSTOptions()))
233 return '';
234 if (considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'VLANSWITCH_LISTSRC'))
235 return 'attn';
236 return '';
237 }
238
239 function trigger_8021q_configured ()
240 {
241 if (!count (getVLANDomainOptions()) or !count (getVSTOptions()))
242 return '';
243 return 'std';
244 }
245
246 // implement similar logic for IPv4 networks
247 function trigger_ipv4net_vlanconfig ()
248 {
249 if (!count (getVLANDomainOptions())) // no domains -- no VLANs to bind with
250 return '';
251 $netinfo = spotEntity ('ipv4net', $_REQUEST['id']);
252 if ($netinfo['vlanc'])
253 return 'std';
254 elseif (considerConfiguredConstraint ($netinfo, 'VLANIPV4NET_LISTSRC'))
255 return 'attn';
256 else
257 return '';
258 }
259
260 // implement similar logic for IPv6 networks
261 function trigger_ipv6net_vlanconfig ()
262 {
263 if (!count (getVLANDomainOptions())) // no domains -- no VLANs to bind with
264 return '';
265 $netinfo = spotEntity ('ipv6net', $_REQUEST['id']);
266 if ($netinfo['vlanc'])
267 return 'std';
268 elseif (considerConfiguredConstraint ($netinfo, 'VLANIPV4NET_LISTSRC'))
269 return 'attn';
270 else
271 return '';
272 }
273
274 function trigger_vlan_ipv4net ()
275 {
276 $vlan_info = getVLANInfo ($_REQUEST['vlan_ck']);
277 return count ($vlan_info['ipv4nets']) ? 'std' : 'attn';
278 }
279
280 function trigger_vlan_ipv6net ()
281 {
282 $vlan_info = getVLANInfo ($_REQUEST['vlan_ck']);
283 return count ($vlan_info['ipv6nets']) ? 'std' : 'attn';
284 }
285
286 function trigger_object_8021qports ()
287 {
288 global $sic;
289 if (NULL === getVLANSwitchInfo ($sic['object_id']))
290 return '';
291 return count (getStored8021QConfig ($sic['object_id'], 'desired')) ? 'std' : '';
292 }
293
294 function trigger_object_8021qsync ()
295 {
296 global $sic;
297 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id']))
298 return '';
299 return $vswitch['out_of_sync'] == 'yes' ? 'attn' : 'std';
300 }
301
302 function trigger_LiveCDP ()
303 {
304 return trigger_anyDP ('getcdpstatus', 'CDP_RUNNERS_LISTSRC');
305 }
306
307 function trigger_LiveLLDP ()
308 {
309 return trigger_anyDP ('getlldpstatus', 'LLDP_RUNNERS_LISTSRC');
310 }
311
312 function trigger_LiveHNDP ()
313 {
314 return trigger_anyDP ('gethndp', 'HNDP_RUNNERS_LISTSRC');
315 }
316
317 function trigger_anyDP ($command, $constraint)
318 {
319 global $gwrxlator;
320 if (!array_key_exists ($command, $gwrxlator))
321 return '';
322 if (!array_key_exists (detectDeviceBreed ($_REQUEST['object_id']), $gwrxlator[$command]))
323 return '';
324 $object = spotEntity ('object', $_REQUEST['object_id']);
325 if (considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), $constraint))
326 return 'std';
327 return '';
328 }
329
330 // tease rules editor tab, when the VST has no rules
331 function trigger_vst_editrules()
332 {
333 $vst = getVLANSwitchTemplate ($_REQUEST['vst_id']);
334 return count ($vst['rules']) ? 'std' : 'attn';
335 }
336
337 ?>