This commit is contained in:
Mn
2023-11-08 17:43:39 +08:00
parent efaed011e0
commit b626dc1b68
5 changed files with 213 additions and 8 deletions

View File

@@ -14,6 +14,7 @@ namespace NetPanel.Bl
public static string Exec(string fileName,string command) public static string Exec(string fileName,string command)
{ {
if (OperatingSystem.IsWindows()) // 检查当前操作系统是否为 Windows if (OperatingSystem.IsWindows()) // 检查当前操作系统是否为 Windows
{ {

View File

@@ -6,6 +6,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="SSH.NET" Version="2023.0.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\NetPanel.Entity\NetPanel.Entity.csproj" /> <ProjectReference Include="..\NetPanel.Entity\NetPanel.Entity.csproj" />
<ProjectReference Include="..\NetPanel.Help\NetPanel.Help.csproj" /> <ProjectReference Include="..\NetPanel.Help\NetPanel.Help.csproj" />

53
NetPanel.Bl/SshBl.cs Normal file
View File

@@ -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)
//{
//}
}
/// <summary>
/// 关闭
/// </summary>
public void Dispose()
{
client.Disconnect();
client.Dispose();
}
}
}

View File

@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NetPanel.Bl;
using System.Text;
namespace NetPanel.Controllers.SSH namespace NetPanel.Controllers.SSH
{ {
@@ -6,6 +8,30 @@ namespace NetPanel.Controllers.SSH
{ {
public IActionResult 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(); return View();
} }
} }

View File

@@ -1,35 +1,156 @@
@{ @{
Layout = "~/Views/Shared/_Layout.cshtml"; Layout = "~/Views/Shared/_Layout.cshtml";
} }
<style>
</style>
<section class="content-header"></section> <section class="content-header"></section>
<section class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
<!-- SELECT2 EXAMPLE --> <!-- SELECT2 EXAMPLE -->
<div class="card card-default"> <div class="card card-primary card-outline direct-chat direct-chat-primary">
<div class="card-header"> <div class="card-header">
<h3 class="card-title">SSH</h3> <h3 class="card-title">SSH</h3>
<div class="card-tools"> <div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse"> <button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i> <i class="fas fa-minus"></i>
</button> </button>
<button type="button" class="btn btn-tool" data-card-widget="remove">
<i class="fas fa-times"></i>
</button>
</div> </div>
</div> </div>
<!-- /.card-header --> <!-- /.card-header -->
<div class="card-body"> <div class="card-body">
<!-- Conversations are loaded here -->
<div class="direct-chat-messages">
<!-- Message. Default to the left -->
<div class="direct-chat-msg">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-left">机器</span>
<span class="direct-chat-timestamp float-right">23 Jan 2:00 pm</span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="/adminlte/dist/img/avatar2.png" alt="Message User Image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
Is this template really for free? That's unbelievable!
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
<!-- Message to the right -->
<div class="direct-chat-msg right">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-right">我</span>
<span class="direct-chat-timestamp float-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="/adminlte/dist/img/avatar3.png" alt="Message User Image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<div class="direct-chat-msg right">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-right">我</span>
<span class="direct-chat-timestamp float-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="/adminlte/dist/img/avatar3.png" alt="Message User Image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<div class="direct-chat-msg right">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-right">我</span>
<span class="direct-chat-timestamp float-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="/adminlte/dist/img/avatar3.png" alt="Message User Image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<div class="direct-chat-msg right">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-right">我</span>
<span class="direct-chat-timestamp float-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="/adminlte/dist/img/avatar3.png" alt="Message User Image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<div class="direct-chat-msg right">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-right">我</span>
<span class="direct-chat-timestamp float-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="/adminlte/dist/img/avatar3.png" alt="Message User Image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<div class="direct-chat-msg right">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-right">我</span>
<span class="direct-chat-timestamp float-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="/adminlte/dist/img/avatar3.png" alt="Message User Image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<div class="direct-chat-msg right">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-right">我</span>
<span class="direct-chat-timestamp float-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="/adminlte/dist/img/avatar3.png" alt="Message User Image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
</div>
<!--/.direct-chat-messages-->
</div> </div>
<!-- /.card-body --> <!-- /.card-body -->
<div class="card-footer" id="pager"> <div class="card-footer">
<form action="#" method="post">
<div class="input-group">
<input type="text" name="message" placeholder="Type Message ..." class="form-control">
<span class="input-group-append">
<button type="submit" class="btn btn-primary">Send</button>
</span>
</div>
</form>
</div> </div>
<!-- /.card-footer-->
</div> </div>
<!-- /.card --> <!-- /.card -->