diff --git a/Inotify.Vue/src/views/manager/settingpro/sendauths/index.vue b/Inotify.Vue/src/views/manager/settingpro/sendauths/index.vue index 1feb746..4cd773f 100644 --- a/Inotify.Vue/src/views/manager/settingpro/sendauths/index.vue +++ b/Inotify.Vue/src/views/manager/settingpro/sendauths/index.vue @@ -3,8 +3,8 @@ - - + + @@ -14,6 +14,12 @@ + + + + +
+
- > + @@ -103,7 +109,8 @@ export default { isModify: false, authform: {}, title: "设置", - sendKey: "" + sendKey: "", + isBark: false } }, created() { @@ -114,6 +121,10 @@ export default { this.listLoading = true getSendAuths().then((response) => { this.sendAuthinfos = response.data + let origin = window.document.location.origin; + for (var sendinfo of this.sendAuthinfos) { + sendinfo.url = origin + '/' + sendinfo.key + ".send/{title}/{data}" + } this.listLoading = false }) getSendTemplates().then((response) => { @@ -129,11 +140,24 @@ export default { }, selectTemplateChange(selectTemplate) { this.selectTemplate = deepClone(selectTemplate) + this.isBark = false; if (this.selectTemplate.warning) { this.$message({ message: this.selectTemplate.warning, type: 'warning' }) + if (this.selectTemplate.typeName == 'Bark') { + this.isBark = true; + this.selectTemplate.values = []; + let origin = window.document.location.origin; + this.selectTemplate.barkUrl = origin + '?act=' + this.sendKey; + document.getElementById("bark").innerHTML = ''; + new QRCode(document.getElementById('bark'), { + text: this.selectTemplate.barkUrl, + width: 250, + height: 250, + }); + } } }, submitForm(formName) { @@ -181,6 +205,7 @@ export default { }); }, addAuth() { + this.isBark = false; this.title = '新增设置' this.dialogVisible = true this.isModify = false @@ -190,21 +215,18 @@ export default { modifyAuth(index, row) { this.title = '修改设置' this.isModify = true; + this.isBark = false; this.selectTemplate = deepClone(row); - if (this.selectTemplate.type == "Bark") { - let wPath = window.document.location.href; - let pathName = this.$route.path; - let pos = wPath.indexOf(pathName); - let localhostPath = wPath.substring(0, pos); - localhostPath = localhostPath.replace("#", ""); - + if (this.selectTemplate.typeName == "Bark") { + this.isBark = true; + let origin = window.document.location.origin; var devieItem = this.selectTemplate.values.find(item => { return item.name == "DeviceKey" }) var sendUrlItem = this.selectTemplate.values.find(item => { return item.name == "SendUrl" }); - sendUrlItem.value = localhostPath + "?act=" + this.sendKey + "/" + devieItem.value + "/{title}/{data}" + sendUrlItem.value = origin + "?act=" + this.sendKey + "/" + devieItem.value + "/{title}/{data}" } this.dialogVisible = true; @@ -234,6 +256,9 @@ export default { this.$message.error(state ? '激活失败' : '注销失败'); } }) + }, + getBarkUrl() { + } } } diff --git a/Inotify.Vue/src/views/manager/settingpro/sendkey/index.vue b/Inotify.Vue/src/views/manager/settingpro/sendkey/index.vue index dbacf85..0a74a61 100644 --- a/Inotify.Vue/src/views/manager/settingpro/sendkey/index.vue +++ b/Inotify.Vue/src/views/manager/settingpro/sendkey/index.vue @@ -20,17 +20,17 @@ 重置授权 - + - + - + - 重置SendKey + 重置Token @@ -100,14 +100,10 @@ export default { getSendKey().then((response) => { this.keyForm.sendKey = response.data; this.messageForm.sendKey = response.data; - let wPath = window.document.location.href; - let pathName = this.$route.path; - let pos = wPath.indexOf(pathName); - let localhostPath = wPath.substring(0, pos); - localhostPath = localhostPath.replace("#", ""); - this.keyForm.sendUrlTitle = localhostPath + this.keyForm.sendKey + '.send' + "/{title}" - this.keyForm.sendUrl = localhostPath + this.keyForm.sendKey + '.send' + "/{title}/{data}" - this.keyForm.barkUrl = wPath.substring(0, pos - 2) + '?act=' + this.keyForm.sendKey + let origin = window.document.location.origin; + this.keyForm.sendUrlTitle = origin + '/' + this.keyForm.sendKey + '.send' + "/{title}" + this.keyForm.sendUrl = origin + '/' + this.keyForm.sendKey + '.send' + "/{title}/{data}" + this.keyForm.barkUrl = origin + '?act=' + this.keyForm.sendKey this.listLoading = false; new QRCode(document.getElementById("qrcode"), { text: this.keyForm.barkUrl, diff --git a/Inotify/Controllers/BarkControlor.cs b/Inotify/Controllers/BarkControlor.cs index f3fc0ec..1124545 100644 --- a/Inotify/Controllers/BarkControlor.cs +++ b/Inotify/Controllers/BarkControlor.cs @@ -90,7 +90,7 @@ Register(device_key) : Register(act, key, devicetoken); if (barkSendAuthInfo == null) { - device_key = 16.GenerateCheckCode(); + device_key = Guid.NewGuid().ToString("N").ToUpper(); barkAuth = new BarkAuth() { DeviceKey = device_key, DeviceToken = device_token, IsArchive = "1", AutoMaticallyCopy = "1", Sound = "1107" }; barkSendAuthInfo = new SendAuthInfo() { diff --git a/Inotify/Controllers/SendControlor.cs b/Inotify/Controllers/SendControlor.cs index edaf3ab..4549874 100644 --- a/Inotify/Controllers/SendControlor.cs +++ b/Inotify/Controllers/SendControlor.cs @@ -19,21 +19,6 @@ namespace Inotify.Controllers return Fail(400, "you have no tunnel is acitve"); } - if (!string.IsNullOrEmpty(key)) - { - if (DBManager.Instance.IsSendKey(key, out bool isActive)) - { - if (!isActive) - { - return Fail(400, $"device:{key} tunnel is not acitve"); - } - } - else - { - return Fail(400, $"device:{key} is not registered"); - } - } - var message = new SendMessage() { Token = token, @@ -47,6 +32,34 @@ namespace Inotify.Controllers return OK(); } } + else + { + key = token; + if (DBManager.Instance.IsSendKey(token, out bool isActive, out token)) + { + if (!isActive) + { + return Fail(400, $"device:{key} tunnel is not acitve"); + } + var message = new SendMessage() + { + Token = token, + Title = title, + Data = data, + Key = key, + }; + + if (SendTaskManager.Instance.SendMessage(message)) + { + return OK(); + } + + } + else + { + return Fail(400, $"device:{key} is not registered"); + } + } return Fail(400, $"token:{token} is not registered"); } diff --git a/Inotify/Controllers/SettingControlor.cs b/Inotify/Controllers/SettingControlor.cs index 483b7d1..ddf97fc 100644 --- a/Inotify/Controllers/SettingControlor.cs +++ b/Inotify/Controllers/SettingControlor.cs @@ -41,14 +41,16 @@ namespace Inotify.Controllers var sendTemplate = SendTaskManager.Instance.GetInputTemplate(sendAuthInfo.SendMethodTemplate); if (sendTemplate != null) { + + sendTemplate.Key = sendAuthInfo.Key; + sendTemplate.SendAuthId = sendAuthInfo.Id; sendTemplate.Name = sendAuthInfo.Name; sendTemplate.AuthData = sendAuthInfo.AuthData; - sendTemplate.SendAuthId = sendAuthInfo.Id; sendTemplate.IsActive = sendAuthInfo.Active; sendTemplate.AuthToTemplate(sendAuthInfo.AuthData); userSendTemplates.Add(sendTemplate); } - if (barkTemplateAttribute.Key == sendTemplate.Key) + if (barkTemplateAttribute.Key == sendTemplate.Type) { sendTemplate.Values.FirstOrDefault(e => e.Name == nameof(BarkSendTemplate.Auth.SendUrl)).Value = ""; } @@ -96,10 +98,10 @@ namespace Inotify.Controllers public JsonResult AddSendAuth(InputTemeplate inputTemeplate) { var userInfo = DBManager.Instance.GetUser(UserName); - if (userInfo != null && inputTemeplate.Key != null && inputTemeplate.Name != null) + if (userInfo != null && inputTemeplate.Type != null && inputTemeplate.Name != null) { var barkKey = typeof(BarkSendTemplate).GetCustomAttributes(typeof(SendMethodKeyAttribute), false).OfType().First().Key; - if (barkKey == inputTemeplate.Key) + if (barkKey == inputTemeplate.Type) { return Fail(406, "BARK通道勿手动添加,请使用APP添加BARK地址绑定"); } @@ -109,9 +111,10 @@ namespace Inotify.Controllers var sendAuth = new SendAuthInfo() { UserId = userInfo.Id, - SendMethodTemplate = inputTemeplate.Key, + SendMethodTemplate = inputTemeplate.Type, AuthData = authInfo, Name = inputTemeplate.Name, + Key = Guid.NewGuid().ToString("N").ToUpper(), CreateTime = DateTime.Now, ModifyTime = DateTime.Now, }; diff --git a/Inotify/Data/DBManager.cs b/Inotify/Data/DBManager.cs index 9632c9d..034ce5b 100644 --- a/Inotify/Data/DBManager.cs +++ b/Inotify/Data/DBManager.cs @@ -136,12 +136,18 @@ namespace Inotify.Data return false; } - public bool IsSendKey(string key, out bool isActive) + public bool IsSendKey(string key, out bool isActive, out string token) { isActive = false; + token = null; var sendAuthInfo = DBase.Query().FirstOrDefault(e => e.Key == key); if (sendAuthInfo != null) { + var userInfo = DBase.Query().FirstOrDefault(e => e.Id == sendAuthInfo.UserId); + if (userInfo != null&& userInfo.Token!=null) + { + token = userInfo.Token; + } isActive = sendAuthInfo.Active; return true; } @@ -219,6 +225,7 @@ namespace Inotify.Data var builder = new MigrationBuilder(MigrationName, DBase); builder.Append(new Version(2, 0, 0, 0), new V2UpdateMigration()); builder.Append(new Version(2, 0, 0, 1), new V2001UpdateMigration()); + builder.Append(new Version(2, 0, 0, 4), new V2004UpdateMigration()); builder.Execute(); } } diff --git a/Inotify/Data/DBMigrations.cs b/Inotify/Data/DBMigrations.cs index b05b041..a0432aa 100644 --- a/Inotify/Data/DBMigrations.cs +++ b/Inotify/Data/DBMigrations.cs @@ -80,7 +80,6 @@ namespace Inotify.Data protected override void execute() { - //对AuthInfo的AuthDate字段进行加密 var sendAuthInfos = Migrator.Database.Query().ToList(); sendAuthInfos.ForEach(sendAuthInfo => { @@ -88,7 +87,6 @@ namespace Inotify.Data Migrator.Database.Update(sendAuthInfo); }); - //添加bark密钥相关内容 Migrator.Database.Insert(new SystemInfo() { key = "barkKeyId", @@ -106,4 +104,18 @@ namespace Inotify.Data }); } } + + public class V2004UpdateMigration : Migration, IMigration + { + protected override void execute() + { + var sendAuthInfos = Migrator.Database.Query().ToList(); + sendAuthInfos.ForEach(sendAuthInfo => + { + if (string.IsNullOrEmpty(sendAuthInfo.Key)) + sendAuthInfo.Key = Guid.NewGuid().ToString("N").ToUpper(); + Migrator.Database.Update(sendAuthInfo); + }); + } + } } diff --git a/Inotify/Inotify.csproj b/Inotify/Inotify.csproj index 97631a1..d1333c9 100644 --- a/Inotify/Inotify.csproj +++ b/Inotify/Inotify.csproj @@ -6,8 +6,8 @@ Linux Inotify.Program enable - 2.0.0.3 - 2.0.0.3 + 2.0.0.4 + 2.0.0.4 diff --git a/Inotify/Sends/SendTaskManager.cs b/Inotify/Sends/SendTaskManager.cs index e56a28b..2eb15a7 100644 --- a/Inotify/Sends/SendTaskManager.cs +++ b/Inotify/Sends/SendTaskManager.cs @@ -124,9 +124,9 @@ namespace Inotify.Sends var getTemeplateMethod = sendMethodTemplateType.GetMethod("GetTemeplate"); if (getTemeplateMethod != null) { - if (getTemeplateMethod.Invoke(obj, null) is InputTemeplate temeplate && temeplate.Key != null) + if (getTemeplateMethod.Invoke(obj, null) is InputTemeplate temeplate && temeplate.Type != null) { - sendTemplates.Add(temeplate.Key, temeplate); + sendTemplates.Add(temeplate.Type, temeplate); } } } diff --git a/Inotify/Sends/SendTemplate.cs b/Inotify/Sends/SendTemplate.cs index ad67c1f..54f1b94 100644 --- a/Inotify/Sends/SendTemplate.cs +++ b/Inotify/Sends/SendTemplate.cs @@ -62,8 +62,9 @@ namespace Inotify.Sends public class InputTemeplate { - public string? Key { get; set; } public string? Type { get; set; } + public string? TypeName { get; set; } + public string? Key { get; set; } public string? Name { get; set; } public bool IsActive { get; set; } public string Warning { get; set; } @@ -179,9 +180,10 @@ namespace Inotify.Sends { return new InputTemeplate() { + Key = "", Name = sendMethodKeyAttribute.Name, - Type = sendMethodKeyAttribute.Name, - Key = sendMethodKeyAttribute.Key, + Type = sendMethodKeyAttribute.Key, + TypeName = sendMethodKeyAttribute.Name, Warning = sendMethodKeyAttribute.Waring, Values = values }; diff --git a/Inotify/Startup.cs b/Inotify/Startup.cs index fb7479b..4fa769e 100644 --- a/Inotify/Startup.cs +++ b/Inotify/Startup.cs @@ -109,7 +109,7 @@ namespace Inotify if (match.Success) { rewriteContext.HttpContext.Request.Path = @"/api/send"; - rewriteContext.HttpContext.Request.QueryString = new QueryString($"?token={groups[1]}&key={groups[2]}&title={groups[3]}&date={groups[4]}"); + rewriteContext.HttpContext.Request.QueryString = new QueryString($"?key={groups[2]}&title={groups[3]}&date={groups[4]}"); } else { @@ -117,7 +117,7 @@ namespace Inotify if (match.Success) { rewriteContext.HttpContext.Request.Path = @"/api/send"; - rewriteContext.HttpContext.Request.QueryString = new QueryString($"?token={groups[1]}&key={groups[2]}&title={groups[3]}"); + rewriteContext.HttpContext.Request.QueryString = new QueryString($"?key={groups[2]}&title={groups[3]}"); } else { @@ -125,7 +125,7 @@ namespace Inotify if (match.Success) { rewriteContext.HttpContext.Request.Path = @"/api/send"; - rewriteContext.HttpContext.Request.QueryString = new QueryString($"?token={groups[1]}&key={groups[2]}"); + rewriteContext.HttpContext.Request.QueryString = new QueryString($"?key={groups[2]}"); } else if (rewriteContext.HttpContext.Request.QueryString.Value.StartsWith("?")) { diff --git a/README.md b/README.md index fb91358..359c412 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ * V2.0.0.3 * 支持钉钉群消息 * 支持飞书群消息 + * V2.0.0.4 + * 支持通道独立消息推送 ## 使用方法 1. Docker安装 @@ -45,7 +47,7 @@ ``` docker run --name=inotify -d -p 8000:80 -v inotify_data:/inotify_data --restart=always xpnas/inotify:latest ``` - * 开发版V2.0.0.3 + * 开发版V2.0.0.4 ``` docker run --name=inotify -d -p 8000:80 -v inotify_data:/inotify_data --restart=always xpnas/inotify:master ```