]> source.dussan.org Git - gitea.git/commitdiff
able to allow insecure certification of webhook for #891
authorUnknwon <joe2010xtmf@163.com>
Wed, 11 Feb 2015 02:06:59 +0000 (21:06 -0500)
committerUnknwon <joe2010xtmf@163.com>
Wed, 11 Feb 2015 02:06:59 +0000 (21:06 -0500)
conf/app.ini
conf/locale/locale_en-US.ini
gogs.go
models/webhook.go
modules/cron/manager.go
modules/setting/setting.go
routers/admin/admin.go
templates/.VERSION
templates/admin/config.tmpl

index 782dc51c89c59077e3477a31b3a32aa752ca580a..e80d77a9ca5b9415df8c81c67e1da5e7be707233 100644 (file)
@@ -89,6 +89,8 @@ ENABLE_REVERSE_PROXY_AUTO_REGISTERATION = false
 TASK_INTERVAL = 1
 ; Deliver timeout in seconds
 DELIVER_TIMEOUT = 5
+; Allow insecure certification
+ALLOW_INSECURE_CERTIFICATION = false
 
 [mailer]
 ENABLED = false
index 8ea383f26bc081aa25ad43bd1372a13e9fe3f8ec..9e691171a4195cd9397ae62cc06113dabf217358 100644 (file)
@@ -647,6 +647,7 @@ config.reset_password_code_lives = Reset Password Code Lives
 config.webhook_config = Webhook Configuration
 config.task_interval = Task Interval
 config.deliver_timeout = Deliver Timeout
+config.allow_insecure_certification = Allow Insecure Certification
 config.mailer_config = Mailer Configuration
 config.mailer_enabled = Enabled
 config.mailer_name = Name
diff --git a/gogs.go b/gogs.go
index 0990391714b408fed340c3011347cfae37fb1d4f..b2f45b333f3278e286d028c0a8c782ae3b3b1c63 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
        "github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.5.13.0209 Beta"
+const APP_VER = "0.5.13.0210 Beta"
 
 func init() {
        runtime.GOMAXPROCS(runtime.NumCPU())
index 8e112ac572b63102da0a11bcd2c6d906824306f8..34349bb598c17548b80c4fab915093c7ed9cc4b8 100644 (file)
@@ -5,6 +5,7 @@
 package models
 
 import (
+       "crypto/tls"
        "encoding/json"
        "errors"
        "io/ioutil"
@@ -307,13 +308,14 @@ func DeliverHooks() {
        defer func() { isShooting = false }()
 
        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),
                func(idx int, bean interface{}) error {
                        t := bean.(*HookTask)
                        req := httplib.Post(t.Url).SetTimeout(timeout, timeout).
                                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 {
                        case JSON:
@@ -329,7 +331,7 @@ func DeliverHooks() {
                        case GOGS:
                                {
                                        if _, err := req.Response(); err != nil {
-                                               log.Error(4, "Delivery: %v", err)
+                                               log.Error(5, "Delivery: %v", err)
                                        } else {
                                                t.IsSucceed = true
                                        }
@@ -337,15 +339,15 @@ func DeliverHooks() {
                        case SLACK:
                                {
                                        if res, err := req.Response(); err != nil {
-                                               log.Error(4, "Delivery: %v", err)
+                                               log.Error(5, "Delivery: %v", err)
                                        } else {
                                                defer res.Body.Close()
                                                contents, err := ioutil.ReadAll(res.Body)
                                                if err != nil {
-                                                       log.Error(4, "%s", err)
+                                                       log.Error(5, "%s", err)
                                                } else {
                                                        if string(contents) != "ok" {
-                                                               log.Error(4, "slack failed with: %s", string(contents))
+                                                               log.Error(5, "slack failed with: %s", string(contents))
                                                        } else {
                                                                t.IsSucceed = true
                                                        }
index 135fec4faa7605a5e461ac609f9d4f97dea6b30c..2990ab0604493d474e0faae566a01a6ef7f776e5 100644 (file)
@@ -15,7 +15,7 @@ var c = New()
 
 func NewCronContext() {
        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 {
                c.AddFunc("Repository health check", fmt.Sprintf("@every %dh", setting.Git.Fsck.Interval), models.GitFsck)
        }
index 55e0a79ab82641144710449965c6e3049b04c317..d71a8cda555e1400f132ec70f0094b10cdecf7c7 100644 (file)
@@ -68,8 +68,11 @@ var (
        ReverseProxyAuthUser string
 
        // Webhook settings.
-       WebhookTaskInterval   int
-       WebhookDeliverTimeout int
+       Webhook struct {
+               TaskInterval               int
+               DeliverTimeout             int
+               AllowInsecureCertification bool
+       }
 
        // Repository settings.
        RepoRootPath string
@@ -508,8 +511,10 @@ func newNotifyMailService() {
 }
 
 func newWebhookService() {
-       WebhookTaskInterval = Cfg.Section("webhook").Key("TASK_INTERVAL").MustInt(1)
-       WebhookDeliverTimeout = Cfg.Section("webhook").Key("DELIVER_TIMEOUT").MustInt(5)
+       sec := Cfg.Section("webhook")
+       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() {
index d54bb629fd28e6efe831ee4ee665b63eb5af167c..316f1d4257ce24e173927c8479d46017104d9036 100644 (file)
@@ -188,11 +188,8 @@ func Config(ctx *middleware.Context) {
        ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser
 
        ctx.Data["Service"] = setting.Service
-
        ctx.Data["DbCfg"] = models.DbCfg
-
-       ctx.Data["WebhookTaskInterval"] = setting.WebhookTaskInterval
-       ctx.Data["WebhookDeliverTimeout"] = setting.WebhookDeliverTimeout
+       ctx.Data["Webhook"] = setting.Webhook
 
        ctx.Data["MailerEnabled"] = false
        if setting.MailService != nil {
index 1f077fbfcc68e5b978c7ed89020a75af49fbdb9c..8f04f6d0da7c14e4c70b2ea15416e62cf19316e1 100644 (file)
@@ -1 +1 @@
-0.5.13.0209 Beta
\ No newline at end of file
+0.5.13.0210 Beta
\ No newline at end of file
index f8b4be0b8314ba0b51405f4fb7fe77a29df810d2..5cf84beb99f19713f0488c942f5b6f334e88c09d 100644 (file)
                             <div class="panel-body">
                                 <dl class="dl-horizontal admin-dl-horizontal">
                                     <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>
-                                    <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>
                             </div>
                         </div>