|
@@ -11,7 +11,6 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"github.com/json-iterator/go"
|
|
|
- "github.com/unknwon/com"
|
|
|
|
|
|
"gogs.io/gogs/internal/conf"
|
|
|
"gogs.io/gogs/internal/context"
|
|
@@ -110,63 +109,11 @@ func updateSystemStatus() {
|
|
|
sysStatus.NumGC = m.NumGC
|
|
|
}
|
|
|
|
|
|
-// Operation types.
|
|
|
-type AdminOperation int
|
|
|
-
|
|
|
-const (
|
|
|
- CLEAN_INACTIVATE_USER AdminOperation = iota + 1
|
|
|
- CLEAN_REPO_ARCHIVES
|
|
|
- CLEAN_MISSING_REPOS
|
|
|
- GIT_GC_REPOS
|
|
|
- SYNC_SSH_AUTHORIZED_KEY
|
|
|
- SYNC_REPOSITORY_HOOKS
|
|
|
- REINIT_MISSING_REPOSITORY
|
|
|
-)
|
|
|
-
|
|
|
func Dashboard(c *context.Context) {
|
|
|
c.Title("admin.dashboard")
|
|
|
c.PageIs("Admin")
|
|
|
c.PageIs("AdminDashboard")
|
|
|
|
|
|
- // Run operation.
|
|
|
- op, _ := com.StrTo(c.Query("op")).Int()
|
|
|
- if op > 0 {
|
|
|
- var err error
|
|
|
- var success string
|
|
|
-
|
|
|
- switch AdminOperation(op) {
|
|
|
- case CLEAN_INACTIVATE_USER:
|
|
|
- success = c.Tr("admin.dashboard.delete_inactivate_accounts_success")
|
|
|
- err = db.DeleteInactivateUsers()
|
|
|
- case CLEAN_REPO_ARCHIVES:
|
|
|
- success = c.Tr("admin.dashboard.delete_repo_archives_success")
|
|
|
- err = db.DeleteRepositoryArchives()
|
|
|
- case CLEAN_MISSING_REPOS:
|
|
|
- success = c.Tr("admin.dashboard.delete_missing_repos_success")
|
|
|
- err = db.DeleteMissingRepositories()
|
|
|
- case GIT_GC_REPOS:
|
|
|
- success = c.Tr("admin.dashboard.git_gc_repos_success")
|
|
|
- err = db.GitGcRepos()
|
|
|
- case SYNC_SSH_AUTHORIZED_KEY:
|
|
|
- success = c.Tr("admin.dashboard.resync_all_sshkeys_success")
|
|
|
- err = db.RewriteAuthorizedKeys()
|
|
|
- case SYNC_REPOSITORY_HOOKS:
|
|
|
- success = c.Tr("admin.dashboard.resync_all_hooks_success")
|
|
|
- err = db.SyncRepositoryHooks()
|
|
|
- case REINIT_MISSING_REPOSITORY:
|
|
|
- success = c.Tr("admin.dashboard.reinit_missing_repos_success")
|
|
|
- err = db.ReinitMissingRepositories()
|
|
|
- }
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- c.Flash.Error(err.Error())
|
|
|
- } else {
|
|
|
- c.Flash.Success(success)
|
|
|
- }
|
|
|
- c.RedirectSubpath("/admin")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
c.Data["GitVersion"] = conf.Git.Version
|
|
|
c.Data["GoVersion"] = runtime.Version()
|
|
|
c.Data["BuildTime"] = conf.BuildTime
|
|
@@ -179,6 +126,55 @@ func Dashboard(c *context.Context) {
|
|
|
c.Success(DASHBOARD)
|
|
|
}
|
|
|
|
|
|
+// Operation types.
|
|
|
+type AdminOperation int
|
|
|
+
|
|
|
+const (
|
|
|
+ CleanInactivateUser AdminOperation = iota + 1
|
|
|
+ CleanRepoArchives
|
|
|
+ CleanMissingRepos
|
|
|
+ GitGCRepos
|
|
|
+ SyncSSHAuthorizedKey
|
|
|
+ SyncRepositoryHooks
|
|
|
+ ReinitMissingRepository
|
|
|
+)
|
|
|
+
|
|
|
+func Operation(c *context.Context) {
|
|
|
+ var err error
|
|
|
+ var success string
|
|
|
+ switch AdminOperation(c.QueryInt("op")) {
|
|
|
+ case CleanInactivateUser:
|
|
|
+ success = c.Tr("admin.dashboard.delete_inactivate_accounts_success")
|
|
|
+ err = db.DeleteInactivateUsers()
|
|
|
+ case CleanRepoArchives:
|
|
|
+ success = c.Tr("admin.dashboard.delete_repo_archives_success")
|
|
|
+ err = db.DeleteRepositoryArchives()
|
|
|
+ case CleanMissingRepos:
|
|
|
+ success = c.Tr("admin.dashboard.delete_missing_repos_success")
|
|
|
+ err = db.DeleteMissingRepositories()
|
|
|
+ case GitGCRepos:
|
|
|
+ success = c.Tr("admin.dashboard.git_gc_repos_success")
|
|
|
+ err = db.GitGcRepos()
|
|
|
+ case SyncSSHAuthorizedKey:
|
|
|
+ success = c.Tr("admin.dashboard.resync_all_sshkeys_success")
|
|
|
+ err = db.RewriteAuthorizedKeys()
|
|
|
+ case SyncRepositoryHooks:
|
|
|
+ success = c.Tr("admin.dashboard.resync_all_hooks_success")
|
|
|
+ err = db.SyncRepositoryHooks()
|
|
|
+ case ReinitMissingRepository:
|
|
|
+ success = c.Tr("admin.dashboard.reinit_missing_repos_success")
|
|
|
+ err = db.ReinitMissingRepositories()
|
|
|
+ }
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.Flash.Error(err.Error())
|
|
|
+ } else {
|
|
|
+ c.Flash.Success(success)
|
|
|
+ }
|
|
|
+ c.RedirectSubpath("/admin")
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func SendTestMail(c *context.Context) {
|
|
|
emailAddr := c.Query("email")
|
|
|
// Send a test email to the user's email address and redirect back to Config
|