From 2846ff7d31fc93659a2e90fe869ff51c885decfa Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 6 Apr 2014 13:00:20 -0400 Subject: [PATCH 1/7] Fix bug related to log --- .gopmfile | 3 ++- bee.json | 2 ++ modules/base/conf.go | 36 ++++++++++++++--------------------- modules/log/log.go | 2 -- routers/install.go | 5 ++--- update.go | 45 ++++++++++++++++++++++---------------------- web.go | 10 ++++------ 7 files changed, 46 insertions(+), 57 deletions(-) diff --git a/.gopmfile b/.gopmfile index d3f0b3ca3..9bdca49fc 100644 --- a/.gopmfile +++ b/.gopmfile @@ -12,6 +12,8 @@ github.com/nfnt/resize = github.com/lunny/xorm = github.com/go-sql-driver/mysql = github.com/lib/pq = +github.com/qiniu/log = +code.google.com/p/goauth2 = github.com/gogits/logs = github.com/gogits/binding = github.com/gogits/git = @@ -19,7 +21,6 @@ github.com/gogits/gfm = github.com/gogits/cache = github.com/gogits/session = github.com/gogits/webdav = -code.google.com/p/goauth2 = [res] include = templates|public|conf diff --git a/bee.json b/bee.json index 4f7f7a771..ff120f0c9 100644 --- a/bee.json +++ b/bee.json @@ -13,6 +13,8 @@ "others": [ "modules", "$GOPATH/src/github.com/gogits/binding", + "$GOPATH/src/github.com/gogits/webdav", + "$GOPATH/src/github.com/gogits/logs", "$GOPATH/src/github.com/gogits/git", "$GOPATH/src/github.com/gogits/gfm" ] diff --git a/modules/base/conf.go b/modules/base/conf.go index 3ebc4ede1..4a6eec70a 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -14,6 +14,7 @@ import ( "github.com/Unknwon/com" "github.com/Unknwon/goconfig" + qlog "github.com/qiniu/log" "github.com/gogits/cache" "github.com/gogits/session" @@ -105,16 +106,14 @@ func newLogService() { LogMode = Cfg.MustValue("log", "MODE", "console") modeSec := "log." + LogMode if _, err := Cfg.GetSection(modeSec); err != nil { - fmt.Printf("Unknown log mode: %s\n", LogMode) - os.Exit(2) + qlog.Fatalf("Unknown log mode: %s\n", LogMode) } // Log level. levelName := Cfg.MustValue("log."+LogMode, "LEVEL", "Trace") level, ok := logLevels[levelName] if !ok { - fmt.Printf("Unknown log level: %s\n", levelName) - os.Exit(2) + qlog.Fatalf("Unknown log level: %s\n", levelName) } // Generate log configuration. @@ -164,16 +163,14 @@ func newCacheService() { case "redis", "memcache": CacheConfig = fmt.Sprintf(`{"conn":"%s"}`, Cfg.MustValue("cache", "HOST")) default: - fmt.Printf("Unknown cache adapter: %s\n", CacheAdapter) - os.Exit(2) + qlog.Fatalf("Unknown cache adapter: %s\n", CacheAdapter) } var err error Cache, err = cache.NewCache(CacheAdapter, CacheConfig) if err != nil { - fmt.Printf("Init cache system failed, adapter: %s, config: %s, %v\n", + qlog.Fatalf("Init cache system failed, adapter: %s, config: %s, %v\n", CacheAdapter, CacheConfig, err) - os.Exit(2) } log.Info("Cache Service Enabled") @@ -199,9 +196,8 @@ func newSessionService() { var err error SessionManager, err = session.NewManager(SessionProvider, *SessionConfig) if err != nil { - fmt.Printf("Init session system failed, provider: %s, %v\n", + qlog.Fatalf("Init session system failed, provider: %s, %v\n", SessionProvider, err) - os.Exit(2) } log.Info("Session Service Enabled") @@ -246,23 +242,20 @@ func NewConfigContext() { //var err error workDir, err := ExecDir() if err != nil { - fmt.Printf("Fail to get work directory: %s\n", err) - os.Exit(2) + qlog.Fatalf("Fail to get work directory: %s\n", err) } cfgPath := filepath.Join(workDir, "conf/app.ini") Cfg, err = goconfig.LoadConfigFile(cfgPath) if err != nil { - fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err) - os.Exit(2) + qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err) } Cfg.BlockMode = false cfgPath = filepath.Join(workDir, "custom/conf/app.ini") if com.IsFile(cfgPath) { if err = Cfg.AppendFiles(cfgPath); err != nil { - fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err) - os.Exit(2) + qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err) } } @@ -281,8 +274,7 @@ func NewConfigContext() { } // Does not check run user when the install lock is off. if InstallLock && RunUser != curUser { - fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) - os.Exit(2) + qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser) } LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS") @@ -294,14 +286,14 @@ func NewConfigContext() { // Determine and create root git reposiroty path. homeDir, err := com.HomeDir() if err != nil { - fmt.Printf("Fail to get home directory): %v\n", err) - os.Exit(2) + qlog.Fatalf("Fail to get home directory): %v\n", err) } RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "git/gogs-repositories")) if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil { - fmt.Printf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err) - os.Exit(2) + qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err) } + + log.Info("%s %s", AppName, AppVer) } func NewServices() { diff --git a/modules/log/log.go b/modules/log/log.go index 65150237d..f21897b90 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -21,8 +21,6 @@ func init() { func NewLogger(bufLen int64, mode, config string) { Mode, Config = mode, config logger = logs.NewLogger(bufLen) - logger.EnableFuncCallDepth(true) - logger.SetLogFuncCallDepth(4) logger.SetLogger(mode, config) } diff --git a/routers/install.go b/routers/install.go index 48c1b5e13..1c4e6181d 100644 --- a/routers/install.go +++ b/routers/install.go @@ -6,13 +6,13 @@ package routers import ( "errors" - "fmt" "os" "strings" "github.com/Unknwon/goconfig" "github.com/go-martini/martini" "github.com/lunny/xorm" + qlog "github.com/qiniu/log" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" @@ -43,8 +43,7 @@ func GlobalInit() { if base.InstallLock { if err := models.NewEngine(); err != nil { - fmt.Println(err) - os.Exit(2) + qlog.Fatal(err) } models.HasEngine = true diff --git a/update.go b/update.go index 5ccb72fd4..97d924085 100644 --- a/update.go +++ b/update.go @@ -6,7 +6,6 @@ package main import ( "container/list" - "fmt" "os" "os/exec" "path" @@ -14,11 +13,11 @@ import ( "strings" "github.com/codegangsta/cli" + qlog "github.com/qiniu/log" + "github.com/gogits/git" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/log" - //"github.com/qiniu/log" ) var CmdUpdate = cli.Command{ @@ -31,11 +30,15 @@ gogs serv provide access auth for repositories`, } func newUpdateLogger(execDir string) { - level := "0" logPath := execDir + "/log/update.log" os.MkdirAll(path.Dir(logPath), os.ModePerm) - log.NewLogger(0, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, logPath)) - log.Trace("start logging...") + f, err := os.Open(logPath) + if err != nil { + qlog.Fatal(err) + } + + qlog.SetOutput(f) + qlog.Info("Start logging update...") } // for command: ./gogs update @@ -54,14 +57,12 @@ func runUpdate(c *cli.Context) { args := c.Args() if len(args) != 3 { - log.Error("received less 3 parameters") - return + qlog.Fatal("received less 3 parameters") } refName := args[0] if refName == "" { - log.Error("refName is empty, shouldn't use") - return + qlog.Fatal("refName is empty, shouldn't use") } oldCommitId := args[1] newCommitId := args[2] @@ -69,8 +70,7 @@ func runUpdate(c *cli.Context) { isNew := strings.HasPrefix(oldCommitId, "0000000") if isNew && strings.HasPrefix(newCommitId, "0000000") { - log.Error("old rev and new rev both 000000") - return + qlog.Fatal("old rev and new rev both 000000") } userName := os.Getenv("userName") @@ -86,19 +86,18 @@ func runUpdate(c *cli.Context) { repo, err := git.OpenRepository(f) if err != nil { - log.Error("runUpdate.Open repoId: %v", err) - return + qlog.Fatalf("runUpdate.Open repoId: %v", err) } newOid, err := git.NewOidFromString(newCommitId) if err != nil { - log.Error("runUpdate.Ref repoId: %v", err) + qlog.Fatalf("runUpdate.Ref repoId: %v", err) return } newCommit, err := repo.LookupCommit(newOid) if err != nil { - log.Error("runUpdate.Ref repoId: %v", err) + qlog.Fatalf("runUpdate.Ref repoId: %v", err) return } @@ -107,38 +106,38 @@ func runUpdate(c *cli.Context) { if isNew { l, err = repo.CommitsBefore(newCommit.Id()) if err != nil { - log.Error("Find CommitsBefore erro:", err) + qlog.Fatalf("Find CommitsBefore erro:", err) return } } else { oldOid, err := git.NewOidFromString(oldCommitId) if err != nil { - log.Error("runUpdate.Ref repoId: %v", err) + qlog.Fatalf("runUpdate.Ref repoId: %v", err) return } oldCommit, err := repo.LookupCommit(oldOid) if err != nil { - log.Error("runUpdate.Ref repoId: %v", err) + qlog.Fatalf("runUpdate.Ref repoId: %v", err) return } l = repo.CommitsBetween(newCommit, oldCommit) } if err != nil { - log.Error("runUpdate.Commit repoId: %v", err) + qlog.Fatalf("runUpdate.Commit repoId: %v", err) return } sUserId, err := strconv.Atoi(userId) if err != nil { - log.Error("runUpdate.Parse userId: %v", err) + qlog.Fatalf("runUpdate.Parse userId: %v", err) return } repos, err := models.GetRepositoryByName(int64(sUserId), repoName) if err != nil { - log.Error("runUpdate.GetRepositoryByName userId: %v", err) + qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err) return } @@ -163,6 +162,6 @@ func runUpdate(c *cli.Context) { //commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()}) if err = models.CommitRepoAction(int64(sUserId), userName, actEmail, repos.Id, repoName, git.BranchName(refName), &base.PushCommits{l.Len(), commits}); err != nil { - log.Error("runUpdate.models.CommitRepoAction: %v", err) + qlog.Fatalf("runUpdate.models.CommitRepoAction: %v", err) } } diff --git a/web.go b/web.go index cab3dfecc..00fa72cbc 100644 --- a/web.go +++ b/web.go @@ -11,6 +11,7 @@ import ( "github.com/codegangsta/cli" "github.com/go-martini/martini" + qlog "github.com/qiniu/log" "github.com/gogits/binding" @@ -50,9 +51,7 @@ func newMartini() *martini.ClassicMartini { } func runWeb(*cli.Context) { - fmt.Println("Server is running...") routers.GlobalInit() - log.Info("%s %s", base.AppName, base.AppVer) m := newMartini() @@ -147,7 +146,7 @@ func runWeb(*cli.Context) { r.Get("/issues", repo.Issues) r.Get("/issues/:index", repo.ViewIssue) r.Get("/releases", repo.Releases) - r.Any("/releases/new",repo.ReleasesNew) + r.Any("/releases/new", repo.ReleasesNew) r.Get("/pulls", repo.Pulls) r.Get("/branches", repo.Branches) }, ignSignIn, middleware.RepoAssignment(true)) @@ -177,14 +176,13 @@ func runWeb(*cli.Context) { if protocol == "http" { log.Info("Listen: http://%s", listenAddr) if err := http.ListenAndServe(listenAddr, m); err != nil { - fmt.Println(err.Error()) - //log.Critical(err.Error()) // not working now + qlog.Error(err.Error()) } } else if protocol == "https" { log.Info("Listen: https://%s", listenAddr) if err := http.ListenAndServeTLS(listenAddr, base.Cfg.MustValue("server", "CERT_FILE"), base.Cfg.MustValue("server", "KEY_FILE"), m); err != nil { - fmt.Println(err.Error()) + qlog.Error(err.Error()) } } } From 794cd27db3de55cce4c5d3716bf9e60fadaa86bc Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 6 Apr 2014 13:07:34 -0400 Subject: [PATCH 2/7] Fix bug related to log --- gogs.go | 2 +- serve.go | 53 ++++++++++++++++++++++------------------------------- update.go | 8 -------- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/gogs.go b/gogs.go index 13b9d377d..0e48ff7b1 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.2.1.0405 Alpha" +const APP_VER = "0.2.1.0406 Alpha" func init() { base.AppVer = APP_VER diff --git a/serve.go b/serve.go index afc16c281..e7649476d 100644 --- a/serve.go +++ b/serve.go @@ -14,7 +14,7 @@ import ( "strings" "github.com/codegangsta/cli" - "github.com/gogits/gogs/modules/log" + qlog "github.com/qiniu/log" //"github.com/gogits/git" "github.com/gogits/gogs/models" @@ -44,11 +44,15 @@ gogs serv provide access auth for repositories`, } func newLogger(execDir string) { - level := "0" logPath := execDir + "/log/serv.log" os.MkdirAll(path.Dir(logPath), os.ModePerm) - log.NewLogger(0, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, logPath)) - log.Trace("start logging...") + f, err := os.Open(logPath) + if err != nil { + qlog.Fatal(err) + } + + qlog.SetOutput(f) + qlog.Info("Start logging serv...") } func parseCmd(cmd string) (string, string) { @@ -87,21 +91,18 @@ func runServ(k *cli.Context) { keys := strings.Split(os.Args[2], "-") if len(keys) != 2 { println("auth file format error") - log.Error("auth file format error") - return + qlog.Fatal("auth file format error") } keyId, err := strconv.ParseInt(keys[1], 10, 64) if err != nil { println("auth file format error") - log.Error("auth file format error", err) - return + qlog.Fatal("auth file format error", err) } user, err := models.GetUserByKeyId(keyId) if err != nil { println("You have no right to access") - log.Error("SSH visit error: %v", err) - return + qlog.Fatalf("SSH visit error: %v", err) } cmd := os.Getenv("SSH_ORIGINAL_COMMAND") @@ -115,8 +116,7 @@ func runServ(k *cli.Context) { rr := strings.SplitN(repoPath, "/", 2) if len(rr) != 2 { println("Unavilable repository", args) - log.Error("Unavilable repository %v", args) - return + qlog.Fatalf("Unavilable repository %v", args) } repoUserName := rr[0] repoName := rr[1] @@ -129,9 +129,8 @@ func runServ(k *cli.Context) { repoUser, err := models.GetUserByName(repoUserName) if err != nil { - fmt.Println("You have no right to access") - log.Error("Get user failed", err) - return + println("You have no right to access") + qlog.Fatal("Get user failed", err) } // access check @@ -140,19 +139,16 @@ func runServ(k *cli.Context) { has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE) if err != nil { println("Inernel error:", err) - log.Error(err.Error()) - return + qlog.Fatal(err) } else if !has { println("You have no right to write this repository") - log.Error("User %s has no right to write repository %s", user.Name, repoPath) - return + qlog.Fatalf("User %s has no right to write repository %s", user.Name, repoPath) } case isRead: repo, err := models.GetRepositoryByName(repoUser.Id, repoName) if err != nil { println("Get repository error:", err) - log.Error("Get repository error: " + err.Error()) - return + qlog.Fatal("Get repository error: " + err.Error()) } if !repo.IsPrivate { @@ -162,26 +158,22 @@ func runServ(k *cli.Context) { has, err := models.HasAccess(user.Name, repoPath, models.AU_READABLE) if err != nil { println("Inernel error") - log.Error(err.Error()) - return + qlog.Fatal(err) } if !has { has, err = models.HasAccess(user.Name, repoPath, models.AU_WRITABLE) if err != nil { println("Inernel error") - log.Error(err.Error()) - return + qlog.Fatal(err) } } if !has { println("You have no right to access this repository") - log.Error("You have no right to access this repository") - return + qlog.Fatal("You have no right to access this repository") } default: println("Unknown command") - log.Error("Unknown command") - return + qlog.Fatal("Unknown command") } // for update use @@ -197,7 +189,6 @@ func runServ(k *cli.Context) { if err = gitcmd.Run(); err != nil { println("execute command error:", err.Error()) - log.Error("execute command error: " + err.Error()) - return + qlog.Fatal("execute command error: " + err.Error()) } } diff --git a/update.go b/update.go index 97d924085..aae2e7104 100644 --- a/update.go +++ b/update.go @@ -92,13 +92,11 @@ func runUpdate(c *cli.Context) { newOid, err := git.NewOidFromString(newCommitId) if err != nil { qlog.Fatalf("runUpdate.Ref repoId: %v", err) - return } newCommit, err := repo.LookupCommit(newOid) if err != nil { qlog.Fatalf("runUpdate.Ref repoId: %v", err) - return } var l *list.List @@ -107,38 +105,32 @@ func runUpdate(c *cli.Context) { l, err = repo.CommitsBefore(newCommit.Id()) if err != nil { qlog.Fatalf("Find CommitsBefore erro:", err) - return } } else { oldOid, err := git.NewOidFromString(oldCommitId) if err != nil { qlog.Fatalf("runUpdate.Ref repoId: %v", err) - return } oldCommit, err := repo.LookupCommit(oldOid) if err != nil { qlog.Fatalf("runUpdate.Ref repoId: %v", err) - return } l = repo.CommitsBetween(newCommit, oldCommit) } if err != nil { qlog.Fatalf("runUpdate.Commit repoId: %v", err) - return } sUserId, err := strconv.Atoi(userId) if err != nil { qlog.Fatalf("runUpdate.Parse userId: %v", err) - return } repos, err := models.GetRepositoryByName(int64(sUserId), repoName) if err != nil { qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err) - return } commits := make([]*base.PushCommit, 0) From 6a16866f4e0908e62c5e5b30e3dc0ef8e4cb0819 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 6 Apr 2014 13:41:58 -0400 Subject: [PATCH 3/7] Fix bug related to log --- conf/app.ini | 2 +- modules/base/conf.go | 2 +- serve.go | 3 ++- update.go | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index f88c750e0..43033eaa6 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -14,7 +14,7 @@ LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|Artistic License 2.0| [server] PROTOCOL = http DOMAIN = localhost -ROOT_URL = %(PROTOCOL)://%(DOMAIN)s:%(HTTP_PORT)s/ +ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/ HTTP_ADDR = HTTP_PORT = 3000 CERT_FILE = cert.pem diff --git a/modules/base/conf.go b/modules/base/conf.go index 4a6eec70a..4285b5239 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -288,7 +288,7 @@ func NewConfigContext() { if err != nil { qlog.Fatalf("Fail to get home directory): %v\n", err) } - RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "git/gogs-repositories")) + RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories")) if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil { qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err) } diff --git a/serve.go b/serve.go index e7649476d..7e00db473 100644 --- a/serve.go +++ b/serve.go @@ -46,7 +46,8 @@ gogs serv provide access auth for repositories`, func newLogger(execDir string) { logPath := execDir + "/log/serv.log" os.MkdirAll(path.Dir(logPath), os.ModePerm) - f, err := os.Open(logPath) + + f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.ModePerm) if err != nil { qlog.Fatal(err) } diff --git a/update.go b/update.go index aae2e7104..79ce8f524 100644 --- a/update.go +++ b/update.go @@ -32,7 +32,8 @@ gogs serv provide access auth for repositories`, func newUpdateLogger(execDir string) { logPath := execDir + "/log/update.log" os.MkdirAll(path.Dir(logPath), os.ModePerm) - f, err := os.Open(logPath) + + f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.ModePerm) if err != nil { qlog.Fatal(err) } From db1fe3483ed2c8c0962ee4395073e0b190310602 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 6 Apr 2014 13:54:48 -0400 Subject: [PATCH 4/7] Fix bug related to log --- modules/base/conf.go | 3 +-- update.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/base/conf.go b/modules/base/conf.go index 4285b5239..0a618ab1d 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -150,6 +150,7 @@ func newLogService() { Cfg.MustValue(modeSec, "CONN")) } + log.Info("%s %s", AppName, AppVer) log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), LogMode, LogConfig) log.Info("Log Mode: %s(%s)", strings.Title(LogMode), levelName) } @@ -292,8 +293,6 @@ func NewConfigContext() { if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil { qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err) } - - log.Info("%s %s", AppName, AppVer) } func NewServices() { diff --git a/update.go b/update.go index 79ce8f524..c9cbb35b9 100644 --- a/update.go +++ b/update.go @@ -45,7 +45,7 @@ func newUpdateLogger(execDir string) { // for command: ./gogs update func runUpdate(c *cli.Context) { execDir, _ := base.ExecDir() - newLogger(execDir) + newUpdateLogger(execDir) base.NewConfigContext() models.LoadModelsConfig() From e7c8a3cb8d26da68b09f799585c03970cd243be1 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 6 Apr 2014 16:10:57 -0400 Subject: [PATCH 5/7] Add salt for every single user --- .gopmfile | 1 - README.md | 4 ++-- README_ZH.md | 2 +- gogs.go | 2 +- models/user.go | 31 ++++++++++++++++--------------- modules/base/tool.go | 40 ++++++++++++++++++++++++++++++++++++++++ routers/user/setting.go | 7 ++----- routers/user/user.go | 7 ++----- 8 files changed, 64 insertions(+), 30 deletions(-) diff --git a/.gopmfile b/.gopmfile index 9bdca49fc..c9fad8a03 100644 --- a/.gopmfile +++ b/.gopmfile @@ -7,7 +7,6 @@ github.com/go-martini/martini = github.com/Unknwon/com = github.com/Unknwon/cae = github.com/Unknwon/goconfig = -github.com/dchest/scrypt = github.com/nfnt/resize = github.com/lunny/xorm = github.com/go-sql-driver/mysql = diff --git a/README.md b/README.md index ede1894ad..fe15328b1 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.2.1 Alpha +##### Current version: 0.2.2 Alpha -#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in March 29, 2014 and will reset multiple times after. Please do NOT put your important data on the site. +#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site. #### Other language version diff --git a/README_ZH.md b/README_ZH.md index 9b5e46413..015ee0af9 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。 ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.2.1 Alpha +##### 当前版本:0.2.2 Alpha ## 开发目的 diff --git a/gogs.go b/gogs.go index 0e48ff7b1..e71974820 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.2.1.0406 Alpha" +const APP_VER = "0.2.2.0406 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/user.go b/models/user.go index 2196eae84..a5a6de097 100644 --- a/models/user.go +++ b/models/user.go @@ -5,6 +5,7 @@ package models import ( + "crypto/sha256" "encoding/hex" "errors" "fmt" @@ -13,8 +14,6 @@ import ( "strings" "time" - "github.com/dchest/scrypt" - "github.com/gogits/git" "github.com/gogits/gogs/modules/base" @@ -62,6 +61,7 @@ type User struct { IsActive bool IsAdmin bool Rands string `xorm:"VARCHAR(10)"` + Salt string `xorm:"VARCHAR(10)"` Created time.Time `xorm:"created"` Updated time.Time `xorm:"updated"` } @@ -89,10 +89,9 @@ func (user *User) NewGitSig() *git.Signature { } // EncodePasswd encodes password to safe format. -func (user *User) EncodePasswd() error { - newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte(base.SecretKey), 16384, 8, 1, 64) +func (user *User) EncodePasswd() { + newPasswd := base.PBKDF2([]byte(user.Passwd), []byte(user.Salt), 10000, 50, sha256.New) user.Passwd = fmt.Sprintf("%x", newPasswd) - return err } // Member represents user is member of organization. @@ -148,9 +147,9 @@ func RegisterUser(user *User) (*User, error) { user.Avatar = base.EncodeMd5(user.Email) user.AvatarEmail = user.Email user.Rands = GetUserSalt() - if err = user.EncodePasswd(); err != nil { - return nil, err - } else if _, err = orm.Insert(user); err != nil { + user.Salt = GetUserSalt() + user.EncodePasswd() + if _, err = orm.Insert(user); err != nil { return nil, err } else if err = os.MkdirAll(UserPath(user.Name), os.ModePerm); err != nil { if _, err := orm.Id(user.Id).Delete(&User{}); err != nil { @@ -384,18 +383,20 @@ func GetUserByEmail(email string) (*User, error) { // LoginUserPlain validates user by raw user name and password. func LoginUserPlain(name, passwd string) (*User, error) { - user := User{LowerName: strings.ToLower(name), Passwd: passwd} - if err := user.EncodePasswd(); err != nil { - return nil, err - } - + user := User{LowerName: strings.ToLower(name)} has, err := orm.Get(&user) if err != nil { return nil, err } else if !has { - err = ErrUserNotExist + return nil, ErrUserNotExist } - return &user, err + + newUser := &User{Passwd: passwd, Salt: user.Salt} + newUser.EncodePasswd() + if user.Passwd != newUser.Passwd { + return nil, ErrUserNotExist + } + return &user, nil } // Follow is connection request for receiving user notifycation. diff --git a/modules/base/tool.go b/modules/base/tool.go index 3946c4b56..f7d1bc2c5 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -6,12 +6,14 @@ package base import ( "bytes" + "crypto/hmac" "crypto/md5" "crypto/rand" "crypto/sha1" "encoding/hex" "encoding/json" "fmt" + "hash" "math" "strconv" "strings" @@ -40,6 +42,44 @@ func GetRandomString(n int, alphabets ...byte) string { return string(bytes) } +// http://code.google.com/p/go/source/browse/pbkdf2/pbkdf2.go?repo=crypto +func PBKDF2(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte { + prf := hmac.New(h, password) + hashLen := prf.Size() + numBlocks := (keyLen + hashLen - 1) / hashLen + + var buf [4]byte + dk := make([]byte, 0, numBlocks*hashLen) + U := make([]byte, hashLen) + for block := 1; block <= numBlocks; block++ { + // N.B.: || means concatenation, ^ means XOR + // for each block T_i = U_1 ^ U_2 ^ ... ^ U_iter + // U_1 = PRF(password, salt || uint(i)) + prf.Reset() + prf.Write(salt) + buf[0] = byte(block >> 24) + buf[1] = byte(block >> 16) + buf[2] = byte(block >> 8) + buf[3] = byte(block) + prf.Write(buf[:4]) + dk = prf.Sum(dk) + T := dk[len(dk)-hashLen:] + copy(U, T) + + // U_n = PRF(password, U_(n-1)) + for n := 2; n <= iter; n++ { + prf.Reset() + prf.Write(U) + U = U[:0] + U = prf.Sum(U) + for x := range U { + T[x] ^= U[x] + } + } + } + return dk[:keyLen] +} + // verify time limit code func VerifyTimeLimitCode(data string, minutes int, code string) bool { if len(code) <= 18 { diff --git a/routers/user/setting.go b/routers/user/setting.go index 4b6d88a36..ea779e854 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -73,11 +73,7 @@ func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) { user := ctx.User newUser := &models.User{Passwd: form.NewPasswd} - if err := newUser.EncodePasswd(); err != nil { - ctx.Handle(200, "setting.SettingPassword", err) - return - } - + newUser.EncodePasswd() if user.Passwd != newUser.Passwd { ctx.Data["HasError"] = true ctx.Data["ErrorMsg"] = "Old password is not correct" @@ -85,6 +81,7 @@ func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) { ctx.Data["HasError"] = true ctx.Data["ErrorMsg"] = "New password and re-type password are not same" } else { + newUser.Salt = models.GetUserSalt() user.Passwd = newUser.Passwd if err := models.UpdateUser(user); err != nil { ctx.Handle(200, "setting.SettingPassword", err) diff --git a/routers/user/user.go b/routers/user/user.go index 872ed0d60..12f2bd8c5 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -477,12 +477,9 @@ func ResetPasswd(ctx *middleware.Context) { } u.Passwd = passwd - if err := u.EncodePasswd(); err != nil { - ctx.Handle(404, "user.ResetPasswd(EncodePasswd)", err) - return - } - u.Rands = models.GetUserSalt() + u.Salt = models.GetUserSalt() + u.EncodePasswd() if err := models.UpdateUser(u); err != nil { ctx.Handle(404, "user.ResetPasswd(UpdateUser)", err) return From e2fe2209057b90e6c78a84b7c66c3395cf100e30 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 7 Apr 2014 00:47:19 -0400 Subject: [PATCH 6/7] Work on comment --- modules/base/markdown.go | 27 +++++++++- modules/base/template.go | 106 +++++++++++++++++++++++++++++++++++++++ modules/base/tool.go | 106 --------------------------------------- 3 files changed, 131 insertions(+), 108 deletions(-) diff --git a/modules/base/markdown.go b/modules/base/markdown.go index 962e1ae1e..828f87de5 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -6,9 +6,11 @@ package base import ( "bytes" + "fmt" "net/http" "path" "path/filepath" + "regexp" "strings" "github.com/gogits/gfm" @@ -87,7 +89,28 @@ func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte, options.Renderer.Link(out, link, title, content) } +var ( + mentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) + commitPattern = regexp.MustCompile(`[^>]http[s]{0,}.*commit/[0-9a-zA-Z]{1,}`) +) + +func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { + ms := mentionPattern.FindAll(rawBytes, -1) + for _, m := range ms { + rawBytes = bytes.Replace(rawBytes, m, + []byte(fmt.Sprintf(`%s`, m[1:], m)), -1) + } + ms = commitPattern.FindAll(rawBytes, -1) + for _, m := range ms { + rawBytes = bytes.Replace(rawBytes, m, + []byte(fmt.Sprintf(`%s`, m, m)), -1) + } + return rawBytes +} + func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { + body := RenderSpecialLink(rawBytes, urlPrefix) + fmt.Println(string(body)) htmlFlags := 0 // htmlFlags |= gfm.HTML_USE_XHTML // htmlFlags |= gfm.HTML_USE_SMARTYPANTS @@ -115,7 +138,7 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { extensions |= gfm.EXTENSION_SPACE_HEADERS extensions |= gfm.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK - body := gfm.Markdown(rawBytes, renderer, extensions) - + body = gfm.Markdown(body, renderer, extensions) + fmt.Println(string(body)) return body } diff --git a/modules/base/template.go b/modules/base/template.go index 56b77a5d6..6cd8ade61 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -5,7 +5,9 @@ package base import ( + "bytes" "container/list" + "encoding/json" "fmt" "html/template" "strings" @@ -85,3 +87,107 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "DiffLineTypeToStr": DiffLineTypeToStr, "ShortSha": ShortSha, } + +type Actioner interface { + GetOpType() int + GetActUserName() string + GetActEmail() string + GetRepoName() string + GetBranch() string + GetContent() string +} + +// ActionIcon accepts a int that represents action operation type +// and returns a icon class name. +func ActionIcon(opType int) string { + switch opType { + case 1: // Create repository. + return "plus-circle" + case 5: // Commit repository. + return "arrow-circle-o-right" + case 6: // Create issue. + return "exclamation-circle" + case 8: // Transfer repository. + return "share" + default: + return "invalid type" + } +} + +const ( + TPL_CREATE_REPO = `%s created repository %s` + TPL_COMMIT_REPO = `%s pushed to %s at %s%s` + TPL_COMMIT_REPO_LI = `
user-avatar %s %s
` + TPL_CREATE_ISSUE = `%s opened issue %s#%s +
user-avatar %s
` + TPL_TRANSFER_REPO = `%s transfered repository %s to %s` +) + +type PushCommit struct { + Sha1 string + Message string + AuthorEmail string + AuthorName string +} + +type PushCommits struct { + Len int + Commits []*PushCommit +} + +// ActionDesc accepts int that represents action operation type +// and returns the description. +func ActionDesc(act Actioner) string { + actUserName := act.GetActUserName() + email := act.GetActEmail() + repoName := act.GetRepoName() + repoLink := actUserName + "/" + repoName + branch := act.GetBranch() + content := act.GetContent() + switch act.GetOpType() { + case 1: // Create repository. + return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, repoLink, repoName) + case 5: // Commit repository. + var push *PushCommits + if err := json.Unmarshal([]byte(content), &push); err != nil { + return err.Error() + } + buf := bytes.NewBuffer([]byte("\n")) + for _, commit := range push.Commits { + buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") + } + if push.Len > 3 { + buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len)) + } + return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, + buf.String()) + case 6: // Create issue. + infos := strings.SplitN(content, "|", 2) + return fmt.Sprintf(TPL_CREATE_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], + AvatarLink(email), infos[1]) + case 8: // Transfer repository. + newRepoLink := content + "/" + repoName + return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink) + default: + return "invalid type" + } +} + +func DiffTypeToStr(diffType int) string { + diffTypes := map[int]string{ + 1: "add", 2: "modify", 3: "del", + } + return diffTypes[diffType] +} + +func DiffLineTypeToStr(diffType int) string { + switch diffType { + case 2: + return "add" + case 3: + return "del" + case 4: + return "tag" + } + return "same" +} diff --git a/modules/base/tool.go b/modules/base/tool.go index f7d1bc2c5..0f06b3e0e 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -5,13 +5,11 @@ package base import ( - "bytes" "crypto/hmac" "crypto/md5" "crypto/rand" "crypto/sha1" "encoding/hex" - "encoding/json" "fmt" "hash" "math" @@ -514,107 +512,3 @@ func (a argInt) Get(i int, args ...int) (r int) { } return } - -type Actioner interface { - GetOpType() int - GetActUserName() string - GetActEmail() string - GetRepoName() string - GetBranch() string - GetContent() string -} - -// ActionIcon accepts a int that represents action operation type -// and returns a icon class name. -func ActionIcon(opType int) string { - switch opType { - case 1: // Create repository. - return "plus-circle" - case 5: // Commit repository. - return "arrow-circle-o-right" - case 6: // Create issue. - return "exclamation-circle" - case 8: // Transfer repository. - return "share" - default: - return "invalid type" - } -} - -const ( - TPL_CREATE_REPO = `%s created repository %s` - TPL_COMMIT_REPO = `%s pushed to %s at %s%s` - TPL_COMMIT_REPO_LI = `
user-avatar %s %s
` - TPL_CREATE_ISSUE = `%s opened issue %s#%s -
user-avatar %s
` - TPL_TRANSFER_REPO = `%s transfered repository %s to %s` -) - -type PushCommit struct { - Sha1 string - Message string - AuthorEmail string - AuthorName string -} - -type PushCommits struct { - Len int - Commits []*PushCommit -} - -// ActionDesc accepts int that represents action operation type -// and returns the description. -func ActionDesc(act Actioner) string { - actUserName := act.GetActUserName() - email := act.GetActEmail() - repoName := act.GetRepoName() - repoLink := actUserName + "/" + repoName - branch := act.GetBranch() - content := act.GetContent() - switch act.GetOpType() { - case 1: // Create repository. - return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, repoLink, repoName) - case 5: // Commit repository. - var push *PushCommits - if err := json.Unmarshal([]byte(content), &push); err != nil { - return err.Error() - } - buf := bytes.NewBuffer([]byte("\n")) - for _, commit := range push.Commits { - buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") - } - if push.Len > 3 { - buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len)) - } - return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, - buf.String()) - case 6: // Create issue. - infos := strings.SplitN(content, "|", 2) - return fmt.Sprintf(TPL_CREATE_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], - AvatarLink(email), infos[1]) - case 8: // Transfer repository. - newRepoLink := content + "/" + repoName - return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink) - default: - return "invalid type" - } -} - -func DiffTypeToStr(diffType int) string { - diffTypes := map[int]string{ - 1: "add", 2: "modify", 3: "del", - } - return diffTypes[diffType] -} - -func DiffLineTypeToStr(diffType int) string { - switch diffType { - case 2: - return "add" - case 3: - return "del" - case 4: - return "tag" - } - return "same" -} From 8c9a0494ecb477a641c07be68a9c0cb8fa661d29 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 7 Apr 2014 01:55:22 -0400 Subject: [PATCH 7/7] Add @ # commit link detect on all markdown render --- modules/base/markdown.go | 45 +++++++++++++++++++++++++-------- routers/api/v1/miscellaneous.go | 2 +- routers/repo/issue.go | 8 +++--- templates/issue/view.tmpl | 2 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/modules/base/markdown.go b/modules/base/markdown.go index 828f87de5..f0992d04d 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -90,8 +90,10 @@ func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte, } var ( - mentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) - commitPattern = regexp.MustCompile(`[^>]http[s]{0,}.*commit/[0-9a-zA-Z]{1,}`) + mentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) + commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`) + issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`) + issueIndexPattern = regexp.MustCompile(`(\s|^)#[0-9]+`) ) func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { @@ -102,8 +104,31 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { } ms = commitPattern.FindAll(rawBytes, -1) for _, m := range ms { - rawBytes = bytes.Replace(rawBytes, m, - []byte(fmt.Sprintf(`%s`, m, m)), -1) + m = bytes.TrimPrefix(m, []byte(" ")) + i := strings.Index(string(m), "commit/") + j := strings.Index(string(m), "#") + if j == -1 { + j = len(m) + } + rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( + ` %s`, m, ShortSha(string(m[i+7:j])))), -1) + } + ms = issueFullPattern.FindAll(rawBytes, -1) + for _, m := range ms { + m = bytes.TrimPrefix(m, []byte(" ")) + i := strings.Index(string(m), "issues/") + j := strings.Index(string(m), "#") + if j == -1 { + j = len(m) + } + rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( + ` #%s`, m, ShortSha(string(m[i+7:j])))), -1) + } + ms = issueIndexPattern.FindAll(rawBytes, -1) + for _, m := range ms { + m = bytes.TrimPrefix(m, []byte(" ")) + rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( + ` %s`, urlPrefix, m[1:], m)), -1) } return rawBytes } @@ -122,10 +147,10 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { htmlFlags |= gfm.HTML_GITHUB_BLOCKCODE htmlFlags |= gfm.HTML_OMIT_CONTENTS // htmlFlags |= gfm.HTML_COMPLETE_PAGE - renderer := &CustomRender{ - Renderer: gfm.HtmlRenderer(htmlFlags, "", ""), - urlPrefix: urlPrefix, - } + // renderer := &CustomRender{ + // Renderer: gfm.HtmlRenderer(htmlFlags, "", ""), + // urlPrefix: urlPrefix, + // } // set up the parser extensions := 0 @@ -138,7 +163,7 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { extensions |= gfm.EXTENSION_SPACE_HEADERS extensions |= gfm.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK - body = gfm.Markdown(body, renderer, extensions) - fmt.Println(string(body)) + // body = gfm.Markdown(body, renderer, extensions) + // fmt.Println(string(body)) return body } diff --git a/routers/api/v1/miscellaneous.go b/routers/api/v1/miscellaneous.go index 0ff1eb04a..babdfce9b 100644 --- a/routers/api/v1/miscellaneous.go +++ b/routers/api/v1/miscellaneous.go @@ -13,6 +13,6 @@ func Markdown(ctx *middleware.Context) { content := ctx.Query("content") ctx.Render.JSON(200, map[string]interface{}{ "ok": true, - "content": string(base.RenderMarkdown([]byte(content), "")), + "content": string(base.RenderMarkdown([]byte(content), ctx.Query("repoLink"))), }) } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index be9254264..38522e0c7 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -147,7 +147,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { return } issue.Poster = u - issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), "")) + issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink)) // Get comments. comments, err := models.GetIssueComments(issue.Id) @@ -164,7 +164,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { return } comments[i].Poster = u - comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), "")) + comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ctx.Repo.RepoLink)) } ctx.Data["Title"] = issue.Name @@ -193,7 +193,7 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat return } - if ctx.User.Id != issue.PosterId { + if ctx.User.Id != issue.PosterId && !ctx.Repo.IsOwner { ctx.Handle(404, "issue.UpdateIssue", nil) return } @@ -211,7 +211,7 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat ctx.JSON(200, map[string]interface{}{ "ok": true, "title": issue.Name, - "content": string(base.RenderMarkdown([]byte(issue.Content), "")), + "content": string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink)), }) } diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index e619451cc..16d60d358 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -72,7 +72,7 @@