diff --git a/main.go b/main.go index 43072473..e8428a52 100644 --- a/main.go +++ b/main.go @@ -28,9 +28,9 @@ var buildversion string // RunServer runs webapp mainloop func RunServer(conf *config.Config) { // TODO Use config from cli - os.Mkdir(router.DatabaseDumpPath, 700) + os.Mkdir(router.DatabaseDumpPath, 0700) // TODO Use config from cli - os.Mkdir(router.GPGPublicKeyPath, 700) + os.Mkdir(router.GPGPublicKeyPath, 0700) http.Handle("/", router.CSRFRouter) diff --git a/public/css/main.css b/public/css/main.css index 2aea82b7..a47d36bc 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -965,3 +965,7 @@ input.filelist-checkbox:checked + table.table-filelist { input.nav-btn { cursor: pointer; } + +.comment-captcha { + width: 240px; +} \ No newline at end of file diff --git a/router/database_dump_handler.go b/router/database_dump_handler.go index be88d1e3..fee8b63f 100644 --- a/router/database_dump_handler.go +++ b/router/database_dump_handler.go @@ -24,7 +24,7 @@ func DatabaseDumpHandler(w http.ResponseWriter, r *http.Request) { // db params url var err error // TODO Use config from cli - files, err := filepath.Glob(filepath.Join(DatabaseDumpPath, "*.torrent")) + files, _ := filepath.Glob(filepath.Join(DatabaseDumpPath, "*.torrent")) defer r.Body.Close() var dumpsJSON []model.DatabaseDumpJSON // TODO Filter *.torrent files diff --git a/router/modpanel.go b/router/modpanel.go index f14566a2..70d9d53e 100644 --- a/router/modpanel.go +++ b/router/modpanel.go @@ -163,6 +163,9 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) { } searchParam, torrents, count, err := search.SearchByQueryWithUser(r, pagenum) + if err != nil { + messages.ImportFromError("errors", err) + } searchForm := searchForm{ SearchParam: searchParam, Category: searchParam.Category.String(), @@ -469,6 +472,9 @@ func DeletedTorrentsModPanel(w http.ResponseWriter, r *http.Request) { } searchParam, torrents, count, err := search.SearchByQueryDeleted(r, pagenum) + if err != nil { + messages.ImportFromError("errors", err) + } searchForm := searchForm{ SearchParam: searchParam, Category: searchParam.Category.String(), diff --git a/router/template_variables.go b/router/template_variables.go index 9e9f0a3a..af230914 100644 --- a/router/template_variables.go +++ b/router/template_variables.go @@ -76,12 +76,6 @@ type changeLanguageVariables struct { Languages map[string]string } -type publicSettingsVariables struct { - commonTemplateVariables - Language string - Languages map[string]string -} - /* MODERATION Variables */ type panelIndexVbs struct { diff --git a/router/view_torrent_handler.go b/router/view_torrent_handler.go index 213bd7b3..8447402b 100644 --- a/router/view_torrent_handler.go +++ b/router/view_torrent_handler.go @@ -117,6 +117,9 @@ func PostCommentHandler(w http.ResponseWriter, r *http.Request) { comment := model.Comment{TorrentID: torrent.ID, UserID: userID, Content: content, CreatedAt: time.Now()} err := db.ORM.Create(&comment).Error + if err != nil { + messages.ImportFromError("errors", err) + } comment.Torrent = &torrent url, err := Router.Get("view_torrent").URL("id", strconv.FormatUint(uint64(torrent.ID), 10)) @@ -147,7 +150,7 @@ func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) { } } if !messages.HasErrors() { - idNum, err := strconv.Atoi(id) + idNum, _ := strconv.Atoi(id) userID := currentUser.ID report := model.TorrentReport{ @@ -157,7 +160,7 @@ func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) { CreatedAt: time.Now(), } - err = db.ORM.Create(&report).Error + err := db.ORM.Create(&report).Error messages.AddInfoTf("infos", "report_msg", id) if err != nil { messages.ImportFromError("errors", err) @@ -268,12 +271,12 @@ func DownloadTorrent(w http.ResponseWriter, r *http.Request) { //Check if file exists and open Openfile, err := os.Open(fmt.Sprintf("%s%c%s.torrent", config.Conf.Torrents.FileStorage, os.PathSeparator, hash)) - defer Openfile.Close() //Close after function return if err != nil { //File not found, send 404 http.Error(w, "File not found.", 404) return } + defer Openfile.Close() //Close after function return //Get the file size FileStat, _ := Openfile.Stat() //Get info from file diff --git a/service/api/api.go b/service/api/api.go index 2014355f..a9c65e90 100644 --- a/service/api/api.go +++ b/service/api/api.go @@ -158,31 +158,15 @@ func (r *TorrentRequest) validateDescription() error { return nil } -// TODO Check category is within accepted range -func validateCategory(r *TorrentRequest) (error, int) { - if r.CategoryID == 0 { - return ErrCategory, http.StatusNotAcceptable - } - return nil, http.StatusOK -} - -// TODO Check subCategory is within accepted range -func validateSubCategory(r *TorrentRequest) (error, int) { - if r.SubCategory == 0 { - return ErrSubCategory, http.StatusNotAcceptable - } - return nil, http.StatusOK -} - -func validateWebsiteLink(r *TorrentRequest) (error, int) { +func (r *TorrentRequest) validateWebsiteLink() error { if r.WebsiteLink != "" { // WebsiteLink urlRegexp, _ := regexp.Compile(`^(https?:\/\/|ircs?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$`) if !urlRegexp.MatchString(r.WebsiteLink) { - return ErrWebsiteLink, http.StatusNotAcceptable + return errInvalidWebsiteLink } } - return nil, http.StatusOK + return nil } func (r *TorrentRequest) validateMagnet() error { @@ -252,25 +236,24 @@ func (r *TorrentRequest) ExtractEditInfo(req *http.Request) error { func (r *TorrentRequest) ExtractCategory(req *http.Request) error { catsSplit := strings.Split(r.Category, "_") // need this to prevent out of index panics - if len(catsSplit) == 2 { - CatID, err := strconv.Atoi(catsSplit[0]) - if err != nil { - return errInvalidTorrentCategory - } - SubCatID, err := strconv.Atoi(catsSplit[1]) - if err != nil { - return errInvalidTorrentCategory - } - - if !categories.CategoryExists(r.Category) { - return errInvalidTorrentCategory - } - - r.CategoryID = CatID - r.SubCategoryID = SubCatID - } else { + if len(catsSplit) != 2 { return errInvalidTorrentCategory } + CatID, err := strconv.Atoi(catsSplit[0]) + if err != nil { + return errInvalidTorrentCategory + } + SubCatID, err := strconv.Atoi(catsSplit[1]) + if err != nil { + return errInvalidTorrentCategory + } + + if !categories.CategoryExists(r.Category) { + return errInvalidTorrentCategory + } + + r.CategoryID = CatID + r.SubCategoryID = SubCatID return nil } @@ -354,14 +337,8 @@ func (r *TorrentRequest) ExtractBasicValue(req *http.Request) error { return err } - if r.WebsiteLink != "" { - // WebsiteLink - urlRegexp, _ := regexp.Compile(`^(https?:\/\/|ircs?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$`) - if !urlRegexp.MatchString(r.WebsiteLink) { - return errInvalidWebsiteLink - } - } - return nil + err = r.validateWebsiteLink() + return err } // ExtractInfo : takes an http request and computes all fields for this form diff --git a/service/scraper/scraper.go b/service/scraper/scraper.go index bc492faf..4856ab06 100644 --- a/service/scraper/scraper.go +++ b/service/scraper/scraper.go @@ -124,32 +124,38 @@ func (sc *Scraper) RunWorker(pc net.PacketConn) (err error) { break } tid, err := ev.TID() + if err != nil { + log.Warnf("failed: %s", err) + break + } action, err := ev.Action() + if err != nil { + log.Warnf("failed: %s", err) + break + } log.Debugf("transaction = %d action = %d", tid, action) - if err == nil { - bucket, ok = sc.trackers[ev.From.String()] - if ok && bucket != nil { - bucket.VisitTransaction(tid, func(t *Transaction) { - if t == nil { - log.Warnf("no transaction %d", tid) - } else { - if t.GotData(ev.Data) { - err := t.Sync() - if err != nil { - log.Warnf("failed to sync swarm: %s", err) - } - t.Done() - log.Debugf("transaction %d done", tid) - } else { - sc.sendQueue <- t.SendEvent(ev.From) - } - } - }) - } else { - log.Warnf("bucket not found for %s", ev.From) - } + bucket, ok = sc.trackers[ev.From.String()] + if !ok || bucket == nil { + log.Warnf("bucket not found for %s", ev.From) + break } + bucket.VisitTransaction(tid, func(t *Transaction) { + if t == nil { + log.Warnf("no transaction %d", tid) + return + } + if t.GotData(ev.Data) { + err := t.Sync() + if err != nil { + log.Warnf("failed to sync swarm: %s", err) + } + t.Done() + log.Debugf("transaction %d done", tid) + } else { + sc.sendQueue <- t.SendEvent(ev.From) + } + }) } return } diff --git a/service/scraper/transaction.go b/service/scraper/transaction.go index 486bd7b6..394531d2 100644 --- a/service/scraper/transaction.go +++ b/service/scraper/transaction.go @@ -21,7 +21,8 @@ const stateTransact = 2 const actionError = 3 const actionScrape = 2 -const actionAnnounce = 1 + +//const actionAnnounce = 1 const actionConnect = 0 // Transaction a scrape transaction on a udp tracker diff --git a/service/user/user.go b/service/user/user.go index bcb4d1a5..8e14698f 100644 --- a/service/user/user.go +++ b/service/user/user.go @@ -62,10 +62,8 @@ func CheckEmail(email string) bool { } var count int db.ORM.Model(model.User{}).Where("email = ?", email).Count(&count) - if count != 0 { - return true // error: duplicate - } - return false + + return count != 0 } // CreateUserFromForm creates a user from a registration form. diff --git a/templates/_captcha.html b/templates/_captcha.html index 44da2d05..7c477953 100644 --- a/templates/_captcha.html +++ b/templates/_captcha.html @@ -1,11 +1,14 @@ {{define "captcha"}} {{/* unset if user doesn't need captcha */}} {{if ne .CaptchaID ""}} -
+

{{call $.T "captcha"}}


- + +
{{end}} {{end}} diff --git a/templates/view.html b/templates/view.html index cb7ad296..b9c0c995 100644 --- a/templates/view.html +++ b/templates/view.html @@ -131,8 +131,8 @@
{{block "captcha" (makeCaptchaData .CaptchaID $.T)}}{{end}} -
+ @@ -154,7 +154,9 @@


+
{{template "captcha" (makeCaptchaData $.CaptchaID $.T)}} +