From 90efd6e2392153f7bb7133783e417a92fbc2eb21 Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Sun, 11 Sep 2016 03:23:01 +0300 Subject: [PATCH] properly handle redirections from https netdata to http netdata --- conf.d/health_alarm_notify.conf | 1 + web/goto-host-from-alarm.html | 34 ++++++++++++++++++++++++++------- web/index.html | 5 +++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/conf.d/health_alarm_notify.conf b/conf.d/health_alarm_notify.conf index 0e3d23f9..84e0b211 100644 --- a/conf.d/health_alarm_notify.conf +++ b/conf.d/health_alarm_notify.conf @@ -72,6 +72,7 @@ SEND_SLACK="YES" # Login to slack.com and create an incoming webhook. # You need only one for all your netdata servers. # Without it, netdata cannot send slack notifications. +# Get yours from: https://api.slack.com/incoming-webhooks SLACK_WEBHOOK_URL="" # if a role's recipients are not configured, a notification will be send to diff --git a/web/goto-host-from-alarm.html b/web/goto-host-from-alarm.html index e1849bc3..987ee11e 100755 --- a/web/goto-host-from-alarm.html +++ b/web/goto-host-from-alarm.html @@ -46,12 +46,22 @@ var gotoServerValidateRemaining = 0; var gotoServerMiddleClick = false; var gotoServerStop = false; + var thisIsHttps = false; + var urlsInHttp = 0; function gotoServerValidateUrl(id, guid, url) { var penaldy = 0; - if(document.location.toString().startsWith('http://') && url.toString().startsWith('https://')) - // we penalize https only if the current url is http - // to allow the user walk through all its servers. - penaldy = 500; + var error = 'failed'; + + if(thisIsHttps === false && url.toString().startsWith('https://')) { + // we penalize https only if the current url is http + // to allow the user walk through all its servers. + penaldy = 500; + } + + else if(thisIsHttps === true && url.toString().startsWith('http://')) { + error = 'can\'t check'; + urlsInHttp++; + } var finalURL = netdataURL(url); @@ -66,7 +76,7 @@ gotoServerStop = true; if(gotoServerMiddleClick) { - window.open(finalURL, '_blank'); + window.open(finalURL); gotoServerMiddleClick = false; document.getElementById('gotoServerResponse').innerHTML = 'Opening new window to ' + NETDATA.registry.machines[guid].name + '
' + url + '

(check your pop-up blocker if it fails)'; } @@ -75,11 +85,16 @@ } } else { - document.getElementById(guid + '-' + id + '-status').innerHTML = "failed!"; + document.getElementById(guid + '-' + id + '-status').innerHTML = error; gotoServerValidateRemaining--; if(gotoServerValidateRemaining <= 0) { gotoServerMiddleClick = false; document.getElementById('gotoServerResponse').innerHTML = 'Sorry! I cannot find any operational URL for this server'; + + if(thisIsHttps === true && urlsInHttp > 0) { + document.getElementById('gotoServerResponse').innerHTML += '
redirecting myself to HTTP to allow checking'; + document.location = document.location.toString().replace('https://', 'http://'); + } } } }); @@ -87,6 +102,11 @@ } var netdataRegistryCallback = function(machines_array) { + document.getElementById('message').innerHTML = 'These are the URLs this machine is known:'; + + if(document.location.toString().startsWith('https://')) + thisIsHttps = true; + if(machines_array) { var len = machines_array.length; while(len--) { @@ -119,7 +139,7 @@
- Please wait... + Please wait...
diff --git a/web/index.html b/web/index.html index df54b3e0..8f31ae54 100644 --- a/web/index.html +++ b/web/index.html @@ -1263,11 +1263,16 @@ var gotoServerMiddleClick = false; var gotoServerStop = false; function gotoServerValidateUrl(id, guid, url) { var penaldy = 0; + var error = 'failed'; + if(document.location.toString().startsWith('http://') && url.toString().startsWith('https://')) // we penalize https only if the current url is http // to allow the user walk through all its servers. penaldy = 500; + else if(document.location.toString().startsWith('https://') && url.toString().startsWith('http://')) + error = 'can\'t check'; + var finalURL = netdataURL(url); setTimeout(function() { -- 2.39.2