diff --git a/common/common.go b/common/common.go index 90682c4f..104b35cd 100644 --- a/common/common.go +++ b/common/common.go @@ -82,6 +82,9 @@ var AllowedFileExts = StringList{ var ImageFileExts = StringList{ "png", "jpg", "jpe", "jpeg", "jif", "jfi", "jfif", "svg", "bmp", "gif", "tiff", "tif", "webp", /* "apng", "bpg", */ } +var TextFileExts = StringList{ + "txt", "xml", "json", "yaml", "toml", "ini", "md", "html", "rtf", "js", "py", "rb", "css", "scss", "less", "eqcss", "pcss", "java", "ts", "cs", "c", "cc", "cpp", "cxx", "C", "c++", "h", "hh", "hpp", "hxx", "h++", "rs", "rlib", "htaccess", "gitignore", /*"go","php",*/ +} var VideoFileExts = StringList{ "mp4", "avi", "ogg", "ogv", "ogx", "wmv", "webm", } diff --git a/common/parser.go b/common/parser.go index 2d115676..fae73559 100644 --- a/common/parser.go +++ b/common/parser.go @@ -44,6 +44,9 @@ var attachOpen = []byte("Attachment") var sidParam = []byte("?sid=") var stypeParam = []byte("&stype=") +var textOpen = []byte("View / Download") var urlPattern = `(?s)([ {1}])((http|https|ftp|mailto)*)(:{??)\/\/([\.a-zA-Z\/]+)([ {1}])` var urlReg *regexp.Regexp @@ -713,6 +716,24 @@ func ParseMessage(msg string, sectionID int, sectionType string, settings *Parse case EImage: addImage(media.URL) continue + case AText: + sb.Write(textOpen) + sb.WriteString(media.URL) + sb.Write(sidParam) + sid := strconv.Itoa(sectionID) + sb.WriteString(sid) + sb.Write(stypeParam) + sb.WriteString(sectionType) + sb.Write(textOpen2) + sb.WriteString(media.URL) + sb.Write(sidParam) + sb.WriteString(sid) + sb.Write(stypeParam) + sb.WriteString(sectionType) + sb.Write(textClose) + i += urlLen + lastItem = i + continue case AOther: sb.Write(attachOpen) sb.WriteString(media.URL) @@ -951,6 +972,7 @@ const ( AImage AVideo AAudio + AText AOther ) @@ -1011,6 +1033,8 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o media.Type = AVideo case WebAudioFileExts.Contains(ext): media.Type = AAudio + case TextFileExts.Contains(ext): + media.Type = AText default: media.Type = AOther } diff --git a/routes/moderate.go b/routes/moderate.go index 6ccc8658..538c2a29 100644 --- a/routes/moderate.go +++ b/routes/moderate.go @@ -7,11 +7,11 @@ import ( "github.com/Azareal/Gosora/common/phrases" ) -func IPSearch(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Header) c.RouteError { +func IPSearch(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError { h.Title = phrases.GetTitlePhrase("ip_search") // TODO: How should we handle the permissions if we extend this into an alt detector of sorts? - if !user.Perms.ViewIPs { - return c.NoPermissions(w, r, user) + if !u.Perms.ViewIPs { + return c.NoPermissions(w, r, u) } // TODO: Reject IP Addresses with illegal characters diff --git a/routes/panel/word_filters.go b/routes/panel/word_filters.go index f03b3e18..c6643898 100644 --- a/routes/panel/word_filters.go +++ b/routes/panel/word_filters.go @@ -10,13 +10,13 @@ import ( c "github.com/Azareal/Gosora/common" ) -func WordFilters(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError { - basePage, ferr := buildBasePage(w, r, user, "word_filters", "word-filters") +func WordFilters(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError { + basePage, ferr := buildBasePage(w, r, u, "word_filters", "word-filters") if ferr != nil { return ferr } - if !user.Perms.EditSettings { - return c.NoPermissions(w, r, user) + if !u.Perms.EditSettings { + return c.NoPermissions(w, r, u) } // TODO: What if this list gets too long? @@ -29,20 +29,20 @@ func WordFilters(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteEr return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_word_filters", &pi}) } -func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError { - _, ferr := c.SimplePanelUserCheck(w, r, user) +func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError { + _, ferr := c.SimplePanelUserCheck(w, r, u) if ferr != nil { return ferr } - if !user.Perms.EditSettings { - return c.NoPermissions(w, r, user) + if !u.Perms.EditSettings { + return c.NoPermissions(w, r, u) } js := r.PostFormValue("js") == "1" // ? - We're not doing a full sanitise here, as it would be useful if admins were able to put down rules for replacing things with HTML, etc. find := strings.TrimSpace(r.PostFormValue("find")) if find == "" { - return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, user, js) + return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, u, js) } // Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement @@ -52,7 +52,7 @@ func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, user *c.Use if err != nil { return c.InternalErrorJSQ(err, w, r, js) } - err = c.AdminLogs.Create("create", wfid, "word_filter", user.GetIP(), user.ID) + err = c.AdminLogs.Create("create", wfid, "word_filter", u.GetIP(), u.ID) if err != nil { return c.InternalError(err, w, r) } @@ -61,13 +61,13 @@ func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, user *c.Use } // TODO: Implement this as a non-JS fallback -func WordFiltersEdit(w http.ResponseWriter, r *http.Request, user *c.User, wfid string) c.RouteError { - basePage, ferr := buildBasePage(w, r, user, "edit_word_filter", "word-filters") +func WordFiltersEdit(w http.ResponseWriter, r *http.Request, u *c.User, wfid string) c.RouteError { + basePage, ferr := buildBasePage(w, r, u, "edit_word_filter", "word-filters") if ferr != nil { return ferr } - if !user.Perms.EditSettings { - return c.NoPermissions(w, r, user) + if !u.Perms.EditSettings { + return c.NoPermissions(w, r, u) } _ = wfid @@ -75,30 +75,30 @@ func WordFiltersEdit(w http.ResponseWriter, r *http.Request, user *c.User, wfid return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_word_filters_edit", &pi}) } -func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, user *c.User, swfid string) c.RouteError { - _, ferr := c.SimplePanelUserCheck(w, r, user) +func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, u *c.User, swfid string) c.RouteError { + _, ferr := c.SimplePanelUserCheck(w, r, u) if ferr != nil { return ferr } js := r.PostFormValue("js") == "1" - if !user.Perms.EditSettings { - return c.NoPermissionsJSQ(w, r, user, js) + if !u.Perms.EditSettings { + return c.NoPermissionsJSQ(w, r, u, js) } wfid, err := strconv.Atoi(swfid) if err != nil { - return c.LocalErrorJSQ("The word filter ID must be an integer.", w, r, user, js) + return c.LocalErrorJSQ("The word filter ID must be an integer.", w, r, u, js) } find := strings.TrimSpace(r.PostFormValue("find")) if find == "" { - return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, user, js) + return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, u, js) } // Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement replace := strings.TrimSpace(r.PostFormValue("replace")) wf, err := c.WordFilters.Get(wfid) if err == sql.ErrNoRows { - return c.LocalErrorJSQ("This word filter doesn't exist.", w, r, user, js) + return c.LocalErrorJSQ("This word filter doesn't exist.", w, r, u, js) } else if err != nil { return c.InternalErrorJSQ(err, w, r, js) } @@ -111,7 +111,7 @@ func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, user *c.User, if err != nil { return c.InternalErrorJSQ(err, w, r, js) } - err = c.AdminLogs.CreateExtra("edit", wfid, "word_filter", user.GetIP(), user.ID, string(lBytes)) + err = c.AdminLogs.CreateExtra("edit", wfid, "word_filter", u.GetIP(), u.ID, string(lBytes)) if err != nil { return c.InternalErrorJSQ(err, w, r, js) } @@ -120,25 +120,25 @@ func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, user *c.User, return nil } -func WordFiltersDeleteSubmit(w http.ResponseWriter, r *http.Request, user *c.User, swfid string) c.RouteError { - _, ferr := c.SimplePanelUserCheck(w, r, user) +func WordFiltersDeleteSubmit(w http.ResponseWriter, r *http.Request, u *c.User, swfid string) c.RouteError { + _, ferr := c.SimplePanelUserCheck(w, r, u) if ferr != nil { return ferr } js := r.PostFormValue("js") == "1" - if !user.Perms.EditSettings { - return c.NoPermissionsJSQ(w, r, user, js) + if !u.Perms.EditSettings { + return c.NoPermissionsJSQ(w, r, u, js) } wfid, err := strconv.Atoi(swfid) if err != nil { - return c.LocalErrorJSQ("The word filter ID must be an integer.", w, r, user, js) + return c.LocalErrorJSQ("The word filter ID must be an integer.", w, r, u, js) } err = c.WordFilters.Delete(wfid) if err == sql.ErrNoRows { - return c.LocalErrorJSQ("This word filter doesn't exist", w, r, user, js) + return c.LocalErrorJSQ("This word filter doesn't exist", w, r, u, js) } - err = c.AdminLogs.Create("delete", wfid, "word_filter", user.GetIP(), user.ID) + err = c.AdminLogs.Create("delete", wfid, "word_filter", u.GetIP(), u.ID) if err != nil { return c.InternalError(err, w, r) } diff --git a/templates/ip_search.html b/templates/ip_search.html index ab0bea4f..3fd86fbb 100644 --- a/templates/ip_search.html +++ b/templates/ip_search.html @@ -5,11 +5,11 @@