r2594 - eval_expression(): $silent arg to hide error messages
[racktables] / 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
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.
46f92ff7 18function trigger_livevlans ()
641fe9b0 19{
2c6c7645 20 assertUIntArg ('object_id', __FUNCTION__);
641fe9b0
DO
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 {
dce5a9e7 28 if ($record['id'] != 4) // SW type
641fe9b0 29 continue;
dce5a9e7
DO
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)))
641fe9b0
DO
34 return TRUE;
35 else
36 return FALSE;
37 }
38 return FALSE;
39}
40
9c67f713
DO
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.
44function trigger_snmpportfinder ()
45{
2c6c7645 46 assertUIntArg ('object_id', __FUNCTION__);
9c67f713
DO
47 $object_id = $_REQUEST['object_id'];
48 $object = getObjectInfo ($object_id);
49 if ($object['objtype_id'] != 8)
50 return FALSE;
cf6c472b 51 if (!objectIsPortless ($_REQUEST['object_id']))
9c67f713
DO
52 return FALSE;
53 return TRUE;
54}
55
19627044 56// Show "click me" teaser in an empty rackspace.
9b0cf84f
DO
57function trigger_emptyRackspace ()
58{
19627044 59 return (count (getRackRows()) == 0);
9b0cf84f
DO
60}
61
a0527aef 62function trigger_isloadbalancer ()
3ee1252b 63{
2c6c7645 64 assertUIntArg ('object_id', __FUNCTION__);
a0527aef
DO
65 // Compile the same text, which was used for making the decision.
66 $filtertext = getConfigVar ('IPV4LB_LISTSRC');
67 if (!strlen ($filtertext))
68 return TRUE; // no restriction, always show the tab
69 $filter = spotPayload ($filtertext, 'SYNT_EXPR');
70 if ($filter['result'] != 'ACK')
71 return FALSE; // filter set, but cannot be used
72 global $rackCode;
73 return judgeEntity ('object', $_REQUEST['object_id'], $filter['load'], buildPredicateTable ($rackCode));
6dbdc7c7
DO
74}
75
76function trigger_ipv4 ()
77{
2c6c7645 78 assertUIntArg ('object_id', __FUNCTION__);
6dbdc7c7
DO
79 $info = getObjectInfo ($_REQUEST['object_id']);
80 return in_array ($info['objtype_id'], explode (',', getConfigVar ('IPV4_PERFORMERS')));
81}
82
83function trigger_natv4 ()
84{
2c6c7645 85 assertUIntArg ('object_id', __FUNCTION__);
6dbdc7c7
DO
86 $info = getObjectInfo ($_REQUEST['object_id']);
87 return in_array ($info['objtype_id'], explode (',', getConfigVar ('NATV4_PERFORMERS')));
3ee1252b
DO
88}
89
a785988f
DO
90function trigger_poolrscount ()
91{
2c6c7645 92 assertUIntArg ('pool_id', __FUNCTION__);
6aff02cf 93 $poolInfo = getRSPoolInfo ($_REQUEST['pool_id']);
a785988f
DO
94 return count ($poolInfo['rslist']) > 0;
95}
96
118e4c38
DO
97function trigger_autoports ()
98{
2c6c7645 99 assertUIntArg ('object_id', __FUNCTION__);
cf6c472b 100 if (!objectIsPortless ($_REQUEST['object_id']))
118e4c38
DO
101 return FALSE;
102 $info = getObjectInfo ($_REQUEST['object_id']);
103 return count (getAutoPorts ($info['objtype_id'])) != 0;
104}
105
91dbb8a3
DO
106function trigger_tags ()
107{
20c901a7
DO
108 global $taglist;
109 return count ($taglist) > 0;
91dbb8a3
DO
110}
111
0ac7e4b3
DO
112function trigger_passwdchange ()
113{
204284ba
DO
114 global $user_auth_src;
115 return $user_auth_src == 'database';
0ac7e4b3
DO
116}
117
e5c4506d
DO
118function trigger_localreports ()
119{
120 global $localreports;
121 return count ($localreports) > 0;
122}
123
8628ae44
DO
124function trigger_file_editText ()
125{
126 assertUIntArg ('file_id', __FUNCTION__);
127 $fileInfo = getFileInfo ($_REQUEST['file_id']);
128 return ($fileInfo['type'] == 'text/plain');
129}
130
641fe9b0 131?>