|
@@ -11,6 +11,7 @@ using System.IdentityModel.Tokens.Jwt;
|
|
|
using IES.ExamServer.Services;
|
|
|
using IES.ExamServer.DI;
|
|
|
using IES.ExamLib.Models;
|
|
|
+using IES.ExamServer.Helpers;
|
|
|
|
|
|
namespace IES.ExamServer.Controllers
|
|
|
{
|
|
@@ -34,6 +35,43 @@ namespace IES.ExamServer.Controllers
|
|
|
_connectionService=connectionService;
|
|
|
_liteDBFactory=liteDBFactory;
|
|
|
}
|
|
|
+ [HttpPost("generate-certificate")]
|
|
|
+ public async Task<IActionResult> GenerateCertificate(JsonNode json)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ ServerDevice serverDevice = _memoryCache.Get<ServerDevice>(Constant._KeyServerDevice);
|
|
|
+ if (serverDevice!=null && serverDevice.networks.IsNotEmpty())
|
|
|
+ {
|
|
|
+ string mac = $"{json["mac"]}";
|
|
|
+ var network = serverDevice.networks.Find(x => mac.Equals(x.mac));
|
|
|
+ if (network!=null)
|
|
|
+ {
|
|
|
+ string pathBat = Path.Combine(Directory.GetCurrentDirectory(), "Configs", "certificate.bat");
|
|
|
+ string pathCer = Path.Combine(Directory.GetCurrentDirectory(), "Configs", "certificate.cer");
|
|
|
+ string text = await System.IO.File.ReadAllTextAsync(pathBat);
|
|
|
+ text = text.Replace("192.168.8.131", network.ip);
|
|
|
+ string pathCertificateBat = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package", "certificate.bat");
|
|
|
+ await System.IO.File.WriteAllTextAsync(pathCertificateBat, text);
|
|
|
+ string pathCertificateCer = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package", "certificate.cer");
|
|
|
+ System.IO.File.Copy(pathCer, pathCertificateCer);
|
|
|
+ return Ok(new { code = 200, msg = "生成成功。", bat = "package/certificate.bat", cer = "package/certificate.cer" });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ msg="未找到匹配的网卡设备。";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ msg="服务端设备未找到,或网卡设备不存在。";
|
|
|
+ }
|
|
|
+ } catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError($"生成证书和自定义域名映射脚本错误。{ex.Message},{ex.StackTrace}");
|
|
|
+ msg=$"服务端错误,{ex.Message}";
|
|
|
+ }
|
|
|
+ return Ok(new { code = 400, msg = msg });
|
|
|
+ }
|
|
|
[HttpPost("list-schools")]
|
|
|
public async Task<IActionResult> ListSchool(JsonNode json)
|
|
|
{
|