1 package util 2 3 import ( 4 "log" 5 "strings" 6 "time" 7 ) 8 9 type UploadType struct { 10 Ext string 11 MIME string 12 Thumb string 13 } 14 15 // Config represents the server configuration. 16 type Config struct { 17 Locale string // Default locale. See locale directory for available languages. 18 Root string // Directory where board files are written to. 19 HTTP string // Address:Port to listen for HTTP connections on. 20 HTTPS string // Address:Port to listen for HTTPS connections on. 21 Header string // Client IP address header. 22 RejectHTTP1 bool // Whether the server should reject HTTP/1 connections. 23 24 HTTPSCert string // Path to HTTPS certificate file. 25 HTTPSKey string // Path to HTTPS certificate private key file. 26 InsecureSkipVerify bool // Whether HTTPS certificate verification is skipped. 27 28 Algorithm string // Hash algorithm. Supported algorithms are sha-2 and sha-3. 29 SaltData string // Long random string of text used when one-way hashing data. Must not change once set. 30 SaltPass string // Long random string of text used when two-way hashing data. Must not change once set. 31 SaltTrip string // Long random string of text used when generating secure tripcodes. Must not change once set. 32 33 Address string // Address:Port to connect to the database. 34 Username string // Database username. 35 Password string // Database password. 36 DBName string // Database name. 37 DBURL string // Database connection URL. 38 39 MailAddress string // SMTP server Address:Port. 40 MailTLS bool // Whether TLS is used to connect to the server. 41 MailInsecure bool // Whether TLS certificate verification is skipped. 42 MailUsername string // SMTP server username. 43 MailPassword string // SMTP server password. 44 MailAuth string // SMTP server authentication mechanism. May be challenge / plain / none. 45 MailFrom string // "From" email address. 46 MailReplyTo string // "Reply-To" email address. 47 MailDomains string // Regular expression specifying allowed email address domains. 48 49 Mentions int // Duration (in minutes) mention notifications are batched together. 50 Notifications int // Duration (in minutes) non-mention notifications are batched together. 51 52 Template string // Custom template directory. 53 54 Identifiers bool // Whether staff may browse posts by IP hashes and boards may display identifier hashes. 55 56 Uploads []string // Supported upload file types. 57 58 Access map[string]string // Specifies which roles may perform each management or moderation action. 59 60 // Calculated fields. 61 cachedUploads []*UploadType 62 ImportMode bool 63 ImportComplete bool 64 StartTime time.Time 65 66 // Obsolete fields. 67 Serve string // Replaced by HTTP option. 68 } 69 70 func (c *Config) UploadTypes() []*UploadType { 71 if c.cachedUploads != nil { 72 return c.cachedUploads 73 } 74 uploads := []*UploadType{} 75 for _, upload := range c.Uploads { 76 fields := strings.Fields(upload) 77 l := len(fields) 78 if l != 2 && l != 3 { 79 log.Fatalf("error: invalid entry in uploads configuration: expected 2 or 3 fields, found %d: %s\nexpected format: ext mime optional_thumb", l, upload) 80 } 81 u := &UploadType{ 82 Ext: strings.ToLower(fields[0]), 83 MIME: strings.ToLower(fields[1]), 84 } 85 if l == 3 { 86 u.Thumb = fields[2] 87 } 88 uploads = append(uploads, u) 89 } 90 c.cachedUploads = uploads 91 return uploads 92 } 93