mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-14 05:12:09 +08:00
1.1.3 -> 1.1.4 第48次更新
This commit is contained in:
parent
3a95e8cbea
commit
4af0990ea6
@ -38,6 +38,7 @@ internal partial class MainConst : MainMultilangConst
|
|||||||
|
|
||||||
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[] MihomoNameServers => ["https://doh.apad.pro/dns-query", "https://ns.net.kg/dns-query"];
|
||||||
|
|
||||||
[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();
|
||||||
|
@ -203,14 +203,19 @@ public partial class MainWin : Window
|
|||||||
|
|
||||||
RSA certKey = RSA.Create(2048);
|
RSA certKey = RSA.Create(2048);
|
||||||
|
|
||||||
|
#region Root Cert
|
||||||
CertificateRequest rootCertRequest = new(MainConst.NginxRootCertSubjectName, certKey, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
CertificateRequest rootCertRequest = new(MainConst.NginxRootCertSubjectName, certKey, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||||
|
|
||||||
rootCertRequest.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, false));
|
rootCertRequest.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, false));
|
||||||
|
|
||||||
using X509Certificate2 rootCert = rootCertRequest.CreateSelfSigned(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddYears(100));
|
using X509Certificate2 rootCert = rootCertRequest.CreateSelfSigned(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddYears(100));
|
||||||
using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
|
using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
|
||||||
|
|
||||||
certStore.Add(rootCert);
|
certStore.Add(rootCert);
|
||||||
certStore.Close();
|
certStore.Close();
|
||||||
|
#endregion Root Cert
|
||||||
|
|
||||||
|
#region Child Cert & Hosts
|
||||||
CertificateRequest childCertRequest = new(MainConst.NginxChildCertSubjectName, certKey, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
CertificateRequest childCertRequest = new(MainConst.NginxChildCertSubjectName, certKey, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||||
SubjectAlternativeNameBuilder childCertSanBuilder = new();
|
SubjectAlternativeNameBuilder childCertSanBuilder = new();
|
||||||
string hostsConfAppendContent = MainConst.HostsConfStartMarker;
|
string hostsConfAppendContent = MainConst.HostsConfStartMarker;
|
||||||
@ -238,6 +243,7 @@ public partial class MainWin : Window
|
|||||||
}
|
}
|
||||||
|
|
||||||
childCertRequest.CertificateExtensions.Add(childCertSanBuilder.Build());
|
childCertRequest.CertificateExtensions.Add(childCertSanBuilder.Build());
|
||||||
|
|
||||||
using X509Certificate2 childCert = childCertRequest.Create(rootCert, rootCert.NotBefore, rootCert.NotAfter, Guid.NewGuid().ToByteArray());
|
using X509Certificate2 childCert = childCertRequest.Create(rootCert, rootCert.NotBefore, rootCert.NotAfter, Guid.NewGuid().ToByteArray());
|
||||||
|
|
||||||
File.WriteAllText(MainConst.NginxCertPath, childCert.ExportCertificatePem());
|
File.WriteAllText(MainConst.NginxCertPath, childCert.ExportCertificatePem());
|
||||||
@ -247,6 +253,7 @@ public partial class MainWin : Window
|
|||||||
|
|
||||||
File.SetAttributes(MainConst.HostsConfPath, File.GetAttributes(MainConst.HostsConfPath) & ~FileAttributes.ReadOnly);
|
File.SetAttributes(MainConst.HostsConfPath, File.GetAttributes(MainConst.HostsConfPath) & ~FileAttributes.ReadOnly);
|
||||||
File.AppendAllText(MainConst.HostsConfPath, hostsConfAppendContent);
|
File.AppendAllText(MainConst.HostsConfPath, hostsConfAppendContent);
|
||||||
|
#endregion Child Cert & Hosts
|
||||||
|
|
||||||
MainPres.IsNginxIniting = true;
|
MainPres.IsNginxIniting = true;
|
||||||
NginxConfWatcher.EnableRaisingEvents = false;
|
NginxConfWatcher.EnableRaisingEvents = false;
|
||||||
@ -262,6 +269,7 @@ public partial class MainWin : Window
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Http.GetAsync<HttpResponseMessage>($"https://localhost:{NginxHttpsPort}", MainClient);
|
await Http.GetAsync<HttpResponseMessage>($"https://localhost:{NginxHttpsPort}", MainClient);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (HttpRequestException ex) when (ex.InnerException is SocketException innerEx)
|
catch (HttpRequestException ex) when (ex.InnerException is SocketException innerEx)
|
||||||
@ -333,6 +341,7 @@ public partial class MainWin : Window
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Http.GetAsync<HttpResponseMessage>($"http://localhost:{MihomoMixedPort}", MainClient);
|
await Http.GetAsync<HttpResponseMessage>($"http://localhost:{MihomoMixedPort}", MainClient);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (HttpRequestException ex) when (ex.InnerException is SocketException innerEx)
|
catch (HttpRequestException ex) when (ex.InnerException is SocketException innerEx)
|
||||||
@ -364,7 +373,6 @@ public partial class MainWin : Window
|
|||||||
private void EditHostButton_Click(object sender, RoutedEventArgs e)
|
private void EditHostButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Button senderButton = (Button)sender;
|
Button senderButton = (Button)sender;
|
||||||
|
|
||||||
string cealHostPath = senderButton == EditLocalHostButton ? MainConst.LocalHostPath : MainConst.UpstreamHostPath;
|
string cealHostPath = senderButton == EditLocalHostButton ? MainConst.LocalHostPath : MainConst.UpstreamHostPath;
|
||||||
|
|
||||||
if (!File.Exists(cealHostPath))
|
if (!File.Exists(cealHostPath))
|
||||||
@ -411,6 +419,7 @@ public partial class MainWin : Window
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBoxResult overrideOptionResult = MessageBox.Show(MainConst._OverrideUpstreamHostPrompt, string.Empty, MessageBoxButton.YesNoCancel);
|
MessageBoxResult overrideOptionResult = MessageBox.Show(MainConst._OverrideUpstreamHostPrompt, string.Empty, MessageBoxButton.YesNoCancel);
|
||||||
|
|
||||||
if (overrideOptionResult == MessageBoxResult.Yes)
|
if (overrideOptionResult == MessageBoxResult.Yes)
|
||||||
{
|
{
|
||||||
File.WriteAllText(MainConst.UpstreamHostPath, upstreamUpstreamHostString);
|
File.WriteAllText(MainConst.UpstreamHostPath, upstreamUpstreamHostString);
|
||||||
@ -428,6 +437,7 @@ public partial class MainWin : Window
|
|||||||
if (GameFlashInterval <= 10)
|
if (GameFlashInterval <= 10)
|
||||||
{
|
{
|
||||||
MessageBox.Show(MainConst._GameReviewEndingMsg);
|
MessageBox.Show(MainConst._GameReviewEndingMsg);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,9 +479,9 @@ public partial class MainWin : Window
|
|||||||
foreach (Window currentWindow in Application.Current.Windows)
|
foreach (Window currentWindow in Application.Current.Windows)
|
||||||
BorderThemeSetter.SetBorderTheme(currentWindow, isLightTheme);
|
BorderThemeSetter.SetBorderTheme(currentWindow, isLightTheme);
|
||||||
|
|
||||||
|
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
|
||||||
Color? newForegroundColor = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
Color? newForegroundColor = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
||||||
|
|
||||||
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
|
|
||||||
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
|
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
|
||||||
Application.Current.Resources[typeof(Button)] = newButtonStyle;
|
Application.Current.Resources[typeof(Button)] = newButtonStyle;
|
||||||
|
|
||||||
@ -601,9 +611,7 @@ public partial class MainWin : Window
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
using FileStream nginxConfStream = new(MainConst.NginxConfPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
|
using FileStream nginxConfStream = new(MainConst.NginxConfPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
|
||||||
ExtraNginxConfs = new StreamReader(nginxConfStream).ReadToEnd();
|
NginxConfig extraNginxConfig = NginxConfig.Load(ExtraNginxConfs = new StreamReader(nginxConfStream).ReadToEnd());
|
||||||
|
|
||||||
NginxConfig extraNginxConfig = NginxConfig.Load(ExtraNginxConfs);
|
|
||||||
int serverIndex = 0;
|
int serverIndex = 0;
|
||||||
|
|
||||||
foreach (IToken extraNginxConfigToken in extraNginxConfig.GetTokens())
|
foreach (IToken extraNginxConfigToken in extraNginxConfig.GetTokens())
|
||||||
@ -673,13 +681,11 @@ public partial class MainWin : Window
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
using FileStream mihomoConfStream = new(MainConst.MihomoConfPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
|
using FileStream mihomoConfStream = new(MainConst.MihomoConfPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
|
||||||
ExtraMihomoConfs = new StreamReader(mihomoConfStream).ReadToEnd();
|
|
||||||
|
|
||||||
Dictionary<string, object> mihomoConfDict = new DeserializerBuilder()
|
Dictionary<string, object> mihomoConfDict = new DeserializerBuilder()
|
||||||
.WithNamingConvention(HyphenatedNamingConvention.Instance)
|
.WithNamingConvention(HyphenatedNamingConvention.Instance)
|
||||||
.IgnoreUnmatchedProperties()
|
.IgnoreUnmatchedProperties()
|
||||||
.Build()
|
.Build()
|
||||||
.Deserialize<Dictionary<string, object>>(ExtraMihomoConfs) ?? [];
|
.Deserialize<Dictionary<string, object>>(ExtraMihomoConfs = new StreamReader(mihomoConfStream).ReadToEnd()) ?? [];
|
||||||
|
|
||||||
mihomoConfDict["mixed-port"] = MihomoMixedPort;
|
mihomoConfDict["mixed-port"] = MihomoMixedPort;
|
||||||
mihomoConfDict["dns"] = new
|
mihomoConfDict["dns"] = new
|
||||||
@ -687,7 +693,7 @@ public partial class MainWin : Window
|
|||||||
enable = true,
|
enable = true,
|
||||||
listen = ":53",
|
listen = ":53",
|
||||||
enhancedMode = "redir-host",
|
enhancedMode = "redir-host",
|
||||||
nameserver = new[] { "https://doh.apad.pro/dns-query", "https://ns.net.kg/dns-query" }
|
nameserver = MainConst.MihomoNameServers
|
||||||
};
|
};
|
||||||
mihomoConfDict["tun"] = new
|
mihomoConfDict["tun"] = new
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user