From 9c9c05bc334ebe2f56dd0154bcf2924493b989b5 Mon Sep 17 00:00:00 2001 From: Sahbi Date: Sun, 9 Aug 2020 12:21:39 +0300 Subject: [PATCH 1/6] Add support for subdir when running behind a reverse proxy --- htdocs/css/style.css | 8 ++++---- htdocs/index-dev.html | 6 +++--- htdocs/js/app.js | 19 ++++++++++--------- lib/api/config.js | 7 ++++++- lib/test.js | 3 ++- sample_conf/config.json | 1 + 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/htdocs/css/style.css b/htdocs/css/style.css index 4c6945da..372e874e 100644 --- a/htdocs/css/style.css +++ b/htdocs/css/style.css @@ -9,7 +9,7 @@ div.container { position: relative; width: 40px; height: 40px; - background: url(/images/clock-bkgnd.png) no-repeat center center; + background: url(../images/clock-bkgnd.png) no-repeat center center; background-size: 36px 36px; } @@ -35,15 +35,15 @@ div.container { } #d_header_clock_hour { - background-image: url(/images/clock-hour.png); + background-image: url(../images/clock-hour.png); } #d_header_clock_minute { - background-image: url(/images/clock-minute.png); + background-image: url(../images/clock-minute.png); } #d_header_clock_second { - background-image: url(/images/clock-second.png); + background-image: url(../images/clock-second.png); } #d_tab_time { diff --git a/htdocs/index-dev.html b/htdocs/index-dev.html index 1b5d7898..2c3bae69 100755 --- a/htdocs/index-dev.html +++ b/htdocs/index-dev.html @@ -6,7 +6,7 @@ Loading... - + @@ -112,8 +112,8 @@ - - + + \ No newline at end of file diff --git a/htdocs/js/app.js b/htdocs/js/app.js index ff2f3e08..85e1ffa5 100755 --- a/htdocs/js/app.js +++ b/htdocs/js/app.js @@ -22,7 +22,7 @@ app.extend({ // receive config from server if (resp.code) { app.showProgress( 1.0, "Waiting for master server..." ); - setTimeout( function() { load_script( '/api/app/config?callback=app.receiveConfig' ); }, 1000 ); + setTimeout( function() { load_script( 'api/app/config?callback=app.receiveConfig' ); }, 1000 ); return; } delete resp.code; @@ -79,7 +79,7 @@ app.extend({ for (var idx = 0, len = this.preload_images.length; idx < len; idx++) { var filename = '' + this.preload_images[idx]; var img = new Image(); - img.src = '/images/'+filename; + img.src = this.config.subdir + '/images/'+filename; } // populate prefs for first time user @@ -230,7 +230,7 @@ app.extend({ doExternalLogin: function() { // login using external user management system // Force API to hit current page hostname vs. master server, so login redirect URL reflects it - app.api.post( '/api/user/external_login', { cookie: document.cookie }, function(resp) { + app.api.post( 'api/user/external_login', { cookie: document.cookie }, function(resp) { if (resp.user) { Debug.trace("User Session Resume: " + resp.username + ": " + resp.session_id); app.hideProgress(); @@ -275,8 +275,8 @@ app.extend({ this.socket.removeAllListeners(); if (this.socket.connected) this.socket.disconnect(); this.socket = null; - } - + } + const path = config.subdir + "/socket.io"; var socket = this.socket = io( url, { // forceNew: true, transports: config.socket_io_transports || ['websocket'], @@ -284,7 +284,8 @@ app.extend({ reconnectionDelay: 1000, reconnectionDelayMax: 2000, reconnectionAttempts: 9999, - timeout: 3000 + timeout: 3000, + path:path, } ); socket.on('connect', function() { @@ -486,14 +487,14 @@ app.extend({ this.masterHostname = hostname; if (config.web_direct_connect) { - this.base_api_url = this.proto + this.masterHostname + ':' + this.port + config.base_api_uri; + this.base_api_url = this.proto + this.masterHostname + ':' + this.port + config.subdir + config.base_api_uri; if (!config.web_socket_use_hostnames && this.servers && this.servers[this.masterHostname] && this.servers[this.masterHostname].ip) { // use ip instead of hostname if available - this.base_api_url = this.proto + this.servers[this.masterHostname].ip + ':' + this.port + config.base_api_uri; + this.base_api_url = this.proto + this.servers[this.masterHostname].ip + ':' + this.port + config.subdir + config.base_api_uri; } } else { - this.base_api_url = this.proto + location.host + config.base_api_uri; + this.base_api_url = this.proto + location.host + config.subdir + config.base_api_uri; } Debug.trace("API calls now going to: " + this.base_api_url); diff --git a/lib/api/config.js b/lib/api/config.js index f8f34a3f..19d7a08a 100644 --- a/lib/api/config.js +++ b/lib/api/config.js @@ -22,13 +22,18 @@ module.exports = Class.create({ if (!this.multi.masterHostname) { return callback({ code: 'master', description: "No master server found" }); } - + + var subdir = this.server.config.get("subdir") || ""; + if (subdir.match(/^\/?([A-z0-9-_+]+\/?)+$/g)) { + subdir = "/" + subdir.replace(/^\/|\/$/g, ''); + } var resp = { code: 0, version: this.server.__version, config: Tools.mergeHashes( this.server.config.get('client'), { debug: this.server.debug ? 1 : 0, job_memory_max: this.server.config.get('job_memory_max'), + subdir: subdir, base_api_uri: this.api.config.get('base_uri'), default_privileges: this.usermgr.config.get('default_privileges'), free_accounts: this.usermgr.config.get('free_accounts'), diff --git a/lib/test.js b/lib/test.js index 7e9ede29..58bd554d 100644 --- a/lib/test.js +++ b/lib/test.js @@ -105,7 +105,8 @@ module.exports = { // prepare to make api calls request = cronicle.request; - api_url = server.config.get('base_app_url') + server.API.config.get('base_uri'); + api_url = server.config.get('base_app_url') + + server.config.get('subdir') + server.API.config.get('base_uri'); // cancel auto ticks, so we can send our own later clearTimeout( server.tickTimer ); diff --git a/sample_conf/config.json b/sample_conf/config.json index 09312f69..1efb803b 100644 --- a/sample_conf/config.json +++ b/sample_conf/config.json @@ -1,5 +1,6 @@ { "base_app_url": "http://localhost:3012", + "subdir": "/proxy/", "email_from": "admin@localhost", "smtp_hostname": "localhost", "smtp_port": 25, From 57f6dd3db88a5f332edee5e4e282cd2ff18d0fe7 Mon Sep 17 00:00:00 2001 From: Sahbi Date: Sun, 9 Aug 2020 13:30:03 +0300 Subject: [PATCH 2/6] By default subdir is empty --- sample_conf/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample_conf/config.json b/sample_conf/config.json index 1efb803b..e0fb2ff1 100644 --- a/sample_conf/config.json +++ b/sample_conf/config.json @@ -1,6 +1,6 @@ { "base_app_url": "http://localhost:3012", - "subdir": "/proxy/", + "subdir": "", "email_from": "admin@localhost", "smtp_hostname": "localhost", "smtp_port": 25, From 65d0d204d97143f10956f10a964835b2857acbc6 Mon Sep 17 00:00:00 2001 From: Sahbi Date: Sun, 9 Aug 2020 22:16:42 +0300 Subject: [PATCH 3/6] Another location using websocket needs path --- htdocs/js/pages/JobDetails.class.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/js/pages/JobDetails.class.js b/htdocs/js/pages/JobDetails.class.js index 5a0e3d3d..7e154723 100644 --- a/htdocs/js/pages/JobDetails.class.js +++ b/htdocs/js/pages/JobDetails.class.js @@ -1057,7 +1057,7 @@ Class.subclass( Page.Base, "Page.JobDetails", { $('#d_live_job_log').append( '
Log Watcher: Connecting to server: ' + url + '...
' ); - + const path = config.subdir + "/socket.io"; this.socket = io( url, { forceNew: true, transports: config.socket_io_transports || ['websocket'], @@ -1065,7 +1065,8 @@ Class.subclass( Page.Base, "Page.JobDetails", { reconnectionDelay: 1000, reconnectionDelayMax: 5000, reconnectionAttempts: 9999, - timeout: 5000 + timeout: 5000, + path:path } ); this.socket.on('connect', function() { From 9737e68916776044594ecc3d30ae701ec6bdce72 Mon Sep 17 00:00:00 2001 From: Sahbi Date: Sun, 9 Aug 2020 22:49:04 +0300 Subject: [PATCH 4/6] static files better without uri composition --- htdocs/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/js/app.js b/htdocs/js/app.js index 85e1ffa5..b868ac41 100755 --- a/htdocs/js/app.js +++ b/htdocs/js/app.js @@ -79,7 +79,7 @@ app.extend({ for (var idx = 0, len = this.preload_images.length; idx < len; idx++) { var filename = '' + this.preload_images[idx]; var img = new Image(); - img.src = this.config.subdir + '/images/'+filename; + img.src = 'images/'+filename; } // populate prefs for first time user From 9fb0016be28651b417296681fcf3343c77aa50a9 Mon Sep 17 00:00:00 2001 From: Sahbi Date: Tue, 11 Aug 2020 14:31:00 +0300 Subject: [PATCH 5/6] for live_log_watcher to work we need to set custom_live_log_socket_url --- htdocs/js/app.js | 4 ++-- lib/api/config.js | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/htdocs/js/app.js b/htdocs/js/app.js index b868ac41..ac8e6944 100755 --- a/htdocs/js/app.js +++ b/htdocs/js/app.js @@ -284,8 +284,8 @@ app.extend({ reconnectionDelay: 1000, reconnectionDelayMax: 2000, reconnectionAttempts: 9999, - timeout: 3000, - path:path, + timeout: 3000, + path:path, } ); socket.on('connect', function() { diff --git a/lib/api/config.js b/lib/api/config.js index 19d7a08a..31c801b2 100644 --- a/lib/api/config.js +++ b/lib/api/config.js @@ -22,11 +22,13 @@ module.exports = Class.create({ if (!this.multi.masterHostname) { return callback({ code: 'master', description: "No master server found" }); } - - var subdir = this.server.config.get("subdir") || ""; - if (subdir.match(/^\/?([A-z0-9-_+]+\/?)+$/g)) { - subdir = "/" + subdir.replace(/^\/|\/$/g, ''); - } + + var subdir = this.server.config.get("subdir"); + if (subdir && subdir.match(/^\/?([A-z0-9-_+]+\/?)+$/g)) { + subdir = "/" + subdir.replace(/^\/|\/$/g, ''); + } else { + subdir = ""; + } var resp = { code: 0, version: this.server.__version, @@ -39,6 +41,7 @@ module.exports = Class.create({ free_accounts: this.usermgr.config.get('free_accounts'), external_users: this.usermgr.config.get('external_user_api') ? 1 : 0, external_user_api: this.usermgr.config.get('external_user_api') || '', + custom_live_log_socket_url: this.server.config.get('custom_live_log_socket_url'), web_socket_use_hostnames: this.server.config.get('web_socket_use_hostnames') || 0, web_direct_connect: this.server.config.get('web_direct_connect') || 0, socket_io_transports: this.server.config.get('socket_io_transports') || 0 From 01f0c0f0c3e0201419f3735dfa2a830e524d72dd Mon Sep 17 00:00:00 2001 From: Sahbi Date: Fri, 11 Sep 2020 14:44:42 +0300 Subject: [PATCH 6/6] Adding missing documentation of custom_live_log_socket_url parameter --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 9a7ac18c..525aa8ac 100644 --- a/README.md +++ b/README.md @@ -587,6 +587,15 @@ Setting this parameter to `true` will force Cronicle's Web UI to connect to the This property only takes effect if [web_direct_connect](#web_direct_connect) is also set to `true`. +### custom_live_log_socket_url +This is an fancy configuration to provide a url for web socket which live log needs to connect. +Notice this is useful for single-master system behind an LB. +Socket URL should be like this, e.g. +```js +"custom_live_log_socket_url": "http://127.0.0.1:8888" +``` +Feel free to change the ip and the port. + ### socket_io_transports This is an advanced configuration property that you will probably never need to worry about. This allows you to customize the [socket.io transports](https://socket.io/docs/client-api/) used to connect to the server for real-time updates. By default, this property is set internally to an array containing the `websocket` transport only, e.g.