1 : <?php
2 :
3 : /**
4 : * PHPIDS
5 : *
6 : * Requirements: PHP5, SimpleXML
7 : *
8 : * Copyright (c) 2008 PHPIDS group (http://php-ids.org)
9 : *
10 : * PHPIDS is free software; you can redistribute it and/or modify
11 : * it under the terms of the GNU Lesser General Public License as published by
12 : * the Free Software Foundation, version 3 of the License, or
13 : * (at your option) any later version.
14 : *
15 : * PHPIDS is distributed in the hope that it will be useful,
16 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : * GNU Lesser General Public License for more details.
19 : *
20 : * You should have received a copy of the GNU Lesser General Public License
21 : * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
22 : *
23 : * PHP version 5.1.6+
24 : *
25 : * @category Security
26 : * @package PHPIDS
27 : * @author Mario Heiderich <mario.heiderich@gmail.com>
28 : * @author Christian Matthies <ch0012@gmail.com>
29 : * @author Lars Strojny <lars@strojny.net>
30 : * @license http://www.gnu.org/licenses/lgpl.html LGPL
31 : * @link http://php-ids.org/
32 : */
33 :
34 : /**
35 : * PHPIDS Filter object
36 : *
37 : * Each object of this class serves as a container for a specific filter. The
38 : * object provides methods to get information about this particular filter and
39 : * also to match an arbitrary string against it.
40 : *
41 : * @category Security
42 : * @package PHPIDS
43 : * @author Christian Matthies <ch0012@gmail.com>
44 : * @author Mario Heiderich <mario.heiderich@gmail.com>
45 : * @author Lars Strojny <lars@strojny.net>
46 : * @copyright 2007 The PHPIDS Group
47 : * @license http://www.gnu.org/licenses/lgpl.html LGPL
48 : * @version Release: $Id:Filter.php 517 2007-09-15 15:04:13Z mario $
49 : * @link http://php-ids.org/
50 : * @since Version 0.4
51 : */
52 : class IDS_Filter
53 : {
54 :
55 : /**
56 : * Filter rule
57 : *
58 : * @var string
59 : */
60 : protected $rule;
61 :
62 : /**
63 : * List of tags of the filter
64 : *
65 : * @var array
66 : */
67 : protected $tags = array();
68 :
69 : /**
70 : * Filter impact level
71 : *
72 : * @var integer
73 : */
74 : protected $impact = 0;
75 :
76 : /**
77 : * Filter description
78 : *
79 : * @var string
80 : */
81 : protected $description = null;
82 :
83 : /**
84 : * Constructor
85 : *
86 : * @param mixed $rule filter rule
87 : * @param string $description filter description
88 : * @param array $tags list of tags
89 : * @param integer $impact filter impact level
90 : *
91 : * @return void
92 : */
93 : public function __construct($id, $rule, $description, array $tags, $impact)
94 : {
95 69 : $this->id = $id;
96 69 : $this->rule = $rule;
97 69 : $this->tags = $tags;
98 69 : $this->impact = $impact;
99 69 : $this->description = $description;
100 69 : }
101 :
102 : /**
103 : * Matches a string against current filter
104 : *
105 : * Matches given string against the filter rule the specific object of this
106 : * class represents
107 : *
108 : * @param string $string the string to match
109 : *
110 : * @throws InvalidArgumentException if argument is no string
111 : * @return boolean
112 : */
113 : public function match($string)
114 : {
115 38 : if (!is_string($string)) {
116 1 : throw new InvalidArgumentException('
117 1 : Invalid argument. Expected a string, received ' . gettype($string)
118 1 : );
119 : }
120 :
121 37 : return (bool) preg_match(
122 37 : '/' . $this->getRule() . '/ms', strtolower($string)
123 37 : );
124 : }
125 :
126 : /**
127 : * Returns filter description
128 : *
129 : * @return string
130 : */
131 : public function getDescription()
132 : {
133 2 : return $this->description;
134 : }
135 :
136 : /**
137 : * Return list of affected tags
138 : *
139 : * Each filter rule is concerned with a certain kind of attack vectors.
140 : * This method returns those affected kinds.
141 : *
142 : * @return array
143 : */
144 : public function getTags()
145 : {
146 6 : return $this->tags;
147 : }
148 :
149 : /**
150 : * Returns filter rule
151 : *
152 : * @return string
153 : */
154 : public function getRule()
155 : {
156 38 : return $this->rule;
157 : }
158 :
159 : /**
160 : * Get filter impact level
161 : *
162 : * @return integer
163 : */
164 : public function getImpact()
165 : {
166 36 : return $this->impact;
167 : }
168 :
169 : /**
170 : * Get filter ID
171 : *
172 : * @return integer
173 : */
174 : public function getId()
175 : {
176 1 : return $this->id;
177 : }
178 : }
179 :
180 : /*
181 : * Local variables:
182 : * tab-width: 4
183 : * c-basic-offset: 4
184 : * End:
185 : */
|