From 6d8140337ef0f68f5177988f3c87bba5e4946399 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 18 Jun 2018 12:39:22 -0400 Subject: MM-8701 Limit the number of client config fields sent before user logs in (#8954) * MM-8701 Limit the number of client config fields sent before user logs in * Fixed missing client config field * Reduced duplication between limited and regular client config --- utils/config.go | 194 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 109 insertions(+), 85 deletions(-) (limited to 'utils/config.go') diff --git a/utils/config.go b/utils/config.go index e42c2820b..d3cdbd3ee 100644 --- a/utils/config.go +++ b/utils/config.go @@ -495,22 +495,11 @@ func LoadConfig(fileName string) (*model.Config, string, map[string]interface{}, } func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.License) map[string]string { - props := make(map[string]string) - - props["Version"] = model.CurrentVersion - props["BuildNumber"] = model.BuildNumber - props["BuildDate"] = model.BuildDate - props["BuildHash"] = model.BuildHash - props["BuildHashEnterprise"] = model.BuildHashEnterprise - props["BuildEnterpriseReady"] = model.BuildEnterpriseReady + props := GenerateLimitedClientConfig(c, diagnosticId, license) props["SiteURL"] = strings.TrimRight(*c.ServiceSettings.SiteURL, "/") props["WebsocketURL"] = strings.TrimRight(*c.ServiceSettings.WebsocketURL, "/") - props["SiteName"] = c.TeamSettings.SiteName - props["EnableTeamCreation"] = strconv.FormatBool(*c.TeamSettings.EnableTeamCreation) - props["EnableUserCreation"] = strconv.FormatBool(*c.TeamSettings.EnableUserCreation) props["EnableUserDeactivation"] = strconv.FormatBool(*c.TeamSettings.EnableUserDeactivation) - props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer) props["RestrictDirectMessage"] = *c.TeamSettings.RestrictDirectMessage props["RestrictTeamInvite"] = *c.TeamSettings.RestrictTeamInvite props["RestrictPublicChannelCreation"] = *c.TeamSettings.RestrictPublicChannelCreation @@ -524,13 +513,6 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L props["TeammateNameDisplay"] = *c.TeamSettings.TeammateNameDisplay props["ExperimentalPrimaryTeam"] = *c.TeamSettings.ExperimentalPrimaryTeam - props["AndroidLatestVersion"] = c.ClientRequirements.AndroidLatestVersion - props["AndroidMinVersion"] = c.ClientRequirements.AndroidMinVersion - props["DesktopLatestVersion"] = c.ClientRequirements.DesktopLatestVersion - props["DesktopMinVersion"] = c.ClientRequirements.DesktopMinVersion - props["IosLatestVersion"] = c.ClientRequirements.IosLatestVersion - props["IosMinVersion"] = c.ClientRequirements.IosMinVersion - props["EnableOAuthServiceProvider"] = strconv.FormatBool(c.ServiceSettings.EnableOAuthServiceProvider) props["GoogleDeveloperKey"] = c.ServiceSettings.GoogleDeveloperKey props["EnableIncomingWebhooks"] = strconv.FormatBool(c.ServiceSettings.EnableIncomingWebhooks) @@ -543,7 +525,6 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L props["EnableLinkPreviews"] = strconv.FormatBool(*c.ServiceSettings.EnableLinkPreviews) props["EnableTesting"] = strconv.FormatBool(c.ServiceSettings.EnableTesting) props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper) - props["EnableDiagnostics"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) props["RestrictPostDelete"] = *c.ServiceSettings.RestrictPostDelete props["AllowEditPost"] = *c.ServiceSettings.AllowEditPost props["PostEditTimeLimit"] = fmt.Sprintf("%v", *c.ServiceSettings.PostEditTimeLimit) @@ -557,46 +538,25 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L props["SendEmailNotifications"] = strconv.FormatBool(c.EmailSettings.SendEmailNotifications) props["SendPushNotifications"] = strconv.FormatBool(*c.EmailSettings.SendPushNotifications) - props["EnableSignUpWithEmail"] = strconv.FormatBool(c.EmailSettings.EnableSignUpWithEmail) - props["EnableSignInWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithEmail) - props["EnableSignInWithUsername"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithUsername) props["RequireEmailVerification"] = strconv.FormatBool(c.EmailSettings.RequireEmailVerification) props["EnableEmailBatching"] = strconv.FormatBool(*c.EmailSettings.EnableEmailBatching) props["EnablePreviewModeBanner"] = strconv.FormatBool(*c.EmailSettings.EnablePreviewModeBanner) props["EmailNotificationContentsType"] = *c.EmailSettings.EmailNotificationContentsType - props["EmailLoginButtonColor"] = *c.EmailSettings.LoginButtonColor - props["EmailLoginButtonBorderColor"] = *c.EmailSettings.LoginButtonBorderColor - props["EmailLoginButtonTextColor"] = *c.EmailSettings.LoginButtonTextColor - - props["EnableSignUpWithGitLab"] = strconv.FormatBool(c.GitLabSettings.Enable) - props["ShowEmailAddress"] = strconv.FormatBool(c.PrivacySettings.ShowEmailAddress) - props["TermsOfServiceLink"] = *c.SupportSettings.TermsOfServiceLink - props["PrivacyPolicyLink"] = *c.SupportSettings.PrivacyPolicyLink - props["AboutLink"] = *c.SupportSettings.AboutLink - props["HelpLink"] = *c.SupportSettings.HelpLink - props["ReportAProblemLink"] = *c.SupportSettings.ReportAProblemLink - props["SupportEmail"] = *c.SupportSettings.SupportEmail - props["EnableFileAttachments"] = strconv.FormatBool(*c.FileSettings.EnableFileAttachments) props["EnablePublicLink"] = strconv.FormatBool(c.FileSettings.EnablePublicLink) props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort) props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort) - props["DefaultClientLocale"] = *c.LocalizationSettings.DefaultClientLocale props["AvailableLocales"] = *c.LocalizationSettings.AvailableLocales props["SQLDriverName"] = *c.SqlSettings.DriverName - props["EnableCustomEmoji"] = strconv.FormatBool(*c.ServiceSettings.EnableCustomEmoji) props["EnableEmojiPicker"] = strconv.FormatBool(*c.ServiceSettings.EnableEmojiPicker) props["RestrictCustomEmojiCreation"] = *c.ServiceSettings.RestrictCustomEmojiCreation props["MaxFileSize"] = strconv.FormatInt(*c.FileSettings.MaxFileSize, 10) - props["AppDownloadLink"] = *c.NativeAppSettings.AppDownloadLink - props["AndroidAppDownloadLink"] = *c.NativeAppSettings.AndroidAppDownloadLink - props["IosAppDownloadLink"] = *c.NativeAppSettings.IosAppDownloadLink props["EnableWebrtc"] = strconv.FormatBool(*c.WebrtcSettings.Enable) @@ -606,48 +566,26 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L props["EnableUserTypingMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableUserTypingMessages) props["EnableChannelViewedMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableChannelViewedMessages) - props["DiagnosticId"] = diagnosticId - props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) - props["PluginsEnabled"] = strconv.FormatBool(*c.PluginSettings.Enable) - hasImageProxy := c.ServiceSettings.ImageProxyType != nil && *c.ServiceSettings.ImageProxyType != "" && c.ServiceSettings.ImageProxyURL != nil && *c.ServiceSettings.ImageProxyURL != "" - props["HasImageProxy"] = strconv.FormatBool(hasImageProxy) - props["RunJobs"] = strconv.FormatBool(*c.JobSettings.RunJobs) // Set default values for all options that require a license. props["ExperimentalHideTownSquareinLHS"] = "false" props["ExperimentalTownSquareIsReadOnly"] = "false" props["ExperimentalEnableAuthenticationTransfer"] = "true" - props["EnableCustomBrand"] = "false" - props["CustomBrandText"] = "" - props["CustomDescriptionText"] = "" - props["EnableLdap"] = "false" - props["LdapLoginFieldName"] = "" props["LdapNicknameAttributeSet"] = "false" props["LdapFirstNameAttributeSet"] = "false" props["LdapLastNameAttributeSet"] = "false" - props["LdapLoginButtonColor"] = "" - props["LdapLoginButtonBorderColor"] = "" - props["LdapLoginButtonTextColor"] = "" - props["EnableMultifactorAuthentication"] = "false" props["EnforceMultifactorAuthentication"] = "false" props["EnableCompliance"] = "false" props["EnableMobileFileDownload"] = "true" props["EnableMobileFileUpload"] = "true" - props["EnableSaml"] = "false" - props["SamlLoginButtonText"] = "" props["SamlFirstNameAttributeSet"] = "false" props["SamlLastNameAttributeSet"] = "false" props["SamlNicknameAttributeSet"] = "false" - props["SamlLoginButtonColor"] = "" - props["SamlLoginButtonBorderColor"] = "" - props["SamlLoginButtonTextColor"] = "" props["EnableCluster"] = "false" props["EnableMetrics"] = "false" - props["EnableSignUpWithGoogle"] = "false" - props["EnableSignUpWithOffice365"] = "false" props["PasswordMinimumLength"] = "0" props["PasswordRequireLowercase"] = "false" props["PasswordRequireUppercase"] = "false" @@ -672,9 +610,6 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L props["PasswordRequireNumber"] = strconv.FormatBool(*c.PasswordSettings.Number) props["PasswordRequireSymbol"] = strconv.FormatBool(*c.PasswordSettings.Symbol) props["CustomUrlSchemes"] = strings.Join(*c.DisplaySettings.CustomUrlSchemes, ",") - props["EnableCustomBrand"] = strconv.FormatBool(*c.TeamSettings.EnableCustomBrand) - props["CustomBrandText"] = *c.TeamSettings.CustomBrandText - props["CustomDescriptionText"] = *c.TeamSettings.CustomDescriptionText if license != nil { props["ExperimentalHideTownSquareinLHS"] = strconv.FormatBool(*c.TeamSettings.ExperimentalHideTownSquareinLHS) @@ -682,18 +617,12 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L props["ExperimentalEnableAuthenticationTransfer"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalEnableAuthenticationTransfer) if *license.Features.LDAP { - props["EnableLdap"] = strconv.FormatBool(*c.LdapSettings.Enable) - props["LdapLoginFieldName"] = *c.LdapSettings.LoginFieldName props["LdapNicknameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.NicknameAttribute != "") props["LdapFirstNameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.FirstNameAttribute != "") props["LdapLastNameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.LastNameAttribute != "") - props["LdapLoginButtonColor"] = *c.LdapSettings.LoginButtonColor - props["LdapLoginButtonBorderColor"] = *c.LdapSettings.LoginButtonBorderColor - props["LdapLoginButtonTextColor"] = *c.LdapSettings.LoginButtonTextColor } if *license.Features.MFA { - props["EnableMultifactorAuthentication"] = strconv.FormatBool(*c.ServiceSettings.EnableMultifactorAuthentication) props["EnforceMultifactorAuthentication"] = strconv.FormatBool(*c.ServiceSettings.EnforceMultifactorAuthentication) } @@ -704,14 +633,9 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L } if *license.Features.SAML { - props["EnableSaml"] = strconv.FormatBool(*c.SamlSettings.Enable) - props["SamlLoginButtonText"] = *c.SamlSettings.LoginButtonText props["SamlFirstNameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.FirstNameAttribute != "") props["SamlLastNameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.LastNameAttribute != "") props["SamlNicknameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.NicknameAttribute != "") - props["SamlLoginButtonColor"] = *c.SamlSettings.LoginButtonColor - props["SamlLoginButtonBorderColor"] = *c.SamlSettings.LoginButtonBorderColor - props["SamlLoginButtonTextColor"] = *c.SamlSettings.LoginButtonTextColor // do this under the correct licensed feature props["ExperimentalClientSideCertEnable"] = strconv.FormatBool(*c.ExperimentalSettings.ClientSideCertEnable) @@ -726,14 +650,6 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L props["EnableMetrics"] = strconv.FormatBool(*c.MetricsSettings.Enable) } - if *license.Features.GoogleOAuth { - props["EnableSignUpWithGoogle"] = strconv.FormatBool(c.GoogleSettings.Enable) - } - - if *license.Features.Office365OAuth { - props["EnableSignUpWithOffice365"] = strconv.FormatBool(c.Office365Settings.Enable) - } - if *license.Features.Announcement { props["EnableBanner"] = strconv.FormatBool(*c.AnnouncementSettings.EnableBanner) props["BannerText"] = *c.AnnouncementSettings.BannerText @@ -760,6 +676,114 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L return props } +func GenerateLimitedClientConfig(c *model.Config, diagnosticId string, license *model.License) map[string]string { + props := make(map[string]string) + + props["Version"] = model.CurrentVersion + props["BuildNumber"] = model.BuildNumber + props["BuildDate"] = model.BuildDate + props["BuildHash"] = model.BuildHash + props["BuildHashEnterprise"] = model.BuildHashEnterprise + props["BuildEnterpriseReady"] = model.BuildEnterpriseReady + + props["SiteName"] = c.TeamSettings.SiteName + props["EnableTeamCreation"] = strconv.FormatBool(*c.TeamSettings.EnableTeamCreation) + props["EnableUserCreation"] = strconv.FormatBool(*c.TeamSettings.EnableUserCreation) + props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer) + + props["AndroidLatestVersion"] = c.ClientRequirements.AndroidLatestVersion + props["AndroidMinVersion"] = c.ClientRequirements.AndroidMinVersion + props["DesktopLatestVersion"] = c.ClientRequirements.DesktopLatestVersion + props["DesktopMinVersion"] = c.ClientRequirements.DesktopMinVersion + props["IosLatestVersion"] = c.ClientRequirements.IosLatestVersion + props["IosMinVersion"] = c.ClientRequirements.IosMinVersion + + props["EnableDiagnostics"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) + + props["EnableSignUpWithEmail"] = strconv.FormatBool(c.EmailSettings.EnableSignUpWithEmail) + props["EnableSignInWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithEmail) + props["EnableSignInWithUsername"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithUsername) + + props["EmailLoginButtonColor"] = *c.EmailSettings.LoginButtonColor + props["EmailLoginButtonBorderColor"] = *c.EmailSettings.LoginButtonBorderColor + props["EmailLoginButtonTextColor"] = *c.EmailSettings.LoginButtonTextColor + + props["EnableSignUpWithGitLab"] = strconv.FormatBool(c.GitLabSettings.Enable) + + props["TermsOfServiceLink"] = *c.SupportSettings.TermsOfServiceLink + props["PrivacyPolicyLink"] = *c.SupportSettings.PrivacyPolicyLink + props["AboutLink"] = *c.SupportSettings.AboutLink + props["HelpLink"] = *c.SupportSettings.HelpLink + props["ReportAProblemLink"] = *c.SupportSettings.ReportAProblemLink + props["SupportEmail"] = *c.SupportSettings.SupportEmail + + props["DefaultClientLocale"] = *c.LocalizationSettings.DefaultClientLocale + + props["EnableCustomEmoji"] = strconv.FormatBool(*c.ServiceSettings.EnableCustomEmoji) + props["AppDownloadLink"] = *c.NativeAppSettings.AppDownloadLink + props["AndroidAppDownloadLink"] = *c.NativeAppSettings.AndroidAppDownloadLink + props["IosAppDownloadLink"] = *c.NativeAppSettings.IosAppDownloadLink + + props["DiagnosticId"] = diagnosticId + props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) + + hasImageProxy := c.ServiceSettings.ImageProxyType != nil && *c.ServiceSettings.ImageProxyType != "" && c.ServiceSettings.ImageProxyURL != nil && *c.ServiceSettings.ImageProxyURL != "" + props["HasImageProxy"] = strconv.FormatBool(hasImageProxy) + + // Set default values for all options that require a license. + props["EnableCustomBrand"] = "false" + props["CustomBrandText"] = "" + props["CustomDescriptionText"] = "" + props["EnableLdap"] = "false" + props["LdapLoginFieldName"] = "" + props["LdapLoginButtonColor"] = "" + props["LdapLoginButtonBorderColor"] = "" + props["LdapLoginButtonTextColor"] = "" + props["EnableMultifactorAuthentication"] = "false" + props["EnableSaml"] = "false" + props["SamlLoginButtonText"] = "" + props["SamlLoginButtonColor"] = "" + props["SamlLoginButtonBorderColor"] = "" + props["SamlLoginButtonTextColor"] = "" + props["EnableSignUpWithGoogle"] = "false" + props["EnableSignUpWithOffice365"] = "false" + props["EnableCustomBrand"] = strconv.FormatBool(*c.TeamSettings.EnableCustomBrand) + props["CustomBrandText"] = *c.TeamSettings.CustomBrandText + props["CustomDescriptionText"] = *c.TeamSettings.CustomDescriptionText + + if license != nil { + if *license.Features.LDAP { + props["EnableLdap"] = strconv.FormatBool(*c.LdapSettings.Enable) + props["LdapLoginFieldName"] = *c.LdapSettings.LoginFieldName + props["LdapLoginButtonColor"] = *c.LdapSettings.LoginButtonColor + props["LdapLoginButtonBorderColor"] = *c.LdapSettings.LoginButtonBorderColor + props["LdapLoginButtonTextColor"] = *c.LdapSettings.LoginButtonTextColor + } + + if *license.Features.MFA { + props["EnableMultifactorAuthentication"] = strconv.FormatBool(*c.ServiceSettings.EnableMultifactorAuthentication) + } + + if *license.Features.SAML { + props["EnableSaml"] = strconv.FormatBool(*c.SamlSettings.Enable) + props["SamlLoginButtonText"] = *c.SamlSettings.LoginButtonText + props["SamlLoginButtonColor"] = *c.SamlSettings.LoginButtonColor + props["SamlLoginButtonBorderColor"] = *c.SamlSettings.LoginButtonBorderColor + props["SamlLoginButtonTextColor"] = *c.SamlSettings.LoginButtonTextColor + } + + if *license.Features.GoogleOAuth { + props["EnableSignUpWithGoogle"] = strconv.FormatBool(c.GoogleSettings.Enable) + } + + if *license.Features.Office365OAuth { + props["EnableSignUpWithOffice365"] = strconv.FormatBool(c.Office365Settings.Enable) + } + } + + return props +} + func ValidateLdapFilter(cfg *model.Config, ldap einterfaces.LdapInterface) *model.AppError { if *cfg.LdapSettings.Enable && ldap != nil && *cfg.LdapSettings.UserFilter != "" { if err := ldap.ValidateFilter(*cfg.LdapSettings.UserFilter); err != nil { -- cgit v1.2.3-1-g7c22