mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 17:02:41 +01:00
ab4324148a
Summary: Currently, the Aphlict server will crash if invalid JSON data is `POST`ed to it. I have fixed this to, instead, return a 400. Also made some minor formatting changes. Ref T4324. Ref T5284. Also, modify the data structure that is passed around (i.e. `POST`ed to the Aphlict server and broadcast to the Aphlict clients) to include the subscribers. Initially, I figured that we shouldn't expose this information to the clients... however, it is necessary for T4324 that the `AphlictMaster` is able to route a notification to the appropriate clients. Test Plan: Making the following `curl` request: `curl --data "{" http://localhost:22281/`. **Before** ``` sudo ./bin/aphlict debug Starting Aphlict server in foreground... Launching server: $ 'nodejs' '/usr/src/phabricator/src/applications/aphlict/management/../../../../support/aphlict/server/aphlict_server.js' --port='22280' --admin='22281' --host='localhost' --user='aphlict' [Wed Jun 11 2014 17:07:51 GMT+0000 (UTC)] Started Server (PID 2033) [Wed Jun 11 2014 17:07:55 GMT+0000 (UTC)] <<< UNCAUGHT EXCEPTION! >>> SyntaxError: Unexpected end of input >>> Server exited! ``` **After** (No output... the bad JSON is caught and a 400 is returned) Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4324, T5284 Differential Revision: https://secure.phabricator.com/D9480
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
var JX = require('javelin').JX;
|
|
|
|
var net = require('net');
|
|
|
|
/**
|
|
* Server which handles cross-domain policy requests for Flash.
|
|
*
|
|
* var server = new AphlictFlashPolicyServer()
|
|
* .setAccessPort(9999)
|
|
* .start();
|
|
*/
|
|
JX.install('AphlictFlashPolicyServer', {
|
|
|
|
members: {
|
|
_server: null,
|
|
_port: 843,
|
|
_accessPort: null,
|
|
_debug: null,
|
|
|
|
setDebugLog: function(log) {
|
|
this._debug = log;
|
|
return this;
|
|
},
|
|
|
|
setAccessPort: function(port) {
|
|
this._accessPort = port;
|
|
return this;
|
|
},
|
|
|
|
start: function() {
|
|
this._server = net.createServer(JX.bind(this, this._didConnect));
|
|
this._server.listen(this._port);
|
|
return this;
|
|
},
|
|
|
|
_didConnect: function(socket) {
|
|
this._log('<FlashPolicy> Policy Request From %s', socket.remoteAddress);
|
|
|
|
socket.on('error', JX.bind(this, this._didSocketError, socket));
|
|
|
|
socket.write(this._getFlashPolicyResponse());
|
|
socket.end();
|
|
},
|
|
|
|
_didSocketError: function(socket, error) {
|
|
this._log('<FlashPolicy> Socket Error: %s', error);
|
|
},
|
|
|
|
_log: function(pattern) {
|
|
this._debug && this._debug.log.apply(this._debug, arguments);
|
|
},
|
|
|
|
_getFlashPolicyResponse: function() {
|
|
var policy = [
|
|
'<?xml version="1.0"?>',
|
|
'<!DOCTYPE cross-domain-policy SYSTEM ' +
|
|
'"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">',
|
|
'<cross-domain-policy>',
|
|
'<allow-access-from domain="*" to-ports="' + this._accessPort + '"/>',
|
|
'</cross-domain-policy>'
|
|
];
|
|
|
|
return policy.join("\n") + "\0";
|
|
}
|
|
|
|
}
|
|
|
|
});
|