93 lines
1.6 KiB
Go
93 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
type Config struct {
|
|
HttpPort int
|
|
HttpsPort int
|
|
CertPath string
|
|
KeyPath string
|
|
DocBase string
|
|
HomeDocBase string
|
|
LogPath string
|
|
AllowRemoteContent bool
|
|
MaxHtmlDepth int
|
|
MaxImages int
|
|
BadMimes []string
|
|
BadMimesMap map[string]bool
|
|
BadTags []string
|
|
BadTagsMap map[string]bool
|
|
BadDomains []string
|
|
}
|
|
|
|
func getConfig(filename string) (Config, error) {
|
|
|
|
var config Config
|
|
|
|
// Defaults
|
|
config.HttpPort = 80
|
|
config.HttpsPort = 443
|
|
config.CertPath = "cert.pem"
|
|
config.KeyPath = "key.pem"
|
|
config.DocBase = "/var/www/"
|
|
config.HomeDocBase = "/html/"
|
|
config.LogPath = "shizaru.log"
|
|
|
|
config.AllowRemoteContent = false
|
|
config.MaxHtmlDepth = 10
|
|
config.MaxImages = 3
|
|
|
|
config.BadMimes = []string{
|
|
"text/javascript",
|
|
"application/javascript",
|
|
"application/x-shockwave-flash",
|
|
}
|
|
|
|
config.BadTags = []string{
|
|
"applet",
|
|
"audio",
|
|
"base",
|
|
"blink",
|
|
"canvas",
|
|
"embed",
|
|
"frame",
|
|
"frameset",
|
|
"iframe",
|
|
"marquee",
|
|
"script",
|
|
}
|
|
|
|
config.BadDomains = []string{
|
|
"facebook.com",
|
|
"google.com",
|
|
"instagram.com",
|
|
"twitter.com",
|
|
}
|
|
|
|
if filename == "" {
|
|
return config, nil
|
|
}
|
|
|
|
_, err := toml.DecodeFile(filename, &config)
|
|
if err != nil {
|
|
return config, err
|
|
}
|
|
|
|
// Build maps from lists
|
|
config.BadTagsMap = sliceToMap(config.BadTags)
|
|
config.BadMimesMap = sliceToMap(config.BadMimes)
|
|
|
|
// Done
|
|
return config, nil
|
|
}
|
|
|
|
func sliceToMap(slice []string) map[string]bool {
|
|
themap := make(map[string]bool)
|
|
for _, x := range slice {
|
|
themap[x] = true
|
|
}
|
|
return themap
|
|
}
|