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