Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- var createHmac = require('crypto').createHmac;
- var https = require('https');
- var http = require('http');
- var stringify = require('querystring').stringify;
- var url = require('url');
- var APP_KEY = 'xxfvFQcOzpTBvwuwPMwwzLZxiCSaGb';
- var HM_KEY = 'DgQ3aNpoluV1cl3GFJAqitBg5xKiXZ';
- var PORT = 8088;
- var headerList = [
- 'accept-encoding',
- 'if-modified-since',
- 'range'
- ];
- var _sid;
- function authenticate() {
- var ct = '1234567890';
- var message = APP_KEY + ct;
- var hb = createHmac('sha256', HM_KEY).update(message).digest('hex');
- var data = { ID: '', PW: '', KY: APP_KEY, CT: ct, HB: hb };
- var headers = {
- 'User-Agent': '',
- 'X-2ch-UA': 'JaneStyle/3.80',
- 'Content-Type': 'application/x-www-form-urlencoded'
- };
- var options = {
- 'method': 'POST',
- 'hostname': 'api.2ch.net',
- 'path': '/v1/auth/',
- 'headers': headers
- };
- https.request(options, function(response) {
- var buf = '';
- response.on('data', function(d) { buf += d; });
- response.on('end', function() { _sid = buf.split(':')[1]; });
- }).end(stringify(data));
- }
- authenticate();
- var server = http.createServer(function(req, res) {
- var o = url.parse(req.url);
- if (o.href.match(/http:\/\/(\w+)\.2ch\.net\/(\w+)\/dat\/(\d+)\.dat/)) {
- var server = RegExp.$1;
- var board = RegExp.$2;
- var threadID = RegExp.$3;
- var message = '/v1/' + server + '/' + board + '/' + threadID;
- message += _sid + APP_KEY;
- var hobo = createHmac('sha256', HM_KEY).update(message).digest('hex');
- var data = { sid: _sid, hobo: hobo, appkey: APP_KEY };
- var headers = {
- 'user-agent': 'Mozilla/3.0 (compatible; JaneStyle/3.80..)',
- 'content-type': 'application/x-www-form-urlencoded'
- };
- headerList.forEach(function(key) {
- if (key in req.headers) headers[key] = req.headers[key];
- });
- var options = {
- 'method': 'POST',
- 'hostname': 'api.2ch.net',
- 'path': '/v1/' + server + '/' + board + '/' + threadID,
- 'headers': headers
- };
- return https.request(options, function(response) {
- res.writeHead(response.statusCode, response.headers);
- response.pipe(res);
- }).end(stringify(data));
- }
- o.method = req.method;
- o.headers = req.headers;
- req.pipe(http.request(o, function(response) {
- res.writeHead(response.statusCode, response.headers);
- response.pipe(res);
- }));
- });
- server.on('clientError', function(err, sock) {
- console.log(err);
- sock.end();
- });
- server.listen(PORT, function() {
- console.log('proxy server is listening on port %d', server.address().port);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement