diff --git a/NetPanel.Bl/ExecuteBl.cs b/NetPanel.Bl/ExecuteBl.cs index 4ec918a..809631e 100644 --- a/NetPanel.Bl/ExecuteBl.cs +++ b/NetPanel.Bl/ExecuteBl.cs @@ -14,6 +14,7 @@ namespace NetPanel.Bl public static string Exec(string fileName,string command) { + if (OperatingSystem.IsWindows()) // 检查当前操作系统是否为 Windows { diff --git a/NetPanel.Bl/NetPanel.Bl.csproj b/NetPanel.Bl/NetPanel.Bl.csproj index 9da64cd..2c20308 100644 --- a/NetPanel.Bl/NetPanel.Bl.csproj +++ b/NetPanel.Bl/NetPanel.Bl.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/NetPanel.Bl/SshBl.cs b/NetPanel.Bl/SshBl.cs new file mode 100644 index 0000000..fcd2eb1 --- /dev/null +++ b/NetPanel.Bl/SshBl.cs @@ -0,0 +1,53 @@ +using Renci.SshNet; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.PortableExecutable; +using System.Text; +using System.Threading.Tasks; + +namespace NetPanel.Bl +{ + public class SshBl + { + + private string _username = ""; + private string _pwd = ""; + private string _host = ""; + + private SshClient client = null; + + public SshBl(string host, string username, string pwd) + { + _username = username; + _pwd = pwd; + _host = host; + client = new SshClient(host, username, pwd); + client.Connect(); + } + + + + public StreamReader RunCommand(string command) + { + var sshCommand = client.CreateCommand(command); + var asyncExecute = sshCommand.BeginExecute(); + return new StreamReader(sshCommand.OutputStream); + //string outStr; + //while ((outStr = reader.ReadLine()) != null) + //{ + + //} + } + + + /// + /// 关闭 + /// + public void Dispose() + { + client.Disconnect(); + client.Dispose(); + } + } +} diff --git a/NetPanel/Controllers/SSH/SSHController.cs b/NetPanel/Controllers/SSH/SSHController.cs index 7caa709..828da90 100644 --- a/NetPanel/Controllers/SSH/SSHController.cs +++ b/NetPanel/Controllers/SSH/SSHController.cs @@ -1,4 +1,6 @@ using Microsoft.AspNetCore.Mvc; +using NetPanel.Bl; +using System.Text; namespace NetPanel.Controllers.SSH { @@ -6,6 +8,30 @@ namespace NetPanel.Controllers.SSH { public IActionResult SSH() { + //SshBl sshBl = new SshBl("172.31.110.239", "root", "123456789"); + + //StringBuilder sbStr = new StringBuilder(); + //string tt = ""; + //var reader = sshBl.RunCommand("uname -a"); + //string outStr = null; + //while ((outStr = reader.ReadLine()) != null) + //{ + // sbStr.Append(outStr + "/r/n"); + //} + + //tt = sbStr.ToString(); + + //reader = sshBl.RunCommand("uname -a"); + //outStr = null; + //while ((outStr = reader.ReadLine()) != null) + //{ + // sbStr.Append(outStr); + //} + + + //tt = sbStr.ToString(); + + //sshBl.Dispose(); return View(); } } diff --git a/NetPanel/Views/SSH/SSH.cshtml b/NetPanel/Views/SSH/SSH.cshtml index b926958..92312b8 100644 --- a/NetPanel/Views/SSH/SSH.cshtml +++ b/NetPanel/Views/SSH/SSH.cshtml @@ -1,35 +1,156 @@ @{ Layout = "~/Views/Shared/_Layout.cshtml"; } +
-
+

SSH

+ - +
- + +
+ +
+
+ 机器 + 23 Jan 2:00 pm +
+ + Message User Image + +
+ Is this template really for free? That's unbelievable! +
+ +
+ + +
+
+ + 23 Jan 2:05 pm +
+ + Message User Image + +
+ You better believe it! +
+ +
+
+
+ + 23 Jan 2:05 pm +
+ + Message User Image + +
+ You better believe it! +
+ +
+
+
+ + 23 Jan 2:05 pm +
+ + Message User Image + +
+ You better believe it! +
+ +
+
+
+ + 23 Jan 2:05 pm +
+ + Message User Image + +
+ You better believe it! +
+ +
+
+
+ + 23 Jan 2:05 pm +
+ + Message User Image + +
+ You better believe it! +
+ +
+
+
+ + 23 Jan 2:05 pm +
+ + Message User Image + +
+ You better believe it! +
+ +
+
+
+ + 23 Jan 2:05 pm +
+ + Message User Image + +
+ You better believe it! +
+ +
- - + +
+
-