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