Merge branch 'ent-6752-ventana-desconexion-del-servidor' into 'develop'

Changed check connection method to ajax. Check deleted from login

See merge request artica/pandorafms!3679
This commit is contained in:
Daniel Rodriguez 2020-12-03 12:27:55 +01:00
commit aca33ba224
9 changed files with 58 additions and 47 deletions

View File

@ -114,12 +114,6 @@ foreach ($custom_fields as $field) {
}
}
// Connection lost alert.
ui_require_css_file('register', 'include/styles/', true);
ui_require_javascript_file('connection_check');
$conn_title = __('Connection with server has been lost');
$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.');
ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png');
// Get the custom icons.
$docs_logo = ui_get_docs_logo();

View File

@ -0,0 +1,23 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
require_once 'functions.php';
if (check_login(false)) {
$return = true;
} else {
$return = false;
}
echo json_encode($return);

View File

@ -29,22 +29,30 @@ function handleConnection() {
var connected;
var msg = "online";
var homeurl = getServerUrl();
if (homeurl == null || homeurl == "") {
return;
}
if (navigator.onLine) {
isReachable(getServerUrl())
.then(function(online) {
if (online) {
// handle online status
connected = true;
showConnectionMessage(connected, msg);
} else {
connected = false;
msg = "No connectivity with server";
showConnectionMessage(connected, msg);
}
$.ajax({
url: homeurl + "include/connection_check.php",
type: "post",
dataType: "json"
})
.done(function(response) {
connected = true;
showConnectionMessage(connected, msg);
})
.catch(function(err) {
connected = false;
msg = err;
.fail(function(err) {
// If test connection file is not found, do not show message.
if (err.status != 404) {
connected = false;
msg = err;
} else {
connected = true;
}
showConnectionMessage(connected, msg);
});
} else {
@ -55,38 +63,17 @@ function handleConnection() {
}
}
/**
* Test server reachibilty and get response.
*
* @param {String} url
*
* Return {promise}
*/
function isReachable(url) {
/**
* Note: fetch() still "succeeds" for 404s on subdirectories,
* which is ok when only testing for domain reachability.
*
* Example:
* https://google.com/noexist does not throw
* https://noexist.com/noexist does throw
*/
return fetch(url, { method: "HEAD", mode: "no-cors" })
.then(function(resp) {
return resp && (resp.ok || resp.type === "opaque");
})
.catch(function(error) {
console.warn("[conn test failure]:", error);
});
}
/**
* Gets server origin url
*/
function getServerUrl() {
var server_url;
server_url = window.location.origin;
try {
server_url = get_php_value("absolute_homeurl");
} catch (error) {
return "";
}
return server_url;
}
@ -99,7 +86,7 @@ function getServerUrl() {
*/
function showConnectionMessage(conn = true, msg = "") {
var data = {};
if (conn) {
if (conn && closed == false) {
$("div#message_dialog_connection")
.closest(".ui-dialog-content")
.dialog("close");
@ -164,6 +151,7 @@ function infoMessage(data, idMsg) {
},
close: function(event, ui) {
$(".ui-widget-overlay").removeClass("error-modal-opened");
closed = true;
}
})
.show();

View File

@ -1274,6 +1274,7 @@ echo '</div>';
// Connection lost alert.
ui_require_javascript_file('connection_check');
set_js_value('absolute_homeurl', ui_get_full_url(false, false, false, false));
$conn_title = __('Connection with server has been lost');
$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.');
ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png');

View File

@ -87,6 +87,7 @@ ui_require_css_file('register', 'include/styles/', true);
$conn_title = __('Connection with server has been lost');
$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.');
ui_require_javascript_file('connection_check');
set_js_value('absolute_homeurl', ui_get_full_url(false, false, false, false));
ui_print_message_dialog(
$conn_title,
$conn_text,

View File

@ -66,6 +66,7 @@ ui_require_css_file('register', 'include/styles/', true);
$conn_title = __('Connection with server has been lost');
$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.');
ui_require_javascript_file('connection_check');
set_js_value('absolute_homeurl', ui_get_full_url(false, false, false, false));
ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png');
$table = new StdClass;

View File

@ -277,6 +277,7 @@ if ($layers != false) {
$conn_title = __('Connection with server has been lost');
$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.');
ui_require_javascript_file('connection_check');
set_js_value('absolute_homeurl', ui_get_full_url(false, false, false, false));
ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png');
}

View File

@ -49,6 +49,7 @@ $url_css_modal = ui_get_full_url('include/styles/register.css', false, false, fa
echo '<link rel="stylesheet" href="'.$url_css_modal.'" type="text/css" />';
// Connection lost alert.
ui_require_javascript_file('connection_check', 'include/javascript/', true);
set_js_value('absolute_homeurl', ui_get_full_url(false, false, false, false));
$conn_title = __('Connection with server has been lost');
$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.');
ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png');

View File

@ -33,6 +33,7 @@ ui_require_css_file('register', 'include/styles/', true);
// Connection lost alert.
ui_require_javascript_file('connection_check', 'include/javascript/', true);
set_js_value('absolute_homeurl', ui_get_full_url(false, false, false, false));
$conn_title = __('Connection with server has been lost');
$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.');
ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png');