web: allow pasting in text. [Firehawke]

This commit is contained in:
R. Belmont 2014-09-26 01:51:01 +00:00
parent 0f35e74fe8
commit de4a491aab
2 changed files with 108 additions and 3 deletions

View file

@ -292,6 +292,53 @@ int web_engine::begin_request_handler(struct mg_connection *conn)
return json_slider_handler(conn);
}
}
else if (!strncmp(conn->uri, "/keypost",8))
{
// Is there any sane way to determine the length of the buffer before getting it?
// A request for a way was previously filed with the mongoose devs,
// but it looks like it was never implemented.
// For now, we'll allow a paste buffer of 32k.
// To-do: Send an error if the paste is too big?
char cmd_val[32768];
int pastelength = mg_get_var(conn, "val", cmd_val, sizeof(cmd_val));
if (pastelength > 0) {
machine().ioport().natkeyboard().post_utf8(cmd_val);
}
// Send HTTP reply to the client
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: 2\r\n" // Always set Content-Length
"\r\n"
"OK");
// Returning non-zero tells mongoose that our function has replied to
// the client, and mongoose should not send client any more data.
return MG_TRUE;
}
else if (!strncmp(conn->uri, "/keyupload",8))
{
const char *upload_data;
int data_length, ofs = 0;
char var_name[100], file_name[255];
while ((ofs = mg_parse_multipart(conn->content + ofs, conn->content_len - ofs, var_name, sizeof(var_name), file_name, sizeof(file_name), &upload_data, &data_length)) > 0) {
mg_printf_data(conn, "File: %s, size: %d bytes", file_name, data_length);
}
// That upload_data contains more than we need. It also has the headers.
// We'll need to strip it down to just what we want.
if ((&data_length > 0) && (sizeof(file_name) > 0))
{
char paste_data[data_length];
strncpy (paste_data, upload_data, data_length);
// Now paste the stripped down paste_data..
machine().ioport().natkeyboard().post_utf8(paste_data);
}
return MG_TRUE;
}
else if (!strncmp(conn->uri, "/cmd",4))
{
char cmd_name[64];

View file

@ -79,7 +79,7 @@
updateStatusBar('<b style="color: red;">Disconnected</b>','Exited','No Driver');
}
}
function executeHardReset()
{
executeCommands("hardreset");
@ -202,6 +202,25 @@
window.onload = function() {
startWebSocket();
};
$(document).ready(function() {
$( '#pasteTextForm' ).submit(function( event )
{
$.ajax({
url: "/keypost",
type:'POST',
data:
{
val: pasteText.value
},
success: function(msg)
{
}
});
event.preventDefault();
});
});
</script>
<!-- This begins the MAIN MENU page ------------------------------------------------------------------->
@ -327,6 +346,11 @@
<div class="ui-block-a"><a href="#savestatepanel" data-transition="fade" data-role="button">Save State</a></div>
<div class="ui-block-b"><a href="#loadstatepanel" data-transition="fade" data-role="button">Load State</a></div>
</div>
<h2>Paste/Upload Text</h2>
<div class="ui-grid-a">
<div class="ui-block-a"><a href="#pastepanel" data-transition="fade" data-role="button">Paste Text</a></div>
<div class="ui-block-b"><a href="#uploadpastepanel" data-transition="fade" data-role="button">Upload Text</a></div>
</div>
<h2>Execution Control</h2>
<a href="javascript:executeCommands('togglepause');" data-role="button">Toggle Pause</a>
<a href="confirmexit.html" data-rel="dialog" data-role="button">Exit</a>
@ -464,7 +488,39 @@
<!-- This is here to prevent webkit from trying to put the last row of states under the bottom menu on small screens like phone-->
<br><br><br><br><br>
</div>
<!-- This begins the Paste Text panel -------------------------------------------------------->
<div data-role="panel" id="pastepanel" data-position="left" data-display="overlay" data-theme="a">
<h4>Paste Text to Keyboard</h4>
<form id="pasteTextForm" action="#pastepanel" method="post">
<div data-role="controlgroup" data-type="horizontal">
<a href="" data-rel="close" data-role="button">Exit</a>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</div>
<br>
<textarea id="pasteText" name="val"></textarea>
</form>
<!-- This is here to prevent webkit from trying to put the last row of states under the bottom menu on small screens like phone-->
<br><br><br><br><br>
</div>
<!-- This begins the Upload Text panel -------------------------------------------------------->
<div data-role="panel" id="uploadpastepanel" data-position="left" data-display="overlay" data-theme="a">
<h4>Upload Text to Keyboard</h4>
<form method="post" action="/keyupload" enctype="multipart/form-data" target="uploadpastelog" data-ajax="false">
<!-- note that we can't do file uploads via Ajax -->
<div data-role="controlgroup" data-type="horizontal">
<a href="" data-rel="close" data-role="button">Exit</a>
<input type="submit" value="Upload" />
</div>
<input type="file" name="file" /> <br/>
</form>
<!-- This is here to prevent webkit from trying to put the last row of states under the bottom menu on small screens like phone-->
<br><br><br><br><br>
</div>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
@ -795,7 +851,9 @@
</ul>
</div>
</div>
<div data-role="content" id="logsmenucontent">
<div data-role="content" id="logsmenucontent">
<p>Paste Upload Log</p> <!-- Yeah, this'll need reworking later. -->
<iframe name="uploadpastelog" width="250" height="250"></iframe>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">