diff --git a/NetPanel.Help/SystemHelp.cs b/NetPanel.Help/SystemHelp.cs new file mode 100644 index 0000000..6ff36e4 --- /dev/null +++ b/NetPanel.Help/SystemHelp.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace NetPanel.Help +{ + public class SystemHelp + { + /// + /// 是否 win系统 + /// + /// + public static bool IsWindows() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return true; + } + return false; + } + + + /// + /// 是否 linux 系统 + /// + /// + public static bool IsLinux() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return true; + } + return false; + } + + /// + /// 是否MacOs环境 + /// + /// + public static bool IsOSX() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return true; + } + return false; + } + + + + } +} diff --git a/NetPanel/Controllers/DataListController.cs b/NetPanel/Controllers/DataListController.cs deleted file mode 100644 index b305818..0000000 --- a/NetPanel/Controllers/DataListController.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json.Linq; - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace NetPanel.Controllers -{ - public class DataListController : Controller - { - public IActionResult DownloadFileList() - { - return View(); - } - - - - } - -} \ No newline at end of file diff --git a/NetPanel/Controllers/Home/HomeController.cs b/NetPanel/Controllers/Home/HomeController.cs new file mode 100644 index 0000000..d67175f --- /dev/null +++ b/NetPanel/Controllers/Home/HomeController.cs @@ -0,0 +1,70 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using NetPanel.Bl; +using NetPanel.Entity; +using NetPanel.Help; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +namespace NetPanel.Controllers.Home +{ + public class HomeController : Controller + { + + public IActionResult Overview() + { + return View(); + } + + + public IActionResult Index() + { + + ViewBag.data = new List() + { + + new Menu() + { + Id=1, + MenuName="概况", + Icon="nav-icon fas fa-th", + Url="/Home/Overview" + }, + + + new Menu() + { + Id=2, + MenuName="SSH", + Icon="nav-icon fas fa-th", + Url="/SSH/SSH" + }, + + + new Menu() + { + Id=2, + MenuName="列表", + Icon="nav-icon fas fa-th", + Child=new List(){ + new Menu{ MenuName="已有插件" , Url="/DataList/JsonData"}, + new Menu{ MenuName="模板插件" , Url="/DataList/JsonDataV7"}, + new Menu{ MenuName="404列表" , Url="/DataList/DownloadFileList"}, + } + } + + }; + + return View(); + + } + + + + } +} diff --git a/NetPanel/Controllers/Home/OverviewController.cs b/NetPanel/Controllers/Home/OverviewController.cs new file mode 100644 index 0000000..5387846 --- /dev/null +++ b/NetPanel/Controllers/Home/OverviewController.cs @@ -0,0 +1,89 @@ +using Microsoft.AspNetCore.Mvc; +using NetPanel.Bl; +using NetPanel.Entity; +using NetPanel.Help; + +namespace NetPanel.Controllers.Home +{ + public class OverviewController : Controller + { + /// + /// 获取概况 + /// + /// + public IActionResult GetOverview() + { + ReturnMsg returnMsg = new ReturnMsg(); + + try + { + if (SystemHelp.IsLinux()) + { + + #region 内存 + string output = ExecuteBl.Exec("free", "-m"); + + // 解析输出行 + string[] lines = output.Split('\n'); + string[] memoryInfo = lines[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + // 获取已使用和总内存大小 + float totalMemory = float.Parse(memoryInfo[1]); + float usedMemory = float.Parse(memoryInfo[2]); + + LogHeler.SelErrt("[HomeController-GetOverview]" + output); + + #endregion + + #region 存储 + output = ExecuteBl.Exec("df", "-h ./"); + lines = output.Split('\n'); + memoryInfo = lines[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + // 转换为GB单位 + double totalSizeInGB = memoryInfo[1].Replace("G", "").ToDouble(); + double availableFreeSpaceInGB = memoryInfo[2].Replace("G", "").ToDouble(); + + #endregion + + #region Cpu使用率 + output = ExecuteBl.Exec("/usr/bin/top", "-b -n 1"); + string cpuLine = output.Split('\n')[2]; + string[] cpuValues = cpuLine.Split(' ', StringSplitOptions.RemoveEmptyEntries); + double cpuUsage = double.Parse(cpuValues[1]); + + #endregion + + var data = new + { + //cpu + Cpu = new { Total = 100, Used = cpuUsage }, + //内存 + Ram = new { Total = totalMemory, Used = usedMemory }, + Size = new { Total = totalSizeInGB, Used = availableFreeSpaceInGB }, + }; + } + else + { + var data = new + { + //cpu + Cpu = new { Total = 100, Used = new Random().Next(0, 100) }, + //内存 + Ram = new { Total = 1000, Used = new Random().Next(0, 1000) }, + //内存 + Size = new { Total = 2000, Used = new Random().Next(0, 2000) }, + }; + returnMsg.Obj = data; + } + returnMsg.Code = 1; + + } + catch (Exception es) + { + LogHeler.SelErrt("[HomeController-GetOverview]" + es.ToString()); + } + return Ok(returnMsg); + } + + } +} diff --git a/NetPanel/Controllers/HomeController.cs b/NetPanel/Controllers/HomeController.cs deleted file mode 100644 index 14beb28..0000000 --- a/NetPanel/Controllers/HomeController.cs +++ /dev/null @@ -1,142 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using NetPanel.Bl; -using NetPanel.Entity; -using NetPanel.Help; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.Linq; -using System.Threading.Tasks; - -namespace NetPanel.Controllers -{ - public class HomeController : Controller - { - - public IActionResult Overview() - { - return View(); - } - - - /// - /// 获取概况 - /// - /// - public IActionResult GetOverview() - { - ReturnMsg returnMsg = new ReturnMsg(); - - try - { - - - - #region 内存 - string output = ExecuteBl.Exec("free", "-m"); - - // 解析输出行 - string[] lines = output.Split('\n'); - string[] memoryInfo = lines[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - // 获取已使用和总内存大小 - float totalMemory = float.Parse(memoryInfo[1]); - float usedMemory = float.Parse(memoryInfo[2]); - - LogHeler.SelErrt("[HomeController-GetOverview]" + output); - - #endregion - - #region 存储 - output = ExecuteBl.Exec("df", "-h ./"); - lines = output.Split('\n'); - memoryInfo = lines[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - - // 转换为GB单位 - double totalSizeInGB = memoryInfo[1].Replace("G", "").ToDouble(); - double availableFreeSpaceInGB = memoryInfo[2].Replace("G", "").ToDouble(); - - #endregion - - #region Cpu使用率 - output = ExecuteBl.Exec("/usr/bin/top", "-b -n 1"); - string cpuLine = output.Split('\n')[2]; - string[] cpuValues = cpuLine.Split(' ', StringSplitOptions.RemoveEmptyEntries); - double cpuUsage = double.Parse(cpuValues[1]); - - #endregion - - var data = new - { - //cpu - Cpu = new { Total = 100, Used = cpuUsage }, - //内存 - Ram = new { Total = totalMemory, Used = usedMemory }, - Size = new { Total = totalSizeInGB, Used = availableFreeSpaceInGB }, - }; - - //var data = new - //{ - // //cpu - // Cpu = new { Total = 100, Used = new Random().Next(0, 100) }, - // //内存 - // Ram = new { Total = 1000, Used = new Random().Next(0, 1000) }, - // //内存 - // Size = new { Total = 2000, Used = new Random().Next(0, 2000) }, - //}; - - returnMsg.Code = 1; - returnMsg.Obj = data; - } - catch (Exception es) - { - LogHeler.SelErrt("[HomeController-GetOverview]" + es.ToString()); - } - return Ok(returnMsg); - } - - - - public IActionResult Index() - { - - ViewBag.data = new List() - { - - new Menu() - { - Id=1, - MenuName="概况", - Icon="nav-icon fas fa-th", - Url="/Home/Overview" - }, - - - new Menu() - { - Id=1, - MenuName="列表", - Icon="nav-icon fas fa-th", - Child=new List(){ - new Menu{ MenuName="已有插件" , Url="/DataList/JsonData"}, - new Menu{ MenuName="模板插件" , Url="/DataList/JsonDataV7"}, - new Menu{ MenuName="404列表" , Url="/DataList/DownloadFileList"}, - } - } - - }; - - return View(); - - } - - public IActionResult Privacy() - { - return View(); - } - - - - } -} diff --git a/NetPanel/Controllers/LoginController.cs b/NetPanel/Controllers/Login/LoginController.cs similarity index 97% rename from NetPanel/Controllers/LoginController.cs rename to NetPanel/Controllers/Login/LoginController.cs index b75189f..e98f011 100644 --- a/NetPanel/Controllers/LoginController.cs +++ b/NetPanel/Controllers/Login/LoginController.cs @@ -14,7 +14,7 @@ using System.Diagnostics; using System.Text; using NetPanel.Bl; -namespace NetPanel.Controllers +namespace NetPanel.Controllers.Login { public class LoginController : MyController { @@ -31,7 +31,7 @@ namespace NetPanel.Controllers //string output = ExecuteBl.Exec("ping www.baidu.com"); - + //// 解析输出行 //string[] lines = output.Split('\n'); //string[] memoryInfo = lines[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); diff --git a/NetPanel/Controllers/SSH/SSHController.cs b/NetPanel/Controllers/SSH/SSHController.cs new file mode 100644 index 0000000..7caa709 --- /dev/null +++ b/NetPanel/Controllers/SSH/SSHController.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; + +namespace NetPanel.Controllers.SSH +{ + public class SSHController : Controller + { + public IActionResult SSH() + { + return View(); + } + } +} diff --git a/NetPanel/NetPanel.csproj b/NetPanel/NetPanel.csproj index e239f4d..1ee3f7a 100644 --- a/NetPanel/NetPanel.csproj +++ b/NetPanel/NetPanel.csproj @@ -7,13 +7,16 @@ - - - + + + + - + + + diff --git a/NetPanel/Program.cs b/NetPanel/Program.cs index a19f3d5..b6b3921 100644 --- a/NetPanel/Program.cs +++ b/NetPanel/Program.cs @@ -1,3 +1,5 @@ + + var builder = WebApplication.CreateBuilder(args); var services = builder.Services; @@ -17,7 +19,6 @@ services.AddControllersWithViews(o => o.Filters.Add(); }); - var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/NetPanel/Views/DataList/DownloadFileList.cshtml b/NetPanel/Views/DataList/DownloadFileList.cshtml deleted file mode 100644 index e9a76b4..0000000 --- a/NetPanel/Views/DataList/DownloadFileList.cshtml +++ /dev/null @@ -1,138 +0,0 @@ -@{ Layout = "~/Views/Shared/_Layout.cshtml"; } - -
- -
-
- -
-
-

404列表

- -
- - -
-
- -
- -
- - -
- - - - - - - - - - - -
路径状态时间操作
- - -
- - -
- - - - -
- -
- - - - diff --git a/NetPanel/Views/DataList/JsonData.cshtml b/NetPanel/Views/DataList/JsonData.cshtml deleted file mode 100644 index 9e59a7c..0000000 --- a/NetPanel/Views/DataList/JsonData.cshtml +++ /dev/null @@ -1,144 +0,0 @@ -@{ Layout = "~/Views/Shared/_Layout.cshtml"; } - -
- -
-
- -
-
-

已有插件

- -
- - -
-
- -
- -
- -
- -
- -
-
-
- -
-
- - - - - - - - - - -
key名称说明
- - -
- - -
- - - - -
- -
- - - - diff --git a/NetPanel/Views/DataList/JsonDataV7.cshtml b/NetPanel/Views/DataList/JsonDataV7.cshtml deleted file mode 100644 index c7caf0d..0000000 --- a/NetPanel/Views/DataList/JsonDataV7.cshtml +++ /dev/null @@ -1,137 +0,0 @@ -@{ Layout = "~/Views/Shared/_Layout.cshtml"; } - -
- -
-
- -
-
-

已有插件

- -
- - -
-
- -
- -
-
- -
- -
- - - - - - - - - - -
key名称说明
- - -
- - -
- - - - -
- -
- - - - diff --git a/NetPanel/Views/Home/Overview.cshtml b/NetPanel/Views/Home/Overview.cshtml index 4e4d2f5..e14debb 100644 --- a/NetPanel/Views/Home/Overview.cshtml +++ b/NetPanel/Views/Home/Overview.cshtml @@ -160,7 +160,7 @@ function GetOverview() { $.ajax({ - url: "/Home/GetOverview", + url: "/Overview/GetOverview", type: 'get', dataType: "json", success: function (msg) { diff --git a/NetPanel/Views/Home/Privacy.cshtml b/NetPanel/Views/Home/Privacy.cshtml deleted file mode 100644 index af4fb19..0000000 --- a/NetPanel/Views/Home/Privacy.cshtml +++ /dev/null @@ -1,6 +0,0 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

- -

Use this page to detail your site's privacy policy.

diff --git a/NetPanel/Views/Login/Login.cshtml b/NetPanel/Views/Login/Login.cshtml index 46c35df..f6feaf6 100644 --- a/NetPanel/Views/Login/Login.cshtml +++ b/NetPanel/Views/Login/Login.cshtml @@ -73,7 +73,7 @@ success: function (msg) { if (msg.Code == 1) { - window.location.href = "/Home/Index#/Home/Overview"; + window.location.href = "Home/Index#/Home/Overview"; } else { alert(msg.Msg); } diff --git a/NetPanel/Views/SSH/SSH.cshtml b/NetPanel/Views/SSH/SSH.cshtml new file mode 100644 index 0000000..b926958 --- /dev/null +++ b/NetPanel/Views/SSH/SSH.cshtml @@ -0,0 +1,48 @@ +@{ + Layout = "~/Views/Shared/_Layout.cshtml"; +} +
+
+
+ +
+
+

SSH

+ +
+ + +
+
+ +
+ + + + + + +
+ + +
+ + + + +
+ +
+ + + +