Skip to content
Browse files

First version of the ZeSecurity module.

Currently contains a wrapper for PHPIDS (modified to follow PSR-0 and removed require_once), ability to set up unlimited threat levels and to define new actions to handle attacks.
  • Loading branch information...
1 parent abf32c5 commit 0f7365ec0e813116fc4067ec5834a8b919883944 @cosmin-harangus cosmin-harangus committed Jun 19, 2012
Showing with 18,142 additions and 1 deletion.
  1. +5 −0 .htaccess
  2. +30 −0 LICENSE
  3. +82 −0 Module.php
  4. +48 −1 README.md
  5. +8 −0 autoload/classmap.php
  6. +12 −0 autoload/function.php
  7. +2 −0 autoload/register.php
  8. +31 −0 composer.json
  9. +72 −0 config/module.config.php
  10. +6 −0 config/service.config.php
  11. +104 −0 config/zesecurity.ids.global.php
  12. +22 −0 src/ZeSecurity/IDS/Action/AbstractAction.php
  13. +23 −0 src/ZeSecurity/IDS/Action/ActionInterface.php
  14. +22 −0 src/ZeSecurity/IDS/Action/CleanSession.php
  15. +19 −0 src/ZeSecurity/IDS/Action/Ignore.php
  16. +60 −0 src/ZeSecurity/IDS/Action/Log.php
  17. +43 −0 src/ZeSecurity/IDS/Action/Log/EmailFactory.php
  18. +12 −0 src/ZeSecurity/IDS/Action/Log/FactoryInterface.php
  19. +23 −0 src/ZeSecurity/IDS/Action/Log/LogFactory.php
  20. +28 −0 src/ZeSecurity/IDS/Action/Log/StreamFactory.php
  21. +25 −0 src/ZeSecurity/IDS/Action/Redirect.php
  22. +189 −0 src/ZeSecurity/IDS/Monitor.php
  23. +35 −0 src/ZeSecurity/IDS/MonitorFactory.php
  24. +22 −0 src/ZeSecurity/IDS/Util/FormatNumbers.php
  25. +5 −0 vendor/IDS/.htaccess
  26. +84 −0 vendor/IDS/Caching.php
  27. +149 −0 vendor/IDS/Caching/Apc.php
  28. +289 −0 vendor/IDS/Caching/Database.php
  29. +185 −0 vendor/IDS/Caching/File.php
  30. +73 −0 vendor/IDS/Caching/Interface.php
  31. +193 −0 vendor/IDS/Caching/Memcached.php
  32. +144 −0 vendor/IDS/Caching/Session.php
  33. +89 −0 vendor/IDS/Config/Config.ini.php
  34. +750 −0 vendor/IDS/Converter.php
  35. +235 −0 vendor/IDS/Event.php
  36. +187 −0 vendor/IDS/Filter.php
  37. +376 −0 vendor/IDS/Filter/Storage.php
  38. +229 −0 vendor/IDS/Init.php
  39. +136 −0 vendor/IDS/Log/Composite.php
  40. +300 −0 vendor/IDS/Log/Database.php
  41. +400 −0 vendor/IDS/Log/Email.php
  42. +229 −0 vendor/IDS/Log/File.php
  43. +65 −0 vendor/IDS/Log/Interface.php
  44. +775 −0 vendor/IDS/Monitor.php
  45. +341 −0 vendor/IDS/Report.php
  46. +49 −0 vendor/IDS/Version.php
  47. +1 −0 vendor/IDS/default_filter.json
  48. +799 −0 vendor/IDS/default_filter.xml
  49. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier.auto.php
  50. +26 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier.autoload.php
  51. +23 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier.func.php
  52. +214 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier.includes.php
  53. +30 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier.kses.php
  54. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier.path.php
  55. +237 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier.php
  56. +208 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier.safe-includes.php
  57. +128 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrCollections.php
  58. +123 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef.php
  59. +87 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS.php
  60. +21 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/AlphaValue.php
  61. +87 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Background.php
  62. +133 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php
  63. +43 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Border.php
  64. +78 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Color.php
  65. +38 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Composite.php
  66. +28 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/DenyElementDecorator.php
  67. +54 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Filter.php
  68. +149 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Font.php
  69. +197 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/FontFamily.php
  70. +40 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php
  71. +47 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Length.php
  72. +78 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/ListStyle.php
  73. +58 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Multiple.php
  74. +69 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Number.php
  75. +40 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Percentage.php
  76. +38 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/TextDecoration.php
  77. +61 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/URI.php
  78. +65 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/Enum.php
  79. +28 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/Bool.php
  80. +34 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/Class.php
  81. +32 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/Color.php
  82. +21 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/FrameTarget.php
  83. +70 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/ID.php
  84. +41 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/Length.php
  85. +53 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/LinkTypes.php
  86. +41 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/MultiLength.php
  87. +52 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/Nmtokens.php
  88. +48 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/Pixels.php
  89. +73 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/Integer.php
  90. +73 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/Lang.php
  91. +34 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/Switch.php
  92. +15 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/Text.php
  93. +77 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/URI.php
  94. +17 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/URI/Email.php
  95. +21 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php
  96. +68 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/URI/Host.php
  97. +39 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv4.php
  98. +99 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv6.php
  99. +56 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform.php
  100. +23 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/Background.php
  101. +19 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/BdoDir.php
  102. +23 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/BgColor.php
  103. +36 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/BoolToCSS.php
  104. +18 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/Border.php
  105. +58 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/EnumToCSS.php
  106. +43 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php
  107. +44 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php
  108. +40 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/Input.php
  109. +28 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/Lang.php
  110. +27 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/Length.php
  111. +21 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/Name.php
  112. +27 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/NameSync.php
  113. +41 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/Nofollow.php
  114. +15 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/SafeEmbed.php
  115. +16 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/SafeObject.php
  116. +64 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/SafeParam.php
  117. +16 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/ScriptRequired.php
  118. +18 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTransform/Textarea.php
  119. +77 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrTypes.php
  120. +162 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/AttrValidator.php
  121. +104 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Bootstrap.php
  122. +322 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/CSSDefinition.php
  123. +48 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ChildDef.php
  124. +48 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ChildDef/Chameleon.php
  125. +90 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ChildDef/Custom.php
  126. +20 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ChildDef/Empty.php
  127. +26 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ChildDef/Optional.php
  128. +117 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ChildDef/Required.php
  129. +88 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ChildDef/StrictBlockquote.php
  130. +142 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ChildDef/Table.php
  131. +709 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Config.php
  132. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigDef.php
  133. +55 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigDef/Directive.php
  134. +24 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigDef/DirectiveAlias.php
  135. +10 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigDef/Namespace.php
  136. +164 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema.php
  137. +44 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php
  138. +106 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php
  139. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/Exception.php
  140. +42 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange.php
  141. +77 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Directive.php
  142. +37 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Id.php
  143. +21 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Namespace.php
  144. +180 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php
  145. +206 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php
  146. +66 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
  147. BIN vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema.ser
  148. +8 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedClasses.txt
  149. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedFrameTargets.txt
  150. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRel.txt
  151. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRev.txt
  152. +19 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ClassUseCDATA.txt
  153. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultImageAlt.txt
  154. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImage.txt
  155. +8 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImageAlt.txt
  156. +10 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultTextDir.txt
  157. +16 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.EnableID.txt
  158. +8 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ForbiddenClasses.txt
  159. +5 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklist.txt
  160. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklistRegexp.txt
  161. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefix.txt
  162. +14 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefixLocal.txt
  163. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.txt
  164. +31 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.AutoParagraph.txt
  165. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.Custom.txt
  166. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.DisplayLinkURI.txt
  167. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.Linkify.txt
  168. +12 −0 ...r/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.DocURL.txt
  169. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.txt
  170. +11 −0 ...rs/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions.txt
  171. +15 −0 ...r/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.txt
  172. +46 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.txt
  173. +11 −0 ...vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveSpansWithoutAttributes.txt
  174. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.txt
  175. +12 −0 ...S/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormatParam.PurifierLinkifyDocURL.txt
  176. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormatParam.txt
  177. +8 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowImportant.txt
  178. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowTricky.txt
  179. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowedFonts.txt
  180. +18 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowedProperties.txt
  181. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.DefinitionRev.txt
  182. +13 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.ForbiddenProperties.txt
  183. +16 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.MaxImgLength.txt
  184. +10 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.Proprietary.txt
  185. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.Trusted.txt
  186. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.txt
  187. +14 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.DefinitionImpl.txt
  188. +13 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPath.txt
  189. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt
  190. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.txt
  191. +18 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AggressivelyFixLt.txt
  192. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.CollectErrors.txt
  193. +28 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.ColorKeywords.txt
  194. +14 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.ConvertDocumentToFragment.txt
  195. +17 −0 ...DS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.DirectLexLineNumberSyncInterval.txt
  196. +15 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.Encoding.txt
  197. +10 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt
  198. +7 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidTags.txt
  199. +13 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeNonASCIICharacters.txt
  200. +19 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.HiddenElements.txt
  201. +10 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.Language.txt
  202. +34 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.LexerImpl.txt
  203. +16 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.MaintainLineNumbers.txt
  204. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt
  205. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveInvalidImg.txt
  206. +11 −0 ...r/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveProcessingInstructions.txt
  207. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveScriptContents.txt
  208. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.txt
  209. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.Custom.txt
  210. +14 −0 .../IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Escaping.txt
  211. +29 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Scope.txt
  212. +16 −0 .../IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.TidyImpl.txt
  213. +74 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.txt
  214. +16 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.YouTube.txt
  215. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.txt
  216. +14 −0 .../vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksEscaping.txt
  217. +29 −0 ...IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksScope.txt
  218. +15 −0 .../vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksTidyImpl.txt
  219. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/FilterParam.txt
  220. +25 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Allowed.txt
  221. +19 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedAttributes.txt
  222. +23 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedElements.txt
  223. +20 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedModules.txt
  224. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Attr.Name.UseCDATA.txt
  225. +18 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.BlockWrapper.txt
  226. +23 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.CoreModules.txt
  227. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.CustomDoctype.txt
  228. +33 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionID.txt
  229. +16 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionRev.txt
  230. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Doctype.txt
  231. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.FlashAllowFullScreen.txt
  232. +21 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenAttributes.txt
  233. +20 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenElements.txt
  234. +14 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.MaxImgLength.txt
  235. +7 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Nofollow.txt
  236. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Parent.txt
  237. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Proprietary.txt
  238. +13 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeEmbed.txt
  239. +13 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeObject.txt
  240. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Strict.txt
  241. +8 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyAdd.txt
  242. +24 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyLevel.txt
  243. +8 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyRemove.txt
  244. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Trusted.txt
  245. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.XHTML.txt
  246. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.txt
  247. +10 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.CommentScriptContents.txt
  248. +15 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.FixInnerHTML.txt
  249. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.FlashCompat.txt
  250. +13 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.Newline.txt
  251. +14 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.SortAttr.txt
  252. +25 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.TidyFormat.txt
  253. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.txt
  254. +7 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Test.ForceNoIconv.txt
  255. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Test.txt
  256. +17 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.AllowedSchemes.txt
  257. +17 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Base.txt
  258. +10 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefaultScheme.txt
  259. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefinitionID.txt
  260. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefinitionRev.txt
  261. +14 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Disable.txt
  262. +11 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableExternal.txt
  263. +13 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableExternalResources.txt
  264. +15 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableResources.txt
  265. +19 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Host.txt
  266. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.HostBlacklist.txt
  267. +13 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MakeAbsolute.txt
  268. +83 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Munge.txt
  269. +17 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeResources.txt
  270. +30 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt
  271. +9 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.OverrideAllowedSchemes.txt
  272. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.txt
  273. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ConfigSchema/schema/info.ini
  274. +155 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ContentSets.php
  275. +82 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Context.php
  276. +50 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Definition.php
  277. +108 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCache.php
  278. +62 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator.php
  279. +43 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Cleanup.php
  280. +46 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Memory.php
  281. +47 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Template.php.in
  282. +39 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCache/Null.php
  283. +191 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer.php
  284. BIN ...purifier/HTMLPurifier/DefinitionCache/Serializer/CSS/4.1.0,801ad73acbcf9d3127e1d01768d26453,1.ser
  285. BIN ...urifier/HTMLPurifier/DefinitionCache/Serializer/HTML/4.1.0,ddc9b993d7fc8d4a185e8dbf5b9a0996,1.ser
  286. +3 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer/README
  287. BIN ...purifier/HTMLPurifier/DefinitionCache/Serializer/URI/4.0.0,05c766101e813c246917b022f97b5e6e,1.ser
  288. +91 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php
  289. +60 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Doctype.php
  290. +103 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/DoctypeRegistry.php
  291. +183 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ElementDef.php
  292. +426 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Encoder.php
  293. +44 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/EntityLookup.php
  294. +1 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/EntityLookup/entities.ser
  295. +144 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/EntityParser.php
  296. +209 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ErrorCollector.php
  297. +60 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/ErrorStruct.php
  298. +12 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Exception.php
  299. +46 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Filter.php
  300. +135 −0 vendor/IDS/vendors/htmlpurifier/HTMLPurifier/Filter/ExtractStyleBlocks.php
Sorry, we could not display the entire diff because too many files (410) changed.
View
5 .htaccess
@@ -0,0 +1,5 @@
+# in case PHPIDS is placed in the web-root
+deny from all
+
+# silence is golden
+php_flag display_errors off
View
30 LICENSE
@@ -0,0 +1,30 @@
+Copyright (c) 2012 to ZendExperts Team, see AUTHORS for more details.
+
+Some rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * The names of the contributors may not be used to endorse or
+ promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
82 Module.php
@@ -0,0 +1,82 @@
+<?php
+/**
+ * This file is part of ZeSecurity
+ *
+ * (c) 2012 ZendExperts <team@zendexperts.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace ZeSecurity;
+
+use Zend\ModuleManager\Feature\AutoloaderProviderInterface,
+ Zend\Mvc\MvcEvent,
+ IDS\MonitorFactory;
+
+/**
+ * ZeSecurity Module class
+ * @package ZeSecurity
+ * @author Cosmin Harangus <cosmin@zendexperts.com>
+ */
+class Module implements AutoloaderProviderInterface
+{
+ protected static $serviceManager = null;
+
+ public function onBootstrap(MvcEvent $event)
+ {
+ // Set the static service manager instance so we can use it everywhere in the module
+ $app = $event->getApplication();
+ self::$serviceManager = $app->getServiceManager();
+ $idsMonitor = self::$serviceManager->get('ZeSecurityIDS');
+
+ $idsMonitor->detect();
+ unset($idsMonitor);
+ }
+
+ /**
+ * Get Autoloader Config
+ * @return array
+ */
+ public function getAutoloaderConfig()
+ {
+ return array(
+ 'Zend\Loader\ClassMapAutoloader' => array(
+ __DIR__ . '/autoload/classmap.php',
+ ),
+ 'Zend\Loader\StandardAutoloader' => array(
+ 'namespaces' => array(
+ __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Get Service Configuration
+ * @return array
+ */
+ public function getServiceConfiguration(){
+ return include __DIR__ . '/config/service.config.php';
+ }
+
+ /**
+ * Get Module Configuration
+ * @return mixed
+ */
+ public function getConfig()
+ {
+ $config = include __DIR__ . '/config/module.config.php';
+ return $config;
+ }
+
+ /**
+ * Return the ServiceManager instance
+ * @static
+ * @return \Zend\ServiceManager\ServiceManager
+ */
+ public static function getServiceManager()
+ {
+ return static::$serviceManager;
+ }
+
+}
View
49 README.md
@@ -1,4 +1,51 @@
ZeSecurity
==========
-A ZF2 module that adds an out of the box security layer for your applications based on PHPIDS.
+ZeSecurity is a Zend Framework 2 module that integrates a security layer in your
+applications. It includes various components to manage security threats:
+
+IDS - Powered by [PHP IDS (Intrusion Detection System)](https://phpids.org/):
+-----------------------------------------------------------------------------
+
+This component scans any user input, be it sent via POST, GET or COOKIE and tries to see if the
+user input can be considered a threat. Any number of threat levels can be defined with various
+actions for each one via the configuration file.
+
+Using this component you can define multiple threat levels, what actions should be taken for each
+level and also register new plugins for handling attacks.
+
+Installation / Usage
+====================
+
+ZeSecurity can be installed using Composer by simply adding the following lines to your composer.json file:
+
+ "require": {
+ "ZendExperts/ZeSecurity": "1.0.*"
+ }
+
+Then run `php composer.phar update`.
+
+After the module is installed copy the "zesecurity.ids.global.php" file from "ZeSecurity/config/" in the "/config/autoload/" folder and
+modify the paths to temp, log or cache files:
+
+ // define used paths by ZeSecurity IDS
+ $ids = array(
+ 'log'=> __DIR__ . '/../../data/log/ze_security.ids.log',
+ 'tmp'=> __DIR__ . '/../../data/tmp/',
+ 'cache'=> __DIR__ . '/../../data/cache/ze_security.ids.cache'
+ );
+
+In the same configuration file a default range of attack levels is defined with various actions for each one.
+
+Feel free to change them per your needs or define new actions in the actions array. By default the following actions are defined:
+- ignore: Do nothing with the attack report
+- log: Save a log message in a stream, email, db, etc. depending on the writter factory param. Currently only stream/file and email are defined.
+- notify: Send an email with the report using the options defined in the actions array for this action.
+- redirect: Redirect to a specific URL.
+- clean_session: Destroy the session to log out any users. When used along with redirect you can log out any users and redirect them to a specic page.
+
+Documentation
+=============
+Comming soon.
+
+In the meanwhile please be sure to check out the [PHP IDS (Intrusion Detection System)](https://phpids.org/) documentation.
View
8 autoload/classmap.php
@@ -0,0 +1,8 @@
+<?php
+/**
+ * Generated Class-File Relation Config
+ */
+$prefix = dirname(__DIR__) . "";
+return array(
+
+);
View
12 autoload/function.php
@@ -0,0 +1,12 @@
+<?php
+return function ($class) {
+ static $map;
+ if (!$map) {
+ $map = include __DIR__ . '/classmap.php';
+ }
+
+ if (!isset($map[$class])) {
+ return false;
+ }
+ return include $map[$class];
+};
View
2 autoload/register.php
@@ -0,0 +1,2 @@
+<?php
+spl_autoload_register(include __DIR__ . '/function.php');
View
31 composer.json
@@ -0,0 +1,31 @@
+{
+ "name": "ZendExperts/ZeSecurity",
+ "type": "library",
+ "description": "ZeSecurity is a Zend Framework 2 module that adds an out of the box security layer for your applications based on PHPIDS(Intrusion Detection System)(https://phpids.org/).",
+ "keywords": ["module", "zf2", "security", "phpids"],
+ "homepage": "https://github.com/ZendExperts/ZeSecurity",
+ "license": "New BSD",
+ "authors": [
+ {
+ "name": "Cosmin Harangus",
+ "homepage": "http://www.zendexperts.com"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "autoload": {
+ "psr-0": {
+ "ZeSecurity": "src/",
+ "IDS_": "vendor/"
+ },
+ "classmap":[
+ "./"
+ ]
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ }
+}
View
72 config/module.config.php
@@ -0,0 +1,72 @@
+<?php
+return array(
+ 'zendexperts_security' => array(
+ 'IDS'=>array(
+ 'aggregate_in_session'=>true,
+ 'levels' =>array(),
+ 'actions' => array(
+ 'ignore' => array(
+ 'class' => 'ZeSecurity\IDS\Action\Ignore',
+ ),
+ 'redirect' => array(
+ 'class' => 'ZeSecurity\IDS\Action\Redirect',
+ 'options' => array(
+ 'url'=>'/'
+ )
+ ),
+ 'clean_session' => array(
+ 'class' => 'ZeSecurity\IDS\Action\CleanSession',
+ 'options'=> array(
+ 'send_expire_cookie' => true,
+ 'clear_storage' => true,
+ ),
+ )
+ ),
+ 'options'=>array(
+ 'General'=>array(
+ 'filter_type' => 'xml',
+ 'filter_path' => __DIR__ . '/../vendor/IDS/default_filter.xml',
+ // 'base_path' => __DIR__ . '/../vendor/IDS/',
+ 'use_base_path' => false,
+// 'tmp_path' => __DIR__ . '/../../../data/tmp/',
+ 'scan_keys' => false,
+ // in case you want to use a different HTMLPurifier source, specify it here
+ // By default, those files are used that are being shipped with PHPIDS
+ 'HTML_Purifier_Path' => 'vendors/htmlpurifier/HTMLPurifier.auto.php',
+ 'HTML_Purifier_Cache' => 'vendors/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer',
+ // define which fields contain html and need preparation before hitting the PHPIDS rules(new in PHPIDS 0.5)
+ 'html' => array(),
+ // define which fields contain JSON data and should be treated as such; for fewer false positives(new in PHPIDS 0.5.3)
+ 'json' => array(),
+ // define which fields shouldn't be monitored (a[b]=c should be referenced via a.b)
+ // you can use regular expressions for wildcard exceptions - example: /.*foo/i
+ 'exceptions' => array(
+ 'GET.__utmz',
+ 'GET.__utmc'
+ ),
+ 'min_php_version' => '5.1.6',
+ ),
+ 'Caching'=>array(
+ //caching: session|file|database|memcached|none
+ 'caching' => 'none',
+ 'expiration_time' => 600,
+// 'path' => __DIR__ . '/../../../data/cache/ze_security.ids.cache',
+// 'path' => 'tmp/default_filter.cache'
+ /**
+ ; database cache
+ wrapper = "mysql:host=localhost;port=3306;dbname=phpids"
+ user = phpids_user
+ password = 123456
+ table = cache
+
+ ; memcached
+ ;host = localhost
+ ;port = 11211
+ ;key_prefix = PHPIDS
+ */
+ ),
+ )
+ )
+ ),
+
+);
View
6 config/service.config.php
@@ -0,0 +1,6 @@
+<?php
+return array(
+ 'factories' => array(
+ 'ZeSecurityIDS' =>'ZeSecurity\IDS\MonitorFactory',
+ )
+);
View
104 config/zesecurity.ids.global.php
@@ -0,0 +1,104 @@
+<?php
+// define used paths by ZeSecurity IDS
+$ids = array(
+ 'log'=> __DIR__ . '/../../data/log/ze_security.ids.log',
+ 'tmp'=> __DIR__ . '/../../data/tmp/',
+ 'cache'=> __DIR__ . '/../../data/cache/ze_security.ids.cache'
+);
+
+return array(
+ 'zendexperts_security' => array(
+ 'IDS' => array(
+ 'aggregate_in_session' => true,
+ 'levels' => array(
+ 'unlikely' => array(
+ 'max_impact' => 5,
+ 'actions' => array(
+ '1st' => 'ignore'
+ )
+ ),
+ 'likely' => array(
+ 'max_impact' => 25,
+ 'actions' => array(
+ '1st' => 'log'
+ )
+ ),
+ 'attack' => array(
+ 'max_impact' => 50,
+ 'actions' => array(
+ '1st' => 'log',
+ '2nd' => 'redirect',
+ )
+ ),
+ 'threat' => array(
+ 'max_impact' => null,
+ 'actions' => array(
+ '1st' => 'log',
+ '2nd' => 'notify',
+ '4th' => 'clean_session',
+ '3rd' => 'redirect',
+ )
+ ),
+ ),
+ 'actions' => array(
+ 'log' => array(
+ 'class' => 'ZeSecurity\IDS\Action\Log',
+ 'options' => array(
+ // 'log_factory' => 'ZeSecurity\IDS\Action\Log\LogFactory',
+ 'writer_factory' => 'ZeSecurity\IDS\Action\Log\StreamFactory',
+ 'stream' => $ids['log'],
+ // 'formatter' => 'Zend\Log\Formatter\Simple',
+ // 'mode' => 'a',
+ ),
+ ),
+ 'notify' => array(
+ 'class' => 'ZeSecurity\IDS\Action\Log',
+ 'options' => array(
+ 'writer_factory' => 'ZeSecurity\IDS\Action\Log\EmailFactory',
+ 'from' => 'PHPIDS <security@example.com>',
+ 'to' => array(
+ 'webadmin@example.com',
+ ),
+ 'subject' => 'Intruder attack detected'
+ ),
+ )
+ ),
+ 'options' => array(
+ 'General' => array(
+ 'tmp_path' => $ids['tmp'],
+ 'scan_keys' => false,
+ // define which fields contain html and need preparation before hitting the PHPIDS rules(new in PHPIDS 0.5)
+ 'html' => array(),
+ // define which fields contain JSON data and should be treated as such; for fewer false positives(new in PHPIDS 0.5.3)
+ 'json' => array(),
+ // define which fields shouldn't be monitored (a[b]=c should be referenced via a.b)
+ // you can use regular expressions for wildcard exceptions - example: /.*foo/i
+ 'exceptions' => array(
+ 'GET.__utmz',
+ 'GET.__utmc'
+ ),
+ 'min_php_version' => '5.1.6',
+ ),
+ 'Caching' => array(
+ //caching: session|file|database|memcached|none
+ 'caching' => 'file',
+ 'expiration_time' => 600,
+ 'path' => $ids['cache'],
+ /**
+ ; database cache
+ wrapper = "mysql:host=localhost;port=3306;dbname=phpids"
+ user = phpids_user
+ password = 123456
+ table = cache
+
+ ; memcached
+ ;host = localhost
+ ;port = 11211
+ ;key_prefix = PHPIDS
+ */
+ ),
+ )
+ )
+ ),
+
+);
View
22 src/ZeSecurity/IDS/Action/AbstractAction.php
@@ -0,0 +1,22 @@
+<?php
+namespace ZeSecurity\IDS\Action;
+use IDS_Report;
+
+abstract class AbstractAction implements ActionInterface
+{
+ protected $config = null;
+
+ /**
+ * Set the configuration array for the action object
+ * @param array|null $config
+ */
+ public function setConfig($config)
+ {
+ $this->config = $config;
+ }
+
+ public function getConfig()
+ {
+ return $this->config;
+ }
+}
View
23 src/ZeSecurity/IDS/Action/ActionInterface.php
@@ -0,0 +1,23 @@
+<?php
+namespace ZeSecurity\IDS\Action;
+use IDS_Report,
+ ZeSecurity\IDS\Monitor;
+
+interface ActionInterface
+{
+ /**
+ * Set the configuration array for the action object
+ * @abstract
+ * @param array|null $config
+ */
+ public function setConfig($config);
+
+ /**
+ * @abstract
+ * @param IDS_Report $report
+ * @param int $impact
+ * @param string $level
+ * @return bool
+ */
+ public function run(IDS_Report $report, $impact, $level, Monitor $monitor = null);
+}
View
22 src/ZeSecurity/IDS/Action/CleanSession.php
@@ -0,0 +1,22 @@
+<?php
+namespace ZeSecurity\IDS\Action;
+use IDS_Report,
+ ZeSecurity\Module,
+ ZeSecurity\IDS\Monitor;
+
+class CleanSession extends AbstractAction
+{
+ /**
+ * @param IDS_Report $report
+ * @param int $impact
+ * @param string $level
+ * @return bool
+ */
+ public function run(IDS_Report $report, $impact, $level, Monitor $monitor = null)
+ {
+ $session = new \Zend\Session\SessionManager();
+ $session->destroy($this->config);
+ return false;
+ }
+
+}
View
19 src/ZeSecurity/IDS/Action/Ignore.php
@@ -0,0 +1,19 @@
+<?php
+namespace ZeSecurity\IDS\Action;
+use IDS_Report,
+ ZeSecurity\IDS\Monitor;
+
+class Ignore extends AbstractAction
+{
+ /**
+ * @param IDS_Report $report
+ * @param int $impact
+ * @param string $level
+ * @return bool
+ */
+ public function run(IDS_Report $report, $impact, $level, Monitor $monitor = null)
+ {
+ //do nothing
+ }
+
+}
View
60 src/ZeSecurity/IDS/Action/Log.php
@@ -0,0 +1,60 @@
+<?php
+namespace ZeSecurity\IDS\Action;
+use IDS_Report,
+ ZeSecurity\IDS\Monitor;
+
+class Log extends AbstractAction
+{
+ /**
+ * @todo Based on the configuration add a log entry in the registry
+ *
+ * @param IDS_Report $report
+ * @param int $impact
+ * @param string $level
+ * @return bool
+ */
+ public function run(IDS_Report $report, $impact, $level, Monitor $monitor = null)
+ {
+ if (isset($this->config['log_factory'])){
+ $factoryClass = $this->config['log_factory'];
+ }else{
+ $factoryClass = 'ZeSecurity\IDS\Action\Log\LogFactory';
+ }
+
+ $factory = new $factoryClass();
+ $log = $factory->create($this->config);
+
+ $origin = $_SERVER['SERVER_ADDR'];
+ $ip = $_SERVER['REMOTE_ADDR'] .
+ (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ?
+ ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')' : '');
+ $date = date('c');
+ $params = array();
+ foreach($report->getIterator() as $event){
+ $params[] = $event->getName() . '=' . $event->getValue();
+ }
+ $params = implode(', ', $params);
+ $requestURI = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8');
+ $tags = implode(' ', $report->getTags());
+ $actions = "log";
+ if ($monitor){
+ $conf = $monitor->getConfig();
+ $actions = implode(', ', $conf['levels'][$level]['actions']);
+ }
+ $log->alert(<<<END
+A possible attack has been detected by ZeSecurity IDS:
+IP: $ip
+Date: $date
+URI: $requestURI
+Tags: $tags
+Actions taken: $actions
+Origin: $origin
+Raised By:
+$params
+
+END
+);
+ return false;
+ }
+
+}
View
43 src/ZeSecurity/IDS/Action/Log/EmailFactory.php
@@ -0,0 +1,43 @@
+<?php
+namespace ZeSecurity\IDS\Action\Log;
+
+use Zend\Log\Writer\Mail;
+
+class EmailFactory implements FactoryInterface
+{
+ /**
+ * Factory method for creating an email log writer based on the configuration array
+ * @param array $config
+ * @return \Zend\Log\Writer\Mail
+ */
+ public function create($config)
+ {
+ $to = $config['to'];
+ $from = $config['from'];
+ $subject = $config['subject'];
+
+ //create the message object that should be sent
+ $message = new \Zend\Mail\Message();
+
+ //populate it with data based on the config
+ $message->setFrom($from);
+ $message->setSubject($subject);
+ if (is_string($to)) {
+ $to = array($to);
+ }
+ foreach ($to as $email) {
+ $message->addTo($email);
+ }
+
+ //create the log writer
+ $writer = new Mail($message);
+
+ //set up a formatter if present
+ if (isset($config['formatter'])) {
+ $formatter = new $config['formatter']();
+ $writer->setFormatter($formatter);
+ }
+ return $writer;
+ }
+
+}
View
12 src/ZeSecurity/IDS/Action/Log/FactoryInterface.php
@@ -0,0 +1,12 @@
+<?php
+namespace ZeSecurity\IDS\Action\Log;
+
+interface FactoryInterface
+{
+ /**
+ * Factory method for creating a log object
+ * @abstract
+ * @param array $config
+ */
+ public function create($config);
+}
View
23 src/ZeSecurity/IDS/Action/Log/LogFactory.php
@@ -0,0 +1,23 @@
+<?php
+namespace ZeSecurity\IDS\Action\Log;
+
+use Zend\Log\Logger;
+
+class LogFactory implements FactoryInterface
+{
+ /**
+ * Factory method for creating a log object
+ * @param array $config
+ * @return Zend\Log\Logger
+ */
+ public function create($config)
+ {
+ $factoryClass = $config['writer_factory'];
+ $factory = new $factoryClass();
+ $writer = $factory->create($config);
+ $logger = new Logger();
+ $logger->addWriter($writer);
+ return $logger;
+ }
+
+}
View
28 src/ZeSecurity/IDS/Action/Log/StreamFactory.php
@@ -0,0 +1,28 @@
+<?php
+namespace ZeSecurity\IDS\Action\Log;
+
+use Zend\Log\Writer\Stream;
+
+class StreamFactory implements FactoryInterface
+{
+ /**
+ * Factory method for creating a log object
+ * @param array $config
+ * @return \Zend\Log\Writer\Stream
+ */
+ public function create($config)
+ {
+ $stream = $config['stream'];
+ $mode = null;
+ if (isset($config['mode'])){
+ $mode = $config['mode'];
+ }
+ $writer = new Stream($stream, $mode);
+ if (isset($config['formatter'])) {
+ $formatter = new $config['formatter']();
+ $writer->setFormatter($formatter);
+ }
+ return $writer;
+ }
+
+}
View
25 src/ZeSecurity/IDS/Action/Redirect.php
@@ -0,0 +1,25 @@
+<?php
+namespace ZeSecurity\IDS\Action;
+use IDS_Report,
+ ZeSecurity\Module,
+ ZeSecurity\IDS\Monitor;
+
+class Redirect extends AbstractAction
+{
+ /**
+ * @param IDS_Report $report
+ * @param int $impact
+ * @param string $level
+ * @return bool
+ */
+ public function run(IDS_Report $report, $impact, $level, Monitor $monitor = null)
+ {
+ $service = Module::getServiceManager();
+ $application = $service->get('Application');
+ $response = $application->getResponse();
+ $response->headers()->addHeaderLine('Location', $this->config['url']);
+ $response->setStatusCode(302);
+ return true;
+ }
+
+}
View
189 src/ZeSecurity/IDS/Monitor.php
@@ -0,0 +1,189 @@
+<?php
+/**
+ * This file is part of ZeSecurity
+ *
+ * (c) 2012 ZendExperts <team@zendexperts.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace ZeSecurity\IDS;
+
+use Zend\Session\SessionManager,
+ IDS_Init,
+ IDS_Monitor,
+ IDS_Report,
+ ZeSecurity\Module;
+
+/**
+ * ZeSecurity IDS service monitor
+ * @package ZeSecurity
+ * @subpackage IDS
+ * @author Cosmin Harangus <cosmin@zendexperts.com>
+ */
+class Monitor
+{
+ protected $config = array();
+ protected $ids = null;
+ protected $actions = array();
+ private $events = null;
+
+ /**
+ * Constructor for the monitor. Sets the configuration array for the component and the PHPIDS dependency
+ * @param array $config
+ */
+ public function __construct($config = array())
+ {
+ $this->setConfig($config);
+ }
+
+ public function getConfig()
+ {
+ return $this->config;
+ }
+ public function setConfig($config)
+ {
+ $this->config = $config;
+ return $this;
+ }
+
+ /**
+ * Initialize the PHPIDS monitor
+ * @throws \Exception
+ */
+ public function initMonitor()
+ {
+ try {
+ $init = IDS_Init::init();
+ $init->setConfig($this->config['options']);
+ $request = $this->getRequest();
+ $this->ids = new IDS_Monitor($request, $init);
+ } catch (\Exception $e) {
+ //@todo Handle exception case
+ throw $e;
+ }
+ }
+
+ /**
+ * Detect a possible attack in the application from the user
+ * @throws \Exception
+ */
+ public function detect()
+ {
+ if (!$this->ids){
+ $this->initMonitor();
+ }
+
+ // run the monitor
+ try{
+ $report = $this->ids->run();
+ // if something found react
+ if (!$report->isEmpty()) {
+ $this->react($report);
+ }
+ }catch(\Exception $e){
+ //@todo Handle exception case
+ throw $e;
+ }
+ }
+
+ /**
+ * React to a potential threat by analyzing the generated report object
+ * @param IDS_Report $result
+ * @return boolean
+ */
+ protected function react(IDS_Report $report)
+ {
+ $impact = $this->aggregateImpactInSession($report);
+
+ $exit = false;
+ foreach ($this->config['levels'] as $level=>$options){
+ if ($options['max_impact']>=$impact || $options['max_impact']===null){
+ if (isset($options['actions'])){
+ foreach ($options['actions'] as $name){
+ if ($action = $this->getAction($name)){
+ $exit = $exit || $action->run($report, $impact, $level, $this);
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ //if an action needs to stop execution then return the response and exit
+ if ($exit){
+ Module::getServiceManager()->get('Application')->getResponse()->send();
+ exit();
+ }
+
+ return false;
+ }
+
+ /**
+ * Get an action instance by it's alias
+ *
+ * @param $name
+ * @return Action\ActionInterface | null
+ */
+ public function getAction($name)
+ {
+ // return it if it's already created
+ if (isset($this->actions[$name])){
+ return $this->actions[$name];
+ }
+ // if not found use the ignore action
+ if (!isset($this->config['actions'][$name])){
+ return null;
+ }else {
+ $config = $this->config['actions'][$name];
+ }
+
+ // configure the action and return it
+ $class = $config['class'];
+ $options = isset($config['options']) ? $config['options'] : null;
+ $action = new $class();
+ if ($options){
+ $action->setConfig($options);
+ }
+
+ $this->actions[$name] = $action;
+ return $action;
+ }
+
+ /**
+ * If configured aggregate the impact from the report in the session and return the updated value.
+ * @param IDS_Report $report
+ * @return int
+ */
+ protected function aggregateImpactInSession(IDS_Report $report)
+ {
+ if ($this->config['aggregate_in_session']) {
+ $sessionManager = new SessionManager();
+ $sessionManager->start();
+ $session = $sessionManager->getStorage();
+ if (!isset($session->ZeSecurityIDS)) {
+ $session->ZeSecurityIDS = array('impact' => 0);
+ }
+ $impact = $session->ZeSecurityIDS['impact'];
+ $impact += $report->getImpact();
+ $session->ZeSecurityIDS['impact'] = $impact;
+ } else {
+ $impact = $report->getImpact();
+ }
+ return $impact;
+ }
+
+ /**
+ * Returns an array with variables that should be tested for an potential attack
+ * @return array
+ */
+ protected function getRequest()
+ {
+ $request = array(
+ 'GET' => $_GET,
+ 'POST' => $_POST,
+ 'COOKIE' => $_COOKIE
+ );
+ return $request;
+ }
+}
View
35 src/ZeSecurity/IDS/MonitorFactory.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * This file is part of ZeSecurity
+ *
+ * (c) 2012 ZendExperts <team@zendexperts.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace ZeSecurity\IDS;
+
+use Zend\ServiceManager\FactoryInterface,
+ Zend\ServiceManager\ServiceLocatorInterface;
+
+/**
+ * ZeSecurity service monitor factory
+ * @package ZeSecurity
+ * @component IDS
+ * @author Cosmin Harangus <cosmin@zendexperts.com>
+ */
+class MonitorFactory implements FactoryInterface
+{
+ /**
+ * Factory method for ZeSecurity IDS Monitor service
+ *
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return Monitor
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ $config = $serviceLocator->get('Configuration');
+ $monitor = new Monitor($config['zendexperts_security']['IDS']);
+ return $monitor;
+ }
+}
View
22 src/ZeSecurity/IDS/Util/FormatNumbers.php
@@ -0,0 +1,22 @@
+<?php
+namespace ZeSecurity\IDS\Util;
+
+class FormatNumbers
+{
+ public static function addOrdinalNumberSuffix($num)
+ {
+ $ord = ($num % 100);
+ if ( !($ord== 11 || $ord==12 || $ord==13) ) {
+ switch ($ord % 10) {
+ // Handle 1st, 2nd, 3rd
+ case 1:
+ return $num . 'st';
+ case 2:
+ return $num . 'nd';
+ case 3:
+ return $num . 'rd';
+ }
+ }
+ return $num . 'th';
+ }
+}
View
5 vendor/IDS/.htaccess
@@ -0,0 +1,5 @@
+# in case PHPIDS is placed in the web-root
+deny from all
+
+# silence is golden
+php_flag display_errors off
View
84 vendor/IDS/Caching.php
@@ -0,0 +1,84 @@
+<?php
+
+/**
+ * PHPIDS
+ *
+ * Requirements: PHP5, SimpleXML
+ *
+ * Copyright (c) 2008 PHPIDS group (https://phpids.org)
+ *
+ * PHPIDS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PHPIDS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * PHP version 5.1.6+
+ *
+ * @category Security
+ * @package PHPIDS
+ * @author Mario Heiderich <mario.heiderich@gmail.com>
+ * @author Christian Matthies <ch0012@gmail.com>
+ * @author Lars Strojny <lars@strojny.net>
+ * @license http://www.gnu.org/licenses/lgpl.html LGPL
+ * @link http://php-ids.org/
+ */
+
+/**
+ * Caching factory
+ *
+ * This class is used as a factory to load the correct concrete caching
+ * implementation.
+ *
+ * @category Security
+ * @package PHPIDS
+ * @author Christian Matthies <ch0012@gmail.com>
+ * @author Mario Heiderich <mario.heiderich@gmail.com>
+ * @author Lars Strojny <lars@strojny.net>
+ * @copyright 2007-2009 The PHPIDS Group
+ * @license http://www.gnu.org/licenses/lgpl.html LGPL
+ * @version Release: $Id:Factory.php 517 2007-09-15 15:04:13Z mario $
+ * @link http://php-ids.org/
+ * @since Version 0.4
+ */
+class IDS_Caching
+{
+
+ /**
+ * Factory method
+ *
+ * @param object $init the IDS_Init object
+ * @param string $type the caching type
+ *
+ * @return object the caching facility
+ */
+ public static function factory($init, $type)
+ {
+
+ $object = false;
+ $wrapper = preg_replace(
+ '/\W+/m',
+ null,
+ ucfirst($init->config['Caching']['caching'])
+ );
+ $class = 'IDS_Caching_' . $wrapper;
+ $object = call_user_func(array($class, 'getInstance'),
+ $type, $init);
+ return $object;
+ }
+}
+
+/**
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 expandtab
+ */
View
149 vendor/IDS/Caching/Apc.php
@@ -0,0 +1,149 @@
+<?php
+/**
+ * PHPIDS
+ *
+ * Requirements: PHP5, SimpleXML
+ *
+ * Copyright (c) 2008 PHPIDS group (https://phpids.org)
+ *
+ * PHPIDS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PHPIDS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * PHP version 5.1.6+
+ *
+ * @category Security
+ * @package PHPIDS
+ * @author Mario Heiderich <mario.heiderich@gmail.com>
+ * @author Christian Matthies <ch0012@gmail.com>
+ * @author Lars Strojny <lars@strojny.net>
+ * @license http://www.gnu.org/licenses/lgpl.html LGPL
+ * @link http://php-ids.org/
+ */
+
+/**
+ * APC caching wrapper
+ *
+ * This class inhabits functionality to get and set cache via memcached.
+ *
+ * @category Security
+ * @package PHPIDS
+ * @author Yves Berkholz <godzilla80@gmx.net>
+ * @copyright 2007-2009 The PHPIDS Groupoup
+ * @license http://www.gnu.org/licenses/lgpl.html LGPL
+ * @version Release: $Id$
+ * @link http://php-ids.org/
+ * @since Version 0.6.5
+ */
+class IDS_Caching_Apc implements IDS_Caching_Interface
+{
+
+ /**
+ * Caching type
+ *
+ * @var string
+ */
+ private $type = null;
+
+ /**
+ * Cache configuration
+ *
+ * @var array
+ */
+ private $config = null;
+
+ /**
+ * Flag if the filter storage has been found in memcached
+ *
+ * @var boolean
+ */
+ private $isCached = false;
+
+ /**
+ * Holds an instance of this class
+ *
+ * @var object
+ */
+ private static $cachingInstance = null;
+
+
+ /**
+ * Constructor
+ *
+ * @param string $type caching type
+ * @param array $init the IDS_Init object
+ *
+ * @return void
+ */
+ public function __construct($type, $init)
+ {
+
+ $this->type = $type;
+ $this->config = $init->config['Caching'];
+ }
+
+ /**
+ * Returns an instance of this class
+ *
+ * @param string $type caching type
+ * @param object $init the IDS_Init object
+ *
+ * @return object $this
+ */
+ public static function getInstance($type, $init)
+ {
+
+ if (!self::$cachingInstance) {
+ self::$cachingInstance = new IDS_Caching_Apc($type, $init);
+ }
+
+ return self::$cachingInstance;
+ }
+
+ /**
+ * Writes cache data
+ *
+ * @param array $data the caching data
+ *
+ * @return object $this
+ */
+ public function setCache(array $data)
+ {
+ if(!$this->isCached)
+ apc_store($this->config['key_prefix'] . '.storage',
+ $data, $this->config['expiration_time']);
+ return $this;
+ }
+
+ /**
+ * Returns the cached data
+ *
+ * Note that this method returns false if either type or file cache is
+ * not set
+ *
+ * @return mixed cache data or false
+ */
+ public function getCache()
+ {
+ $data = apc_fetch($this->config['key_prefix'] . '.storage');
+ $this->isCached = !empty($data);
+ return $data;
+ }
+}
+
+/**
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 expandtab
+ */
View
289 vendor/IDS/Caching/Database.php
@@ -0,0 +1,289 @@
+<?php
+
+/**
+ * PHPIDS
+ *
+ * Requirements: PHP5, SimpleXML
+ *
+ * Copyright (c) 2008 PHPIDS group (https://phpids.org)
+ *
+ * PHPIDS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PHPIDS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * PHP version 5.1.6+
+ *
+ * @category Security
+ * @package PHPIDS
+ * @author Mario Heiderich <mario.heiderich@gmail.com>
+ * @author Christian Matthies <ch0012@gmail.com>
+ * @author Lars Strojny <lars@strojny.net>
+ * @license http://www.gnu.org/licenses/lgpl.html LGPL
+ * @link http://php-ids.org/
+ */
+
+/**
+ * Needed SQL:
+ *
+
+ #create the database
+
+ CREATE DATABASE IF NOT EXISTS `phpids` DEFAULT CHARACTER
+ SET utf8 COLLATE utf8_general_ci;
+ DROP TABLE IF EXISTS `cache`;
+
+ #now select the created datbase and create the table
+
+ CREATE TABLE `cache` (
+ `type` VARCHAR( 32 ) NOT null ,
+ `data` TEXT NOT null ,
+ `created` DATETIME NOT null ,
+ `modified` DATETIME NOT null
+ ) ENGINE = MYISAM ;
+ */
+
+/**
+ * Database caching wrapper
+ *
+ * This class inhabits functionality to get and set cache via a database.
+ *
+ * @category Security
+ * @package PHPIDS
+ * @author Christian Matthies <ch0012@gmail.com>
+ * @author Mario Heiderich <mario.heiderich@gmail.com>
+ * @author Lars Strojny <lars@strojny.net>
+ * @copyright 2007-2009 The PHPIDS Groupup
+ * @license http://www.gnu.org/licenses/lgpl.html LGPL
+ * @version Release: $Id:Database.php 517 2007-09-15 15:04:13Z mario $
+ * @link http://php-ids.org/
+ * @since Version 0.4
+ */
+class IDS_Caching_Database implements IDS_Caching_Interface
+{
+
+ /**
+ * Caching type
+ *
+ * @var string
+ */
+ private $type = null;
+
+ /**
+ * Cache configuration
+ *
+ * @var array
+ */
+ private $config = null;
+
+ /**
+ * DBH
+ *
+ * @var object
+ */
+ private $handle = null;
+
+ /**
+ * Holds an instance of this class
+ *
+ * @var object
+ */
+ private static $cachingInstance = null;
+
+ /**
+ * Constructor
+ *
+ * Connects to database.
+ *
+ * @param string $type caching type
+ * @param object $init the IDS_Init object
+ *
+ * @return void
+ */
+ public function __construct($type, $init)
+ {
+
+ $this->type = $type;
+ $this->config = $init->config['Caching'];
+ $this->handle = $this->_connect();
+ }
+
+ /**
+ * Returns an instance of this class
+ *
+ * @static
+ * @param string $type caching type
+ * @param object $init the IDS_Init object
+ *
+ * @return object $this
+ */
+ public static function getInstance($type, $init)
+ {
+
+ if (!self::$cachingInstance) {
+ self::$cachingInstance = new IDS_Caching_Database($type, $init);
+ }
+ return self::$cachingInstance;
+ }
+
+ /**
+ * Writes cache data into the database
+ *
+ * @param array $data the caching data
+ *
+ * @throws PDOException if a db error occurred
+ * @return object $this
+ */
+ public function setCache(array $data)
+ {
+
+ $handle = $this->handle;
+
+ $rows = $handle->query('SELECT created FROM `' .
+ $this->config['table'].'`');
+
+ if (!$rows || $rows->rowCount() === 0) {
+
+ $this->_write($handle, $data);
+ } else {
+
+ foreach ($rows as $row) {
+
+ if ((time()-strtotime($row['created'])) >
+ $this->config['expiration_time']) {
+
+ $this->_write($handle, $data);
+ }
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Returns the cached data
+ *
+ * Note that this method returns false if either type or file cache is
+ * not set
+ *
+ * @throws PDOException if a db error occurred
+ * @return mixed cache data or false
+ */
+ public function getCache()
+ {
+
+ try{
+ $handle = $this->handle;
+ $result = $handle->prepare('SELECT * FROM `' .
+ $this->config['table'] .
+ '` where type=?');
+ $result->execute(array($this->type));
+
+ foreach ($result as $row) {
+ return unserialize($row['data']);
+ }
+
+ } catch (PDOException $e) {
+ throw new PDOException('PDOException: ' . $e->getMessage());
+ }
+ return false;
+ }
+
+ /**
+ * Connect to database and return a handle
+ *
+ * @return object PDO
+ * @throws Exception if connection parameters are faulty
+ * @throws PDOException if a db error occurred
+ */
+ private function _connect()
+ {
+
+ // validate connection parameters
+ if (!$this->config['wrapper']
+ || !$this->config['user']
+ || !$this->config['password']
+ || !$this->config['table']) {
+
+ throw new Exception('
+ Insufficient connection parameters'
+ );
+ }
+
+ // try to connect
+ try {
+ $handle = new PDO(
+ $this->config['wrapper'],
+ $this->config['user'],
+ $this->config['password']
+ );
+ $handle->setAttribute(
+ PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true
+ );
+
+ } catch (PDOException $e) {
+ throw new PDOException('PDOException: ' . $e->getMessage());
+ }
+ return $handle;
+ }
+
+ /**
+ * Write the cache data to the table
+ *
+ * @param object $handle the database handle
+ * @param array $data the caching data
+ *
+ * @return object PDO
+ * @throws PDOException if a db error occurred
+ */
+ private function _write($handle, $data)
+ {
+
+ try {
+ $handle->query('TRUNCATE ' .
+ $this->config['table'].'');
+ $statement = $handle->prepare('
+ INSERT INTO `' .
+ $this->config['table'].'` (
+ type,
+ data,
+ created,
+ modified
+ )
+ VALUES (
+ :type,
+ :data,
+ now(),
+ now()
+ )
+ ');
+
+ $statement->bindParam('type',
+ $handle->quote($this->type));
+ $statement->bindParam('data', serialize($data));
+
+ if (!$statement->execute()) {
+ throw new PDOException($statement->errorCode());
+ }
+
+ } catch (PDOException $e) {
+ throw new PDOException('PDOException: ' . $e->getMessage());
+ }
+ }
+}
+
+/**
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 expandtab
+ */
View
185 vendor/IDS/Caching/File.php
@@ -0,0 +1,185 @@
+<?php
+
+/**
+ * PHPIDS
+ *
+ * Requirements: PHP5, SimpleXML
+ *
+ * Copyright (c) 2008 PHPIDS group (https://phpids.org)
+ *
+ * PHPIDS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PHPIDS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * PHP version 5.1.6+
+ *
+ * @category Security
+ * @package PHPIDS
+ * @author Mario Heiderich <mario.heiderich@gmail.com>
+ * @author Christian Matthies <ch0012@gmail.com>
+ * @author Lars Strojny <lars@strojny.net>
+ * @license http://www.gnu.org/licenses/lgpl.html LGPL
+ * @link http://php-ids.org/
+ */
+
+/**
+ * File caching wrapper
+ *
+ * This class inhabits functionality to get and set cache via a static flatfile.
+ *
+ * @category Security
+ * @package PHPIDS
+ * @author Christian Matthies <ch0012@gmail.com>
+ * @author Mario Heiderich <mario.heiderich@gmail.com>
+ * @author Lars Strojny <lars@strojny.net>
+ * @copyright 2007-2009 The PHPIDS Group
+ * @license http://www.gnu.org/licenses/lgpl.html LGPL
+ * @version Release: $Id:File.php 517 2007-09-15 15:04:13Z mario $
+ * @link http://php-ids.org/
+ * @since Version 0.4
+ */
+class IDS_Caching_File implements IDS_Caching_Interface
+{
+
+ /**
+ * Caching type
+ *
+ * @var string
+ */
+ private $type = null;
+
+ /**
+ * Cache configuration
+ *
+ * @var array
+ */
+ private $config = null;