You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Gateway/Proxy/SiteMimeActivity.cs

563 lines
25 KiB
C#

1 year ago
using System.Reflection.Emit;
using System;
2 years ago
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Collections;
using System.Reflection;
using UMC.Web;
using UMC.Data.Entities;
using UMC.Web.UI;
10 months ago
using UMC.ITME.Entities;
2 years ago
10 months ago
namespace UMC.ITME.Activities
2 years ago
{
/// <summary>
/// 邮箱账户
/// </summary>
10 months ago
[UMC.Web.Apiumc("ITME", "Mime", Auth = WebAuthType.User)]
2 years ago
public class SiteMimeActivity : WebActivity
{
bool Check(Hashtable login)
{
var rawUrl = login["RawUrl"] as string;
if (String.IsNullOrEmpty(rawUrl))
{
this.Prompt("接口请求路径未配置");
return false;
}
var Method = login["Method"] as string;
if (String.IsNullOrEmpty(Method))
{
this.Prompt("接口提交方式未配置");
return false;
}
switch (Method)
{
case "POST":
case "PUT":
var ContentType = login["ContentType"] as string;
if (String.IsNullOrEmpty(ContentType))
{
this.Prompt("接口提交类型未配置");
return false;
}
var value = login["Content"] as string;
if (String.IsNullOrEmpty(value))
{
this.Prompt("接口提交内容未配置");
return false;
}
break;
}
var Finish = login["Finish"] as string;
if (String.IsNullOrEmpty(Finish))
{
this.Prompt("未配置效验格式");
return false;
}
return true;
}
public override void ProcessActivity(WebRequest request, WebResponse response)
{
var Key = this.AsyncDialog("Key", g =>
{
this.Prompt("请传入KEY");
return this.DialogValue("none");
});
var mainKey = String.Format("SITE_MIME_{0}", Key).ToUpper();
var config = UMC.Data.DataFactory.Instance().Config(mainKey);
var value = new Hashtable();
if (config != null)
{
var v = UMC.Data.JSON.Deserialize(config.ConfValue) as Hashtable;
if (v != null)
{
value = v;
}
}
1 year ago
var ks = Key.Split('_');
var typeKey = String.Empty;
if (ks.Length == 2)
{
typeKey = ks[1].ToUpper();
}
2 years ago
var Model = this.AsyncDialog("Model", g =>
{
var title = UITitle.Create();
title.Title = "接口MIME";
10 months ago
title.Right(new UIEventText("跨域").Click(new UIClick( request, g, "Domain")));
2 years ago
var ui = UISection.Create(title);
1 year ago
switch (typeKey)
2 years ago
{
1 year ago
case "LOGIN":
title.Title = "登录接口";
break;
case "UPDATE":
title.Title = "密码托管接口";
break;
case "CHECK":
title.Title = "账户检测接口";
break;
2 years ago
}
var Method = value["Method"] as string;
var RawUrl = value["RawUrl"] as string;
var Domain = value["Domain"] as string;
if (String.IsNullOrEmpty(Domain) == false)
{
10 months ago
ui.AddCell("跨域域名", Domain, new UIClick( request, g, "UnDomain"));
ui.AddCell("提交路径", String.IsNullOrEmpty(RawUrl) ? "未设置" : RawUrl, new UIClick( request, g, "RawUrl"));
2 years ago
}
else
{
10 months ago
ui.AddCell("提交路径", String.IsNullOrEmpty(RawUrl) ? "未设置" : RawUrl, new UIClick( request, g, "RawUrl"));
2 years ago
}
10 months ago
ui.NewSection().AddCell("提交方式", String.IsNullOrEmpty(Method) ? "未设置" : Method, new UIClick(request,g, "Method"));
2 years ago
var Header = value["Header"] as string;
10 months ago
ui.NewSection().AddCell("提交表头", String.IsNullOrEmpty(Header) ? "未设置" : "已设置", new UIClick(request,g, "Header"));
2 years ago
if (String.Equals("GET", Method) == false)
{
var ContentType = value["ContentType"] as string ?? "";
if (ContentType.EndsWith("urlencoded"))
{
ContentType = "表单格式";
}
else if (ContentType.EndsWith("json"))
{
ContentType = "JSON格式";
}
else if (ContentType.EndsWith("xml"))
{
ContentType = "Xml格式";
}
else if (String.IsNullOrEmpty(ContentType))
{
ContentType = "未设置";
}
10 months ago
ui.NewSection().AddCell("提交类型", ContentType, new UIClick( request, g, "ContentType"));
2 years ago
var content = value["Content"] as string;
10 months ago
ui.NewSection().AddCell("提交内容", String.IsNullOrEmpty(content) ? "未设置" : "已设置", new UIClick(request,g, "Content"));
1 year ago
// }
// else if (mainKey.EndsWith("_LOGIN") == false && mainKey.EndsWith("_UPDATE") == false && mainKey.EndsWith("_CHECK") == false)
// {
// var content = value["Content"] as string;
2 years ago
10 months ago
// ui.NewSection().AddCell("脚本环境", String.IsNullOrEmpty(content) ? "未设置" : "已设置", new UIClick(new WebMeta(request.Arguments).Put(g, "Content"));
2 years ago
}
1 year ago
switch (typeKey)
2 years ago
{
1 year ago
case "LOGIN":
case "UPDATE":
case "CHECK":
var Finish = value["Finish"] as string;
var root = Key.Substring(0, Key.LastIndexOf('_'));
2 years ago
10 months ago
ui.NewSection().AddCell("检测格式", String.IsNullOrEmpty(Finish) ? "未设置" : "已设置", new UIClick(request,g, "Finish"));
2 years ago
1 year ago
var fui = ui.NewSection();
10 months ago
fui.AddCell("扩展字段", "新增", new UIClick(request,g, "Feilds"));
1 year ago
var feilds = value["Feilds"] as Hashtable;
if (feilds != null && feilds.Count > 0)
2 years ago
{
1 year ago
var fd = feilds.Keys.Cast<String>().OrderBy(r => r).GetEnumerator();
2 years ago
1 year ago
while (fd.MoveNext())
{
var cell = new WebMeta().Put("value", fd.Current).Put("text", feilds[fd.Current]);
2 years ago
10 months ago
cell.Put("click", new UIClick(request,"Key", Key + "_" + fd.Current));
1 year ago
var uICell = UICell.Create("Cell", cell);
if (fd.Current == "LoginAfter")
{
uICell.Style.Name("value").Color(0xff4949);
// uICell.Style.Name("text").Color(0xff4949);
}
10 months ago
fui.Delete(uICell, new UIEventText("移除").Click(new UIClick(request,g, fd.Current)));
2 years ago
1 year ago
}
2 years ago
}
1 year ago
switch (typeKey)
2 years ago
{
1 year ago
case "LOGIN":
{
10 months ago
ui.NewSection().AddCell("登录清空会话", value.ContainsKey("IsNotCookieClear") ? "不清空" : "清空", new UIClick(request,g, "IsNotCookieClear"));
2 years ago
1 year ago
if (value.ContainsKey("IsLoginHTML"))
{
2 years ago
1 year ago
ui.NewSection()
10 months ago
.AddCell("内容转化配置", new UIClick(request,g, "Script"))
.NewSection().AddCell("前端页面登录", "已启用", new UIClick(request,g, "IsLoginHTML"))
2 years ago
10 months ago
.AddCell("前端页面内容配置", new UIClick(request.Model, "Conf",String.Format("{0}_HTML", mainKey).ToUpper()));
2 years ago
1 year ago
}
else
{
10 months ago
ui.NewSection().AddCell("前端页面登录", "未启用", new UIClick(request,g, "IsLoginHTML"));
1 year ago
}
2 years ago
1 year ago
var Callback = value["Callback"] as string;
10 months ago
ui.NewSection().AddCell("跳转参数", String.IsNullOrEmpty(Callback) ? "未设置" : "已设置", new UIClick(request,g, "Callback"));
1 year ago
}
2 years ago
break;
1 year ago
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;
}
10 months ago
ui.NewSection().AddCell("密码托管模式", UpdateModel, new UIClick( request, g, "UpdateModel"));
1 year ago
}
2 years ago
break;
1 year ago
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()
10 months ago
.AddCell("功能启用", userM, new UIClick( request, g, "UserModel"))
.AddCell("检测账户", String.IsNullOrEmpty(site.Account) ? "未设置" : site.Account, new UIClick(request.Model, "Site","Key", site.Root, "Model", "Account"))
.AddCell("检测登录", value.ContainsKey("IsNotLoginApi") ? "不是" : "是", new UIClick( request, g, "IsNotLoginApi"));
1 year ago
}
}
2 years ago
break;
}
1 year ago
break;
default:
10 months ago
ui.NewSection().AddCell("内容转化配置", new UIClick( request, g, "Script"));
2 years ago
10 months ago
ui.NewSection().AddCell("记住选择内容", value.ContainsKey("RememberValue") ? "记住" : "不记住", new UIClick( request, g, "RememberValue"));
2 years ago
1 year ago
var defautValue = value["DefautValue"] as string;
10 months ago
ui.NewSection().AddCell("内容默认值", String.IsNullOrEmpty(defautValue) ? "未设置" : "已设置", new UIClick( request, g, "DefautValue"));
1 year ago
break;
2 years ago
}
9 months ago
ui.SendTo(this.Context, "Mime.Config");
2 years ago
});
switch (Model)
{
case "UserModel":
if (Check(value))
{
var root = Key.Substring(0, Key.LastIndexOf('_'));
var site = DataFactory.Instance().Site(root.ToLower());
if (site != null)
{
if (String.IsNullOrEmpty(site.Account))
{
this.Prompt("未设置检测账户或密码");
}
var tValue = this.AsyncDialog(Model, g =>
{
var sheet = new UMC.Web.UISheetDialog() { Title = "账户检测功能" };
sheet.Put("启用自动检测", "Checked");
sheet.Put("启用自主选择", "Check");
sheet.Put("关闭账户检测", "Standard");
return sheet;
});
var userM = UMC.Data.Utility.Parse(tValue, UserModel.Standard);
DataFactory.Instance().Put(new Site
{
Root = site.Root,
UserModel = userM
});
this.Context.Send("Mime.Config", true);
}
}
this.Context.End();
break;
case "UnDomain":
this.AsyncDialog("Confirm", g => new UIConfirmDialog("您确认移除此跨域网址吗"));
value.Remove("Domain");
break;
case "Feilds":
var t = this.AsyncDialog(Model, g =>
{
var from4 = new UIFormDialog() { Title = "新增扩展字段" };
from4.AddText("字段标题", "Value", "");
from4.AddText("字段标识", "Name", "");
from4.Submit("确认", "Mime.Config");
1 year ago
from4.AddFooter("当标识为“LoginAfter”表示登录之后请求的网络配置");
2 years ago
return from4;
});
var feilds = value["Feilds"] as Hashtable ?? new Hashtable();
feilds[t["Name"]] = t["Value"];
value["Feilds"] = feilds;
break;
case "RememberValue":
if (value.ContainsKey("RememberValue"))
{
value.Remove("RememberValue");
}
else
{
value["RememberValue"] = "YES";
}
break;
default:
var sValue = this.AsyncDialog(Model, g =>
{
switch (Model)
{
case "ContentType":
var sheet = new UMC.Web.UISheetDialog() { Title = "提交方式" };
2 years ago
sheet.Put("表单格式", "application/x-www-form-urlencoded");
2 years ago
sheet.Put("JSON格式", "application/json");
sheet.Put("XML格式", "application/xml");
1 year ago
return sheet;
2 years ago
case "Method":
var sheet2 = new UMC.Web.UISheetDialog() { Title = "提交方式" };
sheet2.Put("GET").Put("POST").Put("PUT");// "application/json");
1 year ago
return sheet2;
2 years ago
case "Domain":
var fromDomain = new UIFormDialog() { Title = "跨域网址" };
fromDomain.AddText("跨域网址", "Domain", value["Domain"] as string);
fromDomain.Submit("确认", "Mime.Config");
return fromDomain;
case "RawUrl":
var from = new UIFormDialog() { Title = "提交路径" };
from.AddText("提交路径", "RawUrl", value["RawUrl"] as string);
from.Submit("确认", "Mime.Config");
return from;
case "Script":
var from5 = new UIFormDialog() { Title = "内容转化" };
from5.AddTextarea("脚本或者标识", "Script", value["Script"] as string).Put("Rows", 20);
2 years ago
from5.AddFooter("可配置内容表单name、属性key或者js脚本");
2 years ago
from5.Submit("确认", "Mime.Config");
return from5;
case "Header":
var from6 = new UIFormDialog() { Title = "Header字典对" };
from6.AddTextarea("字典对", "Header", value["Header"] as string).Put("Rows", 20).PlaceHolder("H:V");
from6.Submit("确认", "Mime.Config");
return from6;
case "Content":
var from2 = new UIFormDialog() { Title = "提交内容" };
if (String.Equals(value["Method"] as string, "GET"))
{
from2.Title = "脚本网址";
1 year ago
from2.AddTextarea("脚本网址", "Content", value["Content"] as string).Put("Rows", 10).NotRequired();
2 years ago
2 years ago
from2.AddFooter("多项用换行、空格或逗号符分割");
2 years ago
}
else
{
1 year ago
from2.AddTextarea("内容格式", "Content", value["Content"] as string).Put("Rows", 20).NotRequired();
2 years ago
}
from2.Submit("确认", "Mime.Config");
return from2;
case "UpdateModel":
if (SiteConfig.CheckMime(value) == false)
{
this.Prompt("请完成托管密码配置,再来设置此属性");
}
var from9 = new UIFormDialog() { Title = "密码托管模式" };
var UpdateModel = value["UpdateModel"] as String;
from9.AddRadio("", "UpdateModel").Put("默认不选中", "Select", String.Equals(UpdateModel, "Select"))
.Put("默认选中", "Selected", String.Equals(UpdateModel, "Selected")).Put("强制托管", "Compel", String.Equals(UpdateModel, "Compel")).Put("禁用托管", "Disable", String.Equals(UpdateModel, "Disable"));
from9.Submit("确认", "Mime.Config");
return from9;
case "DefautValue":
var from8 = new UIFormDialog() { Title = "内容默认值" };
from8.AddText("默认值", "DefautValue", value["DefautValue"] as string).Put("Rows", 20);
from8.Submit("确认", "Mime.Config");
return from8;
case "Callback":
var fromCallback = new UIFormDialog() { Title = "跳转参数" };
fromCallback.AddText("跳转参数", "Callback", value["Callback"] as string).Put("Rows", 20);
fromCallback.Submit("确认", "Mime.Config");
return fromCallback;
case "IsLoginHTML":
return this.DialogValue(value.ContainsKey("IsLoginHTML") ? "none" : "true");
case "IsNotCookieClear":
return this.DialogValue(value.ContainsKey("IsNotCookieClear") ? "none" : "true");
case "IsNotLoginApi":
return this.DialogValue(value.ContainsKey("IsNotLoginApi") ? "none" : "true");
case "Finish":
var from3 = new UIFormDialog() { Title = "检测格式" };
var fh = (value["Finish"] as string) ?? "";
var isBody = true;
var fhv = fh;
if (String.IsNullOrEmpty(fh) == false)
{
if (fh.StartsWith("E:") || fh.StartsWith("HE:") || fh.StartsWith("H:"))
{
isBody = false;
fhv = fh.Substring(fh.IndexOf(':') + 1);
}
}
from3.AddRadio("检测模式", "Format").Put("成功正文", "B", isBody)
.Put("失败正文", "E", fh.StartsWith("E:")).Put("成功表头", "H", fh.StartsWith("H:")).Put("失败表头", "HE", fh.StartsWith("HE:"));
2 years ago
from3.AddFooter("当模式为成功正文时内容是“Url”时表示检测是否重定向");
2 years ago
from3.AddText("检测内容", "Finish", fhv);
from3.Submit("确认", "Mime.Config");
return from3;
default:
var feilds4 = value["Feilds"] as Hashtable;
if (feilds4 != null && feilds4.Count > 0)
{
feilds4.Remove(Model);
}
return this.DialogValue("none");
}
});
if (String.Equals(sValue, "none") == false)
{
switch (Model)
{
case "Domain":
try
{
var Domain = new Uri(sValue);
sValue = new Uri(Domain, "/").AbsoluteUri;
}
catch
{
this.Prompt("跨域格式不正确");
}
break;
case "RawUrl":
if (sValue.StartsWith("/") == false || sValue.StartsWith("//"))
{
this.Prompt("提交路径格式错误,请确认");
}
break;
case "Finish":
if (request.SendValues != null)
{
var fFormat = request.SendValues["Format"];
switch (fFormat)
{
case "E":
case "H":
case "HE":
sValue = fFormat + ":" + sValue;
break;
}
}
break;
}
value[Model] = sValue;
}
else
{
value.Remove(Model);
}
break;
}
Config platformConfig = new Config();
platformConfig.ConfKey = mainKey;
platformConfig.ConfValue = UMC.Data.JSON.Serialize(value);
UMC.Data.DataFactory.Instance().Put(platformConfig);
this.Context.Send("Mime.Config", true);
}
}
}