github.com/rajatvaryani/mattermost-server@v5.11.1+incompatible/model/config.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "crypto/tls" 8 "encoding/json" 9 "io" 10 "math" 11 "net" 12 "net/http" 13 "net/url" 14 "os" 15 "regexp" 16 "strconv" 17 "strings" 18 "time" 19 20 "github.com/go-ldap/ldap" 21 ) 22 23 const ( 24 CONN_SECURITY_NONE = "" 25 CONN_SECURITY_PLAIN = "PLAIN" 26 CONN_SECURITY_TLS = "TLS" 27 CONN_SECURITY_STARTTLS = "STARTTLS" 28 29 IMAGE_DRIVER_LOCAL = "local" 30 IMAGE_DRIVER_S3 = "amazons3" 31 32 DATABASE_DRIVER_SQLITE = "sqlite3" 33 DATABASE_DRIVER_MYSQL = "mysql" 34 DATABASE_DRIVER_POSTGRES = "postgres" 35 36 MINIO_ACCESS_KEY = "minioaccesskey" 37 MINIO_SECRET_KEY = "miniosecretkey" 38 MINIO_BUCKET = "mattermost-test" 39 40 PASSWORD_MAXIMUM_LENGTH = 64 41 PASSWORD_MINIMUM_LENGTH = 5 42 43 SERVICE_GITLAB = "gitlab" 44 SERVICE_GOOGLE = "google" 45 SERVICE_OFFICE365 = "office365" 46 47 GENERIC_NO_CHANNEL_NOTIFICATION = "generic_no_channel" 48 GENERIC_NOTIFICATION = "generic" 49 FULL_NOTIFICATION = "full" 50 51 DIRECT_MESSAGE_ANY = "any" 52 DIRECT_MESSAGE_TEAM = "team" 53 54 SHOW_USERNAME = "username" 55 SHOW_NICKNAME_FULLNAME = "nickname_full_name" 56 SHOW_FULLNAME = "full_name" 57 58 PERMISSIONS_ALL = "all" 59 PERMISSIONS_CHANNEL_ADMIN = "channel_admin" 60 PERMISSIONS_TEAM_ADMIN = "team_admin" 61 PERMISSIONS_SYSTEM_ADMIN = "system_admin" 62 63 FAKE_SETTING = "********************************" 64 65 RESTRICT_EMOJI_CREATION_ALL = "all" 66 RESTRICT_EMOJI_CREATION_ADMIN = "admin" 67 RESTRICT_EMOJI_CREATION_SYSTEM_ADMIN = "system_admin" 68 69 PERMISSIONS_DELETE_POST_ALL = "all" 70 PERMISSIONS_DELETE_POST_TEAM_ADMIN = "team_admin" 71 PERMISSIONS_DELETE_POST_SYSTEM_ADMIN = "system_admin" 72 73 ALLOW_EDIT_POST_ALWAYS = "always" 74 ALLOW_EDIT_POST_NEVER = "never" 75 ALLOW_EDIT_POST_TIME_LIMIT = "time_limit" 76 77 GROUP_UNREAD_CHANNELS_DISABLED = "disabled" 78 GROUP_UNREAD_CHANNELS_DEFAULT_ON = "default_on" 79 GROUP_UNREAD_CHANNELS_DEFAULT_OFF = "default_off" 80 81 EMAIL_BATCHING_BUFFER_SIZE = 256 82 EMAIL_BATCHING_INTERVAL = 30 83 84 EMAIL_NOTIFICATION_CONTENTS_FULL = "full" 85 EMAIL_NOTIFICATION_CONTENTS_GENERIC = "generic" 86 87 SITENAME_MAX_LENGTH = 30 88 89 SERVICE_SETTINGS_DEFAULT_SITE_URL = "http://localhost:8065" 90 SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE = "" 91 SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE = "" 92 SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT = 300 93 SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT = 300 94 SERVICE_SETTINGS_DEFAULT_MAX_LOGIN_ATTEMPTS = 10 95 SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM = "" 96 SERVICE_SETTINGS_DEFAULT_LISTEN_AND_ADDRESS = ":8065" 97 SERVICE_SETTINGS_DEFAULT_GFYCAT_API_KEY = "2_KtH_W5" 98 SERVICE_SETTINGS_DEFAULT_GFYCAT_API_SECRET = "3wLVZPiswc3DnaiaFoLkDvB4X0IV6CpMkj4tf2inJRsBY6-FnkT08zGmppWFgeof" 99 100 TEAM_SETTINGS_DEFAULT_SITE_NAME = "Mattermost" 101 TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM = 50 102 TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT = "" 103 TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT = "" 104 TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT = 300 105 106 SQL_SETTINGS_DEFAULT_DATA_SOURCE = "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s" 107 108 FILE_SETTINGS_DEFAULT_DIRECTORY = "./data/" 109 110 EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION = "" 111 112 SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK = "https://about.mattermost.com/default-terms/" 113 SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK = "https://about.mattermost.com/default-privacy-policy/" 114 SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK = "https://about.mattermost.com/default-about/" 115 SUPPORT_SETTINGS_DEFAULT_HELP_LINK = "https://about.mattermost.com/default-help/" 116 SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK = "https://about.mattermost.com/default-report-a-problem/" 117 SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL = "feedback@mattermost.com" 118 SUPPORT_SETTINGS_DEFAULT_RE_ACCEPTANCE_PERIOD = 365 119 120 LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE = "" 121 LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE = "" 122 LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE = "" 123 LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE = "" 124 LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE = "" 125 LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE = "" 126 LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE = "" 127 LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME = "" 128 LDAP_SETTINGS_DEFAULT_GROUP_DISPLAY_NAME_ATTRIBUTE = "" 129 LDAP_SETTINGS_DEFAULT_GROUP_ID_ATTRIBUTE = "" 130 131 SAML_SETTINGS_DEFAULT_ID_ATTRIBUTE = "" 132 SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE = "" 133 SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE = "" 134 SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE = "" 135 SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE = "" 136 SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE = "" 137 SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE = "" 138 SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE = "" 139 140 NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK = "https://about.mattermost.com/downloads/" 141 NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK = "https://about.mattermost.com/mattermost-android-app/" 142 NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK = "https://about.mattermost.com/mattermost-ios-app/" 143 144 EXPERIMENTAL_SETTINGS_DEFAULT_LINK_METADATA_TIMEOUT_MILLISECONDS = 5000 145 146 ANALYTICS_SETTINGS_DEFAULT_MAX_USERS_FOR_STATISTICS = 2500 147 148 ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR = "#f2a93b" 149 ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR = "#333333" 150 151 TEAM_SETTINGS_DEFAULT_TEAM_TEXT = "default" 152 153 ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL = "http://dockerhost:9200" 154 ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME = "elastic" 155 ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD = "changeme" 156 ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS = 1 157 ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS = 1 158 ELASTICSEARCH_SETTINGS_DEFAULT_CHANNEL_INDEX_REPLICAS = 1 159 ELASTICSEARCH_SETTINGS_DEFAULT_CHANNEL_INDEX_SHARDS = 1 160 ELASTICSEARCH_SETTINGS_DEFAULT_USER_INDEX_REPLICAS = 1 161 ELASTICSEARCH_SETTINGS_DEFAULT_USER_INDEX_SHARDS = 1 162 ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS = 365 163 ELASTICSEARCH_SETTINGS_DEFAULT_POSTS_AGGREGATOR_JOB_START_TIME = "03:00" 164 ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX = "" 165 ELASTICSEARCH_SETTINGS_DEFAULT_LIVE_INDEXING_BATCH_SIZE = 1 166 ELASTICSEARCH_SETTINGS_DEFAULT_BULK_INDEXING_TIME_WINDOW_SECONDS = 3600 167 ELASTICSEARCH_SETTINGS_DEFAULT_REQUEST_TIMEOUT_SECONDS = 30 168 169 DATA_RETENTION_SETTINGS_DEFAULT_MESSAGE_RETENTION_DAYS = 365 170 DATA_RETENTION_SETTINGS_DEFAULT_FILE_RETENTION_DAYS = 365 171 DATA_RETENTION_SETTINGS_DEFAULT_DELETION_JOB_START_TIME = "02:00" 172 173 PLUGIN_SETTINGS_DEFAULT_DIRECTORY = "./plugins" 174 PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY = "./client/plugins" 175 176 COMPLIANCE_EXPORT_TYPE_CSV = "csv" 177 COMPLIANCE_EXPORT_TYPE_ACTIANCE = "actiance" 178 COMPLIANCE_EXPORT_TYPE_GLOBALRELAY = "globalrelay" 179 GLOBALRELAY_CUSTOMER_TYPE_A9 = "A9" 180 GLOBALRELAY_CUSTOMER_TYPE_A10 = "A10" 181 182 CLIENT_SIDE_CERT_CHECK_PRIMARY_AUTH = "primary" 183 CLIENT_SIDE_CERT_CHECK_SECONDARY_AUTH = "secondary" 184 185 IMAGE_PROXY_TYPE_LOCAL = "local" 186 IMAGE_PROXY_TYPE_ATMOS_CAMO = "atmos/camo" 187 ) 188 189 var ServerTLSSupportedCiphers = map[string]uint16{ 190 "TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA, 191 "TLS_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, 192 "TLS_RSA_WITH_AES_128_CBC_SHA": tls.TLS_RSA_WITH_AES_128_CBC_SHA, 193 "TLS_RSA_WITH_AES_256_CBC_SHA": tls.TLS_RSA_WITH_AES_256_CBC_SHA, 194 "TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256, 195 "TLS_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_RSA_WITH_AES_128_GCM_SHA256, 196 "TLS_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_RSA_WITH_AES_256_GCM_SHA384, 197 "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, 198 "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, 199 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, 200 "TLS_ECDHE_RSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, 201 "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, 202 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, 203 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, 204 "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, 205 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, 206 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 207 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 208 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, 209 "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, 210 "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, 211 "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, 212 } 213 214 type ServiceSettings struct { 215 SiteURL *string `restricted:"true"` 216 WebsocketURL *string `restricted:"true"` 217 LicenseFileLocation *string `restricted:"true"` 218 ListenAddress *string `restricted:"true"` 219 ConnectionSecurity *string `restricted:"true"` 220 TLSCertFile *string `restricted:"true"` 221 TLSKeyFile *string `restricted:"true"` 222 TLSMinVer *string `restricted:"true"` 223 TLSStrictTransport *bool `restricted:"true"` 224 TLSStrictTransportMaxAge *int64 `restricted:"true"` 225 TLSOverwriteCiphers []string `restricted:"true"` 226 UseLetsEncrypt *bool `restricted:"true"` 227 LetsEncryptCertificateCacheFile *string `restricted:"true"` 228 Forward80To443 *bool `restricted:"true"` 229 ReadTimeout *int `restricted:"true"` 230 WriteTimeout *int `restricted:"true"` 231 MaximumLoginAttempts *int `restricted:"true"` 232 GoroutineHealthThreshold *int `restricted:"true"` 233 GoogleDeveloperKey *string `restricted:"true"` 234 EnableOAuthServiceProvider *bool 235 EnableIncomingWebhooks *bool 236 EnableOutgoingWebhooks *bool 237 EnableCommands *bool 238 DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations *bool `json:"EnableOnlyAdminIntegrations"` // This field is deprecated and must not be used. 239 EnablePostUsernameOverride *bool 240 EnablePostIconOverride *bool 241 EnableLinkPreviews *bool 242 EnableTesting *bool `restricted:"true"` 243 EnableDeveloper *bool `restricted:"true"` 244 EnableSecurityFixAlert *bool `restricted:"true"` 245 EnableInsecureOutgoingConnections *bool `restricted:"true"` 246 AllowedUntrustedInternalConnections *string `restricted:"true"` 247 EnableMultifactorAuthentication *bool 248 EnforceMultifactorAuthentication *bool 249 EnableUserAccessTokens *bool 250 AllowCorsFrom *string `restricted:"true"` 251 CorsExposedHeaders *string `restricted:"true"` 252 CorsAllowCredentials *bool `restricted:"true"` 253 CorsDebug *bool `restricted:"true"` 254 AllowCookiesForSubdomains *bool `restricted:"true"` 255 SessionLengthWebInDays *int `restricted:"true"` 256 SessionLengthMobileInDays *int `restricted:"true"` 257 SessionLengthSSOInDays *int `restricted:"true"` 258 SessionCacheInMinutes *int `restricted:"true"` 259 SessionIdleTimeoutInMinutes *int `restricted:"true"` 260 WebsocketSecurePort *int `restricted:"true"` 261 WebsocketPort *int `restricted:"true"` 262 WebserverMode *string `restricted:"true"` 263 EnableCustomEmoji *bool 264 EnableEmojiPicker *bool 265 EnableGifPicker *bool 266 GfycatApiKey *string 267 GfycatApiSecret *string 268 DEPRECATED_DO_NOT_USE_RestrictCustomEmojiCreation *string `json:"RestrictCustomEmojiCreation"` // This field is deprecated and must not be used. 269 DEPRECATED_DO_NOT_USE_RestrictPostDelete *string `json:"RestrictPostDelete"` // This field is deprecated and must not be used. 270 DEPRECATED_DO_NOT_USE_AllowEditPost *string `json:"AllowEditPost"` // This field is deprecated and must not be used. 271 PostEditTimeLimit *int 272 TimeBetweenUserTypingUpdatesMilliseconds *int64 `restricted:"true"` 273 EnablePostSearch *bool `restricted:"true"` 274 MinimumHashtagLength *int `restricted:"true"` 275 EnableUserTypingMessages *bool `restricted:"true"` 276 EnableChannelViewedMessages *bool `restricted:"true"` 277 EnableUserStatuses *bool `restricted:"true"` 278 ExperimentalEnableAuthenticationTransfer *bool `restricted:"true"` 279 ClusterLogTimeoutMilliseconds *int `restricted:"true"` 280 CloseUnusedDirectMessages *bool 281 EnablePreviewFeatures *bool 282 EnableTutorial *bool 283 ExperimentalEnableDefaultChannelLeaveJoinMessages *bool 284 ExperimentalGroupUnreadChannels *string 285 ExperimentalChannelOrganization *bool 286 DEPRECATED_DO_NOT_USE_ImageProxyType *string `json:"ImageProxyType" mapstructure:"ImageProxyType"` // This field is deprecated and must not be used. 287 DEPRECATED_DO_NOT_USE_ImageProxyURL *string `json:"ImageProxyURL" mapstructure:"ImageProxyURL"` // This field is deprecated and must not be used. 288 DEPRECATED_DO_NOT_USE_ImageProxyOptions *string `json:"ImageProxyOptions" mapstructure:"ImageProxyOptions"` // This field is deprecated and must not be used. 289 EnableAPITeamDeletion *bool 290 ExperimentalEnableHardenedMode *bool 291 DisableLegacyMFA *bool `restricted:"true"` 292 ExperimentalStrictCSRFEnforcement *bool `restricted:"true"` 293 EnableEmailInvitations *bool 294 ExperimentalLdapGroupSync *bool 295 DisableBotsWhenOwnerIsDeactivated *bool `restricted:"true"` 296 } 297 298 func (s *ServiceSettings) SetDefaults() { 299 if s.EnableEmailInvitations == nil { 300 // If the site URL is also not present then assume this is a clean install 301 if s.SiteURL == nil { 302 s.EnableEmailInvitations = NewBool(false) 303 } else { 304 s.EnableEmailInvitations = NewBool(true) 305 } 306 } 307 308 if s.SiteURL == nil { 309 s.SiteURL = NewString(SERVICE_SETTINGS_DEFAULT_SITE_URL) 310 } 311 312 if s.WebsocketURL == nil { 313 s.WebsocketURL = NewString("") 314 } 315 316 if s.LicenseFileLocation == nil { 317 s.LicenseFileLocation = NewString("") 318 } 319 320 if s.ListenAddress == nil { 321 s.ListenAddress = NewString(SERVICE_SETTINGS_DEFAULT_LISTEN_AND_ADDRESS) 322 } 323 324 if s.EnableLinkPreviews == nil { 325 s.EnableLinkPreviews = NewBool(false) 326 } 327 328 if s.EnableTesting == nil { 329 s.EnableTesting = NewBool(false) 330 } 331 332 if s.EnableDeveloper == nil { 333 s.EnableDeveloper = NewBool(false) 334 } 335 336 if s.EnableSecurityFixAlert == nil { 337 s.EnableSecurityFixAlert = NewBool(true) 338 } 339 340 if s.EnableInsecureOutgoingConnections == nil { 341 s.EnableInsecureOutgoingConnections = NewBool(false) 342 } 343 344 if s.AllowedUntrustedInternalConnections == nil { 345 s.AllowedUntrustedInternalConnections = NewString("") 346 } 347 348 if s.EnableMultifactorAuthentication == nil { 349 s.EnableMultifactorAuthentication = NewBool(false) 350 } 351 352 if s.EnforceMultifactorAuthentication == nil { 353 s.EnforceMultifactorAuthentication = NewBool(false) 354 } 355 356 if s.EnableUserAccessTokens == nil { 357 s.EnableUserAccessTokens = NewBool(false) 358 } 359 360 if s.GoroutineHealthThreshold == nil { 361 s.GoroutineHealthThreshold = NewInt(-1) 362 } 363 364 if s.GoogleDeveloperKey == nil { 365 s.GoogleDeveloperKey = NewString("") 366 } 367 368 if s.EnableOAuthServiceProvider == nil { 369 s.EnableOAuthServiceProvider = NewBool(false) 370 } 371 372 if s.EnableIncomingWebhooks == nil { 373 s.EnableIncomingWebhooks = NewBool(true) 374 } 375 376 if s.EnableIncomingWebhooks == nil { 377 s.EnableIncomingWebhooks = NewBool(true) 378 } 379 380 if s.EnableOutgoingWebhooks == nil { 381 s.EnableOutgoingWebhooks = NewBool(true) 382 } 383 384 if s.ConnectionSecurity == nil { 385 s.ConnectionSecurity = NewString("") 386 } 387 388 if s.TLSKeyFile == nil { 389 s.TLSKeyFile = NewString(SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE) 390 } 391 392 if s.TLSCertFile == nil { 393 s.TLSCertFile = NewString(SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE) 394 } 395 396 if s.TLSMinVer == nil { 397 s.TLSMinVer = NewString("1.2") 398 } 399 400 if s.TLSStrictTransport == nil { 401 s.TLSStrictTransport = NewBool(false) 402 } 403 404 if s.TLSStrictTransportMaxAge == nil { 405 s.TLSStrictTransportMaxAge = NewInt64(63072000) 406 } 407 408 if s.TLSOverwriteCiphers == nil { 409 s.TLSOverwriteCiphers = []string{} 410 } 411 412 if s.UseLetsEncrypt == nil { 413 s.UseLetsEncrypt = NewBool(false) 414 } 415 416 if s.LetsEncryptCertificateCacheFile == nil { 417 s.LetsEncryptCertificateCacheFile = NewString("./config/letsencrypt.cache") 418 } 419 420 if s.ReadTimeout == nil { 421 s.ReadTimeout = NewInt(SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT) 422 } 423 424 if s.WriteTimeout == nil { 425 s.WriteTimeout = NewInt(SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT) 426 } 427 428 if s.MaximumLoginAttempts == nil { 429 s.MaximumLoginAttempts = NewInt(SERVICE_SETTINGS_DEFAULT_MAX_LOGIN_ATTEMPTS) 430 } 431 432 if s.Forward80To443 == nil { 433 s.Forward80To443 = NewBool(false) 434 } 435 436 if s.TimeBetweenUserTypingUpdatesMilliseconds == nil { 437 s.TimeBetweenUserTypingUpdatesMilliseconds = NewInt64(5000) 438 } 439 440 if s.EnablePostSearch == nil { 441 s.EnablePostSearch = NewBool(true) 442 } 443 444 if s.MinimumHashtagLength == nil { 445 s.MinimumHashtagLength = NewInt(3) 446 } 447 448 if s.EnableUserTypingMessages == nil { 449 s.EnableUserTypingMessages = NewBool(true) 450 } 451 452 if s.EnableChannelViewedMessages == nil { 453 s.EnableChannelViewedMessages = NewBool(true) 454 } 455 456 if s.EnableUserStatuses == nil { 457 s.EnableUserStatuses = NewBool(true) 458 } 459 460 if s.ClusterLogTimeoutMilliseconds == nil { 461 s.ClusterLogTimeoutMilliseconds = NewInt(2000) 462 } 463 464 if s.CloseUnusedDirectMessages == nil { 465 s.CloseUnusedDirectMessages = NewBool(false) 466 } 467 468 if s.EnableTutorial == nil { 469 s.EnableTutorial = NewBool(true) 470 } 471 472 if s.SessionLengthWebInDays == nil { 473 s.SessionLengthWebInDays = NewInt(180) 474 } 475 476 if s.SessionLengthMobileInDays == nil { 477 s.SessionLengthMobileInDays = NewInt(180) 478 } 479 480 if s.SessionLengthSSOInDays == nil { 481 s.SessionLengthSSOInDays = NewInt(30) 482 } 483 484 if s.SessionCacheInMinutes == nil { 485 s.SessionCacheInMinutes = NewInt(10) 486 } 487 488 if s.SessionIdleTimeoutInMinutes == nil { 489 s.SessionIdleTimeoutInMinutes = NewInt(43200) 490 } 491 492 if s.EnableCommands == nil { 493 s.EnableCommands = NewBool(true) 494 } 495 496 if s.DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations == nil { 497 s.DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations = NewBool(true) 498 } 499 500 if s.EnablePostUsernameOverride == nil { 501 s.EnablePostUsernameOverride = NewBool(false) 502 } 503 504 if s.EnablePostIconOverride == nil { 505 s.EnablePostIconOverride = NewBool(false) 506 } 507 508 if s.WebsocketPort == nil { 509 s.WebsocketPort = NewInt(80) 510 } 511 512 if s.WebsocketSecurePort == nil { 513 s.WebsocketSecurePort = NewInt(443) 514 } 515 516 if s.AllowCorsFrom == nil { 517 s.AllowCorsFrom = NewString(SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM) 518 } 519 520 if s.CorsExposedHeaders == nil { 521 s.CorsExposedHeaders = NewString("") 522 } 523 524 if s.CorsAllowCredentials == nil { 525 s.CorsAllowCredentials = NewBool(false) 526 } 527 528 if s.CorsDebug == nil { 529 s.CorsDebug = NewBool(false) 530 } 531 532 if s.AllowCookiesForSubdomains == nil { 533 s.AllowCookiesForSubdomains = NewBool(false) 534 } 535 536 if s.WebserverMode == nil { 537 s.WebserverMode = NewString("gzip") 538 } else if *s.WebserverMode == "regular" { 539 *s.WebserverMode = "gzip" 540 } 541 542 if s.EnableCustomEmoji == nil { 543 s.EnableCustomEmoji = NewBool(false) 544 } 545 546 if s.EnableEmojiPicker == nil { 547 s.EnableEmojiPicker = NewBool(true) 548 } 549 550 if s.EnableGifPicker == nil { 551 s.EnableGifPicker = NewBool(false) 552 } 553 554 if s.GfycatApiKey == nil || *s.GfycatApiKey == "" { 555 s.GfycatApiKey = NewString(SERVICE_SETTINGS_DEFAULT_GFYCAT_API_KEY) 556 } 557 558 if s.GfycatApiSecret == nil || *s.GfycatApiSecret == "" { 559 s.GfycatApiSecret = NewString(SERVICE_SETTINGS_DEFAULT_GFYCAT_API_SECRET) 560 } 561 562 if s.DEPRECATED_DO_NOT_USE_RestrictCustomEmojiCreation == nil { 563 s.DEPRECATED_DO_NOT_USE_RestrictCustomEmojiCreation = NewString(RESTRICT_EMOJI_CREATION_ALL) 564 } 565 566 if s.DEPRECATED_DO_NOT_USE_RestrictPostDelete == nil { 567 s.DEPRECATED_DO_NOT_USE_RestrictPostDelete = NewString(PERMISSIONS_DELETE_POST_ALL) 568 } 569 570 if s.DEPRECATED_DO_NOT_USE_AllowEditPost == nil { 571 s.DEPRECATED_DO_NOT_USE_AllowEditPost = NewString(ALLOW_EDIT_POST_ALWAYS) 572 } 573 574 if s.ExperimentalEnableAuthenticationTransfer == nil { 575 s.ExperimentalEnableAuthenticationTransfer = NewBool(true) 576 } 577 578 if s.PostEditTimeLimit == nil { 579 s.PostEditTimeLimit = NewInt(-1) 580 } 581 582 if s.EnablePreviewFeatures == nil { 583 s.EnablePreviewFeatures = NewBool(true) 584 } 585 586 if s.ExperimentalEnableDefaultChannelLeaveJoinMessages == nil { 587 s.ExperimentalEnableDefaultChannelLeaveJoinMessages = NewBool(true) 588 } 589 590 if s.ExperimentalGroupUnreadChannels == nil { 591 s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DISABLED) 592 } else if *s.ExperimentalGroupUnreadChannels == "0" { 593 s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DISABLED) 594 } else if *s.ExperimentalGroupUnreadChannels == "1" { 595 s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DEFAULT_ON) 596 } 597 598 if s.ExperimentalChannelOrganization == nil { 599 experimentalUnreadEnabled := *s.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED 600 s.ExperimentalChannelOrganization = NewBool(experimentalUnreadEnabled) 601 } 602 603 if s.DEPRECATED_DO_NOT_USE_ImageProxyType == nil { 604 s.DEPRECATED_DO_NOT_USE_ImageProxyType = NewString("") 605 } 606 607 if s.DEPRECATED_DO_NOT_USE_ImageProxyURL == nil { 608 s.DEPRECATED_DO_NOT_USE_ImageProxyURL = NewString("") 609 } 610 611 if s.DEPRECATED_DO_NOT_USE_ImageProxyOptions == nil { 612 s.DEPRECATED_DO_NOT_USE_ImageProxyOptions = NewString("") 613 } 614 615 if s.EnableAPITeamDeletion == nil { 616 s.EnableAPITeamDeletion = NewBool(false) 617 } 618 619 if s.ExperimentalEnableHardenedMode == nil { 620 s.ExperimentalEnableHardenedMode = NewBool(false) 621 } 622 623 if s.DisableLegacyMFA == nil { 624 s.DisableLegacyMFA = NewBool(false) 625 } 626 627 if s.ExperimentalLdapGroupSync == nil { 628 s.ExperimentalLdapGroupSync = NewBool(false) 629 } 630 631 if s.ExperimentalStrictCSRFEnforcement == nil { 632 s.ExperimentalStrictCSRFEnforcement = NewBool(false) 633 } 634 635 if s.DisableBotsWhenOwnerIsDeactivated == nil { 636 s.DisableBotsWhenOwnerIsDeactivated = NewBool(true) 637 } 638 } 639 640 type ClusterSettings struct { 641 Enable *bool `restricted:"true"` 642 ClusterName *string `restricted:"true"` 643 OverrideHostname *string `restricted:"true"` 644 UseIpAddress *bool `restricted:"true"` 645 UseExperimentalGossip *bool `restricted:"true"` 646 ReadOnlyConfig *bool `restricted:"true"` 647 GossipPort *int `restricted:"true"` 648 StreamingPort *int `restricted:"true"` 649 MaxIdleConns *int `restricted:"true"` 650 MaxIdleConnsPerHost *int `restricted:"true"` 651 IdleConnTimeoutMilliseconds *int `restricted:"true"` 652 } 653 654 func (s *ClusterSettings) SetDefaults() { 655 if s.Enable == nil { 656 s.Enable = NewBool(false) 657 } 658 659 if s.ClusterName == nil { 660 s.ClusterName = NewString("") 661 } 662 663 if s.OverrideHostname == nil { 664 s.OverrideHostname = NewString("") 665 } 666 667 if s.UseIpAddress == nil { 668 s.UseIpAddress = NewBool(true) 669 } 670 671 if s.UseExperimentalGossip == nil { 672 s.UseExperimentalGossip = NewBool(false) 673 } 674 675 if s.ReadOnlyConfig == nil { 676 s.ReadOnlyConfig = NewBool(true) 677 } 678 679 if s.GossipPort == nil { 680 s.GossipPort = NewInt(8074) 681 } 682 683 if s.StreamingPort == nil { 684 s.StreamingPort = NewInt(8075) 685 } 686 687 if s.MaxIdleConns == nil { 688 s.MaxIdleConns = NewInt(100) 689 } 690 691 if s.MaxIdleConnsPerHost == nil { 692 s.MaxIdleConnsPerHost = NewInt(128) 693 } 694 695 if s.IdleConnTimeoutMilliseconds == nil { 696 s.IdleConnTimeoutMilliseconds = NewInt(90000) 697 } 698 } 699 700 type MetricsSettings struct { 701 Enable *bool `restricted:"true"` 702 BlockProfileRate *int `restricted:"true"` 703 ListenAddress *string `restricted:"true"` 704 } 705 706 func (s *MetricsSettings) SetDefaults() { 707 if s.ListenAddress == nil { 708 s.ListenAddress = NewString(":8067") 709 } 710 711 if s.Enable == nil { 712 s.Enable = NewBool(false) 713 } 714 715 if s.BlockProfileRate == nil { 716 s.BlockProfileRate = NewInt(0) 717 } 718 } 719 720 type ExperimentalSettings struct { 721 ClientSideCertEnable *bool 722 ClientSideCertCheck *string 723 DisablePostMetadata *bool `restricted:"true"` 724 EnableClickToReply *bool `restricted:"true"` 725 LinkMetadataTimeoutMilliseconds *int64 `restricted:"true"` 726 RestrictSystemAdmin *bool `restricted:"true"` 727 } 728 729 func (s *ExperimentalSettings) SetDefaults() { 730 if s.ClientSideCertEnable == nil { 731 s.ClientSideCertEnable = NewBool(false) 732 } 733 734 if s.ClientSideCertCheck == nil { 735 s.ClientSideCertCheck = NewString(CLIENT_SIDE_CERT_CHECK_SECONDARY_AUTH) 736 } 737 738 if s.DisablePostMetadata == nil { 739 s.DisablePostMetadata = NewBool(false) 740 } 741 742 if s.EnableClickToReply == nil { 743 s.EnableClickToReply = NewBool(false) 744 } 745 746 if s.LinkMetadataTimeoutMilliseconds == nil { 747 s.LinkMetadataTimeoutMilliseconds = NewInt64(EXPERIMENTAL_SETTINGS_DEFAULT_LINK_METADATA_TIMEOUT_MILLISECONDS) 748 } 749 750 if s.RestrictSystemAdmin == nil { 751 s.RestrictSystemAdmin = NewBool(false) 752 } 753 } 754 755 type AnalyticsSettings struct { 756 MaxUsersForStatistics *int `restricted:"true"` 757 } 758 759 func (s *AnalyticsSettings) SetDefaults() { 760 if s.MaxUsersForStatistics == nil { 761 s.MaxUsersForStatistics = NewInt(ANALYTICS_SETTINGS_DEFAULT_MAX_USERS_FOR_STATISTICS) 762 } 763 } 764 765 type SSOSettings struct { 766 Enable *bool 767 Secret *string 768 Id *string 769 Scope *string 770 AuthEndpoint *string 771 TokenEndpoint *string 772 UserApiEndpoint *string 773 } 774 775 func (s *SSOSettings) setDefaults() { 776 if s.Enable == nil { 777 s.Enable = NewBool(false) 778 } 779 780 if s.Secret == nil { 781 s.Secret = NewString("") 782 } 783 784 if s.Id == nil { 785 s.Id = NewString("") 786 } 787 788 if s.Scope == nil { 789 s.Scope = NewString("") 790 } 791 792 if s.AuthEndpoint == nil { 793 s.AuthEndpoint = NewString("") 794 } 795 796 if s.TokenEndpoint == nil { 797 s.TokenEndpoint = NewString("") 798 } 799 800 if s.UserApiEndpoint == nil { 801 s.UserApiEndpoint = NewString("") 802 } 803 } 804 805 type SqlSettings struct { 806 DriverName *string `restricted:"true"` 807 DataSource *string `restricted:"true"` 808 DataSourceReplicas []string `restricted:"true"` 809 DataSourceSearchReplicas []string `restricted:"true"` 810 MaxIdleConns *int `restricted:"true"` 811 ConnMaxLifetimeMilliseconds *int `restricted:"true"` 812 MaxOpenConns *int `restricted:"true"` 813 Trace *bool `restricted:"true"` 814 AtRestEncryptKey *string `restricted:"true"` 815 QueryTimeout *int `restricted:"true"` 816 } 817 818 func (s *SqlSettings) SetDefaults() { 819 if s.DriverName == nil { 820 s.DriverName = NewString(DATABASE_DRIVER_MYSQL) 821 } 822 823 if s.DataSource == nil { 824 s.DataSource = NewString(SQL_SETTINGS_DEFAULT_DATA_SOURCE) 825 } 826 827 if s.DataSourceReplicas == nil { 828 s.DataSourceReplicas = []string{} 829 } 830 831 if s.DataSourceSearchReplicas == nil { 832 s.DataSourceSearchReplicas = []string{} 833 } 834 835 if s.AtRestEncryptKey == nil || len(*s.AtRestEncryptKey) == 0 { 836 s.AtRestEncryptKey = NewString(NewRandomString(32)) 837 } 838 839 if s.MaxIdleConns == nil { 840 s.MaxIdleConns = NewInt(20) 841 } 842 843 if s.MaxOpenConns == nil { 844 s.MaxOpenConns = NewInt(300) 845 } 846 847 if s.ConnMaxLifetimeMilliseconds == nil { 848 s.ConnMaxLifetimeMilliseconds = NewInt(3600000) 849 } 850 851 if s.Trace == nil { 852 s.Trace = NewBool(false) 853 } 854 855 if s.QueryTimeout == nil { 856 s.QueryTimeout = NewInt(30) 857 } 858 } 859 860 type LogSettings struct { 861 EnableConsole *bool `restricted:"true"` 862 ConsoleLevel *string `restricted:"true"` 863 ConsoleJson *bool `restricted:"true"` 864 EnableFile *bool `restricted:"true"` 865 FileLevel *string `restricted:"true"` 866 FileJson *bool `restricted:"true"` 867 FileLocation *string `restricted:"true"` 868 EnableWebhookDebugging *bool `restricted:"true"` 869 EnableDiagnostics *bool `restricted:"true"` 870 } 871 872 func (s *LogSettings) SetDefaults() { 873 if s.EnableConsole == nil { 874 s.EnableConsole = NewBool(true) 875 } 876 877 if s.ConsoleLevel == nil { 878 s.ConsoleLevel = NewString("DEBUG") 879 } 880 881 if s.EnableFile == nil { 882 s.EnableFile = NewBool(true) 883 } 884 885 if s.FileLevel == nil { 886 s.FileLevel = NewString("INFO") 887 } 888 889 if s.FileLocation == nil { 890 s.FileLocation = NewString("") 891 } 892 893 if s.EnableWebhookDebugging == nil { 894 s.EnableWebhookDebugging = NewBool(true) 895 } 896 897 if s.EnableDiagnostics == nil { 898 s.EnableDiagnostics = NewBool(true) 899 } 900 901 if s.ConsoleJson == nil { 902 s.ConsoleJson = NewBool(true) 903 } 904 905 if s.FileJson == nil { 906 s.FileJson = NewBool(true) 907 } 908 } 909 910 type PasswordSettings struct { 911 MinimumLength *int 912 Lowercase *bool 913 Number *bool 914 Uppercase *bool 915 Symbol *bool 916 } 917 918 func (s *PasswordSettings) SetDefaults() { 919 if s.MinimumLength == nil { 920 s.MinimumLength = NewInt(PASSWORD_MINIMUM_LENGTH) 921 } 922 923 if s.Lowercase == nil { 924 s.Lowercase = NewBool(false) 925 } 926 927 if s.Number == nil { 928 s.Number = NewBool(false) 929 } 930 931 if s.Uppercase == nil { 932 s.Uppercase = NewBool(false) 933 } 934 935 if s.Symbol == nil { 936 s.Symbol = NewBool(false) 937 } 938 } 939 940 type FileSettings struct { 941 EnableFileAttachments *bool 942 EnableMobileUpload *bool 943 EnableMobileDownload *bool 944 MaxFileSize *int64 945 DriverName *string `restricted:"true"` 946 Directory *string `restricted:"true"` 947 EnablePublicLink *bool 948 PublicLinkSalt *string 949 InitialFont *string 950 AmazonS3AccessKeyId *string `restricted:"true"` 951 AmazonS3SecretAccessKey *string `restricted:"true"` 952 AmazonS3Bucket *string `restricted:"true"` 953 AmazonS3Region *string `restricted:"true"` 954 AmazonS3Endpoint *string `restricted:"true"` 955 AmazonS3SSL *bool `restricted:"true"` 956 AmazonS3SignV2 *bool `restricted:"true"` 957 AmazonS3SSE *bool `restricted:"true"` 958 AmazonS3Trace *bool `restricted:"true"` 959 } 960 961 func (s *FileSettings) SetDefaults() { 962 if s.EnableFileAttachments == nil { 963 s.EnableFileAttachments = NewBool(true) 964 } 965 966 if s.EnableMobileUpload == nil { 967 s.EnableMobileUpload = NewBool(true) 968 } 969 970 if s.EnableMobileDownload == nil { 971 s.EnableMobileDownload = NewBool(true) 972 } 973 974 if s.MaxFileSize == nil { 975 s.MaxFileSize = NewInt64(52428800) // 50 MB 976 } 977 978 if s.DriverName == nil { 979 s.DriverName = NewString(IMAGE_DRIVER_LOCAL) 980 } 981 982 if s.Directory == nil { 983 s.Directory = NewString(FILE_SETTINGS_DEFAULT_DIRECTORY) 984 } 985 986 if s.EnablePublicLink == nil { 987 s.EnablePublicLink = NewBool(false) 988 } 989 990 if s.PublicLinkSalt == nil || len(*s.PublicLinkSalt) == 0 { 991 s.PublicLinkSalt = NewString(NewRandomString(32)) 992 } 993 994 if s.InitialFont == nil { 995 // Defaults to "nunito-bold.ttf" 996 s.InitialFont = NewString("nunito-bold.ttf") 997 } 998 999 if s.AmazonS3AccessKeyId == nil { 1000 s.AmazonS3AccessKeyId = NewString("") 1001 } 1002 1003 if s.AmazonS3SecretAccessKey == nil { 1004 s.AmazonS3SecretAccessKey = NewString("") 1005 } 1006 1007 if s.AmazonS3Bucket == nil { 1008 s.AmazonS3Bucket = NewString("") 1009 } 1010 1011 if s.AmazonS3Region == nil { 1012 s.AmazonS3Region = NewString("") 1013 } 1014 1015 if s.AmazonS3Endpoint == nil || len(*s.AmazonS3Endpoint) == 0 { 1016 // Defaults to "s3.amazonaws.com" 1017 s.AmazonS3Endpoint = NewString("s3.amazonaws.com") 1018 } 1019 1020 if s.AmazonS3SSL == nil { 1021 s.AmazonS3SSL = NewBool(true) // Secure by default. 1022 } 1023 1024 if s.AmazonS3SignV2 == nil { 1025 s.AmazonS3SignV2 = new(bool) 1026 // Signature v2 is not enabled by default. 1027 } 1028 1029 if s.AmazonS3SSE == nil { 1030 s.AmazonS3SSE = NewBool(false) // Not Encrypted by default. 1031 } 1032 1033 if s.AmazonS3Trace == nil { 1034 s.AmazonS3Trace = NewBool(false) 1035 } 1036 } 1037 1038 type EmailSettings struct { 1039 EnableSignUpWithEmail *bool 1040 EnableSignInWithEmail *bool 1041 EnableSignInWithUsername *bool 1042 SendEmailNotifications *bool 1043 UseChannelInEmailNotifications *bool 1044 RequireEmailVerification *bool 1045 FeedbackName *string 1046 FeedbackEmail *string 1047 ReplyToAddress *string 1048 FeedbackOrganization *string 1049 EnableSMTPAuth *bool `restricted:"true"` 1050 SMTPUsername *string `restricted:"true"` 1051 SMTPPassword *string `restricted:"true"` 1052 SMTPServer *string `restricted:"true"` 1053 SMTPPort *string `restricted:"true"` 1054 ConnectionSecurity *string `restricted:"true"` 1055 SendPushNotifications *bool 1056 PushNotificationServer *string 1057 PushNotificationContents *string 1058 EnableEmailBatching *bool 1059 EmailBatchingBufferSize *int 1060 EmailBatchingInterval *int 1061 EnablePreviewModeBanner *bool 1062 SkipServerCertificateVerification *bool `restricted:"true"` 1063 EmailNotificationContentsType *string 1064 LoginButtonColor *string 1065 LoginButtonBorderColor *string 1066 LoginButtonTextColor *string 1067 } 1068 1069 func (s *EmailSettings) SetDefaults() { 1070 if s.EnableSignUpWithEmail == nil { 1071 s.EnableSignUpWithEmail = NewBool(true) 1072 } 1073 1074 if s.EnableSignInWithEmail == nil { 1075 s.EnableSignInWithEmail = NewBool(*s.EnableSignUpWithEmail) 1076 } 1077 1078 if s.EnableSignInWithUsername == nil { 1079 s.EnableSignInWithUsername = NewBool(true) 1080 } 1081 1082 if s.SendEmailNotifications == nil { 1083 s.SendEmailNotifications = NewBool(true) 1084 } 1085 1086 if s.UseChannelInEmailNotifications == nil { 1087 s.UseChannelInEmailNotifications = NewBool(false) 1088 } 1089 1090 if s.RequireEmailVerification == nil { 1091 s.RequireEmailVerification = NewBool(false) 1092 } 1093 1094 if s.FeedbackName == nil { 1095 s.FeedbackName = NewString("") 1096 } 1097 1098 if s.FeedbackEmail == nil { 1099 s.FeedbackEmail = NewString("test@example.com") 1100 } 1101 1102 if s.ReplyToAddress == nil { 1103 s.ReplyToAddress = NewString("test@example.com") 1104 } 1105 1106 if s.FeedbackOrganization == nil { 1107 s.FeedbackOrganization = NewString(EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION) 1108 } 1109 1110 if s.EnableSMTPAuth == nil { 1111 if s.ConnectionSecurity == nil || *s.ConnectionSecurity == CONN_SECURITY_NONE { 1112 s.EnableSMTPAuth = NewBool(false) 1113 } else { 1114 s.EnableSMTPAuth = NewBool(true) 1115 } 1116 } 1117 1118 if s.SMTPUsername == nil { 1119 s.SMTPUsername = NewString("") 1120 } 1121 1122 if s.SMTPPassword == nil { 1123 s.SMTPPassword = NewString("") 1124 } 1125 1126 if s.SMTPServer == nil || len(*s.SMTPServer) == 0 { 1127 s.SMTPServer = NewString("dockerhost") 1128 } 1129 1130 if s.SMTPPort == nil || len(*s.SMTPPort) == 0 { 1131 s.SMTPPort = NewString("2500") 1132 } 1133 1134 if s.ConnectionSecurity == nil || *s.ConnectionSecurity == CONN_SECURITY_PLAIN { 1135 s.ConnectionSecurity = NewString(CONN_SECURITY_NONE) 1136 } 1137 1138 if s.SendPushNotifications == nil { 1139 s.SendPushNotifications = NewBool(false) 1140 } 1141 1142 if s.PushNotificationServer == nil { 1143 s.PushNotificationServer = NewString("") 1144 } 1145 1146 if s.PushNotificationContents == nil { 1147 s.PushNotificationContents = NewString(GENERIC_NOTIFICATION) 1148 } 1149 1150 if s.EnableEmailBatching == nil { 1151 s.EnableEmailBatching = NewBool(false) 1152 } 1153 1154 if s.EmailBatchingBufferSize == nil { 1155 s.EmailBatchingBufferSize = NewInt(EMAIL_BATCHING_BUFFER_SIZE) 1156 } 1157 1158 if s.EmailBatchingInterval == nil { 1159 s.EmailBatchingInterval = NewInt(EMAIL_BATCHING_INTERVAL) 1160 } 1161 1162 if s.EnablePreviewModeBanner == nil { 1163 s.EnablePreviewModeBanner = NewBool(true) 1164 } 1165 1166 if s.EnableSMTPAuth == nil { 1167 if *s.ConnectionSecurity == CONN_SECURITY_NONE { 1168 s.EnableSMTPAuth = NewBool(false) 1169 } else { 1170 s.EnableSMTPAuth = NewBool(true) 1171 } 1172 } 1173 1174 if *s.ConnectionSecurity == CONN_SECURITY_PLAIN { 1175 *s.ConnectionSecurity = CONN_SECURITY_NONE 1176 } 1177 1178 if s.SkipServerCertificateVerification == nil { 1179 s.SkipServerCertificateVerification = NewBool(false) 1180 } 1181 1182 if s.EmailNotificationContentsType == nil { 1183 s.EmailNotificationContentsType = NewString(EMAIL_NOTIFICATION_CONTENTS_FULL) 1184 } 1185 1186 if s.LoginButtonColor == nil { 1187 s.LoginButtonColor = NewString("#0000") 1188 } 1189 1190 if s.LoginButtonBorderColor == nil { 1191 s.LoginButtonBorderColor = NewString("#2389D7") 1192 } 1193 1194 if s.LoginButtonTextColor == nil { 1195 s.LoginButtonTextColor = NewString("#2389D7") 1196 } 1197 } 1198 1199 type RateLimitSettings struct { 1200 Enable *bool `restricted:"true"` 1201 PerSec *int `restricted:"true"` 1202 MaxBurst *int `restricted:"true"` 1203 MemoryStoreSize *int `restricted:"true"` 1204 VaryByRemoteAddr *bool `restricted:"true"` 1205 VaryByUser *bool `restricted:"true"` 1206 VaryByHeader string `restricted:"true"` 1207 } 1208 1209 func (s *RateLimitSettings) SetDefaults() { 1210 if s.Enable == nil { 1211 s.Enable = NewBool(false) 1212 } 1213 1214 if s.PerSec == nil { 1215 s.PerSec = NewInt(10) 1216 } 1217 1218 if s.MaxBurst == nil { 1219 s.MaxBurst = NewInt(100) 1220 } 1221 1222 if s.MemoryStoreSize == nil { 1223 s.MemoryStoreSize = NewInt(10000) 1224 } 1225 1226 if s.VaryByRemoteAddr == nil { 1227 s.VaryByRemoteAddr = NewBool(true) 1228 } 1229 1230 if s.VaryByUser == nil { 1231 s.VaryByUser = NewBool(false) 1232 } 1233 } 1234 1235 type PrivacySettings struct { 1236 ShowEmailAddress *bool 1237 ShowFullName *bool 1238 } 1239 1240 func (s *PrivacySettings) setDefaults() { 1241 if s.ShowEmailAddress == nil { 1242 s.ShowEmailAddress = NewBool(true) 1243 } 1244 1245 if s.ShowFullName == nil { 1246 s.ShowFullName = NewBool(true) 1247 } 1248 } 1249 1250 type SupportSettings struct { 1251 TermsOfServiceLink *string `restricted:"true"` 1252 PrivacyPolicyLink *string `restricted:"true"` 1253 AboutLink *string `restricted:"true"` 1254 HelpLink *string `restricted:"true"` 1255 ReportAProblemLink *string `restricted:"true"` 1256 SupportEmail *string 1257 CustomTermsOfServiceEnabled *bool 1258 CustomTermsOfServiceReAcceptancePeriod *int 1259 } 1260 1261 func (s *SupportSettings) SetDefaults() { 1262 if !IsSafeLink(s.TermsOfServiceLink) { 1263 *s.TermsOfServiceLink = SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK 1264 } 1265 1266 if s.TermsOfServiceLink == nil { 1267 s.TermsOfServiceLink = NewString(SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK) 1268 } 1269 1270 if !IsSafeLink(s.PrivacyPolicyLink) { 1271 *s.PrivacyPolicyLink = "" 1272 } 1273 1274 if s.PrivacyPolicyLink == nil { 1275 s.PrivacyPolicyLink = NewString(SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK) 1276 } 1277 1278 if !IsSafeLink(s.AboutLink) { 1279 *s.AboutLink = "" 1280 } 1281 1282 if s.AboutLink == nil { 1283 s.AboutLink = NewString(SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK) 1284 } 1285 1286 if !IsSafeLink(s.HelpLink) { 1287 *s.HelpLink = "" 1288 } 1289 1290 if s.HelpLink == nil { 1291 s.HelpLink = NewString(SUPPORT_SETTINGS_DEFAULT_HELP_LINK) 1292 } 1293 1294 if !IsSafeLink(s.ReportAProblemLink) { 1295 *s.ReportAProblemLink = "" 1296 } 1297 1298 if s.ReportAProblemLink == nil { 1299 s.ReportAProblemLink = NewString(SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK) 1300 } 1301 1302 if s.SupportEmail == nil { 1303 s.SupportEmail = NewString(SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL) 1304 } 1305 1306 if s.CustomTermsOfServiceEnabled == nil { 1307 s.CustomTermsOfServiceEnabled = NewBool(false) 1308 } 1309 1310 if s.CustomTermsOfServiceReAcceptancePeriod == nil { 1311 s.CustomTermsOfServiceReAcceptancePeriod = NewInt(SUPPORT_SETTINGS_DEFAULT_RE_ACCEPTANCE_PERIOD) 1312 } 1313 } 1314 1315 type AnnouncementSettings struct { 1316 EnableBanner *bool 1317 BannerText *string 1318 BannerColor *string 1319 BannerTextColor *string 1320 AllowBannerDismissal *bool 1321 } 1322 1323 func (s *AnnouncementSettings) SetDefaults() { 1324 if s.EnableBanner == nil { 1325 s.EnableBanner = NewBool(false) 1326 } 1327 1328 if s.BannerText == nil { 1329 s.BannerText = NewString("") 1330 } 1331 1332 if s.BannerColor == nil { 1333 s.BannerColor = NewString(ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR) 1334 } 1335 1336 if s.BannerTextColor == nil { 1337 s.BannerTextColor = NewString(ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR) 1338 } 1339 1340 if s.AllowBannerDismissal == nil { 1341 s.AllowBannerDismissal = NewBool(true) 1342 } 1343 } 1344 1345 type ThemeSettings struct { 1346 EnableThemeSelection *bool 1347 DefaultTheme *string 1348 AllowCustomThemes *bool 1349 AllowedThemes []string 1350 } 1351 1352 func (s *ThemeSettings) SetDefaults() { 1353 if s.EnableThemeSelection == nil { 1354 s.EnableThemeSelection = NewBool(true) 1355 } 1356 1357 if s.DefaultTheme == nil { 1358 s.DefaultTheme = NewString(TEAM_SETTINGS_DEFAULT_TEAM_TEXT) 1359 } 1360 1361 if s.AllowCustomThemes == nil { 1362 s.AllowCustomThemes = NewBool(true) 1363 } 1364 1365 if s.AllowedThemes == nil { 1366 s.AllowedThemes = []string{} 1367 } 1368 } 1369 1370 type TeamSettings struct { 1371 SiteName *string 1372 MaxUsersPerTeam *int 1373 DEPRECATED_DO_NOT_USE_EnableTeamCreation *bool `json:"EnableTeamCreation"` // This field is deprecated and must not be used. 1374 EnableUserCreation *bool 1375 EnableOpenServer *bool 1376 EnableUserDeactivation *bool 1377 RestrictCreationToDomains *string 1378 EnableCustomBrand *bool 1379 CustomBrandText *string 1380 CustomDescriptionText *string 1381 RestrictDirectMessage *string 1382 DEPRECATED_DO_NOT_USE_RestrictTeamInvite *string `json:"RestrictTeamInvite"` // This field is deprecated and must not be used. 1383 DEPRECATED_DO_NOT_USE_RestrictPublicChannelManagement *string `json:"RestrictPublicChannelManagement"` // This field is deprecated and must not be used. 1384 DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManagement *string `json:"RestrictPrivateChannelManagement"` // This field is deprecated and must not be used. 1385 DEPRECATED_DO_NOT_USE_RestrictPublicChannelCreation *string `json:"RestrictPublicChannelCreation"` // This field is deprecated and must not be used. 1386 DEPRECATED_DO_NOT_USE_RestrictPrivateChannelCreation *string `json:"RestrictPrivateChannelCreation"` // This field is deprecated and must not be used. 1387 DEPRECATED_DO_NOT_USE_RestrictPublicChannelDeletion *string `json:"RestrictPublicChannelDeletion"` // This field is deprecated and must not be used. 1388 DEPRECATED_DO_NOT_USE_RestrictPrivateChannelDeletion *string `json:"RestrictPrivateChannelDeletion"` // This field is deprecated and must not be used. 1389 DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManageMembers *string `json:"RestrictPrivateChannelManageMembers"` // This field is deprecated and must not be used. 1390 EnableXToLeaveChannelsFromLHS *bool 1391 UserStatusAwayTimeout *int64 1392 MaxChannelsPerTeam *int64 1393 MaxNotificationsPerChannel *int64 1394 EnableConfirmNotificationsToChannel *bool 1395 TeammateNameDisplay *string 1396 ExperimentalViewArchivedChannels *bool 1397 ExperimentalEnableAutomaticReplies *bool 1398 ExperimentalHideTownSquareinLHS *bool 1399 ExperimentalTownSquareIsReadOnly *bool 1400 ExperimentalPrimaryTeam *string 1401 ExperimentalDefaultChannels []string 1402 } 1403 1404 func (s *TeamSettings) SetDefaults() { 1405 1406 if s.SiteName == nil || *s.SiteName == "" { 1407 s.SiteName = NewString(TEAM_SETTINGS_DEFAULT_SITE_NAME) 1408 } 1409 1410 if s.MaxUsersPerTeam == nil { 1411 s.MaxUsersPerTeam = NewInt(TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM) 1412 } 1413 1414 if s.DEPRECATED_DO_NOT_USE_EnableTeamCreation == nil { 1415 s.DEPRECATED_DO_NOT_USE_EnableTeamCreation = NewBool(true) 1416 } 1417 1418 if s.EnableUserCreation == nil { 1419 s.EnableUserCreation = NewBool(true) 1420 } 1421 1422 if s.EnableOpenServer == nil { 1423 s.EnableOpenServer = NewBool(false) 1424 } 1425 1426 if s.RestrictCreationToDomains == nil { 1427 s.RestrictCreationToDomains = NewString("") 1428 } 1429 1430 if s.EnableCustomBrand == nil { 1431 s.EnableCustomBrand = NewBool(false) 1432 } 1433 1434 if s.EnableUserDeactivation == nil { 1435 s.EnableUserDeactivation = NewBool(false) 1436 } 1437 1438 if s.CustomBrandText == nil { 1439 s.CustomBrandText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT) 1440 } 1441 1442 if s.CustomDescriptionText == nil { 1443 s.CustomDescriptionText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT) 1444 } 1445 1446 if s.RestrictDirectMessage == nil { 1447 s.RestrictDirectMessage = NewString(DIRECT_MESSAGE_ANY) 1448 } 1449 1450 if s.DEPRECATED_DO_NOT_USE_RestrictTeamInvite == nil { 1451 s.DEPRECATED_DO_NOT_USE_RestrictTeamInvite = NewString(PERMISSIONS_ALL) 1452 } 1453 1454 if s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelManagement == nil { 1455 s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelManagement = NewString(PERMISSIONS_ALL) 1456 } 1457 1458 if s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManagement == nil { 1459 s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManagement = NewString(PERMISSIONS_ALL) 1460 } 1461 1462 if s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelCreation == nil { 1463 s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelCreation = new(string) 1464 // If this setting does not exist, assume migration from <3.6, so use management setting as default. 1465 if *s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelManagement == PERMISSIONS_CHANNEL_ADMIN { 1466 *s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelCreation = PERMISSIONS_TEAM_ADMIN 1467 } else { 1468 *s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelCreation = *s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelManagement 1469 } 1470 } 1471 1472 if s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelCreation == nil { 1473 // If this setting does not exist, assume migration from <3.6, so use management setting as default. 1474 if *s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManagement == PERMISSIONS_CHANNEL_ADMIN { 1475 s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelCreation = NewString(PERMISSIONS_TEAM_ADMIN) 1476 } else { 1477 s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelCreation = NewString(*s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManagement) 1478 } 1479 } 1480 1481 if s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelDeletion == nil { 1482 // If this setting does not exist, assume migration from <3.6, so use management setting as default. 1483 s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelDeletion = NewString(*s.DEPRECATED_DO_NOT_USE_RestrictPublicChannelManagement) 1484 } 1485 1486 if s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelDeletion == nil { 1487 // If this setting does not exist, assume migration from <3.6, so use management setting as default. 1488 s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelDeletion = NewString(*s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManagement) 1489 } 1490 1491 if s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManageMembers == nil { 1492 s.DEPRECATED_DO_NOT_USE_RestrictPrivateChannelManageMembers = NewString(PERMISSIONS_ALL) 1493 } 1494 1495 if s.EnableXToLeaveChannelsFromLHS == nil { 1496 s.EnableXToLeaveChannelsFromLHS = NewBool(false) 1497 } 1498 1499 if s.UserStatusAwayTimeout == nil { 1500 s.UserStatusAwayTimeout = NewInt64(TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT) 1501 } 1502 1503 if s.MaxChannelsPerTeam == nil { 1504 s.MaxChannelsPerTeam = NewInt64(2000) 1505 } 1506 1507 if s.MaxNotificationsPerChannel == nil { 1508 s.MaxNotificationsPerChannel = NewInt64(1000) 1509 } 1510 1511 if s.EnableConfirmNotificationsToChannel == nil { 1512 s.EnableConfirmNotificationsToChannel = NewBool(true) 1513 } 1514 1515 if s.ExperimentalEnableAutomaticReplies == nil { 1516 s.ExperimentalEnableAutomaticReplies = NewBool(false) 1517 } 1518 1519 if s.ExperimentalHideTownSquareinLHS == nil { 1520 s.ExperimentalHideTownSquareinLHS = NewBool(false) 1521 } 1522 1523 if s.ExperimentalTownSquareIsReadOnly == nil { 1524 s.ExperimentalTownSquareIsReadOnly = NewBool(false) 1525 } 1526 1527 if s.ExperimentalPrimaryTeam == nil { 1528 s.ExperimentalPrimaryTeam = NewString("") 1529 } 1530 1531 if s.ExperimentalDefaultChannels == nil { 1532 s.ExperimentalDefaultChannels = []string{} 1533 } 1534 1535 if s.DEPRECATED_DO_NOT_USE_EnableTeamCreation == nil { 1536 s.DEPRECATED_DO_NOT_USE_EnableTeamCreation = NewBool(true) 1537 } 1538 1539 if s.EnableUserCreation == nil { 1540 s.EnableUserCreation = NewBool(true) 1541 } 1542 1543 if s.ExperimentalViewArchivedChannels == nil { 1544 s.ExperimentalViewArchivedChannels = NewBool(false) 1545 } 1546 } 1547 1548 type ClientRequirements struct { 1549 AndroidLatestVersion string `restricted:"true"` 1550 AndroidMinVersion string `restricted:"true"` 1551 DesktopLatestVersion string `restricted:"true"` 1552 DesktopMinVersion string `restricted:"true"` 1553 IosLatestVersion string `restricted:"true"` 1554 IosMinVersion string `restricted:"true"` 1555 } 1556 1557 type LdapSettings struct { 1558 // Basic 1559 Enable *bool 1560 EnableSync *bool 1561 LdapServer *string 1562 LdapPort *int 1563 ConnectionSecurity *string 1564 BaseDN *string 1565 BindUsername *string 1566 BindPassword *string 1567 1568 // Filtering 1569 UserFilter *string 1570 GroupFilter *string 1571 1572 // Group Mapping 1573 GroupDisplayNameAttribute *string 1574 GroupIdAttribute *string 1575 1576 // User Mapping 1577 FirstNameAttribute *string 1578 LastNameAttribute *string 1579 EmailAttribute *string 1580 UsernameAttribute *string 1581 NicknameAttribute *string 1582 IdAttribute *string 1583 PositionAttribute *string 1584 LoginIdAttribute *string 1585 1586 // Synchronization 1587 SyncIntervalMinutes *int 1588 1589 // Advanced 1590 SkipCertificateVerification *bool 1591 QueryTimeout *int 1592 MaxPageSize *int 1593 1594 // Customization 1595 LoginFieldName *string 1596 1597 LoginButtonColor *string 1598 LoginButtonBorderColor *string 1599 LoginButtonTextColor *string 1600 } 1601 1602 func (s *LdapSettings) SetDefaults() { 1603 if s.Enable == nil { 1604 s.Enable = NewBool(false) 1605 } 1606 1607 // When unset should default to LDAP Enabled 1608 if s.EnableSync == nil { 1609 s.EnableSync = NewBool(*s.Enable) 1610 } 1611 1612 if s.LdapServer == nil { 1613 s.LdapServer = NewString("") 1614 } 1615 1616 if s.LdapPort == nil { 1617 s.LdapPort = NewInt(389) 1618 } 1619 1620 if s.ConnectionSecurity == nil { 1621 s.ConnectionSecurity = NewString("") 1622 } 1623 1624 if s.BaseDN == nil { 1625 s.BaseDN = NewString("") 1626 } 1627 1628 if s.BindUsername == nil { 1629 s.BindUsername = NewString("") 1630 } 1631 1632 if s.BindPassword == nil { 1633 s.BindPassword = NewString("") 1634 } 1635 1636 if s.UserFilter == nil { 1637 s.UserFilter = NewString("") 1638 } 1639 1640 if s.GroupFilter == nil { 1641 s.GroupFilter = NewString("") 1642 } 1643 1644 if s.GroupDisplayNameAttribute == nil { 1645 s.GroupDisplayNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_GROUP_DISPLAY_NAME_ATTRIBUTE) 1646 } 1647 1648 if s.GroupIdAttribute == nil { 1649 s.GroupIdAttribute = NewString(LDAP_SETTINGS_DEFAULT_GROUP_ID_ATTRIBUTE) 1650 } 1651 1652 if s.FirstNameAttribute == nil { 1653 s.FirstNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE) 1654 } 1655 1656 if s.LastNameAttribute == nil { 1657 s.LastNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE) 1658 } 1659 1660 if s.EmailAttribute == nil { 1661 s.EmailAttribute = NewString(LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE) 1662 } 1663 1664 if s.UsernameAttribute == nil { 1665 s.UsernameAttribute = NewString(LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE) 1666 } 1667 1668 if s.NicknameAttribute == nil { 1669 s.NicknameAttribute = NewString(LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE) 1670 } 1671 1672 if s.IdAttribute == nil { 1673 s.IdAttribute = NewString(LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE) 1674 } 1675 1676 if s.PositionAttribute == nil { 1677 s.PositionAttribute = NewString(LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE) 1678 } 1679 1680 // For those upgrading to the version when LoginIdAttribute was added 1681 // they need IdAttribute == LoginIdAttribute not to break 1682 if s.LoginIdAttribute == nil { 1683 s.LoginIdAttribute = s.IdAttribute 1684 } 1685 1686 if s.SyncIntervalMinutes == nil { 1687 s.SyncIntervalMinutes = NewInt(60) 1688 } 1689 1690 if s.SkipCertificateVerification == nil { 1691 s.SkipCertificateVerification = NewBool(false) 1692 } 1693 1694 if s.QueryTimeout == nil { 1695 s.QueryTimeout = NewInt(60) 1696 } 1697 1698 if s.MaxPageSize == nil { 1699 s.MaxPageSize = NewInt(0) 1700 } 1701 1702 if s.LoginFieldName == nil { 1703 s.LoginFieldName = NewString(LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME) 1704 } 1705 1706 if s.LoginButtonColor == nil { 1707 s.LoginButtonColor = NewString("#0000") 1708 } 1709 1710 if s.LoginButtonBorderColor == nil { 1711 s.LoginButtonBorderColor = NewString("#2389D7") 1712 } 1713 1714 if s.LoginButtonTextColor == nil { 1715 s.LoginButtonTextColor = NewString("#2389D7") 1716 } 1717 } 1718 1719 type ComplianceSettings struct { 1720 Enable *bool 1721 Directory *string 1722 EnableDaily *bool 1723 } 1724 1725 func (s *ComplianceSettings) SetDefaults() { 1726 if s.Enable == nil { 1727 s.Enable = NewBool(false) 1728 } 1729 1730 if s.Directory == nil { 1731 s.Directory = NewString("./data/") 1732 } 1733 1734 if s.EnableDaily == nil { 1735 s.EnableDaily = NewBool(false) 1736 } 1737 } 1738 1739 type LocalizationSettings struct { 1740 DefaultServerLocale *string 1741 DefaultClientLocale *string 1742 AvailableLocales *string 1743 } 1744 1745 func (s *LocalizationSettings) SetDefaults() { 1746 if s.DefaultServerLocale == nil { 1747 s.DefaultServerLocale = NewString(DEFAULT_LOCALE) 1748 } 1749 1750 if s.DefaultClientLocale == nil { 1751 s.DefaultClientLocale = NewString(DEFAULT_LOCALE) 1752 } 1753 1754 if s.AvailableLocales == nil { 1755 s.AvailableLocales = NewString("") 1756 } 1757 } 1758 1759 type SamlSettings struct { 1760 // Basic 1761 Enable *bool 1762 EnableSyncWithLdap *bool 1763 EnableSyncWithLdapIncludeAuth *bool 1764 1765 Verify *bool 1766 Encrypt *bool 1767 1768 IdpUrl *string 1769 IdpDescriptorUrl *string 1770 AssertionConsumerServiceURL *string 1771 1772 ScopingIDPProviderId *string 1773 ScopingIDPName *string 1774 1775 IdpCertificateFile *string 1776 PublicCertificateFile *string 1777 PrivateKeyFile *string 1778 1779 // User Mapping 1780 IdAttribute *string 1781 FirstNameAttribute *string 1782 LastNameAttribute *string 1783 EmailAttribute *string 1784 UsernameAttribute *string 1785 NicknameAttribute *string 1786 LocaleAttribute *string 1787 PositionAttribute *string 1788 1789 LoginButtonText *string 1790 1791 LoginButtonColor *string 1792 LoginButtonBorderColor *string 1793 LoginButtonTextColor *string 1794 } 1795 1796 func (s *SamlSettings) SetDefaults() { 1797 if s.Enable == nil { 1798 s.Enable = NewBool(false) 1799 } 1800 1801 if s.EnableSyncWithLdap == nil { 1802 s.EnableSyncWithLdap = NewBool(false) 1803 } 1804 1805 if s.EnableSyncWithLdapIncludeAuth == nil { 1806 s.EnableSyncWithLdapIncludeAuth = NewBool(false) 1807 } 1808 1809 if s.Verify == nil { 1810 s.Verify = NewBool(true) 1811 } 1812 1813 if s.Encrypt == nil { 1814 s.Encrypt = NewBool(true) 1815 } 1816 1817 if s.IdpUrl == nil { 1818 s.IdpUrl = NewString("") 1819 } 1820 1821 if s.IdpDescriptorUrl == nil { 1822 s.IdpDescriptorUrl = NewString("") 1823 } 1824 1825 if s.IdpCertificateFile == nil { 1826 s.IdpCertificateFile = NewString("") 1827 } 1828 1829 if s.PublicCertificateFile == nil { 1830 s.PublicCertificateFile = NewString("") 1831 } 1832 1833 if s.PrivateKeyFile == nil { 1834 s.PrivateKeyFile = NewString("") 1835 } 1836 1837 if s.AssertionConsumerServiceURL == nil { 1838 s.AssertionConsumerServiceURL = NewString("") 1839 } 1840 1841 if s.ScopingIDPProviderId == nil { 1842 s.ScopingIDPProviderId = NewString("") 1843 } 1844 1845 if s.ScopingIDPName == nil { 1846 s.ScopingIDPName = NewString("") 1847 } 1848 1849 if s.LoginButtonText == nil || *s.LoginButtonText == "" { 1850 s.LoginButtonText = NewString(USER_AUTH_SERVICE_SAML_TEXT) 1851 } 1852 1853 if s.IdAttribute == nil { 1854 s.IdAttribute = NewString(SAML_SETTINGS_DEFAULT_ID_ATTRIBUTE) 1855 } 1856 1857 if s.FirstNameAttribute == nil { 1858 s.FirstNameAttribute = NewString(SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE) 1859 } 1860 1861 if s.LastNameAttribute == nil { 1862 s.LastNameAttribute = NewString(SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE) 1863 } 1864 1865 if s.EmailAttribute == nil { 1866 s.EmailAttribute = NewString(SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE) 1867 } 1868 1869 if s.UsernameAttribute == nil { 1870 s.UsernameAttribute = NewString(SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE) 1871 } 1872 1873 if s.NicknameAttribute == nil { 1874 s.NicknameAttribute = NewString(SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE) 1875 } 1876 1877 if s.PositionAttribute == nil { 1878 s.PositionAttribute = NewString(SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE) 1879 } 1880 1881 if s.LocaleAttribute == nil { 1882 s.LocaleAttribute = NewString(SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE) 1883 } 1884 1885 if s.LoginButtonColor == nil { 1886 s.LoginButtonColor = NewString("#34a28b") 1887 } 1888 1889 if s.LoginButtonBorderColor == nil { 1890 s.LoginButtonBorderColor = NewString("#2389D7") 1891 } 1892 1893 if s.LoginButtonTextColor == nil { 1894 s.LoginButtonTextColor = NewString("#ffffff") 1895 } 1896 } 1897 1898 type NativeAppSettings struct { 1899 AppDownloadLink *string `restricted:"true"` 1900 AndroidAppDownloadLink *string `restricted:"true"` 1901 IosAppDownloadLink *string `restricted:"true"` 1902 } 1903 1904 func (s *NativeAppSettings) SetDefaults() { 1905 if s.AppDownloadLink == nil { 1906 s.AppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK) 1907 } 1908 1909 if s.AndroidAppDownloadLink == nil { 1910 s.AndroidAppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK) 1911 } 1912 1913 if s.IosAppDownloadLink == nil { 1914 s.IosAppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK) 1915 } 1916 } 1917 1918 type ElasticsearchSettings struct { 1919 ConnectionUrl *string `restricted:"true"` 1920 Username *string `restricted:"true"` 1921 Password *string `restricted:"true"` 1922 EnableIndexing *bool `restricted:"true"` 1923 EnableSearching *bool `restricted:"true"` 1924 EnableAutocomplete *bool `restricted:"true"` 1925 Sniff *bool `restricted:"true"` 1926 PostIndexReplicas *int `restricted:"true"` 1927 PostIndexShards *int `restricted:"true"` 1928 ChannelIndexReplicas *int `restricted:"true"` 1929 ChannelIndexShards *int `restricted:"true"` 1930 UserIndexReplicas *int `restricted:"true"` 1931 UserIndexShards *int `restricted:"true"` 1932 AggregatePostsAfterDays *int `restricted:"true"` 1933 PostsAggregatorJobStartTime *string `restricted:"true"` 1934 IndexPrefix *string `restricted:"true"` 1935 LiveIndexingBatchSize *int `restricted:"true"` 1936 BulkIndexingTimeWindowSeconds *int `restricted:"true"` 1937 RequestTimeoutSeconds *int `restricted:"true"` 1938 } 1939 1940 func (s *ElasticsearchSettings) SetDefaults() { 1941 if s.ConnectionUrl == nil { 1942 s.ConnectionUrl = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL) 1943 } 1944 1945 if s.Username == nil { 1946 s.Username = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME) 1947 } 1948 1949 if s.Password == nil { 1950 s.Password = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD) 1951 } 1952 1953 if s.EnableIndexing == nil { 1954 s.EnableIndexing = NewBool(false) 1955 } 1956 1957 if s.EnableSearching == nil { 1958 s.EnableSearching = NewBool(false) 1959 } 1960 1961 if s.EnableAutocomplete == nil { 1962 s.EnableAutocomplete = NewBool(false) 1963 } 1964 1965 if s.Sniff == nil { 1966 s.Sniff = NewBool(true) 1967 } 1968 1969 if s.PostIndexReplicas == nil { 1970 s.PostIndexReplicas = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS) 1971 } 1972 1973 if s.PostIndexShards == nil { 1974 s.PostIndexShards = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS) 1975 } 1976 1977 if s.ChannelIndexReplicas == nil { 1978 s.ChannelIndexReplicas = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_CHANNEL_INDEX_REPLICAS) 1979 } 1980 1981 if s.ChannelIndexShards == nil { 1982 s.ChannelIndexShards = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_CHANNEL_INDEX_SHARDS) 1983 } 1984 1985 if s.UserIndexReplicas == nil { 1986 s.UserIndexReplicas = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_USER_INDEX_REPLICAS) 1987 } 1988 1989 if s.UserIndexShards == nil { 1990 s.UserIndexShards = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_USER_INDEX_SHARDS) 1991 } 1992 1993 if s.AggregatePostsAfterDays == nil { 1994 s.AggregatePostsAfterDays = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS) 1995 } 1996 1997 if s.PostsAggregatorJobStartTime == nil { 1998 s.PostsAggregatorJobStartTime = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_POSTS_AGGREGATOR_JOB_START_TIME) 1999 } 2000 2001 if s.IndexPrefix == nil { 2002 s.IndexPrefix = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX) 2003 } 2004 2005 if s.LiveIndexingBatchSize == nil { 2006 s.LiveIndexingBatchSize = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_LIVE_INDEXING_BATCH_SIZE) 2007 } 2008 2009 if s.BulkIndexingTimeWindowSeconds == nil { 2010 s.BulkIndexingTimeWindowSeconds = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_BULK_INDEXING_TIME_WINDOW_SECONDS) 2011 } 2012 2013 if s.RequestTimeoutSeconds == nil { 2014 s.RequestTimeoutSeconds = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_REQUEST_TIMEOUT_SECONDS) 2015 } 2016 } 2017 2018 type DataRetentionSettings struct { 2019 EnableMessageDeletion *bool 2020 EnableFileDeletion *bool 2021 MessageRetentionDays *int 2022 FileRetentionDays *int 2023 DeletionJobStartTime *string 2024 } 2025 2026 func (s *DataRetentionSettings) SetDefaults() { 2027 if s.EnableMessageDeletion == nil { 2028 s.EnableMessageDeletion = NewBool(false) 2029 } 2030 2031 if s.EnableFileDeletion == nil { 2032 s.EnableFileDeletion = NewBool(false) 2033 } 2034 2035 if s.MessageRetentionDays == nil { 2036 s.MessageRetentionDays = NewInt(DATA_RETENTION_SETTINGS_DEFAULT_MESSAGE_RETENTION_DAYS) 2037 } 2038 2039 if s.FileRetentionDays == nil { 2040 s.FileRetentionDays = NewInt(DATA_RETENTION_SETTINGS_DEFAULT_FILE_RETENTION_DAYS) 2041 } 2042 2043 if s.DeletionJobStartTime == nil { 2044 s.DeletionJobStartTime = NewString(DATA_RETENTION_SETTINGS_DEFAULT_DELETION_JOB_START_TIME) 2045 } 2046 } 2047 2048 type JobSettings struct { 2049 RunJobs *bool `restricted:"true"` 2050 RunScheduler *bool `restricted:"true"` 2051 } 2052 2053 func (s *JobSettings) SetDefaults() { 2054 if s.RunJobs == nil { 2055 s.RunJobs = NewBool(true) 2056 } 2057 2058 if s.RunScheduler == nil { 2059 s.RunScheduler = NewBool(true) 2060 } 2061 } 2062 2063 type PluginState struct { 2064 Enable bool 2065 } 2066 2067 type PluginSettings struct { 2068 Enable *bool 2069 EnableUploads *bool `restricted:"true"` 2070 Directory *string `restricted:"true"` 2071 ClientDirectory *string `restricted:"true"` 2072 Plugins map[string]map[string]interface{} 2073 PluginStates map[string]*PluginState 2074 } 2075 2076 func (s *PluginSettings) SetDefaults() { 2077 if s.Enable == nil { 2078 s.Enable = NewBool(true) 2079 } 2080 2081 if s.EnableUploads == nil { 2082 s.EnableUploads = NewBool(false) 2083 } 2084 2085 if s.Directory == nil { 2086 s.Directory = NewString(PLUGIN_SETTINGS_DEFAULT_DIRECTORY) 2087 } 2088 2089 if *s.Directory == "" { 2090 *s.Directory = PLUGIN_SETTINGS_DEFAULT_DIRECTORY 2091 } 2092 2093 if s.ClientDirectory == nil { 2094 s.ClientDirectory = NewString(PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY) 2095 } 2096 2097 if *s.ClientDirectory == "" { 2098 *s.ClientDirectory = PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY 2099 } 2100 2101 if s.Plugins == nil { 2102 s.Plugins = make(map[string]map[string]interface{}) 2103 } 2104 2105 if s.PluginStates == nil { 2106 s.PluginStates = make(map[string]*PluginState) 2107 } 2108 } 2109 2110 type GlobalRelayMessageExportSettings struct { 2111 CustomerType *string // must be either A9 or A10, dictates SMTP server url 2112 SmtpUsername *string 2113 SmtpPassword *string 2114 EmailAddress *string // the address to send messages to 2115 } 2116 2117 func (s *GlobalRelayMessageExportSettings) SetDefaults() { 2118 if s.CustomerType == nil { 2119 s.CustomerType = NewString(GLOBALRELAY_CUSTOMER_TYPE_A9) 2120 } 2121 if s.SmtpUsername == nil { 2122 s.SmtpUsername = NewString("") 2123 } 2124 if s.SmtpPassword == nil { 2125 s.SmtpPassword = NewString("") 2126 } 2127 if s.EmailAddress == nil { 2128 s.EmailAddress = NewString("") 2129 } 2130 } 2131 2132 type MessageExportSettings struct { 2133 EnableExport *bool 2134 ExportFormat *string 2135 DailyRunTime *string 2136 ExportFromTimestamp *int64 2137 BatchSize *int 2138 2139 // formatter-specific settings - these are only expected to be non-nil if ExportFormat is set to the associated format 2140 GlobalRelaySettings *GlobalRelayMessageExportSettings 2141 } 2142 2143 func (s *MessageExportSettings) SetDefaults() { 2144 if s.EnableExport == nil { 2145 s.EnableExport = NewBool(false) 2146 } 2147 2148 if s.ExportFormat == nil { 2149 s.ExportFormat = NewString(COMPLIANCE_EXPORT_TYPE_ACTIANCE) 2150 } 2151 2152 if s.DailyRunTime == nil { 2153 s.DailyRunTime = NewString("01:00") 2154 } 2155 2156 if s.ExportFromTimestamp == nil { 2157 s.ExportFromTimestamp = NewInt64(0) 2158 } 2159 2160 if s.BatchSize == nil { 2161 s.BatchSize = NewInt(10000) 2162 } 2163 2164 if s.GlobalRelaySettings == nil { 2165 s.GlobalRelaySettings = &GlobalRelayMessageExportSettings{} 2166 } 2167 s.GlobalRelaySettings.SetDefaults() 2168 } 2169 2170 type DisplaySettings struct { 2171 CustomUrlSchemes []string 2172 ExperimentalTimezone *bool 2173 } 2174 2175 func (s *DisplaySettings) SetDefaults() { 2176 if s.CustomUrlSchemes == nil { 2177 customUrlSchemes := []string{} 2178 s.CustomUrlSchemes = customUrlSchemes 2179 } 2180 2181 if s.ExperimentalTimezone == nil { 2182 s.ExperimentalTimezone = NewBool(false) 2183 } 2184 } 2185 2186 type ImageProxySettings struct { 2187 Enable *bool 2188 ImageProxyType *string 2189 RemoteImageProxyURL *string 2190 RemoteImageProxyOptions *string 2191 } 2192 2193 func (ips *ImageProxySettings) SetDefaults(ss ServiceSettings) { 2194 if ips.Enable == nil { 2195 if ss.DEPRECATED_DO_NOT_USE_ImageProxyType == nil || *ss.DEPRECATED_DO_NOT_USE_ImageProxyType == "" { 2196 ips.Enable = NewBool(false) 2197 } else { 2198 ips.Enable = NewBool(true) 2199 } 2200 } 2201 2202 if ips.ImageProxyType == nil { 2203 if ss.DEPRECATED_DO_NOT_USE_ImageProxyType == nil || *ss.DEPRECATED_DO_NOT_USE_ImageProxyType == "" { 2204 ips.ImageProxyType = NewString(IMAGE_PROXY_TYPE_LOCAL) 2205 } else { 2206 ips.ImageProxyType = ss.DEPRECATED_DO_NOT_USE_ImageProxyType 2207 } 2208 } 2209 2210 if ips.RemoteImageProxyURL == nil { 2211 if ss.DEPRECATED_DO_NOT_USE_ImageProxyURL == nil { 2212 ips.RemoteImageProxyURL = NewString("") 2213 } else { 2214 ips.RemoteImageProxyURL = ss.DEPRECATED_DO_NOT_USE_ImageProxyURL 2215 } 2216 } 2217 2218 if ips.RemoteImageProxyOptions == nil { 2219 if ss.DEPRECATED_DO_NOT_USE_ImageProxyOptions == nil { 2220 ips.RemoteImageProxyOptions = NewString("") 2221 } else { 2222 ips.RemoteImageProxyOptions = ss.DEPRECATED_DO_NOT_USE_ImageProxyOptions 2223 } 2224 } 2225 } 2226 2227 type ConfigFunc func() *Config 2228 2229 type Config struct { 2230 ServiceSettings ServiceSettings 2231 TeamSettings TeamSettings 2232 ClientRequirements ClientRequirements 2233 SqlSettings SqlSettings 2234 LogSettings LogSettings 2235 PasswordSettings PasswordSettings 2236 FileSettings FileSettings 2237 EmailSettings EmailSettings 2238 RateLimitSettings RateLimitSettings 2239 PrivacySettings PrivacySettings 2240 SupportSettings SupportSettings 2241 AnnouncementSettings AnnouncementSettings 2242 ThemeSettings ThemeSettings 2243 GitLabSettings SSOSettings 2244 GoogleSettings SSOSettings 2245 Office365Settings SSOSettings 2246 LdapSettings LdapSettings 2247 ComplianceSettings ComplianceSettings 2248 LocalizationSettings LocalizationSettings 2249 SamlSettings SamlSettings 2250 NativeAppSettings NativeAppSettings 2251 ClusterSettings ClusterSettings 2252 MetricsSettings MetricsSettings 2253 ExperimentalSettings ExperimentalSettings 2254 AnalyticsSettings AnalyticsSettings 2255 ElasticsearchSettings ElasticsearchSettings 2256 DataRetentionSettings DataRetentionSettings 2257 MessageExportSettings MessageExportSettings 2258 JobSettings JobSettings 2259 PluginSettings PluginSettings 2260 DisplaySettings DisplaySettings 2261 ImageProxySettings ImageProxySettings 2262 } 2263 2264 func (o *Config) Clone() *Config { 2265 var ret Config 2266 if err := json.Unmarshal([]byte(o.ToJson()), &ret); err != nil { 2267 panic(err) 2268 } 2269 return &ret 2270 } 2271 2272 func (o *Config) ToJson() string { 2273 b, _ := json.Marshal(o) 2274 return string(b) 2275 } 2276 2277 func (o *Config) GetSSOService(service string) *SSOSettings { 2278 switch service { 2279 case SERVICE_GITLAB: 2280 return &o.GitLabSettings 2281 case SERVICE_GOOGLE: 2282 return &o.GoogleSettings 2283 case SERVICE_OFFICE365: 2284 return &o.Office365Settings 2285 } 2286 2287 return nil 2288 } 2289 2290 func ConfigFromJson(data io.Reader) *Config { 2291 var o *Config 2292 json.NewDecoder(data).Decode(&o) 2293 return o 2294 } 2295 2296 func (o *Config) SetDefaults() { 2297 o.LdapSettings.SetDefaults() 2298 o.SamlSettings.SetDefaults() 2299 2300 if o.TeamSettings.TeammateNameDisplay == nil { 2301 o.TeamSettings.TeammateNameDisplay = NewString(SHOW_USERNAME) 2302 2303 if *o.SamlSettings.Enable || *o.LdapSettings.Enable { 2304 *o.TeamSettings.TeammateNameDisplay = SHOW_FULLNAME 2305 } 2306 } 2307 2308 o.SqlSettings.SetDefaults() 2309 o.FileSettings.SetDefaults() 2310 o.EmailSettings.SetDefaults() 2311 o.PrivacySettings.setDefaults() 2312 o.Office365Settings.setDefaults() 2313 o.GitLabSettings.setDefaults() 2314 o.GoogleSettings.setDefaults() 2315 o.ServiceSettings.SetDefaults() 2316 o.PasswordSettings.SetDefaults() 2317 o.TeamSettings.SetDefaults() 2318 o.MetricsSettings.SetDefaults() 2319 o.ExperimentalSettings.SetDefaults() 2320 o.SupportSettings.SetDefaults() 2321 o.AnnouncementSettings.SetDefaults() 2322 o.ThemeSettings.SetDefaults() 2323 o.ClusterSettings.SetDefaults() 2324 o.PluginSettings.SetDefaults() 2325 o.AnalyticsSettings.SetDefaults() 2326 o.ComplianceSettings.SetDefaults() 2327 o.LocalizationSettings.SetDefaults() 2328 o.ElasticsearchSettings.SetDefaults() 2329 o.NativeAppSettings.SetDefaults() 2330 o.DataRetentionSettings.SetDefaults() 2331 o.RateLimitSettings.SetDefaults() 2332 o.LogSettings.SetDefaults() 2333 o.JobSettings.SetDefaults() 2334 o.MessageExportSettings.SetDefaults() 2335 o.DisplaySettings.SetDefaults() 2336 o.ImageProxySettings.SetDefaults(o.ServiceSettings) 2337 } 2338 2339 func (o *Config) IsValid() *AppError { 2340 if len(*o.ServiceSettings.SiteURL) == 0 && *o.EmailSettings.EnableEmailBatching { 2341 return NewAppError("Config.IsValid", "model.config.is_valid.site_url_email_batching.app_error", nil, "", http.StatusBadRequest) 2342 } 2343 2344 if *o.ClusterSettings.Enable && *o.EmailSettings.EnableEmailBatching { 2345 return NewAppError("Config.IsValid", "model.config.is_valid.cluster_email_batching.app_error", nil, "", http.StatusBadRequest) 2346 } 2347 2348 if len(*o.ServiceSettings.SiteURL) == 0 && *o.ServiceSettings.AllowCookiesForSubdomains { 2349 return NewAppError("Config.IsValid", "model.config.is_valid.allow_cookies_for_subdomains.app_error", nil, "", http.StatusBadRequest) 2350 } 2351 2352 if err := o.TeamSettings.isValid(); err != nil { 2353 return err 2354 } 2355 2356 if err := o.SqlSettings.isValid(); err != nil { 2357 return err 2358 } 2359 2360 if err := o.FileSettings.isValid(); err != nil { 2361 return err 2362 } 2363 2364 if err := o.EmailSettings.isValid(); err != nil { 2365 return err 2366 } 2367 2368 if err := o.LdapSettings.isValid(); err != nil { 2369 return err 2370 } 2371 2372 if err := o.SamlSettings.isValid(); err != nil { 2373 return err 2374 } 2375 2376 if *o.PasswordSettings.MinimumLength < PASSWORD_MINIMUM_LENGTH || *o.PasswordSettings.MinimumLength > PASSWORD_MAXIMUM_LENGTH { 2377 return NewAppError("Config.IsValid", "model.config.is_valid.password_length.app_error", map[string]interface{}{"MinLength": PASSWORD_MINIMUM_LENGTH, "MaxLength": PASSWORD_MAXIMUM_LENGTH}, "", http.StatusBadRequest) 2378 } 2379 2380 if err := o.RateLimitSettings.isValid(); err != nil { 2381 return err 2382 } 2383 2384 if err := o.ServiceSettings.isValid(); err != nil { 2385 return err 2386 } 2387 2388 if err := o.ElasticsearchSettings.isValid(); err != nil { 2389 return err 2390 } 2391 2392 if err := o.DataRetentionSettings.isValid(); err != nil { 2393 return err 2394 } 2395 2396 if err := o.LocalizationSettings.isValid(); err != nil { 2397 return err 2398 } 2399 2400 if err := o.MessageExportSettings.isValid(o.FileSettings); err != nil { 2401 return err 2402 } 2403 2404 if err := o.DisplaySettings.isValid(); err != nil { 2405 return err 2406 } 2407 2408 if err := o.ImageProxySettings.isValid(); err != nil { 2409 return err 2410 } 2411 2412 return nil 2413 } 2414 2415 func (ts *TeamSettings) isValid() *AppError { 2416 if *ts.MaxUsersPerTeam <= 0 { 2417 return NewAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "", http.StatusBadRequest) 2418 } 2419 2420 if *ts.MaxChannelsPerTeam <= 0 { 2421 return NewAppError("Config.IsValid", "model.config.is_valid.max_channels.app_error", nil, "", http.StatusBadRequest) 2422 } 2423 2424 if *ts.MaxNotificationsPerChannel <= 0 { 2425 return NewAppError("Config.IsValid", "model.config.is_valid.max_notify_per_channel.app_error", nil, "", http.StatusBadRequest) 2426 } 2427 2428 if !(*ts.RestrictDirectMessage == DIRECT_MESSAGE_ANY || *ts.RestrictDirectMessage == DIRECT_MESSAGE_TEAM) { 2429 return NewAppError("Config.IsValid", "model.config.is_valid.restrict_direct_message.app_error", nil, "", http.StatusBadRequest) 2430 } 2431 2432 if !(*ts.TeammateNameDisplay == SHOW_FULLNAME || *ts.TeammateNameDisplay == SHOW_NICKNAME_FULLNAME || *ts.TeammateNameDisplay == SHOW_USERNAME) { 2433 return NewAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "", http.StatusBadRequest) 2434 } 2435 2436 if len(*ts.SiteName) == 0 { 2437 return NewAppError("Config.IsValid", "model.config.is_valid.sitename_empty.app_error", nil, "", http.StatusBadRequest) 2438 } 2439 2440 if len(*ts.SiteName) > SITENAME_MAX_LENGTH { 2441 return NewAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "", http.StatusBadRequest) 2442 } 2443 2444 return nil 2445 } 2446 2447 func (ss *SqlSettings) isValid() *AppError { 2448 if len(*ss.AtRestEncryptKey) < 32 { 2449 return NewAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "", http.StatusBadRequest) 2450 } 2451 2452 if !(*ss.DriverName == DATABASE_DRIVER_MYSQL || *ss.DriverName == DATABASE_DRIVER_POSTGRES) { 2453 return NewAppError("Config.IsValid", "model.config.is_valid.sql_driver.app_error", nil, "", http.StatusBadRequest) 2454 } 2455 2456 if *ss.MaxIdleConns <= 0 { 2457 return NewAppError("Config.IsValid", "model.config.is_valid.sql_idle.app_error", nil, "", http.StatusBadRequest) 2458 } 2459 2460 if *ss.ConnMaxLifetimeMilliseconds < 0 { 2461 return NewAppError("Config.IsValid", "model.config.is_valid.sql_conn_max_lifetime_milliseconds.app_error", nil, "", http.StatusBadRequest) 2462 } 2463 2464 if *ss.QueryTimeout <= 0 { 2465 return NewAppError("Config.IsValid", "model.config.is_valid.sql_query_timeout.app_error", nil, "", http.StatusBadRequest) 2466 } 2467 2468 if len(*ss.DataSource) == 0 { 2469 return NewAppError("Config.IsValid", "model.config.is_valid.sql_data_src.app_error", nil, "", http.StatusBadRequest) 2470 } 2471 2472 if *ss.MaxOpenConns <= 0 { 2473 return NewAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "", http.StatusBadRequest) 2474 } 2475 2476 return nil 2477 } 2478 2479 func (fs *FileSettings) isValid() *AppError { 2480 if *fs.MaxFileSize <= 0 { 2481 return NewAppError("Config.IsValid", "model.config.is_valid.max_file_size.app_error", nil, "", http.StatusBadRequest) 2482 } 2483 2484 if !(*fs.DriverName == IMAGE_DRIVER_LOCAL || *fs.DriverName == IMAGE_DRIVER_S3) { 2485 return NewAppError("Config.IsValid", "model.config.is_valid.file_driver.app_error", nil, "", http.StatusBadRequest) 2486 } 2487 2488 if len(*fs.PublicLinkSalt) < 32 { 2489 return NewAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "", http.StatusBadRequest) 2490 } 2491 2492 return nil 2493 } 2494 2495 func (es *EmailSettings) isValid() *AppError { 2496 if !(*es.ConnectionSecurity == CONN_SECURITY_NONE || *es.ConnectionSecurity == CONN_SECURITY_TLS || *es.ConnectionSecurity == CONN_SECURITY_STARTTLS || *es.ConnectionSecurity == CONN_SECURITY_PLAIN) { 2497 return NewAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "", http.StatusBadRequest) 2498 } 2499 2500 if *es.EmailBatchingBufferSize <= 0 { 2501 return NewAppError("Config.IsValid", "model.config.is_valid.email_batching_buffer_size.app_error", nil, "", http.StatusBadRequest) 2502 } 2503 2504 if *es.EmailBatchingInterval < 30 { 2505 return NewAppError("Config.IsValid", "model.config.is_valid.email_batching_interval.app_error", nil, "", http.StatusBadRequest) 2506 } 2507 2508 if !(*es.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_FULL || *es.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_GENERIC) { 2509 return NewAppError("Config.IsValid", "model.config.is_valid.email_notification_contents_type.app_error", nil, "", http.StatusBadRequest) 2510 } 2511 2512 return nil 2513 } 2514 2515 func (rls *RateLimitSettings) isValid() *AppError { 2516 if *rls.MemoryStoreSize <= 0 { 2517 return NewAppError("Config.IsValid", "model.config.is_valid.rate_mem.app_error", nil, "", http.StatusBadRequest) 2518 } 2519 2520 if *rls.PerSec <= 0 { 2521 return NewAppError("Config.IsValid", "model.config.is_valid.rate_sec.app_error", nil, "", http.StatusBadRequest) 2522 } 2523 2524 if *rls.MaxBurst <= 0 { 2525 return NewAppError("Config.IsValid", "model.config.is_valid.max_burst.app_error", nil, "", http.StatusBadRequest) 2526 } 2527 2528 return nil 2529 } 2530 2531 func (ls *LdapSettings) isValid() *AppError { 2532 if !(*ls.ConnectionSecurity == CONN_SECURITY_NONE || *ls.ConnectionSecurity == CONN_SECURITY_TLS || *ls.ConnectionSecurity == CONN_SECURITY_STARTTLS) { 2533 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_security.app_error", nil, "", http.StatusBadRequest) 2534 } 2535 2536 if *ls.SyncIntervalMinutes <= 0 { 2537 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_sync_interval.app_error", nil, "", http.StatusBadRequest) 2538 } 2539 2540 if *ls.MaxPageSize < 0 { 2541 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_max_page_size.app_error", nil, "", http.StatusBadRequest) 2542 } 2543 2544 if *ls.Enable { 2545 if *ls.LdapServer == "" { 2546 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_server", nil, "", http.StatusBadRequest) 2547 } 2548 2549 if *ls.BaseDN == "" { 2550 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_basedn", nil, "", http.StatusBadRequest) 2551 } 2552 2553 if *ls.EmailAttribute == "" { 2554 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_email", nil, "", http.StatusBadRequest) 2555 } 2556 2557 if *ls.UsernameAttribute == "" { 2558 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_username", nil, "", http.StatusBadRequest) 2559 } 2560 2561 if *ls.IdAttribute == "" { 2562 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_id", nil, "", http.StatusBadRequest) 2563 } 2564 2565 if *ls.LoginIdAttribute == "" { 2566 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_login_id", nil, "", http.StatusBadRequest) 2567 } 2568 2569 if *ls.UserFilter != "" { 2570 if _, err := ldap.CompileFilter(*ls.UserFilter); err != nil { 2571 return NewAppError("ValidateFilter", "ent.ldap.validate_filter.app_error", nil, err.Error(), http.StatusBadRequest) 2572 } 2573 } 2574 } 2575 2576 return nil 2577 } 2578 2579 func (ss *SamlSettings) isValid() *AppError { 2580 if *ss.Enable { 2581 if len(*ss.IdpUrl) == 0 || !IsValidHttpUrl(*ss.IdpUrl) { 2582 return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_url.app_error", nil, "", http.StatusBadRequest) 2583 } 2584 2585 if len(*ss.IdpDescriptorUrl) == 0 || !IsValidHttpUrl(*ss.IdpDescriptorUrl) { 2586 return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_descriptor_url.app_error", nil, "", http.StatusBadRequest) 2587 } 2588 2589 if len(*ss.IdpCertificateFile) == 0 { 2590 return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_cert.app_error", nil, "", http.StatusBadRequest) 2591 } 2592 2593 if len(*ss.EmailAttribute) == 0 { 2594 return NewAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "", http.StatusBadRequest) 2595 } 2596 2597 if len(*ss.UsernameAttribute) == 0 { 2598 return NewAppError("Config.IsValid", "model.config.is_valid.saml_username_attribute.app_error", nil, "", http.StatusBadRequest) 2599 } 2600 2601 if *ss.Verify { 2602 if len(*ss.AssertionConsumerServiceURL) == 0 || !IsValidHttpUrl(*ss.AssertionConsumerServiceURL) { 2603 return NewAppError("Config.IsValid", "model.config.is_valid.saml_assertion_consumer_service_url.app_error", nil, "", http.StatusBadRequest) 2604 } 2605 } 2606 2607 if *ss.Encrypt { 2608 if len(*ss.PrivateKeyFile) == 0 { 2609 return NewAppError("Config.IsValid", "model.config.is_valid.saml_private_key.app_error", nil, "", http.StatusBadRequest) 2610 } 2611 2612 if len(*ss.PublicCertificateFile) == 0 { 2613 return NewAppError("Config.IsValid", "model.config.is_valid.saml_public_cert.app_error", nil, "", http.StatusBadRequest) 2614 } 2615 } 2616 2617 if len(*ss.EmailAttribute) == 0 { 2618 return NewAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "", http.StatusBadRequest) 2619 } 2620 } 2621 2622 return nil 2623 } 2624 2625 func (ss *ServiceSettings) isValid() *AppError { 2626 if !(*ss.ConnectionSecurity == CONN_SECURITY_NONE || *ss.ConnectionSecurity == CONN_SECURITY_TLS) { 2627 return NewAppError("Config.IsValid", "model.config.is_valid.webserver_security.app_error", nil, "", http.StatusBadRequest) 2628 } 2629 2630 if *ss.ConnectionSecurity == CONN_SECURITY_TLS && *ss.UseLetsEncrypt == false { 2631 appErr := NewAppError("Config.IsValid", "model.config.is_valid.tls_cert_file.app_error", nil, "", http.StatusBadRequest) 2632 2633 if *ss.TLSCertFile == "" { 2634 return appErr 2635 } else if _, err := os.Stat(*ss.TLSCertFile); os.IsNotExist(err) { 2636 return appErr 2637 } 2638 2639 appErr = NewAppError("Config.IsValid", "model.config.is_valid.tls_key_file.app_error", nil, "", http.StatusBadRequest) 2640 2641 if *ss.TLSKeyFile == "" { 2642 return appErr 2643 } else if _, err := os.Stat(*ss.TLSKeyFile); os.IsNotExist(err) { 2644 return appErr 2645 } 2646 } 2647 2648 if len(ss.TLSOverwriteCiphers) > 0 { 2649 for _, cipher := range ss.TLSOverwriteCiphers { 2650 if _, ok := ServerTLSSupportedCiphers[cipher]; !ok { 2651 return NewAppError("Config.IsValid", "model.config.is_valid.tls_overwrite_cipher.app_error", map[string]interface{}{"name": cipher}, "", http.StatusBadRequest) 2652 } 2653 } 2654 } 2655 2656 if *ss.ReadTimeout <= 0 { 2657 return NewAppError("Config.IsValid", "model.config.is_valid.read_timeout.app_error", nil, "", http.StatusBadRequest) 2658 } 2659 2660 if *ss.WriteTimeout <= 0 { 2661 return NewAppError("Config.IsValid", "model.config.is_valid.write_timeout.app_error", nil, "", http.StatusBadRequest) 2662 } 2663 2664 if *ss.TimeBetweenUserTypingUpdatesMilliseconds < 1000 { 2665 return NewAppError("Config.IsValid", "model.config.is_valid.time_between_user_typing.app_error", nil, "", http.StatusBadRequest) 2666 } 2667 2668 if *ss.MaximumLoginAttempts <= 0 { 2669 return NewAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "", http.StatusBadRequest) 2670 } 2671 2672 if len(*ss.SiteURL) != 0 { 2673 if _, err := url.ParseRequestURI(*ss.SiteURL); err != nil { 2674 return NewAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "", http.StatusBadRequest) 2675 } 2676 } 2677 2678 if len(*ss.WebsocketURL) != 0 { 2679 if _, err := url.ParseRequestURI(*ss.WebsocketURL); err != nil { 2680 return NewAppError("Config.IsValid", "model.config.is_valid.websocket_url.app_error", nil, "", http.StatusBadRequest) 2681 } 2682 } 2683 2684 host, port, _ := net.SplitHostPort(*ss.ListenAddress) 2685 var isValidHost bool 2686 if host == "" { 2687 isValidHost = true 2688 } else { 2689 isValidHost = (net.ParseIP(host) != nil) || IsDomainName(host) 2690 } 2691 portInt, err := strconv.Atoi(port) 2692 if err != nil || !isValidHost || portInt < 0 || portInt > math.MaxUint16 { 2693 return NewAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "", http.StatusBadRequest) 2694 } 2695 2696 if *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED && 2697 *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_ON && 2698 *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_OFF { 2699 return NewAppError("Config.IsValid", "model.config.is_valid.group_unread_channels.app_error", nil, "", http.StatusBadRequest) 2700 } 2701 2702 return nil 2703 } 2704 2705 func (ess *ElasticsearchSettings) isValid() *AppError { 2706 if *ess.EnableIndexing { 2707 if len(*ess.ConnectionUrl) == 0 { 2708 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.connection_url.app_error", nil, "", http.StatusBadRequest) 2709 } 2710 } 2711 2712 if *ess.EnableSearching && !*ess.EnableIndexing { 2713 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.enable_searching.app_error", nil, "", http.StatusBadRequest) 2714 } 2715 2716 if *ess.EnableAutocomplete && !*ess.EnableIndexing { 2717 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.enable_autocomplete.app_error", nil, "", http.StatusBadRequest) 2718 } 2719 2720 if *ess.AggregatePostsAfterDays < 1 { 2721 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.aggregate_posts_after_days.app_error", nil, "", http.StatusBadRequest) 2722 } 2723 2724 if _, err := time.Parse("15:04", *ess.PostsAggregatorJobStartTime); err != nil { 2725 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.posts_aggregator_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest) 2726 } 2727 2728 if *ess.LiveIndexingBatchSize < 1 { 2729 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.live_indexing_batch_size.app_error", nil, "", http.StatusBadRequest) 2730 } 2731 2732 if *ess.BulkIndexingTimeWindowSeconds < 1 { 2733 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.bulk_indexing_time_window_seconds.app_error", nil, "", http.StatusBadRequest) 2734 } 2735 2736 if *ess.RequestTimeoutSeconds < 1 { 2737 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.request_timeout_seconds.app_error", nil, "", http.StatusBadRequest) 2738 } 2739 2740 return nil 2741 } 2742 2743 func (drs *DataRetentionSettings) isValid() *AppError { 2744 if *drs.MessageRetentionDays <= 0 { 2745 return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.message_retention_days_too_low.app_error", nil, "", http.StatusBadRequest) 2746 } 2747 2748 if *drs.FileRetentionDays <= 0 { 2749 return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.file_retention_days_too_low.app_error", nil, "", http.StatusBadRequest) 2750 } 2751 2752 if _, err := time.Parse("15:04", *drs.DeletionJobStartTime); err != nil { 2753 return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.deletion_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest) 2754 } 2755 2756 return nil 2757 } 2758 2759 func (ls *LocalizationSettings) isValid() *AppError { 2760 if len(*ls.AvailableLocales) > 0 { 2761 if !strings.Contains(*ls.AvailableLocales, *ls.DefaultClientLocale) { 2762 return NewAppError("Config.IsValid", "model.config.is_valid.localization.available_locales.app_error", nil, "", http.StatusBadRequest) 2763 } 2764 } 2765 2766 return nil 2767 } 2768 2769 func (mes *MessageExportSettings) isValid(fs FileSettings) *AppError { 2770 if mes.EnableExport == nil { 2771 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.enable.app_error", nil, "", http.StatusBadRequest) 2772 } 2773 if *mes.EnableExport { 2774 if mes.ExportFromTimestamp == nil || *mes.ExportFromTimestamp < 0 || *mes.ExportFromTimestamp > GetMillis() { 2775 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.export_from.app_error", nil, "", http.StatusBadRequest) 2776 } else if mes.DailyRunTime == nil { 2777 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, "", http.StatusBadRequest) 2778 } else if _, err := time.Parse("15:04", *mes.DailyRunTime); err != nil { 2779 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, err.Error(), http.StatusBadRequest) 2780 } else if mes.BatchSize == nil || *mes.BatchSize < 0 { 2781 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.batch_size.app_error", nil, "", http.StatusBadRequest) 2782 } else if mes.ExportFormat == nil || (*mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_ACTIANCE && *mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_GLOBALRELAY && *mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_CSV) { 2783 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.export_type.app_error", nil, "", http.StatusBadRequest) 2784 } 2785 2786 if *mes.ExportFormat == COMPLIANCE_EXPORT_TYPE_GLOBALRELAY { 2787 if mes.GlobalRelaySettings == nil { 2788 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.config_missing.app_error", nil, "", http.StatusBadRequest) 2789 } else if mes.GlobalRelaySettings.CustomerType == nil || (*mes.GlobalRelaySettings.CustomerType != GLOBALRELAY_CUSTOMER_TYPE_A9 && *mes.GlobalRelaySettings.CustomerType != GLOBALRELAY_CUSTOMER_TYPE_A10) { 2790 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.customer_type.app_error", nil, "", http.StatusBadRequest) 2791 } else if mes.GlobalRelaySettings.EmailAddress == nil || !strings.Contains(*mes.GlobalRelaySettings.EmailAddress, "@") { 2792 // validating email addresses is hard - just make sure it contains an '@' sign 2793 // see https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address 2794 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.email_address.app_error", nil, "", http.StatusBadRequest) 2795 } else if mes.GlobalRelaySettings.SmtpUsername == nil || *mes.GlobalRelaySettings.SmtpUsername == "" { 2796 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.smtp_username.app_error", nil, "", http.StatusBadRequest) 2797 } else if mes.GlobalRelaySettings.SmtpPassword == nil || *mes.GlobalRelaySettings.SmtpPassword == "" { 2798 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.smtp_password.app_error", nil, "", http.StatusBadRequest) 2799 } 2800 } 2801 } 2802 return nil 2803 } 2804 2805 func (ds *DisplaySettings) isValid() *AppError { 2806 if len(ds.CustomUrlSchemes) != 0 { 2807 validProtocolPattern := regexp.MustCompile(`(?i)^\s*[a-z][a-z0-9-]*\s*$`) 2808 2809 for _, scheme := range ds.CustomUrlSchemes { 2810 if !validProtocolPattern.MatchString(scheme) { 2811 return NewAppError( 2812 "Config.IsValid", 2813 "model.config.is_valid.display.custom_url_schemes.app_error", 2814 map[string]interface{}{"Scheme": scheme}, 2815 "", 2816 http.StatusBadRequest, 2817 ) 2818 } 2819 } 2820 } 2821 2822 return nil 2823 } 2824 2825 func (ips *ImageProxySettings) isValid() *AppError { 2826 if *ips.Enable { 2827 switch *ips.ImageProxyType { 2828 case IMAGE_PROXY_TYPE_LOCAL: 2829 // No other settings to validate 2830 case IMAGE_PROXY_TYPE_ATMOS_CAMO: 2831 if *ips.RemoteImageProxyURL == "" { 2832 return NewAppError("Config.IsValid", "model.config.is_valid.atmos_camo_image_proxy_url.app_error", nil, "", http.StatusBadRequest) 2833 } 2834 2835 if *ips.RemoteImageProxyOptions == "" { 2836 return NewAppError("Config.IsValid", "model.config.is_valid.atmos_camo_image_proxy_options.app_error", nil, "", http.StatusBadRequest) 2837 } 2838 default: 2839 return NewAppError("Config.IsValid", "model.config.is_valid.image_proxy_type.app_error", nil, "", http.StatusBadRequest) 2840 } 2841 } 2842 2843 return nil 2844 } 2845 2846 func (o *Config) GetSanitizeOptions() map[string]bool { 2847 options := map[string]bool{} 2848 options["fullname"] = *o.PrivacySettings.ShowFullName 2849 options["email"] = *o.PrivacySettings.ShowEmailAddress 2850 2851 return options 2852 } 2853 2854 func (o *Config) Sanitize() { 2855 if o.LdapSettings.BindPassword != nil && len(*o.LdapSettings.BindPassword) > 0 { 2856 *o.LdapSettings.BindPassword = FAKE_SETTING 2857 } 2858 2859 *o.FileSettings.PublicLinkSalt = FAKE_SETTING 2860 if len(*o.FileSettings.AmazonS3SecretAccessKey) > 0 { 2861 *o.FileSettings.AmazonS3SecretAccessKey = FAKE_SETTING 2862 } 2863 2864 if len(*o.GitLabSettings.Secret) > 0 { 2865 *o.GitLabSettings.Secret = FAKE_SETTING 2866 } 2867 2868 *o.SqlSettings.DataSource = FAKE_SETTING 2869 *o.SqlSettings.AtRestEncryptKey = FAKE_SETTING 2870 2871 for i := range o.SqlSettings.DataSourceReplicas { 2872 o.SqlSettings.DataSourceReplicas[i] = FAKE_SETTING 2873 } 2874 2875 for i := range o.SqlSettings.DataSourceSearchReplicas { 2876 o.SqlSettings.DataSourceSearchReplicas[i] = FAKE_SETTING 2877 } 2878 2879 *o.ElasticsearchSettings.Password = FAKE_SETTING 2880 }