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