|
|
@ -3,22 +3,24 @@
|
|
|
|
package router
|
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"html"
|
|
|
|
"html/template"
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ewhal/nyaa/service/comment"
|
|
|
|
"github.com/ewhal/nyaa/service/comment"
|
|
|
|
"github.com/ewhal/nyaa/service/moderation"
|
|
|
|
"github.com/ewhal/nyaa/service/moderation"
|
|
|
|
"github.com/ewhal/nyaa/service/torrent"
|
|
|
|
"github.com/ewhal/nyaa/service/torrent"
|
|
|
|
"github.com/ewhal/nyaa/service/torrent/form"
|
|
|
|
"github.com/ewhal/nyaa/service/torrent/form"
|
|
|
|
"github.com/ewhal/nyaa/util/search"
|
|
|
|
|
|
|
|
"github.com/ewhal/nyaa/service/user"
|
|
|
|
"github.com/ewhal/nyaa/service/user"
|
|
|
|
form "github.com/ewhal/nyaa/service/user/form"
|
|
|
|
form "github.com/ewhal/nyaa/service/user/form"
|
|
|
|
"github.com/ewhal/nyaa/service/user/permission"
|
|
|
|
"github.com/ewhal/nyaa/service/user/permission"
|
|
|
|
"github.com/ewhal/nyaa/util/languages"
|
|
|
|
"github.com/ewhal/nyaa/util/languages"
|
|
|
|
|
|
|
|
"github.com/ewhal/nyaa/util/log"
|
|
|
|
"github.com/ewhal/nyaa/util/modelHelper"
|
|
|
|
"github.com/ewhal/nyaa/util/modelHelper"
|
|
|
|
|
|
|
|
"github.com/ewhal/nyaa/util/search"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -28,13 +30,13 @@ func init() {
|
|
|
|
panelTorrentList = template.Must(template.New("torrentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrentlist.html")))
|
|
|
|
panelTorrentList = template.Must(template.New("torrentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrentlist.html")))
|
|
|
|
panelTorrentList = template.Must(panelTorrentList.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelTorrentList = template.Must(panelTorrentList.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelUserList = template.Must(template.New("userlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/userlist.html")))
|
|
|
|
panelUserList = template.Must(template.New("userlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/userlist.html")))
|
|
|
|
panelUserList = template.Must(panelUserList.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelUserList = template.Must(panelUserList.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelCommentList = template.Must(template.New("commentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/commentlist.html")))
|
|
|
|
panelCommentList = template.Must(template.New("commentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/commentlist.html")))
|
|
|
|
panelCommentList = template.Must(panelCommentList.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelCommentList = template.Must(panelCommentList.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelIndex = template.Must(template.New("indexPanel").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/panelindex.html")))
|
|
|
|
panelIndex = template.Must(template.New("indexPanel").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/panelindex.html")))
|
|
|
|
panelIndex = template.Must(panelIndex.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelIndex = template.Must(panelIndex.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelTorrentEd = template.Must(template.New("torrent_ed").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/paneltorrentedit.html")))
|
|
|
|
panelTorrentEd = template.Must(template.New("torrent_ed").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/paneltorrentedit.html")))
|
|
|
|
panelTorrentEd = template.Must(panelTorrentEd.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
panelTorrentEd = template.Must(panelTorrentEd.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
torrentReportTemplate = template.Must(template.New("torrent_report").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrent_report.html")))
|
|
|
|
torrentReportTemplate = template.Must(template.New("torrent_report").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrent_report.html")))
|
|
|
|
torrentReportTemplate = template.Must(torrentReportTemplate.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
torrentReportTemplate = template.Must(torrentReportTemplate.ParseGlob(filepath.Join("templates", "_*.html")))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -47,9 +49,9 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
|
|
|
|
torrents, _, _ := torrentService.GetAllTorrents(offset, 0)
|
|
|
|
torrents, _, _ := torrentService.GetAllTorrents(offset, 0)
|
|
|
|
users, _ := userService.RetrieveUsersForAdmin(offset, 0)
|
|
|
|
users, _ := userService.RetrieveUsersForAdmin(offset, 0)
|
|
|
|
comments, _ := commentService.GetAllComments(offset, 0, "", "")
|
|
|
|
comments, _ := commentService.GetAllComments(offset, 0, "", "")
|
|
|
|
torrentReports, _, _ := moderationService.GetTorrentReports(offset,0, "", "")
|
|
|
|
torrentReports, _, _ := moderationService.GetTorrentReports(offset, 0, "", "")
|
|
|
|
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
|
|
|
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
|
|
|
htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL}
|
|
|
|
htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL}
|
|
|
|
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
|
|
|
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
http.Error(w, "admins only", http.StatusForbidden)
|
|
|
|
http.Error(w, "admins only", http.StatusForbidden)
|
|
|
@ -59,10 +61,20 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
|
|
|
|
currentUser := GetUser(r)
|
|
|
|
currentUser := GetUser(r)
|
|
|
|
if userPermission.HasAdmin(currentUser) {
|
|
|
|
if userPermission.HasAdmin(currentUser) {
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
page, _ := strconv.Atoi(vars["page"])
|
|
|
|
page := vars["page"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
pagenum := 1
|
|
|
|
|
|
|
|
if page != "" {
|
|
|
|
|
|
|
|
pagenum, err = strconv.Atoi(html.EscapeString(page))
|
|
|
|
|
|
|
|
if !log.CheckError(err) {
|
|
|
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
offset := 100
|
|
|
|
offset := 100
|
|
|
|
|
|
|
|
|
|
|
|
searchParam, torrents, _, err := search.SearchByQuery(r, page)
|
|
|
|
searchParam, torrents, _, err := search.SearchByQuery(r, pagenum)
|
|
|
|
searchForm := SearchForm{
|
|
|
|
searchForm := SearchForm{
|
|
|
|
SearchParam: searchParam,
|
|
|
|
SearchParam: searchParam,
|
|
|
|
Category: searchParam.Category.String(),
|
|
|
|
Category: searchParam.Category.String(),
|
|
|
@ -70,7 +82,7 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
|
|
|
|
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
|
|
|
|
htv := PanelTorrentListVbs{torrents, searchForm, Navigation{int(searchParam.Max), offset, page, "mod_tlist_page"}, currentUser, r.URL}
|
|
|
|
htv := PanelTorrentListVbs{torrents, searchForm, Navigation{int(searchParam.Max), offset, pagenum, "mod_tlist_page"}, currentUser, r.URL}
|
|
|
|
err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
|
|
|
err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -82,13 +94,23 @@ func UsersListPanel(w http.ResponseWriter, r *http.Request) {
|
|
|
|
currentUser := GetUser(r)
|
|
|
|
currentUser := GetUser(r)
|
|
|
|
if userPermission.HasAdmin(currentUser) {
|
|
|
|
if userPermission.HasAdmin(currentUser) {
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
page, _ := strconv.Atoi(vars["page"])
|
|
|
|
page := vars["page"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
pagenum := 1
|
|
|
|
|
|
|
|
if page != "" {
|
|
|
|
|
|
|
|
pagenum, err = strconv.Atoi(html.EscapeString(page))
|
|
|
|
|
|
|
|
if !log.CheckError(err) {
|
|
|
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
offset := 100
|
|
|
|
offset := 100
|
|
|
|
|
|
|
|
|
|
|
|
users, nbUsers := userService.RetrieveUsersForAdmin(offset, page*offset)
|
|
|
|
users, nbUsers := userService.RetrieveUsersForAdmin(offset, (pagenum-1)*offset)
|
|
|
|
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
|
|
|
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
|
|
|
htv := PanelUserListVbs{users, NewSearchForm(), Navigation{nbUsers, offset, page, "mod_ulist_page"}, currentUser, r.URL}
|
|
|
|
htv := PanelUserListVbs{users, NewSearchForm(), Navigation{nbUsers, offset, pagenum, "mod_ulist_page"}, currentUser, r.URL}
|
|
|
|
err := panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
|
|
|
err = panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
http.Error(w, "admins only", http.StatusForbidden)
|
|
|
|
http.Error(w, "admins only", http.StatusForbidden)
|
|
|
@ -98,19 +120,30 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
|
|
|
currentUser := GetUser(r)
|
|
|
|
currentUser := GetUser(r)
|
|
|
|
if userPermission.HasAdmin(currentUser) {
|
|
|
|
if userPermission.HasAdmin(currentUser) {
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
page, _ := strconv.Atoi(vars["page"])
|
|
|
|
page := vars["page"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
pagenum := 1
|
|
|
|
|
|
|
|
if page != "" {
|
|
|
|
|
|
|
|
pagenum, err = strconv.Atoi(html.EscapeString(page))
|
|
|
|
|
|
|
|
if !log.CheckError(err) {
|
|
|
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
offset := 100
|
|
|
|
offset := 100
|
|
|
|
userid := r.URL.Query().Get("userid")
|
|
|
|
userid := r.URL.Query().Get("userid")
|
|
|
|
var conditions string
|
|
|
|
var conditions string
|
|
|
|
var values []interface{}
|
|
|
|
var values []interface{}
|
|
|
|
if (userid != "") {
|
|
|
|
if userid != "" {
|
|
|
|
conditions = "user_id = ?"
|
|
|
|
conditions = "user_id = ?"
|
|
|
|
values = append(values, userid)
|
|
|
|
values = append(values, userid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
comments, nbComments := commentService.GetAllComments(offset, page * offset, conditions, values...)
|
|
|
|
|
|
|
|
|
|
|
|
comments, nbComments := commentService.GetAllComments(offset, (pagenum-1)*offset, conditions, values...)
|
|
|
|
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
|
|
|
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
|
|
|
htv := PanelCommentListVbs{comments, NewSearchForm(), Navigation{nbComments, offset, page, "mod_clist_page"}, currentUser, r.URL}
|
|
|
|
htv := PanelCommentListVbs{comments, NewSearchForm(), Navigation{nbComments, offset, pagenum, "mod_clist_page"}, currentUser, r.URL}
|
|
|
|
err := panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
|
|
|
err = panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
http.Error(w, "admins only", http.StatusForbidden)
|
|
|
|
http.Error(w, "admins only", http.StatusForbidden)
|
|
|
@ -185,4 +218,4 @@ func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
http.Error(w, "admins only", http.StatusForbidden)
|
|
|
|
http.Error(w, "admins only", http.StatusForbidden)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|