github.com/vnforks/kid@v5.11.1+incompatible/config/client.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package config 5 6 import ( 7 "fmt" 8 "strconv" 9 "strings" 10 11 "github.com/mattermost/mattermost-server/model" 12 ) 13 14 // GenerateClientConfig renders the given configuration for a client. 15 func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.License) map[string]string { 16 props := GenerateLimitedClientConfig(c, diagnosticId, license) 17 18 props["SiteURL"] = strings.TrimRight(*c.ServiceSettings.SiteURL, "/") 19 props["EnableUserDeactivation"] = strconv.FormatBool(*c.TeamSettings.EnableUserDeactivation) 20 props["RestrictDirectMessage"] = *c.TeamSettings.RestrictDirectMessage 21 props["EnableXToLeaveChannelsFromLHS"] = strconv.FormatBool(*c.TeamSettings.EnableXToLeaveChannelsFromLHS) 22 props["TeammateNameDisplay"] = *c.TeamSettings.TeammateNameDisplay 23 props["ExperimentalPrimaryTeam"] = *c.TeamSettings.ExperimentalPrimaryTeam 24 props["ExperimentalViewArchivedChannels"] = strconv.FormatBool(*c.TeamSettings.ExperimentalViewArchivedChannels) 25 26 props["EnableOAuthServiceProvider"] = strconv.FormatBool(*c.ServiceSettings.EnableOAuthServiceProvider) 27 props["GoogleDeveloperKey"] = *c.ServiceSettings.GoogleDeveloperKey 28 props["EnableIncomingWebhooks"] = strconv.FormatBool(*c.ServiceSettings.EnableIncomingWebhooks) 29 props["EnableOutgoingWebhooks"] = strconv.FormatBool(*c.ServiceSettings.EnableOutgoingWebhooks) 30 props["EnableCommands"] = strconv.FormatBool(*c.ServiceSettings.EnableCommands) 31 props["EnablePostUsernameOverride"] = strconv.FormatBool(*c.ServiceSettings.EnablePostUsernameOverride) 32 props["EnablePostIconOverride"] = strconv.FormatBool(*c.ServiceSettings.EnablePostIconOverride) 33 props["EnableUserAccessTokens"] = strconv.FormatBool(*c.ServiceSettings.EnableUserAccessTokens) 34 props["EnableLinkPreviews"] = strconv.FormatBool(*c.ServiceSettings.EnableLinkPreviews) 35 props["EnableTesting"] = strconv.FormatBool(*c.ServiceSettings.EnableTesting) 36 props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper) 37 props["PostEditTimeLimit"] = fmt.Sprintf("%v", *c.ServiceSettings.PostEditTimeLimit) 38 props["MinimumHashtagLength"] = fmt.Sprintf("%v", *c.ServiceSettings.MinimumHashtagLength) 39 props["CloseUnusedDirectMessages"] = strconv.FormatBool(*c.ServiceSettings.CloseUnusedDirectMessages) 40 props["EnablePreviewFeatures"] = strconv.FormatBool(*c.ServiceSettings.EnablePreviewFeatures) 41 props["EnableTutorial"] = strconv.FormatBool(*c.ServiceSettings.EnableTutorial) 42 props["ExperimentalEnableDefaultChannelLeaveJoinMessages"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages) 43 props["ExperimentalGroupUnreadChannels"] = *c.ServiceSettings.ExperimentalGroupUnreadChannels 44 45 // This setting is only temporary, so keep using the old setting name for the mobile and web apps 46 props["ExperimentalEnablePostMetadata"] = strconv.FormatBool(!*c.ExperimentalSettings.DisablePostMetadata) 47 props["ExperimentalEnableClickToReply"] = strconv.FormatBool(*c.ExperimentalSettings.EnableClickToReply) 48 49 if *c.ServiceSettings.ExperimentalChannelOrganization || *c.ServiceSettings.ExperimentalGroupUnreadChannels != model.GROUP_UNREAD_CHANNELS_DISABLED { 50 props["ExperimentalChannelOrganization"] = strconv.FormatBool(true) 51 } else { 52 props["ExperimentalChannelOrganization"] = strconv.FormatBool(false) 53 } 54 55 props["ExperimentalEnableAutomaticReplies"] = strconv.FormatBool(*c.TeamSettings.ExperimentalEnableAutomaticReplies) 56 props["ExperimentalTimezone"] = strconv.FormatBool(*c.DisplaySettings.ExperimentalTimezone) 57 58 props["SendEmailNotifications"] = strconv.FormatBool(*c.EmailSettings.SendEmailNotifications) 59 props["SendPushNotifications"] = strconv.FormatBool(*c.EmailSettings.SendPushNotifications) 60 props["RequireEmailVerification"] = strconv.FormatBool(*c.EmailSettings.RequireEmailVerification) 61 props["EnableEmailBatching"] = strconv.FormatBool(*c.EmailSettings.EnableEmailBatching) 62 props["EnablePreviewModeBanner"] = strconv.FormatBool(*c.EmailSettings.EnablePreviewModeBanner) 63 props["EmailNotificationContentsType"] = *c.EmailSettings.EmailNotificationContentsType 64 65 props["ShowEmailAddress"] = strconv.FormatBool(*c.PrivacySettings.ShowEmailAddress) 66 67 props["EnableFileAttachments"] = strconv.FormatBool(*c.FileSettings.EnableFileAttachments) 68 props["EnablePublicLink"] = strconv.FormatBool(*c.FileSettings.EnablePublicLink) 69 70 props["AvailableLocales"] = *c.LocalizationSettings.AvailableLocales 71 props["SQLDriverName"] = *c.SqlSettings.DriverName 72 73 props["EnableEmojiPicker"] = strconv.FormatBool(*c.ServiceSettings.EnableEmojiPicker) 74 props["EnableGifPicker"] = strconv.FormatBool(*c.ServiceSettings.EnableGifPicker) 75 props["GfycatApiKey"] = *c.ServiceSettings.GfycatApiKey 76 props["GfycatApiSecret"] = *c.ServiceSettings.GfycatApiSecret 77 props["MaxFileSize"] = strconv.FormatInt(*c.FileSettings.MaxFileSize, 10) 78 79 props["MaxNotificationsPerChannel"] = strconv.FormatInt(*c.TeamSettings.MaxNotificationsPerChannel, 10) 80 props["EnableConfirmNotificationsToChannel"] = strconv.FormatBool(*c.TeamSettings.EnableConfirmNotificationsToChannel) 81 props["TimeBetweenUserTypingUpdatesMilliseconds"] = strconv.FormatInt(*c.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds, 10) 82 props["EnableUserTypingMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableUserTypingMessages) 83 props["EnableChannelViewedMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableChannelViewedMessages) 84 85 props["RunJobs"] = strconv.FormatBool(*c.JobSettings.RunJobs) 86 87 props["EnableEmailInvitations"] = strconv.FormatBool(*c.ServiceSettings.EnableEmailInvitations) 88 89 // Set default values for all options that require a license. 90 props["ExperimentalHideTownSquareinLHS"] = "false" 91 props["ExperimentalTownSquareIsReadOnly"] = "false" 92 props["ExperimentalEnableAuthenticationTransfer"] = "true" 93 props["LdapNicknameAttributeSet"] = "false" 94 props["LdapFirstNameAttributeSet"] = "false" 95 props["LdapLastNameAttributeSet"] = "false" 96 props["EnableCompliance"] = "false" 97 props["EnableMobileFileDownload"] = "true" 98 props["EnableMobileFileUpload"] = "true" 99 props["SamlFirstNameAttributeSet"] = "false" 100 props["SamlLastNameAttributeSet"] = "false" 101 props["SamlNicknameAttributeSet"] = "false" 102 props["EnableCluster"] = "false" 103 props["EnableMetrics"] = "false" 104 props["PasswordMinimumLength"] = "0" 105 props["PasswordRequireLowercase"] = "false" 106 props["PasswordRequireUppercase"] = "false" 107 props["PasswordRequireNumber"] = "false" 108 props["PasswordRequireSymbol"] = "false" 109 props["EnableBanner"] = "false" 110 props["BannerText"] = "" 111 props["BannerColor"] = "" 112 props["BannerTextColor"] = "" 113 props["AllowBannerDismissal"] = "false" 114 props["EnableThemeSelection"] = "true" 115 props["DefaultTheme"] = "" 116 props["AllowCustomThemes"] = "true" 117 props["AllowedThemes"] = "" 118 props["DataRetentionEnableMessageDeletion"] = "false" 119 props["DataRetentionMessageRetentionDays"] = "0" 120 props["DataRetentionEnableFileDeletion"] = "false" 121 props["DataRetentionFileRetentionDays"] = "0" 122 props["PasswordMinimumLength"] = fmt.Sprintf("%v", *c.PasswordSettings.MinimumLength) 123 props["PasswordRequireLowercase"] = strconv.FormatBool(*c.PasswordSettings.Lowercase) 124 props["PasswordRequireUppercase"] = strconv.FormatBool(*c.PasswordSettings.Uppercase) 125 props["PasswordRequireNumber"] = strconv.FormatBool(*c.PasswordSettings.Number) 126 props["PasswordRequireSymbol"] = strconv.FormatBool(*c.PasswordSettings.Symbol) 127 props["CustomUrlSchemes"] = strings.Join(c.DisplaySettings.CustomUrlSchemes, ",") 128 129 if license != nil { 130 props["ExperimentalHideTownSquareinLHS"] = strconv.FormatBool(*c.TeamSettings.ExperimentalHideTownSquareinLHS) 131 props["ExperimentalTownSquareIsReadOnly"] = strconv.FormatBool(*c.TeamSettings.ExperimentalTownSquareIsReadOnly) 132 props["ExperimentalEnableAuthenticationTransfer"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalEnableAuthenticationTransfer) 133 134 if *license.Features.LDAP { 135 props["LdapNicknameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.NicknameAttribute != "") 136 props["LdapFirstNameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.FirstNameAttribute != "") 137 props["LdapLastNameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.LastNameAttribute != "") 138 } 139 140 if *license.Features.Compliance { 141 props["EnableCompliance"] = strconv.FormatBool(*c.ComplianceSettings.Enable) 142 props["EnableMobileFileDownload"] = strconv.FormatBool(*c.FileSettings.EnableMobileDownload) 143 props["EnableMobileFileUpload"] = strconv.FormatBool(*c.FileSettings.EnableMobileUpload) 144 } 145 146 if *license.Features.SAML { 147 props["SamlFirstNameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.FirstNameAttribute != "") 148 props["SamlLastNameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.LastNameAttribute != "") 149 props["SamlNicknameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.NicknameAttribute != "") 150 151 // do this under the correct licensed feature 152 props["ExperimentalClientSideCertEnable"] = strconv.FormatBool(*c.ExperimentalSettings.ClientSideCertEnable) 153 props["ExperimentalClientSideCertCheck"] = *c.ExperimentalSettings.ClientSideCertCheck 154 } 155 156 if *license.Features.Cluster { 157 props["EnableCluster"] = strconv.FormatBool(*c.ClusterSettings.Enable) 158 } 159 160 if *license.Features.Cluster { 161 props["EnableMetrics"] = strconv.FormatBool(*c.MetricsSettings.Enable) 162 } 163 164 if *license.Features.Announcement { 165 props["EnableBanner"] = strconv.FormatBool(*c.AnnouncementSettings.EnableBanner) 166 props["BannerText"] = *c.AnnouncementSettings.BannerText 167 props["BannerColor"] = *c.AnnouncementSettings.BannerColor 168 props["BannerTextColor"] = *c.AnnouncementSettings.BannerTextColor 169 props["AllowBannerDismissal"] = strconv.FormatBool(*c.AnnouncementSettings.AllowBannerDismissal) 170 } 171 172 if *license.Features.ThemeManagement { 173 props["EnableThemeSelection"] = strconv.FormatBool(*c.ThemeSettings.EnableThemeSelection) 174 props["DefaultTheme"] = *c.ThemeSettings.DefaultTheme 175 props["AllowCustomThemes"] = strconv.FormatBool(*c.ThemeSettings.AllowCustomThemes) 176 props["AllowedThemes"] = strings.Join(c.ThemeSettings.AllowedThemes, ",") 177 } 178 179 if *license.Features.DataRetention { 180 props["DataRetentionEnableMessageDeletion"] = strconv.FormatBool(*c.DataRetentionSettings.EnableMessageDeletion) 181 props["DataRetentionMessageRetentionDays"] = strconv.FormatInt(int64(*c.DataRetentionSettings.MessageRetentionDays), 10) 182 props["DataRetentionEnableFileDeletion"] = strconv.FormatBool(*c.DataRetentionSettings.EnableFileDeletion) 183 props["DataRetentionFileRetentionDays"] = strconv.FormatInt(int64(*c.DataRetentionSettings.FileRetentionDays), 10) 184 } 185 } 186 187 return props 188 } 189 190 // GenerateLimitedClientConfig renders the given configuration for an untrusted client. 191 func GenerateLimitedClientConfig(c *model.Config, diagnosticId string, license *model.License) map[string]string { 192 props := make(map[string]string) 193 194 props["Version"] = model.CurrentVersion 195 props["BuildNumber"] = model.BuildNumber 196 props["BuildDate"] = model.BuildDate 197 props["BuildHash"] = model.BuildHash 198 props["BuildHashEnterprise"] = model.BuildHashEnterprise 199 props["BuildEnterpriseReady"] = model.BuildEnterpriseReady 200 201 props["SiteName"] = *c.TeamSettings.SiteName 202 props["WebsocketURL"] = strings.TrimRight(*c.ServiceSettings.WebsocketURL, "/") 203 props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort) 204 props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort) 205 props["EnableUserCreation"] = strconv.FormatBool(*c.TeamSettings.EnableUserCreation) 206 props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer) 207 208 props["AndroidLatestVersion"] = c.ClientRequirements.AndroidLatestVersion 209 props["AndroidMinVersion"] = c.ClientRequirements.AndroidMinVersion 210 props["DesktopLatestVersion"] = c.ClientRequirements.DesktopLatestVersion 211 props["DesktopMinVersion"] = c.ClientRequirements.DesktopMinVersion 212 props["IosLatestVersion"] = c.ClientRequirements.IosLatestVersion 213 props["IosMinVersion"] = c.ClientRequirements.IosMinVersion 214 215 props["EnableDiagnostics"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) 216 217 props["EnableSignUpWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignUpWithEmail) 218 props["EnableSignInWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithEmail) 219 props["EnableSignInWithUsername"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithUsername) 220 221 props["EmailLoginButtonColor"] = *c.EmailSettings.LoginButtonColor 222 props["EmailLoginButtonBorderColor"] = *c.EmailSettings.LoginButtonBorderColor 223 props["EmailLoginButtonTextColor"] = *c.EmailSettings.LoginButtonTextColor 224 225 props["EnableSignUpWithGitLab"] = strconv.FormatBool(*c.GitLabSettings.Enable) 226 227 props["TermsOfServiceLink"] = *c.SupportSettings.TermsOfServiceLink 228 props["PrivacyPolicyLink"] = *c.SupportSettings.PrivacyPolicyLink 229 props["AboutLink"] = *c.SupportSettings.AboutLink 230 props["HelpLink"] = *c.SupportSettings.HelpLink 231 props["ReportAProblemLink"] = *c.SupportSettings.ReportAProblemLink 232 props["SupportEmail"] = *c.SupportSettings.SupportEmail 233 234 props["DefaultClientLocale"] = *c.LocalizationSettings.DefaultClientLocale 235 236 props["EnableCustomEmoji"] = strconv.FormatBool(*c.ServiceSettings.EnableCustomEmoji) 237 props["AppDownloadLink"] = *c.NativeAppSettings.AppDownloadLink 238 props["AndroidAppDownloadLink"] = *c.NativeAppSettings.AndroidAppDownloadLink 239 props["IosAppDownloadLink"] = *c.NativeAppSettings.IosAppDownloadLink 240 241 props["DiagnosticId"] = diagnosticId 242 props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) 243 244 props["HasImageProxy"] = strconv.FormatBool(*c.ImageProxySettings.Enable) 245 246 props["PluginsEnabled"] = strconv.FormatBool(*c.PluginSettings.Enable) 247 248 // Set default values for all options that require a license. 249 props["EnableCustomBrand"] = "false" 250 props["CustomBrandText"] = "" 251 props["CustomDescriptionText"] = "" 252 props["EnableLdap"] = "false" 253 props["LdapLoginFieldName"] = "" 254 props["LdapLoginButtonColor"] = "" 255 props["LdapLoginButtonBorderColor"] = "" 256 props["LdapLoginButtonTextColor"] = "" 257 props["EnableSaml"] = "false" 258 props["SamlLoginButtonText"] = "" 259 props["SamlLoginButtonColor"] = "" 260 props["SamlLoginButtonBorderColor"] = "" 261 props["SamlLoginButtonTextColor"] = "" 262 props["EnableSignUpWithGoogle"] = "false" 263 props["EnableSignUpWithOffice365"] = "false" 264 props["EnableCustomBrand"] = strconv.FormatBool(*c.TeamSettings.EnableCustomBrand) 265 props["CustomBrandText"] = *c.TeamSettings.CustomBrandText 266 props["CustomDescriptionText"] = *c.TeamSettings.CustomDescriptionText 267 props["EnableMultifactorAuthentication"] = strconv.FormatBool(*c.ServiceSettings.EnableMultifactorAuthentication) 268 props["EnforceMultifactorAuthentication"] = "false" 269 270 if license != nil { 271 if *license.Features.LDAP { 272 props["EnableLdap"] = strconv.FormatBool(*c.LdapSettings.Enable) 273 props["LdapLoginFieldName"] = *c.LdapSettings.LoginFieldName 274 props["LdapLoginButtonColor"] = *c.LdapSettings.LoginButtonColor 275 props["LdapLoginButtonBorderColor"] = *c.LdapSettings.LoginButtonBorderColor 276 props["LdapLoginButtonTextColor"] = *c.LdapSettings.LoginButtonTextColor 277 } 278 279 if *license.Features.SAML { 280 props["EnableSaml"] = strconv.FormatBool(*c.SamlSettings.Enable) 281 props["SamlLoginButtonText"] = *c.SamlSettings.LoginButtonText 282 props["SamlLoginButtonColor"] = *c.SamlSettings.LoginButtonColor 283 props["SamlLoginButtonBorderColor"] = *c.SamlSettings.LoginButtonBorderColor 284 props["SamlLoginButtonTextColor"] = *c.SamlSettings.LoginButtonTextColor 285 } 286 287 if *license.Features.GoogleOAuth { 288 props["EnableSignUpWithGoogle"] = strconv.FormatBool(*c.GoogleSettings.Enable) 289 } 290 291 if *license.Features.Office365OAuth { 292 props["EnableSignUpWithOffice365"] = strconv.FormatBool(*c.Office365Settings.Enable) 293 } 294 295 if *license.Features.CustomTermsOfService { 296 props["EnableCustomTermsOfService"] = strconv.FormatBool(*c.SupportSettings.CustomTermsOfServiceEnabled) 297 props["CustomTermsOfServiceReAcceptancePeriod"] = strconv.FormatInt(int64(*c.SupportSettings.CustomTermsOfServiceReAcceptancePeriod), 10) 298 } 299 300 if *license.Features.MFA { 301 props["EnforceMultifactorAuthentication"] = strconv.FormatBool(*c.ServiceSettings.EnforceMultifactorAuthentication) 302 } 303 } 304 305 return props 306 }