From 09fe67bd27f5da5fc2b8b7b33c06e9240bac46c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E9=A1=BA=E6=98=8E?= Date: Wed, 24 Apr 2024 15:27:02 +0800 Subject: [PATCH] Change --- Mime/HttpMime.cs | 158 +++++++++++++++++------------------- Mime/HttpMimeRequest.cs | 4 +- Mime/HttpsMimeSocket.cs | 5 +- Program.cs | 10 +-- Proxy/HttpProxy.cs | 25 +++++- Proxy/SiteConfig.cs | 10 +-- Proxy/SiteSSHActivities.cs | 41 +++++++--- Proxy/SiteServerActivity.cs | 59 +++++++------- Proxy/Utility.cs | 5 +- Proxy/WebServlet.cs | 52 +++++++----- UMC.ITME.csproj | 4 +- 11 files changed, 210 insertions(+), 163 deletions(-) diff --git a/Mime/HttpMime.cs b/Mime/HttpMime.cs index 37ef6e0..b6a905e 100644 --- a/Mime/HttpMime.cs +++ b/Mime/HttpMime.cs @@ -182,6 +182,7 @@ namespace UMC.ITME var by = str[i]; switch (by) { + case '\0': case '\a': break; case '\b': @@ -240,15 +241,11 @@ namespace UMC.ITME { isInput = str.StartsWith(device.Username); } - if (isPwd && isInput) + if (isPwd) { - if (lines.Length == 2) + if (lines[0].StartsWith("/")) { - if (lines[0].StartsWith("/")) - { - webSocket.Send("{\"type\":\"view\",\"value\":{\"Path\":\"" + lines[0] + "\",\"Key\":\"" + device.Id + "\"}}"); - - } + webSocket.Send("{\"type\":\"view\",\"value\":{\"Path\":\"" + lines[0] + "\",\"Key\":\"" + device.Id + "\"}}"); } } @@ -264,7 +261,7 @@ namespace UMC.ITME isInput = false; if (count > 0) { - var ls = new String(input.AsSpan(0, count)); + var ls = new String(input.AsSpan(0, input.Length < count ? input.Length : count)); isPwd = ls == "pwd"; inputIndex = 0; @@ -299,102 +296,95 @@ namespace UMC.ITME if (request.RawUrl.StartsWith("/UMC.WS/")) { var Path = request.Url.AbsolutePath.Substring(8); - - var ds = request.Cookies.GetValues(WebServlet.SessionCookieName) ?? new string[] { Path }; - if (ds.Length > 0) + Guid dID; + var sttDevice = Path; + if (Path.Contains("/")) { - string secWebSocketKey = request.Headers["Sec-WebSocket-Key"]; - if (String.IsNullOrEmpty(secWebSocketKey) == false) - { - var buffers = System.Buffers.ArrayPool.Shared.Rent(0x200); - Guid dID; + sttDevice = request.Cookies.Get(WebServlet.SessionCookieName); + dID = SiteConfig.MD5Key(sttDevice, Path); + } + else + { + dID = UMC.Data.Utility.Guid(Path, true).Value; + } - if (ds.Any(r => r == Path)) - { - ds[0] = Path; - dID = UMC.Data.Utility.Guid(Path, true).Value; - } - else - { - dID = SiteConfig.MD5Key(String.Join(',', ds), Path); - } - var webr = new UMC.Host.HttpWebSocket(this.Write, dID, this.Dispose); - this.Request = webr; - - var size = secWebSocketKey.WriteBytes(buffers, 0); - size += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11".WriteBytes(buffers, size); - int len = System.Security.Cryptography.SHA1.HashData(buffers.AsSpan(0, size), buffers.AsSpan(size, 24)); - string secWebSocketAcceptString = Convert.ToBase64String(buffers.AsSpan(size, len)); - var writer = new Net.TextWriter(request._context.Write, buffers); - writer.Write($"HTTP/1.1 101 {HttpStatusDescription.Get(101)}\r\n"); - writer.Write("Connection: Upgrade\r\n"); - writer.Write("Upgrade: websocket\r\n"); - writer.Write($"Sec-WebSocket-Accept: {secWebSocketAcceptString}\r\n"); - writer.Write("Server: ITME\r\n\r\n"); - writer.Flush(); - writer.Dispose(); - System.Buffers.ArrayPool.Shared.Return(buffers); - HttpMimeServier.httpMimes.TryRemove(this.Id, out var _); - var devices = Path.Split('/', StringSplitOptions.RemoveEmptyEntries); - if (devices.Length > 1) + string secWebSocketKey = request.Headers["Sec-WebSocket-Key"]; + if (String.IsNullOrEmpty(secWebSocketKey) == false) + { + var buffers = System.Buffers.ArrayPool.Shared.Rent(0x200); + + var webr = new UMC.Host.HttpWebSocket(this.Write, dID, this.Dispose); + this.Request = webr; + + var size = secWebSocketKey.WriteBytes(buffers, 0); + size += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11".WriteBytes(buffers, size); + int len = System.Security.Cryptography.SHA1.HashData(buffers.AsSpan(0, size), buffers.AsSpan(size, 24)); + string secWebSocketAcceptString = Convert.ToBase64String(buffers.AsSpan(size, len)); + var writer = new Net.TextWriter(request._context.Write, buffers); + writer.Write($"HTTP/1.1 101 {HttpStatusDescription.Get(101)}\r\n"); + writer.Write("Connection: Upgrade\r\n"); + writer.Write("Upgrade: websocket\r\n"); + writer.Write($"Sec-WebSocket-Accept: {secWebSocketAcceptString}\r\n"); + writer.Write("Server: ITME\r\n\r\n"); + writer.Flush(); + writer.Dispose(); + System.Buffers.ArrayPool.Shared.Return(buffers); + HttpMimeServier.httpMimes.TryRemove(this.Id, out var _); + var devices = Path.Split('/', StringSplitOptions.RemoveEmptyEntries); + if (devices.Length > 1) + { + var deviceId = Data.Utility.Guid(sttDevice, true).Value; + var session = new Data.Session(deviceId.ToString()); + if (session.Value != null && session.Value.Device == deviceId) { - var deviceId = Data.Utility.Guid(ds[0], true).Value; - var session = new Data.Session(deviceId.ToString()); - if (session.Value != null && session.Value.Device == deviceId) + if (session.Value.IsInRole(UMC.Security.Membership.UserRole)) { - if (session.Value.IsInRole(UMC.Security.Membership.UserRole)) + if (Security.AuthManager.Authorization(session.Value.Identity(), 0, $"WebSSH/{devices[1]}", out var isBiometric) > 0) { - if (Security.AuthManager.Authorization(session.Value.Identity(), 0, $"WebSSH/{devices[1]}", out var isBiometric) > 0) + if (isBiometric && session.Value.BiometricTime == 0) { - if (isBiometric && session.Value.BiometricTime == 0) - { - var seesionKey = UMC.Data.Utility.Guid(session.Value.Device.Value); - var url = $"/Biometric?oauth_callback={Uri.EscapeDataString(request.Url.AbsoluteUri)}&transfer={seesionKey}"; - webr.Send("{\"type\":\"url\",\"value\":" + url + "\"}}"); - } - else + var seesionKey = UMC.Data.Utility.Guid(session.Value.Device.Value); + var url = $"/Biometric?oauth_callback={Uri.EscapeDataString(request.Url.AbsoluteUri)}&transfer={seesionKey}"; + webr.Send("{\"type\":\"url\",\"value\":" + url + "\"}}"); + } + else + { + var device = UMC.Data.HotCache.Get(new Entities.Device { Id = Utility.IntParse(devices[1], 0) }); + if (device != null) { - var device = UMC.Data.HotCache.Get(new Entities.Device { Id = Utility.IntParse(devices[1], 0) }); - if (device != null) - { - var us = UMC.Data.License.GetLicense("WebSSH", 5); - Data.Caches.ICacheSet cacheSet2 = UMC.Data.HotCache.Cache(); - if ((cacheSet2.Count > us.Quantity && us.Quantity > 0) || (us.ExpireTime > 0 && us.ExpireTime < Utility.TimeSpan())) - { - webr.Send("{\"type\":\"license\",\"msg\":\"设备数量超限,请保持合规\"}"); - // return; - webr.Disconnect(); - return; - } - var password = UMC.Data.DataFactory.Instance().Password(SiteConfig.MD5Key(device.Ip, device.Username)); + var us = UMC.Data.License.GetLicense("WebSSH", 5); + Data.Caches.ICacheSet cacheSet2 = UMC.Data.HotCache.Cache(); + if ((cacheSet2.Count > us.Quantity && us.Quantity > 0) || (us.ExpireTime > 0 && us.ExpireTime < Utility.TimeSpan())) + { + webr.Send("{\"type\":\"license\",\"msg\":\"设备数量超限,请保持合规\"}"); + // return; + webr.Disconnect(); + return; + } + var password = UMC.Data.DataFactory.Instance().Password(SiteConfig.MD5Key(device.Ip, device.Username)); - var ssh = new SshClient(device.Ip, device.Port ?? 22, device.Username, password); + var ssh = new SshClient(device.Ip, device.Port ?? 22, device.Username, password); - var _QueryString = System.Web.HttpUtility.ParseQueryString(request.Url.Query); - webr.Send("{\"type\":\"device\",\"value\":\"" + Utility.Guid(dID) + "\"}"); + var _QueryString = System.Web.HttpUtility.ParseQueryString(request.Url.Query); + webr.Send("{\"type\":\"device\",\"value\":\"" + Utility.Guid(dID) + "\"}"); - this.SSH(ssh, webr, device, _QueryString, session.Value.Username); - return; + this.SSH(ssh, webr, device, _QueryString, session.Value.Username); + return; - } } } } - } - } - var lic = UMC.Data.License.GetLicense("UserSession", 1000); - Data.Caches.ICacheSet cacheSet = UMC.Data.HotCache.Cache(); - if ((cacheSet.Count > lic.Quantity && lic.Quantity > 0) || (lic.ExpireTime > 0 && lic.ExpireTime < Utility.TimeSpan())) - { - webr.Send("{\"msg\":\"会话规模超限,请保持合规\"}"); } } - else + var lic = UMC.Data.License.GetLicense("UserSession", 1000); + + Data.Caches.ICacheSet cacheSet = UMC.Data.HotCache.Cache(); + if ((cacheSet.Count > lic.Quantity && lic.Quantity > 0) || (lic.ExpireTime > 0 && lic.ExpireTime < Utility.TimeSpan())) { - OutText(403, "not validate websocket headers"); + webr.Send("{\"msg\":\"会话规模超限,请保持合规\"}"); } } else diff --git a/Mime/HttpMimeRequest.cs b/Mime/HttpMimeRequest.cs index 2fe0699..c25368b 100644 --- a/Mime/HttpMimeRequest.cs +++ b/Mime/HttpMimeRequest.cs @@ -107,7 +107,7 @@ namespace UMC.ITME var start = offset; var host = ""; var scheme = _context.Scheme; - for (var ci = 0; ci < size - 2; ci++) + for (var ci = 1; ci < size - 2; ci++) { var index = ci + offset; @@ -423,7 +423,7 @@ namespace UMC.ITME { while (this._body.TryDequeue(out var d)) { - _readData(d.Item1, 0, d.Item2); + readData(d.Item1, 0, d.Item2); ArrayPool.Shared.Return(d.Item1); } diff --git a/Mime/HttpsMimeSocket.cs b/Mime/HttpsMimeSocket.cs index f13981b..d475af9 100644 --- a/Mime/HttpsMimeSocket.cs +++ b/Mime/HttpsMimeSocket.cs @@ -111,10 +111,9 @@ public class HttpsMimeSocket : HttpMime } } - catch + catch (Exception ex) { - // this.Dispose(); - // return; + Utility.Error("Http", ex.ToString()); } this.Dispose(); diff --git a/Program.cs b/Program.cs index 624e683..de0cda3 100644 --- a/Program.cs +++ b/Program.cs @@ -508,11 +508,11 @@ namespace UMC.ITME UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SettingsFlow()); UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemFlow()); UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemSetupActivity()); - UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemCellActivity()); - UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemImageActivity()); - UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemLinkActivity()); - UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemPictureActivity()); - UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemResourceActivity()); + // UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemCellActivity()); + // UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemImageActivity()); + // UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemLinkActivity()); + // UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemPictureActivity()); + // UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SystemResourceActivity()); UMC.Web.WebClient.Register(() => new UMC.ITME.Activities.SiteScanningActivity()); UMC.Web.WebClient.Register(() => new UMC.ITME.HttpBridgeActivity()); UMC.Web.WebClient.Register(() => new UMC.Web.Activities.SettingsAreaActivity()); diff --git a/Proxy/HttpProxy.cs b/Proxy/HttpProxy.cs index 086948a..871c346 100644 --- a/Proxy/HttpProxy.cs +++ b/Proxy/HttpProxy.cs @@ -2925,7 +2925,7 @@ namespace UMC.ITME logs[logSize++] = "Referrer"; logs[logSize++] = context.UrlReferrer?.AbsoluteUri; - + if (String.IsNullOrEmpty(account) == false) { logs[logSize++] = "Account"; @@ -4192,6 +4192,29 @@ namespace UMC.ITME } WebServlet.WebHeaderConf(webr, this.Site, this.Context, this.SiteCookie.Account); + var host2 = this.Site.Site.Host; + if (String.IsNullOrEmpty(host2) == false) + { + var port = webr.Address.Port; + if (String.Equals(host2, "*")) + { + host2 = this.Context.Url.Authority; + } + else + { + switch (port) + { + case 80: + case 443: + break; + default: + host2 = String.Format("{0}:{1}", host2, port); + break; + } + } + webr.Headers[System.Net.HttpRequestHeader.Host] = host2; + } + webr.Timeout = (this.Site.Site.Timeout ?? 10) * 1000; return webr; } diff --git a/Proxy/SiteConfig.cs b/Proxy/SiteConfig.cs index 945f205..bcc0275 100644 --- a/Proxy/SiteConfig.cs +++ b/Proxy/SiteConfig.cs @@ -194,7 +194,7 @@ namespace UMC.ITME for (var i = 0; i < dom.Length; i++) { var v = dom[i].Trim(); - if (String.IsNullOrEmpty(v) == false) + if (String.IsNullOrEmpty(v) == false && v.StartsWith("#") == false) { var valueIndex = v.IndexOf('~'); if (valueIndex > 0) @@ -709,7 +709,7 @@ namespace UMC.ITME else { - if (String.IsNullOrEmpty(this.Site.Host) == false) + if (String.IsNullOrEmpty(this.Site.Host) == false && this.Site.Host != "*") { url = url.Replace(new UMCUri(url).Host, this.Site.Host); } @@ -742,7 +742,7 @@ namespace UMC.ITME } var hostPage = new HashSet>(new EqualityComparer()); // hostPage.TryGetValue - if (String.IsNullOrEmpty(sConf) == false) + if (String.IsNullOrEmpty(sConf) == false && sConf.StartsWith("#") == false) { foreach (var k in sConf.Split('\n')) { @@ -1089,7 +1089,7 @@ namespace UMC.ITME var saticPagePath = new HashSet>(new EqualityComparer()); Dictionary>> subs = new System.Collections.Generic.Dictionary>>(); - if (String.IsNullOrEmpty(sConf) == false) + if (String.IsNullOrEmpty(sConf) == false && sConf.StartsWith("#") == false) { foreach (var k in sConf.Split(',', ' ', '\t', '\n')) @@ -1186,7 +1186,7 @@ namespace UMC.ITME { var saticPagePath = new HashSet(); - if (String.IsNullOrEmpty(sConf) == false) + if (String.IsNullOrEmpty(sConf) == false && sConf.StartsWith("#") == false) { foreach (var k in sConf.Split(',', ' ', '\t', '\n')) diff --git a/Proxy/SiteSSHActivities.cs b/Proxy/SiteSSHActivities.cs index da32091..89cdf43 100644 --- a/Proxy/SiteSSHActivities.cs +++ b/Proxy/SiteSSHActivities.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO.Compression; -// using System.Net; using System; using System.Linq; using UMC.SshNet; @@ -256,9 +255,10 @@ class SiteSSHActivities : Web.WebActivity pathUI.Add(desc); } ui.UIFootBar = new UIFootBar() { IsFixed = true }; + ui.UIFootBar.AddIcon(new UIEventText('\uf122', "展开").Click(new UIClick(request, g, "Open"))); ui.UIFootBar.AddIcon(new UIEventText('\uf0ee', "上传").Click(new UIClick(request, g, "UploadFile"))); - ui.UIFootBar.AddText(new UIEventText("新建目录").Click(new UIClick(request, g, "New")), - new UIEventText("终端打开").Click(new UIClick(request, g, "Open")).Style(new UIStyle().BgColor())); + ui.UIFootBar.AddText(new UIEventText("新建文件").Click(new UIClick(request, g, "NewFile")), + new UIEventText("新建目录").Click(new UIClick(request, g, "New")).Style(new UIStyle().BgColor())); ui.SendTo($"OpenPath,UploadFile,{request.Model}.{request.Command}.Remove", this.Context, true, $"{request.Model}.{request.Command}"); @@ -449,7 +449,7 @@ class SiteSSHActivities : Web.WebActivity s.Put(new UIClick("Event", new WebMeta().UIEvent("UI.Callback", ui, new WebMeta().Put("type", "Keyboard", "value", "\u001b[A"))) { Text = "↑" }); s.Put(new UIClick("Event", new WebMeta().UIEvent("UI.Callback", ui, new WebMeta().Put("type", "Keyboard", "value", "\u0003"))) { Text = "Ctrl + C" }); s.Put(new UIClick("Event", new WebMeta().UIEvent("UI.Callback", ui, new WebMeta().Put("type", "Keyboard", "value", "\u001b[D"))) { Text = "←" }); - s.Put(new UIClick("CaseCMS", new UIClick(request)) { Text = "粘贴" }); + s.Put(new UIClick("Paste", new UIClick(request)) { Text = "粘贴" }); // s.Put(new UIClick("Event", new WebMeta().UIEvent("UI.Refresh", ui, new WebMeta().Put("type", "Keyboard", "value", "\t"))) { Text = "刷新" }); s.Put(new UIClick("Event", new WebMeta().UIEvent("UI.Callback", ui, new WebMeta().Put("type", "Keyboard", "value", "\u001b[C"))) { Text = "→" }); @@ -476,6 +476,14 @@ class SiteSSHActivities : Web.WebActivity this.Context.Send(true); } break; + case "NewFile": + { + var filePath = String.Format("{0}{1}", Path, Path.EndsWith('/') ? "" : "/"); + var dir = this.AsyncDialog("FileName", r => new UITextDialog() { Title = "新建文件名" }); + request.Arguments["Path"] = filePath + dir; + this.Context.Send("Markdown", new WebMeta().Put("submit", new UIClick(request, "Model", "Content")), true); + } + break; case "Download": response.Redirect(new Uri(request.Url, $"/WebSSH/{device.Id}{Path}")); break; @@ -486,7 +494,7 @@ class SiteSSHActivities : Web.WebActivity case "View": this.AsyncDialog("View", r => { - var value = UIClick.Markdown(new UIClick(request, "Model", "Content")); value.Text = "编辑"; + var value = UIClick.Markdown(new UIClick(request, "Model", "Content")); value.Text = "内容查看"; var s = new UISheetDialog() { Title = "文件选择" }; s.Put(new UIClick(new Uri(request.Url, $"/WebSSH/{device.Id}{Path}").AbsoluteUri) { Key = "Url", Text = "下载" }); if (model == "View") @@ -507,15 +515,18 @@ class SiteSSHActivities : Web.WebActivity { s = sftp.ReadAllText(Path); } - catch (Exception ex) + catch //(Exception ex) { - this.Prompt("打开失败", ex.Message); + // this.Prompt("打开失败", ex.Message); } response.Redirect(new WebMeta().Put("Content", s).Put("title", Path)); }); - sftp.DeleteFile(Path); + if (sftp.Exists(Path)) + { + sftp.DeleteFile(Path); + } sftp.WriteAllText(Path, Content); SSHLog(device, this.Context.Token.Username, $"write {Path}"); @@ -595,8 +606,13 @@ class SiteSSHActivities : Web.WebActivity using (var stm = f.Open()) { + var file = filePath + f.FullName; var now = Utility.TimeSpan(); - sftp.UploadFile(stm, filePath + f.FullName, true, (v) => + if (sftp.Exists(file)) + { + sftp.DeleteFile(file); + } + sftp.UploadFile(stm, file, true, (v) => { if (deviceKey.HasValue) { @@ -617,8 +633,13 @@ class SiteSSHActivities : Web.WebActivity { using (var s = System.IO.File.OpenRead(filename)) { + var file = filePath + name; var now = Utility.TimeSpan(); - sftp.UploadFile(s, filePath + name, true, (v) => + if (sftp.Exists(file)) + { + sftp.DeleteFile(file); + } + sftp.UploadFile(s, file, true, (v) => { if (deviceKey.HasValue) { diff --git a/Proxy/SiteServerActivity.cs b/Proxy/SiteServerActivity.cs index 8c34e3f..809e9c4 100644 --- a/Proxy/SiteServerActivity.cs +++ b/Proxy/SiteServerActivity.cs @@ -298,41 +298,43 @@ namespace UMC.ITME.Activities }); // var certs = UMC.Data.Reflection.Configuration("certs"); + var Domain = httpPorts2["Domain"]; + var publicKey = httpPorts2["publicKey"]; + var privateKey = httpPorts2["privateKey"]; + X509Certificate2 x509 = null; try { - var Domain = httpPorts2["Domain"]; - var publicKey = httpPorts2["publicKey"]; - var privateKey = httpPorts2["privateKey"]; - var x509 = X509Certificate2.CreateFromPem(publicKey, privateKey); - if (x509.NotAfter < DateTime.Now) - { - x509.Dispose(); - this.Prompt("此证书已过期"); - } + x509 = X509Certificate2.CreateFromPem(publicKey, privateKey); - HotCache.Put(new Entities.SiteCert - { - Domain = Domain, - IsApiumc = true, - ExpirationTime = Utility.TimeSpan(x509.NotAfter), - CheckTime = Utility.TimeSpan(), - PrivateKey = publicKey, - PublicKey = privateKey - }); - - - Certificater.Certificates[Domain] = new Certificater - { - Name = Domain, - Certificate = x509 - }; - // UMC.Data.Reflection.Configuration("certs", certs); - this.Context.Send($"{request.Model}.{request.Command}.Cert", true); } catch { this.Prompt("证书不正确"); } + if (x509.NotAfter < DateTime.Now) + { + x509.Dispose(); + this.Prompt("此证书已过期"); + } + + + HotCache.Put(new Entities.SiteCert + { + Domain = Domain, + IsApiumc = true, + ExpirationTime = Utility.TimeSpan(x509.NotAfter), + CheckTime = Utility.TimeSpan(), + PrivateKey = privateKey, + PublicKey = publicKey + }); + + + Certificater.Certificates[Domain] = new Certificater + { + Name = Domain, + Certificate = x509 + }; + this.Context.Send($"{request.Model}.{request.Command}", true); break; } case "Del": @@ -401,10 +403,7 @@ namespace UMC.ITME.Activities } else if (string.Equals(hs["code"], "completed")) { - // if (Certificater.Certificates.TryGetValue(host, out var _cert) == false || _cert.Certificate == null) - // { webr2.Post(new WebMeta().Put("type", "cert", "domain", host), UMC.ITME.Utility.Certificate); - // } this.Prompt(hs["msg"]); } else if (string.Equals(hs["code"], "verifing")) diff --git a/Proxy/Utility.cs b/Proxy/Utility.cs index a0cf1d5..fd56420 100644 --- a/Proxy/Utility.cs +++ b/Proxy/Utility.cs @@ -15,7 +15,7 @@ namespace UMC.ITME class WebResource : UMC.Data.WebResource { - public override void Push(Guid tid, params object[] objs) + public override void Push(Uri uri, Guid tid, params object[] objs) { var str = JSON.Serialize(objs); var device = Utility.Guid(tid); @@ -40,7 +40,8 @@ namespace UMC.ITME } } public class Utility : UMC.Data.Utility - { public static String MD5(System.Guid guid) + { + public static String MD5(System.Guid guid) { using (var md5 = System.Security.Cryptography.MD5.Create()) { diff --git a/Proxy/WebServlet.cs b/Proxy/WebServlet.cs index d24f8c9..0dd9968 100644 --- a/Proxy/WebServlet.cs +++ b/Proxy/WebServlet.cs @@ -112,7 +112,6 @@ namespace UMC.ITME var seesionKey = UMC.Data.Utility.Guid(context.Token.Device.Value); var url = $"/Biometric?oauth_callback={Uri.EscapeDataString(context.Url.AbsoluteUri)}&transfer={seesionKey}"; context.Redirect(url); - // context.Redirect($"/Biometric?oauth_callback={Uri.EscapeDataString(context.Url.PathAndQuery)}"); } else { @@ -162,7 +161,6 @@ namespace UMC.ITME } else { - Error(context, "ITME Web SSH", "没有此设备资源,请联系管理员"); } } @@ -1247,12 +1245,21 @@ namespace UMC.ITME context.Output.Write("UMC.UI.Config({possrc:'"); context.Output.Write("/UMC.'"); - var domain = Data.WebResource.Instance().WebDomain(); + var webr = Data.WebResource.Instance(); + var domain = webr.WebDomain(); context.Output.Write(",posurl: '"); var host2 = context.Url.Host; if (host2.Contains(domain)) { - context.Output.Write($"{context.Url.Scheme}://{domain}/UMC.Core/"); + var auth = webr.Provider["auth"]; + if (String.IsNullOrEmpty(auth)) + { + context.Output.Write($"{context.Url.Scheme}://{domain}/UMC.Core/"); + } + else + { + context.Output.Write($"{context.Url.Scheme}://{auth}.{domain}/UMC.Core/"); + } } else @@ -1264,9 +1271,18 @@ namespace UMC.ITME { if (String.Equals("localhost", domain) == false) { - if (host2.EndsWith(domain) && host2.Length > domain.Length) + var auth = webr.Provider["auth"]; + if (String.IsNullOrEmpty(auth)) { context.Output.Write(",'domain':'{0}://{1}'", context.Url.Scheme, domain); + } + else + { + context.Output.Write(",'domain':'{0}://{1}.{2}'", context.Url.Scheme, auth, domain); + } + if (host2.EndsWith(domain) && host2.Length > domain.Length) + { + var sroot = host2.Substring(0, host2.Length - domain.Length - 1); var psite2 = UMC.ITME.DataFactory.Instance().SiteConfig(sroot); @@ -1277,12 +1293,6 @@ namespace UMC.ITME context.Output.Write(",'title':{0}", UMC.Data.JSON.Serialize(psite2.Caption)); } } - else - { - - context.Output.Write(",'domain':'{0}://{1}'", context.Url.Scheme, domain); - - } } } context.Output.WriteLine("});"); @@ -1535,7 +1545,9 @@ namespace UMC.ITME } if (siteConfig != null) { + Proxy(context, siteConfig, pfxDomain, rawUrl); + return; } @@ -2058,13 +2070,11 @@ namespace UMC.ITME context.Tag = WebTransfer(siteConfig, context, RawUrl); return; } - // var startTime = UMC.Data.Reflection.TimeSpanMilli(DateTime.Now); + NameValueCollection resHeaders = null; String _attachmentFile = null; context.UseSynchronousIO(() => { - // var duration = (int)(UMC.Data.Reflection.TimeSpanMilli(DateTime.Now) - startTime); - HttpProxy.LogWrite(context, siteConfig, String.Empty, resHeaders, _attachmentFile); }); @@ -2372,6 +2382,7 @@ namespace UMC.ITME } } } + context.Token = this.AccessToken(context); if (psite.IsClose) { if (psite.Site.Flag < 0 || psite.Domains.Length == 0 || String.IsNullOrEmpty(psite.Site.MarketKey)) @@ -2381,20 +2392,24 @@ namespace UMC.ITME else { - Error(context, "市场应用已过期", "市场应用已经过期,请联系管理员更新许可证", ""); + Error(context, $"{psite.Caption}应用已过期", "市场应用已经过期,请联系管理员更新许可证", ""); } return; } + else if (psite.AllowAllPath) + { + this.Transfer(psite, context, rawUrl); + + return; + } var indexPath = rawUrl.IndexOf('?'); var path = indexPath > 0 ? rawUrl.Substring(0, indexPath) : rawUrl; - if (psite.AllowAllPath || String.Equals(context.HttpMethod, "OPTIONS") || IsAllowPath(path, pfxDomain, psite)) + if (String.Equals(context.HttpMethod, "OPTIONS") || IsAllowPath(path, pfxDomain, psite)) { - - context.Token = new UMC.Data.AccessToken(Guid.Empty).Login(new UMC.Security.Guest(Guid.Empty), 0);// this.AccessToken(context); if (psite.IsFile) { this.StaticFile(psite, psite.Domains[0].Substring(7), context, rawUrl); @@ -2419,7 +2434,6 @@ namespace UMC.ITME } var IsAuth = false; var isBiometric = false; - context.Token = this.AccessToken(context); var user = context.Token.Identity(); switch (psite.Site.AuthType ?? Web.WebAuthType.User) diff --git a/UMC.ITME.csproj b/UMC.ITME.csproj index 2fc3ef9..fd453d1 100644 --- a/UMC.ITME.csproj +++ b/UMC.ITME.csproj @@ -42,10 +42,10 @@ - + - +