diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs index 22e9b1a..d001c4b 100644 --- a/FastGithub/Program.cs +++ b/FastGithub/Program.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using System.IO; namespace FastGithub { @@ -30,6 +32,13 @@ namespace FastGithub { c.ValidateOnBuild = false; }) + .ConfigureAppConfiguration(c => + { + foreach (var jsonFile in Directory.GetFiles(".", "appsettings.*.json")) + { + c.AddJsonFile(Path.GetFileName(jsonFile), true, true); + } + }) .ConfigureServices((ctx, services) => { services.AddDnsServer(); diff --git a/FastGithub/appsettings.github.json b/FastGithub/appsettings.github.json new file mode 100644 index 0000000..df6cecb --- /dev/null +++ b/FastGithub/appsettings.github.json @@ -0,0 +1,35 @@ +{ + "FastGithub": { + "DomainConfigs": { + "github.com": { + "TlsSni": false + }, + "githubstatus.com": { + "TlsSni": false + }, + "*.github.com": { + "TlsSni": false + }, + "*.github.io": { + "TlsSni": false, + "TlsIgnoreNameMismatch": true + }, + "*.githubapp.com": { + "TlsSni": false, + "TlsIgnoreNameMismatch": true + }, + "*.githubassets.com": { + "TlsSni": false, + "TlsIgnoreNameMismatch": true + }, + "*.githubusercontent.com": { + "TlsSni": false, + "TlsIgnoreNameMismatch": true + }, + "*github*.s3.amazonaws.com": { + "TlsSni": false, + "TlsIgnoreNameMismatch": true + } + } + } +} diff --git a/FastGithub/appsettings.json b/FastGithub/appsettings.json index 890ef88..c108d5b 100644 --- a/FastGithub/appsettings.json +++ b/FastGithub/appsettings.json @@ -1,4 +1,5 @@ { + // 新增的子配置文件appsettings.*.json,重启应用程序才生效 "FastGithub": { "PureDns": { // 用于解析DomainConfigs的域名 "IPAddress": "127.0.0.1", @@ -8,82 +9,17 @@ "IPAddress": "114.114.114.114", "Port": 53 }, - "DomainConfigs": { // 域名的*表示除.之外0到多个任意字符 - "github.com": { + "DomainConfigs": { + "*.x.y.z.com": { // 域名的*表示除.之外0到多个任意字符 "TlsSni": false, // 指示tls握手时是否发送SNI "TlsSniPattern": null, // SNI表达式,@domain变量表示取域名值 @ipadress变量表示取ip @random变量表示取随机值,其它字符保留不替换 "TlsIgnoreNameMismatch": false, // 是否忽略服务器证书域名不匹配,当不发送SNI时服务器可能发回域名不匹配的证书,默认为false "Timeout": null, // 请求超时时长,格式为"00:02:00",默认为null - "Destination": null // 请求目的地,格式为绝对或相对Uri,默认null - //"Response": { // 阻断请求直接响应,设置了Response其它配置都不起作用了 - // "StatusCode": 404, - // "ContentType": "text/plain;charset=utf-8", - // "ContentValue": "阻断的请求" - //} - }, - "githubstatus.com": { - "TlsSni": false - }, - "*.github.com": { - "TlsSni": false - }, - "*.github.io": { - "TlsSni": false, - "TlsIgnoreNameMismatch": true - }, - "*.githubapp.com": { - "TlsSni": false, - "TlsIgnoreNameMismatch": true - }, - "*.githubassets.com": { - "TlsSni": false, - "TlsIgnoreNameMismatch": true - }, - "*.githubusercontent.com": { - "TlsSni": false, - "TlsIgnoreNameMismatch": true - }, - "*github*.s3.amazonaws.com": { - "TlsSni": false, - "TlsIgnoreNameMismatch": true - }, - "ajax.googleapis.com": { - "TlsSni": true, - "Destination": "https://gapis.geekzu.org/ajax/" - }, - "fonts.googleapis.com": { - "TlsSni": true, - "Destination": "https://fonts.geekzu.org/" - }, - "themes.googleusercontent.com": { - "TlsSni": true, - "Destination": "https://gapis.geekzu.org/g-themes/" - }, - "fonts.gstatic.com": { - "TlsSni": true, - "Destination": "https://gapis.geekzu.org/g-fonts/" - }, - "secure.gravatar.com": { - "TlsSni": true, - "Destination": "https://sdn.geekzu.org/" - }, - "*.gravatar.com": { - "TlsSni": true, - "Destination": "https://fdn.geekzu.org/" - }, - "i.stack.imgur.com": { - "Response": { - "StatusCode": 404 - } - }, - "lh*.googleusercontent.com": { - "Response": { - "StatusCode": 404 - } - }, - "www.google.com": { - "Response": { - "StatusCode": 404 + "Destination": null, // 请求目的地,格式为绝对或相对Uri,默认null + "Response": { // 阻断请求直接响应,设置了Response其它配置都不起作用了 + "StatusCode": 404, // 响应的状态码 + "ContentType": "text/plain;charset=utf-8", // 如果有ContentValue,就要指示ContentType + "ContentValue": "这是一个用于示范配置的域名" // 自定义返回的内容,这是可选的 } } } diff --git a/FastGithub/appsettings.stackoverflow.json b/FastGithub/appsettings.stackoverflow.json new file mode 100644 index 0000000..a3b9be9 --- /dev/null +++ b/FastGithub/appsettings.stackoverflow.json @@ -0,0 +1,45 @@ +{ + "FastGithub": { + "DomainConfigs": { + "ajax.googleapis.com": { + "TlsSni": true, + "Destination": "https://gapis.geekzu.org/ajax/" + }, + "fonts.googleapis.com": { + "TlsSni": true, + "Destination": "https://fonts.geekzu.org/" + }, + "themes.googleusercontent.com": { + "TlsSni": true, + "Destination": "https://gapis.geekzu.org/g-themes/" + }, + "fonts.gstatic.com": { + "TlsSni": true, + "Destination": "https://gapis.geekzu.org/g-fonts/" + }, + "secure.gravatar.com": { + "TlsSni": true, + "Destination": "https://sdn.geekzu.org/" + }, + "*.gravatar.com": { + "TlsSni": true, + "Destination": "https://fdn.geekzu.org/" + }, + "i.stack.imgur.com": { + "Response": { + "StatusCode": 404 + } + }, + "lh*.googleusercontent.com": { + "Response": { + "StatusCode": 404 + } + }, + "www.google.com": { + "Response": { + "StatusCode": 404 + } + } + } + } +}