feat: initial development

This commit is contained in:
2023-07-27 01:47:59 +04:00
commit 85dc5981cd
30 changed files with 3075 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
namespace NaiveHttpServer
{
public static class NetAclChecker
{
public static ILogger? Logger { get; set; }
public static void AddAddress(string address)
{
AddAddress(address, Environment.UserDomainName, Environment.UserName);
}
public static void AddAddress(string address, string domain, string user)
{
string args = $@"http add urlacl url={address}, user={domain}\{user}";
try
{
ProcessStartInfo processStartInfo = new("netsh", args)
{
Verb = "runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true,
};
var process = Process.Start(processStartInfo);
process?.WaitForExit();
}
catch (Win32Exception e)
{
if (e.NativeErrorCode == 1223)
{
Logger?.Info("User canceled the operation by rejected the UAC.");
}
else
{
Logger?.Warning($"Failed to 'netsh http add urlacl {address}' with an {nameof(Win32Exception)}.", e);
}
}
catch (Exception e)
{
Logger?.Warning($"Failed to 'netsh http add urlacl {address}'.", e);
}
}
}
}