Batch of mirror fixes
This commit is contained in:
parent
e573855a4f
commit
7cb5a15c9b
12 changed files with 120 additions and 20 deletions
|
@ -43,7 +43,7 @@ func newMartini() *martini.ClassicMartini {
|
||||||
m := martini.New()
|
m := martini.New()
|
||||||
m.Use(middleware.Logger())
|
m.Use(middleware.Logger())
|
||||||
m.Use(martini.Recovery())
|
m.Use(martini.Recovery())
|
||||||
m.Use(martini.Static("public", martini.StaticOptions{SkipLogging: !base.RouterLog}))
|
m.Use(martini.Static("public", martini.StaticOptions{SkipLogging: !base.DisableRouterLog}))
|
||||||
m.MapTo(r, (*martini.Routes)(nil))
|
m.MapTo(r, (*martini.Routes)(nil))
|
||||||
m.Action(r.Handle)
|
m.Action(r.Handle)
|
||||||
return &martini.ClassicMartini{m, r}
|
return &martini.ClassicMartini{m, r}
|
||||||
|
|
|
@ -20,7 +20,7 @@ HTTP_ADDR =
|
||||||
HTTP_PORT = 3000
|
HTTP_PORT = 3000
|
||||||
; Disable CDN even in "prod" mode
|
; Disable CDN even in "prod" mode
|
||||||
OFFLINE_MODE = false
|
OFFLINE_MODE = false
|
||||||
ROUTER_LOG = true
|
DISABLE_ROUTER_LOG = false
|
||||||
; Generate steps:
|
; Generate steps:
|
||||||
; $ cd path/to/gogs/custom/https
|
; $ cd path/to/gogs/custom/https
|
||||||
; $ go run $GOROOT/src/pkg/crypto/tls/generate_cert.go -ca=true -duration=8760h0m0s -host=myhost.example.com
|
; $ go run $GOROOT/src/pkg/crypto/tls/generate_cert.go -ca=true -duration=8760h0m0s -host=myhost.example.com
|
||||||
|
|
|
@ -30,14 +30,15 @@ const (
|
||||||
OP_PULL_REQUEST
|
OP_PULL_REQUEST
|
||||||
OP_TRANSFER_REPO
|
OP_TRANSFER_REPO
|
||||||
OP_PUSH_TAG
|
OP_PUSH_TAG
|
||||||
|
OP_COMMENT_ISSUE
|
||||||
)
|
)
|
||||||
|
|
||||||
// Action represents user operation type and other information to repository.,
|
// Action represents user operation type and other information to repository.,
|
||||||
// it implemented interface base.Actioner so that can be used in template render.
|
// it implemented interface base.Actioner so that can be used in template render.
|
||||||
type Action struct {
|
type Action struct {
|
||||||
Id int64
|
Id int64
|
||||||
UserId int64 // Receiver user id.
|
UserId int64 // Receiver user id.
|
||||||
OpType int // Operations: CREATE DELETE STAR ...
|
OpType int
|
||||||
ActUserId int64 // Action user id.
|
ActUserId int64 // Action user id.
|
||||||
ActUserName string // Action user name.
|
ActUserName string // Action user name.
|
||||||
ActEmail string
|
ActEmail string
|
||||||
|
|
|
@ -80,3 +80,9 @@ func DeleteOauth2ById(id int64) error {
|
||||||
_, err := orm.Delete(&Oauth2{Id: id})
|
_, err := orm.Delete(&Oauth2{Id: id})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CleanUnbindOauth deletes all unbind OAuthes.
|
||||||
|
func CleanUnbindOauth() error {
|
||||||
|
_, err := orm.Delete(&Oauth2{Uid: -1})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -45,16 +45,16 @@ type Oauther struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
AppVer string
|
AppVer string
|
||||||
AppName string
|
AppName string
|
||||||
AppLogo string
|
AppLogo string
|
||||||
AppUrl string
|
AppUrl string
|
||||||
OfflineMode bool
|
OfflineMode bool
|
||||||
RouterLog bool
|
DisableRouterLog bool
|
||||||
ProdMode bool
|
ProdMode bool
|
||||||
Domain string
|
Domain string
|
||||||
SecretKey string
|
SecretKey string
|
||||||
RunUser string
|
RunUser string
|
||||||
|
|
||||||
RepoRootPath string
|
RepoRootPath string
|
||||||
ScriptType string
|
ScriptType string
|
||||||
|
@ -330,7 +330,7 @@ func NewConfigContext() {
|
||||||
AppUrl = Cfg.MustValue("server", "ROOT_URL")
|
AppUrl = Cfg.MustValue("server", "ROOT_URL")
|
||||||
Domain = Cfg.MustValue("server", "DOMAIN")
|
Domain = Cfg.MustValue("server", "DOMAIN")
|
||||||
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
|
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
|
||||||
RouterLog = Cfg.MustBool("server", "ROUTER_LOG", true)
|
DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG", false)
|
||||||
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
|
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
|
||||||
|
|
||||||
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
|
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
|
||||||
|
|
|
@ -117,6 +117,8 @@ func ActionIcon(opType int) string {
|
||||||
return "exclamation-circle"
|
return "exclamation-circle"
|
||||||
case 8: // Transfer repository.
|
case 8: // Transfer repository.
|
||||||
return "share"
|
return "share"
|
||||||
|
case 10: // Comment issue.
|
||||||
|
return "comment"
|
||||||
default:
|
default:
|
||||||
return "invalid type"
|
return "invalid type"
|
||||||
}
|
}
|
||||||
|
@ -130,6 +132,8 @@ const (
|
||||||
<div><img src="%s?s=16" alt="user-avatar"/> %s</div>`
|
<div><img src="%s?s=16" alt="user-avatar"/> %s</div>`
|
||||||
TPL_TRANSFER_REPO = `<a href="/user/%s">%s</a> transfered repository <code>%s</code> to <a href="/%s">%s</a>`
|
TPL_TRANSFER_REPO = `<a href="/user/%s">%s</a> transfered repository <code>%s</code> to <a href="/%s">%s</a>`
|
||||||
TPL_PUSH_TAG = `<a href="/user/%s">%s</a> pushed tag <a href="/%s/src/%s" rel="nofollow">%s</a> at <a href="/%s">%s</a>`
|
TPL_PUSH_TAG = `<a href="/user/%s">%s</a> pushed tag <a href="/%s/src/%s" rel="nofollow">%s</a> at <a href="/%s">%s</a>`
|
||||||
|
TPL_COMMENT_ISSUE = `<a href="/user/%s">%s</a> commented on issue <a href="/%s/issues/%s">%s#%s</a>
|
||||||
|
<div><img src="%s?s=16" alt="user-avatar"/> %s</div>`
|
||||||
)
|
)
|
||||||
|
|
||||||
type PushCommit struct {
|
type PushCommit struct {
|
||||||
|
@ -179,6 +183,10 @@ func ActionDesc(act Actioner) string {
|
||||||
return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink)
|
return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink)
|
||||||
case 9: // Push tag.
|
case 9: // Push tag.
|
||||||
return fmt.Sprintf(TPL_PUSH_TAG, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink)
|
return fmt.Sprintf(TPL_PUSH_TAG, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink)
|
||||||
|
case 10: // Comment issue.
|
||||||
|
infos := strings.SplitN(content, "|", 2)
|
||||||
|
return fmt.Sprintf(TPL_COMMENT_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0],
|
||||||
|
AvatarLink(email), infos[1])
|
||||||
default:
|
default:
|
||||||
return "invalid type"
|
return "invalid type"
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ func handleQueue() {
|
||||||
log.Error("hooks.handleQueue: Fail to deliver hook: %v", err)
|
log.Error("hooks.handleQueue: Fail to deliver hook: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Info("Hook delivered")
|
log.Info("Hook delivered: %s", string(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func init() {
|
||||||
|
|
||||||
func Logger() martini.Handler {
|
func Logger() martini.Handler {
|
||||||
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) {
|
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) {
|
||||||
if !base.RouterLog {
|
if base.DisableRouterLog {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,9 +98,36 @@ func updateSystemStatus() {
|
||||||
sysStatus.NumGC = m.NumGC
|
sysStatus.NumGC = m.NumGC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Operation types.
|
||||||
|
const (
|
||||||
|
OT_CLEAN_OAUTH = iota + 1
|
||||||
|
)
|
||||||
|
|
||||||
func Dashboard(ctx *middleware.Context) {
|
func Dashboard(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = "Admin Dashboard"
|
ctx.Data["Title"] = "Admin Dashboard"
|
||||||
ctx.Data["PageIsDashboard"] = true
|
ctx.Data["PageIsDashboard"] = true
|
||||||
|
|
||||||
|
// Run operation.
|
||||||
|
op, _ := base.StrTo(ctx.Query("op")).Int()
|
||||||
|
if op > 0 {
|
||||||
|
var err error
|
||||||
|
var success string
|
||||||
|
|
||||||
|
switch op {
|
||||||
|
case OT_CLEAN_OAUTH:
|
||||||
|
success = "All unbind OAuthes have been deleted."
|
||||||
|
err = models.CleanUnbindOauth()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ctx.Flash.Error(err.Error())
|
||||||
|
} else {
|
||||||
|
ctx.Flash.Success(success)
|
||||||
|
}
|
||||||
|
ctx.Redirect("/admin")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Data["Stats"] = models.GetStatistic()
|
ctx.Data["Stats"] = models.GetStatistic()
|
||||||
updateSystemStatus()
|
updateSystemStatus()
|
||||||
ctx.Data["SysStatus"] = sysStatus
|
ctx.Data["SysStatus"] = sysStatus
|
||||||
|
@ -153,7 +180,7 @@ func Config(ctx *middleware.Context) {
|
||||||
ctx.Data["AppUrl"] = base.AppUrl
|
ctx.Data["AppUrl"] = base.AppUrl
|
||||||
ctx.Data["Domain"] = base.Domain
|
ctx.Data["Domain"] = base.Domain
|
||||||
ctx.Data["OfflineMode"] = base.OfflineMode
|
ctx.Data["OfflineMode"] = base.OfflineMode
|
||||||
ctx.Data["RouterLog"] = base.RouterLog
|
ctx.Data["DisableRouterLog"] = base.DisableRouterLog
|
||||||
ctx.Data["RunUser"] = base.RunUser
|
ctx.Data["RunUser"] = base.RunUser
|
||||||
ctx.Data["RunMode"] = strings.Title(martini.Env)
|
ctx.Data["RunMode"] = strings.Title(martini.Env)
|
||||||
ctx.Data["RepoRootPath"] = base.RepoRootPath
|
ctx.Data["RepoRootPath"] = base.RepoRootPath
|
||||||
|
|
|
@ -295,5 +295,39 @@ func Comment(ctx *middleware.Context, params martini.Params) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify watchers.
|
||||||
|
if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name, ActEmail: ctx.User.Email,
|
||||||
|
OpType: models.OP_COMMENT_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]),
|
||||||
|
RepoId: ctx.Repo.Repository.Id, RepoName: ctx.Repo.Repository.Name, RefName: ""}); err != nil {
|
||||||
|
ctx.Handle(500, "issue.CreateIssue(NotifyWatchers)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mail watchers and mentions.
|
||||||
|
if base.Service.NotifyMail {
|
||||||
|
issue.Content = content
|
||||||
|
tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "issue.Comment(SendIssueNotifyMail)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tos = append(tos, ctx.User.LowerName)
|
||||||
|
ms := base.MentionPattern.FindAllString(issue.Content, -1)
|
||||||
|
newTos := make([]string, 0, len(ms))
|
||||||
|
for _, m := range ms {
|
||||||
|
if com.IsSliceContainsStr(tos, m[1:]) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
newTos = append(newTos, m[1:])
|
||||||
|
}
|
||||||
|
if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner,
|
||||||
|
ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil {
|
||||||
|
ctx.Handle(500, "issue.Comment(SendIssueMentionMail)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index))
|
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index))
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
<dd>{{.Domain}}</dd>
|
<dd>{{.Domain}}</dd>
|
||||||
<dt>Offline Mode</dt>
|
<dt>Offline Mode</dt>
|
||||||
<dd><i class="fa fa{{if .OfflineMode}}-check{{end}}-square-o"></i></dd>
|
<dd><i class="fa fa{{if .OfflineMode}}-check{{end}}-square-o"></i></dd>
|
||||||
<dt>Router Log</dt>
|
<dt>Disable Router Log</dt>
|
||||||
<dd><i class="fa fa{{if .RouterLog}}-check{{end}}-square-o"></i></dd>
|
<dd><i class="fa fa{{if .DisableRouterLog}}-check{{end}}-square-o"></i></dd>
|
||||||
<hr/>
|
<hr/>
|
||||||
<dt>Run User</dt>
|
<dt>Run User</dt>
|
||||||
<dd>{{.RunUser}}</dd>
|
<dd>{{.RunUser}}</dd>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<div id="body" class="container" data-page="admin">
|
<div id="body" class="container" data-page="admin">
|
||||||
{{template "admin/nav" .}}
|
{{template "admin/nav" .}}
|
||||||
<div id="admin-container" class="col-md-10">
|
<div id="admin-container" class="col-md-10">
|
||||||
|
{{template "base/alert" .}}
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
Statistic
|
Statistic
|
||||||
|
@ -13,6 +14,29 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
Operations
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel-body">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Op.</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Clean unbind OAuthes</td>
|
||||||
|
<td><i class="fa fa-caret-square-o-right"></i> <a href="/admin?op=1">Run</a></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
System Monitor Status
|
System Monitor Status
|
||||||
|
|
Loading…
Reference in a new issue