|
|
|
@ -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<byte>.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<byte>.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<byte>.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<byte>.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<Data.AccessToken>(deviceId.ToString());
|
|
|
|
|
if (session.Value != null && session.Value.Device == deviceId)
|
|
|
|
|
{
|
|
|
|
|
var deviceId = Data.Utility.Guid(ds[0], true).Value;
|
|
|
|
|
var session = new Data.Session<Data.AccessToken>(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<Entities.Device>();
|
|
|
|
|
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<Entities.Device>();
|
|
|
|
|
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<UMC.Data.Entities.Session>();
|
|
|
|
|
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<UMC.Data.Entities.Session>();
|
|
|
|
|
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
|
|
|
|
|