able to allow insecure certification of webhook for #891

tokarchuk/v1.17
Unknwon 10 years ago
parent e407df54f0
commit 6a23252edc
  1. 2
      conf/app.ini
  2. 1
      conf/locale/locale_en-US.ini
  3. 2
      gogs.go
  4. 14
      models/webhook.go
  5. 2
      modules/cron/manager.go
  6. 13
      modules/setting/setting.go
  7. 5
      routers/admin/admin.go
  8. 2
      templates/.VERSION
  9. 6
      templates/admin/config.tmpl

@ -89,6 +89,8 @@ ENABLE_REVERSE_PROXY_AUTO_REGISTERATION = false
TASK_INTERVAL = 1 TASK_INTERVAL = 1
; Deliver timeout in seconds ; Deliver timeout in seconds
DELIVER_TIMEOUT = 5 DELIVER_TIMEOUT = 5
; Allow insecure certification
ALLOW_INSECURE_CERTIFICATION = false
[mailer] [mailer]
ENABLED = false ENABLED = false

@ -647,6 +647,7 @@ config.reset_password_code_lives = Reset Password Code Lives
config.webhook_config = Webhook Configuration config.webhook_config = Webhook Configuration
config.task_interval = Task Interval config.task_interval = Task Interval
config.deliver_timeout = Deliver Timeout config.deliver_timeout = Deliver Timeout
config.allow_insecure_certification = Allow Insecure Certification
config.mailer_config = Mailer Configuration config.mailer_config = Mailer Configuration
config.mailer_enabled = Enabled config.mailer_enabled = Enabled
config.mailer_name = Name config.mailer_name = Name

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.5.13.0209 Beta" const APP_VER = "0.5.13.0210 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

@ -5,6 +5,7 @@
package models package models
import ( import (
"crypto/tls"
"encoding/json" "encoding/json"
"errors" "errors"
"io/ioutil" "io/ioutil"
@ -307,13 +308,14 @@ func DeliverHooks() {
defer func() { isShooting = false }() defer func() { isShooting = false }()
tasks := make([]*HookTask, 0, 10) tasks := make([]*HookTask, 0, 10)
timeout := time.Duration(setting.WebhookDeliverTimeout) * time.Second timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second
x.Where("is_delivered=?", false).Iterate(new(HookTask), x.Where("is_delivered=?", false).Iterate(new(HookTask),
func(idx int, bean interface{}) error { func(idx int, bean interface{}) error {
t := bean.(*HookTask) t := bean.(*HookTask)
req := httplib.Post(t.Url).SetTimeout(timeout, timeout). req := httplib.Post(t.Url).SetTimeout(timeout, timeout).
Header("X-Gogs-Delivery", t.Uuid). Header("X-Gogs-Delivery", t.Uuid).
Header("X-Gogs-Event", string(t.EventType)) Header("X-Gogs-Event", string(t.EventType)).
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: setting.Webhook.AllowInsecureCertification})
switch t.ContentType { switch t.ContentType {
case JSON: case JSON:
@ -329,7 +331,7 @@ func DeliverHooks() {
case GOGS: case GOGS:
{ {
if _, err := req.Response(); err != nil { if _, err := req.Response(); err != nil {
log.Error(4, "Delivery: %v", err) log.Error(5, "Delivery: %v", err)
} else { } else {
t.IsSucceed = true t.IsSucceed = true
} }
@ -337,15 +339,15 @@ func DeliverHooks() {
case SLACK: case SLACK:
{ {
if res, err := req.Response(); err != nil { if res, err := req.Response(); err != nil {
log.Error(4, "Delivery: %v", err) log.Error(5, "Delivery: %v", err)
} else { } else {
defer res.Body.Close() defer res.Body.Close()
contents, err := ioutil.ReadAll(res.Body) contents, err := ioutil.ReadAll(res.Body)
if err != nil { if err != nil {
log.Error(4, "%s", err) log.Error(5, "%s", err)
} else { } else {
if string(contents) != "ok" { if string(contents) != "ok" {
log.Error(4, "slack failed with: %s", string(contents)) log.Error(5, "slack failed with: %s", string(contents))
} else { } else {
t.IsSucceed = true t.IsSucceed = true
} }

@ -15,7 +15,7 @@ var c = New()
func NewCronContext() { func NewCronContext() {
c.AddFunc("Update mirrors", "@every 1h", models.MirrorUpdate) c.AddFunc("Update mirrors", "@every 1h", models.MirrorUpdate)
c.AddFunc("Deliver hooks", fmt.Sprintf("@every %dm", setting.WebhookTaskInterval), models.DeliverHooks) c.AddFunc("Deliver hooks", fmt.Sprintf("@every %dm", setting.Webhook.TaskInterval), models.DeliverHooks)
if setting.Git.Fsck.Enable { if setting.Git.Fsck.Enable {
c.AddFunc("Repository health check", fmt.Sprintf("@every %dh", setting.Git.Fsck.Interval), models.GitFsck) c.AddFunc("Repository health check", fmt.Sprintf("@every %dh", setting.Git.Fsck.Interval), models.GitFsck)
} }

@ -68,8 +68,11 @@ var (
ReverseProxyAuthUser string ReverseProxyAuthUser string
// Webhook settings. // Webhook settings.
WebhookTaskInterval int Webhook struct {
WebhookDeliverTimeout int TaskInterval int
DeliverTimeout int
AllowInsecureCertification bool
}
// Repository settings. // Repository settings.
RepoRootPath string RepoRootPath string
@ -508,8 +511,10 @@ func newNotifyMailService() {
} }
func newWebhookService() { func newWebhookService() {
WebhookTaskInterval = Cfg.Section("webhook").Key("TASK_INTERVAL").MustInt(1) sec := Cfg.Section("webhook")
WebhookDeliverTimeout = Cfg.Section("webhook").Key("DELIVER_TIMEOUT").MustInt(5) Webhook.TaskInterval = sec.Key("TASK_INTERVAL").MustInt(1)
Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5)
Webhook.AllowInsecureCertification = sec.Key("ALLOW_INSECURE_CERTIFICATION").MustBool()
} }
func NewServices() { func NewServices() {

@ -188,11 +188,8 @@ func Config(ctx *middleware.Context) {
ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser
ctx.Data["Service"] = setting.Service ctx.Data["Service"] = setting.Service
ctx.Data["DbCfg"] = models.DbCfg ctx.Data["DbCfg"] = models.DbCfg
ctx.Data["Webhook"] = setting.Webhook
ctx.Data["WebhookTaskInterval"] = setting.WebhookTaskInterval
ctx.Data["WebhookDeliverTimeout"] = setting.WebhookDeliverTimeout
ctx.Data["MailerEnabled"] = false ctx.Data["MailerEnabled"] = false
if setting.MailService != nil { if setting.MailService != nil {

@ -1 +1 @@
0.5.13.0209 Beta 0.5.13.0210 Beta

@ -102,9 +102,11 @@
<div class="panel-body"> <div class="panel-body">
<dl class="dl-horizontal admin-dl-horizontal"> <dl class="dl-horizontal admin-dl-horizontal">
<dt>{{.i18n.Tr "admin.config.task_interval"}}</dt> <dt>{{.i18n.Tr "admin.config.task_interval"}}</dt>
<dd>{{.WebhookTaskInterval}} {{.i18n.Tr "tool.raw_minutes"}}</dd> <dd>{{.Webhook.TaskInterval}} {{.i18n.Tr "tool.raw_minutes"}}</dd>
<dt>{{.i18n.Tr "admin.config.deliver_timeout"}}</dt> <dt>{{.i18n.Tr "admin.config.deliver_timeout"}}</dt>
<dd>{{.WebhookDeliverTimeout}} {{.i18n.Tr "tool.raw_seconds"}}</dd> <dd>{{.Webhook.DeliverTimeout}} {{.i18n.Tr "tool.raw_seconds"}}</dd>
<dt>{{.i18n.Tr "admin.config.allow_insecure_certification"}}</dt>
<dd><i class="fa fa{{if .Webhook.AllowInsecureCertification}}-check{{end}}-square-o"></i></dd>
</dl> </dl>
</div> </div>
</div> </div>

Loading…
Cancel
Save