<commit_before>"use strict"

path          = require "path"

ZEN           = require "./zen.config"
CONST         = require "./zen.constants"
zenrequest    = require "./zen.request"
zenresponse   = require "./zen.response"

if ZEN.firewall?
  fs            = require "fs"
  path_firewall = "#{__dirname}/../../../firewall"
  file_name     = "#{path_firewall}/blacklist.json"
  blacklist     = {}
  fs.mkdirSync path_firewall unless fs.existsSync path_firewall
  fs.readFile file_name, "utf8", (error, data) =>
    ZEN.blacklist = if error or data?.length is 0 then {} else JSON.parse data

module.exports = (request, response) ->
  valid = true

  # Blacklist block
  if ZEN.firewall?
    request.ip = zenrequest.ip request
    if parseInt(ZEN.blacklist?[request.ip]) >= 10
      valid = false
      response.writeHead 403
      response.end()

  # Middleware
  response.request = url: request.url, method: request.method, at: new Date()
  response[method] = callback for method, callback of zenresponse
  response.setTimeout ZEN.timeout, -> response.requestTimeout()
  request.session = response.request.session  = zenrequest.session request
  request.agent = response.request.agent = zenrequest.agent request
  request.mobile = response.request.mobile = zenrequest.mobile request
  response.request.ip = request.ip<commit_msg>Block IP if rule is defined or default numbers of query<commit_after>"use strict"

path          = require "path"

ZEN           = require "./zen.config"
CONST         = require "./zen.constants"
zenrequest    = require "./zen.request"
zenresponse   = require "./zen.response"

if ZEN.firewall?
  fs            = require "fs"
  path_firewall = "#{__dirname}/../../../firewall"
  file_name     = "#{path_firewall}/blacklist.json"
  blacklist     = {}
  fs.mkdirSync path_firewall unless fs.existsSync path_firewall
  fs.readFile file_name, "utf8", (error, data) =>
    ZEN.blacklist = if error or data?.length is 0 then {} else JSON.parse data

module.exports = (request, response) ->
  valid = true

  # Blacklist block
  if ZEN.firewall?
    request.ip = zenrequest.ip request
    if parseInt(ZEN.blacklist?[request.ip]) >= (ZEN.firewall.ip or 10)
      valid = false
      response.writeHead 403
      response.end()

  # Middleware
  response.request = url: request.url, method: request.method, at: new Date()
  response[method] = callback for method, callback of zenresponse
  response.setTimeout ZEN.timeout, -> response.requestTimeout()
  request.session = response.request.session  = zenrequest.session request
  request.agent = response.request.agent = zenrequest.agent request
  request.mobile = response.request.mobile = zenrequest.mobile request
  response.request.ip = request.ip
{'fraction_non_alphanumeric': 0.11695476278043399, 'fraction_numerical': 0.0051489518205222505, 'mean_word_length': 3.2170542635658914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6238732', 'n_tokens_mistral': 827, 'n_tokens_neox': 812, 'n_words': 213}