Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14036160
D8257.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D8257.diff
View Options
Index: support/aphlict/server/aphlict_server.js
===================================================================
--- support/aphlict/server/aphlict_server.js
+++ support/aphlict/server/aphlict_server.js
@@ -8,6 +8,7 @@
var JX = require('./lib/javelin').JX;
+JX.require('lib/AphlictFlashPolicyServer', __dirname);
JX.require('lib/AphlictListenerList', __dirname);
JX.require('lib/AphlictLog', __dirname);
@@ -64,33 +65,15 @@
var url = require('url');
var querystring = require('querystring');
-
process.on('uncaughtException', function (err) {
- log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err);
+ debug.log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err);
process.exit(1);
});
-function getFlashPolicy() {
- return [
- '<?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="'+config.port+'"/>',
- '</cross-domain-policy>'
- ].join('\n');
-}
-
-net.createServer(function(socket) {
- socket.write(getFlashPolicy() + '\0');
- socket.end();
-
- debug.log('[' + socket.remoteAddress + '] Sent Flash Policy');
-
- socket.on('error', function (e) {
- debug.log('Error in policy server: ' + e);
- });
-}).listen(843);
+var flash_server = new JX.AphlictFlashPolicyServer()
+ .setDebugLog(debug)
+ .setAccessPort(config.port)
+ .start();
var send_server = net.createServer(function(socket) {
Index: support/aphlict/server/lib/AphlictFlashPolicyServer.js
===================================================================
--- /dev/null
+++ support/aphlict/server/lib/AphlictFlashPolicyServer.js
@@ -0,0 +1,68 @@
+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";
+ }
+
+ }
+
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 11, 8:44 AM (6 d, 21 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6728014
Default Alt Text
D8257.diff (3 KB)
Attached To
Mode
D8257: Break Aphlict's flash policy server into a separate class
Attached
Detach File
Event Timeline
Log In to Comment