mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-14 05:12:09 +08:00
1.1.2 -> 1.1.3 第9次更新
This commit is contained in:
parent
f54e470874
commit
6431a90a72
@ -5,9 +5,8 @@ namespace Sheas_Cealer.Consts;
|
|||||||
internal class AboutConst : AboutMultilangConst
|
internal class AboutConst : AboutMultilangConst
|
||||||
{
|
{
|
||||||
public static string DeveloperButtonUrl => "https://www.spacetimee.xyz";
|
public static string DeveloperButtonUrl => "https://www.spacetimee.xyz";
|
||||||
public static string VersionButtonVersionContent => Assembly.GetExecutingAssembly().GetName().Version!.ToString().TrimEnd(".0".ToCharArray());
|
public static string VersionButtonVersionContent => Assembly.GetExecutingAssembly().GetName().Version!.ToString()[0..^2];
|
||||||
public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc";
|
public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc";
|
||||||
internal static string ReleasePagePassword => "3wnj";
|
|
||||||
public static string EmailButtonUrl => "Zeus6_6@163.com";
|
public static string EmailButtonUrl => "Zeus6_6@163.com";
|
||||||
|
|
||||||
public static string DocumentationButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer/wiki/Sheas-Cealer-Documentation";
|
public static string DocumentationButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer/wiki/Sheas-Cealer-Documentation";
|
||||||
|
@ -13,29 +13,32 @@ internal partial class MainConst : MainMultilangConst
|
|||||||
|
|
||||||
public static bool IsAdmin => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
public static bool IsAdmin => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
||||||
|
|
||||||
internal static string CealingHostPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-*.json");
|
internal static string DefaultUpstreamUrl => "https://gitlab.com/SpaceTimee/Cealing-Host/raw/main/Cealing-Host.json";
|
||||||
|
internal static string CealHostPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-*.json");
|
||||||
internal static string LocalHostPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-Local.json");
|
internal static string LocalHostPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-Local.json");
|
||||||
internal static string UpstreamHostPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-Upstream.json");
|
internal static string UpstreamHostPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-Upstream.json");
|
||||||
|
|
||||||
internal static string EdgeBrowserRegistryPath => @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe";
|
internal static string EdgeBrowserRegistryPath => @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe";
|
||||||
internal static string ChromeBrowserRegistryPath => @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe";
|
internal static string ChromeBrowserRegistryPath => @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe";
|
||||||
internal static string BraveBrowserRegistryPath => @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe";
|
internal static string BraveBrowserRegistryPath => @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe";
|
||||||
internal static string UncealedBrowserPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Uncealed-Browser.lnk");
|
internal static string UncealedBrowserPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Uncealed-Browser.lnk");
|
||||||
internal static string UncealedBrowserDescription => "Created By Sheas Cealer";
|
internal static string UncealedBrowserDescription => "Created By Sheas Cealer";
|
||||||
internal static string CommandName => "Cmd.exe";
|
|
||||||
internal static string HostsConfPath => Path.Combine(Registry.LocalMachine.OpenSubKey(@"\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath")?.GetValue("DataBasePath", null)?.ToString() ?? @"C:\Windows\System32\drivers\etc", "hosts");
|
internal static string HostsConfPath => Path.Combine(Registry.LocalMachine.OpenSubKey(@"\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath")?.GetValue("DataBasePath", null)?.ToString() ?? @"C:\Windows\System32\drivers\etc", "hosts");
|
||||||
internal static string HostsConfStartMarker => "# Cealing Nginx Start\n";
|
internal static string HostsConfStartMarker => "# Cealing Nginx Start\n";
|
||||||
internal static string HostsConfEndMarker => "# Cealing Nginx End";
|
internal static string HostsConfEndMarker => "# Cealing Nginx End";
|
||||||
|
|
||||||
internal static string NginxPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Nginx.exe");
|
internal static string NginxPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Nginx.exe");
|
||||||
internal static string NginxConfPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "nginx.conf");
|
internal static string NginxConfPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "nginx.conf");
|
||||||
internal static string NginxLogsPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "logs");
|
internal static string NginxLogsPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "logs");
|
||||||
internal static string NginxTempPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "temp");
|
internal static string NginxTempPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "temp");
|
||||||
internal static string NginxCertPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Cert.pem");
|
internal static string NginxCertPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Cert.pem");
|
||||||
|
internal static string NginxKeyPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Key.pem");
|
||||||
internal static string NginxRootCertSubjectName => "CN=Cealing Cert Root";
|
internal static string NginxRootCertSubjectName => "CN=Cealing Cert Root";
|
||||||
internal static string NginxChildCertSubjectName => "CN=Cealing Cert Child";
|
internal static string NginxChildCertSubjectName => "CN=Cealing Cert Child";
|
||||||
internal static string NginxKeyPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Key.pem");
|
|
||||||
internal static string MihomoPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Mihomo.exe");
|
internal static string MihomoPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Mihomo.exe");
|
||||||
internal static string MihomoConfPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "config.yaml");
|
internal static string MihomoConfPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "config.yaml");
|
||||||
internal static string DefaultUpstreamUrl => "https://gitlab.com/SpaceTimee/Cealing-Host/raw/main/Cealing-Host.json";
|
|
||||||
|
|
||||||
[GeneratedRegex(@"^(https?:\/\/)?[a-zA-Z0-9](-*[a-zA-Z0-9])*(\.[a-zA-Z0-9](-*[a-zA-Z0-9])*)*(:\d{1,5})?(\/[a-zA-Z0-9.\-_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%]*)*$")]
|
[GeneratedRegex(@"^(https?:\/\/)?[a-zA-Z0-9](-*[a-zA-Z0-9])*(\.[a-zA-Z0-9](-*[a-zA-Z0-9])*)*(:\d{1,5})?(\/[a-zA-Z0-9.\-_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%]*)*$")]
|
||||||
internal static partial Regex UpstreamUrlRegex();
|
internal static partial Regex UpstreamUrlRegex();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Sheas_Cealer.Consts;
|
|
||||||
using SheasCore;
|
using SheasCore;
|
||||||
|
|
||||||
namespace Sheas_Cealer.Utils;
|
namespace Sheas_Cealer.Utils;
|
||||||
@ -9,7 +8,7 @@ internal class CommandProc : Proc
|
|||||||
{
|
{
|
||||||
private static bool ShutDownAppOnProcessExit;
|
private static bool ShutDownAppOnProcessExit;
|
||||||
|
|
||||||
internal CommandProc(bool shutDownAppOnProcessExit) : base(MainConst.CommandName) => ShutDownAppOnProcessExit = shutDownAppOnProcessExit;
|
internal CommandProc(bool shutDownAppOnProcessExit) : base("Cmd.exe") => ShutDownAppOnProcessExit = shutDownAppOnProcessExit;
|
||||||
|
|
||||||
public override void Process_Exited(object sender, EventArgs e)
|
public override void Process_Exited(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ public partial class AboutWin : Window
|
|||||||
Button? senderButton = sender as Button;
|
Button? senderButton = sender as Button;
|
||||||
|
|
||||||
if (senderButton == VersionButton)
|
if (senderButton == VersionButton)
|
||||||
MessageBox.Show($"{AboutConst._ReleasePagePasswordLabel} {AboutConst.ReleasePagePassword}");
|
MessageBox.Show($"{AboutConst._ReleasePagePasswordLabel} 3wnj");
|
||||||
|
|
||||||
ProcessStartInfo processStartInfo = new(senderButton == EmailButton ? "mailto:" : string.Empty + senderButton!.ToolTip) { UseShellExecute = true };
|
ProcessStartInfo processStartInfo = new(senderButton == EmailButton ? "mailto:" : string.Empty + senderButton!.ToolTip) { UseShellExecute = true };
|
||||||
Process.Start(processStartInfo);
|
Process.Start(processStartInfo);
|
||||||
|
@ -34,15 +34,17 @@ public partial class MainWin : Window
|
|||||||
private static readonly HttpClient MainClient = new(new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator });
|
private static readonly HttpClient MainClient = new(new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator });
|
||||||
private static DispatcherTimer? HoldButtonTimer;
|
private static DispatcherTimer? HoldButtonTimer;
|
||||||
private static readonly DispatcherTimer ProxyTimer = new() { Interval = TimeSpan.FromSeconds(0.1) };
|
private static readonly DispatcherTimer ProxyTimer = new() { Interval = TimeSpan.FromSeconds(0.1) };
|
||||||
private static readonly FileSystemWatcher CealingHostWatcher = new(Path.GetDirectoryName(MainConst.CealingHostPath)!, Path.GetFileName(MainConst.CealingHostPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
|
private static readonly FileSystemWatcher CealHostWatcher = new(Path.GetDirectoryName(MainConst.CealHostPath)!, Path.GetFileName(MainConst.CealHostPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
|
||||||
private static readonly FileSystemWatcher NginxConfWatcher = new(Path.GetDirectoryName(MainConst.NginxConfPath)!, Path.GetFileName(MainConst.NginxConfPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
|
private static readonly FileSystemWatcher NginxConfWatcher = new(Path.GetDirectoryName(MainConst.NginxConfPath)!, Path.GetFileName(MainConst.NginxConfPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
|
||||||
private static readonly FileSystemWatcher MihomoConfWatcher = new(Path.GetDirectoryName(MainConst.MihomoConfPath)!, Path.GetFileName(MainConst.MihomoConfPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
|
private static readonly FileSystemWatcher MihomoConfWatcher = new(Path.GetDirectoryName(MainConst.MihomoConfPath)!, Path.GetFileName(MainConst.MihomoConfPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
|
||||||
private static readonly Dictionary<string, List<(List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp)>> HostRulesDict = [];
|
|
||||||
|
private static readonly Dictionary<string, List<(List<(string cealHostIncludeDomain, string ceahHostExcludeDomain)> cealHostDomainPairs, string cealHostSni, string cealHostIp)>> CealHostRulesDict = [];
|
||||||
private static string CealArgs = string.Empty;
|
private static string CealArgs = string.Empty;
|
||||||
private static NginxConfig? NginxConfs;
|
private static NginxConfig? NginxConfs;
|
||||||
private static string? ExtraNginxConfs;
|
private static string? ExtraNginxConfs;
|
||||||
private static string? MihomoConfs;
|
private static string? MihomoConfs;
|
||||||
private static string? ExtraMihomoConfs;
|
private static string? ExtraMihomoConfs;
|
||||||
|
|
||||||
private static int GameClickTime = 0;
|
private static int GameClickTime = 0;
|
||||||
private static int GameFlashInterval = 1000;
|
private static int GameFlashInterval = 1000;
|
||||||
|
|
||||||
@ -60,14 +62,14 @@ public partial class MainWin : Window
|
|||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
ProxyTimer.Tick += ProxyTimer_Tick;
|
ProxyTimer.Tick += ProxyTimer_Tick;
|
||||||
CealingHostWatcher.Changed += CealingHostWatcher_Changed;
|
CealHostWatcher.Changed += CealHostWatcher_Changed;
|
||||||
NginxConfWatcher.Changed += NginxConfWatcher_Changed;
|
NginxConfWatcher.Changed += NginxConfWatcher_Changed;
|
||||||
MihomoConfWatcher.Changed += MihomoConfWatcher_Changed;
|
MihomoConfWatcher.Changed += MihomoConfWatcher_Changed;
|
||||||
|
|
||||||
ProxyTimer.Start();
|
ProxyTimer.Start();
|
||||||
|
|
||||||
foreach (string hostPath in Directory.GetFiles(CealingHostWatcher.Path, CealingHostWatcher.Filter))
|
foreach (string cealHostPath in Directory.GetFiles(CealHostWatcher.Path, CealHostWatcher.Filter))
|
||||||
CealingHostWatcher_Changed(null!, new(new(), Path.GetDirectoryName(hostPath)!, Path.GetFileName(hostPath)));
|
CealHostWatcher_Changed(null!, new(new(), Path.GetDirectoryName(cealHostPath)!, Path.GetFileName(cealHostPath)));
|
||||||
|
|
||||||
MihomoConfWatcher_Changed(null!, null!);
|
MihomoConfWatcher_Changed(null!, null!);
|
||||||
});
|
});
|
||||||
@ -157,7 +159,7 @@ public partial class MainWin : Window
|
|||||||
foreach (Process browserProcess in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainPres.BrowserPath)))
|
foreach (Process browserProcess in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainPres.BrowserPath)))
|
||||||
{
|
{
|
||||||
browserProcess.Kill();
|
browserProcess.Kill();
|
||||||
browserProcess.WaitForExit();
|
await browserProcess.WaitForExitAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
@ -211,32 +213,32 @@ public partial class MainWin : Window
|
|||||||
|
|
||||||
string hostsConfAppendContent = MainConst.HostsConfStartMarker;
|
string hostsConfAppendContent = MainConst.HostsConfStartMarker;
|
||||||
|
|
||||||
foreach (List<(List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp)> hostRules in HostRulesDict.Values)
|
foreach (List<(List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, string cealHostSni, string cealHostIp)> cealHostRules in CealHostRulesDict.Values)
|
||||||
foreach ((List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, _, _) in hostRules)
|
foreach ((List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, _, _) in cealHostRules)
|
||||||
foreach ((string hostIncludeDomain, _) in hostDomainPairs)
|
foreach ((string cealHostIncludeDomain, _) in cealHostDomainPairs)
|
||||||
{
|
{
|
||||||
// 配置证书 SAN
|
// 配置证书 SAN
|
||||||
if (hostIncludeDomain.StartsWith("*."))
|
if (cealHostIncludeDomain.StartsWith("*."))
|
||||||
{
|
{
|
||||||
childCertSanBuilder.AddDnsName("*" + hostIncludeDomain.Replace("*", string.Empty));
|
childCertSanBuilder.AddDnsName("*" + cealHostIncludeDomain.Replace("*", string.Empty));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (hostIncludeDomain.StartsWith('*'))
|
else if (cealHostIncludeDomain.StartsWith('*'))
|
||||||
childCertSanBuilder.AddDnsName("*." + hostIncludeDomain.Replace("*", string.Empty));
|
childCertSanBuilder.AddDnsName("*." + cealHostIncludeDomain.Replace("*", string.Empty));
|
||||||
|
|
||||||
childCertSanBuilder.AddDnsName(hostIncludeDomain.Replace("*", string.Empty));
|
childCertSanBuilder.AddDnsName(cealHostIncludeDomain.Replace("*", string.Empty));
|
||||||
|
|
||||||
// 配置 hosts
|
// 配置 hosts
|
||||||
string hostIncludeDomainWithoutWildcard = hostIncludeDomain.Replace("*", string.Empty);
|
string cealHostIncludeDomainWithoutWildcard = cealHostIncludeDomain.Replace("*", string.Empty);
|
||||||
|
|
||||||
if (hostIncludeDomainWithoutWildcard.StartsWith('^') || hostIncludeDomainWithoutWildcard.EndsWith('^') ||
|
if (cealHostIncludeDomainWithoutWildcard.StartsWith('^') || cealHostIncludeDomainWithoutWildcard.EndsWith('^') ||
|
||||||
hostIncludeDomainWithoutWildcard.StartsWith('.') || hostIncludeDomainWithoutWildcard.EndsWith('.'))
|
cealHostIncludeDomainWithoutWildcard.StartsWith('.') || cealHostIncludeDomainWithoutWildcard.EndsWith('.'))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
hostsConfAppendContent += $"127.0.0.1 {hostIncludeDomainWithoutWildcard.Split('^', 2)[0]}\n";
|
hostsConfAppendContent += $"127.0.0.1 {cealHostIncludeDomainWithoutWildcard.Split('^', 2)[0]}\n";
|
||||||
|
|
||||||
if (hostIncludeDomain.StartsWith('*'))
|
if (cealHostIncludeDomain.StartsWith('*'))
|
||||||
hostsConfAppendContent += $"127.0.0.1 www.{hostIncludeDomainWithoutWildcard.Split('^', 2)[0]}\n";
|
hostsConfAppendContent += $"127.0.0.1 www.{cealHostIncludeDomainWithoutWildcard.Split('^', 2)[0]}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
childCertRequest.CertificateExtensions.Add(childCertSanBuilder.Build());
|
childCertRequest.CertificateExtensions.Add(childCertSanBuilder.Build());
|
||||||
@ -358,12 +360,12 @@ public partial class MainWin : Window
|
|||||||
{
|
{
|
||||||
Button? senderButton = sender as Button;
|
Button? senderButton = sender as Button;
|
||||||
|
|
||||||
string hostPath = senderButton == EditLocalHostButton ? MainConst.LocalHostPath : MainConst.UpstreamHostPath;
|
string cealHostPath = senderButton == EditLocalHostButton ? MainConst.LocalHostPath : MainConst.UpstreamHostPath;
|
||||||
|
|
||||||
if (!File.Exists(hostPath))
|
if (!File.Exists(cealHostPath))
|
||||||
File.Create(hostPath).Dispose();
|
File.Create(cealHostPath).Dispose();
|
||||||
|
|
||||||
ProcessStartInfo processStartInfo = new(hostPath) { UseShellExecute = true };
|
ProcessStartInfo processStartInfo = new(cealHostPath) { UseShellExecute = true };
|
||||||
Process.Start(processStartInfo);
|
Process.Start(processStartInfo);
|
||||||
}
|
}
|
||||||
private void EditConfButton_Click(object sender, RoutedEventArgs e)
|
private void EditConfButton_Click(object sender, RoutedEventArgs e)
|
||||||
@ -487,55 +489,55 @@ public partial class MainWin : Window
|
|||||||
MainPres.IsMihomoExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, Path.GetFileName(MainConst.MihomoPath)));
|
MainPres.IsMihomoExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, Path.GetFileName(MainConst.MihomoPath)));
|
||||||
MainPres.IsMihomoRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainConst.MihomoPath)).Length != 0;
|
MainPres.IsMihomoRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainConst.MihomoPath)).Length != 0;
|
||||||
}
|
}
|
||||||
private void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e)
|
private void CealHostWatcher_Changed(object sender, FileSystemEventArgs e)
|
||||||
{
|
{
|
||||||
string hostName = e.Name!.TrimStart("Cealing-Host-".ToCharArray()).TrimEnd(".json".ToCharArray());
|
string cealHostName = e.Name!.TrimStart("Cealing-Host-".ToCharArray()).TrimEnd(".json".ToCharArray());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HostRulesDict[hostName] = [];
|
CealHostRulesDict[cealHostName] = [];
|
||||||
string hostRulesFragments = string.Empty;
|
string cealHostRulesFragments = string.Empty;
|
||||||
string hostResolverRulesFragments = string.Empty;
|
string cealHostResolverRulesFragments = string.Empty;
|
||||||
|
|
||||||
using FileStream hostStream = new(e.FullPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
|
using FileStream cealHostStream = new(e.FullPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
|
||||||
JsonDocumentOptions hostOptions = new() { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip };
|
JsonDocumentOptions cealHostOptions = new() { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip };
|
||||||
JsonElement hostArray = JsonDocument.Parse(hostStream, hostOptions).RootElement;
|
JsonElement cealHostArray = JsonDocument.Parse(cealHostStream, cealHostOptions).RootElement;
|
||||||
|
|
||||||
foreach (JsonElement hostRule in hostArray.EnumerateArray())
|
foreach (JsonElement cealHostRule in cealHostArray.EnumerateArray())
|
||||||
{
|
{
|
||||||
List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs = [];
|
List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs = [];
|
||||||
string hostSni = string.IsNullOrWhiteSpace(hostRule[1].ToString()) ? $"{hostName}{HostRulesDict[hostName].Count}" : hostRule[1].ToString();
|
string cealHostSni = string.IsNullOrWhiteSpace(cealHostRule[1].ToString()) ? $"{cealHostName}{CealHostRulesDict[cealHostName].Count}" : cealHostRule[1].ToString();
|
||||||
string hostIp = string.IsNullOrWhiteSpace(hostRule[2].ToString()) ? "127.0.0.1" : hostRule[2].ToString();
|
string cealHostIp = string.IsNullOrWhiteSpace(cealHostRule[2].ToString()) ? "127.0.0.1" : cealHostRule[2].ToString();
|
||||||
|
|
||||||
foreach (JsonElement hostDomain in hostRule[0].EnumerateArray())
|
foreach (JsonElement cealHostDomain in cealHostRule[0].EnumerateArray())
|
||||||
{
|
{
|
||||||
if (hostDomain.ToString().StartsWith('^') || hostDomain.ToString().EndsWith('^'))
|
if (cealHostDomain.ToString().StartsWith('^') || cealHostDomain.ToString().EndsWith('^'))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string[] hostDomainPair = hostDomain.ToString().Split('^', 2);
|
string[] cealHostDomainPair = cealHostDomain.ToString().Split('^', 2);
|
||||||
|
|
||||||
hostDomainPairs.Add((hostDomainPair[0], hostDomainPair.Length == 2 ? hostDomainPair[1] : string.Empty));
|
cealHostDomainPairs.Add((cealHostDomainPair[0], cealHostDomainPair.Length == 2 ? cealHostDomainPair[1] : string.Empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
HostRulesDict[hostName].Add((hostDomainPairs, hostSni, hostIp));
|
CealHostRulesDict[cealHostName].Add((cealHostDomainPairs, cealHostSni, cealHostIp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { HostRulesDict.Remove(hostName); }
|
catch { CealHostRulesDict.Remove(cealHostName); }
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
string cealHostRules = string.Empty;
|
string hostRules = string.Empty;
|
||||||
string cealHostResolverRules = string.Empty;
|
string hostResolverRules = string.Empty;
|
||||||
|
|
||||||
foreach (List<(List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp)> hostRules in HostRulesDict.Values)
|
foreach (List<(List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, string cealHostSni, string cealHostIp)> cealHostRules in CealHostRulesDict.Values)
|
||||||
foreach ((List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp) in hostRules)
|
foreach ((List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, string cealHostSni, string cealHostIp) in cealHostRules)
|
||||||
{
|
{
|
||||||
foreach ((string hostIncludeDomain, string hostExcludeDomain) in hostDomainPairs)
|
foreach ((string cealHostIncludeDomain, string cealHostExcludeDomain) in cealHostDomainPairs)
|
||||||
cealHostRules += $"MAP {hostIncludeDomain} {hostSni}," + (!string.IsNullOrWhiteSpace(hostExcludeDomain) ? $"EXCLUDE {hostExcludeDomain}," : string.Empty);
|
hostRules += $"MAP {cealHostIncludeDomain} {cealHostSni}," + (!string.IsNullOrWhiteSpace(cealHostExcludeDomain) ? $"EXCLUDE {cealHostExcludeDomain}," : string.Empty);
|
||||||
|
|
||||||
cealHostResolverRules += $"MAP {hostSni} {hostIp},";
|
hostResolverRules += $"MAP {cealHostSni} {cealHostIp},";
|
||||||
}
|
}
|
||||||
|
|
||||||
CealArgs = @$"/c @start .\""{Path.GetFileName(MainConst.UncealedBrowserPath)}"" --host-rules=""{cealHostRules.TrimEnd(',')}"" --host-resolver-rules=""{cealHostResolverRules.TrimEnd(',')}"" --test-type --ignore-certificate-errors";
|
CealArgs = @$"/c @start .\""{Path.GetFileName(MainConst.UncealedBrowserPath)}"" --host-rules=""{hostRules.TrimEnd(',')}"" --host-resolver-rules=""{hostResolverRules.TrimEnd(',')}"" --test-type --ignore-certificate-errors";
|
||||||
|
|
||||||
NginxConfWatcher_Changed(null!, null!);
|
NginxConfWatcher_Changed(null!, null!);
|
||||||
}
|
}
|
||||||
@ -574,24 +576,24 @@ public partial class MainWin : Window
|
|||||||
.AddOrUpdate("http:proxy_ssl_server_name", !MainPres.IsFlashing ? "on" : "off")
|
.AddOrUpdate("http:proxy_ssl_server_name", !MainPres.IsFlashing ? "on" : "off")
|
||||||
.AddOrUpdate($"http:server[{serverIndex}]:return", "https://$host$request_uri");
|
.AddOrUpdate($"http:server[{serverIndex}]:return", "https://$host$request_uri");
|
||||||
|
|
||||||
foreach (List<(List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp)> hostRules in HostRulesDict.Values)
|
foreach (List<(List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, string cealHostSni, string cealHostIp)> cealHostRules in CealHostRulesDict.Values)
|
||||||
foreach ((List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp) in hostRules)
|
foreach ((List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, string cealHostSni, string cealHostIp) in cealHostRules)
|
||||||
{
|
{
|
||||||
++serverIndex;
|
++serverIndex;
|
||||||
|
|
||||||
string serverName = "~";
|
string serverName = "~";
|
||||||
|
|
||||||
foreach ((string hostIncludeDomain, string hostExcludeDomain) in hostDomainPairs)
|
foreach ((string cealHostIncludeDomain, string cealHostExcludeDomain) in cealHostDomainPairs)
|
||||||
serverName += "^" + (!string.IsNullOrWhiteSpace(hostExcludeDomain) ? $"(?!{hostExcludeDomain.Replace(".", "\\.").Replace("*", ".*")})" : string.Empty) + hostIncludeDomain.Replace(".", "\\.").Replace("*", ".*") + "$|";
|
serverName += "^" + (!string.IsNullOrWhiteSpace(cealHostExcludeDomain) ? $"(?!{cealHostExcludeDomain.Replace(".", "\\.").Replace("*", ".*")})" : string.Empty) + cealHostIncludeDomain.Replace(".", "\\.").Replace("*", ".*") + "$|";
|
||||||
|
|
||||||
NginxConfs = NginxConfs
|
NginxConfs = NginxConfs
|
||||||
.AddOrUpdate($"http:server[{serverIndex}]:server_name", serverName.TrimEnd('|'))
|
.AddOrUpdate($"http:server[{serverIndex}]:server_name", serverName.TrimEnd('|'))
|
||||||
.AddOrUpdate($"http:server[{serverIndex}]:listen", "443 ssl")
|
.AddOrUpdate($"http:server[{serverIndex}]:listen", "443 ssl")
|
||||||
.AddOrUpdate($"http:server[{serverIndex}]:ssl_certificate", Path.GetFileName(MainConst.NginxCertPath))
|
.AddOrUpdate($"http:server[{serverIndex}]:ssl_certificate", Path.GetFileName(MainConst.NginxCertPath))
|
||||||
.AddOrUpdate($"http:server[{serverIndex}]:ssl_certificate_key", Path.GetFileName(MainConst.NginxKeyPath))
|
.AddOrUpdate($"http:server[{serverIndex}]:ssl_certificate_key", Path.GetFileName(MainConst.NginxKeyPath))
|
||||||
.AddOrUpdate($"http:server[{serverIndex}]:proxy_ssl_name", hostSni)
|
.AddOrUpdate($"http:server[{serverIndex}]:proxy_ssl_name", cealHostSni)
|
||||||
.AddOrUpdate($"http:server[{serverIndex}]:location", "/", true)
|
.AddOrUpdate($"http:server[{serverIndex}]:location", "/", true)
|
||||||
.AddOrUpdate($"http:server[{serverIndex}]:location:proxy_pass", $"https://{hostIp}");
|
.AddOrUpdate($"http:server[{serverIndex}]:location:proxy_pass", $"https://{cealHostIp}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user