Filter.php 4.3 KB

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