简化WebVPN的部署

pull/1/head
吴顺明 1 year ago
parent e723eb8ba2
commit b78ed55048

@ -86,7 +86,8 @@ namespace UMC.Host
{
if (HttpBridgeClient.IsRunning)
{
if(request.IsApp){
if (request.IsApp)
{
this.Prompt("App不支持关停Web VPN");
}
@ -203,6 +204,7 @@ namespace UMC.Host
{
provider.Attributes["scheme"] = scheme;
provider.Attributes["domain"] = domain;
UMC.Proxy.WebServlet.MainDomain = domain;
isTag = true;
}
if (String.Equals(provider.Attributes["bridge"], bridgeUrl) == false)
@ -235,12 +237,12 @@ namespace UMC.Host
var desc = new UMC.Web.WebMeta().Put("title", isbridge ? "Web VPN已经开启" : (data["tip"] ?? "无可用的流量,请充值")).Put("icon", isbridge ? "\uEA06" : "\uEA05");
UISection ui = UISection.Create(new UIHeader().Desc(desc, "{icon}\n{title}", style), new UITitle("Web VPN"));
var caption = data["caption"];
ui.AddCell("所属账户", String.IsNullOrEmpty(caption) ? "[点击完善]" : caption, new UIClick("System", "License","Name"));
ui.AddCell("所属账户", String.IsNullOrEmpty(caption) ? "[点击完善]" : caption, new UIClick("System", "License", "Name"));
var bridgeSrc = data["bridgeSrc"];
@ -255,12 +257,12 @@ namespace UMC.Host
}
ui.NewSection("Web VPN").AddCell("剩余流量", data["allowSize"])
.AddCell("上行流量", data["inputSize"])
.AddCell("下行流量", data["outputSize"])
.AddCell("流量过期", data["expireTime"]).Footer.Put("text", "注意:流量过期后,剩余流量将会清零");
ui.NewSection("Web VPN").AddCell("剩余流量", data["allowSize"])
.AddCell("上行流量", data["inputSize"])
.AddCell("下行流量", data["outputSize"])
.AddCell("流量过期", data["expireTime"]).Footer.Put("text", "注意:流量过期后,剩余流量将会清零");
ui.UIFootBar = new UIFootBar() { IsFixed = true };
ui.UIFootBar.AddText(
new UIEventText(HttpBridgeClient.IsRunning ? "关停" : "开启").Click(new UIClick(HttpBridgeClient.IsRunning ? "Stop" : "Start").Post(request.Model, request.Command)), new UIEventText("去充值").Style(new UIStyle().BgColor()).Click(new UIClick("Recharge").Post(request)));

@ -60,6 +60,7 @@ namespace UMC.Host
string Config(ProviderConfiguration hosts)
{
UMC.Proxy.WebServlet.IsHttps = UMC.Data.WebResource.Instance().Provider["scheme"] == "https";
UMC.Proxy.WebServlet.MainDomain = UMC.Data.WebResource.Instance().Provider["domain"] ?? "localhost";
_urls.Clear();
var host = new Dictionary<int, Socket>();

@ -19,15 +19,7 @@ namespace UMC.Host
{
public static void Main(string[] args)
{
// var files = System.IO.Directory.GetFiles("/Users/wushunming/Documents/APIUMC/UMC.Host", "*.cs", SearchOption.AllDirectories);
// var textFile = new StreamWriter(Utility.Writer(Utility.MapPath("all.txt"), true));
// foreach (var d in files)
// {
// textFile.WriteLine();
// textFile.Write(Utility.Reader(d));
// }
// textFile.Close();
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
var variable = System.Environment.GetEnvironmentVariable("UMC");
@ -485,7 +477,7 @@ namespace UMC.Host
Register();
// File.WriteAllText(UMC.Data.Utility.MapPath($".lock"), $"{{\"Id\":\"{System.Diagnostics.Process.GetCurrentProcess().Id}\"}}");
// UMC.Data.HotCache.Namespace(typeof(UMC.Proxy.Entities.Cookie).Namespace);
UMC.Data.HotCache.Namespace(typeof(UMC.Proxy.Entities.Cookie).Namespace);
UMC.Proxy.DataFactory.Instance();
UMC.Data.DataFactory.Instance();

@ -5,8 +5,8 @@ namespace UMC.Proxy.Entities
{
public partial class Site
{
readonly static Action<Site, object>[] _SetValues = new Action<Site, object>[] { (r, t) => r.Account = Reflection.ParseObject(t, r.Account), (r, t) => r.AdminConf = Reflection.ParseObject(t, r.AdminConf), (r, t) => r.AppendJSConf = Reflection.ParseObject(t, r.AppendJSConf), (r, t) => r.AppSecret = Reflection.ParseObject(t, r.AppSecret), (r, t) => r.AppSecretAuth = Reflection.ParseObject(t, r.AppSecretAuth), (r, t) => r.AuthConf = Reflection.ParseObject(t, r.AuthConf), (r, t) => r.AuthExpire = Reflection.ParseObject(t, r.AuthExpire), (r, t) => r.AuthType = Reflection.ParseObject(t, r.AuthType), (r, t) => r.Caption = Reflection.ParseObject(t, r.Caption), (r, t) => r.Conf = Reflection.ParseObject(t, r.Conf), (r, t) => r.Domain = Reflection.ParseObject(t, r.Domain), (r, t) => r.Flag = Reflection.ParseObject(t, r.Flag), (r, t) => r.HeaderConf = Reflection.ParseObject(t, r.HeaderConf), (r, t) => r.HelpKey = Reflection.ParseObject(t, r.HelpKey), (r, t) => r.Home = Reflection.ParseObject(t, r.Home), (r, t) => r.Host = Reflection.ParseObject(t, r.Host), (r, t) => r.HostModel = Reflection.ParseObject(t, r.HostModel), (r, t) => r.HostReConf = Reflection.ParseObject(t, r.HostReConf), (r, t) => r.ImagesConf = Reflection.ParseObject(t, r.ImagesConf), (r, t) => r.IsAuth = Reflection.ParseObject(t, r.IsAuth), (r, t) => r.IsDebug = Reflection.ParseObject(t, r.IsDebug), (r, t) => r.IsDesktop = Reflection.ParseObject(t, r.IsDesktop), (r, t) => r.IsMarket = Reflection.ParseObject(t, r.IsMarket), (r, t) => r.IsModule = Reflection.ParseObject(t, r.IsModule), (r, t) => r.LogConf = Reflection.ParseObject(t, r.LogConf), (r, t) => r.LogoutPath = Reflection.ParseObject(t, r.LogoutPath), (r, t) => r.MobileHome = Reflection.ParseObject(t, r.MobileHome), (r, t) => r.ModifyTime = Reflection.ParseObject(t, r.ModifyTime), (r, t) => r.OpenModel = Reflection.ParseObject(t, r.OpenModel), (r, t) => r.OutputCookies = Reflection.ParseObject(t, r.OutputCookies), (r, t) => r.RedirectPath = Reflection.ParseObject(t, r.RedirectPath), (r, t) => r.Root = Reflection.ParseObject(t, r.Root), (r, t) => r.SiteKey = Reflection.ParseObject(t, r.SiteKey), (r, t) => r.SLB = Reflection.ParseObject(t, r.SLB), (r, t) => r.StaticConf = Reflection.ParseObject(t, r.StaticConf), (r, t) => r.Time = Reflection.ParseObject(t, r.Time), (r, t) => r.Timeout = Reflection.ParseObject(t, r.Timeout), (r, t) => r.Type = Reflection.ParseObject(t, r.Type), (r, t) => r.UserBrowser = Reflection.ParseObject(t, r.UserBrowser), (r, t) => r.UserModel = Reflection.ParseObject(t, r.UserModel), (r, t) => r.Version = Reflection.ParseObject(t, r.Version) };
readonly static string[] _Columns = new string[] { "Account", "AdminConf", "AppendJSConf", "AppSecret", "AppSecretAuth", "AuthConf", "AuthExpire", "AuthType", "Caption", "Conf", "Domain", "Flag", "HeaderConf", "HelpKey", "Home", "Host", "HostModel", "HostReConf", "ImagesConf", "IsAuth", "IsDebug", "IsDesktop", "IsMarket", "IsModule", "LogConf", "LogoutPath", "MobileHome", "ModifyTime", "OpenModel", "OutputCookies", "RedirectPath", "Root", "SiteKey", "SLB", "StaticConf", "Time", "Timeout", "Type", "UserBrowser", "UserModel", "Version" };
readonly static Action<Site, object>[] _SetValues = new Action<Site, object>[] { (r, t) => r.Account = Reflection.ParseObject(t, r.Account), (r, t) => r.AdminConf = Reflection.ParseObject(t, r.AdminConf), (r, t) => r.AppendJSConf = Reflection.ParseObject(t, r.AppendJSConf), (r, t) => r.AppSecret = Reflection.ParseObject(t, r.AppSecret), (r, t) => r.AppSecretAuth = Reflection.ParseObject(t, r.AppSecretAuth), (r, t) => r.AuthConf = Reflection.ParseObject(t, r.AuthConf), (r, t) => r.AuthExpire = Reflection.ParseObject(t, r.AuthExpire), (r, t) => r.AuthType = Reflection.ParseObject(t, r.AuthType), (r, t) => r.Caption = Reflection.ParseObject(t, r.Caption), (r, t) => r.Domain = Reflection.ParseObject(t, r.Domain), (r, t) => r.Flag = Reflection.ParseObject(t, r.Flag), (r, t) => r.HeaderConf = Reflection.ParseObject(t, r.HeaderConf), (r, t) => r.HelpKey = Reflection.ParseObject(t, r.HelpKey), (r, t) => r.Home = Reflection.ParseObject(t, r.Home), (r, t) => r.Host = Reflection.ParseObject(t, r.Host), (r, t) => r.HostModel = Reflection.ParseObject(t, r.HostModel), (r, t) => r.HostReConf = Reflection.ParseObject(t, r.HostReConf), (r, t) => r.ImagesConf = Reflection.ParseObject(t, r.ImagesConf), (r, t) => r.IsAuth = Reflection.ParseObject(t, r.IsAuth), (r, t) => r.IsDebug = Reflection.ParseObject(t, r.IsDebug), (r, t) => r.IsDesktop = Reflection.ParseObject(t, r.IsDesktop), (r, t) => r.IsMarket = Reflection.ParseObject(t, r.IsMarket), (r, t) => r.IsModule = Reflection.ParseObject(t, r.IsModule), (r, t) => r.LogConf = Reflection.ParseObject(t, r.LogConf), (r, t) => r.LogoutPath = Reflection.ParseObject(t, r.LogoutPath), (r, t) => r.MobileHome = Reflection.ParseObject(t, r.MobileHome), (r, t) => r.ModifyTime = Reflection.ParseObject(t, r.ModifyTime), (r, t) => r.OpenModel = Reflection.ParseObject(t, r.OpenModel), (r, t) => r.OutputCookies = Reflection.ParseObject(t, r.OutputCookies), (r, t) => r.RedirectPath = Reflection.ParseObject(t, r.RedirectPath), (r, t) => r.Root = Reflection.ParseObject(t, r.Root), (r, t) => r.SiteKey = Reflection.ParseObject(t, r.SiteKey), (r, t) => r.SLB = Reflection.ParseObject(t, r.SLB), (r, t) => r.StaticConf = Reflection.ParseObject(t, r.StaticConf), (r, t) => r.SubSite = Reflection.ParseObject(t, r.SubSite), (r, t) => r.Time = Reflection.ParseObject(t, r.Time), (r, t) => r.Timeout = Reflection.ParseObject(t, r.Timeout), (r, t) => r.Type = Reflection.ParseObject(t, r.Type), (r, t) => r.UserBrowser = Reflection.ParseObject(t, r.UserBrowser), (r, t) => r.UserModel = Reflection.ParseObject(t, r.UserModel), (r, t) => r.Version = Reflection.ParseObject(t, r.Version) };
readonly static string[] _Columns = new string[] { "Account", "AdminConf", "AppendJSConf", "AppSecret", "AppSecretAuth", "AuthConf", "AuthExpire", "AuthType", "Caption", "Domain", "Flag", "HeaderConf", "HelpKey", "Home", "Host", "HostModel", "HostReConf", "ImagesConf", "IsAuth", "IsDebug", "IsDesktop", "IsMarket", "IsModule", "LogConf", "LogoutPath", "MobileHome", "ModifyTime", "OpenModel", "OutputCookies", "RedirectPath", "Root", "SiteKey", "SLB", "StaticConf", "SubSite", "Time", "Timeout", "Type", "UserBrowser", "UserModel", "Version" };
protected override void SetValue(string name, object obv)
{
var index = Utility.Search(_Columns, name, StringComparer.CurrentCultureIgnoreCase);
@ -23,7 +23,6 @@ namespace UMC.Proxy.Entities
AppendValue(action, "AuthExpire", this.AuthExpire);
AppendValue(action, "AuthType", this.AuthType);
AppendValue(action, "Caption", this.Caption);
AppendValue(action, "Conf", this.Conf);
AppendValue(action, "Domain", this.Domain);
AppendValue(action, "Flag", this.Flag);
AppendValue(action, "HeaderConf", this.HeaderConf);
@ -49,6 +48,7 @@ namespace UMC.Proxy.Entities
AppendValue(action, "SiteKey", this.SiteKey);
AppendValue(action, "SLB", this.SLB);
AppendValue(action, "StaticConf", this.StaticConf);
AppendValue(action, "SubSite", this.SubSite);
AppendValue(action, "Time", this.Time);
AppendValue(action, "Timeout", this.Timeout);
AppendValue(action, "Type", this.Type);
@ -69,32 +69,32 @@ namespace UMC.Proxy.Entities
cols[6] = RecordColumn.Column("AuthExpire", this.AuthExpire);
cols[7] = RecordColumn.Column("AuthType", this.AuthType);
cols[8] = RecordColumn.Column("Caption", this.Caption);
cols[9] = RecordColumn.Column("Conf", this.Conf);
cols[10] = RecordColumn.Column("Domain", this.Domain);
cols[11] = RecordColumn.Column("Flag", this.Flag);
cols[12] = RecordColumn.Column("HeaderConf", this.HeaderConf);
cols[13] = RecordColumn.Column("HelpKey", this.HelpKey);
cols[14] = RecordColumn.Column("Home", this.Home);
cols[15] = RecordColumn.Column("Host", this.Host);
cols[16] = RecordColumn.Column("HostModel", this.HostModel);
cols[17] = RecordColumn.Column("HostReConf", this.HostReConf);
cols[18] = RecordColumn.Column("ImagesConf", this.ImagesConf);
cols[19] = RecordColumn.Column("IsAuth", this.IsAuth);
cols[20] = RecordColumn.Column("IsDebug", this.IsDebug);
cols[21] = RecordColumn.Column("IsDesktop", this.IsDesktop);
cols[22] = RecordColumn.Column("IsMarket", this.IsMarket);
cols[23] = RecordColumn.Column("IsModule", this.IsModule);
cols[24] = RecordColumn.Column("LogConf", this.LogConf);
cols[25] = RecordColumn.Column("LogoutPath", this.LogoutPath);
cols[26] = RecordColumn.Column("MobileHome", this.MobileHome);
cols[27] = RecordColumn.Column("ModifyTime", this.ModifyTime);
cols[28] = RecordColumn.Column("OpenModel", this.OpenModel);
cols[29] = RecordColumn.Column("OutputCookies", this.OutputCookies);
cols[30] = RecordColumn.Column("RedirectPath", this.RedirectPath);
cols[31] = RecordColumn.Column("Root", this.Root);
cols[32] = RecordColumn.Column("SiteKey", this.SiteKey);
cols[33] = RecordColumn.Column("SLB", this.SLB);
cols[34] = RecordColumn.Column("StaticConf", this.StaticConf);
cols[9] = RecordColumn.Column("Domain", this.Domain);
cols[10] = RecordColumn.Column("Flag", this.Flag);
cols[11] = RecordColumn.Column("HeaderConf", this.HeaderConf);
cols[12] = RecordColumn.Column("HelpKey", this.HelpKey);
cols[13] = RecordColumn.Column("Home", this.Home);
cols[14] = RecordColumn.Column("Host", this.Host);
cols[15] = RecordColumn.Column("HostModel", this.HostModel);
cols[16] = RecordColumn.Column("HostReConf", this.HostReConf);
cols[17] = RecordColumn.Column("ImagesConf", this.ImagesConf);
cols[18] = RecordColumn.Column("IsAuth", this.IsAuth);
cols[19] = RecordColumn.Column("IsDebug", this.IsDebug);
cols[20] = RecordColumn.Column("IsDesktop", this.IsDesktop);
cols[21] = RecordColumn.Column("IsMarket", this.IsMarket);
cols[22] = RecordColumn.Column("IsModule", this.IsModule);
cols[23] = RecordColumn.Column("LogConf", this.LogConf);
cols[24] = RecordColumn.Column("LogoutPath", this.LogoutPath);
cols[25] = RecordColumn.Column("MobileHome", this.MobileHome);
cols[26] = RecordColumn.Column("ModifyTime", this.ModifyTime);
cols[27] = RecordColumn.Column("OpenModel", this.OpenModel);
cols[28] = RecordColumn.Column("OutputCookies", this.OutputCookies);
cols[29] = RecordColumn.Column("RedirectPath", this.RedirectPath);
cols[30] = RecordColumn.Column("Root", this.Root);
cols[31] = RecordColumn.Column("SiteKey", this.SiteKey);
cols[32] = RecordColumn.Column("SLB", this.SLB);
cols[33] = RecordColumn.Column("StaticConf", this.StaticConf);
cols[34] = RecordColumn.Column("SubSite", this.SubSite);
cols[35] = RecordColumn.Column("Time", this.Time);
cols[36] = RecordColumn.Column("Timeout", this.Timeout);
cols[37] = RecordColumn.Column("Type", this.Type);

@ -87,7 +87,7 @@ namespace UMC.Proxy.Entities
/// <summary>
/// 应用子目录
/// </summary>
public String Conf { get; set; }
public String SubSite { get; set; }
public String AuthConf { get; set; }
public String StaticConf { get; set; }

File diff suppressed because it is too large Load Diff

@ -50,7 +50,6 @@ namespace UMC.Proxy.Activities
}
void Market(Site site)
{
// System.Net.Cache.HttpCacheAgeControl
var secret = UMC.Data.WebResource.Instance().Provider["appSecret"];
if (String.IsNullOrEmpty(secret))
{
@ -72,7 +71,7 @@ namespace UMC.Proxy.Activities
confData.Remove("IsDesktop");
confData.Remove("SiteKey");
confData.Remove("HostModel");
confData.Remove("HostReConf");
// confData.Remove("HostReConf");
confData.Remove("Conf");
var login = UMC.Data.DataFactory.Instance().Config($"SITE_MIME_{site.Root}_LOGIN".ToUpper());
@ -150,9 +149,9 @@ namespace UMC.Proxy.Activities
{
var config = this.AsyncDialog("Config", g =>
{
var from = new Web.UIFormDialog() { Title = "透传会话" };
from.AddTextarea("Cookie名称", "OutputCookie", site.OutputCookies).PlaceHolder("Cookie的名称").NotRequired();
from.AddFooter("多个用换行、空格或逗号符分割,用*表示透传所有Cookie");
var from = new Web.UIFormDialog() { Title = "过期会话" };
from.AddTextarea("Cookie名称", "OutputCookie", site.OutputCookies).PlaceHolder("Cookie的名称和路径").NotRequired();
from.AddFooter("当从新登录时需要清空的Cookie,值为name和path字典对。");
from.Submit("确认", "Site.Config");
return from;
});
@ -201,20 +200,20 @@ namespace UMC.Proxy.Activities
}
var path = new Hashtable();
if (String.IsNullOrEmpty(site.Conf) == false)
if (String.IsNullOrEmpty(site.SubSite) == false)
{
var v = UMC.Data.JSON.Deserialize(site.Conf) as Hashtable;
var v = UMC.Data.JSON.Deserialize(site.SubSite) as Hashtable;
if (v != null)
{
path = v;
}
}
path[Key] = Value;
site.Conf = UMC.Data.JSON.Serialize(path);
site.SubSite = UMC.Data.JSON.Serialize(path);
DataFactory.Instance().Put(new Site
{
Root = site.Root,
Conf = site.Conf
SubSite = site.SubSite
});
this.Context.Send("Site.Config", true);
@ -1025,9 +1024,9 @@ namespace UMC.Proxy.Activities
var path = new Hashtable();
if (String.IsNullOrEmpty(site.Conf) == false)
if (String.IsNullOrEmpty(site.SubSite) == false)
{
var v = UMC.Data.JSON.Deserialize(site.Conf) as Hashtable;
var v = UMC.Data.JSON.Deserialize(site.SubSite) as Hashtable;
if (v != null)
{
path = v;
@ -1136,7 +1135,7 @@ namespace UMC.Proxy.Activities
ui2 = ui.NewSection().AddCell("内容转化", String.IsNullOrEmpty(site.HostReConf) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "HostReConf")).Post(request.Model, request.Command));
// ui2.AddCell("透传会话", String.IsNullOrEmpty(site.OutputCookies) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "OutputCookie")).Post(request.Model, request.Command));
ui2.AddCell("过期会话", String.IsNullOrEmpty(site.OutputCookies) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "OutputCookie")).Post(request.Model, request.Command));
var m = "标准模式";
switch ((site.UserModel ?? UserModel.Standard))
@ -1313,9 +1312,9 @@ namespace UMC.Proxy.Activities
{
var path = new Hashtable();
if (String.IsNullOrEmpty(site.Conf) == false)
if (String.IsNullOrEmpty(site.SubSite) == false)
{
var v = UMC.Data.JSON.Deserialize(site.Conf) as Hashtable;
var v = UMC.Data.JSON.Deserialize(site.SubSite) as Hashtable;
if (v != null)
{
path = v;
@ -1323,7 +1322,7 @@ namespace UMC.Proxy.Activities
}
path.Remove(Model);
DataFactory.Instance().Put(new Site { Root = site.Root, Conf = UMC.Data.JSON.Serialize(path) });
DataFactory.Instance().Put(new Site { Root = site.Root, SubSite = UMC.Data.JSON.Serialize(path) });
}
else
{

@ -7,6 +7,12 @@ using System.Linq;
namespace UMC.Proxy
{
// class HostConvert
// {
// Span<byte> Item1;
// Span<byte> Item1();
// Span<byte> Item1;
// }
public class UMCUri : Uri
{
public UMCUri([StringSyntax("Uri")] string uriString) : base(uriString)
@ -36,7 +42,7 @@ namespace UMC.Proxy
public enum HostReplaceModel
{
Replace = 1,
Remove = 2,
// Remove = 2,
Input = 4,
CDN = 8,
Script = 16
@ -48,10 +54,18 @@ namespace UMC.Proxy
get;
set;
}
public System.Collections.Generic.Dictionary<String, UMCUri> Hosts
// public System.Collections.Generic.Dictionary<String, UMCUri> Hosts
// {
// get;
// set;
// }
HashSet<HostConvert> _Domains = new HashSet<HostConvert>(new EqualityComparer());
public HashSet<HostConvert> Domains
{
get;
set;
get
{
return _Domains;
}
}
}
public class LogSetting
@ -91,6 +105,27 @@ namespace UMC.Proxy
set;
}
}
public class HostConvert
{
public byte[] Main;
public byte[] Proxy;
public byte[] ProxyPort;
public byte[] Decode;
}
class EqualityComparer : IEqualityComparer<HostConvert>
{
public bool Equals(HostConvert x, HostConvert y)
{
return Utility.IntParse(System.Security.Cryptography.MD5.HashData(x.Main)) == Utility.IntParse(System.Security.Cryptography.MD5.HashData(y.Main));
}
public int GetHashCode(HostConvert obj)
{
return Utility.IntParse(System.Security.Cryptography.MD5.HashData(obj.Main));
}
}
public class KeyValue
{
@ -136,16 +171,8 @@ namespace UMC.Proxy
public SiteConfig(Entities.Site site)
{
this.Caption = site.Caption;
var vindex = this.Caption.IndexOf("v.", StringComparison.CurrentCultureIgnoreCase);
if (vindex > -1)
{
this.Caption = this.Caption.Substring(0, vindex);
}
if (String.IsNullOrEmpty(site.Home) == false && (site.Home.StartsWith("https:") || site.Home.StartsWith("http:")))
{
this.Home = new Uri(site.Home).PathAndQuery;
}
else
if (String.IsNullOrEmpty(site.Home) == false)//&& (site.Home.StartsWith("https:") || site.Home.StartsWith("http:")))
{
this.Home = site.Home;
}
@ -161,13 +188,13 @@ namespace UMC.Proxy
for (var i = 0; i < dom.Length; i++)
{
var v = dom[i].Trim();
var timeout = String.Empty;
var KeepAlive = String.Empty;
if (String.IsNullOrEmpty(v) == false)
{
var valueIndex = v.IndexOf('~');
if (valueIndex > 0)
{
timeout = v.Substring(valueIndex).Trim();
KeepAlive = v.Substring(valueIndex + 1).Trim();
v = v.Substring(0, valueIndex).Trim();
}
if (v.EndsWith("]"))
@ -187,16 +214,16 @@ namespace UMC.Proxy
ls.Add(1);
}
var sIndex = tUrl.LastIndexOf('/');
var sIndex = tUrl.IndexOf('/', 8);
if (sIndex > 0)
{
tUrl = tUrl.Substring(0, sIndex);
}
domains.Add(tUrl);
if (String.IsNullOrEmpty(timeout) == false)
if (String.IsNullOrEmpty(KeepAlive) == false)
{
Net.NetProxy.KeepAlives(new Uri(tUrl), Utility.IntParse(timeout, 60));
Net.NetProxy.KeepAlives(new Uri(tUrl), Utility.IntParse(KeepAlive, 60));
}
}
else
@ -226,7 +253,7 @@ namespace UMC.Proxy
}
if (tUsers.Count > 0 || tAuth.Count > 0)
{
var sIndex = tUrl.LastIndexOf('/');//, tIndex);
var sIndex = tUrl.IndexOf('/', 8);//, tIndex);
if (sIndex > 0)
{
tUrl = tUrl.Substring(0, sIndex);
@ -239,7 +266,7 @@ namespace UMC.Proxy
{
if (tUrl.StartsWith("file://") == false)
{
var sIndex = tUrl.LastIndexOf('/');
var sIndex = tUrl.IndexOf('/', 8);
if (sIndex > 0)
{
tUrl = tUrl.Substring(0, sIndex);
@ -249,9 +276,9 @@ namespace UMC.Proxy
total++;
ls.Add(1);
}
if (String.IsNullOrEmpty(timeout) == false)
if (String.IsNullOrEmpty(KeepAlive) == false)
{
Net.NetProxy.KeepAlives(new Uri(tUrl), Utility.IntParse(timeout, 60));
Net.NetProxy.KeepAlives(new Uri(tUrl), Utility.IntParse(KeepAlive, 60));
}
}
@ -279,16 +306,15 @@ namespace UMC.Proxy
this.Weights = ls.ToArray();
this.AllowPath = Config(site.AuthConf);
this.OutputCookies = Config(site.OutputCookies);
this.LogoutPath = Config(site.LogoutPath);
this.AppendJSConf = Config(site.AppendJSConf);
this.RedirectPath = Config(site.RedirectPath);
this.ImagesConf = Config(site.ImagesConf);
var subSite = new List<KeyValue>();
if (String.IsNullOrEmpty(site.Conf) == false)
if (String.IsNullOrEmpty(site.SubSite) == false)
{
var v = UMC.Data.JSON.Deserialize(site.Conf) as Hashtable;
var v = UMC.Data.JSON.Deserialize(site.SubSite) as Hashtable;
if (v != null)
{
var pem = v.GetEnumerator();
@ -309,12 +335,14 @@ namespace UMC.Proxy
}
_subSite = subSite.ToArray();
InitStatic(site.StaticConf);
InitHost(site.HostReConf);
InitHeader(site.HeaderConf);
InitLogConf(site.LogConf);
InitCookie(site.OutputCookies);
this.AllowAllPath = this.AllowPath.Contains("*");
InitHost(site.HostReConf);
}
public bool AllowAllPath
@ -406,6 +434,42 @@ namespace UMC.Proxy
this.LogConf.ResHeaders = rhs.ToArray();
this.LogConf.Cookies = cs.ToArray();
}
void InitCookie(String sConf)
{
if (String.IsNullOrEmpty(sConf) == false)
{
foreach (var k in sConf.Split('\n', ','))
{
var v = k.Trim();
if (String.IsNullOrEmpty(v) == false && String.Equals(k, "none") == false)
{
var nindex = v.IndexOf(':');
if (nindex == -1)
{
nindex = v.IndexOf(' ');
if (nindex == -1)
{
nindex = v.IndexOf('\t');
}
}
if (nindex > -1)
{
var mv = v.Substring(nindex + 1).Trim();
var key = v.Substring(0, nindex).Trim();
if (mv.StartsWith('/'))
{
_OutputCookies[key] = mv;
}
}
}
}
}
}
void InitHeader(String sConf)
{
@ -448,9 +512,6 @@ namespace UMC.Proxy
}
}
}
@ -526,12 +587,44 @@ namespace UMC.Proxy
}
}
public HostConvert MainHost
{
get;
private set;
}
void InitHost(String sConf)
{
// this.Do
var domain = Data.WebResource.Instance().Provider["domain"];
var union = Data.WebResource.Instance().Provider["union"] ?? ".";
var union = ".";
if (this.Domains.Length > 0)
{
var url = this.Domains[0];
var hostConvert = this.MainHost = new HostConvert();
if (url.Contains('*'))
{
hostConvert.Main = System.Text.ASCIIEncoding.UTF8.GetBytes(String.Format(".{0}{1}{2}", this.Site.Root, union, domain));
var l = new UMCUri(url.Replace("*.", ""));
hostConvert.Proxy = System.Text.ASCIIEncoding.UTF8.GetBytes("." + l.Host);
hostConvert.ProxyPort = System.Text.ASCIIEncoding.UTF8.GetBytes("." + l.UMCAuthority);
hostConvert.Decode = System.Text.ASCIIEncoding.UTF8.GetBytes(Uri.EscapeDataString("." + l.UMCAuthority));
}
else
{
if (String.IsNullOrEmpty(this.Site.Host) == false)
{
url = url.Replace(new UMCUri(url).Host, this.Site.Host);
}
hostConvert.Main = System.Text.ASCIIEncoding.UTF8.GetBytes(String.Format("{0}{1}{2}", this.Site.Root, union, domain));
var l = new UMCUri(url);
hostConvert.Proxy = System.Text.ASCIIEncoding.UTF8.GetBytes(l.Host);
hostConvert.ProxyPort = System.Text.ASCIIEncoding.UTF8.GetBytes(l.UMCAuthority);
hostConvert.Decode = System.Text.ASCIIEncoding.UTF8.GetBytes(Uri.EscapeDataString(l.UMCAuthority));
}
}
if (String.IsNullOrEmpty(sConf) == false)
{
foreach (var k in sConf.Split('\n'))
@ -557,11 +650,11 @@ namespace UMC.Proxy
key = v.Substring(0, nindex).Trim();
if (_HostPage.ContainsKey(key) == false)
{
_HostPage[key] = new ReplaceSetting() { Model = HostReplaceModel.Replace, Hosts = new System.Collections.Generic.Dictionary<String, UMCUri>() };
_HostPage[key] = new ReplaceSetting() { Model = HostReplaceModel.Replace };
}
ReplaceSetting replaceSetting = _HostPage[key];
HostReplaceModel hostReplace = replaceSetting.Model;
var list = replaceSetting.Hosts;
var list = replaceSetting.Domains;
foreach (var kv in mv)
{
@ -625,14 +718,40 @@ namespace UMC.Proxy
}
if (String.IsNullOrEmpty(url) == false)
{
var surl = new UMCUri(url);
if (String.IsNullOrEmpty(sit.Host) == false)
// var v=
var hostConvert = new HostConvert();
if (url.Contains('*'))
{
hostConvert.Main = System.Text.ASCIIEncoding.UTF8.GetBytes(String.Format(".{0}{1}{2}", sit.Root, union, domain));
var l = new UMCUri(url.Replace("*.", ""));
hostConvert.Proxy = System.Text.ASCIIEncoding.UTF8.GetBytes("." + l.Host);
hostConvert.ProxyPort = System.Text.ASCIIEncoding.UTF8.GetBytes("." + l.UMCAuthority);
hostConvert.Decode = System.Text.ASCIIEncoding.UTF8.GetBytes(Uri.EscapeDataString("." + l.UMCAuthority));
}
else
{
surl = new UMCUri(url.Replace(surl.Host, sit.Host));
if (String.IsNullOrEmpty(sit.Host) == false)
{
url = url.Replace(new UMCUri(url).Host, sit.Host);
}
hostConvert.Main = System.Text.ASCIIEncoding.UTF8.GetBytes(String.Format("{0}{1}{2}", sit.Root, union, domain));
var l = new UMCUri(url);
hostConvert.Proxy = System.Text.ASCIIEncoding.UTF8.GetBytes(l.Host);
hostConvert.ProxyPort = System.Text.ASCIIEncoding.UTF8.GetBytes(l.UMCAuthority);
hostConvert.Decode = System.Text.ASCIIEncoding.UTF8.GetBytes(Uri.EscapeDataString(l.UMCAuthority));
}
list.Add(hostConvert);
// var surl = new UMCUri(url);
// if (String.IsNullOrEmpty(sit.Host) == false)
// {
// surl = new UMCUri(url.Replace(surl.Host, sit.Host));
// }
list[String.Format("{0}{1}{2}", sit.Root, union, domain)] = surl;// new Uri(String.f);
// list[String.Format("{0}{1}{2}", sit.Root, union, domain)] = surl;// new Uri(String.f);
break;
}
@ -644,7 +763,7 @@ namespace UMC.Proxy
hostReplace |= HostReplaceModel.Replace;
break;
case "rm":
hostReplace |= HostReplaceModel.Remove;
hostReplace |= HostReplaceModel.Replace;
break;
case "input":
case "in":
@ -750,10 +869,14 @@ namespace UMC.Proxy
get;
private set;
}
public String[] OutputCookies
System.Collections.Generic.Dictionary<String, String> _OutputCookies = new Dictionary<string, String>();
public System.Collections.Generic.Dictionary<String, String> OutputCookies
{
get;
private set;
get
{
return _OutputCookies;
}
}
public String[] ImagesConf
{

@ -183,14 +183,13 @@ namespace UMC.Proxy.Activities
var union = provider["union"] ?? ".";
var scheme = provider["scheme"] ?? "http";
fm.AddRadio("主协议", "scheme").Put("http", "http", scheme == "http").Put("https", "https", scheme == "https");
// fm.AddRadio("连接符", "union").Put("-", "-", union == "-").Put(".", ".", union == ".");
fm.Submit("确认", $"{request.Model}.{request.Command}");
return fm;
});
// provider.Attributes["union"] = Domains["union"];
provider.Attributes["scheme"] = Domains["scheme"];
provider.Attributes["domain"] = Domains["domain"];
var pc = UMC.Data.Reflection.Configuration("assembly") ?? new ProviderConfiguration();
pc.Add(provider);

@ -28,7 +28,7 @@ namespace UMC.Proxy
public override void ProcessActivity(WebRequest request, WebResponse response)
{
var user = this.Context.Token.Identity();
var httpProxy = new HttpProxy(site, this.Context.Client.Context, -1, false, "/");
var httpProxy = new HttpProxy(site, this.Context.Client.Context, -1, "/", String.Empty);
if (httpProxy.Domain == null)
{
this.Prompt("安全审记", $"此应用临时关闭,请联系应用管理员");
@ -173,7 +173,7 @@ namespace UMC.Proxy
var getUrl = new Uri(httpProxy.Domain, $"/UMC/{Utility.Guid(this.Context.Token.Device.Value)}/{query}");
var content = this.Context.Client.Context;
var webReq = httpProxy.Reqesut(content.Transfer(getUrl, httpProxy.Cookies));
var webReq = httpProxy.Reqesut(content.Transfer(getUrl));
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.Post(sb.ToString(), res =>
{

@ -467,7 +467,6 @@ namespace UMC.Proxy
var appids = new List<String>();
foreach (var p in account.Providers)
{
// var p = account[i];
if (String.Equals(p.Type, "dingtalk"))
{
@ -617,7 +616,7 @@ namespace UMC.Proxy
var ds = cdmn.Split('.');
if (ds.Length > 2)
{
cdmn = cdmn.Substring(ds[0].Length + 1);// ds[ds.Length - 2] + "." + ds[ds.Length - 1];
cdmn = cdmn.Substring(ds[0].Length + 1);
}
}
context.AddHeader("Set-Cookie", String.Format(cookieStr, sessionKey, DateTime.Now.AddYears(10).ToString("r"), cdmn, SameSite));
@ -1006,9 +1005,6 @@ namespace UMC.Proxy
{
webMeta.Put("msg", "域名所有权签名验证不通过").Put("code", "error");
}
}
UMC.Data.JSON.Serialize(webMeta, context.Output);
context.OutputFinish();
@ -1096,7 +1092,7 @@ namespace UMC.Proxy
if (psite2 != null)
{
context.Token = new UMC.Data.AccessToken(Guid.Empty).Login(new UMC.Security.Guest(Guid.Empty), 0);
var httpProxy = new HttpProxy(psite2, context, 0, true, rawUrl);
var httpProxy = new HttpProxy(psite2, context, 0, rawUrl, String.Empty);
if (httpProxy.Domain == null)
{
@ -1282,7 +1278,7 @@ namespace UMC.Proxy
rawUrl = rawUrl.Substring(keyIndex2);
}
}
var httpProxy = new HttpProxy(psite, context, 0, true, rawUrl);
var httpProxy = new HttpProxy(psite, context, 0, rawUrl, String.Empty);
if (httpProxy.Domain == null)
{
Close(context);
@ -1323,65 +1319,45 @@ namespace UMC.Proxy
var host = context.Url.Host;
SiteConfig siteConfig = null;
var pfxDomain = String.Empty;
var ishttps = IsHttps;
if (host.Length > MainDomain.Length && host.EndsWith(MainDomain))
{
var rook = host.Substring(0, host.Length - MainDomain.Length - 1);
var ls = rook.Split('.', '-');
if (ls.Length > 1)
{
pfxDomain = rook.Substring(0, rook.Length - ls[ls.Length - 1].Length - 1);
siteConfig = UMC.Proxy.DataFactory.Instance().SiteConfig(ls[ls.Length - 1]);
}
else
{
for (var i = 0; i < host.Length; i++)
siteConfig = UMC.Proxy.DataFactory.Instance().SiteConfig(ls[0]);
}
}
if (siteConfig == null)
{
if (host[i] == '.')
var hostSite = DataFactory.Instance().HostSite(host);
if (hostSite != null)
{
var hostSite = DataFactory.Instance().HostSite(host);
if (hostSite != null)
if (hostSite.IsAuthModel == true)
{
if (hostSite.IsAuthModel == true)
if (hostSite.Scheme == 2)
{
if (hostSite.Scheme == 2)
{
ishttps = true;
}
siteConfig = UMC.Proxy.DataFactory.Instance().SiteConfig(hostSite.Root);
break;
ishttps = true;
}
else
{
Transfer(hostSite, context, rawUrl);
siteConfig = UMC.Proxy.DataFactory.Instance().SiteConfig(hostSite.Root);
return;
}
}
siteConfig = UMC.Proxy.DataFactory.Instance().SiteConfig(host.Substring(0, i));
break;
}
else if (host[i] == '-')
{
siteConfig = UMC.Proxy.DataFactory.Instance().SiteConfig(host.Substring(0, i));
if (siteConfig == null)
else
{
var hostSite = DataFactory.Instance().HostSite(host);
if (hostSite != null)
{
if (hostSite.IsAuthModel == true)
{
if (hostSite.Scheme == 2)
{
ishttps = true;
}
Transfer(hostSite, context, rawUrl);
siteConfig = UMC.Proxy.DataFactory.Instance().SiteConfig(hostSite.Root);
break;
}
else
{
Transfer(hostSite, context, rawUrl);
return;
}
}
return;
}
break;
}
}
if (ishttps && context.Url.Port == 80)
{
@ -1412,7 +1388,7 @@ namespace UMC.Proxy
}
if (siteConfig != null)
{
Proxy(context, siteConfig, rawUrl);
Proxy(context, siteConfig, pfxDomain, rawUrl);
return;
}
@ -1432,7 +1408,14 @@ namespace UMC.Proxy
break;
}
var file = Path == "/" ? "/index.html" : Path;
var staticFile = FilePath($"{UMC.Data.Reflection.ConfigPath("Static")}{file}");
if (System.IO.File.Exists(staticFile))
{
TransmitFile(context, staticFile, true);
return;
}
switch (Path)
{
case "/notsupport":
@ -1608,7 +1591,10 @@ namespace UMC.Proxy
HttpWebRequest WebTransfer(SiteConfig siteConfig, UMC.Net.NetContext context, string rawUrl)
{
var webR = new Uri(HttpProxy.WeightUri(siteConfig, context), rawUrl).WebRequest();
var d = siteConfig.Domains[HttpProxy.WeightUri(siteConfig, context)]; //siteConfig.Domains[WeightUri(this.Site, this.Context)];
var dIndex = d.IndexOf('*');
var webR = new Uri(new Uri(dIndex > 0 ? d.Remove(dIndex, 2) : d), rawUrl).WebRequest();
WebHeaderConf(webR, siteConfig, context, String.Empty);
@ -1877,7 +1863,6 @@ namespace UMC.Proxy
context.OutputFinish();
break;
case "PUT":
//x X500DistinguishedName/x var ns = new NameValueCollection();
if (Data.Utility.CheckSign(context.Headers, "umc-", siteConfig.Site.AppSecret) == false)
{
@ -1921,6 +1906,22 @@ namespace UMC.Proxy
}
}
static string _MainDomain;
public static string MainDomain
{
get
{
if (String.IsNullOrEmpty(_MainDomain))
{
_MainDomain = UMC.Data.WebResource.Instance().Provider["domain"] ?? "localhost";
}
return _MainDomain;
}
set
{
_MainDomain = value;
}
}
void Transfer(SiteConfig siteConfig, UMC.Net.NetContext context, string RawUrl)
{
@ -2100,7 +2101,7 @@ namespace UMC.Proxy
if (i == -1)
{
context.StatusCode = 405;
context.ContentType = "text/plain;charset=utf-8";
context.ContentType = "text/plain; charset=utf-8";
context.Output.Write("接收Body错误");
context.OutputFinish();
}
@ -2132,7 +2133,7 @@ namespace UMC.Proxy
var v = UMC.Data.HotCache.Cache(type, hsh["value"] as Hashtable);
if (v != null)
{
context.ContentType = "application/json;charset=utf-8";
context.ContentType = "application/json; charset=utf-8";
UMC.Data.JSON.Serialize(v, context.Output, "ts");
return;
}
@ -2197,9 +2198,9 @@ namespace UMC.Proxy
{
get; set;
}
// public i
void Proxy(UMC.Net.NetContext context, SiteConfig psite, string rawUrl)
void Proxy(UMC.Net.NetContext context, SiteConfig psite, String pfxDomain, string rawUrl)
{
for (var i = 0; i < psite.SubSite.Length; i++)
{
@ -2324,7 +2325,8 @@ namespace UMC.Proxy
this.StaticFile(psite, psite.Domains[0].Substring(7), context, rawUrl);
return;
}
var httpProxy = new HttpProxy(psite, context, HttpProxy.CheckStaticPage(psite, path), false, rawUrl);
var httpProxy = new HttpProxy(psite, context, HttpProxy.CheckStaticPage(psite, path), rawUrl, pfxDomain);
if (httpProxy.Domain == null)
{
Close(context);
@ -2380,7 +2382,7 @@ namespace UMC.Proxy
var getUrl = new Uri(httpProxy.Domain, httpProxy.RawUrl);
context.Tag = httpProxy.Reqesut(context.Transfer(getUrl, httpProxy.Cookies));
context.Tag = httpProxy.Reqesut(context.Transfer(getUrl));
}

@ -1,13 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<InvariantGlobalization>true</InvariantGlobalization>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<!-- <VersionPrefix>1.0.420</VersionPrefix> -->
<RootNamespace>UMC.Proxy</RootNamespace>
</PropertyGroup>
<!-- <PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup> -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>

Loading…
Cancel
Save