Enable "strict" mode for NodeJS
Summary:
In particular, this changes the behavior of NodeJS in the following ways:
- Any attempt to get or modify the global object will result in an error.
- `null` values of `this` will no longer be evaluated to the global object and primitive values of this will not be converted to wrapper objects.
- Writing or deleting properties which have there writeable or configurable attributes set to false will now throw an error instead of failing silently.
- Adding a property to an object whose extensible attribute is false will also throw an error now.
- A functions arguments are not writeable so attempting to change them will now throw an error `arguments = [...]`.
- `with(){}` statements are gone.
- Use of `eval` is effectively banned.
- `eval` and `arguments` are not allowed as variable or function identifiers in any scope.
- The identifiers `implements`, `interface`, `let`, `package`, `private`, `protected`, `public`, `static` and `yield` are all now reserved for future use (roll on ES6).
Test Plan: Verified that Aphlict was still functional.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D11430
2015-01-19 21:41:46 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-02-18 01:00:01 +01:00
|
|
|
var JX = require('./lib/javelin').JX;
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
var http = require('http');
|
|
|
|
var https = require('https');
|
|
|
|
var util = require('util');
|
|
|
|
var fs = require('fs');
|
2014-02-18 01:00:01 +01:00
|
|
|
|
2012-06-14 15:12:54 +02:00
|
|
|
function parse_command_line_arguments(argv) {
|
|
|
|
var config = {
|
2015-01-08 23:59:33 +01:00
|
|
|
'client-port': 22280,
|
|
|
|
'admin-port': 22281,
|
|
|
|
'client-host': '0.0.0.0',
|
|
|
|
'admin-host': '127.0.0.1',
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
log: '/var/log/aphlict.log',
|
|
|
|
'ssl-key': null,
|
2015-01-08 22:33:33 +01:00
|
|
|
'ssl-cert': null,
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
test: false
|
2012-06-14 15:12:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var ii = 2; ii < argv.length; ii++) {
|
|
|
|
var arg = argv[ii];
|
|
|
|
var matches = arg.match(/^--([^=]+)=(.*)$/);
|
|
|
|
if (!matches) {
|
2015-01-19 22:53:47 +01:00
|
|
|
throw new Error('Unknown argument "' + arg + '"!');
|
2012-06-14 15:12:54 +02:00
|
|
|
}
|
|
|
|
if (!(matches[1] in config)) {
|
2015-01-19 22:53:47 +01:00
|
|
|
throw new Error('Unknown argument "' + matches[1] + '"!');
|
2012-06-14 15:12:54 +02:00
|
|
|
}
|
|
|
|
config[matches[1]] = matches[2];
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
config['client-port'] = parseInt(config['client-port'], 10);
|
|
|
|
config['admin-port'] = parseInt(config['admin-port'], 10);
|
2012-06-14 15:12:54 +02:00
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2015-01-19 20:46:14 +01:00
|
|
|
require('./lib/AphlictLog');
|
|
|
|
|
2014-12-30 12:06:44 +01:00
|
|
|
var debug = new JX.AphlictLog()
|
|
|
|
.addConsole(console);
|
|
|
|
|
|
|
|
var config = parse_command_line_arguments(process.argv);
|
|
|
|
|
2015-01-21 20:41:06 +01:00
|
|
|
function set_exit_code(code) {
|
|
|
|
process.on('exit', function() {
|
|
|
|
process.exit(code);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
process.on('uncaughtException', function(err) {
|
2015-01-12 17:16:08 +01:00
|
|
|
var context = null;
|
2015-01-18 21:48:48 +01:00
|
|
|
if (err.code == 'EACCES' && err.path == config.log) {
|
2015-01-12 17:16:08 +01:00
|
|
|
context = util.format(
|
|
|
|
'Unable to open logfile ("%s"). Check that permissions are set ' +
|
|
|
|
'correctly.',
|
|
|
|
err.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
var message = [
|
|
|
|
'\n<<< UNCAUGHT EXCEPTION! >>>',
|
|
|
|
];
|
|
|
|
if (context) {
|
|
|
|
message.push(context);
|
|
|
|
}
|
|
|
|
message.push(err.stack);
|
|
|
|
|
|
|
|
debug.log(message.join('\n\n'));
|
2015-01-21 20:41:06 +01:00
|
|
|
set_exit_code(1);
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
});
|
|
|
|
|
2015-01-21 21:45:55 +01:00
|
|
|
// Add the logfile so we'll fail if we can't write to it.
|
|
|
|
if (config.log) {
|
|
|
|
debug.addLog(config.log);
|
|
|
|
}
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
try {
|
2015-01-18 21:48:48 +01:00
|
|
|
require('ws');
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
} catch (ex) {
|
|
|
|
throw new Error(
|
|
|
|
'You need to install the Node.js "ws" module for websocket support. ' +
|
2015-01-08 23:02:14 +01:00
|
|
|
'See "Notifications User Guide: Setup and Configuration" in the ' +
|
|
|
|
'documentation for instructions. ' + ex.toString());
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
}
|
|
|
|
|
2015-01-19 20:46:14 +01:00
|
|
|
// NOTE: Require these only after checking for the "ws" module, since they
|
|
|
|
// depend on it.
|
|
|
|
|
|
|
|
require('./lib/AphlictAdminServer');
|
|
|
|
require('./lib/AphlictClientServer');
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
var ssl_config = {
|
|
|
|
enabled: (config['ssl-key'] || config['ssl-cert'])
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load the SSL certificates (if any were provided) now, so that runs with
|
|
|
|
// `--test` will see any errors.
|
|
|
|
if (ssl_config.enabled) {
|
|
|
|
ssl_config.key = fs.readFileSync(config['ssl-key']);
|
|
|
|
ssl_config.cert = fs.readFileSync(config['ssl-cert']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're just doing a configuration test, exit here before starting any
|
|
|
|
// servers.
|
|
|
|
if (config.test) {
|
|
|
|
debug.log('Configuration test OK.');
|
2015-01-21 20:41:06 +01:00
|
|
|
set_exit_code(0);
|
|
|
|
return;
|
2012-06-14 15:12:54 +02:00
|
|
|
}
|
|
|
|
|
2015-01-18 21:48:48 +01:00
|
|
|
var server;
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
if (ssl_config.enabled) {
|
2015-01-18 21:48:48 +01:00
|
|
|
server = https.createServer({
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
key: ssl_config.key,
|
|
|
|
cert: ssl_config.cert
|
2015-01-18 21:48:48 +01:00
|
|
|
}, function(req, res) {
|
|
|
|
res.writeHead(501);
|
|
|
|
res.end('HTTP/501 Use Websockets\n');
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
});
|
2015-01-18 21:48:48 +01:00
|
|
|
} else {
|
|
|
|
server = http.createServer(function() {});
|
2014-12-30 12:06:44 +01:00
|
|
|
}
|
|
|
|
|
2015-01-18 21:48:48 +01:00
|
|
|
var client_server = new JX.AphlictClientServer(server);
|
|
|
|
var admin_server = new JX.AphlictAdminServer();
|
2012-06-12 02:49:32 +02:00
|
|
|
|
2015-01-18 21:48:48 +01:00
|
|
|
client_server.setLogger(debug);
|
|
|
|
admin_server.setLogger(debug);
|
|
|
|
admin_server.setClientServer(client_server);
|
Make the Aphlict server more resilient.
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
2014-06-11 19:16:31 +02:00
|
|
|
|
2015-01-18 21:48:48 +01:00
|
|
|
client_server.listen(config['client-port'], config['client-host']);
|
|
|
|
admin_server.listen(config['admin-port'], config['admin-host']);
|
2012-06-12 02:49:32 +02:00
|
|
|
|
2014-02-18 01:00:51 +01:00
|
|
|
debug.log('Started Server (PID %d)', process.pid);
|