m := martini.New()
m.Use(middleware.Logger())
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.Action(r.Handle)
return &martini.ClassicMartini{m, r}
HTTP_PORT = 3000
; Disable CDN even in "prod" mode
OFFLINE_MODE = false
-ROUTER_LOG = true
+DISABLE_ROUTER_LOG = false
; Generate steps:
; $ cd path/to/gogs/custom/https
; $ go run $GOROOT/src/pkg/crypto/tls/generate_cert.go -ca=true -duration=8760h0m0s -host=myhost.example.com
OP_PULL_REQUEST
OP_TRANSFER_REPO
OP_PUSH_TAG
+ OP_COMMENT_ISSUE
)
// Action represents user operation type and other information to repository.,
// it implemented interface base.Actioner so that can be used in template render.
type Action struct {
Id int64
- UserId int64 // Receiver user id.
- OpType int // Operations: CREATE DELETE STAR ...
+ UserId int64 // Receiver user id.
+ OpType int
ActUserId int64 // Action user id.
ActUserName string // Action user name.
ActEmail string
_, err := orm.Delete(&Oauth2{Id: id})
return err
}
+
+// CleanUnbindOauth deletes all unbind OAuthes.
+func CleanUnbindOauth() error {
+ _, err := orm.Delete(&Oauth2{Uid: -1})
+ return err
+}
}
var (
- AppVer string
- AppName string
- AppLogo string
- AppUrl string
- OfflineMode bool
- RouterLog bool
- ProdMode bool
- Domain string
- SecretKey string
- RunUser string
+ AppVer string
+ AppName string
+ AppLogo string
+ AppUrl string
+ OfflineMode bool
+ DisableRouterLog bool
+ ProdMode bool
+ Domain string
+ SecretKey string
+ RunUser string
RepoRootPath string
ScriptType string
AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN")
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")
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
return "exclamation-circle"
case 8: // Transfer repository.
return "share"
+ case 10: // Comment issue.
+ return "comment"
default:
return "invalid type"
}
<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_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 {
return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink)
case 9: // Push tag.
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:
return "invalid type"
}
log.Error("hooks.handleQueue: Fail to deliver hook: %v", err)
continue
}
- log.Info("Hook delivered")
+ log.Info("Hook delivered: %s", string(data))
}
}
}
func Logger() martini.Handler {
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) {
- if !base.RouterLog {
+ if base.DisableRouterLog {
return
}
sysStatus.NumGC = m.NumGC
}
+// Operation types.
+const (
+ OT_CLEAN_OAUTH = iota + 1
+)
+
func Dashboard(ctx *middleware.Context) {
ctx.Data["Title"] = "Admin Dashboard"
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()
updateSystemStatus()
ctx.Data["SysStatus"] = sysStatus
ctx.Data["AppUrl"] = base.AppUrl
ctx.Data["Domain"] = base.Domain
ctx.Data["OfflineMode"] = base.OfflineMode
- ctx.Data["RouterLog"] = base.RouterLog
+ ctx.Data["DisableRouterLog"] = base.DisableRouterLog
ctx.Data["RunUser"] = base.RunUser
ctx.Data["RunMode"] = strings.Title(martini.Env)
ctx.Data["RepoRootPath"] = base.RepoRootPath
}
}
+ // 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))
}
<dd>{{.Domain}}</dd>
<dt>Offline Mode</dt>
<dd><i class="fa fa{{if .OfflineMode}}-check{{end}}-square-o"></i></dd>
- <dt>Router Log</dt>
- <dd><i class="fa fa{{if .RouterLog}}-check{{end}}-square-o"></i></dd>
+ <dt>Disable Router Log</dt>
+ <dd><i class="fa fa{{if .DisableRouterLog}}-check{{end}}-square-o"></i></dd>
<hr/>
<dt>Run User</dt>
<dd>{{.RunUser}}</dd>
<div id="body" class="container" data-page="admin">
{{template "admin/nav" .}}
<div id="admin-container" class="col-md-10">
+ {{template "base/alert" .}}
<div class="panel panel-default">
<div class="panel-heading">
Statistic
</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-heading">
System Monitor Status