diff options
Diffstat (limited to 'utils/config.go')
-rw-r--r-- | utils/config.go | 102 |
1 files changed, 69 insertions, 33 deletions
diff --git a/utils/config.go b/utils/config.go index c67e17e79..0eb8329d1 100644 --- a/utils/config.go +++ b/utils/config.go @@ -4,33 +4,38 @@ package utils import ( - l4g "code.google.com/p/log4go" "encoding/json" + "fmt" "os" "path/filepath" + "strconv" + + l4g "code.google.com/p/log4go" ) const ( - MODE_DEV = "dev" - MODE_BETA = "beta" - MODE_PROD = "prod" + MODE_DEV = "dev" + MODE_BETA = "beta" + MODE_PROD = "prod" + LOG_ROTATE_SIZE = 10000 ) type ServiceSettings struct { - SiteName string - Mode string - AllowTesting bool - UseSSL bool - Port string - Version string - InviteSalt string - PublicLinkSalt string - ResetSalt string - AnalyticsUrl string - UseLocalStorage bool - StorageDirectory string - AllowedLoginAttempts int - DisableEmailSignUp bool + SiteName string + Mode string + AllowTesting bool + UseSSL bool + Port string + Version string + InviteSalt string + PublicLinkSalt string + ResetSalt string + AnalyticsUrl string + UseLocalStorage bool + StorageDirectory string + AllowedLoginAttempts int + DisableEmailSignUp bool + EnableOAuthServiceProvider bool } type SSOSetting struct { @@ -108,15 +113,15 @@ type PrivacySettings struct { ShowFullName bool } +type ClientSettings struct { + SegmentDeveloperKey string + GoogleDeveloperKey string +} + type TeamSettings struct { MaxUsersPerTeam int AllowPublicLink bool AllowValetDefault bool - TermsLink string - PrivacyLink string - AboutLink string - HelpLink string - ReportProblemLink string TourLink string DefaultThemeColor string DisableTeamCreation bool @@ -132,6 +137,7 @@ type Config struct { EmailSettings EmailSettings RateLimitSettings RateLimitSettings PrivacySettings PrivacySettings + ClientSettings ClientSettings TeamSettings TeamSettings SSOSettings map[string]SSOSetting } @@ -146,6 +152,8 @@ func (o *Config) ToJson() string { } var Cfg *Config = &Config{} +var CfgLastModified int64 = 0 +var ClientProperties map[string]string = map[string]string{} var SanitizeOptions map[string]bool = map[string]bool{} func FindConfigFile(fileName string) string { @@ -180,10 +188,10 @@ func ConfigureCmdLineLog() { ls.ConsoleEnable = true ls.ConsoleLevel = "ERROR" ls.FileEnable = false - configureLog(ls) + configureLog(&ls) } -func configureLog(s LogSettings) { +func configureLog(s *LogSettings) { l4g.Close() @@ -217,7 +225,7 @@ func configureLog(s LogSettings) { flw := l4g.NewFileLogWriter(s.FileLocation, false) flw.SetFormat(s.FileFormat) flw.SetRotate(true) - flw.SetRotateLines(100000) + flw.SetRotateLines(LOG_ROTATE_SIZE) l4g.AddFilter("file", level, flw) } } @@ -241,22 +249,50 @@ func LoadConfig(fileName string) { panic("Error decoding config file=" + fileName + ", err=" + err.Error()) } - configureLog(config.LogSettings) + if info, err := file.Stat(); err != nil { + panic("Error getting config info file=" + fileName + ", err=" + err.Error()) + } else { + CfgLastModified = info.ModTime().Unix() + } + + configureLog(&config.LogSettings) Cfg = &config - SanitizeOptions = getSanitizeOptions() + SanitizeOptions = getSanitizeOptions(Cfg) + ClientProperties = getClientProperties(Cfg) } -func getSanitizeOptions() map[string]bool { +func getSanitizeOptions(c *Config) map[string]bool { options := map[string]bool{} - options["fullname"] = Cfg.PrivacySettings.ShowFullName - options["email"] = Cfg.PrivacySettings.ShowEmailAddress - options["skypeid"] = Cfg.PrivacySettings.ShowSkypeId - options["phonenumber"] = Cfg.PrivacySettings.ShowPhoneNumber + options["fullname"] = c.PrivacySettings.ShowFullName + options["email"] = c.PrivacySettings.ShowEmailAddress + options["skypeid"] = c.PrivacySettings.ShowSkypeId + options["phonenumber"] = c.PrivacySettings.ShowPhoneNumber return options } +func getClientProperties(c *Config) map[string]string { + props := make(map[string]string) + + props["Version"] = c.ServiceSettings.Version + props["SiteName"] = c.ServiceSettings.SiteName + props["ByPassEmail"] = strconv.FormatBool(c.EmailSettings.ByPassEmail) + props["FeedbackEmail"] = c.EmailSettings.FeedbackEmail + props["ShowEmailAddress"] = strconv.FormatBool(c.PrivacySettings.ShowEmailAddress) + props["AllowPublicLink"] = strconv.FormatBool(c.TeamSettings.AllowPublicLink) + props["SegmentDeveloperKey"] = c.ClientSettings.SegmentDeveloperKey + props["GoogleDeveloperKey"] = c.ClientSettings.GoogleDeveloperKey + props["AnalyticsUrl"] = c.ServiceSettings.AnalyticsUrl + props["ByPassEmail"] = strconv.FormatBool(c.EmailSettings.ByPassEmail) + props["ProfileHeight"] = fmt.Sprintf("%v", c.ImageSettings.ProfileHeight) + props["ProfileWidth"] = fmt.Sprintf("%v", c.ImageSettings.ProfileWidth) + props["ProfileWidth"] = fmt.Sprintf("%v", c.ImageSettings.ProfileWidth) + props["EnableOAuthServiceProvider"] = strconv.FormatBool(c.ServiceSettings.EnableOAuthServiceProvider) + + return props +} + func IsS3Configured() bool { if Cfg.AWSSettings.S3AccessKeyId == "" || Cfg.AWSSettings.S3SecretAccessKey == "" || Cfg.AWSSettings.S3Region == "" || Cfg.AWSSettings.S3Bucket == "" { return false |