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