f8f46b3c48
Added the Account Dashboard and merged a few account views into it. BREAKING CHANGE: We now use config/config.json instead of config/config.go, be sure to setup one of these files, you can config_default.json as an example of what a config.json should look like. If you don't have an existing installation, you can just rely on the installer to do this for you. CSS Changes (does not include Nox Theme): Sidebar should no longer show up in the account manager in some odd situations or themes. Made a few CSS rules more generic. Forms have a new look in Cosora now. Config Changes: Removed the DefaultRoute config field. Added the DefaultPath config field. Added the MaxRequestSizeStr config field to make it easier for users to input custom max request sizes without having to use a calculator or figure out how many bytes there are in a megabyte. Removed the CacheTopicUser config field. Added the UserCache config field. Added the TopicCache config field Phrases: Removed ten english phrases. Added 21 english phrases. Changed eleven english phrases. Removed some duplicate indices in the english phrase pack. Removed some old benchmark code. Tweaked some things to make the linter happy. Added comments for all the MemoryUserCache and MemoryTopicCache methods. Added a comment for the null caches, consult the other caches for further information on the methods. Added a client-side check to make sure the user doesn't upload too much data in a single post. The server already did this, but it might be a while before feedback arrives from it. Simplified a lot of the control panel route code with the buildBasePage function. Renamed /user/edit/critical/ to /user/edit/password/ Renamed /user/edit/critical/submit/ to /user/edit/password/submit/ Made some small improvements to SEO with a couple of meta tags. Renamed some of the control panel templates so that they use _ instead of -. Fixed a bug where notices were being moved to the wrong place in some areas in Cosora. Added the writeJsonError function to help abstract writing json errors. Moved routePanelUsers to panel.Users Moved routePanelUsersEdit to panel.UsersEdit Moved routePanelUsersEditSubmit to panel.UsersEditSubmit Renamed routes.AccountEditCritical to routes.AccountEditPassword Renamed routes.AccountEditCriticalSubmit to routes.AccountEditPasswordSubmit Removed the routes.AccountEditAvatar and routes.AccountEditUsername routes. Fixed a data race in MemoryTopicCache.Add which could lead to the capacity limit being bypassed. Tweaked MemoryTopicCache.AddUnsafe under the assumption that it's not going to be safe anyway, but we might as-well try in case this call is properly synchronised. Fixed a data race in MemoryTopicCache.Remove which could lead to the length counter being decremented twice. Tweaked the behaviour of MemoryTopicCache.RemoveUnsafe to mirror that of Remove. Fixed a data race in MemoryUserCache.Add which could lead to the capacity limit being bypassed. User can no longer change their usernames to blank. Made a lot of progress on the Nox theme. Added modified FA5 SVGs as a dependency for Nox. Be sure to run the patcher or update script and don't forget to create a customised config/config.json file.
121 lines
3.1 KiB
Go
121 lines
3.1 KiB
Go
package common
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"../query_gen/lib"
|
|
)
|
|
|
|
// nolint I don't want to write comments for each of these o.o
|
|
const Hour int = 60 * 60
|
|
const Day int = Hour * 24
|
|
const Week int = Day * 7
|
|
const Month int = Day * 30
|
|
const Year int = Day * 365
|
|
const Kilobyte int = 1024
|
|
const Megabyte int = Kilobyte * 1024
|
|
const Gigabyte int = Megabyte * 1024
|
|
const Terabyte int = Gigabyte * 1024
|
|
const Petabyte int = Terabyte * 1024
|
|
|
|
var StartTime time.Time
|
|
var TmplPtrMap = make(map[string]interface{})
|
|
|
|
// Anti-spam token with rotated key
|
|
var JSTokenBox atomic.Value // TODO: Move this and some of these other globals somewhere else
|
|
var SessionSigningKeyBox atomic.Value // For MFA to avoid hitting the database unneccesarily
|
|
var OldSessionSigningKeyBox atomic.Value // Just in case we've signed with a key that's about to go stale so we don't annoy the user too much
|
|
|
|
// ErrNoRows is an alias of sql.ErrNoRows, just in case we end up with non-database/sql datastores
|
|
var ErrNoRows = sql.ErrNoRows
|
|
|
|
// ? - Make this more customisable?
|
|
var ExternalSites = map[string]string{
|
|
"YT": "https://www.youtube.com/",
|
|
}
|
|
|
|
type StringList []string
|
|
|
|
// ? - Should we allow users to upload .php or .go files? It could cause security issues. We could store them with a mangled extension to render them inert
|
|
// TODO: Let admins manage this from the Control Panel
|
|
var AllowedFileExts = StringList{
|
|
"png", "jpg", "jpeg", "svg", "bmp", "gif", "tif", "webp", "apng", // images
|
|
|
|
"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", // text
|
|
|
|
"mp3", "mp4", "avi", "wmv", "webm", // video
|
|
|
|
"otf", "woff2", "woff", "ttf", "eot", // fonts
|
|
}
|
|
var ImageFileExts = StringList{
|
|
"png", "jpg", "jpeg", "svg", "bmp", "gif", "tif", "webp", "apng",
|
|
}
|
|
var ArchiveFileExts = StringList{
|
|
"bz2", "zip", "gz", "7z", "tar", "cab",
|
|
}
|
|
var ExecutableFileExts = StringList{
|
|
"exe", "jar", "phar", "shar", "iso",
|
|
}
|
|
|
|
func init() {
|
|
JSTokenBox.Store("")
|
|
SessionSigningKeyBox.Store("")
|
|
OldSessionSigningKeyBox.Store("")
|
|
}
|
|
|
|
// TODO: Write a test for this
|
|
func (slice StringList) Contains(needle string) bool {
|
|
for _, item := range slice {
|
|
if item == needle {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
type dbInits []func(acc *qgen.Accumulator) error
|
|
|
|
var DbInits dbInits
|
|
|
|
func (inits dbInits) Run() error {
|
|
for _, init := range inits {
|
|
acc := qgen.Builder.Accumulator()
|
|
err := init(acc)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (inits dbInits) Add(init ...func(acc *qgen.Accumulator) error) {
|
|
DbInits = dbInits(append(DbInits, init...))
|
|
}
|
|
|
|
func DebugDetail(args ...interface{}) {
|
|
if Dev.SuperDebug {
|
|
log.Print(args...)
|
|
}
|
|
}
|
|
|
|
func DebugDetailf(str string, args ...interface{}) {
|
|
if Dev.SuperDebug {
|
|
log.Printf(str, args...)
|
|
}
|
|
}
|
|
|
|
func DebugLog(args ...interface{}) {
|
|
if Dev.DebugMode {
|
|
log.Print(args...)
|
|
}
|
|
}
|
|
|
|
func DebugLogf(str string, args ...interface{}) {
|
|
if Dev.DebugMode {
|
|
log.Printf(str, args...)
|
|
}
|
|
}
|