a5f5f4af7e
Added the PageStore. Renamed account_own_edit.html to account_own_edit_password.html Renamed custom-page.html to custom_page.html Renamed the pre_render_custom_page hook to pre_render_tmpl_page. Added a new pre_render_custom_page hook, not to be confused with the previous one. Renamed the pre_render_account_own_edit_critical hook to pre_render_account_own_edit_password. Moved the report forum ID into a constant. Renamed todaysReportCount to topicsTopicCountByForum and made it more generic. Renamed panel-menu.html to panel_menu.html Renamed panel-inner-menu.html to panel_inner_menu.html Removed an irrelevant editable_parent in a no results row. Fixed the profile page loading the wrong profile.css Fixed a bug where the last poster avatar would break on the forum page. Added the AddNotice method to *Header. Greatly simplified many of the page struct definitions. Added the ErrorPage page struct and refactored the error pages to use it. Added the BasePanelPage page struct and refactored the panel page structs to use it. Tweaked the DefaultHeader function to set the user on the spot rather than after the fact. Simplified AccountEditAvatarSubmit into a redirect. Add the addElement closure in the control panel dashboard to reduce the amount of complexity. Tweaked LogWarning to better handle nils. Added the account_username phrase. Added the account_avatar phrase. Added the account_email phrase. Added the panel_pages phrase. Added the panel_pages_edit phrase. Added the panel_page_created phrase. Added the panel_page_updated phrase. Added the panel_page_deleted phrase. Added the account_menu_security phrase. Added the panel_menu_pages phrase. Added the panel_pages_head phrase. Added the panel_pages_edit_button_aria phrase. Added the panel_pages_delete_button_aria phrase. Added the panel_pages_no_pages phrase. Added the panel_pages_create_head phrase. Added the panel_pages_create_name phrase. Added the panel_pages_create_name_placeholder phrase. Added the panel_pages_create_title phrase. Added the panel_pages_create_title_placeholder phrase. Added the panel_pages_create_body_placeholder phrase. Added the panel_pages_create_submit_button phrase. Added the panel_pages_edit_head phrase. Added the panel_pages_name phrase. Added the panel_pages_title phrase. Added the panel_pages_edit_update_button phrase. Began work on two-factor authentication. Made more progress with the Nox Theme.
159 lines
6.0 KiB
Go
159 lines
6.0 KiB
Go
package panel
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"../../common"
|
|
)
|
|
|
|
func LogsRegs(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
|
header, stats, ferr := common.PanelUserCheck(w, r, &user)
|
|
if ferr != nil {
|
|
return ferr
|
|
}
|
|
header.Title = common.GetTitlePhrase("panel_registration_logs")
|
|
|
|
logCount := common.RegLogs.GlobalCount()
|
|
page, _ := strconv.Atoi(r.FormValue("page"))
|
|
perPage := 10
|
|
offset, page, lastPage := common.PageOffset(logCount, page, perPage)
|
|
|
|
logs, err := common.RegLogs.GetOffset(offset, perPage)
|
|
if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
var llist = make([]common.PageRegLogItem, len(logs))
|
|
for index, log := range logs {
|
|
llist[index] = common.PageRegLogItem{log, strings.Replace(strings.TrimSuffix(log.FailureReason, "|"), "|", " | ", -1)}
|
|
}
|
|
|
|
pageList := common.Paginate(logCount, perPage, 5)
|
|
pi := common.PanelRegLogsPage{&common.BasePanelPage{header, stats, "logs", common.ReportForumID}, llist, common.Paginator{pageList, page, lastPage}}
|
|
return panelRenderTemplate("panel_reglogs", w, r, user, &pi)
|
|
}
|
|
|
|
// TODO: Log errors when something really screwy is going on?
|
|
func handleUnknownUser(user *common.User, err error) *common.User {
|
|
if err != nil {
|
|
return &common.User{Name: "Unknown", Link: common.BuildProfileURL("unknown", 0)}
|
|
}
|
|
return user
|
|
}
|
|
func handleUnknownTopic(topic *common.Topic, err error) *common.Topic {
|
|
if err != nil {
|
|
return &common.Topic{Title: "Unknown", Link: common.BuildProfileURL("unknown", 0)}
|
|
}
|
|
return topic
|
|
}
|
|
|
|
// TODO: Move the log building logic into /common/ and it's own abstraction
|
|
func topicElementTypeAction(action string, elementType string, elementID int, actor *common.User, topic *common.Topic) (out string) {
|
|
if action == "delete" {
|
|
return fmt.Sprintf("Topic #%d was deleted by <a href='%s'>%s</a>", elementID, actor.Link, actor.Name)
|
|
}
|
|
switch action {
|
|
case "lock":
|
|
out = "<a href='%s'>%s</a> was locked by <a href='%s'>%s</a>"
|
|
case "unlock":
|
|
out = "<a href='%s'>%s</a> was reopened by <a href='%s'>%s</a>"
|
|
case "stick":
|
|
out = "<a href='%s'>%s</a> was pinned by <a href='%s'>%s</a>"
|
|
case "unstick":
|
|
out = "<a href='%s'>%s</a> was unpinned by <a href='%s'>%s</a>"
|
|
case "move":
|
|
out = "<a href='%s'>%s</a> was moved by <a href='%s'>%s</a>" // TODO: Add where it was moved to, we'll have to change the source data for that, most likely? Investigate that and try to work this in
|
|
default:
|
|
return fmt.Sprintf("Unknown action '%s' on elementType '%s' by <a href='%s'>%s</a>", action, elementType, actor.Link, actor.Name)
|
|
}
|
|
return fmt.Sprintf(out, topic.Link, topic.Title, actor.Link, actor.Name)
|
|
}
|
|
|
|
func modlogsElementType(action string, elementType string, elementID int, actor *common.User) (out string) {
|
|
switch elementType {
|
|
case "topic":
|
|
topic := handleUnknownTopic(common.Topics.Get(elementID))
|
|
out = topicElementTypeAction(action, elementType, elementID, actor, topic)
|
|
case "user":
|
|
targetUser := handleUnknownUser(common.Users.Get(elementID))
|
|
switch action {
|
|
case "ban":
|
|
out = "<a href='%s'>%s</a> was banned by <a href='%s'>%s</a>"
|
|
case "unban":
|
|
out = "<a href='%s'>%s</a> was unbanned by <a href='%s'>%s</a>"
|
|
case "activate":
|
|
out = "<a href='%s'>%s</a> was activated by <a href='%s'>%s</a>"
|
|
}
|
|
out = fmt.Sprintf(out, targetUser.Link, targetUser.Name, actor.Link, actor.Name)
|
|
case "reply":
|
|
if action == "delete" {
|
|
topic := handleUnknownTopic(common.TopicByReplyID(elementID))
|
|
out = fmt.Sprintf("A reply in <a href='%s'>%s</a> was deleted by <a href='%s'>%s</a>", topic.Link, topic.Title, actor.Link, actor.Name)
|
|
}
|
|
}
|
|
|
|
if out == "" {
|
|
out = fmt.Sprintf("Unknown action '%s' on elementType '%s' by <a href='%s'>%s</a>", action, elementType, actor.Link, actor.Name)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func LogsMod(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
|
header, stats, ferr := common.PanelUserCheck(w, r, &user)
|
|
if ferr != nil {
|
|
return ferr
|
|
}
|
|
header.Title = common.GetTitlePhrase("panel_mod_logs")
|
|
|
|
logCount := common.ModLogs.GlobalCount()
|
|
page, _ := strconv.Atoi(r.FormValue("page"))
|
|
perPage := 10
|
|
offset, page, lastPage := common.PageOffset(logCount, page, perPage)
|
|
|
|
logs, err := common.ModLogs.GetOffset(offset, perPage)
|
|
if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
var llist = make([]common.PageLogItem, len(logs))
|
|
for index, log := range logs {
|
|
actor := handleUnknownUser(common.Users.Get(log.ActorID))
|
|
action := modlogsElementType(log.Action, log.ElementType, log.ElementID, actor)
|
|
llist[index] = common.PageLogItem{Action: template.HTML(action), IPAddress: log.IPAddress, DoneAt: log.DoneAt}
|
|
}
|
|
|
|
pageList := common.Paginate(logCount, perPage, 5)
|
|
pi := common.PanelLogsPage{&common.BasePanelPage{header, stats, "logs", common.ReportForumID}, llist, common.Paginator{pageList, page, lastPage}}
|
|
return panelRenderTemplate("panel_modlogs", w, r, user, &pi)
|
|
}
|
|
|
|
func LogsAdmin(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
|
header, stats, ferr := common.PanelUserCheck(w, r, &user)
|
|
if ferr != nil {
|
|
return ferr
|
|
}
|
|
header.Title = common.GetTitlePhrase("panel_admin_logs")
|
|
|
|
logCount := common.ModLogs.GlobalCount()
|
|
page, _ := strconv.Atoi(r.FormValue("page"))
|
|
perPage := 10
|
|
offset, page, lastPage := common.PageOffset(logCount, page, perPage)
|
|
|
|
logs, err := common.AdminLogs.GetOffset(offset, perPage)
|
|
if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
var llist = make([]common.PageLogItem, len(logs))
|
|
for index, log := range logs {
|
|
actor := handleUnknownUser(common.Users.Get(log.ActorID))
|
|
action := modlogsElementType(log.Action, log.ElementType, log.ElementID, actor)
|
|
llist[index] = common.PageLogItem{Action: template.HTML(action), IPAddress: log.IPAddress, DoneAt: log.DoneAt}
|
|
}
|
|
|
|
pageList := common.Paginate(logCount, perPage, 5)
|
|
pi := common.PanelLogsPage{&common.BasePanelPage{header, stats, "logs", common.ReportForumID}, llist, common.Paginator{pageList, page, lastPage}}
|
|
return panelRenderTemplate("panel_adminlogs", w, r, user, &pi)
|
|
}
|