Skip to content

Commit

Permalink
feat: checkbox to disable Webhook (#656)
Browse files Browse the repository at this point in the history
* 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]
  • Loading branch information
WaterLemons2k committed Apr 4, 2023
1 parent 947ff98 commit ee81627
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// Webhook Webhook
type Webhook struct {
WebhookDisable bool
WebhookURL string
WebhookRequestBody string
}
Expand All @@ -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 := ""
Expand Down
1 change: 1 addition & 0 deletions web/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
// 如启用公网访问,帐号密码不能为空
Expand Down
1 change: 1 addition & 0 deletions web/webhookTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func WebhookTest(writer http.ResponseWriter, request *http.Request) {

fakeConfig := &config.Config{
Webhook: config.Webhook{
WebhookDisable: false,
WebhookURL: url,
WebhookRequestBody: requestBody,
},
Expand Down
2 changes: 2 additions & 0 deletions web/writing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type writtingData struct {
DnsConf template.JS
NotAllowWanAccess string
config.User
WebhookDisable string
config.Webhook
Version string
}
Expand Down Expand Up @@ -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),
})
Expand Down
9 changes: 9 additions & 0 deletions web/writing.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ <h5 class="portlet__head">其它配置</h5>
<div class="portlet">
<h5 class="portlet__head">Webhook</h5>
<div class="portlet__body">

<div class="form-group row">
<label for="WebhookDisable" class="col-sm-2">是否禁用</label>
<div class="col-sm-10">
<input type="checkbox" class="form-check-inline" style="margin-top: 5px;" id="WebhookDisable"
name="WebhookDisable" checked>
</div>
</div>

<div class="form-group row">
<label for="WebhookURL" class="col-sm-2 col-form-label">URL</label>
Expand Down Expand Up @@ -445,6 +453,7 @@ <h5 class="portlet__head">Webhook</h5>
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}}";
});
Expand Down

0 comments on commit ee81627

Please sign in to comment.