Block data uploads
This commit is contained in:
parent
ca70c3536f
commit
7b54f443ab
5 changed files with 56 additions and 7 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,3 +1,7 @@
|
||||||
|
config.json
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
|
||||||
## Ignore Visual Studio temporary files, build results, and
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
## files generated by popular Visual Studio add-ons.
|
## files generated by popular Visual Studio add-ons.
|
||||||
##
|
##
|
||||||
|
|
12
Program.cs
12
Program.cs
|
@ -7,6 +7,7 @@ namespace FireflySR.Tool.Proxy
|
||||||
{
|
{
|
||||||
private const string Title = "FreeSR Proxy (Alter)";
|
private const string Title = "FreeSR Proxy (Alter)";
|
||||||
private const string ConfigPath = "config.json";
|
private const string ConfigPath = "config.json";
|
||||||
|
private const string ConfigTemplatePath = "config.tmpl.json";
|
||||||
|
|
||||||
private static ProxyService s_proxyService = null!;
|
private static ProxyService s_proxyService = null!;
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ namespace FireflySR.Tool.Proxy
|
||||||
Console.Title = Title;
|
Console.Title = Title;
|
||||||
Console.WriteLine($"Firefly.Tool.Proxy - Credits for original FreeSR Proxy");
|
Console.WriteLine($"Firefly.Tool.Proxy - Credits for original FreeSR Proxy");
|
||||||
CheckProxy();
|
CheckProxy();
|
||||||
|
InitConfig();
|
||||||
|
|
||||||
var conf = JsonSerializer.Deserialize<ProxyConfig>(File.ReadAllText(ConfigPath)) ?? throw new FileLoadException("Please correctly configure config.json.");
|
var conf = JsonSerializer.Deserialize<ProxyConfig>(File.ReadAllText(ConfigPath)) ?? throw new FileLoadException("Please correctly configure config.json.");
|
||||||
s_proxyService = new ProxyService(conf.DestinationHost, conf.DestinationPort, conf);
|
s_proxyService = new ProxyService(conf.DestinationHost, conf.DestinationPort, conf);
|
||||||
|
@ -24,6 +26,14 @@ namespace FireflySR.Tool.Proxy
|
||||||
Thread.Sleep(-1);
|
Thread.Sleep(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void InitConfig()
|
||||||
|
{
|
||||||
|
if (!File.Exists(ConfigPath))
|
||||||
|
{
|
||||||
|
File.Copy(ConfigTemplatePath, ConfigPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void OnProcessExit(object? sender, EventArgs args)
|
private static void OnProcessExit(object? sender, EventArgs args)
|
||||||
{
|
{
|
||||||
s_proxyService.Shutdown();
|
s_proxyService.Shutdown();
|
||||||
|
@ -68,4 +78,4 @@ namespace FireflySR.Tool.Proxy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ public class ProxyConfig
|
||||||
public List<string> RedirectDomains { get; set; } = [];
|
public List<string> RedirectDomains { get; set; } = [];
|
||||||
public List<string> AlwaysIgnoreDomains { get; set; } = [];
|
public List<string> AlwaysIgnoreDomains { get; set; } = [];
|
||||||
public List<string> ForceRedirectOnUrlContains { get; set; } = [];
|
public List<string> ForceRedirectOnUrlContains { get; set; } = [];
|
||||||
|
public HashSet<string> BlockUrls { get; set; } = [];
|
||||||
public required string DestinationHost { get; set; }
|
public required string DestinationHost { get; set; }
|
||||||
public required int DestinationPort { get; set; }
|
public required int DestinationPort { get; set; }
|
||||||
public int ProxyBindPort { get; set; }
|
public int ProxyBindPort { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Titanium.Web.Proxy;
|
using Titanium.Web.Proxy;
|
||||||
using Titanium.Web.Proxy.EventArguments;
|
using Titanium.Web.Proxy.EventArguments;
|
||||||
|
@ -38,8 +39,11 @@
|
||||||
_webProxyServer.AddEndPoint(explicitEP);
|
_webProxyServer.AddEndPoint(explicitEP);
|
||||||
_webProxyServer.Start();
|
_webProxyServer.Start();
|
||||||
|
|
||||||
_webProxyServer.SetAsSystemHttpProxy(explicitEP);
|
if (OperatingSystem.IsWindows())
|
||||||
_webProxyServer.SetAsSystemHttpsProxy(explicitEP);
|
{
|
||||||
|
_webProxyServer.SetAsSystemHttpProxy(explicitEP);
|
||||||
|
_webProxyServer.SetAsSystemHttpsProxy(explicitEP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Shutdown()
|
public void Shutdown()
|
||||||
|
@ -74,6 +78,12 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool ShouldBlock(Uri uri)
|
||||||
|
{
|
||||||
|
var path = uri.AbsolutePath;
|
||||||
|
return _conf.BlockUrls.Contains(path);
|
||||||
|
}
|
||||||
|
|
||||||
private Task BeforeRequest(object sender, SessionEventArgs args)
|
private Task BeforeRequest(object sender, SessionEventArgs args)
|
||||||
{
|
{
|
||||||
string hostname = args.HttpClient.Request.RequestUri.Host;
|
string hostname = args.HttpClient.Request.RequestUri.Host;
|
||||||
|
@ -82,12 +92,24 @@
|
||||||
string requestUrl = args.HttpClient.Request.Url;
|
string requestUrl = args.HttpClient.Request.Url;
|
||||||
Uri local = new Uri($"http://{_targetRedirectHost}:{_targetRedirectPort}/");
|
Uri local = new Uri($"http://{_targetRedirectHost}:{_targetRedirectPort}/");
|
||||||
|
|
||||||
string replacedUrl = new UriBuilder(requestUrl)
|
Uri builtUrl = new UriBuilder(requestUrl)
|
||||||
{
|
{
|
||||||
Scheme = local.Scheme,
|
Scheme = local.Scheme,
|
||||||
Host = local.Host,
|
Host = local.Host,
|
||||||
Port = local.Port
|
Port = local.Port
|
||||||
}.Uri.ToString();
|
}.Uri;
|
||||||
|
|
||||||
|
string replacedUrl = builtUrl.ToString();
|
||||||
|
if (ShouldBlock(builtUrl))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Blocked: {replacedUrl}");
|
||||||
|
args.Respond(new Titanium.Web.Proxy.Http.Response(Encoding.UTF8.GetBytes("Fuck off"))
|
||||||
|
{
|
||||||
|
StatusCode = 404,
|
||||||
|
StatusDescription = "Oh no!!!",
|
||||||
|
}, true);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("Redirecting: " + replacedUrl);
|
Console.WriteLine("Redirecting: " + replacedUrl);
|
||||||
args.HttpClient.Request.Url = replacedUrl;
|
args.HttpClient.Request.Url = replacedUrl;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
".juequling.com",
|
".juequling.com",
|
||||||
".zenlesszonezero.com",
|
".zenlesszonezero.com",
|
||||||
".bh3.com",
|
".bh3.com",
|
||||||
|
".honkaiimpact3.com",
|
||||||
".mob.com",
|
".mob.com",
|
||||||
".hyg.com"
|
".hyg.com"
|
||||||
],
|
],
|
||||||
|
@ -21,10 +22,21 @@
|
||||||
"autopatchcn.bhsr.com",
|
"autopatchcn.bhsr.com",
|
||||||
"autopatchos.starrails.com"
|
"autopatchos.starrails.com"
|
||||||
],
|
],
|
||||||
|
"BlockUrls": [
|
||||||
|
"/sdk/upload",
|
||||||
|
"/sdk/dataUpload",
|
||||||
|
"/common/h5log/log/batch",
|
||||||
|
"/crash/dataUpload",
|
||||||
|
"/crashdump/dataUpload",
|
||||||
|
"/client/event/dataUpload",
|
||||||
|
"/log",
|
||||||
|
"/asm/dataUpload",
|
||||||
|
"/sophon/dataUpload"
|
||||||
|
],
|
||||||
"ForceRedirectOnUrlContains": [
|
"ForceRedirectOnUrlContains": [
|
||||||
"query_dispatch",
|
"query_dispatch",
|
||||||
"query_gateway",
|
"query_gateway",
|
||||||
"query_region_list",
|
"query_region_list",
|
||||||
"query_cur_region"
|
"query_cur_region"
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in a new issue