This commit is contained in:
Mn
2023-11-08 16:07:56 +08:00
parent 15c0aa1c5c
commit efaed011e0
16 changed files with 287 additions and 598 deletions

View File

@@ -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
{
/// <summary>
/// 是否 win系统
/// </summary>
/// <returns></returns>
public static bool IsWindows()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return true;
}
return false;
}
/// <summary>
/// 是否 linux 系统
/// </summary>
/// <returns></returns>
public static bool IsLinux()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return true;
}
return false;
}
/// <summary>
/// 是否MacOs环境
/// </summary>
/// <returns></returns>
public static bool IsOSX()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return true;
}
return false;
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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<Menu>()
{
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<Menu>(){
new Menu{ MenuName="已有插件" , Url="/DataList/JsonData"},
new Menu{ MenuName="模板插件" , Url="/DataList/JsonDataV7"},
new Menu{ MenuName="404列表" , Url="/DataList/DownloadFileList"},
}
}
};
return View();
}
}
}

View File

@@ -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
{
/// <summary>
/// 获取概况
/// </summary>
/// <returns></returns>
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);
}
}
}

View File

@@ -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();
}
/// <summary>
/// 获取概况
/// </summary>
/// <returns></returns>
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<Menu>()
{
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<Menu>(){
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();
}
}
}

View File

@@ -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);

View File

@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
namespace NetPanel.Controllers.SSH
{
public class SSHController : Controller
{
public IActionResult SSH()
{
return View();
}
}
}

View File

@@ -7,13 +7,16 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NetPanel.Bl\NetPanel.Bl.csproj" />
<ProjectReference Include="..\NetPanel.Entity\NetPanel.Entity.csproj" />
<ProjectReference Include="..\NetPanel.Help\NetPanel.Help.csproj" />
<Compile Remove="Dll\**" />
<Content Remove="Dll\**" />
<EmbeddedResource Remove="Dll\**" />
<None Remove="Dll\**" />
</ItemGroup>
<ItemGroup>
<Folder Include="Dll\" />
<ProjectReference Include="..\NetPanel.Bl\NetPanel.Bl.csproj" />
<ProjectReference Include="..\NetPanel.Entity\NetPanel.Entity.csproj" />
<ProjectReference Include="..\NetPanel.Help\NetPanel.Help.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,3 +1,5 @@
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
@@ -17,7 +19,6 @@ services.AddControllersWithViews(o =>
o.Filters.Add<NetPanel.Filter.ActionFilter>();
});
var app = builder.Build();
// Configure the HTTP request pipeline.

View File

@@ -1,138 +0,0 @@
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
<section class="content-header"></section>
<section class="content">
<div class="container-fluid">
<!-- SELECT2 EXAMPLE -->
<div class="card card-default">
<div class="card-header">
<h3 class="card-title">404列表</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="remove">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="form-group">
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>路径</th>
<th>状态</th>
<th>时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
<!-- /.card-body -->
<div class="card-footer" id="pager">
</div>
</div>
<!-- /.card -->
</div>
<!-- /.container-fluid -->
</section>
<script>
$(function () {
getList();
})
function getList() {
$('#pager').sjAjaxPager({
url: "/DataList/getDownloadFileList",
pageSize: 10,
searchParam: {
action: "getDownloadFileList"
},
success: function (data) {
if (data.ErrorCode == 1) {
var sHtml = '';
for (var i = 0; i < data.Data.length; i++) {
sHtml += "<tr>";
sHtml += "<td>" + data.Data[i]['Path'] + "</td>";
sHtml += "<td>" + data.Data[i]['Status'] + "</td>";
sHtml += "<td>" + dateFtt('yyyy-MM-dd hh:mm:ss', data.Data[i]['SysAddTime']) + "</td>";
if (data.Data[i]['Status'] == 0) {
sHtml += '<td><button type="button" class="btn btn-primary " onclick="updDownloadFile(' + data.Data[i]['Id'] + ')">已检查</button></td>';
} else {
sHtml += '<td></td>';
}
sHtml += "</tr>";
}
$('#tbody').html(sHtml)
}
},
complete: function () {
}
});
}
var isOk = true;
function updDownloadFile(id) {
if (isOk) {
isOk = false;
$.ajax({
url: "/DataList/updDownloadFile",
type: 'post',
dataType: "json",
data: { 'status': 1, 'id': id},
success: function (msg) {
alert(msg.Msg)
if (msg.Code == 1) {
getList();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
},
complete: function () {
isOk = true;
}
});
}
}
//时间 格式化
function dateFtt(fmt, date) { //author: meizz
date = new Date(date);
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
</script>

View File

@@ -1,144 +0,0 @@
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
<section class="content-header"></section>
<section class="content">
<div class="container-fluid">
<!-- SELECT2 EXAMPLE -->
<div class="card card-default">
<div class="card-header">
<h3 class="card-title">已有插件</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="remove">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="row">
<div class="form-group row col-12 col-md-3 col-xl-3">
<label class="col-form-label col-2 col-md-4 col-xl-3">key</label>
<div class="col-10 col-md-8 col-xl-9">
<input type="text" class="form-control" id="key">
</div>
</div>
<div class="form-group row col-12 col-md-3 col-xl-3">
<button type="button" class="btn btn-primary " onclick="getList()">添加</button>
</div>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>key</th>
<th>名称</th>
<th>说明</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
<!-- /.card-body -->
<div class="card-footer" id="pager">
</div>
</div>
<!-- /.card -->
</div>
<!-- /.container-fluid -->
</section>
<script>
$(function () {
getList();
})
function getList() {
$('#pager').sjAjaxPager({
url: "/DataList/getJsonDataList",
pageSize: 10,
searchParam: {
action: "getJsonDataList"
},
success: function (data) {
if (data.ErrorCode == 1) {
var sHtml = '';
for (var i = 0; i < data.Data.length; i++) {
sHtml += "<tr>";
sHtml += "<td>" + data.Data[i]['name'] + "</td>";
sHtml += "<td>" + data.Data[i]['title'] + "</td>";
sHtml += "<td title=\"" + data.Data[i]['ps'] + "\">" + getText(data.Data[i]['ps'], 12) + "</td>";
sHtml += "</tr>";
}
$('#tbody').html(sHtml)
}
},
complete: function () {
}
});
}
var isOk = true;
function addPluginList() {
if (isOk) {
isOk = false;
$.ajax({
url: "/DataList/addPluginList",
type: 'post',
dataType: "json",
data: { key: $('#key').val() },
success: function (msg) {
alert(msg.Msg)
if (msg.Code == 1) {
getList();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
},
complete: function () {
isOk = true;
}
});
}
}
function getText(str, len) {
if (str.length > len) {
return str.substring(0, len);
}
return str;
}
//时间 格式化
function dateFtt(fmt, date) { //author: meizz
date = new Date(date);
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
</script>

View File

@@ -1,137 +0,0 @@
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
<section class="content-header"></section>
<section class="content">
<div class="container-fluid">
<!-- SELECT2 EXAMPLE -->
<div class="card card-default">
<div class="card-header">
<h3 class="card-title">已有插件</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="remove">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="row">
<div class="form-group row col-12 col-md-3 col-xl-3">
<button type="button" class="btn btn-primary " onclick="getV7List()">更新列表</button>
</div>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>key</th>
<th>名称</th>
<th>说明</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
<!-- /.card-body -->
<div class="card-footer" id="pager">
</div>
</div>
<!-- /.card -->
</div>
<!-- /.container-fluid -->
</section>
<script>
$(function () {
getList();
})
function getList() {
$('#pager').sjAjaxPager({
url: "/DataList/getJsonDataV7List",
pageSize: 10,
searchParam: {
action: "getJsonDataList"
},
success: function (data) {
if (data.ErrorCode == 1) {
var sHtml = '';
for (var i = 0; i < data.Data.length; i++) {
sHtml += "<tr>";
sHtml += "<td>" + data.Data[i]['name'] + "</td>";
sHtml += "<td>" + data.Data[i]['title'] + "</td>";
sHtml += "<td title=\"" + data.Data[i]['ps']+ "\">" + getText(data.Data[i]['ps'],20) + "</td>";
sHtml += "</tr>";
}
$('#tbody').html(sHtml)
}
},
complete: function () {
}
});
}
var isOk = true;
function getV7List() {
if (isOk) {
isOk = false;
$.ajax({
url: "/DataList/getV7List",
type: 'post',
dataType: "json",
success: function (msg) {
alert(msg.Msg)
if (msg.Code == 1) {
getList();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
},
complete: function () {
isOk = true;
}
});
}
}
function getText(str, len) {
if (str.length > len) {
return str.substring(0, len);
}
return str;
}
//时间 格式化
function dateFtt(fmt, date) { //author: meizz
date = new Date(date);
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
</script>

View File

@@ -160,7 +160,7 @@
function GetOverview() {
$.ajax({
url: "/Home/GetOverview",
url: "/Overview/GetOverview",
type: 'get',
dataType: "json",
success: function (msg) {

View File

@@ -1,6 +0,0 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

View File

@@ -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);
}

View File

@@ -0,0 +1,48 @@
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content-header"></section>
<section class="content">
<div class="container-fluid">
<!-- SELECT2 EXAMPLE -->
<div class="card card-default">
<div class="card-header">
<h3 class="card-title">SSH</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="remove">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- /.card-header -->
<div class="card-body">
</div>
<!-- /.card-body -->
<div class="card-footer" id="pager">
</div>
</div>
<!-- /.card -->
</div>
<!-- /.container-fluid -->
</section>
<script>
</script>