diff --git a/Mime/HttpMimeSocket.cs b/Mime/HttpMimeSocket.cs index b66cce5..fae0e30 100644 --- a/Mime/HttpMimeSocket.cs +++ b/Mime/HttpMimeSocket.cs @@ -101,7 +101,6 @@ namespace UMC.ITME try { Subscribe(this._data, e.Offset + 1, e.BytesTransferred - 1); - // _socket = null; } catch (Exception ex) { @@ -119,7 +118,6 @@ namespace UMC.ITME } var req = this.Request; - // req.Receive(this._data, 0, size); req.Receive(this._data, e.Offset, e.BytesTransferred); @@ -131,7 +129,6 @@ namespace UMC.ITME else if (this.isDispose == false) { return true; - // ProcessReceive(e); } } catch (Exception ex) @@ -158,12 +155,13 @@ namespace UMC.ITME var ps = System.Text.Encoding.UTF8.GetString(header, offset, size).Split("\r\n", StringSplitOptions.RemoveEmptyEntries); foreach (var s in ps) { - var vi = s.IndexOf(':'); - var key = s.Substring(0, vi); - var value = s.Substring(vi + 2); - headers.Add(key, value); - + if (vi > 0 && vi + 2 < s.Length) + { + var key = s.Substring(0, vi); + var value = s.Substring(vi + 2); + headers.Add(key, value); + } } int length = 0; diff --git a/Proxy/DataFactory.cs b/Proxy/DataFactory.cs index 2fe0a09..e5c0422 100644 --- a/Proxy/DataFactory.cs +++ b/Proxy/DataFactory.cs @@ -29,12 +29,8 @@ namespace UMC.ITME } return _Instance; } - static DataFactory _Instance;// = new DataFactory(); - // public static void Instance(DataFactory dataFactory) - // { - // _Instance = dataFactory; - // NetSubscribe.Subscribe("SiteConfig", _Instance); - // } + static DataFactory _Instance; + public virtual Site[] Site() @@ -43,12 +39,6 @@ namespace UMC.ITME return HotCache.Cache().Find(new Entities.Site(), 0, out index); } - // public virtual Device[] Devices() - // { - // int index; - // return HotCache.Cache().Find(new Entities.Device(), 0, out index); - - // } public virtual Site Site(String root) @@ -134,10 +124,6 @@ namespace UMC.ITME } } - public virtual String Evaluate(String js, params string[] args) - { - return ""; - } public virtual Stream Decompress(Stream response, string encoding) { switch (encoding) diff --git a/Proxy/HttpProxy.cs b/Proxy/HttpProxy.cs index 871c346..39fac1d 100644 --- a/Proxy/HttpProxy.cs +++ b/Proxy/HttpProxy.cs @@ -911,12 +911,12 @@ namespace UMC.ITME if (String.IsNullOrEmpty(sStrDomain) == false) { - getUrl = new Uri(sStrDomain);// new Uri(new, PathAndQuery); + getUrl = new Uri(sStrDomain); } else { - getUrl = Domain;// new Uri(Domain, PathAndQuery); + getUrl = Domain; } var Method = login["Method"] as string ?? "GET"; @@ -1312,14 +1312,6 @@ namespace UMC.ITME var checkConfig = GetConf(String.Format("SITE_MIME_{0}_CHECK", proxy.Site.Root).ToUpper()); if (checkConfig.ContainsKey("Finish")) { - - // if (String.IsNullOrEmpty(proxy.Site.Home) == false && proxy.Site.Home.StartsWith("http") == false) - // { - // var r = proxy.Reqesut(this.Context.Transfer(new Uri(proxy.Domain, proxy.Site.Home))).Get(); - - // proxy.SetCookie(r); - - // } var config = new Hashtable(); if (proxy.IsLog == true) @@ -2788,7 +2780,7 @@ namespace UMC.ITME } - bool SaveCookie() + internal bool SaveCookie() { if (this.IsChangeUser == true) @@ -2828,6 +2820,7 @@ namespace UMC.ITME } siteCookie.Config = this.SiteCookie.Config; + siteCookie.Cookies = this.SiteCookie.Cookies; siteCookie.LoginTime = UMC.Data.Utility.TimeSpan(); this.IsChangeUser = null; DataFactory.Instance().Put(siteCookie); @@ -3025,6 +3018,21 @@ namespace UMC.ITME this.Context.AddHeader(key, this.Context.Headers.Get("Origin") ?? m_HttpHeaders.Get(i)); // } break; + case "itme-access-token": + if (this.Site.Site.UserModel == Entities.UserModel.Bridge) + { + var access = m_HttpHeaders.Get(i); + if (String.Equals(this.SiteCookie.Cookies, access) == false) + { + this.SiteCookie.Cookies = access; + this.IsChangeUser = true; + } + } + else + { + goto default; + } + break; case "strict-transport-security": case "content-type": case "server": @@ -3267,6 +3275,16 @@ namespace UMC.ITME user = this.Account; } break; + case Entities.UserModel.Bridge: + if (this.Site.Site.IsAuth == true) + { + user = this.Account; + } + if (String.IsNullOrEmpty(this.SiteCookie.Cookies) == false) + { + heaers.Add("itme-access-token", this.SiteCookie.Cookies); + } + break; } heaers.Add("umc-request-user-name", Uri.EscapeDataString(user.Name)); heaers.Add("umc-request-user-id", UMC.Data.Utility.Guid(user.Id.Value)); diff --git a/Proxy/SiteActivity.cs b/Proxy/SiteActivity.cs index e86dd48..1fa27f8 100644 --- a/Proxy/SiteActivity.cs +++ b/Proxy/SiteActivity.cs @@ -923,7 +923,7 @@ namespace UMC.ITME.Activities style.BgColor(0xfafcff).Height(180).AlignCenter(); from.AddHeader(new UIHeader().Desc(new UMC.Web.WebMeta().Put("title", "配置市场应用需要证书").Put("icon", "\uea05"), "{icon}\n{title}", style)); - from.Add(UICell.QRCode($"https://api.apiumc.com/UMC/Platform/EditCert/{appId}/{Seller}")); + from.Add(new UIQRCode($"https://api.apiumc.com/UMC/Platform/EditCert/{appId}/{Seller}")); from.AddFooter("请应用开发者用ITME App扫一扫,生成证书,再点击下一步", "Settings", "YES"); from.Submit("下一步", $"{request.Model}.{request.Command}"); diff --git a/Proxy/SiteSetupActivity.cs b/Proxy/SiteSetupActivity.cs index 6e633d9..fb726b1 100644 --- a/Proxy/SiteSetupActivity.cs +++ b/Proxy/SiteSetupActivity.cs @@ -84,7 +84,7 @@ namespace UMC.ITME.Activities } from.Title = "开发者发布"; - from.Add(UICell.QRCode($"https://api.apiumc.com/UMC/Platform/EditCert/{appId}")); + from.Add(new UIQRCode($"https://api.apiumc.com/UMC/Platform/EditCert/{appId}")); from.AddFooter("请开发者用ITME App扫一扫,生成开发者证书,再点击下一步", "Settings", "YES"); from.Submit("下一步", $"{request.Model}.{request.Command}"); diff --git a/Proxy/WebFactory.cs b/Proxy/WebFactory.cs index 7cb8672..56c4e18 100644 --- a/Proxy/WebFactory.cs +++ b/Proxy/WebFactory.cs @@ -233,13 +233,23 @@ namespace UMC.ITME webReq.ContentType = "application/x-www-form-urlencoded"; webReq.Post(sb.ToString(), res => { + var token = res.Headers.Get("itme-access-token"); + if (String.IsNullOrEmpty(token) == false) + { + if (String.Equals(httpProxy.SiteCookie.Cookies, token) == false) + { + httpProxy.SiteCookie.Cookies = token; + httpProxy.IsChangeUser = true; + httpProxy.SaveCookie(); + } + + } int StatusCode = (int)res.StatusCode; - HttpProxy.LogWrite(httpProxy.Context, httpProxy.Site, 200, webReq.RawUrl, httpProxy.SiteCookie.Account, null, String.Empty); + HttpProxy.LogWrite(httpProxy.Context, httpProxy.Site, StatusCode, webReq.RawUrl, httpProxy.SiteCookie.Account, null, String.Empty); if (StatusCode > 300 && StatusCode < 400) { - httpProxy.ProcessEnd(); var url = res.Headers.Get("Location"); response.Headers.Put("Data", new Uri(content.Url, url)); response.ClientEvent |= (WebEvent)131072;