Created
July 24, 2013 08:26
-
-
Save ilmsg/6068883 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Pikachu.js | |
| // 테러범들에겐 백만볼트! | |
| // 사용법__________________________ | |
| // 사용법은 간단하다. "var pikachu = require("Pikachu.js");"로 초기화 한 후 http.createServer에다가 붙여주면 된다. | |
| // req와 res는 알다시피 request와 response. :) | |
| // 특정 사이트에서 공격이 들어온다거나 할 때 http referer를 바탕으로 검열(?!) 쯤 해준다고 보면 된다. | |
| // 차단하기 쉽도록 유명한 사이트들은 미리 정규표현식을 만들어놨다. 필요할 때 요긴하게 쓸 수 있다. | |
| exports.dcinside = '/(.+?)dcinside.com/'; | |
| exports.todayhumor = '/(.+?)todayhumor.co.kr/'; | |
| exports.ilbe = '/(.+?)ilbe.com/'; | |
| function Pikachu(req, regex){ | |
| var referer = req.headers['referer'] || req.headers['referrer']; | |
| if(referer != undefined){ | |
| if(referer.match(regex)) return true; | |
| } | |
| else return false; | |
| } | |
| // 해당 정규식과, url에 맞춰 referer가 정규식에 맞다면 url로 리다이렉트 시켜준다. | |
| exports.thunder = function(req, res, regex, url){ | |
| if(Pikachu(req, regex)){ | |
| res.writeHead(301, {Location: url}); | |
| res.end(); | |
| } | |
| } | |
| // referer가 정규식에 맞다면 warning.or.kr로 보내버린다. | |
| exports.volttackle = function(req, res, regex){ | |
| if(Pikachu(req, regex)){ | |
| res.writeHead(301, {Location: 'http://warning.or.kr'}); | |
| res.end(); | |
| } | |
| } | |
| // 일베, 오유, 디씨인사이드에서 들어오는 것들을 모두 warning.or.kr로 보내버린다. | |
| exports.millionvolt = function(req, res){ | |
| var redirect = false; | |
| if(Pikachu(req, '/(.+?)dcinside.com/')) redirect = true; | |
| else if (Pikachu(req, '/(.+?)ilbe.com/')) redirect = true; | |
| else if (Pikachu(req, '/(.+?)todayhumor.co.kr/')) redirect = true; | |
| if(redirect){ | |
| res.writeHead(301, {Location: 'http://warning.or.kr'}); | |
| res.end(); | |
| } | |
| } | |
| // 사실은 디버깅용인데, 클라이언트에 referer 정보를 가져오려고 쓰는 것이다. | |
| // Console에 로그가 남도록 되어있으니 디버깅할 때 참고하면 좋을 것이다. | |
| exports.irontail = function(req){ | |
| var referer = req.headers['referer'] || req.headers['referrer']; | |
| if(referer != undefined) console.log("Client's referer data is " + referer + "."); | |
| else console.log("Client's referer is undefined."); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment