Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing banner - damn you async

  • Loading branch information...
commit f97e7a10ec39013fe249c5e989d08c0ffea45532 1 parent 5d45147
Nicholas Kinsey authored
Showing with 57 additions and 58 deletions.
  1. +1 −1  BANNER
  2. +56 −57 proxy.coffee
View
2  BANNER
@@ -3,4 +3,4 @@ ___ __ )__(_)______ ___ __ )______________ /___ /______________
__ __ |_ /__ __ `/_ __ |_ ___/ __ \ __/_ __ \ _ \_ ___/
_ /_/ /_ / _ /_/ /_ /_/ /_ / / /_/ / /_ _ / / / __/ /
/_____/ /_/ _\__, / /_____/ /_/ \____/\__/ /_/ /_/\___//_/
- /____/
+ /____/
View
113 proxy.coffee
@@ -6,83 +6,82 @@ vm = require 'vm'
util = require 'util'
colors = require 'colors'
-rapid = require 'rapid'
-request = require 'request'
-# {gist} = require 'gist'
{Hit} = require './hit'
-#process.on 'uncaughtException', ->
-# console.log 'error'
+#process.on 'uncaughtException', (e) ->
+# console.dir e
port = process.argv[2] or 8080
db = ip: new Object, host: new Object, url: new Object
-console.log fs.readFileSync('BANNER', 'utf8').rainbow.bold
+process.stdin.write fs.readFileSync('BANNER', 'utf8').bold, ->
+ server = http.createServer (request, response) ->
+ save = -> true
-server = http.createServer (request, response) ->
- save = -> true
+ hit = new Hit
+ date: new Date
+ method: request.method
+ url: request.url
+ host: url.parse(request.url).hostname
+ ip: request.connection.remoteAddress
+ status: 'init'
- hit = new Hit
- date: new Date
- method: request.method
- url: request.url
- host: url.parse(request.url).hostname
- ip: request.connection.remoteAddress
- status: 'init'
-
- hit.save save
-
- timeout = setTimeout((->
- console.log "[Timeout]".red + ' ' + "#{request.connection.remoteAddress} #{request.method} #{request.url}"
- response.writeHead 404 #ToDo: Add correct HTTP error code 'timeout'
- response.end()
- hit.status = 'timeout'
hit.save save
- ), 30 * 1000)
- deny = (reason) ->
- console.log "[Denied]".red + ' ' + "[#{reason}]".red + ' ' + "#{request.connection.remoteAddress} #{request.method} #{request.url}"
- response.writeHead 403
- response.end()
- hit.status = reason
- hit.save save
- clearTimeout timeout
+ timeout = setTimeout((->
+ console.log "[Timeout]".red + ' ' + "#{request.connection.remoteAddress} #{request.method} #{request.url}"
+ response.writeHead 404 #ToDo: Add correct HTTP error code 'timeout'
+ response.end()
+ hit.status = 'timeout'
+ hit.save save
+ ), 30 * 1000)
- if db.ip[request.connection.remoteAddress]
- deny 'ip'
- return
+ deny = (reason) ->
+ console.log "[Denied]".red + ' ' + "[#{reason}]".red + ' ' + "#{request.connection.remoteAddress} #{request.method} #{request.url}"
+ response.writeHead 403
+ response.end()
+ hit.status = reason
+ hit.save save
+ clearTimeout timeout
+
+ # NODE this is where one would apply filters
- for host, regex of db.host
- if RegExp(host).test request.url
- deny 'host'
+ if db.ip[request.connection.remoteAddress]
+ deny 'ip'
return
- console.log "#{request.connection.remoteAddress} #{request.method} #{request.url}"
- proxy = http.createClient url.parse(request.url).port || 80, request.headers.host
- proxy_request = proxy.request request.method, request.url, request.headers
- proxy_request.addListener 'response', (proxy_response) ->
- proxy_response.addListener 'data', (chunk) ->
- response.write chunk, 'binary'
+ for host, regex of db.host
+ if RegExp(host).test request.url
+ deny 'host'
+ return
+
+ console.log "#{request.connection.remoteAddress} #{request.method} #{request.url}"
+ proxy = http.createClient url.parse(request.url).port || 80, request.headers.host
+ proxy_request = proxy.request request.method, request.url, request.headers
+ proxy_request.addListener 'response', (proxy_response) ->
+ proxy_response.addListener 'data', (chunk) ->
+ # NOTE this is where one would capture raw response content
+ response.write chunk, 'binary'
- proxy_response.addListener 'end', ->
- response.end()
+ proxy_response.addListener 'end', ->
+ response.end()
- response.writeHead proxy_response.statusCode, proxy_response.headers
- hit.status = 'success'
- hit.save save
- clearTimeout timeout
+ response.writeHead proxy_response.statusCode, proxy_response.headers
+ hit.status = 'success'
+ hit.save save
+ clearTimeout timeout
- request.addListener 'data', (chunk) ->
- proxy_request.write chunk, 'binary'
+ request.addListener 'data', (chunk) ->
+ proxy_request.write chunk, 'binary'
- request.addListener 'end', ->
- proxy_request.end()
+ request.addListener 'end', ->
+ proxy_request.end()
-server.listen port
+ server.listen port
-console.log "BigBrother listening on #{port}...".cyan
+ console.log "BigBrother listening on #{port}...".cyan
-repl = require './repl'
-repl.init db
+ repl = require './repl'
+ repl.init db
Please sign in to comment.
Something went wrong with that request. Please try again.