Created
February 28, 2012 18:58
-
-
Save leafo/1934385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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