Skip to content

Commit

Permalink
You can now search for whatever IP you want in the IP Searcher.
Browse files Browse the repository at this point in the history
Removed the Uncategorised Forum.
Added the Backup Page for super admins. Not quite functional yet.
Forums are now sorted properly again.
Fixed a bug in DirtyGet() where invalid IDs would trigger a panic.
Fixed a bug where alternate themes wouldn't work without setting them as default first and restarting Gosora.
  • Loading branch information
Azareal committed Sep 23, 2017
1 parent d869b87 commit 11c60b3
Show file tree
Hide file tree
Showing 24 changed files with 307 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ brun.bat

uploads/avatar_*
uploads/socialgroup_*
backups/*.sql
bin/*
out/*
*.exe
Expand Down
1 change: 1 addition & 0 deletions backups/filler.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is here so that Git will include this folder in the repository.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
config.DefaultGroup = 3 // Should be a setting in the database
config.ActivationGroup = 5 // Should be a setting in the database
config.StaffCSS = "staff_post"
config.UncategorisedForumVisible = true
config.DefaultForum = 2
config.MinifyTemplates = false
config.MultiServer = false // Experimental: Enable Cross-Server Synchronisation and several other features

Expand Down
14 changes: 14 additions & 0 deletions forum.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ type ForumSimple struct {
Preset string
}

// TODO: Replace this sorting mechanism with something a lot more efficient
// ? - Use sort.Slice instead?
type SortForum []*Forum

func (sf SortForum) Len() int {
return len(sf)
}
func (sf SortForum) Swap(i, j int) {
sf[i], sf[j] = sf[j], sf[i]
}
func (sf SortForum) Less(i, j int) bool {
return sf[i].ID < sf[j].ID
}

func buildForumURL(slug string, fid int) string {
if slug == "" {
return "/forum/" + strconv.Itoa(fid)
Expand Down
21 changes: 14 additions & 7 deletions forum_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package main
import (
"database/sql"
"log"
"sort"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -104,8 +105,6 @@ func (mfs *MemoryForumStore) LoadForums() error {
}
}

addForum(&Forum{0, buildForumURL(nameToSlug("Uncategorised"), 0), "Uncategorised", "", config.UncategorisedForumVisible, "all", 0, "", 0, "", "", 0, "", 0, ""})

rows, err := getForumsStmt.Query()
if err != nil {
return err
Expand Down Expand Up @@ -148,16 +147,16 @@ func (mfs *MemoryForumStore) rebuildView() {
}
return true
})
sort.Sort(SortForum(forumView))
mfs.forumView.Store(forumView)
}

func (mfs *MemoryForumStore) DirtyGet(id int) *Forum {
fint, ok := mfs.forums.Load(id)
forum := fint.(*Forum)
if !ok || forum.Name == "" {
if !ok || fint.(*Forum).Name == "" {
return &Forum{ID: -1, Name: ""}
}
return forum
return fint.(*Forum)
}

func (mfs *MemoryForumStore) CacheGet(id int) (*Forum, error) {
Expand Down Expand Up @@ -225,24 +224,29 @@ func (mfs *MemoryForumStore) CacheSet(forum *Forum) error {
return nil
}

// ! Has a randomised order
func (mfs *MemoryForumStore) GetAll() (forumView []*Forum, err error) {
mfs.forums.Range(func(_ interface{}, value interface{}) bool {
forumView = append(forumView, value.(*Forum))
return true
})
sort.Sort(SortForum(forumView))
return forumView, nil
}

// ? - Can we optimise the sorting?
func (mfs *MemoryForumStore) GetAllIDs() (ids []int, err error) {
mfs.forums.Range(func(_ interface{}, value interface{}) bool {
ids = append(ids, value.(*Forum).ID)
return true
})
sort.Ints(ids)
return ids, nil
}

func (mfs *MemoryForumStore) GetAllVisible() ([]*Forum, error) {
return mfs.forumView.Load().([]*Forum), nil
func (mfs *MemoryForumStore) GetAllVisible() (forumView []*Forum, err error) {
forumView = mfs.forumView.Load().([]*Forum)
return forumView, nil
}

func (mfs *MemoryForumStore) GetAllVisibleIDs() ([]int, error) {
Expand Down Expand Up @@ -285,6 +289,7 @@ func (mfs *MemoryForumStore) Delete(id int) error {
return nil
}

// ! Is this racey?
func (mfs *MemoryForumStore) IncrementTopicCount(id int) error {
forum, err := mfs.Get(id)
if err != nil {
Expand All @@ -298,6 +303,7 @@ func (mfs *MemoryForumStore) IncrementTopicCount(id int) error {
return nil
}

// ! Is this racey?
func (mfs *MemoryForumStore) DecrementTopicCount(id int) error {
forum, err := mfs.Get(id)
if err != nil {
Expand All @@ -312,6 +318,7 @@ func (mfs *MemoryForumStore) DecrementTopicCount(id int) error {
}

// TODO: Have a pointer to the last topic rather than storing it on the forum itself
// ! Is this racey?
func (mfs *MemoryForumStore) UpdateLastTopic(topicName string, tid int, username string, uid int, time string, fid int) error {
forum, err := mfs.Get(fid)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions gen_router.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ config.DefaultRoute = routeTopics
config.DefaultGroup = 3 // Should be a setting in the database
config.ActivationGroup = 5 // Should be a setting in the database
config.StaffCSS = "staff_post"
config.UncategorisedForumVisible = true
config.DefaultForum = 2
config.MinifyTemplates = true
config.MultiServer = false // Experimental: Enable Cross-Server Synchronisation and several other features
Expand Down
17 changes: 6 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"log"
"net/http"
"os"
"strings"
"time"
//"runtime/pprof"
)
Expand Down Expand Up @@ -41,16 +40,6 @@ var externalSites = map[string]string{
var staticFiles = make(map[string]SFile)
var logWriter = io.MultiWriter(os.Stderr)

func processConfig() {
config.Noavatar = strings.Replace(config.Noavatar, "{site_url}", site.URL, -1)
if site.Port != "80" && site.Port != "443" {
site.URL = strings.TrimSuffix(site.URL, "/")
site.URL = strings.TrimSuffix(site.URL, "\\")
site.URL = strings.TrimSuffix(site.URL, ":")
site.URL = site.URL + ":" + site.Port
}
}

func main() {
// TODO: Have a file for each run with the time/date the server started as the file name?
// TODO: Log panics with recover()
Expand Down Expand Up @@ -121,6 +110,11 @@ func main() {
log.Fatal(err)
}

err = verifyConfig()
if err != nil {
log.Fatal(err)
}

// Run this goroutine once a second
secondTicker := time.NewTicker(1 * time.Second)
fifteenMinuteTicker := time.NewTicker(15 * time.Minute)
Expand Down Expand Up @@ -149,6 +143,7 @@ func main() {
// TODO: Manage the TopicStore, UserStore, and ForumStore
// TODO: Alert the admin, if CPU usage, RAM usage, or the number of posts in the past second are too high
// TODO: Clean-up alerts with no unread matches which are over two weeks old. Move this to a 24 hour task?
// TODO: Rescan the static files for changes

// TODO: Add a plugin hook here
case <-fifteenMinuteTicker.C:
Expand Down
3 changes: 3 additions & 0 deletions member_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func routeTopicCreate(w http.ResponseWriter, r *http.Request, user User, sfid st
return
}
}
if fid == 0 {
fid = config.DefaultForum
}

headerVars, ok := ForumUserCheck(w, r, &user, fid)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion mod_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func routeIps(w http.ResponseWriter, r *http.Request, user User) {
return
}

ip := html.EscapeString(r.URL.Path[len("/users/ips/"):])
ip := r.FormValue("ip")
var uid int
var reqUserList = make(map[int]bool)

Expand Down
30 changes: 28 additions & 2 deletions pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"
"strings"
"sync"
"time"
)

type HeaderVars struct {
Expand Down Expand Up @@ -227,7 +228,23 @@ type PanelEditGroupPermsPage struct {
GlobalPerms []NameLangToggle
}

type Log struct {
type backupItem struct {
SQLURL string

// TODO: Add an easier to parse format here for Gosora to be able to more easily reimport portions of the dump and to strip unneccesary data (e.g. table defs and parsed post data)

Timestamp time.Time
}

type PanelBackupPage struct {
Title string
CurrentUser User
Header *HeaderVars
Stats PanelStats
Backups []backupItem
}

type logItem struct {
Action template.HTML
IPAddress string
DoneAt string
Expand All @@ -238,7 +255,7 @@ type PanelLogsPage struct {
CurrentUser User
Header *HeaderVars
Stats PanelStats
Logs []Log
Logs []logItem
PageList []int
Page int
LastPage int
Expand Down Expand Up @@ -283,6 +300,7 @@ func init() {
urlReg = regexp.MustCompile(urlpattern)
}

// TODO: Write a test for this
func shortcodeToUnicode(msg string) string {
//re := regexp.MustCompile(":(.):")
msg = strings.Replace(msg, ":grinning:", "😀", -1)
Expand Down Expand Up @@ -421,6 +439,7 @@ func preparseMessage(msg string) string {
return shortcodeToUnicode(msg)
}

// TODO: Write a test for this
func parseMessage(msg string /*, user User*/) string {
msg = strings.Replace(msg, ":)", "😀", -1)
msg = strings.Replace(msg, ":(", "😞", -1)
Expand Down Expand Up @@ -634,6 +653,7 @@ func parseMessage(msg string /*, user User*/) string {
return msg
}

// TODO: Write a test for this
func regexParseMessage(msg string) string {
msg = strings.Replace(msg, ":)", "😀", -1)
msg = strings.Replace(msg, ":D", "😃", -1)
Expand All @@ -648,6 +668,7 @@ func regexParseMessage(msg string) string {

// 6, 7, 8, 6, 7
// ftp://, http://, https:// git://, mailto: (not a URL, just here for length comparison purposes)
// TODO: Write a test for this
func validateURLBytes(data []byte) bool {
datalen := len(data)
i := 0
Expand All @@ -670,6 +691,7 @@ func validateURLBytes(data []byte) bool {
return true
}

// TODO: Write a test for this
func validatedURLBytes(data []byte) (url []byte) {
datalen := len(data)
i := 0
Expand All @@ -694,6 +716,7 @@ func validatedURLBytes(data []byte) (url []byte) {
return url
}

// TODO: Write a test for this
func partialURLBytes(data []byte) (url []byte) {
datalen := len(data)
i := 0
Expand All @@ -719,6 +742,7 @@ func partialURLBytes(data []byte) (url []byte) {
return url
}

// TODO: Write a test for this
func partialURLBytesLen(data []byte) int {
datalen := len(data)
i := 0
Expand All @@ -745,6 +769,7 @@ func partialURLBytesLen(data []byte) int {
return datalen
}

// TODO: Write a test for this
func parseMediaBytes(data []byte) (protocol []byte, url []byte) {
datalen := len(data)
i := 0
Expand Down Expand Up @@ -774,6 +799,7 @@ func parseMediaBytes(data []byte) (protocol []byte, url []byte) {
return protocol, data[i:]
}

// TODO: Write a test for this
func coerceIntBytes(data []byte) (res int, length int) {
if !(data[0] > 47 && data[0] < 58) {
return 0, 1
Expand Down
Loading

0 comments on commit 11c60b3

Please sign in to comment.