From 2a2596fe615e4f18e0aff02cc8a016fea0463849 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 7 Feb 2015 10:46:57 -0500 Subject: [PATCH] able to disable SSH for #883 --- README.md | 2 +- README_ZH.md | 2 +- cmd/serve.go | 6 ++++++ conf/app.ini | 2 ++ gogs.go | 2 +- models/action.go | 2 -- models/repo.go | 4 ++-- modules/middleware/repo.go | 1 + modules/setting/setting.go | 6 ++++-- templates/.VERSION | 2 +- templates/repo/header.tmpl | 8 +++++--- 11 files changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3d87e3a1ff..e93e599e71 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Gogs(Go Git Service) is a painless self-hosted Git Service written in Go. ![Demo](http://gogs.qiniudn.com/gogs_demo.gif) -##### Current version: 0.5.12 Beta +##### Current version: 0.5.13 Beta ### NOTICES diff --git a/README_ZH.md b/README_ZH.md index be3a2b1bc4..54e66315a8 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。 ![Demo](http://gogs.qiniudn.com/gogs_demo.gif) -##### 当前版本:0.5.12 Beta +##### 当前版本:0.5.13 Beta ## 开发目的 diff --git a/cmd/serve.go b/cmd/serve.go index 2390962342..1f5d944d4f 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -33,6 +33,12 @@ var CmdServ = cli.Command{ func setup(logPath string) { setting.NewConfigContext() log.NewGitLogger(filepath.Join(setting.LogRootPath, logPath)) + + if setting.DisableSSH { + println("Gogs: SSH has been disabled") + os.Exit(1) + } + models.LoadModelsConfig() if models.UseSQLite3 { diff --git a/conf/app.ini b/conf/app.ini index b7a0f1a7c5..17d1a3b3b9 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -18,6 +18,8 @@ DOMAIN = localhost ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/ HTTP_ADDR = HTTP_PORT = 3000 +; Disable SSH feature when not available +DISABLE_SSH = false SSH_PORT = 22 ; Disable CDN even in "prod" mode OFFLINE_MODE = false diff --git a/gogs.go b/gogs.go index ce524af5aa..c09c4ca196 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.12.0206 Beta" +const APP_VER = "0.5.13.0207 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/action.go b/models/action.go index 34f543c4b2..a6c6cfbfaa 100644 --- a/models/action.go +++ b/models/action.go @@ -119,8 +119,6 @@ func (a Action) GetIssueInfos() []string { func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, commits []*base.PushCommit) error { for _, c := range commits { - // FIXME: should not be a reference when it comes with action. - // e.g. fixes #1 will not have duplicated reference message. for _, ref := range IssueReferenceKeywordsPat.FindAllString(c.Message, -1) { ref := ref[strings.IndexByte(ref, byte(' '))+1:] ref = strings.TrimRightFunc(ref, func(c rune) bool { diff --git a/models/repo.go b/models/repo.go index b745821753..3e07adba63 100644 --- a/models/repo.go +++ b/models/repo.go @@ -247,8 +247,8 @@ func (repo *Repository) CloneLink() (cl CloneLink, err error) { if err = repo.GetOwner(); err != nil { return cl, err } - if setting.SshPort != 22 { - cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.Domain, setting.SshPort, repo.Owner.LowerName, repo.LowerName) + if setting.SSHPort != 22 { + cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.Domain, setting.SSHPort, repo.Owner.LowerName, repo.LowerName) } else { cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.Domain, repo.Owner.LowerName, repo.LowerName) } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index d143d8a86b..1ab158dd6d 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -386,6 +386,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner ctx.Data["IsRepositoryTrueOwner"] = ctx.Repo.IsTrueOwner + ctx.Data["DisableSSH"] = setting.DisableSSH ctx.Repo.CloneLink, err = repo.CloneLink() if err != nil { ctx.Handle(500, "CloneLink", err) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index e79e6d6b96..6a205921b8 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -50,7 +50,8 @@ var ( Protocol Scheme Domain string HttpAddr, HttpPort string - SshPort int + DisableSSH bool + SSHPort int OfflineMode bool DisableRouterLog bool CertFile, KeyFile string @@ -209,7 +210,8 @@ func NewConfigContext() { Domain = sec.Key("DOMAIN").MustString("localhost") HttpAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0") HttpPort = sec.Key("HTTP_PORT").MustString("3000") - SshPort = sec.Key("SSH_PORT").MustInt(22) + DisableSSH = sec.Key("DISABLE_SSH").MustBool() + SSHPort = sec.Key("SSH_PORT").MustInt(22) OfflineMode = sec.Key("OFFLINE_MODE").MustBool() DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool() StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(workDir) diff --git a/templates/.VERSION b/templates/.VERSION index 99de7de73e..5a5ed364d9 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.12.0206 Beta \ No newline at end of file +0.5.13.0207 Beta \ No newline at end of file diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 20e67db810..9e52efc727 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -18,9 +18,11 @@