| 
									
										
											  
											
												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-20 07:41:46 +11:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-17 16:00:01 -08: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 10:03:00 -08:00
										 |  |  | var http = require('http'); | 
					
						
							|  |  |  | var https = require('https'); | 
					
						
							|  |  |  | var util = require('util'); | 
					
						
							|  |  |  | var fs = require('fs'); | 
					
						
							| 
									
										
										
										
											2014-02-17 16:00:01 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-14 06:12:54 -07:00
										 |  |  | function parse_command_line_arguments(argv) { | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  |   var args = { | 
					
						
							|  |  |  |     test: false, | 
					
						
							|  |  |  |     config: null | 
					
						
							| 
									
										
										
										
											2012-06-14 06:12:54 -07:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (var ii = 2; ii < argv.length; ii++) { | 
					
						
							|  |  |  |     var arg = argv[ii]; | 
					
						
							|  |  |  |     var matches = arg.match(/^--([^=]+)=(.*)$/); | 
					
						
							|  |  |  |     if (!matches) { | 
					
						
							| 
									
										
										
										
											2015-01-20 08:53:47 +11:00
										 |  |  |       throw new Error('Unknown argument "' + arg + '"!'); | 
					
						
							| 
									
										
										
										
											2012-06-14 06:12:54 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  |     if (!(matches[1] in args)) { | 
					
						
							| 
									
										
										
										
											2015-01-20 08:53:47 +11:00
										 |  |  |       throw new Error('Unknown argument "' + matches[1] + '"!'); | 
					
						
							| 
									
										
										
										
											2012-06-14 06:12:54 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  |     args[matches[1]] = matches[2]; | 
					
						
							| 
									
										
										
										
											2012-06-14 06:12:54 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  |   return args; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-14 06:12:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  | function parse_config(args) { | 
					
						
							|  |  |  |   var data = fs.readFileSync(args.config); | 
					
						
							|  |  |  |   return JSON.parse(data); | 
					
						
							| 
									
										
										
										
											2012-06-14 06:12:54 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-19 11:46:14 -08:00
										 |  |  | require('./lib/AphlictLog'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 22:06:44 +11:00
										 |  |  | var debug = new JX.AphlictLog() | 
					
						
							|  |  |  |   .addConsole(console); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  | var args = parse_command_line_arguments(process.argv); | 
					
						
							|  |  |  | var config = parse_config(args); | 
					
						
							| 
									
										
										
										
											2014-12-30 22:06:44 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 06:41:06 +11: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 10:03:00 -08:00
										 |  |  | process.on('uncaughtException', function(err) { | 
					
						
							| 
									
										
										
										
											2015-01-12 08:16:08 -08:00
										 |  |  |   var context = null; | 
					
						
							| 
									
										
										
										
											2016-04-13 11:44:20 -07:00
										 |  |  |   if (err.code == 'EACCES') { | 
					
						
							| 
									
										
										
										
											2015-01-12 08:16:08 -08:00
										 |  |  |     context = util.format( | 
					
						
							| 
									
										
										
										
											2016-04-13 11:44:20 -07:00
										 |  |  |       'Unable to open file ("%s"). Check that permissions are set ' + | 
					
						
							| 
									
										
										
										
											2015-01-12 08:16:08 -08:00
										 |  |  |       '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-22 06:41:06 +11: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 10:03:00 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | try { | 
					
						
							| 
									
										
										
										
											2015-01-19 07:48:48 +11: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 10:03:00 -08:00
										 |  |  | } catch (ex) { | 
					
						
							|  |  |  |   throw new Error( | 
					
						
							|  |  |  |     'You need to install the Node.js "ws" module for websocket support. ' + | 
					
						
							| 
									
										
										
										
											2015-01-08 14:02:14 -08: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 10:03:00 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-19 11:46:14 -08:00
										 |  |  | // NOTE: Require these only after checking for the "ws" module, since they
 | 
					
						
							|  |  |  | // depend on it.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require('./lib/AphlictAdminServer'); | 
					
						
							|  |  |  | require('./lib/AphlictClientServer'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 12:07:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  | var ii; | 
					
						
							| 
									
										
										
										
											2016-04-13 11:44:20 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | var logs = config.logs || []; | 
					
						
							|  |  |  | for (ii = 0; ii < logs.length; ii++) { | 
					
						
							|  |  |  |   debug.addLog(logs[ii].path); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  | var servers = []; | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  | for (ii = 0; ii < config.servers.length; ii++) { | 
					
						
							|  |  |  |   var spec = config.servers[ii]; | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  |   spec.listen = spec.listen || '0.0.0.0'; | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  |   if (spec['ssl.key']) { | 
					
						
							|  |  |  |     spec['ssl.key'] = fs.readFileSync(spec['ssl.key']); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (spec['ssl.cert']){ | 
					
						
							|  |  |  |     spec['ssl.cert'] = fs.readFileSync(spec['ssl.cert']); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 05:44:04 -07:00
										 |  |  |   if (spec['ssl.chain']){ | 
					
						
							|  |  |  |     spec['ssl.chain'] = fs.readFileSync(spec['ssl.chain']); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  |   servers.push(spec); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												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 10:03:00 -08:00
										 |  |  | // If we're just doing a configuration test, exit here before starting any
 | 
					
						
							|  |  |  | // servers.
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  | if (args.test) { | 
					
						
							| 
									
										
										
											
												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 10:03:00 -08:00
										 |  |  |   debug.log('Configuration test OK.'); | 
					
						
							| 
									
										
										
										
											2015-01-22 06:41:06 +11:00
										 |  |  |   set_exit_code(0); | 
					
						
							|  |  |  |   return; | 
					
						
							| 
									
										
										
										
											2012-06-14 06:12:54 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  | debug.log('Starting servers (service PID %d).', process.pid); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:44:20 -07:00
										 |  |  | for (ii = 0; ii < logs.length; ii++) { | 
					
						
							|  |  |  |   debug.log('Logging to "%s".', logs[ii].path); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  | var aphlict_servers = []; | 
					
						
							|  |  |  | var aphlict_clients = []; | 
					
						
							|  |  |  | var aphlict_admins = []; | 
					
						
							|  |  |  | for (ii = 0; ii < servers.length; ii++) { | 
					
						
							|  |  |  |   var server = servers[ii]; | 
					
						
							|  |  |  |   var is_client = (server.type == 'client'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var http_server; | 
					
						
							|  |  |  |   if (server['ssl.key']) { | 
					
						
							|  |  |  |     var https_config = { | 
					
						
							|  |  |  |       key: server['ssl.key'], | 
					
						
							| 
									
										
										
										
											2016-04-14 05:44:04 -07:00
										 |  |  |       cert: server['ssl.cert'], | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 05:44:04 -07:00
										 |  |  |     if (server['ssl.chain']) { | 
					
						
							|  |  |  |       https_config.ca = server['ssl.chain']; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  |     http_server = https.createServer(https_config); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     http_server = http.createServer(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var aphlict_server; | 
					
						
							|  |  |  |   if (is_client) { | 
					
						
							|  |  |  |     aphlict_server = new JX.AphlictClientServer(http_server); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     aphlict_server = new JX.AphlictAdminServer(http_server); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-30 22:06:44 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  |   aphlict_server.setLogger(debug); | 
					
						
							|  |  |  |   aphlict_server.listen(server.port, server.listen); | 
					
						
							| 
									
										
										
										
											2012-06-11 17:49:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:03:42 -07:00
										 |  |  |   debug.log( | 
					
						
							|  |  |  |     'Started %s server (Port %d, %s).', | 
					
						
							|  |  |  |     server.type, | 
					
						
							|  |  |  |     server.port, | 
					
						
							|  |  |  |     server['ssl.key'] ? 'With SSL' : 'No SSL'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  |   aphlict_servers.push(aphlict_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 10:16:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary:
Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server.
I want to replace this with a config file. Additionally, I plan to support:
  - arbitrary numbers of listening client ports;
  - arbitrary numbers of listening admin ports;
  - SSL on any port.
For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead.
This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server.
(Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.)
Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10697
Differential Revision: https://secure.phabricator.com/D15700
											
										 
											2016-04-13 09:35:24 -07:00
										 |  |  |   if (is_client) { | 
					
						
							|  |  |  |     aphlict_clients.push(aphlict_server); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     aphlict_admins.push(aphlict_server); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for (ii = 0; ii < aphlict_admins.length; ii++) { | 
					
						
							|  |  |  |   var admin_server = aphlict_admins[ii]; | 
					
						
							|  |  |  |   admin_server.setClientServers(aphlict_clients); | 
					
						
							|  |  |  | } |