/** Checking to see if IP is banned */ this.app.use((req, res, next) => { const userIP = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress; const exists = this.db.get('bans').find({ ip: userIP }).value(); if (exists === undefined) { // if a ban was not found, then it will move on next(); } else { res.statusCode = 401; res.render('unauthorized'); return res.end(); } });
app.get('/authenticate', (req, res) => { const cert = req.socket.getPeerCertificate(); if (req.client.authorized) { res.send(`Hello ${cert.subject.CN}, your certificate was issued by ${cert.issuer.CN}!`); } else if (cert.subject) { res.status(403) .send(`Sorry ${cert.subject.CN}, certificates from ${cert.issuer.CN} are not welcome here.`); } else { res.status(401) .send(`Sorry, but you need to provide a client certificate to continue.`); } });
router.get('/', function(req, res, next) { res.render('index.html',{port:req.socket.localPort}); });
app.use(function (req, res, next) { if (!req.headers['x-forwarded-for']) { req.headers['x-forwarded-for'] = '0.0.0.0'; } req.visitor.pageview({ dp: req.originalUrl, dr: req.get('Referer'), ua: req.headers['user-agent'], uip: req.connection.remoteAddress || req.socket.remoteAddress || req.connection.remoteAddress || req.headers['x-forwarded-for'].split(',').pop() }).send() next(); });
test('request', function (t) { resetAgent(function (data) { t.strictEqual(data.transactions.length, 2) t.strictEqual(data.spans.length, 1) var sub = data.transactions[0] t.strictEqual(sub.name, 'GET /test') var root = data.transactions[1] t.strictEqual(root.name, 'GET /') const span = findObjInArray(data.spans, 'transaction_id', root.id) t.strictEqual(span.name, 'GET localhost:' + server.address().port + '/test') server.close() t.end() }) var app = express() var server = http.createServer(app) app.get('/test', (req, res) => { res.end('hello') }) app.get('/', (req, res) => { request(`http://localhost:${req.socket.localPort}/test`).pipe(res) }) sendRequest(server) })
this.app.use((req, res, next) => { if (req.method === 'POST') { const userIP = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress; if (ratelimited.has(userIP)) { res.statusCode = 429; res.write('Error 429: Ratelimited'); return res.end(); } next(); // Move on if IP is not in ratelimited set ratelimited.add(userIP); // delete IP from ratelimit set after time specified in config.json setTimeout(() => ratelimited.delete(userIP), c.ratelimit); } else { next(); // move on if request type is not POST } });
app.get('/', (req, res) => { publishClient.publish('REQUESTS', `Request on ${req.socket.localPort} for ${req.url}`); console.log(`Local log for ${req.url}`); });
app.post("/api/v1/sessions/forget", function(req, res) { res.setHeader('Content-Type', 'application/json'); var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress; var bundle = { ip: ip, client: req.headers['user-agent'], address: req.body.address.replace(/-/g, ''), }; Authenticator.expireActiveSession(bundle, function(session) { if (!session) { return res.send(JSON.stringify({ "status": "error", "code": AuthErrors.E_SERVER_ERROR, "error": "E_SERVER_ERROR" })); } return res.send(JSON.stringify({ "status": "ok", "code": AuthErrors.E_SESSION_EXPIRED })); }); });
req.socket.bytesRead, 'process:', process.pid);