Skip to content

Instantly share code, notes, and snippets.

@leafo
Created February 28, 2012 18:58
Show Gist options
  • Save leafo/1934385 to your computer and use it in GitHub Desktop.
Save leafo/1934385 to your computer and use it in GitHub Desktop.
port = 8989
http = require "http"
spawn = require("child_process").spawn
banned = [
# "172.16.22.195"
# "172.16.22.149"
# "172.16.22.166"
# "172.16.22.98"
]
server = http.createServer (req, res)->
input = ""
if req.url == "/say" and req.method == "POST"
req.on "data", (chunk) -> input += chunk
req.on "end", ->
if 0 <= banned.indexOf req.connection.remoteAddress
console.log "Stopping #{req.connection.remoteAddress}"
res.end "You are banned"
return
if input != ""
input = input.substr 0, 160
console.log "Saying: #{input} #{req.connection.remoteAddress}"
spawn "say", [input]
res.end "Got: #{input}\n"
else
res.end "Don't know!\n"
server.listen port
console.log "Running on port #{port}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment