remove app->open_shell_socket(); add app->run_command("socket") instead

This commit is contained in:
Michal Moskal 2015-02-16 15:36:24 -08:00
Родитель c0ce88c9c7
Коммит d5a9bf7b8d
2 изменённых файлов: 4 добавлений и 55 удалений

Просмотреть файл

@ -575,24 +575,18 @@ module TDev.RT {
return undefined
}
function askShellAsync(rt:Runtime)
{
return rt.host.askSourceAccessAsync(lf("execute shell commands or manipulate files"),
lf("the shell and/or the file system. This script may be harmful for your computer. Do not allow this if you do not trust the source of this script."), false, true)
}
//? Runs a shell command. This action is only available when the script is running from a local web server.
//@ betaOnly [cmd].deflStrings("shell", "mkdir", "writeFile", "readFile", "readDir", "writeFiles", "pythonEnv")
//@ betaOnly [cmd].deflStrings("shell", "mkdir", "writeFile", "readFile", "readDir", "writeFiles", "pythonEnv", "socket")
//@ cap(shell) returns(JsonObject) async
export function run_command(cmd: string, data: JsonObject, r: ResumeCtx) {
var proxyAsync = r.rt.host.localProxyAsync;
if (cmd == "socket") Util.userError("invalid cmd")
if (!proxyAsync) {
r.resumeVal(JsonObject.wrap({ error: 'notsupported', reason: lf("This command requires a local proxy.") }));
return;
}
askShellAsync(r.rt)
r.rt.host.askSourceAccessAsync(lf("execute shell commands or manipulate files"),
lf("the shell and/or the file system. This script may be harmful for your computer. Do not allow this if you do not trust the source of this script."), false, true)
.then((allow :boolean) => {
if (!allow) return Promise.as(JsonObject.wrap({ error: 'denied', reason: lf("The user denied access to shell execution.") }));
else return proxyAsync(cmd, data ? data.value() : undefined);
@ -602,32 +596,6 @@ module TDev.RT {
)
}
//? Opens a WebSocket to the shell. This action is only available when the script is running from a local web server.
//@ betaOnly dbgOnly
//@ cap(shell) returns(WebSocket_) async
export function open_shell_socket(r: ResumeCtx) {
var proxyAsync = r.rt.host.localProxyAsync;
if (!proxyAsync) {
App.log(lf("This command requires a local proxy."))
r.resumeVal(undefined)
return;
}
askShellAsync(r.rt)
.then((allow :boolean) => {
if (!allow) {
App.log(lf("The user denied access to shell execution."))
return undefined
}
else return proxyAsync("socket", undefined)
})
.done(res => r.resumeVal(WebSocket_.mk(res, r.rt)),
e => {
App.log(e.message)
r.resumeVal(undefined)
})
}
//? Shows a dialog with the logs
//@ uiAsync betaOnly
export function show_logs(filter : string, r : ResumeCtx) {

Просмотреть файл

@ -7,7 +7,7 @@ module TDev {
export function localProxyHandler() {
return function (cmd, data) {
if (cmd == "shell") return LocalShell.runShellAsync(data)
else if (cmd == "socket") return LocalShell.shellSocketAsync()
else if (cmd == "socket") return Promise.as({ url: mgmtUrl("").replace(/^http/, "ws") })
else return LocalShell.mgmtRequestAsync("plugin/" + cmd, data)
};
}
@ -57,25 +57,6 @@ module TDev {
else return Util.httpPostRealJsonAsync(mgmtUrl(path), data)
}
export function shellSocketAsync(): Promise
{
var wsurl = mgmtUrl("").replace(/^http/, "ws");
Util.log('shell socket: {0}', wsurl);
var ws = new WebSocket(wsurl);
var r = new PromiseInv()
ws.onopen = () => {
ws.onopen = null
ws.onerror = null
r.success(ws)
}
ws.onerror = e => {
r.error(ws)
}
return r
}
var lastShell: WebSocket = undefined;
export function runShellAsync(data: any): Promise {
Util.log('shell run {0}', JSON.stringify(data));