Check run user

release/v1.15
Unknown 2014-03-25 06:52:56 -04:00
parent 6ef3e8b3c9
commit eeb793524f
4 changed files with 15 additions and 29 deletions

View File

@ -1,8 +1,8 @@
; App name that shows on every page title ; App name that shows on every page title
APP_NAME = Gogs: Go Git Service APP_NAME = Gogs: Go Git Service
APP_LOGO = img/favicon.png APP_LOGO = img/favicon.png
; !!MUST CHANGE TO YOUR USER NAME!! ; Check it if you run locally
RUN_USER = lunny RUN_USER = git
; Either "dev", "prod" or "test", default is "dev" ; Either "dev", "prod" or "test", default is "dev"
RUN_MODE = dev RUN_MODE = dev

15
gogs.go
View File

@ -7,7 +7,6 @@ package main
import ( import (
"os" "os"
// "os/user"
"runtime" "runtime"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
@ -27,21 +26,7 @@ func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
} }
// func checkRunUser() bool {
// u, err := user.Current()
// if err != nil {
// // TODO: log
// return false
// }
// return u.Username == base.Cfg.MustValue("", "RUN_USER")
// }
func main() { func main() {
/*if !checkRunUser() {
println("The command should be run as", base.Cfg.MustValue("", "RUN_USER"))
return
}*/
app := cli.NewApp() app := cli.NewApp()
app.Name = "Gogs" app.Name = "Gogs"
app.Usage = "Go Git Service" app.Usage = "Go Git Service"

View File

@ -259,16 +259,11 @@ func NewConfigContext() {
Cfg.BlockMode = false Cfg.BlockMode = false
cfgPath = filepath.Join(workDir, "custom/conf/app.ini") cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
if !com.IsFile(cfgPath) { if com.IsFile(cfgPath) {
fmt.Println("Custom configuration not found(custom/conf/app.ini)\n" + if err = Cfg.AppendFiles(cfgPath); err != nil {
"Please create it and make your own configuration!") fmt.Printf("Cannot load config file '%s'\n", cfgPath)
os.Exit(2) os.Exit(2)
}
}
if err = Cfg.AppendFiles(cfgPath); err != nil {
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
os.Exit(2)
} }
AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service") AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
@ -276,7 +271,13 @@ func NewConfigContext() {
AppUrl = Cfg.MustValue("server", "ROOT_URL") AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN") Domain = Cfg.MustValue("server", "DOMAIN")
SecretKey = Cfg.MustValue("security", "SECRET_KEY") SecretKey = Cfg.MustValue("security", "SECRET_KEY")
RunUser = Cfg.MustValue("", "RUN_USER") RunUser = Cfg.MustValue("", "RUN_USER")
curUser := os.Getenv("USERNAME")
if RunUser != curUser {
fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
os.Exit(2)
}
EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false) EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false)

View File

@ -6,9 +6,9 @@
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item"><a href="/user/setting">Account Profile</a></li> <li class="list-group-item"><a href="/user/setting">Account Profile</a></li>
<li class="list-group-item"><a href="/user/setting/password">Password</a></li> <li class="list-group-item"><a href="/user/setting/password">Password</a></li>
<li class="list-group-item"><a href="/user/setting/notification">Notifications</a></li> <!-- <li class="list-group-item"><a href="/user/setting/notification">Notifications</a></li> -->
<li class="list-group-item"><a href="/user/setting/ssh/">SSH Keys</a></li> <li class="list-group-item"><a href="/user/setting/ssh/">SSH Keys</a></li>
<li class="list-group-item"><a href="/user/setting/security">Security</a></li> <!-- <li class="list-group-item"><a href="/user/setting/security">Security</a></li> -->
<li class="list-group-item list-group-item-success"><a href="/user/delete">Delete Account</a></li> <li class="list-group-item list-group-item-success"><a href="/user/delete">Delete Account</a></li>
</ul> </ul>
</div> </div>