|
@@ -10,6 +10,7 @@ using System.Text.Json;
|
|
|
using System.Text.Json.Nodes;
|
|
|
using VueCliMiddleware;
|
|
|
using IES.ExamServer.Services;
|
|
|
+using System.Text;
|
|
|
|
|
|
namespace IES.ExamServer
|
|
|
{
|
|
@@ -18,6 +19,15 @@ namespace IES.ExamServer
|
|
|
public async static Task Main(string[] args)
|
|
|
{
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
+
|
|
|
+ string path = $"{builder.Environment.ContentRootPath}/Configs";
|
|
|
+ //builder.WebHost.UseKestrel(options =>
|
|
|
+ //{
|
|
|
+ // options.ListenAnyIP(5001, listenOptions =>
|
|
|
+ // {
|
|
|
+ // listenOptions.UseHttps($"{path}/cert.pfx", "cdhabook") ;
|
|
|
+ // });
|
|
|
+ //});
|
|
|
builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|
|
builder.Services.AddSpaStaticFiles(opt => opt.RootPath = "ClientApp/dist");
|
|
|
// Add services to the container.
|
|
@@ -40,7 +50,7 @@ namespace IES.ExamServer
|
|
|
};
|
|
|
builder.Services.AddLiteDB(connections_LiteDB);
|
|
|
builder.Services.AddMemoryCache();
|
|
|
- string path = $"{builder.Environment.ContentRootPath}/Configs";
|
|
|
+
|
|
|
builder.Services.AddCors(options =>
|
|
|
{
|
|
|
options.AddDefaultPolicy(
|
|
@@ -142,6 +152,42 @@ namespace IES.ExamServer
|
|
|
var d = server?.Features.Get<IServerAddressesFeature>();
|
|
|
IEnumerable<string>? _url = server?.Features.Get<IServerAddressesFeature>()?.Addresses;
|
|
|
ServerDevice serverDevice = IndexService.GetServerDevice(remote, region, _url);
|
|
|
+ //int domainStatus =0;
|
|
|
+ //string domain = builder.Configuration.GetValue<string>("ExamClient:Domain");
|
|
|
+ //foreach (var network in serverDevice.networks)
|
|
|
+ //{
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // string domain_entry = $"{network.ip} {domain}";
|
|
|
+ // string hostsFilePath = @"C:\Windows\System32\drivers\etc\hosts";
|
|
|
+ // string content = File.ReadAllText(hostsFilePath, Encoding.UTF8);
|
|
|
+ // if (!content.Contains(domain_entry))
|
|
|
+ // {
|
|
|
+ // content += Environment.NewLine + domain_entry;
|
|
|
+ // // 使用管理员权限运行此程序,不然会抛出UnauthorizedAccessException
|
|
|
+ // File.WriteAllText(hostsFilePath, content, Encoding.UTF8);
|
|
|
+ // domainStatus=1;
|
|
|
+ // // Console.WriteLine("Hosts file updated successfully.");
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // domainStatus=1;
|
|
|
+ // //Console.WriteLine("The entry already exists in the hosts file.");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // catch (UnauthorizedAccessException)
|
|
|
+ // {
|
|
|
+ // domainStatus=2;
|
|
|
+ // // Console.WriteLine("You need to run this program with administrative privileges to modify the hosts file.");
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // domainStatus=0;
|
|
|
+ // // Console.WriteLine($"An error occurred: {ex.Message}");
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //serverDevice.domainStatus=domainStatus;
|
|
|
+ //serverDevice.domain=domain;
|
|
|
cache.Set(Constant._KeyServerDevice, serverDevice);
|
|
|
});
|
|
|
app.Run();
|