github.com/levb/mattermost-server@v5.3.1+incompatible/model/config.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "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 } 658 659 func (s *SqlSettings) SetDefaults() { 660 if s.DriverName == nil { 661 s.DriverName = NewString(DATABASE_DRIVER_MYSQL) 662 } 663 664 if s.DataSource == nil { 665 s.DataSource = NewString(SQL_SETTINGS_DEFAULT_DATA_SOURCE) 666 } 667 668 if len(s.AtRestEncryptKey) == 0 { 669 s.AtRestEncryptKey = NewRandomString(32) 670 } 671 672 if s.MaxIdleConns == nil { 673 s.MaxIdleConns = NewInt(20) 674 } 675 676 if s.MaxOpenConns == nil { 677 s.MaxOpenConns = NewInt(300) 678 } 679 680 if s.ConnMaxLifetimeMilliseconds == nil { 681 s.ConnMaxLifetimeMilliseconds = NewInt(3600000) 682 } 683 684 if s.QueryTimeout == nil { 685 s.QueryTimeout = NewInt(30) 686 } 687 } 688 689 type LogSettings struct { 690 EnableConsole bool 691 ConsoleLevel string 692 ConsoleJson *bool 693 EnableFile bool 694 FileLevel string 695 FileJson *bool 696 FileLocation string 697 EnableWebhookDebugging bool 698 EnableDiagnostics *bool 699 } 700 701 func (s *LogSettings) SetDefaults() { 702 if s.EnableDiagnostics == nil { 703 s.EnableDiagnostics = NewBool(true) 704 } 705 706 if s.ConsoleJson == nil { 707 s.ConsoleJson = NewBool(true) 708 } 709 710 if s.FileJson == nil { 711 s.FileJson = NewBool(true) 712 } 713 } 714 715 type PasswordSettings struct { 716 MinimumLength *int 717 Lowercase *bool 718 Number *bool 719 Uppercase *bool 720 Symbol *bool 721 } 722 723 func (s *PasswordSettings) SetDefaults() { 724 if s.MinimumLength == nil { 725 s.MinimumLength = NewInt(PASSWORD_MINIMUM_LENGTH) 726 } 727 728 if s.Lowercase == nil { 729 s.Lowercase = NewBool(false) 730 } 731 732 if s.Number == nil { 733 s.Number = NewBool(false) 734 } 735 736 if s.Uppercase == nil { 737 s.Uppercase = NewBool(false) 738 } 739 740 if s.Symbol == nil { 741 s.Symbol = NewBool(false) 742 } 743 } 744 745 type FileSettings struct { 746 EnableFileAttachments *bool 747 EnableMobileUpload *bool 748 EnableMobileDownload *bool 749 MaxFileSize *int64 750 DriverName *string 751 Directory string 752 EnablePublicLink bool 753 PublicLinkSalt *string 754 InitialFont string 755 AmazonS3AccessKeyId string 756 AmazonS3SecretAccessKey string 757 AmazonS3Bucket string 758 AmazonS3Region string 759 AmazonS3Endpoint string 760 AmazonS3SSL *bool 761 AmazonS3SignV2 *bool 762 AmazonS3SSE *bool 763 AmazonS3Trace *bool 764 } 765 766 func (s *FileSettings) SetDefaults() { 767 if s.DriverName == nil { 768 s.DriverName = NewString(IMAGE_DRIVER_LOCAL) 769 } 770 771 if s.AmazonS3Endpoint == "" { 772 // Defaults to "s3.amazonaws.com" 773 s.AmazonS3Endpoint = "s3.amazonaws.com" 774 } 775 776 if s.AmazonS3SSL == nil { 777 s.AmazonS3SSL = NewBool(true) // Secure by default. 778 } 779 780 if s.AmazonS3SignV2 == nil { 781 s.AmazonS3SignV2 = new(bool) 782 // Signature v2 is not enabled by default. 783 } 784 785 if s.AmazonS3SSE == nil { 786 s.AmazonS3SSE = NewBool(false) // Not Encrypted by default. 787 } 788 789 if s.AmazonS3Trace == nil { 790 s.AmazonS3Trace = NewBool(false) 791 } 792 793 if s.EnableFileAttachments == nil { 794 s.EnableFileAttachments = NewBool(true) 795 } 796 797 if s.EnableMobileUpload == nil { 798 s.EnableMobileUpload = NewBool(true) 799 } 800 801 if s.EnableMobileDownload == nil { 802 s.EnableMobileDownload = NewBool(true) 803 } 804 805 if s.MaxFileSize == nil { 806 s.MaxFileSize = NewInt64(52428800) // 50 MB 807 } 808 809 if s.PublicLinkSalt == nil || len(*s.PublicLinkSalt) == 0 { 810 s.PublicLinkSalt = NewString(NewRandomString(32)) 811 } 812 813 if s.InitialFont == "" { 814 // Defaults to "nunito-bold.ttf" 815 s.InitialFont = "nunito-bold.ttf" 816 } 817 818 if s.Directory == "" { 819 s.Directory = FILE_SETTINGS_DEFAULT_DIRECTORY 820 } 821 } 822 823 type EmailSettings struct { 824 EnableSignUpWithEmail bool 825 EnableSignInWithEmail *bool 826 EnableSignInWithUsername *bool 827 SendEmailNotifications bool 828 UseChannelInEmailNotifications *bool 829 RequireEmailVerification bool 830 FeedbackName string 831 FeedbackEmail string 832 FeedbackOrganization *string 833 EnableSMTPAuth *bool 834 SMTPUsername string 835 SMTPPassword string 836 SMTPServer string 837 SMTPPort string 838 ConnectionSecurity string 839 InviteSalt string 840 SendPushNotifications *bool 841 PushNotificationServer *string 842 PushNotificationContents *string 843 EnableEmailBatching *bool 844 EmailBatchingBufferSize *int 845 EmailBatchingInterval *int 846 EnablePreviewModeBanner *bool 847 SkipServerCertificateVerification *bool 848 EmailNotificationContentsType *string 849 LoginButtonColor *string 850 LoginButtonBorderColor *string 851 LoginButtonTextColor *string 852 } 853 854 func (s *EmailSettings) SetDefaults() { 855 if len(s.InviteSalt) == 0 { 856 s.InviteSalt = NewRandomString(32) 857 } 858 859 if s.EnableSignInWithEmail == nil { 860 s.EnableSignInWithEmail = NewBool(s.EnableSignUpWithEmail) 861 } 862 863 if s.EnableSignInWithUsername == nil { 864 s.EnableSignInWithUsername = NewBool(false) 865 } 866 867 if s.UseChannelInEmailNotifications == nil { 868 s.UseChannelInEmailNotifications = NewBool(false) 869 } 870 871 if s.SendPushNotifications == nil { 872 s.SendPushNotifications = NewBool(false) 873 } 874 875 if s.PushNotificationServer == nil { 876 s.PushNotificationServer = NewString("") 877 } 878 879 if s.PushNotificationContents == nil { 880 s.PushNotificationContents = NewString(GENERIC_NOTIFICATION) 881 } 882 883 if s.FeedbackOrganization == nil { 884 s.FeedbackOrganization = NewString(EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION) 885 } 886 887 if s.EnableEmailBatching == nil { 888 s.EnableEmailBatching = NewBool(false) 889 } 890 891 if s.EmailBatchingBufferSize == nil { 892 s.EmailBatchingBufferSize = NewInt(EMAIL_BATCHING_BUFFER_SIZE) 893 } 894 895 if s.EmailBatchingInterval == nil { 896 s.EmailBatchingInterval = NewInt(EMAIL_BATCHING_INTERVAL) 897 } 898 899 if s.EnablePreviewModeBanner == nil { 900 s.EnablePreviewModeBanner = NewBool(true) 901 } 902 903 if s.EnableSMTPAuth == nil { 904 s.EnableSMTPAuth = new(bool) 905 if s.ConnectionSecurity == CONN_SECURITY_NONE { 906 *s.EnableSMTPAuth = false 907 } else { 908 *s.EnableSMTPAuth = true 909 } 910 } 911 912 if s.ConnectionSecurity == CONN_SECURITY_PLAIN { 913 s.ConnectionSecurity = CONN_SECURITY_NONE 914 } 915 916 if s.SkipServerCertificateVerification == nil { 917 s.SkipServerCertificateVerification = NewBool(false) 918 } 919 920 if s.EmailNotificationContentsType == nil { 921 s.EmailNotificationContentsType = NewString(EMAIL_NOTIFICATION_CONTENTS_FULL) 922 } 923 924 if s.LoginButtonColor == nil { 925 s.LoginButtonColor = NewString("#0000") 926 } 927 928 if s.LoginButtonBorderColor == nil { 929 s.LoginButtonBorderColor = NewString("#2389D7") 930 } 931 932 if s.LoginButtonTextColor == nil { 933 s.LoginButtonTextColor = NewString("#2389D7") 934 } 935 } 936 937 type ExtensionSettings struct { 938 EnableExperimentalExtensions *bool 939 AllowedExtensionsIDs []string 940 } 941 942 func (s *ExtensionSettings) SetDefaults() { 943 if s.EnableExperimentalExtensions == nil { 944 s.EnableExperimentalExtensions = NewBool(false) 945 } 946 947 if s.AllowedExtensionsIDs == nil { 948 s.AllowedExtensionsIDs = []string{} 949 } 950 } 951 952 type RateLimitSettings struct { 953 Enable *bool 954 PerSec *int 955 MaxBurst *int 956 MemoryStoreSize *int 957 VaryByRemoteAddr *bool 958 VaryByUser *bool 959 VaryByHeader string 960 } 961 962 func (s *RateLimitSettings) SetDefaults() { 963 if s.Enable == nil { 964 s.Enable = NewBool(false) 965 } 966 967 if s.PerSec == nil { 968 s.PerSec = NewInt(10) 969 } 970 971 if s.MaxBurst == nil { 972 s.MaxBurst = NewInt(100) 973 } 974 975 if s.MemoryStoreSize == nil { 976 s.MemoryStoreSize = NewInt(10000) 977 } 978 979 if s.VaryByRemoteAddr == nil { 980 s.VaryByRemoteAddr = NewBool(true) 981 } 982 983 if s.VaryByUser == nil { 984 s.VaryByUser = NewBool(false) 985 } 986 } 987 988 type PrivacySettings struct { 989 ShowEmailAddress bool 990 ShowFullName bool 991 } 992 993 type SupportSettings struct { 994 TermsOfServiceLink *string 995 PrivacyPolicyLink *string 996 AboutLink *string 997 HelpLink *string 998 ReportAProblemLink *string 999 SupportEmail *string 1000 } 1001 1002 func (s *SupportSettings) SetDefaults() { 1003 if !IsSafeLink(s.TermsOfServiceLink) { 1004 *s.TermsOfServiceLink = SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK 1005 } 1006 1007 if s.TermsOfServiceLink == nil { 1008 s.TermsOfServiceLink = NewString(SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK) 1009 } 1010 1011 if !IsSafeLink(s.PrivacyPolicyLink) { 1012 *s.PrivacyPolicyLink = "" 1013 } 1014 1015 if s.PrivacyPolicyLink == nil { 1016 s.PrivacyPolicyLink = NewString(SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK) 1017 } 1018 1019 if !IsSafeLink(s.AboutLink) { 1020 *s.AboutLink = "" 1021 } 1022 1023 if s.AboutLink == nil { 1024 s.AboutLink = NewString(SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK) 1025 } 1026 1027 if !IsSafeLink(s.HelpLink) { 1028 *s.HelpLink = "" 1029 } 1030 1031 if s.HelpLink == nil { 1032 s.HelpLink = NewString(SUPPORT_SETTINGS_DEFAULT_HELP_LINK) 1033 } 1034 1035 if !IsSafeLink(s.ReportAProblemLink) { 1036 *s.ReportAProblemLink = "" 1037 } 1038 1039 if s.ReportAProblemLink == nil { 1040 s.ReportAProblemLink = NewString(SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK) 1041 } 1042 1043 if s.SupportEmail == nil { 1044 s.SupportEmail = NewString(SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL) 1045 } 1046 } 1047 1048 type AnnouncementSettings struct { 1049 EnableBanner *bool 1050 BannerText *string 1051 BannerColor *string 1052 BannerTextColor *string 1053 AllowBannerDismissal *bool 1054 } 1055 1056 func (s *AnnouncementSettings) SetDefaults() { 1057 if s.EnableBanner == nil { 1058 s.EnableBanner = NewBool(false) 1059 } 1060 1061 if s.BannerText == nil { 1062 s.BannerText = NewString("") 1063 } 1064 1065 if s.BannerColor == nil { 1066 s.BannerColor = NewString(ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR) 1067 } 1068 1069 if s.BannerTextColor == nil { 1070 s.BannerTextColor = NewString(ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR) 1071 } 1072 1073 if s.AllowBannerDismissal == nil { 1074 s.AllowBannerDismissal = NewBool(true) 1075 } 1076 } 1077 1078 type ThemeSettings struct { 1079 EnableThemeSelection *bool 1080 DefaultTheme *string 1081 AllowCustomThemes *bool 1082 AllowedThemes []string 1083 } 1084 1085 func (s *ThemeSettings) SetDefaults() { 1086 if s.EnableThemeSelection == nil { 1087 s.EnableThemeSelection = NewBool(true) 1088 } 1089 1090 if s.DefaultTheme == nil { 1091 s.DefaultTheme = NewString(TEAM_SETTINGS_DEFAULT_TEAM_TEXT) 1092 } 1093 1094 if s.AllowCustomThemes == nil { 1095 s.AllowCustomThemes = NewBool(true) 1096 } 1097 1098 if s.AllowedThemes == nil { 1099 s.AllowedThemes = []string{} 1100 } 1101 } 1102 1103 type TeamSettings struct { 1104 SiteName string 1105 MaxUsersPerTeam *int 1106 EnableTeamCreation *bool 1107 EnableUserCreation *bool 1108 EnableOpenServer *bool 1109 EnableUserDeactivation *bool 1110 RestrictCreationToDomains string 1111 EnableCustomBrand *bool 1112 CustomBrandText *string 1113 CustomDescriptionText *string 1114 RestrictDirectMessage *string 1115 RestrictTeamInvite *string 1116 RestrictPublicChannelManagement *string 1117 RestrictPrivateChannelManagement *string 1118 RestrictPublicChannelCreation *string 1119 RestrictPrivateChannelCreation *string 1120 RestrictPublicChannelDeletion *string 1121 RestrictPrivateChannelDeletion *string 1122 RestrictPrivateChannelManageMembers *string 1123 EnableXToLeaveChannelsFromLHS *bool 1124 UserStatusAwayTimeout *int64 1125 MaxChannelsPerTeam *int64 1126 MaxNotificationsPerChannel *int64 1127 EnableConfirmNotificationsToChannel *bool 1128 TeammateNameDisplay *string 1129 ExperimentalViewArchivedChannels *bool 1130 ExperimentalEnableAutomaticReplies *bool 1131 ExperimentalHideTownSquareinLHS *bool 1132 ExperimentalTownSquareIsReadOnly *bool 1133 ExperimentalPrimaryTeam *string 1134 ExperimentalDefaultChannels []string 1135 } 1136 1137 func (s *TeamSettings) SetDefaults() { 1138 if s.MaxUsersPerTeam == nil { 1139 s.MaxUsersPerTeam = NewInt(TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM) 1140 } 1141 1142 if s.EnableCustomBrand == nil { 1143 s.EnableCustomBrand = NewBool(false) 1144 } 1145 1146 if s.EnableUserDeactivation == nil { 1147 s.EnableUserDeactivation = NewBool(false) 1148 } 1149 1150 if s.CustomBrandText == nil { 1151 s.CustomBrandText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT) 1152 } 1153 1154 if s.CustomDescriptionText == nil { 1155 s.CustomDescriptionText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT) 1156 } 1157 1158 if s.EnableOpenServer == nil { 1159 s.EnableOpenServer = NewBool(false) 1160 } 1161 1162 if s.RestrictDirectMessage == nil { 1163 s.RestrictDirectMessage = NewString(DIRECT_MESSAGE_ANY) 1164 } 1165 1166 if s.RestrictTeamInvite == nil { 1167 s.RestrictTeamInvite = NewString(PERMISSIONS_ALL) 1168 } 1169 1170 if s.RestrictPublicChannelManagement == nil { 1171 s.RestrictPublicChannelManagement = NewString(PERMISSIONS_ALL) 1172 } 1173 1174 if s.RestrictPrivateChannelManagement == nil { 1175 s.RestrictPrivateChannelManagement = NewString(PERMISSIONS_ALL) 1176 } 1177 1178 if s.RestrictPublicChannelCreation == nil { 1179 s.RestrictPublicChannelCreation = new(string) 1180 // If this setting does not exist, assume migration from <3.6, so use management setting as default. 1181 if *s.RestrictPublicChannelManagement == PERMISSIONS_CHANNEL_ADMIN { 1182 *s.RestrictPublicChannelCreation = PERMISSIONS_TEAM_ADMIN 1183 } else { 1184 *s.RestrictPublicChannelCreation = *s.RestrictPublicChannelManagement 1185 } 1186 } 1187 1188 if s.RestrictPrivateChannelCreation == nil { 1189 // If this setting does not exist, assume migration from <3.6, so use management setting as default. 1190 if *s.RestrictPrivateChannelManagement == PERMISSIONS_CHANNEL_ADMIN { 1191 s.RestrictPrivateChannelCreation = NewString(PERMISSIONS_TEAM_ADMIN) 1192 } else { 1193 s.RestrictPrivateChannelCreation = NewString(*s.RestrictPrivateChannelManagement) 1194 } 1195 } 1196 1197 if s.RestrictPublicChannelDeletion == nil { 1198 // If this setting does not exist, assume migration from <3.6, so use management setting as default. 1199 s.RestrictPublicChannelDeletion = NewString(*s.RestrictPublicChannelManagement) 1200 } 1201 1202 if s.RestrictPrivateChannelDeletion == nil { 1203 // If this setting does not exist, assume migration from <3.6, so use management setting as default. 1204 s.RestrictPrivateChannelDeletion = NewString(*s.RestrictPrivateChannelManagement) 1205 } 1206 1207 if s.RestrictPrivateChannelManageMembers == nil { 1208 s.RestrictPrivateChannelManageMembers = NewString(PERMISSIONS_ALL) 1209 } 1210 1211 if s.EnableXToLeaveChannelsFromLHS == nil { 1212 s.EnableXToLeaveChannelsFromLHS = NewBool(false) 1213 } 1214 1215 if s.UserStatusAwayTimeout == nil { 1216 s.UserStatusAwayTimeout = NewInt64(TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT) 1217 } 1218 1219 if s.MaxChannelsPerTeam == nil { 1220 s.MaxChannelsPerTeam = NewInt64(2000) 1221 } 1222 1223 if s.MaxNotificationsPerChannel == nil { 1224 s.MaxNotificationsPerChannel = NewInt64(1000) 1225 } 1226 1227 if s.EnableConfirmNotificationsToChannel == nil { 1228 s.EnableConfirmNotificationsToChannel = NewBool(true) 1229 } 1230 1231 if s.ExperimentalEnableAutomaticReplies == nil { 1232 s.ExperimentalEnableAutomaticReplies = NewBool(false) 1233 } 1234 1235 if s.ExperimentalHideTownSquareinLHS == nil { 1236 s.ExperimentalHideTownSquareinLHS = NewBool(false) 1237 } 1238 1239 if s.ExperimentalTownSquareIsReadOnly == nil { 1240 s.ExperimentalTownSquareIsReadOnly = NewBool(false) 1241 } 1242 1243 if s.ExperimentalPrimaryTeam == nil { 1244 s.ExperimentalPrimaryTeam = NewString("") 1245 } 1246 1247 if s.ExperimentalDefaultChannels == nil { 1248 s.ExperimentalDefaultChannels = []string{} 1249 } 1250 1251 if s.EnableTeamCreation == nil { 1252 s.EnableTeamCreation = NewBool(true) 1253 } 1254 1255 if s.EnableUserCreation == nil { 1256 s.EnableUserCreation = NewBool(true) 1257 } 1258 1259 if s.ExperimentalViewArchivedChannels == nil { 1260 s.ExperimentalViewArchivedChannels = NewBool(false) 1261 } 1262 } 1263 1264 type ClientRequirements struct { 1265 AndroidLatestVersion string 1266 AndroidMinVersion string 1267 DesktopLatestVersion string 1268 DesktopMinVersion string 1269 IosLatestVersion string 1270 IosMinVersion string 1271 } 1272 1273 type LdapSettings struct { 1274 // Basic 1275 Enable *bool 1276 EnableSync *bool 1277 LdapServer *string 1278 LdapPort *int 1279 ConnectionSecurity *string 1280 BaseDN *string 1281 BindUsername *string 1282 BindPassword *string 1283 1284 // Filtering 1285 UserFilter *string 1286 1287 // User Mapping 1288 FirstNameAttribute *string 1289 LastNameAttribute *string 1290 EmailAttribute *string 1291 UsernameAttribute *string 1292 NicknameAttribute *string 1293 IdAttribute *string 1294 PositionAttribute *string 1295 LoginIdAttribute *string 1296 1297 // Synchronization 1298 SyncIntervalMinutes *int 1299 1300 // Advanced 1301 SkipCertificateVerification *bool 1302 QueryTimeout *int 1303 MaxPageSize *int 1304 1305 // Customization 1306 LoginFieldName *string 1307 1308 LoginButtonColor *string 1309 LoginButtonBorderColor *string 1310 LoginButtonTextColor *string 1311 } 1312 1313 func (s *LdapSettings) SetDefaults() { 1314 if s.Enable == nil { 1315 s.Enable = NewBool(false) 1316 } 1317 1318 // When unset should default to LDAP Enabled 1319 if s.EnableSync == nil { 1320 s.EnableSync = NewBool(*s.Enable) 1321 } 1322 1323 if s.LdapServer == nil { 1324 s.LdapServer = NewString("") 1325 } 1326 1327 if s.LdapPort == nil { 1328 s.LdapPort = NewInt(389) 1329 } 1330 1331 if s.ConnectionSecurity == nil { 1332 s.ConnectionSecurity = NewString("") 1333 } 1334 1335 if s.BaseDN == nil { 1336 s.BaseDN = NewString("") 1337 } 1338 1339 if s.BindUsername == nil { 1340 s.BindUsername = NewString("") 1341 } 1342 1343 if s.BindPassword == nil { 1344 s.BindPassword = NewString("") 1345 } 1346 1347 if s.UserFilter == nil { 1348 s.UserFilter = NewString("") 1349 } 1350 1351 if s.FirstNameAttribute == nil { 1352 s.FirstNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE) 1353 } 1354 1355 if s.LastNameAttribute == nil { 1356 s.LastNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE) 1357 } 1358 1359 if s.EmailAttribute == nil { 1360 s.EmailAttribute = NewString(LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE) 1361 } 1362 1363 if s.UsernameAttribute == nil { 1364 s.UsernameAttribute = NewString(LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE) 1365 } 1366 1367 if s.NicknameAttribute == nil { 1368 s.NicknameAttribute = NewString(LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE) 1369 } 1370 1371 if s.IdAttribute == nil { 1372 s.IdAttribute = NewString(LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE) 1373 } 1374 1375 if s.PositionAttribute == nil { 1376 s.PositionAttribute = NewString(LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE) 1377 } 1378 1379 // For those upgrading to the version when LoginIdAttribute was added 1380 // they need IdAttribute == LoginIdAttribute not to break 1381 if s.LoginIdAttribute == nil { 1382 s.LoginIdAttribute = s.IdAttribute 1383 } 1384 1385 if s.SyncIntervalMinutes == nil { 1386 s.SyncIntervalMinutes = NewInt(60) 1387 } 1388 1389 if s.SkipCertificateVerification == nil { 1390 s.SkipCertificateVerification = NewBool(false) 1391 } 1392 1393 if s.QueryTimeout == nil { 1394 s.QueryTimeout = NewInt(60) 1395 } 1396 1397 if s.MaxPageSize == nil { 1398 s.MaxPageSize = NewInt(0) 1399 } 1400 1401 if s.LoginFieldName == nil { 1402 s.LoginFieldName = NewString(LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME) 1403 } 1404 1405 if s.LoginButtonColor == nil { 1406 s.LoginButtonColor = NewString("#0000") 1407 } 1408 1409 if s.LoginButtonBorderColor == nil { 1410 s.LoginButtonBorderColor = NewString("#2389D7") 1411 } 1412 1413 if s.LoginButtonTextColor == nil { 1414 s.LoginButtonTextColor = NewString("#2389D7") 1415 } 1416 } 1417 1418 type ComplianceSettings struct { 1419 Enable *bool 1420 Directory *string 1421 EnableDaily *bool 1422 } 1423 1424 func (s *ComplianceSettings) SetDefaults() { 1425 if s.Enable == nil { 1426 s.Enable = NewBool(false) 1427 } 1428 1429 if s.Directory == nil { 1430 s.Directory = NewString("./data/") 1431 } 1432 1433 if s.EnableDaily == nil { 1434 s.EnableDaily = NewBool(false) 1435 } 1436 } 1437 1438 type LocalizationSettings struct { 1439 DefaultServerLocale *string 1440 DefaultClientLocale *string 1441 AvailableLocales *string 1442 } 1443 1444 func (s *LocalizationSettings) SetDefaults() { 1445 if s.DefaultServerLocale == nil { 1446 s.DefaultServerLocale = NewString(DEFAULT_LOCALE) 1447 } 1448 1449 if s.DefaultClientLocale == nil { 1450 s.DefaultClientLocale = NewString(DEFAULT_LOCALE) 1451 } 1452 1453 if s.AvailableLocales == nil { 1454 s.AvailableLocales = NewString("") 1455 } 1456 } 1457 1458 type SamlSettings struct { 1459 // Basic 1460 Enable *bool 1461 EnableSyncWithLdap *bool 1462 EnableSyncWithLdapIncludeAuth *bool 1463 1464 Verify *bool 1465 Encrypt *bool 1466 1467 IdpUrl *string 1468 IdpDescriptorUrl *string 1469 AssertionConsumerServiceURL *string 1470 1471 ScopingIDPProviderId *string 1472 ScopingIDPName *string 1473 1474 IdpCertificateFile *string 1475 PublicCertificateFile *string 1476 PrivateKeyFile *string 1477 1478 // User Mapping 1479 IdAttribute *string 1480 FirstNameAttribute *string 1481 LastNameAttribute *string 1482 EmailAttribute *string 1483 UsernameAttribute *string 1484 NicknameAttribute *string 1485 LocaleAttribute *string 1486 PositionAttribute *string 1487 1488 LoginButtonText *string 1489 1490 LoginButtonColor *string 1491 LoginButtonBorderColor *string 1492 LoginButtonTextColor *string 1493 } 1494 1495 func (s *SamlSettings) SetDefaults() { 1496 if s.Enable == nil { 1497 s.Enable = NewBool(false) 1498 } 1499 1500 if s.EnableSyncWithLdap == nil { 1501 s.EnableSyncWithLdap = NewBool(false) 1502 } 1503 1504 if s.EnableSyncWithLdapIncludeAuth == nil { 1505 s.EnableSyncWithLdapIncludeAuth = NewBool(false) 1506 } 1507 1508 if s.Verify == nil { 1509 s.Verify = NewBool(true) 1510 } 1511 1512 if s.Encrypt == nil { 1513 s.Encrypt = NewBool(true) 1514 } 1515 1516 if s.IdpUrl == nil { 1517 s.IdpUrl = NewString("") 1518 } 1519 1520 if s.IdpDescriptorUrl == nil { 1521 s.IdpDescriptorUrl = NewString("") 1522 } 1523 1524 if s.IdpCertificateFile == nil { 1525 s.IdpCertificateFile = NewString("") 1526 } 1527 1528 if s.PublicCertificateFile == nil { 1529 s.PublicCertificateFile = NewString("") 1530 } 1531 1532 if s.PrivateKeyFile == nil { 1533 s.PrivateKeyFile = NewString("") 1534 } 1535 1536 if s.AssertionConsumerServiceURL == nil { 1537 s.AssertionConsumerServiceURL = NewString("") 1538 } 1539 1540 if s.ScopingIDPProviderId == nil { 1541 s.ScopingIDPProviderId = NewString("") 1542 } 1543 1544 if s.ScopingIDPName == nil { 1545 s.ScopingIDPName = NewString("") 1546 } 1547 1548 if s.LoginButtonText == nil || *s.LoginButtonText == "" { 1549 s.LoginButtonText = NewString(USER_AUTH_SERVICE_SAML_TEXT) 1550 } 1551 1552 if s.IdAttribute == nil { 1553 s.IdAttribute = NewString(SAML_SETTINGS_DEFAULT_ID_ATTRIBUTE) 1554 } 1555 1556 if s.FirstNameAttribute == nil { 1557 s.FirstNameAttribute = NewString(SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE) 1558 } 1559 1560 if s.LastNameAttribute == nil { 1561 s.LastNameAttribute = NewString(SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE) 1562 } 1563 1564 if s.EmailAttribute == nil { 1565 s.EmailAttribute = NewString(SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE) 1566 } 1567 1568 if s.UsernameAttribute == nil { 1569 s.UsernameAttribute = NewString(SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE) 1570 } 1571 1572 if s.NicknameAttribute == nil { 1573 s.NicknameAttribute = NewString(SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE) 1574 } 1575 1576 if s.PositionAttribute == nil { 1577 s.PositionAttribute = NewString(SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE) 1578 } 1579 1580 if s.LocaleAttribute == nil { 1581 s.LocaleAttribute = NewString(SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE) 1582 } 1583 1584 if s.LoginButtonColor == nil { 1585 s.LoginButtonColor = NewString("#34a28b") 1586 } 1587 1588 if s.LoginButtonBorderColor == nil { 1589 s.LoginButtonBorderColor = NewString("#2389D7") 1590 } 1591 1592 if s.LoginButtonTextColor == nil { 1593 s.LoginButtonTextColor = NewString("#ffffff") 1594 } 1595 } 1596 1597 type NativeAppSettings struct { 1598 AppDownloadLink *string 1599 AndroidAppDownloadLink *string 1600 IosAppDownloadLink *string 1601 } 1602 1603 func (s *NativeAppSettings) SetDefaults() { 1604 if s.AppDownloadLink == nil { 1605 s.AppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK) 1606 } 1607 1608 if s.AndroidAppDownloadLink == nil { 1609 s.AndroidAppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK) 1610 } 1611 1612 if s.IosAppDownloadLink == nil { 1613 s.IosAppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK) 1614 } 1615 } 1616 1617 type WebrtcSettings struct { 1618 Enable *bool 1619 GatewayWebsocketUrl *string 1620 GatewayAdminUrl *string 1621 GatewayAdminSecret *string 1622 StunURI *string 1623 TurnURI *string 1624 TurnUsername *string 1625 TurnSharedKey *string 1626 } 1627 1628 func (s *WebrtcSettings) SetDefaults() { 1629 if s.Enable == nil { 1630 s.Enable = NewBool(false) 1631 } 1632 1633 if s.GatewayWebsocketUrl == nil { 1634 s.GatewayWebsocketUrl = NewString("") 1635 } 1636 1637 if s.GatewayAdminUrl == nil { 1638 s.GatewayAdminUrl = NewString("") 1639 } 1640 1641 if s.GatewayAdminSecret == nil { 1642 s.GatewayAdminSecret = NewString("") 1643 } 1644 1645 if s.StunURI == nil { 1646 s.StunURI = NewString(WEBRTC_SETTINGS_DEFAULT_STUN_URI) 1647 } 1648 1649 if s.TurnURI == nil { 1650 s.TurnURI = NewString(WEBRTC_SETTINGS_DEFAULT_TURN_URI) 1651 } 1652 1653 if s.TurnUsername == nil { 1654 s.TurnUsername = NewString("") 1655 } 1656 1657 if s.TurnSharedKey == nil { 1658 s.TurnSharedKey = NewString("") 1659 } 1660 } 1661 1662 type ElasticsearchSettings struct { 1663 ConnectionUrl *string 1664 Username *string 1665 Password *string 1666 EnableIndexing *bool 1667 EnableSearching *bool 1668 Sniff *bool 1669 PostIndexReplicas *int 1670 PostIndexShards *int 1671 AggregatePostsAfterDays *int 1672 PostsAggregatorJobStartTime *string 1673 IndexPrefix *string 1674 LiveIndexingBatchSize *int 1675 BulkIndexingTimeWindowSeconds *int 1676 RequestTimeoutSeconds *int 1677 } 1678 1679 func (s *ElasticsearchSettings) SetDefaults() { 1680 if s.ConnectionUrl == nil { 1681 s.ConnectionUrl = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL) 1682 } 1683 1684 if s.Username == nil { 1685 s.Username = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME) 1686 } 1687 1688 if s.Password == nil { 1689 s.Password = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD) 1690 } 1691 1692 if s.EnableIndexing == nil { 1693 s.EnableIndexing = NewBool(false) 1694 } 1695 1696 if s.EnableSearching == nil { 1697 s.EnableSearching = NewBool(false) 1698 } 1699 1700 if s.Sniff == nil { 1701 s.Sniff = NewBool(true) 1702 } 1703 1704 if s.PostIndexReplicas == nil { 1705 s.PostIndexReplicas = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS) 1706 } 1707 1708 if s.PostIndexShards == nil { 1709 s.PostIndexShards = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS) 1710 } 1711 1712 if s.AggregatePostsAfterDays == nil { 1713 s.AggregatePostsAfterDays = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS) 1714 } 1715 1716 if s.PostsAggregatorJobStartTime == nil { 1717 s.PostsAggregatorJobStartTime = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_POSTS_AGGREGATOR_JOB_START_TIME) 1718 } 1719 1720 if s.IndexPrefix == nil { 1721 s.IndexPrefix = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX) 1722 } 1723 1724 if s.LiveIndexingBatchSize == nil { 1725 s.LiveIndexingBatchSize = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_LIVE_INDEXING_BATCH_SIZE) 1726 } 1727 1728 if s.BulkIndexingTimeWindowSeconds == nil { 1729 s.BulkIndexingTimeWindowSeconds = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_BULK_INDEXING_TIME_WINDOW_SECONDS) 1730 } 1731 1732 if s.RequestTimeoutSeconds == nil { 1733 s.RequestTimeoutSeconds = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_REQUEST_TIMEOUT_SECONDS) 1734 } 1735 } 1736 1737 type DataRetentionSettings struct { 1738 EnableMessageDeletion *bool 1739 EnableFileDeletion *bool 1740 MessageRetentionDays *int 1741 FileRetentionDays *int 1742 DeletionJobStartTime *string 1743 } 1744 1745 func (s *DataRetentionSettings) SetDefaults() { 1746 if s.EnableMessageDeletion == nil { 1747 s.EnableMessageDeletion = NewBool(false) 1748 } 1749 1750 if s.EnableFileDeletion == nil { 1751 s.EnableFileDeletion = NewBool(false) 1752 } 1753 1754 if s.MessageRetentionDays == nil { 1755 s.MessageRetentionDays = NewInt(DATA_RETENTION_SETTINGS_DEFAULT_MESSAGE_RETENTION_DAYS) 1756 } 1757 1758 if s.FileRetentionDays == nil { 1759 s.FileRetentionDays = NewInt(DATA_RETENTION_SETTINGS_DEFAULT_FILE_RETENTION_DAYS) 1760 } 1761 1762 if s.DeletionJobStartTime == nil { 1763 s.DeletionJobStartTime = NewString(DATA_RETENTION_SETTINGS_DEFAULT_DELETION_JOB_START_TIME) 1764 } 1765 } 1766 1767 type JobSettings struct { 1768 RunJobs *bool 1769 RunScheduler *bool 1770 } 1771 1772 func (s *JobSettings) SetDefaults() { 1773 if s.RunJobs == nil { 1774 s.RunJobs = NewBool(true) 1775 } 1776 1777 if s.RunScheduler == nil { 1778 s.RunScheduler = NewBool(true) 1779 } 1780 } 1781 1782 type PluginState struct { 1783 Enable bool 1784 } 1785 1786 type PluginSettings struct { 1787 Enable *bool 1788 EnableUploads *bool 1789 Directory *string 1790 ClientDirectory *string 1791 Plugins map[string]map[string]interface{} 1792 PluginStates map[string]*PluginState 1793 } 1794 1795 func (s *PluginSettings) SetDefaults() { 1796 if s.Enable == nil { 1797 s.Enable = NewBool(true) 1798 } 1799 1800 if s.EnableUploads == nil { 1801 s.EnableUploads = NewBool(false) 1802 } 1803 1804 if s.Directory == nil { 1805 s.Directory = NewString(PLUGIN_SETTINGS_DEFAULT_DIRECTORY) 1806 } 1807 1808 if *s.Directory == "" { 1809 *s.Directory = PLUGIN_SETTINGS_DEFAULT_DIRECTORY 1810 } 1811 1812 if s.ClientDirectory == nil { 1813 s.ClientDirectory = NewString(PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY) 1814 } 1815 1816 if *s.ClientDirectory == "" { 1817 *s.ClientDirectory = PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY 1818 } 1819 1820 if s.Plugins == nil { 1821 s.Plugins = make(map[string]map[string]interface{}) 1822 } 1823 1824 if s.PluginStates == nil { 1825 s.PluginStates = make(map[string]*PluginState) 1826 } 1827 } 1828 1829 type GlobalRelayMessageExportSettings struct { 1830 CustomerType *string // must be either A9 or A10, dictates SMTP server url 1831 SmtpUsername *string 1832 SmtpPassword *string 1833 EmailAddress *string // the address to send messages to 1834 } 1835 1836 func (s *GlobalRelayMessageExportSettings) SetDefaults() { 1837 if s.CustomerType == nil { 1838 s.CustomerType = NewString(GLOBALRELAY_CUSTOMER_TYPE_A9) 1839 } 1840 if s.SmtpUsername == nil { 1841 s.SmtpUsername = NewString("") 1842 } 1843 if s.SmtpPassword == nil { 1844 s.SmtpPassword = NewString("") 1845 } 1846 if s.EmailAddress == nil { 1847 s.EmailAddress = NewString("") 1848 } 1849 } 1850 1851 type MessageExportSettings struct { 1852 EnableExport *bool 1853 ExportFormat *string 1854 DailyRunTime *string 1855 ExportFromTimestamp *int64 1856 BatchSize *int 1857 1858 // formatter-specific settings - these are only expected to be non-nil if ExportFormat is set to the associated format 1859 GlobalRelaySettings *GlobalRelayMessageExportSettings 1860 } 1861 1862 func (s *MessageExportSettings) SetDefaults() { 1863 if s.EnableExport == nil { 1864 s.EnableExport = NewBool(false) 1865 } 1866 1867 if s.ExportFormat == nil { 1868 s.ExportFormat = NewString(COMPLIANCE_EXPORT_TYPE_ACTIANCE) 1869 } 1870 1871 if s.DailyRunTime == nil { 1872 s.DailyRunTime = NewString("01:00") 1873 } 1874 1875 if s.ExportFromTimestamp == nil { 1876 s.ExportFromTimestamp = NewInt64(0) 1877 } 1878 1879 if s.EnableExport != nil && *s.EnableExport && *s.ExportFromTimestamp == int64(0) { 1880 // when the feature is enabled via the System Console, use the current timestamp as the start time for future exports 1881 s.ExportFromTimestamp = NewInt64(GetMillis()) 1882 } else if s.EnableExport != nil && !*s.EnableExport { 1883 // when the feature is disabled, reset the timestamp so that the timestamp will be set if the feature is re-enabled 1884 s.ExportFromTimestamp = NewInt64(0) 1885 } 1886 1887 if s.BatchSize == nil { 1888 s.BatchSize = NewInt(10000) 1889 } 1890 1891 if s.GlobalRelaySettings == nil { 1892 s.GlobalRelaySettings = &GlobalRelayMessageExportSettings{} 1893 } 1894 s.GlobalRelaySettings.SetDefaults() 1895 } 1896 1897 type DisplaySettings struct { 1898 CustomUrlSchemes *[]string 1899 ExperimentalTimezone *bool 1900 } 1901 1902 func (s *DisplaySettings) SetDefaults() { 1903 if s.CustomUrlSchemes == nil { 1904 customUrlSchemes := []string{} 1905 s.CustomUrlSchemes = &customUrlSchemes 1906 } 1907 1908 if s.ExperimentalTimezone == nil { 1909 s.ExperimentalTimezone = NewBool(false) 1910 } 1911 } 1912 1913 type TimezoneSettings struct { 1914 SupportedTimezonesPath *string 1915 } 1916 1917 func (s *TimezoneSettings) SetDefaults() { 1918 if s.SupportedTimezonesPath == nil { 1919 s.SupportedTimezonesPath = NewString(TIMEZONE_SETTINGS_DEFAULT_SUPPORTED_TIMEZONES_PATH) 1920 } 1921 } 1922 1923 type ConfigFunc func() *Config 1924 1925 type Config struct { 1926 ServiceSettings ServiceSettings 1927 TeamSettings TeamSettings 1928 ClientRequirements ClientRequirements 1929 SqlSettings SqlSettings 1930 LogSettings LogSettings 1931 PasswordSettings PasswordSettings 1932 FileSettings FileSettings 1933 EmailSettings EmailSettings 1934 ExtensionSettings ExtensionSettings 1935 RateLimitSettings RateLimitSettings 1936 PrivacySettings PrivacySettings 1937 SupportSettings SupportSettings 1938 AnnouncementSettings AnnouncementSettings 1939 ThemeSettings ThemeSettings 1940 GitLabSettings SSOSettings 1941 GoogleSettings SSOSettings 1942 Office365Settings SSOSettings 1943 LdapSettings LdapSettings 1944 ComplianceSettings ComplianceSettings 1945 LocalizationSettings LocalizationSettings 1946 SamlSettings SamlSettings 1947 NativeAppSettings NativeAppSettings 1948 ClusterSettings ClusterSettings 1949 MetricsSettings MetricsSettings 1950 ExperimentalSettings ExperimentalSettings 1951 AnalyticsSettings AnalyticsSettings 1952 WebrtcSettings WebrtcSettings 1953 ElasticsearchSettings ElasticsearchSettings 1954 DataRetentionSettings DataRetentionSettings 1955 MessageExportSettings MessageExportSettings 1956 JobSettings JobSettings 1957 PluginSettings PluginSettings 1958 DisplaySettings DisplaySettings 1959 TimezoneSettings TimezoneSettings 1960 } 1961 1962 func (o *Config) Clone() *Config { 1963 var ret Config 1964 if err := json.Unmarshal([]byte(o.ToJson()), &ret); err != nil { 1965 panic(err) 1966 } 1967 return &ret 1968 } 1969 1970 func (o *Config) ToJson() string { 1971 b, _ := json.Marshal(o) 1972 return string(b) 1973 } 1974 1975 func (o *Config) GetSSOService(service string) *SSOSettings { 1976 switch service { 1977 case SERVICE_GITLAB: 1978 return &o.GitLabSettings 1979 case SERVICE_GOOGLE: 1980 return &o.GoogleSettings 1981 case SERVICE_OFFICE365: 1982 return &o.Office365Settings 1983 } 1984 1985 return nil 1986 } 1987 1988 func ConfigFromJson(data io.Reader) *Config { 1989 var o *Config 1990 json.NewDecoder(data).Decode(&o) 1991 return o 1992 } 1993 1994 func (o *Config) SetDefaults() { 1995 o.LdapSettings.SetDefaults() 1996 o.SamlSettings.SetDefaults() 1997 1998 if o.TeamSettings.TeammateNameDisplay == nil { 1999 o.TeamSettings.TeammateNameDisplay = NewString(SHOW_USERNAME) 2000 2001 if *o.SamlSettings.Enable || *o.LdapSettings.Enable { 2002 *o.TeamSettings.TeammateNameDisplay = SHOW_FULLNAME 2003 } 2004 } 2005 2006 o.SqlSettings.SetDefaults() 2007 o.FileSettings.SetDefaults() 2008 o.EmailSettings.SetDefaults() 2009 o.ServiceSettings.SetDefaults() 2010 o.PasswordSettings.SetDefaults() 2011 o.TeamSettings.SetDefaults() 2012 o.MetricsSettings.SetDefaults() 2013 o.ExperimentalSettings.SetDefaults() 2014 o.SupportSettings.SetDefaults() 2015 o.AnnouncementSettings.SetDefaults() 2016 o.ThemeSettings.SetDefaults() 2017 o.ClusterSettings.SetDefaults() 2018 o.PluginSettings.SetDefaults() 2019 o.AnalyticsSettings.SetDefaults() 2020 o.ComplianceSettings.SetDefaults() 2021 o.LocalizationSettings.SetDefaults() 2022 o.ElasticsearchSettings.SetDefaults() 2023 o.NativeAppSettings.SetDefaults() 2024 o.DataRetentionSettings.SetDefaults() 2025 o.RateLimitSettings.SetDefaults() 2026 o.LogSettings.SetDefaults() 2027 o.JobSettings.SetDefaults() 2028 o.WebrtcSettings.SetDefaults() 2029 o.MessageExportSettings.SetDefaults() 2030 o.TimezoneSettings.SetDefaults() 2031 o.DisplaySettings.SetDefaults() 2032 o.ExtensionSettings.SetDefaults() 2033 } 2034 2035 func (o *Config) IsValid() *AppError { 2036 if len(*o.ServiceSettings.SiteURL) == 0 && *o.EmailSettings.EnableEmailBatching { 2037 return NewAppError("Config.IsValid", "model.config.is_valid.site_url_email_batching.app_error", nil, "", http.StatusBadRequest) 2038 } 2039 2040 if *o.ClusterSettings.Enable && *o.EmailSettings.EnableEmailBatching { 2041 return NewAppError("Config.IsValid", "model.config.is_valid.cluster_email_batching.app_error", nil, "", http.StatusBadRequest) 2042 } 2043 2044 if len(*o.ServiceSettings.SiteURL) == 0 && *o.ServiceSettings.AllowCookiesForSubdomains { 2045 return NewAppError("Config.IsValid", "model.config.is_valid.allow_cookies_for_subdomains.app_error", nil, "", http.StatusBadRequest) 2046 } 2047 2048 if err := o.TeamSettings.isValid(); err != nil { 2049 return err 2050 } 2051 2052 if err := o.SqlSettings.isValid(); err != nil { 2053 return err 2054 } 2055 2056 if err := o.FileSettings.isValid(); err != nil { 2057 return err 2058 } 2059 2060 if err := o.EmailSettings.isValid(); err != nil { 2061 return err 2062 } 2063 2064 if err := o.LdapSettings.isValid(); err != nil { 2065 return err 2066 } 2067 2068 if err := o.SamlSettings.isValid(); err != nil { 2069 return err 2070 } 2071 2072 if *o.PasswordSettings.MinimumLength < PASSWORD_MINIMUM_LENGTH || *o.PasswordSettings.MinimumLength > PASSWORD_MAXIMUM_LENGTH { 2073 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) 2074 } 2075 2076 if err := o.RateLimitSettings.isValid(); err != nil { 2077 return err 2078 } 2079 2080 if err := o.WebrtcSettings.isValid(); err != nil { 2081 return err 2082 } 2083 2084 if err := o.ServiceSettings.isValid(); err != nil { 2085 return err 2086 } 2087 2088 if err := o.ElasticsearchSettings.isValid(); err != nil { 2089 return err 2090 } 2091 2092 if err := o.DataRetentionSettings.isValid(); err != nil { 2093 return err 2094 } 2095 2096 if err := o.LocalizationSettings.isValid(); err != nil { 2097 return err 2098 } 2099 2100 if err := o.MessageExportSettings.isValid(o.FileSettings); err != nil { 2101 return err 2102 } 2103 2104 if err := o.DisplaySettings.isValid(); err != nil { 2105 return err 2106 } 2107 2108 return nil 2109 } 2110 2111 func (ts *TeamSettings) isValid() *AppError { 2112 if *ts.MaxUsersPerTeam <= 0 { 2113 return NewAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "", http.StatusBadRequest) 2114 } 2115 2116 if *ts.MaxChannelsPerTeam <= 0 { 2117 return NewAppError("Config.IsValid", "model.config.is_valid.max_channels.app_error", nil, "", http.StatusBadRequest) 2118 } 2119 2120 if *ts.MaxNotificationsPerChannel <= 0 { 2121 return NewAppError("Config.IsValid", "model.config.is_valid.max_notify_per_channel.app_error", nil, "", http.StatusBadRequest) 2122 } 2123 2124 if !(*ts.RestrictDirectMessage == DIRECT_MESSAGE_ANY || *ts.RestrictDirectMessage == DIRECT_MESSAGE_TEAM) { 2125 return NewAppError("Config.IsValid", "model.config.is_valid.restrict_direct_message.app_error", nil, "", http.StatusBadRequest) 2126 } 2127 2128 if !(*ts.TeammateNameDisplay == SHOW_FULLNAME || *ts.TeammateNameDisplay == SHOW_NICKNAME_FULLNAME || *ts.TeammateNameDisplay == SHOW_USERNAME) { 2129 return NewAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "", http.StatusBadRequest) 2130 } 2131 2132 if len(ts.SiteName) > SITENAME_MAX_LENGTH { 2133 return NewAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "", http.StatusBadRequest) 2134 } 2135 2136 return nil 2137 } 2138 2139 func (ss *SqlSettings) isValid() *AppError { 2140 if len(ss.AtRestEncryptKey) < 32 { 2141 return NewAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "", http.StatusBadRequest) 2142 } 2143 2144 if !(*ss.DriverName == DATABASE_DRIVER_MYSQL || *ss.DriverName == DATABASE_DRIVER_POSTGRES) { 2145 return NewAppError("Config.IsValid", "model.config.is_valid.sql_driver.app_error", nil, "", http.StatusBadRequest) 2146 } 2147 2148 if *ss.MaxIdleConns <= 0 { 2149 return NewAppError("Config.IsValid", "model.config.is_valid.sql_idle.app_error", nil, "", http.StatusBadRequest) 2150 } 2151 2152 if *ss.ConnMaxLifetimeMilliseconds < 0 { 2153 return NewAppError("Config.IsValid", "model.config.is_valid.sql_conn_max_lifetime_milliseconds.app_error", nil, "", http.StatusBadRequest) 2154 } 2155 2156 if *ss.QueryTimeout <= 0 { 2157 return NewAppError("Config.IsValid", "model.config.is_valid.sql_query_timeout.app_error", nil, "", http.StatusBadRequest) 2158 } 2159 2160 if len(*ss.DataSource) == 0 { 2161 return NewAppError("Config.IsValid", "model.config.is_valid.sql_data_src.app_error", nil, "", http.StatusBadRequest) 2162 } 2163 2164 if *ss.MaxOpenConns <= 0 { 2165 return NewAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "", http.StatusBadRequest) 2166 } 2167 2168 return nil 2169 } 2170 2171 func (fs *FileSettings) isValid() *AppError { 2172 if *fs.MaxFileSize <= 0 { 2173 return NewAppError("Config.IsValid", "model.config.is_valid.max_file_size.app_error", nil, "", http.StatusBadRequest) 2174 } 2175 2176 if !(*fs.DriverName == IMAGE_DRIVER_LOCAL || *fs.DriverName == IMAGE_DRIVER_S3) { 2177 return NewAppError("Config.IsValid", "model.config.is_valid.file_driver.app_error", nil, "", http.StatusBadRequest) 2178 } 2179 2180 if len(*fs.PublicLinkSalt) < 32 { 2181 return NewAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "", http.StatusBadRequest) 2182 } 2183 2184 return nil 2185 } 2186 2187 func (es *EmailSettings) isValid() *AppError { 2188 if !(es.ConnectionSecurity == CONN_SECURITY_NONE || es.ConnectionSecurity == CONN_SECURITY_TLS || es.ConnectionSecurity == CONN_SECURITY_STARTTLS || es.ConnectionSecurity == CONN_SECURITY_PLAIN) { 2189 return NewAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "", http.StatusBadRequest) 2190 } 2191 2192 if len(es.InviteSalt) < 32 { 2193 return NewAppError("Config.IsValid", "model.config.is_valid.email_salt.app_error", nil, "", http.StatusBadRequest) 2194 } 2195 2196 if *es.EmailBatchingBufferSize <= 0 { 2197 return NewAppError("Config.IsValid", "model.config.is_valid.email_batching_buffer_size.app_error", nil, "", http.StatusBadRequest) 2198 } 2199 2200 if *es.EmailBatchingInterval < 30 { 2201 return NewAppError("Config.IsValid", "model.config.is_valid.email_batching_interval.app_error", nil, "", http.StatusBadRequest) 2202 } 2203 2204 if !(*es.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_FULL || *es.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_GENERIC) { 2205 return NewAppError("Config.IsValid", "model.config.is_valid.email_notification_contents_type.app_error", nil, "", http.StatusBadRequest) 2206 } 2207 2208 return nil 2209 } 2210 2211 func (rls *RateLimitSettings) isValid() *AppError { 2212 if *rls.MemoryStoreSize <= 0 { 2213 return NewAppError("Config.IsValid", "model.config.is_valid.rate_mem.app_error", nil, "", http.StatusBadRequest) 2214 } 2215 2216 if *rls.PerSec <= 0 { 2217 return NewAppError("Config.IsValid", "model.config.is_valid.rate_sec.app_error", nil, "", http.StatusBadRequest) 2218 } 2219 2220 if *rls.MaxBurst <= 0 { 2221 return NewAppError("Config.IsValid", "model.config.is_valid.max_burst.app_error", nil, "", http.StatusBadRequest) 2222 } 2223 2224 return nil 2225 } 2226 2227 func (ls *LdapSettings) isValid() *AppError { 2228 if !(*ls.ConnectionSecurity == CONN_SECURITY_NONE || *ls.ConnectionSecurity == CONN_SECURITY_TLS || *ls.ConnectionSecurity == CONN_SECURITY_STARTTLS) { 2229 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_security.app_error", nil, "", http.StatusBadRequest) 2230 } 2231 2232 if *ls.SyncIntervalMinutes <= 0 { 2233 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_sync_interval.app_error", nil, "", http.StatusBadRequest) 2234 } 2235 2236 if *ls.MaxPageSize < 0 { 2237 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_max_page_size.app_error", nil, "", http.StatusBadRequest) 2238 } 2239 2240 if *ls.Enable { 2241 if *ls.LdapServer == "" { 2242 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_server", nil, "", http.StatusBadRequest) 2243 } 2244 2245 if *ls.BaseDN == "" { 2246 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_basedn", nil, "", http.StatusBadRequest) 2247 } 2248 2249 if *ls.EmailAttribute == "" { 2250 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_email", nil, "", http.StatusBadRequest) 2251 } 2252 2253 if *ls.UsernameAttribute == "" { 2254 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_username", nil, "", http.StatusBadRequest) 2255 } 2256 2257 if *ls.IdAttribute == "" { 2258 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_id", nil, "", http.StatusBadRequest) 2259 } 2260 2261 if *ls.LoginIdAttribute == "" { 2262 return NewAppError("Config.IsValid", "model.config.is_valid.ldap_login_id", nil, "", http.StatusBadRequest) 2263 } 2264 } 2265 2266 return nil 2267 } 2268 2269 func (ss *SamlSettings) isValid() *AppError { 2270 if *ss.Enable { 2271 if len(*ss.IdpUrl) == 0 || !IsValidHttpUrl(*ss.IdpUrl) { 2272 return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_url.app_error", nil, "", http.StatusBadRequest) 2273 } 2274 2275 if len(*ss.IdpDescriptorUrl) == 0 || !IsValidHttpUrl(*ss.IdpDescriptorUrl) { 2276 return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_descriptor_url.app_error", nil, "", http.StatusBadRequest) 2277 } 2278 2279 if len(*ss.IdpCertificateFile) == 0 { 2280 return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_cert.app_error", nil, "", http.StatusBadRequest) 2281 } 2282 2283 if len(*ss.EmailAttribute) == 0 { 2284 return NewAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "", http.StatusBadRequest) 2285 } 2286 2287 if len(*ss.UsernameAttribute) == 0 { 2288 return NewAppError("Config.IsValid", "model.config.is_valid.saml_username_attribute.app_error", nil, "", http.StatusBadRequest) 2289 } 2290 2291 if *ss.Verify { 2292 if len(*ss.AssertionConsumerServiceURL) == 0 || !IsValidHttpUrl(*ss.AssertionConsumerServiceURL) { 2293 return NewAppError("Config.IsValid", "model.config.is_valid.saml_assertion_consumer_service_url.app_error", nil, "", http.StatusBadRequest) 2294 } 2295 } 2296 2297 if *ss.Encrypt { 2298 if len(*ss.PrivateKeyFile) == 0 { 2299 return NewAppError("Config.IsValid", "model.config.is_valid.saml_private_key.app_error", nil, "", http.StatusBadRequest) 2300 } 2301 2302 if len(*ss.PublicCertificateFile) == 0 { 2303 return NewAppError("Config.IsValid", "model.config.is_valid.saml_public_cert.app_error", nil, "", http.StatusBadRequest) 2304 } 2305 } 2306 2307 if len(*ss.EmailAttribute) == 0 { 2308 return NewAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "", http.StatusBadRequest) 2309 } 2310 } 2311 2312 return nil 2313 } 2314 2315 func (ws *WebrtcSettings) isValid() *AppError { 2316 if *ws.Enable { 2317 if len(*ws.GatewayWebsocketUrl) == 0 || !IsValidWebsocketUrl(*ws.GatewayWebsocketUrl) { 2318 return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_ws_url.app_error", nil, "", http.StatusBadRequest) 2319 } else if len(*ws.GatewayAdminUrl) == 0 || !IsValidHttpUrl(*ws.GatewayAdminUrl) { 2320 return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_admin_url.app_error", nil, "", http.StatusBadRequest) 2321 } else if len(*ws.GatewayAdminSecret) == 0 { 2322 return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_admin_secret.app_error", nil, "", http.StatusBadRequest) 2323 } else if len(*ws.StunURI) != 0 && !IsValidTurnOrStunServer(*ws.StunURI) { 2324 return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_stun_uri.app_error", nil, "", http.StatusBadRequest) 2325 } else if len(*ws.TurnURI) != 0 { 2326 if !IsValidTurnOrStunServer(*ws.TurnURI) { 2327 return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_uri.app_error", nil, "", http.StatusBadRequest) 2328 } 2329 if len(*ws.TurnUsername) == 0 { 2330 return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_username.app_error", nil, "", http.StatusBadRequest) 2331 } else if len(*ws.TurnSharedKey) == 0 { 2332 return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_shared_key.app_error", nil, "", http.StatusBadRequest) 2333 } 2334 } 2335 } 2336 2337 return nil 2338 } 2339 2340 func (ss *ServiceSettings) isValid() *AppError { 2341 if !(*ss.ConnectionSecurity == CONN_SECURITY_NONE || *ss.ConnectionSecurity == CONN_SECURITY_TLS) { 2342 return NewAppError("Config.IsValid", "model.config.is_valid.webserver_security.app_error", nil, "", http.StatusBadRequest) 2343 } 2344 2345 if *ss.ReadTimeout <= 0 { 2346 return NewAppError("Config.IsValid", "model.config.is_valid.read_timeout.app_error", nil, "", http.StatusBadRequest) 2347 } 2348 2349 if *ss.WriteTimeout <= 0 { 2350 return NewAppError("Config.IsValid", "model.config.is_valid.write_timeout.app_error", nil, "", http.StatusBadRequest) 2351 } 2352 2353 if *ss.TimeBetweenUserTypingUpdatesMilliseconds < 1000 { 2354 return NewAppError("Config.IsValid", "model.config.is_valid.time_between_user_typing.app_error", nil, "", http.StatusBadRequest) 2355 } 2356 2357 if *ss.MaximumLoginAttempts <= 0 { 2358 return NewAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "", http.StatusBadRequest) 2359 } 2360 2361 if len(*ss.SiteURL) != 0 { 2362 if _, err := url.ParseRequestURI(*ss.SiteURL); err != nil { 2363 return NewAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "", http.StatusBadRequest) 2364 } 2365 } 2366 2367 if len(*ss.WebsocketURL) != 0 { 2368 if _, err := url.ParseRequestURI(*ss.WebsocketURL); err != nil { 2369 return NewAppError("Config.IsValid", "model.config.is_valid.websocket_url.app_error", nil, "", http.StatusBadRequest) 2370 } 2371 } 2372 2373 host, port, err := net.SplitHostPort(*ss.ListenAddress) 2374 var isValidHost bool 2375 if host == "" { 2376 isValidHost = true 2377 } else { 2378 isValidHost = (net.ParseIP(host) != nil) || IsDomainName(host) 2379 } 2380 portInt, err := strconv.Atoi(port) 2381 if err != nil || !isValidHost || portInt < 0 || portInt > math.MaxUint16 { 2382 return NewAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "", http.StatusBadRequest) 2383 } 2384 2385 if *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED && 2386 *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_ON && 2387 *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_OFF { 2388 return NewAppError("Config.IsValid", "model.config.is_valid.group_unread_channels.app_error", nil, "", http.StatusBadRequest) 2389 } 2390 2391 switch *ss.ImageProxyType { 2392 case "": 2393 case "atmos/camo": 2394 if *ss.ImageProxyOptions == "" { 2395 return NewAppError("Config.IsValid", "model.config.is_valid.atmos_camo_image_proxy_options.app_error", nil, "", http.StatusBadRequest) 2396 } 2397 default: 2398 return NewAppError("Config.IsValid", "model.config.is_valid.image_proxy_type.app_error", nil, "", http.StatusBadRequest) 2399 } 2400 2401 return nil 2402 } 2403 2404 func (ess *ElasticsearchSettings) isValid() *AppError { 2405 if *ess.EnableIndexing { 2406 if len(*ess.ConnectionUrl) == 0 { 2407 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.connection_url.app_error", nil, "", http.StatusBadRequest) 2408 } 2409 } 2410 2411 if *ess.EnableSearching && !*ess.EnableIndexing { 2412 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.enable_searching.app_error", nil, "", http.StatusBadRequest) 2413 } 2414 2415 if *ess.AggregatePostsAfterDays < 1 { 2416 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.aggregate_posts_after_days.app_error", nil, "", http.StatusBadRequest) 2417 } 2418 2419 if _, err := time.Parse("15:04", *ess.PostsAggregatorJobStartTime); err != nil { 2420 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.posts_aggregator_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest) 2421 } 2422 2423 if *ess.LiveIndexingBatchSize < 1 { 2424 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.live_indexing_batch_size.app_error", nil, "", http.StatusBadRequest) 2425 } 2426 2427 if *ess.BulkIndexingTimeWindowSeconds < 1 { 2428 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.bulk_indexing_time_window_seconds.app_error", nil, "", http.StatusBadRequest) 2429 } 2430 2431 if *ess.RequestTimeoutSeconds < 1 { 2432 return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.request_timeout_seconds.app_error", nil, "", http.StatusBadRequest) 2433 } 2434 2435 return nil 2436 } 2437 2438 func (drs *DataRetentionSettings) isValid() *AppError { 2439 if *drs.MessageRetentionDays <= 0 { 2440 return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.message_retention_days_too_low.app_error", nil, "", http.StatusBadRequest) 2441 } 2442 2443 if *drs.FileRetentionDays <= 0 { 2444 return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.file_retention_days_too_low.app_error", nil, "", http.StatusBadRequest) 2445 } 2446 2447 if _, err := time.Parse("15:04", *drs.DeletionJobStartTime); err != nil { 2448 return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.deletion_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest) 2449 } 2450 2451 return nil 2452 } 2453 2454 func (ls *LocalizationSettings) isValid() *AppError { 2455 if len(*ls.AvailableLocales) > 0 { 2456 if !strings.Contains(*ls.AvailableLocales, *ls.DefaultClientLocale) { 2457 return NewAppError("Config.IsValid", "model.config.is_valid.localization.available_locales.app_error", nil, "", http.StatusBadRequest) 2458 } 2459 } 2460 2461 return nil 2462 } 2463 2464 func (mes *MessageExportSettings) isValid(fs FileSettings) *AppError { 2465 if mes.EnableExport == nil { 2466 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.enable.app_error", nil, "", http.StatusBadRequest) 2467 } 2468 if *mes.EnableExport { 2469 if mes.ExportFromTimestamp == nil || *mes.ExportFromTimestamp < 0 || *mes.ExportFromTimestamp > GetMillis() { 2470 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.export_from.app_error", nil, "", http.StatusBadRequest) 2471 } else if mes.DailyRunTime == nil { 2472 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, "", http.StatusBadRequest) 2473 } else if _, err := time.Parse("15:04", *mes.DailyRunTime); err != nil { 2474 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, err.Error(), http.StatusBadRequest) 2475 } else if mes.BatchSize == nil || *mes.BatchSize < 0 { 2476 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.batch_size.app_error", nil, "", http.StatusBadRequest) 2477 } else if mes.ExportFormat == nil || (*mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_ACTIANCE && *mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_GLOBALRELAY && *mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_CSV) { 2478 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.export_type.app_error", nil, "", http.StatusBadRequest) 2479 } 2480 2481 if *mes.ExportFormat == COMPLIANCE_EXPORT_TYPE_GLOBALRELAY { 2482 if mes.GlobalRelaySettings == nil { 2483 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.config_missing.app_error", nil, "", http.StatusBadRequest) 2484 } else if mes.GlobalRelaySettings.CustomerType == nil || (*mes.GlobalRelaySettings.CustomerType != GLOBALRELAY_CUSTOMER_TYPE_A9 && *mes.GlobalRelaySettings.CustomerType != GLOBALRELAY_CUSTOMER_TYPE_A10) { 2485 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.customer_type.app_error", nil, "", http.StatusBadRequest) 2486 } else if mes.GlobalRelaySettings.EmailAddress == nil || !strings.Contains(*mes.GlobalRelaySettings.EmailAddress, "@") { 2487 // validating email addresses is hard - just make sure it contains an '@' sign 2488 // see https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address 2489 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.email_address.app_error", nil, "", http.StatusBadRequest) 2490 } else if mes.GlobalRelaySettings.SmtpUsername == nil || *mes.GlobalRelaySettings.SmtpUsername == "" { 2491 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.smtp_username.app_error", nil, "", http.StatusBadRequest) 2492 } else if mes.GlobalRelaySettings.SmtpPassword == nil || *mes.GlobalRelaySettings.SmtpPassword == "" { 2493 return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.smtp_password.app_error", nil, "", http.StatusBadRequest) 2494 } 2495 } 2496 } 2497 return nil 2498 } 2499 2500 func (ds *DisplaySettings) isValid() *AppError { 2501 if len(*ds.CustomUrlSchemes) != 0 { 2502 validProtocolPattern := regexp.MustCompile(`(?i)^\s*[a-z][a-z0-9-]*\s*$`) 2503 2504 for _, scheme := range *ds.CustomUrlSchemes { 2505 if !validProtocolPattern.MatchString(scheme) { 2506 return NewAppError( 2507 "Config.IsValid", 2508 "model.config.is_valid.display.custom_url_schemes.app_error", 2509 map[string]interface{}{"Scheme": scheme}, 2510 "", 2511 http.StatusBadRequest, 2512 ) 2513 } 2514 } 2515 } 2516 2517 return nil 2518 } 2519 2520 func (o *Config) GetSanitizeOptions() map[string]bool { 2521 options := map[string]bool{} 2522 options["fullname"] = o.PrivacySettings.ShowFullName 2523 options["email"] = o.PrivacySettings.ShowEmailAddress 2524 2525 return options 2526 } 2527 2528 func (o *Config) Sanitize() { 2529 if o.LdapSettings.BindPassword != nil && len(*o.LdapSettings.BindPassword) > 0 { 2530 *o.LdapSettings.BindPassword = FAKE_SETTING 2531 } 2532 2533 *o.FileSettings.PublicLinkSalt = FAKE_SETTING 2534 if len(o.FileSettings.AmazonS3SecretAccessKey) > 0 { 2535 o.FileSettings.AmazonS3SecretAccessKey = FAKE_SETTING 2536 } 2537 2538 o.EmailSettings.InviteSalt = FAKE_SETTING 2539 if len(o.EmailSettings.SMTPPassword) > 0 { 2540 o.EmailSettings.SMTPPassword = FAKE_SETTING 2541 } 2542 2543 if len(o.GitLabSettings.Secret) > 0 { 2544 o.GitLabSettings.Secret = FAKE_SETTING 2545 } 2546 2547 *o.SqlSettings.DataSource = FAKE_SETTING 2548 o.SqlSettings.AtRestEncryptKey = FAKE_SETTING 2549 2550 for i := range o.SqlSettings.DataSourceReplicas { 2551 o.SqlSettings.DataSourceReplicas[i] = FAKE_SETTING 2552 } 2553 2554 for i := range o.SqlSettings.DataSourceSearchReplicas { 2555 o.SqlSettings.DataSourceSearchReplicas[i] = FAKE_SETTING 2556 } 2557 2558 *o.ElasticsearchSettings.Password = FAKE_SETTING 2559 }