优化DNS

main
吴顺明 1 year ago
parent 6aa1b11a76
commit 4c2f737caa

@ -9,7 +9,6 @@ namespace UMC.Host
public abstract class HttpMime : IDisposable
{
// int pid = 0;
public abstract int Id { get; }
public int ActiveTime
{
@ -17,7 +16,7 @@ namespace UMC.Host
get; set;
}
public int TimeOut { protected set; get; } = 20;
// public int TimeOut
public virtual string Scheme => "http";
public abstract void OutputFinish();
public abstract void Write(byte[] buffer, int offset, int count);

@ -1,4 +1,5 @@
using System;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Net.Security;
@ -17,7 +18,7 @@ namespace UMC.Host
class HttpsWebSocket : WebSocket
{
public byte[] buffer = System.Buffers.ArrayPool<byte>.Shared.Rent(0x600);//new byte[0x600];
public byte[] buffer = System.Buffers.ArrayPool<byte>.Shared.Rent(0x600);
System.IO.Stream stream;
public HttpsWebSocket(HttpMime mime, System.IO.Stream stream)
{
@ -25,9 +26,9 @@ namespace UMC.Host
this.stream = stream;
WebSocketRead();
}
public override void Receive(byte[] buffer, int offset, int size)
public override async void Receive(byte[] buffer, int offset, int size)
{
stream.Write(buffer, offset, size);
await stream.WriteAsync(buffer, offset, size);
}
HttpMime mime1;
@ -38,10 +39,11 @@ namespace UMC.Host
{
while ((size = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
// var
mime1.Write(buffer, 0, size);
}
}
catch // (Exception ex)
catch
{
this.Dispose();
return;
@ -79,7 +81,10 @@ namespace UMC.Host
SocketAsyncEventArgs eventArgs = new SocketAsyncEventArgs();
eventArgs.SetBuffer(buffer);
eventArgs.Completed += Http;
this.socket.ReceiveAsync(eventArgs);
if (!this.socket.ReceiveAsync(eventArgs))
{
ProcessReceive(eventArgs);
}
}
HttpMime mime;
@ -116,10 +121,9 @@ namespace UMC.Host
}
}
public override void Receive(byte[] buffer, int offset, int size)
public override async void Receive(byte[] buffer, int offset, int size)
{
socket.Send(buffer, offset, size, SocketFlags.None);
await socket.SendAsync(new ArraySegment<byte>(buffer, offset, size), SocketFlags.None);
}
protected override void Header(byte[] data, int offset, int size)
{
@ -166,9 +170,6 @@ namespace UMC.Host
{
ProcessReceive(eventArgs);
}
}
Socket _socket;
int pid = 0;
@ -313,28 +314,66 @@ namespace UMC.Host
var client = new Socket(SocketType.Stream, ProtocolType.Tcp);
await client.ConnectAsync(url.Host, url.Port);
await client.ConnectAsync(await NetProxy.DNS(url.Host), url.Port);
// await client.ConnectAsync(url.Host, url.Port);
if (url.Scheme == "https")
{
SslStream ssl = new SslStream(new NetworkStream(client, true), false, (sender, certificate, chain, sslPolicyErrors) => true);
await ssl.AuthenticateAsClientAsync(url.Host, null, SslProtocols.None, false);
var ws = new HttpsWebSocket(this, ssl);
var size = UMC.Net.NetHttpResponse.Header(webRequest, ws.buffer);//
request = ws;
await ssl.WriteAsync(ws.buffer, 0, size);
_webSocket = ws;
await ssl.WriteAsync(_data, 0, UMC.Net.NetHttpResponse.Header(webRequest, _data));
int size = await ssl.ReadAsync(_data, 0, _data.Length);
if (NetBridge.ResponseHeader(_data, 0, size, new NameValueCollection(), out var statucode) && statucode == HttpStatusCode.SwitchingProtocols)
{
request = _webSocket = new HttpsWebSocket(this, ssl);
this._socket.Send(_data, 0, size, SocketFlags.None);
}
else
{
this._socket.Send(_data, 0, size, SocketFlags.None);
this.Dispose();
}
}
else
{
var ws = new HttpWebSocket(this, client);
request = _webSocket;
client.Send(ws.buffer, 0, UMC.Net.NetHttpResponse.Header(webRequest, ws.buffer), SocketFlags.None);
_webSocket = ws;
client.Send(_data, 0, UMC.Net.NetHttpResponse.Header(webRequest, _data), SocketFlags.None);
var size = client.Receive(_data, 0, _data.Length, SocketFlags.None);
if (NetBridge.ResponseHeader(_data, 0, size, new NameValueCollection(), out var statucode) && statucode == HttpStatusCode.SwitchingProtocols)
{
request = _webSocket = new HttpWebSocket(this, client);
this._socket.Send(_data, 0, size, SocketFlags.None);
}
else
{
this._socket.Send(_data, 0, size, SocketFlags.None);
this.Dispose();
}
}
// if (url.Scheme == "https")
// {
// SslStream ssl = new SslStream(new NetworkStream(client, true), false, (sender, certificate, chain, sslPolicyErrors) => true);
// await ssl.AuthenticateAsClientAsync(url.Host, null, SslProtocols.None, false);
// var ws = new HttpsWebSocket(this, ssl);
// var size = UMC.Net.NetHttpResponse.Header(webRequest, ws.buffer);//
// request = ws;
// await ssl.WriteAsync(ws.buffer, 0, size);
// _webSocket = ws;
// }
// else
// {
// var ws = new HttpWebSocket(this, client);
// request = _webSocket;
// client.Send(ws.buffer, 0, UMC.Net.NetHttpResponse.Header(webRequest, ws.buffer), SocketFlags.None);
// _webSocket = ws;
// }
HttpMimeServier.httpMimes.TryRemove(this.pid, out var _);
}
catch (Exception ex)

@ -2,6 +2,7 @@ using System.Net.WebSockets;
namespace UMC.Host;
using System;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Net.Security;
@ -37,14 +38,14 @@ public class HttpsMimeSocket : HttpMime
public override String Host => _Host;
public override String RemoteIpAddress => _remoteIpAddress;
public override void Write(byte[] buffer, int offset, int count)
public override async void Write(byte[] buffer, int offset, int count)
{
if (isDispose == false)
{
try
{
_stream.Write(buffer, offset, count);
await _stream.WriteAsync(buffer, offset, count);
}
catch
{
@ -115,25 +116,64 @@ public class HttpsMimeSocket : HttpMime
var client = new Socket(SocketType.Stream, ProtocolType.Tcp);
await client.ConnectAsync(url.Host, url.Port);
// await client.ConnectAsync(url.Host, url.Port);
await client.ConnectAsync(await NetProxy.DNS(url.Host), url.Port);
// if (url.Scheme == "https")
// {
// SslStream ssl = new SslStream(new NetworkStream(client, true), false, (sender, certificate, chain, sslPolicyErrors) => true);
// await ssl.AuthenticateAsClientAsync(url.Host, null, SslProtocols.None, false);
// var ws = new HttpsWebSocket(this, ssl);
// var size = UMC.Net.NetHttpResponse.Header(webRequest, ws.buffer);//
// request = ws;
// await ssl.WriteAsync(ws.buffer, 0, size);
// _webSocket = ws;
// }
// else
// {
// var ws = new HttpWebSocket(this, client);
// request = _webSocket;
// client.Send(ws.buffer, 0, UMC.Net.NetHttpResponse.Header(webRequest, ws.buffer), SocketFlags.None);
// _webSocket = ws;
// }
if (url.Scheme == "https")
{
SslStream ssl = new SslStream(new NetworkStream(client, true), false, (sender, certificate, chain, sslPolicyErrors) => true);
await ssl.AuthenticateAsClientAsync(url.Host, null, SslProtocols.None, false);
var ws = new HttpsWebSocket(this, ssl);
request = ws;
await ssl.WriteAsync(ws.buffer, 0, UMC.Net.NetHttpResponse.Header(webRequest, ws.buffer));
_webSocket = ws;
await ssl.WriteAsync(_data, 0, UMC.Net.NetHttpResponse.Header(webRequest, _data));
int size = await ssl.ReadAsync(_data, 0, _data.Length);
if (NetBridge.ResponseHeader(_data, 0, size, new NameValueCollection(), out var statucode) && statucode == HttpStatusCode.SwitchingProtocols)
{
request = _webSocket = new HttpsWebSocket(this, ssl);
this._stream.Write(_data, 0, size);
}
else
{
this._stream.Write(_data, 0, size);
this.Dispose();
}
}
else
{
var ws = new HttpWebSocket(this, client);
request = ws;
client.Send(ws.buffer, 0, UMC.Net.NetHttpResponse.Header(webRequest, ws.buffer), SocketFlags.None);
_webSocket = ws;
client.Send(_data, 0, UMC.Net.NetHttpResponse.Header(webRequest, _data), SocketFlags.None);
var size = client.Receive(_data, 0, _data.Length, SocketFlags.None);
if (NetBridge.ResponseHeader(_data, 0, size, new NameValueCollection(), out var statucode) && statucode == HttpStatusCode.SwitchingProtocols)
{
request = _webSocket = new HttpWebSocket(this, client);
this._stream.Write(_data, 0, size);
}
else
{
this._stream.Write(_data, 0, size);
this.Dispose();
}
}

@ -11,6 +11,7 @@ using System.IO.Pipes;
using System.Runtime.InteropServices;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
[assembly: UMC.Web.Mapping]
namespace UMC.Host
@ -20,6 +21,8 @@ namespace UMC.Host
public static void Main(string[] args)
{
var ipHost = Dns.GetHostAddresses("blj.sau.edu.cn");
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
var variable = System.Environment.GetEnvironmentVariable("UMC");

File diff suppressed because it is too large Load Diff

@ -6,7 +6,6 @@ using UMC.Data.Entities;
using UMC.Proxy.Entities;
using System.IO;
using UMC.Data;
using System.Text.RegularExpressions;
namespace UMC.Proxy.Activities
{
@ -69,7 +68,7 @@ namespace UMC.Proxy.Activities
sts.Rows.Add("发布新应用", "Add", "javascript:void(0)",
"/css/images/icon/add.png", "max", "", true);
}
var keys = new List<String>();
@ -132,9 +131,28 @@ namespace UMC.Proxy.Activities
}
}
var IsAuth = false;
switch (d.AuthType ?? Web.WebAuthType.User)
{
case Web.WebAuthType.Admin:
if (user.IsInRole(UMC.Security.Membership.AdminRole))
{
IsAuth = true;
}
else if (UMC.Data.DataFactory.Instance().Roles(user.Id.Value, d.SiteKey.Value).Contains(UMC.Security.Membership.AdminRole))
{
IsAuth = true;
}
break;
default:
IsAuth = true;
break;
}
sts.Rows.Add(title.Trim(), d.Root, strUrl, webr.ImageResolve(d.Root, "1", 4, $"_t={d.ModifyTime}"), target, badge, isDesktop);
if (IsAuth)
{
sts.Rows.Add(title.Trim(), d.Root, strUrl, webr.ImageResolve(d.Root, "1", 4, $"_t={d.ModifyTime}"), target, badge, isDesktop);
}
}
}
if (String.IsNullOrEmpty(UMC.Data.WebResource.Instance().Provider["appId"]))

@ -516,14 +516,17 @@ namespace UMC.Proxy
{
var mv = v.Substring(nindex + 1).Trim();
var key = v.Substring(0, nindex).Trim();
switch (key.ToLower())
if (String.IsNullOrEmpty(mv) == false && String.IsNullOrEmpty(key) == false)
{
case "content-type":
this.ContentType = mv;
break;
default:
_HeaderConf[key] = mv;
break;
switch (key.ToLower())
{
case "content-type":
this.ContentType = mv;
break;
default:
_HeaderConf[key] = mv;
break;
}
}
}

@ -1,4 +1,5 @@
using System;
using System.Reflection.Emit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -82,6 +83,13 @@ namespace UMC.Proxy.Activities
}
}
var ks = Key.Split('_');
var typeKey = String.Empty;
if (ks.Length == 2)
{
typeKey = ks[1].ToUpper();
}
var Model = this.AsyncDialog("Model", g =>
{
@ -93,18 +101,17 @@ namespace UMC.Proxy.Activities
var ui = UISection.Create(title);
if (mainKey.EndsWith("_LOGIN"))
{
title.Title = "登录接口";
}
else if (mainKey.EndsWith("_UPDATE"))
switch (typeKey)
{
title.Title = "密码托管接口";
}
else if (mainKey.EndsWith("_CHECK"))
{
title.Title = "账户检测接口";
case "LOGIN":
title.Title = "登录接口";
break;
case "UPDATE":
title.Title = "密码托管接口";
break;
case "CHECK":
title.Title = "账户检测接口";
break;
}
var Method = value["Method"] as string;
@ -155,126 +162,134 @@ namespace UMC.Proxy.Activities
var content = value["Content"] as string;
ui.NewSection().AddCell("提交内容", String.IsNullOrEmpty(content) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "Content")).Post(request.Model, request.Command));
}
else if (mainKey.EndsWith("_LOGIN") == false && mainKey.EndsWith("_UPDATE") == false && mainKey.EndsWith("_CHECK") == false)
{
var content = value["Content"] as string;
// }
// else if (mainKey.EndsWith("_LOGIN") == false && mainKey.EndsWith("_UPDATE") == false && mainKey.EndsWith("_CHECK") == false)
// {
// var content = value["Content"] as string;
ui.NewSection().AddCell("脚本环境", String.IsNullOrEmpty(content) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "Content")).Post(request.Model, request.Command));
// ui.NewSection().AddCell("脚本环境", String.IsNullOrEmpty(content) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "Content")).Post(request.Model, request.Command));
}
if (mainKey.EndsWith("_LOGIN") || mainKey.EndsWith("_UPDATE") || mainKey.EndsWith("_CHECK"))
switch (typeKey)
{
var Finish = value["Finish"] as string;
var root = Key.Substring(0, Key.LastIndexOf('_'));
case "LOGIN":
case "UPDATE":
case "CHECK":
var Finish = value["Finish"] as string;
var root = Key.Substring(0, Key.LastIndexOf('_'));
ui.NewSection().AddCell("检测格式", String.IsNullOrEmpty(Finish) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "Finish")).Post(request.Model, request.Command));
ui.NewSection().AddCell("检测格式", String.IsNullOrEmpty(Finish) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "Finish")).Post(request.Model, request.Command));
var fui = ui.NewSection();
fui.AddCell("扩展字段", "新增", new UIClick(new WebMeta(request.Arguments).Put(g, "Feilds")).Post(request.Model, request.Command));
var feilds = value["Feilds"] as Hashtable;
if (feilds != null && feilds.Count > 0)
{
var fd = feilds.Keys.Cast<String>().OrderBy(r => r).GetEnumerator();
while (fd.MoveNext())
var fui = ui.NewSection();
fui.AddCell("扩展字段", "新增", new UIClick(new WebMeta(request.Arguments).Put(g, "Feilds")).Post(request.Model, request.Command));
var feilds = value["Feilds"] as Hashtable;
if (feilds != null && feilds.Count > 0)
{
var cell = new WebMeta().Put("value", fd.Current).Put("text", feilds[fd.Current]);
var fd = feilds.Keys.Cast<String>().OrderBy(r => r).GetEnumerator();
cell.Put("click", new UIClick(new WebMeta().Put("Key", Key + "_" + fd.Current)).Post(request.Model, request.Command));
while (fd.MoveNext())
{
var cell = new WebMeta().Put("value", fd.Current).Put("text", feilds[fd.Current]);
cell.Put("click", new UIClick(new WebMeta().Put("Key", Key + "_" + fd.Current)).Post(request.Model, request.Command));
var uICell = UICell.Create("Cell", cell);
if (fd.Current == "LoginAfter")
{
uICell.Style.Name("value").Color(0xff4949);
// uICell.Style.Name("text").Color(0xff4949);
}
fui.Delete(uICell, new UIEventText("移除").Click(new UIClick(new WebMeta(request.Arguments).Put(g, fd.Current)).Post(request.Model, request.Command)));
fui.Delete(UICell.Create("Cell", cell), new UIEventText("移除").Click(new UIClick(new WebMeta(request.Arguments).Put(g, fd.Current)).Post(request.Model, request.Command)));
}
}
}
if (mainKey.EndsWith("_LOGIN"))
{
ui.NewSection().AddCell("登录清空会话", value.ContainsKey("IsNotCookieClear") ? "不清空" : "清空", new UIClick(new WebMeta(request.Arguments).Put(g, "IsNotCookieClear")).Post(request.Model, request.Command));
if (value.ContainsKey("IsLoginHTML"))
switch (typeKey)
{
case "LOGIN":
{
ui.NewSection().AddCell("登录清空会话", value.ContainsKey("IsNotCookieClear") ? "不清空" : "清空", new UIClick(new WebMeta(request.Arguments).Put(g, "IsNotCookieClear")).Post(request.Model, request.Command));
ui.NewSection()
.AddCell("内容转化配置", new UIClick(new WebMeta(request.Arguments).Put(g, "Script")).Post(request.Model, request.Command))
.NewSection().AddCell("前端页面登录", "已启用", new UIClick(new WebMeta(request.Arguments).Put(g, "IsLoginHTML")).Post(request.Model, request.Command))
.AddCell("前端页面内容配置", new UIClick(String.Format("{0}_HTML", mainKey).ToUpper()).Post(request.Model, "Conf"));
if (value.ContainsKey("IsLoginHTML"))
{
ui.NewSection()
.AddCell("内容转化配置", new UIClick(new WebMeta(request.Arguments).Put(g, "Script")).Post(request.Model, request.Command))
.NewSection().AddCell("前端页面登录", "已启用", new UIClick(new WebMeta(request.Arguments).Put(g, "IsLoginHTML")).Post(request.Model, request.Command))
}
else
{
ui.NewSection().AddCell("前端页面登录", "未启用", new UIClick(new WebMeta(request.Arguments).Put(g, "IsLoginHTML")).Post(request.Model, request.Command));
}
.AddCell("前端页面内容配置", new UIClick(String.Format("{0}_HTML", mainKey).ToUpper()).Post(request.Model, "Conf"));
var Callback = value["Callback"] as string;
ui.NewSection().AddCell("跳转参数", String.IsNullOrEmpty(Callback) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "Callback")).Post(request.Model, request.Command));
}
else
{
ui.NewSection().AddCell("前端页面登录", "未启用", new UIClick(new WebMeta(request.Arguments).Put(g, "IsLoginHTML")).Post(request.Model, request.Command));
}
}
else if (mainKey.EndsWith("_UPDATE"))
{
var UpdateModel = value["UpdateModel"] as String ?? "Selected";
switch (UpdateModel)
{
case "Selected":
UpdateModel = "默认选中";
break;
case "Select":
UpdateModel = "默认不选中";
break;
case "Compel":
UpdateModel = "强制托管";
break;
case "Disable":
UpdateModel = "禁用托管";
break;
var Callback = value["Callback"] as string;
ui.NewSection().AddCell("跳转参数", String.IsNullOrEmpty(Callback) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "Callback")).Post(request.Model, request.Command));
}
ui.NewSection().AddCell("密码托管模式", UpdateModel, new UIClick(new WebMeta(request.Arguments).Put(g, "UpdateModel")).Post(request.Model, request.Command));
}
break;
case "UPDATE":
{
var UpdateModel = value["UpdateModel"] as String ?? "Selected";
switch (UpdateModel)
{
case "Selected":
UpdateModel = "默认选中";
break;
case "Select":
UpdateModel = "默认不选中";
break;
case "Compel":
UpdateModel = "强制托管";
break;
case "Disable":
UpdateModel = "禁用托管";
break;
}
else if (mainKey.EndsWith("_CHECK"))
{
var site = DataFactory.Instance().Site(root.ToLower());
if (site != null)
{
var userM = "未启用";
switch (site.UserModel ?? UserModel.Standard)
{
case UserModel.Check:
userM = "自主选择";
break;
case UserModel.Checked:
userM = "自动检测";
break;
}
ui.NewSection().AddCell("密码托管模式", UpdateModel, new UIClick(new WebMeta(request.Arguments).Put(g, "UpdateModel")).Post(request.Model, request.Command));
}
ui.NewSection()
.AddCell("功能启用", userM, new UIClick(new WebMeta(request.Arguments).Put(g, "UserModel")).Post(request.Model, request.Command))
.AddCell("检测账户", String.IsNullOrEmpty(site.Account) ? "未设置" : site.Account, new UIClick("Key", site.Root, "Model", "Account").Post(request.Model, "Site"))
.AddCell("检测登录", value.ContainsKey("IsNotLoginApi") ? "不是" : "是", new UIClick(new WebMeta(request.Arguments).Put(g, "IsNotLoginApi")).Post(request.Model, request.Command));
}
break;
case "CHECK":
{
var site = DataFactory.Instance().Site(root.ToLower());
if (site != null)
{
var userM = "未启用";
switch (site.UserModel ?? UserModel.Standard)
{
case UserModel.Check:
userM = "自主选择";
break;
case UserModel.Checked:
userM = "自动检测";
break;
}
ui.NewSection()
.AddCell("功能启用", userM, new UIClick(new WebMeta(request.Arguments).Put(g, "UserModel")).Post(request.Model, request.Command))
.AddCell("检测账户", String.IsNullOrEmpty(site.Account) ? "未设置" : site.Account, new UIClick("Key", site.Root, "Model", "Account").Post(request.Model, "Site"))
.AddCell("检测登录", value.ContainsKey("IsNotLoginApi") ? "不是" : "是", new UIClick(new WebMeta(request.Arguments).Put(g, "IsNotLoginApi")).Post(request.Model, request.Command));
}
}
break;
}
break;
default:
ui.NewSection().AddCell("内容转化配置", new UIClick(new WebMeta(request.Arguments).Put(g, "Script")).Post(request.Model, request.Command));
}
}
else
{
ui.NewSection().AddCell("内容转化配置", new UIClick(new WebMeta(request.Arguments).Put(g, "Script")).Post(request.Model, request.Command));
ui.NewSection().AddCell("记住选择内容", value.ContainsKey("RememberValue") ? "记住" : "不记住", new UIClick(new WebMeta(request.Arguments).Put(g, "RememberValue")).Post(request.Model, request.Command));
var defautValue = value["DefautValue"] as string;
ui.NewSection().AddCell("内容默认值", String.IsNullOrEmpty(defautValue) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "DefautValue")).Post(request.Model, request.Command));
ui.NewSection().AddCell("记住选择内容", value.ContainsKey("RememberValue") ? "记住" : "不记住", new UIClick(new WebMeta(request.Arguments).Put(g, "RememberValue")).Post(request.Model, request.Command));
var defautValue = value["DefautValue"] as string;
ui.NewSection().AddCell("内容默认值", String.IsNullOrEmpty(defautValue) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "DefautValue")).Post(request.Model, request.Command));
break;
}
@ -329,6 +344,7 @@ namespace UMC.Proxy.Activities
from4.AddText("字段标题", "Value", "");
from4.AddText("字段标识", "Name", "");
from4.Submit("确认", "Mime.Config");
from4.AddFooter("当标识为“LoginAfter”表示登录之后请求的网络配置");
return from4;
});
var feilds = value["Feilds"] as Hashtable ?? new Hashtable();

Loading…
Cancel
Save