diff --git a/lib/monitor.js b/lib/monitor.js index 96f469c..9728c3d 100644 --- a/lib/monitor.js +++ b/lib/monitor.js @@ -30,7 +30,7 @@ function Monitor(options) { this._init(options); }; -Monitor.ACCEPT_KEYS = ['pm2', 'refresh', 'daemonize', 'max_restarts', 'port', 'log', 'agent', 'remotes']; +Monitor.ACCEPT_KEYS = ['pm2', 'refresh', 'daemonize', 'max_restarts', 'port', 'log', 'agent', 'remotes', 'origins']; Monitor.DEF_CONF_FILE = 'pm2-gui.ini'; Monitor.PM2_DAEMON_PROPS = ['DAEMON_RPC_PORT', 'DAEMON_PUB_PORT']; diff --git a/pm2-gui.ini b/pm2-gui.ini index 61ecb89..ec1a748 100644 --- a/pm2-gui.ini +++ b/pm2-gui.ini @@ -32,6 +32,11 @@ date = false ; Log level, one of debug, log, info, warn, error. ; level = debug +; +; Socket.io origins check, e.g.: +; origins = 'example.com:* http://example.com:* http://www.example.com:8088' +; By default: +; origins = *:* [agent] ; @@ -41,7 +46,7 @@ authorization = AuTh ; ; A value indicates whether agent offline or not. ; -; offline = true +offline = true [remotes] ; ; the dashboard and web server will use this section to connect remoting socket server @@ -51,3 +56,7 @@ authorization = AuTh ; pm2@172 = 192.168.1.172:9001 ; pm2@173 = 192.168.1.173:9000 ; +pm2@129 = AuTh@192.168.100.129:9009 +pm2@130 = AuTh@192.168.100.130:8088 +pm2@131 = AuTh@192.168.100.131:8088 +pm2@138 = AuTh@192.168.100.138:8088 \ No newline at end of file diff --git a/pm2-gui.js b/pm2-gui.js index bf4d613..6f0a676 100644 --- a/pm2-gui.js +++ b/pm2-gui.js @@ -60,7 +60,9 @@ function startWebServer(confFile) { port: options.port }); - monitor.sockio = socketIO(server); + monitor.sockio = socketIO(server, { + origins: options.origins || '*:*' + }); monitor.run(); console.info('Web server is listening on 127.0.0.1:' + options.port); } @@ -78,7 +80,9 @@ function startAgent(confFile) { } options.port = options.port || 8088; var sockio = socketIO(); - sockio.listen(options.port); + sockio.listen(options.port, { + origins: options.origins || '*:*' + }); monitor.sockio = sockio; monitor.run(); console.info('Socket.io server is listening on 0.0.0.0:' + options.port); @@ -214,7 +218,9 @@ function _connectToDashboard(monitor, options, connection) { } console.warn('Agent is offline, try to start it.'); var sockio = socketIO(); - sockio.listen(connection.port); + sockio.listen(connection.port, { + origins: options.origins || '*:*' + }); monitor.sockio = sockio; monitor.run(); layout(connection).render(monitor); diff --git a/web/public/js/index.html.js b/web/public/js/index.html.js index 77f44c7..f8c5b7a 100644 --- a/web/public/js/index.html.js +++ b/web/public/js/index.html.js @@ -108,8 +108,11 @@ function setFPEnable(enable, unscrollable) { * Connect to socket server. */ function connectSocketServer(ns) { - var uri = GUI.connection.value, - index = uri.indexOf('?'), + var uri = GUI.connection.value; + if(GUI.connection.short == 'localhost'){ + uri = uri.replace(/(127\.0.0\.1|localhost|0\.0\.0\.0)/, location.hostname); + } + var index = uri.indexOf('?'), query = ''; if (index > 0) { query = uri.slice(index); @@ -433,7 +436,7 @@ function addChooser(options) { if (conn == '-') { html += '
'; } else { - html += '