123456
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using System.Reflection.PortableExecutable;
|
using System.Reflection.PortableExecutable;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -30,8 +31,10 @@ namespace NetPanel.Bl
|
|||||||
|
|
||||||
public StreamReader RunCommand(string command)
|
public StreamReader RunCommand(string command)
|
||||||
{
|
{
|
||||||
|
|
||||||
var sshCommand = client.CreateCommand(command);
|
var sshCommand = client.CreateCommand(command);
|
||||||
var asyncExecute = sshCommand.BeginExecute();
|
var asyncExecute = sshCommand.BeginExecute();
|
||||||
|
|
||||||
return new StreamReader(sshCommand.OutputStream);
|
return new StreamReader(sshCommand.OutputStream);
|
||||||
//string outStr;
|
//string outStr;
|
||||||
//while ((outStr = reader.ReadLine()) != null)
|
//while ((outStr = reader.ReadLine()) != null)
|
||||||
@@ -40,6 +43,12 @@ namespace NetPanel.Bl
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ServerVersion()
|
||||||
|
{
|
||||||
|
return client.ConnectionInfo.ServerVersion;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关闭
|
/// 关闭
|
||||||
|
|||||||
@@ -1,24 +1,33 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using NetPanel.Bl;
|
using NetPanel.Bl;
|
||||||
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace NetPanel.Controllers.SSH
|
namespace NetPanel.Controllers.SSH
|
||||||
{
|
{
|
||||||
public class SSHController : Controller
|
public class SSHController : Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public IActionResult SSH()
|
public IActionResult SSH()
|
||||||
{
|
{
|
||||||
//SshBl sshBl = new SshBl("172.31.110.239", "root", "123456789");
|
|
||||||
|
|
||||||
|
//SshBl sshBl = new SshBl("172.31.110.239", "root", "123456789");
|
||||||
|
////string tt = sshBl.ServerVersion();
|
||||||
//StringBuilder sbStr = new StringBuilder();
|
//StringBuilder sbStr = new StringBuilder();
|
||||||
//string tt = "";
|
//string tt = "";
|
||||||
//var reader = sshBl.RunCommand("uname -a");
|
//var reader = sshBl.RunCommand("top");
|
||||||
//string outStr = null;
|
//string outStr = null;
|
||||||
//while ((outStr = reader.ReadLine()) != null)
|
//while ((outStr = reader.ReadLine()) != null)
|
||||||
//{
|
//{
|
||||||
// sbStr.Append(outStr + "/r/n");
|
// sbStr.Append(outStr + "/r/n");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//tt = sbStr.ToString();
|
//tt = sbStr.ToString();
|
||||||
|
|
||||||
//reader = sshBl.RunCommand("uname -a");
|
//reader = sshBl.RunCommand("uname -a");
|
||||||
@@ -34,5 +43,10 @@ namespace NetPanel.Controllers.SSH
|
|||||||
//sshBl.Dispose();
|
//sshBl.Dispose();
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
|
|
||||||
|
using NetPanel.SignalR;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
var services = builder.Services;
|
var services = builder.Services;
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
|
services.AddSignalR(); //ֻ<><D6BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>AddSignalR
|
||||||
|
|
||||||
services.AddControllersWithViews();
|
services.AddControllersWithViews();
|
||||||
services.AddControllers().AddJsonOptions(options =>
|
services.AddControllers().AddJsonOptions(options =>
|
||||||
{
|
{
|
||||||
@@ -37,5 +41,8 @@ app.MapControllerRoute(
|
|||||||
name: "default",
|
name: "default",
|
||||||
pattern: "{controller=Login}/{action=Login}/{id?}");
|
pattern: "{controller=Login}/{action=Login}/{id?}");
|
||||||
|
|
||||||
|
|
||||||
|
app.MapHub<ChatHub>("/chatHub");
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,25 @@
|
|||||||
{
|
{
|
||||||
|
"profiles": {
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WSL": {
|
||||||
|
"commandName": "WSL2",
|
||||||
|
"distributionName": ""
|
||||||
|
},
|
||||||
|
"NetPanel": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
},
|
||||||
|
"applicationUrl": "http://localhost:5238"
|
||||||
|
}
|
||||||
|
},
|
||||||
"iisSettings": {
|
"iisSettings": {
|
||||||
"windowsAuthentication": false,
|
"windowsAuthentication": false,
|
||||||
"anonymousAuthentication": true,
|
"anonymousAuthentication": true,
|
||||||
@@ -6,23 +27,5 @@
|
|||||||
"applicationUrl": "http://localhost:2047",
|
"applicationUrl": "http://localhost:2047",
|
||||||
"sslPort": 0
|
"sslPort": 0
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"NetPanel": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"applicationUrl": "http://localhost:5238",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"IIS Express": {
|
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
54
NetPanel/SignalR/ChatHub.cs
Normal file
54
NetPanel/SignalR/ChatHub.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using NetPanel.Bl;
|
||||||
|
using NetPanel.Entity;
|
||||||
|
using Renci.SshNet.Messages;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NetPanel.SignalR
|
||||||
|
{
|
||||||
|
public class ChatHub : Hub
|
||||||
|
{
|
||||||
|
|
||||||
|
public override async Task OnConnectedAsync()
|
||||||
|
{
|
||||||
|
|
||||||
|
ReturnMsg rm = new ReturnMsg();
|
||||||
|
rm.Code = 1;
|
||||||
|
|
||||||
|
var cid = Context.ConnectionId;
|
||||||
|
rm.Obj = cid;
|
||||||
|
|
||||||
|
//根据id获取指定客户端
|
||||||
|
var client = Clients.Client(cid);
|
||||||
|
//向指定用户发送消息
|
||||||
|
await client.SendAsync("ConnectionId", rm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<ReturnMsg> CreateConnectionAsync(string connectionId, string command)
|
||||||
|
{
|
||||||
|
ReturnMsg rm = new ReturnMsg();
|
||||||
|
rm.Code = 1;
|
||||||
|
|
||||||
|
//SshBl sshBl = new SshBl("172.31.110.239", "root", "123456789");
|
||||||
|
////string tt = sshBl.ServerVersion();
|
||||||
|
//StringBuilder sbStr = new StringBuilder();
|
||||||
|
//string tt = "";
|
||||||
|
//var reader = sshBl.RunCommand("top");
|
||||||
|
//string outStr = null;
|
||||||
|
//while ((outStr = reader.ReadLine()) != null)
|
||||||
|
//{
|
||||||
|
// sbStr.Append(outStr + "/r/n");
|
||||||
|
//}
|
||||||
|
rm.Obj = "====>" + command;
|
||||||
|
//根据id获取指定客户端
|
||||||
|
var client = Clients.Client(connectionId);
|
||||||
|
|
||||||
|
// await client.SendAsync("CreateConnectionAsync", rm);
|
||||||
|
|
||||||
|
|
||||||
|
return rm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,13 +37,22 @@
|
|||||||
|
|
||||||
</section>
|
</section>
|
||||||
<link href="/adminlte/plugins/xterm/xterm.css" rel="stylesheet" />
|
<link href="/adminlte/plugins/xterm/xterm.css" rel="stylesheet" />
|
||||||
<script src="/adminlte/plugins/xterm/xterm.js"></script>
|
<script src="/adminlte/plugins/xterm/xterm.js"></script><
|
||||||
|
<script src="/lib/microsoft/signalr/dist/browser/signalr.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
||||||
var term = new Terminal({
|
var term = new Terminal({
|
||||||
cursorBlink: "block",
|
cursorStyle: 'underline', //光标样式
|
||||||
|
cursorBlink: true, // 光标闪烁
|
||||||
|
convertEol: true, //启用时,光标将设置为下一行的开头
|
||||||
|
disableStdin: false, //是否应禁用输入。
|
||||||
|
theme: {
|
||||||
|
foreground: 'yellow', //字体
|
||||||
|
background: '#060101', //背景色
|
||||||
|
cursor: 'help',//设置光标
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 获取窗口的宽度和高度。
|
// 获取窗口的宽度和高度。
|
||||||
@@ -53,41 +62,80 @@
|
|||||||
// 调整终端的尺寸。
|
// 调整终端的尺寸。
|
||||||
term.resize(parseInt(width / 10), parseInt(height / 22));
|
term.resize(parseInt(width / 10), parseInt(height / 22));
|
||||||
|
|
||||||
|
//回车输入的内容
|
||||||
var curr_line = '';
|
var curr_line = '';
|
||||||
|
//历史内容
|
||||||
var entries = [];
|
var entries = [];
|
||||||
var currPos = 0;
|
var currPos = 0;
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
|
var connectionId = '';
|
||||||
|
|
||||||
term.open(document.getElementById('terminal'));
|
term.open(document.getElementById('terminal'));
|
||||||
term.prompt = () => {
|
term.prompt = () => {
|
||||||
term.write('\n\r' + curr_line + '\r\n\u001b[32m$ > \u001b[37m');
|
term.write('\n\u001b[32m$ >\u001b[37m');
|
||||||
};
|
};
|
||||||
term.write('Welcome to my Scheme web intepreter!\r\n123');
|
|
||||||
term.prompt();
|
|
||||||
|
//通讯
|
||||||
|
var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();
|
||||||
|
|
||||||
|
|
||||||
|
//signalR接收消息
|
||||||
|
connection.on("ReceiveMessage", function (user, message) {
|
||||||
|
term.write(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//获取通讯id
|
||||||
|
connection.on("ConnectionId", function (msg) {
|
||||||
|
|
||||||
|
term.write('Welcome to my Scheme web intepreter!\r\n123');
|
||||||
|
term.prompt();
|
||||||
|
connectionId = msg.obj;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// 监听后端终端关闭
|
||||||
|
connection.on('WriteErrorAsync', () => {
|
||||||
|
|
||||||
|
term.write('SessionClosed');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
term.on('key', function (key, ev) {
|
term.on('key', function (key, ev) {
|
||||||
|
|
||||||
const printable = !ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey &&
|
const printable = !ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey
|
||||||
!(ev.keyCode === 37 && term.buffer.cursorX < 9);
|
//const printable = !e.domEvent.altKey && !e.domEvent.altGraphKey && !e.domEvent.ctrlKey && !e.domEvent.metaKey;
|
||||||
|
|
||||||
if (ev.keyCode === 13) { // Enter key
|
if (ev.keyCode === 13) { // Enter key
|
||||||
if (curr_line.replace(/^\s+|\s+$/g, '').length != 0) { // Check if string is all whitespace
|
if (curr_line.replace(/^\s+|\s+$/g, '').length != 0) { // Check if string is all whitespace
|
||||||
entries.push(curr_line);
|
entries.push(curr_line);
|
||||||
currPos = entries.length - 1;
|
currPos = entries.length - 1;
|
||||||
term.prompt();
|
// term.prompt();
|
||||||
|
|
||||||
|
connection.invoke('CreateConnectionAsync', connectionId, curr_line).then((result) => {
|
||||||
|
if (result.code == 1) {
|
||||||
|
//term.prompt();
|
||||||
|
//term.write(result.obj);
|
||||||
|
|
||||||
|
term.write('\n' + result.obj);
|
||||||
|
term.prompt();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
term.write('\n\33[2K\r\u001b[32m$ > \u001b[37m');
|
term.write('\n\33[2K\r\u001b[32m$ >\u001b[37m');
|
||||||
}
|
}
|
||||||
curr_line = '';
|
curr_line = '';
|
||||||
} else if (ev.keyCode === 8) { // Backspace
|
} else if (ev.keyCode === 8) { // Backspace
|
||||||
if (term.buffer.cursorX > 5) {
|
if (term.buffer.cursorX > 3) {
|
||||||
curr_line = curr_line.slice(0, term.buffer.cursorX - 6) + curr_line.slice(term.buffer.cursorX - 5);
|
curr_line = curr_line.slice(0, -1);
|
||||||
pos = curr_line.length - term.buffer.cursorX + 6;
|
term.write('\b \b');
|
||||||
term.write('\33[2K\r\u001b[32m$ > \u001b[37m' + curr_line);
|
|
||||||
term.write('\033['.concat(pos.toString()).concat('D')); //term.write('\033[<N>D');
|
|
||||||
if (term.buffer.cursorX == 5 || term.buffer.cursorX == curr_line.length + 6) {
|
|
||||||
term.write('\033[1C')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (ev.keyCode === 38) { // Up arrow
|
} else if (ev.keyCode === 38) { // Up arrow
|
||||||
if (entries.length > 0) {
|
if (entries.length > 0) {
|
||||||
@@ -95,41 +143,27 @@
|
|||||||
currPos -= 1;
|
currPos -= 1;
|
||||||
}
|
}
|
||||||
curr_line = entries[currPos];
|
curr_line = entries[currPos];
|
||||||
term.write('\33[2K\r\u001b[32m$ > \u001b[37m' + curr_line);
|
term.write('\33[2K\r\u001b[32m$ >\u001b[37m' + curr_line);
|
||||||
}
|
}
|
||||||
} else if (ev.keyCode === 40) { // Down arrow
|
} else if (ev.keyCode === 40) { // Down arrow
|
||||||
currPos += 1;
|
currPos += 1;
|
||||||
if (currPos === entries.length || entries.length === 0) {
|
if (currPos === entries.length || entries.length === 0) {
|
||||||
currPos -= 1;
|
currPos -= 1;
|
||||||
curr_line = '';
|
curr_line = '';
|
||||||
term.write('\33[2K\r\u001b[32m$ > \u001b[37m');
|
term.write('\33[2K\r\u001b[32m$ >\u001b[37m');
|
||||||
} else {
|
} else {
|
||||||
curr_line = entries[currPos];
|
curr_line = entries[currPos];
|
||||||
term.write('\33[2K\r\u001b[32m$ > \u001b[37m' + curr_line);
|
term.write('\33[2K\r\u001b[32m$ >\u001b[37m' + curr_line);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if (printable && !(ev.keyCode === 39 && term.buffer.cursorX > curr_line.length + 4)) {
|
} else if (printable) {
|
||||||
if (ev.keyCode != 37 && ev.keyCode != 39) {
|
|
||||||
// var input = ev.key;
|
|
||||||
// if (ev.keyCode == 9) { // Tab
|
|
||||||
// input = " ";
|
|
||||||
// }
|
|
||||||
// pos = curr_line.length - term.buffer.cursorX + 4;
|
|
||||||
// curr_line = [curr_line.slice(0, term.buffer.cursorX - 5), input, curr_line.slice(term.buffer.cursorX - 5)].join('');
|
|
||||||
// term.write('\33[2K\r\u001b[32m$ > \u001b[37m' + curr_line);
|
|
||||||
// term.write('\033['.concat(pos.toString()).concat('D')); //term.write('\033[<N>D');
|
|
||||||
|
|
||||||
term.write(key);
|
curr_line += key;
|
||||||
} else {
|
term.write(key);
|
||||||
term.write(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// term.on('paste', function (data) {
|
//启动 SignalR 客户端
|
||||||
// curr_line += data;
|
connection.start();
|
||||||
// term.write(curr_line);
|
|
||||||
// });
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
14
NetPanel/libman.json
Normal file
14
NetPanel/libman.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0",
|
||||||
|
"defaultProvider": "unpkg",
|
||||||
|
"libraries": [
|
||||||
|
{
|
||||||
|
"library": "@microsoft/signalr@latest",
|
||||||
|
"destination": "wwwroot/lib/microsoft/signalr/",
|
||||||
|
"files": [
|
||||||
|
"dist/browser/signalr.min.js",
|
||||||
|
"dist/browser/signalr.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
3190
NetPanel/wwwroot/lib/microsoft/signalr/dist/browser/signalr.js
vendored
Normal file
3190
NetPanel/wwwroot/lib/microsoft/signalr/dist/browser/signalr.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
NetPanel/wwwroot/lib/microsoft/signalr/dist/browser/signalr.min.js
vendored
Normal file
2
NetPanel/wwwroot/lib/microsoft/signalr/dist/browser/signalr.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user