From 3333e41caeb95fed907e515c136e5127f492d742 Mon Sep 17 00:00:00 2001 From: lxsang Date: Thu, 26 Nov 2015 13:52:49 +0100 Subject: [PATCH] add terminal plugin --- Makefile | 2 +- build/htdocs/index.html | 4 +- build/htdocs/scripts/camviewer.js | 1 + build/htdocs/scripts/sidebar.js | 6 +- build/htdocs/scripts/wterm.js | 245 ++++++++++++++++++++++++++++++ build/htdocs/style/site.css | 21 +++ build/httpd | Bin 44860 -> 44860 bytes build/plugins/dummy.dylib | Bin 43252 -> 43252 bytes build/plugins/fileman.dylib | Bin 47524 -> 47524 bytes build/plugins/pluginsman.dylib | Bin 42916 -> 42916 bytes build/plugins/wterm.dylib | Bin 0 -> 43540 bytes plugins/wterm/wterm.c | 88 +++++++++++ 12 files changed, 364 insertions(+), 3 deletions(-) create mode 100644 build/htdocs/scripts/wterm.js create mode 100644 build/htdocs/style/site.css create mode 100755 build/plugins/wterm.dylib create mode 100644 plugins/wterm/wterm.c diff --git a/Makefile b/Makefile index ce25268..2778a73 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ EXT=dylib SERVER=plugin_manager.o ini.o http_server.o plugins/dictionary.o plugins/utils.o SERVERLIB=-lpthread -ldl #-lsocket -PLUGINS= dummy.$(EXT) fileman.$(EXT) pluginsman.$(EXT) +PLUGINS= dummy.$(EXT) fileman.$(EXT) pluginsman.$(EXT) wterm.$(EXT) PLUGINSDEP = plugins/plugin.o plugins/dbhelper.o plugins/dictionary.o plugins/utils.o plugins/list.o PLUGINLIBS = -lsqlite3 diff --git a/build/htdocs/index.html b/build/htdocs/index.html index 9be0adc..de4872c 100644 --- a/build/htdocs/index.html +++ b/build/htdocs/index.html @@ -1,12 +1,14 @@ - + + + diff --git a/build/htdocs/scripts/camviewer.js b/build/htdocs/scripts/camviewer.js index 8369770..be73550 100644 --- a/build/htdocs/scripts/camviewer.js +++ b/build/htdocs/scripts/camviewer.js @@ -1,3 +1,4 @@ + var picam_config = { name: 'picam_layout', toolbar:{ diff --git a/build/htdocs/scripts/sidebar.js b/build/htdocs/scripts/sidebar.js index e42cdf1..ef93fec 100644 --- a/build/htdocs/scripts/sidebar.js +++ b/build/htdocs/scripts/sidebar.js @@ -14,7 +14,8 @@ var sidebar_config = { text: 'Plugins', icon: 'fa-cogs' }, - { id: 'level-fman', text: 'File manager', icon: 'fa-folder-open' } + { id: 'level-fman', text: 'File manager', icon: 'fa-folder-open' }, + { id: 'level-wterm', text: 'Terminal', icon: 'fa-wrench' } ] }, { @@ -47,6 +48,9 @@ var sidebar_config = { case 'level-picam': w2ui.layout.content('main', w2ui.picam_layout); break; + case 'level-wterm': + w2ui.layout.content('main', w2ui.wterm_layout); + break; default: //do nothing w2ui.layout.content('main',"Empty page"); console.log('Event: ' + event.type + ' Target: ' + event.target); diff --git a/build/htdocs/scripts/wterm.js b/build/htdocs/scripts/wterm.js new file mode 100644 index 0000000..3dbfcbb --- /dev/null +++ b/build/htdocs/scripts/wterm.js @@ -0,0 +1,245 @@ +/*! terminal.js v2.0 | (c) 2014 Erik Österberg | https://github.com/eosterberg/terminaljs */ + +var Terminal = (function () { + // PROMPT_TYPE + var PROMPT_INPUT = 1, PROMPT_PASSWORD = 2, PROMPT_CONFIRM = 3 + + var fireCursorInterval = function (inputField, terminalObj) { + var cursor = terminalObj._cursor + setTimeout(function () { + if (inputField.parentElement && terminalObj._shouldBlinkCursor) { + cursor.style.visibility = cursor.style.visibility === 'visible' ? 'hidden' : 'visible' + fireCursorInterval(inputField, terminalObj) + } else { + cursor.style.visibility = 'visible' + } + }, 500) + } + + var firstPrompt = true; + promptInput = function (terminalObj, message, PROMPT_TYPE, callback) { + var shouldDisplayInput = (PROMPT_TYPE === PROMPT_INPUT) + var inputField = document.createElement('input') + + inputField.style.position = 'absolute' + inputField.style.zIndex = '-100' + inputField.style.outline = 'none' + inputField.style.border = 'none' + inputField.style.opacity = '0' + inputField.style.fontSize = '0.2em' + + terminalObj._inputLine.textContent = '' + terminalObj._input.style.display = 'block' + terminalObj.html.appendChild(inputField) + fireCursorInterval(inputField, terminalObj) + + if (message.length) terminalObj.msg(PROMPT_TYPE === PROMPT_CONFIRM ? message + ' (y/n)' : message) + + inputField.onblur = function () { + terminalObj._cursor.style.display = 'none' + } + + inputField.onfocus = function () { + inputField.value = terminalObj._inputLine.textContent + terminalObj._cursor.style.display = 'inline' + } + + terminalObj.html.onclick = function () { + inputField.focus() + } + + inputField.onkeydown = function (e) { + if (e.which === 37 || e.which === 39 || e.which === 38 || e.which === 40 || e.which === 9) { + e.preventDefault() + } else if (shouldDisplayInput && e.which !== 13) { + setTimeout(function () { + terminalObj._inputLine.textContent = inputField.value + }, 1) + } + } + inputField.onkeyup = function (e) { + if (PROMPT_TYPE === PROMPT_CONFIRM || e.which === 13) { + terminalObj._input.style.display = 'none' + var inputValue = inputField.value + if (shouldDisplayInput) terminalObj._print(message+inputValue,"wterm_input_div") + terminalObj.html.removeChild(inputField) + if (typeof(callback) === 'function') { + if (PROMPT_TYPE === PROMPT_CONFIRM) { + callback(inputValue.toUpperCase()[0] === 'Y' ? true : false) + } else callback(inputValue) + } + } + } + if (firstPrompt) { + firstPrompt = false + setTimeout(function () { inputField.focus() }, 50) + } else { + inputField.focus() + } + } + + var terminalBeep + + var TerminalConstructor = function (id) { + if (!terminalBeep) { + terminalBeep = document.createElement('audio') + var source = '' + source + 'ogg" type="audio/ogg">' + terminalBeep.volume = 0.05 + } + + this.html = document.createElement('div') + this.html.className = 'Terminal' + if (typeof(id) === 'string') { this.html.id = id } + + this._innerWindow = document.createElement('div') + this._output = document.createElement('p') + this._inputLine = document.createElement('span') //the span element where the users input is put + this._cursor = document.createElement('span') + this._input = document.createElement('p') //the full element administering the user input, including cursor + this._input.className = "wterm_input_p" + this._cursor.className = "wterm_cursor" + //this._output.className = "wterm_output_p" + this._input.appendChild(document.createElement('span')); + this._shouldBlinkCursor = true + + this.beep = function () { + terminalBeep.load() + terminalBeep.play() + } + this.msg = function (message) { + this._input.firstChild.textContent = message + } + this._print = function(msg,cls) + { + var newLine = document.createElement('div') + newLine.className = cls + newLine.textContent = msg + this._output.appendChild(newLine) + } + this.print = function (message) { + this._print(message,"wterm_output_div") + } + + this.input = function (message, callback) { + promptInput(this, message, PROMPT_INPUT, callback) + } + + this.password = function (message, callback) { + promptInput(this, message, PROMPT_PASSWORD, callback) + } + + this.confirm = function (message, callback) { + promptInput(this, message, PROMPT_CONFIRM, callback) + } + + this.clear = function () { + this._output.innerHTML = '' + } + + this.sleep = function (milliseconds, callback) { + setTimeout(callback, milliseconds) + } + + this.setTextSize = function (size) { + this._output.style.fontSize = size + this._input.style.fontSize = size + } + + this.setTextColor = function (col) { + this.html.style.color = col + this._cursor.style.background = col + } + + this.setBackgroundColor = function (col) { + this.html.style.background = col + } + + this.setWidth = function (width) { + this.html.style.width = width + } + + this.setHeight = function (height) { + this.html.style.height = height + } + + this.blinkingCursor = function (bool) { + bool = bool.toString().toUpperCase() + this._shouldBlinkCursor = (bool === 'TRUE' || bool === '1' || bool === 'YES') + } + + this._input.appendChild(this._inputLine) + this._input.appendChild(this._cursor) + this._innerWindow.appendChild(this._output) + this._innerWindow.appendChild(this._input) + this.html.appendChild(this._innerWindow) + + this.setBackgroundColor('black') + this.setTextColor('white') + this.setTextSize('1em') + this.setWidth('100%') + this.setHeight('100%') + + this.html.style.fontFamily = 'Monaco, Courier' + this.html.style.margin = '0' + this._innerWindow.style.padding = '10px' + this._input.style.margin = '0' + this._output.style.margin = '0' + this._cursor.style.background = '#00cc00' + this._cursor.innerHTML = 'C' //put something in the cursor.. + this._cursor.style.display = 'none' //then hide it + this._input.style.display = 'none' + } + + return TerminalConstructor +}()); +var wtermobj; + +var wterm_config = { + name: 'wterm_layout', + panels: [ + { + type: 'main', + style: 'padding: 0px;', + content: '
' + } + ], + onRefresh:function(event) + { + if($("#wterm_input") ) + { + wtermobj = new Terminal(); + wtermobj.setTextSize(11); + var nest_callback = function(data) + { + if(data.length>0) + { + //send to server + var webtty = new EventSource('/wterm?cmd='+data); + webtty.onmessage = function (e) { + wtermobj.print(e.data); + var par = $("#wterm"); + par.animate({ + scrollTop: par.get(0).scrollHeight + }, 0); + }; + webtty.onerror = function(e) + { + // finish the command + webtty.close(); + wtermobj.input("antd> ",nest_callback); + } + } + else + { + wtermobj.input("antd> ",nest_callback); + } + }; + $("#wterm").html(wtermobj.html); + $("#wterm").parent().css("overflow","hidden"); + $("#wterm").parent().css("background-color","black"); + wtermobj.input("antd> ",nest_callback); + } + } +} +$().w2layout(wterm_config); diff --git a/build/htdocs/style/site.css b/build/htdocs/style/site.css new file mode 100644 index 0000000..ba6325d --- /dev/null +++ b/build/htdocs/style/site.css @@ -0,0 +1,21 @@ +#wterm { + width:100%; + height: 100%; + background-color:black; + position:absolute; + overflow:auto; +} +.wterm_output_div{ + padding-left:15px; +} +.wterm_input_div +{ + color:#00cc00; +} +.wterm_input_p{ + color:#00cc00; +} +.wterm_cursor{ + color:#00cc00; + background-color:#00cc00; +} \ No newline at end of file diff --git a/build/httpd b/build/httpd index c6799778cf46ec20a585e4437c79185368a7ddee..1cdc37f49dd2691b09c46fda3efe56317a09a371 100755 GIT binary patch delta 75 zcmdmUk7>_6rVR?6%#&V+ZC37_%M4~5?%B%-W;FMmg@^=C;$;GhBu|NDfvB0WLx9aF O(a6L&b#vp&-K+pIVIide delta 75 zcmdmUk7>_6rVR?6%*UHTHY<0|Wd<`2_v~e4J^>VI?mNp2W&}^-Wdbvjr^K>=8HZ== S5MVPfvNSg~+T6HuH!A@A)gTK1 diff --git a/build/plugins/dummy.dylib b/build/plugins/dummy.dylib index 9294138ee61e8a431c551b9818ca81abe8d7762f..6ac1b7dc89cbef22eb6b9f10bf3a54ebbc26bb79 100755 GIT binary patch delta 63 zcmexzk?G4trVSNU%#&V+ZLY4G%L-;lH}tZA8LL}(nZS(QZLuuOlYwfayLnl`4DAUg FB>=sJ9AE$d delta 63 zcmexzk?G4trVSNU%qN;cHdj~8Wd$>&8+uv5jMXi?Okl?DwpfUWbT=P8mkG@HJuQ}nc`{H<^lV;MFe7_` Gr6d65C>@mm delta 63 zcmZ4TnQ6&qrVT5)m`^l?Y+l{9mKDs1p3utzX1t!l%LHcpo)!xciJr|1QIoyEQW5~c Cx*Syi diff --git a/build/plugins/pluginsman.dylib b/build/plugins/pluginsman.dylib index 1c53b48124ee7e8428e654d5cba17cced415cb10..208c682071db1f3132c310fcf9d0202076415c13 100755 GIT binary patch delta 63 zcmZ2-o@vQ>rVSod%#&V+ZT7BO%L-=vuJ2_5GrC)NnZS(MZLuuOlYwe}ck!}<8Qc?Q GiURrVSod%qN;cHhWjCWd$>S*Y~o38Qm?sOkl?BwpfVB?=D`58tw@*#Q}(+ B8(9DV diff --git a/build/plugins/wterm.dylib b/build/plugins/wterm.dylib new file mode 100755 index 0000000000000000000000000000000000000000..b5341095cfcd7e049f227ba00f790e5e1d3b7400 GIT binary patch literal 43540 zcmeHwdw5(`x%Zy5Y12ZPfTDmPL#0qIZBw9FE`=#{U@A!omjXwqliQ?8$z_m1;zgir|UZVn9-+fKAIm8UdloEoy~5(xU+@4T$#p{ob|K%$`Z$@c7U7 zJ6=RZLCuRc%N#1l2GSQD)dHw=Yh@wS>+ z)~it7vs%~H9z{Z|o#IiV8JgT6$*tL zLiN$==CJZ9%)f}1*P|JTSw}wVVLjP_3=V}BExdH0i>gYyRdupV{m|9RVm+Z;))hXX zP)k!Nc3pE#Yf~r^kA9>)BaZUidNDiCp&W|a!5b*OU)tOK1mdEr4NT8oksIEF*ZP3{KE2~jqK21WL*Di9b;tGXoTbr9(Ta0&M zc~ln2Bb{46cN<|C%Qc8M6e?f5C+WvI^D9S0nf*KNP&M% zTVqq*oJdpK^2V0foNMFZX!Gp4>zW$1n$~p7>L>#b<+F@RU{j8H{J?$4kP#Ge87ff` z0vJd7ddu1$;O=#nwQ7IM+7Et}nkfp!__9fFh3zh1O_H@bzGGQ8XHm}aIXD^5Gq>+N z@P?%e4*2Oc`)~Ngvj2=94Zl*7?Kjo3rcSkvH<*5Sph`9$sH1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3RUx76it+uZXaS{LWL^NyHDoQQ>dP|okI0;%_&qb_nTlvuZEx88In{Y=m8A_X%1ap|Tp|U7@ zF)-)D+fi9G_A+2L$bAj4z*AiS%zCOKGAg?6{ADTRvLEYM?t&GERdcgS+_+LDHttf< k<|QiHygfym*QUhAeW_4PU6j((nz+6irS3$Hx!-C1A4Q>`7ytkO literal 0 HcmV?d00001 diff --git a/plugins/wterm/wterm.c b/plugins/wterm/wterm.c new file mode 100644 index 0000000..2692e03 --- /dev/null +++ b/plugins/wterm/wterm.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include "../plugin.h" + +void init(); +call __init__ = init; + +void init() +{ + +} +void pexit() +{ + +} + +int read_buf(int fd, char*buf,int size) +{ + int i = 0; + char c = '\0'; + int n; + while ((i < size - 1) && (c != '\n')) + { + n = read(fd, &c, 1); + if (n > 0) + { + buf[i] = c; + i++; + } + else if(n == -1) return n; + else + c = '\n'; + } + buf[i] = '\0'; + return i; +} +void execute(int client, const char* m, dictionary rq) +{ + textstream(client); + int filedes[2]; + char* code = R_STR(rq, "cmd"); + if(!code) return; + if(pipe(filedes) == -1) + { + perror("pipe"); + return; + } + pid_t pid = fork(); + if(pid == -1) + { + perror("folk"); + return; + } else if(pid == 0) + { + while ((dup2(filedes[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {} + close(filedes[1]); + close(filedes[0]); + // executecomand + system(code); + //perror("execl"); + _exit(1); + } + close(filedes[1]); + char buffer[1024]; + while (1) { + ssize_t count = read_buf(filedes[0],buffer, sizeof(buffer)); + if (count == -1) { + if (errno == EINTR) { + continue; + } else { + perror("read"); + return; + } + } else if (count == 0) { + break; + } else { + __t(client,"data:%s\n",buffer); + //handle_child_process_output(buffer, count); + } + } + close(filedes[0]); + wait(0); + free(code); + printf("Child process exit\n"); +} \ No newline at end of file