diff --git a/pandora_console/operation/agentes/ehorus.php b/pandora_console/operation/agentes/ehorus.php index 69418f5c05..0e86b10967 100644 --- a/pandora_console/operation/agentes/ehorus.php +++ b/pandora_console/operation/agentes/ehorus.php @@ -135,6 +135,15 @@ echo ''; +ui_print_error_message( + __('The connection was lost and the authorization token was expired') + . '. ' . + __('Reload the page to request a new authorization token') + . '. ' +); +echo ''; + echo '
'; $query_data = array( @@ -142,6 +151,7 @@ $query_data = array( 'hostname' => (string) $agent_data['serverAddress'], 'port' => (int) $agent_data['serverPort'], 'token' => (string) $response_auth['token'], + 'expiration' => (int) $response_auth['exp'], 'is_busy' => (bool) $agent_data['isBusy'], 'last_connection' => (int) $agent_data['lastConnection'], 'section' => $client_tab @@ -200,7 +210,6 @@ $client_url = $config['homeurl'] . 'operation/agentes/ehorus_client.php?' . $que event.source !== iframe.contentWindow) { return; } - console.log('message from iframe', event.data); if (typeof actionHandlers === 'undefined') return; if (event.data.action in actionHandlers) { @@ -231,6 +240,17 @@ $client_url = $config['homeurl'] . 'operation/agentes/ehorus_client.php?' . $que $('a.tab_processes').click(handleTabClick('processes', messageToIframe)); $('a.tab_services').click(handleTabClick('services', messageToIframe)); $('a.tab_files').click(handleTabClick('files', messageToIframe)); + }, + expired: function () { + $(iframe).remove(); + $('a.ehorus_tab').unbind('click'); + $('a.tab_terminal').unbind('click'); + $('a.tab_display').unbind('click'); + $('a.tab_processes').unbind('click'); + $('a.tab_services').unbind('click'); + $('a.tab_files').unbind('click'); + iframe = null; + $('div#expired_message').show(); } } diff --git a/pandora_console/operation/agentes/ehorus_client.php b/pandora_console/operation/agentes/ehorus_client.php index af6b7708e1..0629ea4704 100644 --- a/pandora_console/operation/agentes/ehorus_client.php +++ b/pandora_console/operation/agentes/ehorus_client.php @@ -28,6 +28,7 @@ $agent_id = (string) get_parameter_get('agent_id'); $hostname = (string) get_parameter_get('hostname'); $port = (int) get_parameter_get('port'); $token = (string) get_parameter_get('token'); +$expiration = (int) get_parameter_get('expiration'); $is_busy = (bool) get_parameter_get('is_busy'); $last_connection = (int) get_parameter_get('last_connection'); $section = (string) get_parameter_get('section'); @@ -92,7 +93,6 @@ $section = (string) get_parameter_get('section'); event.source !== window.parent) { return; } - console.log('message from parent', event.data); if (typeof actionHandlers === 'undefined') return; if (event.data.action in actionHandlers) { @@ -102,6 +102,7 @@ $section = (string) get_parameter_get('section'); } window.onload = function () { + var expiration = ; // Start client var ehorusContainer = document.getElementById('ehorus-client-container'); var eHorus = runClient(ehorusContainer, { @@ -115,11 +116,21 @@ $section = (string) get_parameter_get('section'); section: '' }); + eHorus.remote.onClose(function () { + if (expiration && expiration < Date.now() / 1000) { + eHorus.remote.close(); + // Send expired message + messageToParent({ + action: 'expired', + payload: {} + }); + } + }); + // Listen for messages var actionHandlers = { change_section: function (payload) { eHorus.changeSection(payload.section); - console.log('Changing section', payload.section); } } window.addEventListener('message', handleMessage(actionHandlers));