Changeset View
Changeset View
Standalone View
Standalone View
support/aphlict/server/aphlict_server.js
| Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | |||||
| var messages_out = 0; | var messages_out = 0; | ||||
| var messages_in = 0; | var messages_in = 0; | ||||
| var start_time = new Date().getTime(); | var start_time = new Date().getTime(); | ||||
| var receive_server = http.createServer(function(request, response) { | var receive_server = http.createServer(function(request, response) { | ||||
| // Publishing a notification. | // Publishing a notification. | ||||
| if (request.url == '/') { | |||||
| if (request.method == 'POST') { | if (request.method == 'POST') { | ||||
| var body = ''; | var body = ''; | ||||
| request.on('data', function(data) { | request.on('data', function(data) { | ||||
| body += data; | body += data; | ||||
| }); | }); | ||||
| request.on('end', function() { | request.on('end', function() { | ||||
| try { | try { | ||||
| var msg = JSON.parse(body); | var msg = JSON.parse(body); | ||||
| debug.log('notification: ' + JSON.stringify(msg)); | debug.log('notification: ' + JSON.stringify(msg)); | ||||
| ++messages_in; | ++messages_in; | ||||
| transmit(msg); | transmit(msg); | ||||
| response.writeHead(200, {'Content-Type': 'text/plain'}); | response.writeHead(200, {'Content-Type': 'text/plain'}); | ||||
| } catch (err) { | } catch (err) { | ||||
| debug.log( | debug.log( | ||||
| '<%s> Bad Request! %s', | '<%s> Bad Request! %s', | ||||
| request.socket.remoteAddress, | request.socket.remoteAddress, | ||||
| err); | err); | ||||
| response.statusCode = 400; | response.statusCode = 400; | ||||
| response.write('400 Bad Request'); | response.write('400 Bad Request\n'); | ||||
| } finally { | } finally { | ||||
| response.end(); | response.end(); | ||||
| } | } | ||||
| }); | }); | ||||
| } else { | |||||
| response.statusCode = 405; | |||||
| response.write('405 Method Not Allowed\n'); | |||||
| response.end(); | |||||
| } | |||||
epriestley: This possibly being a bad assumption is the only thing I can imagine being an issue here… | |||||
Not Done Inline ActionsHmm yeah I know. You're right actually, see code below. Currently, someone could set notification.server-uri to 'http://localhost:22281/foobar/' and everything should work fine. This is sort of gross and we should maybe add a setup check to ensure that the notifications server URI has no path component. private static function postMessage(array $data) { $server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri'); id(new HTTPSFuture($server_uri, json_encode($data))) ->setMethod('POST') ->setTimeout(1) ->resolvex(); } joshuaspence: Hmm yeah I know. You're right actually, see code below. Currently, someone could set… | |||||
| } else if (request.url == '/status/') { | } else if (request.url == '/status/') { | ||||
| request.on('data', function() { | request.on('data', function() { | ||||
| // We just ignore the request data, but newer versions of Node don't | // We just ignore the request data, but newer versions of Node don't | ||||
| // get to 'end' if we don't process the data. See T2953. | // get to 'end' if we don't process the data. See T2953. | ||||
| }); | }); | ||||
| request.on('end', function() { | request.on('end', function() { | ||||
| var status = { | var status = { | ||||
| 'uptime': (new Date().getTime() - start_time), | 'uptime': (new Date().getTime() - start_time), | ||||
| 'clients.active': clients.getActiveListenerCount(), | 'clients.active': clients.getActiveListenerCount(), | ||||
| 'clients.total': clients.getTotalListenerCount(), | 'clients.total': clients.getTotalListenerCount(), | ||||
| 'messages.in': messages_in, | 'messages.in': messages_in, | ||||
| 'messages.out': messages_out, | 'messages.out': messages_out, | ||||
| 'log': config.log, | 'log': config.log, | ||||
| 'version': 6 | 'version': 6 | ||||
| }; | }; | ||||
| response.writeHead(200, {'Content-Type': 'text/plain'}); | response.writeHead(200, {'Content-Type': 'text/plain'}); | ||||
| response.write(JSON.stringify(status)); | response.write(JSON.stringify(status)); | ||||
| response.end(); | response.end(); | ||||
| }); | }); | ||||
| } else { | } else { | ||||
| response.statusCode = 400; | response.statusCode = 404; | ||||
| response.write('400 Bad Request'); | response.write('404 Not Found\n'); | ||||
| response.end(); | response.end(); | ||||
| } | } | ||||
| }).listen(config.admin, config.host); | }).listen(config.admin, config.host); | ||||
| function transmit(msg) { | function transmit(msg) { | ||||
| var listeners = clients.getListeners().filter(function(client) { | var listeners = clients.getListeners().filter(function(client) { | ||||
| return client.isSubscribedToAny(msg.subscribers); | return client.isSubscribedToAny(msg.subscribers); | ||||
| }); | }); | ||||
| Show All 23 Lines | |||||
This possibly being a bad assumption is the only thing I can imagine being an issue here, should be clear from testing and I can't imagine we're requesting any other path.