171 lines
5.0 KiB
C#
171 lines
5.0 KiB
C#
using AppLibs.Libs;
|
|
using AppLibs.Libs.Crypt;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.WebUtilities;
|
|
using System.Security.Cryptography;
|
|
using TWASys_App.Models;
|
|
using TWASys_App.Models.ServerInfo;
|
|
|
|
namespace TWASys_App.Controllers
|
|
{
|
|
public class StorageController : Controller
|
|
{
|
|
|
|
|
|
[PageInfor("6101", "Config Storage")]
|
|
public Task<IActionResult> Index()
|
|
{
|
|
return this.ViewAsync();
|
|
}
|
|
|
|
[PageInfor("6102", "Type Storage")]
|
|
public Task<IActionResult> Type()
|
|
{
|
|
return this.ViewAsync();
|
|
}
|
|
|
|
[PageInfor("6103", "Validation Domain")]
|
|
public Task<IActionResult> ValidationDomain()
|
|
{
|
|
return this.ViewAsync();
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> AddValidationDomain([FromForm] ValidationDomainModel model)
|
|
{
|
|
return Json(await model.AddAsync());
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> GetValidationDomain([FromForm] ValidationDomainModel model)
|
|
{
|
|
return await model.GetValidationDomainAsync();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> UpdateValidationDomain([FromForm] ValidationDomainModel model)
|
|
{
|
|
return Json(await model.UpdateAsync());
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> AddType([FromBody] TypeStorageServerModel model)
|
|
{
|
|
return Json(await model.AddAsync());
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> GetTypeStorage([FromForm] TypeStorageServerModel model)
|
|
{
|
|
return await model.GetTypeStoragesAsync();
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetTypeStorage()
|
|
{
|
|
return await TypeStorageServerModel.GetAllTypeStorage();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> GetStorage([FromForm] StorageModel model)
|
|
{
|
|
return await model.GetStorages();
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetValidationDomain()
|
|
{
|
|
return await ValidationDomainModel.GetAllValidationDomain();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> UpdateType([FromBody] TypeStorageServerModel model)
|
|
{
|
|
return Json(await model.UpdateAsync());
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> SetStorageData([FromForm] StorageModel model)
|
|
{
|
|
return Json(await model.AddAsync());
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> UpdateStorageSize([FromForm] StorageModel model)
|
|
{
|
|
|
|
return Json(await model.UpdateStorageSize());
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GenerationAccessToken()
|
|
{
|
|
var t1 = Task<Guid>.Run(() =>
|
|
{
|
|
return UUID7.NewUuid7();
|
|
});
|
|
|
|
var t2 = Task<string>.Run(() => {
|
|
var tokenValue = Base64UrlTextEncoder.Encode(
|
|
Guid.NewGuid().ToByteArray()
|
|
.Concat(BitConverter.GetBytes(DateTime.UtcNow.ToFileTimeUtc()))
|
|
.ToArray()
|
|
);
|
|
using var sha = SHA256.Create();
|
|
var idToken = WebEncoders.Base64UrlEncode(sha.ComputeHash(
|
|
System.Text.Encoding.UTF8.GetBytes(tokenValue)
|
|
));
|
|
|
|
return idToken;
|
|
|
|
});
|
|
await Task.WhenAll(t1, t2);
|
|
|
|
return Json(new
|
|
{
|
|
idToken = t1.Result.ToString(),
|
|
tokenValue = t2.Result.ToLower()
|
|
});
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> CheckStorageInit()
|
|
{
|
|
await Task.Delay(1);
|
|
var f = System.IO.File.Exists(System.IO.Path.GetFullPath("Json/dataServer.json"));
|
|
return Json(new MessageHeader
|
|
{
|
|
ID= 61011,
|
|
Message=f?"has":"no",
|
|
Status=1
|
|
});
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetSysInfo()
|
|
{
|
|
var sys = SysInfoReader.Get();
|
|
var mac = HwIdReader.Get();
|
|
var os = OsInfoReader.Get();
|
|
return Json(new
|
|
{
|
|
socket = sys.SocketCount,
|
|
cpuName = sys.CpuName,
|
|
totalRam = (sys.TotalRamBytes / 1024f / 1024f / 1024f).ToString("F2"),
|
|
biosSerial = mac.SerialNumber,
|
|
biosVendor = mac.BiosVendor,
|
|
biosUUID = mac.ProductUuid,
|
|
privateIP = NetUtils.GetPrimaryPrivateIPv4String(),
|
|
privateIPv6 = NetUtils.GetPrimaryPrivateIPv6String(),
|
|
publicIP = await NetUtils.GetPublicIpAsync(),
|
|
osPlatform = os.Platform,
|
|
osName = os.Name,
|
|
osVersion = os.Version,
|
|
osKernel = os.Kernel,
|
|
osArch = os.Architecture
|
|
});
|
|
}
|
|
}
|
|
}
|