2017-11-10 03:33:11 +00:00
package common
2017-07-17 10:23:42 +00:00
2017-09-23 19:57:13 +00:00
import (
"errors"
"strings"
)
2017-07-17 10:23:42 +00:00
2017-11-11 04:06:16 +00:00
// Site holds the basic settings which should be tweaked when setting up a site, we might move them to the settings table at some point
var Site = & site { Name : "Magical Fairy Land" , Language : "english" }
2017-07-17 10:23:42 +00:00
2017-11-11 04:06:16 +00:00
// DbConfig holds the database configuration
var DbConfig = dbConfig { Host : "localhost" }
// Config holds the more technical settings
var Config config
// Dev holds build flags and other things which should only be modified during developers or to gather additional test data
var Dev devConfig
type site struct {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
ShortName string
2017-11-11 04:06:16 +00:00
Name string
Email string
2017-09-13 15:09:13 +00:00
URL string
2018-01-25 04:57:33 +00:00
Host string
2017-09-10 16:57:22 +00:00
Port string
EnableSsl bool
2017-07-17 10:23:42 +00:00
EnableEmails bool
2017-09-10 16:57:22 +00:00
HasProxy bool
2017-11-11 04:06:16 +00:00
Language string
2017-07-17 10:23:42 +00:00
}
2017-11-11 04:06:16 +00:00
type dbConfig struct {
2017-10-14 07:39:22 +00:00
// Production database
2018-04-22 14:27:04 +00:00
Adapter string
2017-09-10 16:57:22 +00:00
Host string
2017-07-17 10:23:42 +00:00
Username string
Password string
2017-09-10 16:57:22 +00:00
Dbname string
Port string
2017-10-14 07:39:22 +00:00
// Test database. Split this into a separate variable?
2018-04-22 14:27:04 +00:00
TestAdapter string
2017-10-14 07:39:22 +00:00
TestHost string
TestUsername string
TestPassword string
TestDbname string
TestPort string
2017-07-17 10:23:42 +00:00
}
2017-11-11 04:06:16 +00:00
type config struct {
2017-09-10 16:57:22 +00:00
SslPrivkey string
2017-07-17 10:23:42 +00:00
SslFullchain string
2017-09-10 16:57:22 +00:00
MaxRequestSize int
CacheTopicUser int
UserCacheCapacity int
2017-07-17 10:23:42 +00:00
TopicCacheCapacity int
2017-09-18 17:03:52 +00:00
SMTPServer string
SMTPUsername string
SMTPPassword string
SMTPPort string
2017-12-19 03:53:13 +00:00
//SMTPEnableTLS bool
2017-07-17 10:23:42 +00:00
2017-12-22 03:32:23 +00:00
DefaultRoute string
2017-09-23 19:57:13 +00:00
DefaultGroup int
ActivationGroup int
StaffCSS string // ? - Move this into the settings table? Might be better to implement this as Group CSS
DefaultForum int // The forum posts go in by default, this used to be covered by the Uncategorised Forum, but we want to replace it with a more robust solution. Make this a setting?
MinifyTemplates bool
2018-04-03 04:34:07 +00:00
BuildSlugs bool // TODO: Make this a setting?
2018-02-15 13:15:27 +00:00
ServerCount int
2017-07-17 10:23:42 +00:00
2018-03-17 08:16:43 +00:00
Noavatar string // ? - Move this into the settings table?
ItemsPerPage int // ? - Move this into the settings table?
MaxTopicTitleLength int
MaxUsernameLength int
2017-07-17 10:23:42 +00:00
}
2017-11-11 04:06:16 +00:00
type devConfig struct {
2017-09-23 21:28:50 +00:00
DebugMode bool
SuperDebug bool
TemplateDebug bool
Profiling bool
2017-10-14 07:39:22 +00:00
TestDB bool
2017-07-17 10:23:42 +00:00
}
2017-09-23 19:57:13 +00:00
2017-11-11 04:06:16 +00:00
func ProcessConfig ( ) error {
Config . Noavatar = strings . Replace ( Config . Noavatar , "{site_url}" , Site . URL , - 1 )
2018-01-25 04:57:33 +00:00
Site . Host = Site . URL
2017-11-11 04:06:16 +00:00
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
2017-09-23 19:57:13 +00:00
}
2018-03-17 08:16:43 +00:00
// ? Find a way of making these unlimited if zero? It might rule out some optimisations, waste memory, and break layouts
if Config . MaxTopicTitleLength == 0 {
Config . MaxTopicTitleLength = 100
}
if Config . MaxUsernameLength == 0 {
Config . MaxUsernameLength = 100
}
2017-10-14 07:39:22 +00:00
// We need this in here rather than verifyConfig as switchToTestDB() currently overwrites the values it verifies
2017-11-11 04:06:16 +00:00
if DbConfig . TestDbname == DbConfig . Dbname {
2017-10-14 07:39:22 +00:00
return errors . New ( "Your test database can't have the same name as your production database" )
}
2017-11-11 04:06:16 +00:00
if Dev . TestDB {
SwitchToTestDB ( )
2017-10-14 07:39:22 +00:00
}
return nil
2017-09-23 19:57:13 +00:00
}
2017-11-11 04:06:16 +00:00
func VerifyConfig ( ) error {
2017-11-23 05:37:08 +00:00
if ! Forums . Exists ( Config . DefaultForum ) {
2017-09-23 19:57:13 +00:00
return errors . New ( "Invalid default forum" )
}
2018-02-15 13:15:27 +00:00
if Config . ServerCount < 1 {
return errors . New ( "You can't have less than one server" )
}
2018-03-17 08:16:43 +00:00
if Config . MaxTopicTitleLength > 100 {
return errors . New ( "The max topic title length cannot be over 100 as that's unable to fit in the database row" )
}
if Config . MaxUsernameLength > 100 {
return errors . New ( "The max username length cannot be over 100 as that's unable to fit in the database row" )
}
2017-09-23 19:57:13 +00:00
return nil
}
2017-10-14 07:39:22 +00:00
2017-11-11 04:06:16 +00:00
func SwitchToTestDB ( ) {
DbConfig . Host = DbConfig . TestHost
DbConfig . Username = DbConfig . TestUsername
DbConfig . Password = DbConfig . TestPassword
DbConfig . Dbname = DbConfig . TestDbname
DbConfig . Port = DbConfig . TestPort
2017-10-14 07:39:22 +00:00
}