diff --git a/misc/embedded.html b/misc/embedded.html index 4b340c4..09d9953 100644 --- a/misc/embedded.html +++ b/misc/embedded.html @@ -14,7 +14,7 @@ For communication with Shell In A Box we need to set '-m' (messages-origin) command line option with appropriate messages origin. Origin should be set to - URL of parent (this) window. If origin is set to '*' Shell In A Box won't checki + URL of parent (this) window. If origin is set to '*' Shell In A Box won't check origin on received messages. This is usually unsafe option. Command line example: @@ -59,6 +59,9 @@ Following types of messages can be received from shellinabox: + * ready + signals that shellinabox is ready to send and receive messages + * output data field contains terminal output @@ -140,10 +143,6 @@ var output = document.getElementById("output"); var session = document.getElementById("session"); - // Add url to our iframe. We do this, only that variable 'url' can be used - // throughout the whole code where needed. - iframe.src = url; - document.getElementById("execute").addEventListener("click", function() { // Send input to shellinabox var message = JSON.stringify({ @@ -209,6 +208,15 @@ // Handle response according to response type var decoded = JSON.parse(message.data); switch (decoded.type) { + case "ready": + // Shellinabox is ready to communicate and we will enable console output + // by default. + var message = JSON.stringify({ + type : 'output', + data : 'enable' + }); + iframe.contentWindow.postMessage(message, url); + break; case "output" : // Append new output output.innerHTML = output.innerHTML + decoded.data; @@ -220,6 +228,9 @@ } }, false); + // Add url to our iframe after the event listener is installed. + iframe.src = url; + diff --git a/shellinabox/shell_in_a_box.jspp b/shellinabox/shell_in_a_box.jspp index 4e449cc..976c7e5 100644 --- a/shellinabox/shell_in_a_box.jspp +++ b/shellinabox/shell_in_a_box.jspp @@ -406,6 +406,9 @@ ShellInABox.prototype.messageInit = function() { } } + // After message mechanisms are in place "ready" message is sent to parent + // window. + parent.postMessage(JSON.stringify({type : 'ready', data : ''}), '*'); }; ShellInABox.prototype.messageReceive = function (message) {