From ee8162760ba37097d073c93400d8c9df2863656f Mon Sep 17 00:00:00 2001 From: WaterLemons2k <62788816+WaterLemons2k@users.noreply.github.com> Date: Tue, 4 Apr 2023 20:49:43 +0800 Subject: [PATCH] feat: checkbox to disable Webhook (#656) * feat: checkbox to enable Webhook * fix: true when `webhookenable` key missing * feat: `WebhookStatus` button * chore: better comment for `getWebhookStatus` * feat: reuse checkbox The button is no longer used. * chore: move `WebhookStatus` above `WebhookURL` [skip ci] * refactor(`getWebhookStatus`): use conditional operator https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Conditional_Operator * refactor(`WebhookStatus`): moves the part that changes the value to `addEventListener` Add a new function `isWebhookStatusDisable`. * feat: checkbox to disable Webhook * chore(html): re-add blank line [skip ci] --- config/webhook.go | 3 ++- web/save.go | 1 + web/webhookTest.go | 1 + web/writing.go | 2 ++ web/writing.html | 9 +++++++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/config/webhook.go b/config/webhook.go index 1b237b351..470b2f522 100644 --- a/config/webhook.go +++ b/config/webhook.go @@ -13,6 +13,7 @@ import ( // Webhook Webhook type Webhook struct { + WebhookDisable bool WebhookURL string WebhookRequestBody string } @@ -34,7 +35,7 @@ func ExecWebhook(domains *Domains, conf *Config) (v4Status updateStatusType, v6S v4Status = getDomainsStatus(domains.Ipv4Domains) v6Status = getDomainsStatus(domains.Ipv6Domains) - if conf.WebhookURL != "" && (v4Status != UpdatedNothing || v6Status != UpdatedNothing) { + if !conf.WebhookDisable && conf.WebhookURL != "" && (v4Status != UpdatedNothing || v6Status != UpdatedNothing) { // 成功和失败都要触发webhook method := "GET" postPara := "" diff --git a/web/save.go b/web/save.go index f06dc29b0..191759efe 100755 --- a/web/save.go +++ b/web/save.go @@ -42,6 +42,7 @@ func checkAndSave(request *http.Request) string { conf.NotAllowWanAccess = request.FormValue("NotAllowWanAccess") == "on" conf.Username = strings.TrimSpace(request.FormValue("Username")) conf.Password = request.FormValue("Password") + conf.WebhookDisable = request.FormValue("WebhookDisable") == "on" conf.WebhookURL = strings.TrimSpace(request.FormValue("WebhookURL")) conf.WebhookRequestBody = strings.TrimSpace(request.FormValue("WebhookRequestBody")) // 如启用公网访问,帐号密码不能为空 diff --git a/web/webhookTest.go b/web/webhookTest.go index 16357b80e..45987d940 100755 --- a/web/webhookTest.go +++ b/web/webhookTest.go @@ -28,6 +28,7 @@ func WebhookTest(writer http.ResponseWriter, request *http.Request) { fakeConfig := &config.Config{ Webhook: config.Webhook{ + WebhookDisable: false, WebhookURL: url, WebhookRequestBody: requestBody, }, diff --git a/web/writing.go b/web/writing.go index 3fcf292aa..3f289511f 100755 --- a/web/writing.go +++ b/web/writing.go @@ -21,6 +21,7 @@ type writtingData struct { DnsConf template.JS NotAllowWanAccess string config.User + WebhookDisable string config.Webhook Version string } @@ -66,6 +67,7 @@ func Writing(writer http.ResponseWriter, request *http.Request) { DnsConf: template.JS(getDnsConfStr(conf.DnsConf)), NotAllowWanAccess: BooltoOn(conf.NotAllowWanAccess), User: conf.User, + WebhookDisable: BooltoOn(conf.WebhookDisable), Webhook: conf.Webhook, Version: os.Getenv(VersionEnv), }) diff --git a/web/writing.html b/web/writing.html index 9dbba728a..d6a98f6fb 100755 --- a/web/writing.html +++ b/web/writing.html @@ -326,6 +326,14 @@
其它配置
Webhook
+ +
+ +
+ +
+
@@ -445,6 +453,7 @@
Webhook
document.getElementById('NotAllowWanAccess').checked = "{{.NotAllowWanAccess}}"=='on'; document.getElementById('Username').value = "{{.Username}}"; document.getElementById('Password').value = "{{.Password}}"; + document.getElementById('WebhookDisable').checked = "{{.WebhookDisable}}"=='on'; document.getElementById('WebhookURL').value = "{{.WebhookURL}}"; document.getElementById('WebhookRequestBody').value = "{{.WebhookRequestBody}}"; });