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