From d132de4400c181d69c8d560a5f1e33e95e6d8586 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 25 Aug 2015 14:28:02 -0700 Subject: [PATCH 1/4] Fixes PL-1 added ability to disable team creation --- api/team.go | 15 +++++++++++++++ config/config.json | 7 ++++--- docker/0.6/config_docker.json | 3 ++- utils/config.go | 21 +++++++++++---------- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/api/team.go b/api/team.go index a331e9e348..2d60707bb1 100644 --- a/api/team.go +++ b/api/team.go @@ -44,6 +44,11 @@ func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } + if utils.Cfg.TeamSettings.DisableTeamCreation { + c.Err = model.NewAppError("createTeamFromSignup", "Team creation has been disabled. Please ask your systems administrator for details.", "") + return + } + subjectPage := NewServerTemplatePage("signup_team_subject", c.GetSiteURL()) bodyPage := NewServerTemplatePage("signup_team_body", c.GetSiteURL()) bodyPage.Props["TourUrl"] = utils.Cfg.TeamSettings.TourLink @@ -79,6 +84,11 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) { return } + if utils.Cfg.TeamSettings.DisableTeamCreation { + c.Err = model.NewAppError("createTeamFromSignup", "Team creation has been disabled. Please ask your systems administrator for details.", "") + return + } + props := model.MapFromJson(strings.NewReader(teamSignup.Data)) teamSignup.Team.Email = props["email"] teamSignup.User.Email = props["email"] @@ -169,6 +179,11 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } + if utils.Cfg.TeamSettings.DisableTeamCreation { + c.Err = model.NewAppError("createTeam", "Team creation has been disabled. Please ask your systems administrator for details.", "") + return + } + if utils.Cfg.ServiceSettings.Mode != utils.MODE_DEV { c.Err = model.NewAppError("createTeam", "The mode does not allow network creation without a valid invite", "") return diff --git a/config/config.json b/config/config.json index f1f3ba22c8..768fd93565 100644 --- a/config/config.json +++ b/config/config.json @@ -73,8 +73,8 @@ "SMTPUsername": "", "SMTPPassword": "", "SMTPServer": "", - "UseTLS": false, - "UseStartTLS": false, + "UseTLS": false, + "UseStartTLS": false, "FeedbackEmail": "", "FeedbackName": "", "ApplePushServer": "", @@ -104,6 +104,7 @@ "HelpLink": "/static/help/configure_links.html", "ReportProblemLink": "/static/help/configure_links.html", "TourLink": "/static/help/configure_links.html", - "DefaultThemeColor": "#2389D7" + "DefaultThemeColor": "#2389D7", + "DisableTeamCreation": true } } diff --git a/docker/0.6/config_docker.json b/docker/0.6/config_docker.json index 157120b998..2193a6540f 100644 --- a/docker/0.6/config_docker.json +++ b/docker/0.6/config_docker.json @@ -94,6 +94,7 @@ "HelpLink": "/static/help/configure_links.html", "ReportProblemLink": "/static/help/configure_links.html", "TourLink": "/static/help/configure_links.html", - "DefaultThemeColor": "#2389D7" + "DefaultThemeColor": "#2389D7", + "DisableTeamCreation": true } } diff --git a/utils/config.go b/utils/config.go index 46daf203ce..9e5de93bf0 100644 --- a/utils/config.go +++ b/utils/config.go @@ -109,16 +109,17 @@ type PrivacySettings struct { } type TeamSettings struct { - MaxUsersPerTeam int - AllowPublicLink bool - AllowValetDefault bool - TermsLink string - PrivacyLink string - AboutLink string - HelpLink string - ReportProblemLink string - TourLink string - DefaultThemeColor string + MaxUsersPerTeam int + AllowPublicLink bool + AllowValetDefault bool + TermsLink string + PrivacyLink string + AboutLink string + HelpLink string + ReportProblemLink string + TourLink string + DefaultThemeColor string + DisableTeamCreation bool } type Config struct { From 67bc12e4b72960ce5413a6267f11d505d581f1e7 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 25 Aug 2015 14:40:16 -0700 Subject: [PATCH 2/4] Fixes PL-3 Restrict team creation to specific domains --- api/team.go | 45 ++++++++++++++++++++++++++++------- config/config.json | 3 ++- docker/0.6/config_docker.json | 3 ++- utils/config.go | 23 +++++++++--------- 4 files changed, 52 insertions(+), 22 deletions(-) diff --git a/api/team.go b/api/team.go index 2d60707bb1..10bdafcf01 100644 --- a/api/team.go +++ b/api/team.go @@ -44,8 +44,7 @@ func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - if utils.Cfg.TeamSettings.DisableTeamCreation { - c.Err = model.NewAppError("createTeamFromSignup", "Team creation has been disabled. Please ask your systems administrator for details.", "") + if !isTreamCreationAllowed(c, email) { return } @@ -84,11 +83,6 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) { return } - if utils.Cfg.TeamSettings.DisableTeamCreation { - c.Err = model.NewAppError("createTeamFromSignup", "Team creation has been disabled. Please ask your systems administrator for details.", "") - return - } - props := model.MapFromJson(strings.NewReader(teamSignup.Data)) teamSignup.Team.Email = props["email"] teamSignup.User.Email = props["email"] @@ -99,6 +93,11 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) { c.Err = err return } + + if !isTreamCreationAllowed(c, teamSignup.Team.Email) { + return + } + teamSignup.Team.Id = "" password := teamSignup.User.Password @@ -179,8 +178,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - if utils.Cfg.TeamSettings.DisableTeamCreation { - c.Err = model.NewAppError("createTeam", "Team creation has been disabled. Please ask your systems administrator for details.", "") + if !isTreamCreationAllowed(c, team.Email) { return } @@ -211,6 +209,35 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) { } } +func isTreamCreationAllowed(c *Context, email string) bool { + + email = strings.ToLower(email) + + if utils.Cfg.TeamSettings.DisableTeamCreation { + c.Err = model.NewAppError("isTreamCreationAllowed", "Team creation has been disabled. Please ask your systems administrator for details.", "") + return false + } + + // commas and @ signs are optional + // can be in the form of "@corp.mattermost.com, mattermost.com mattermost.org" -> corp.mattermost.com mattermost.com mattermost.org + domains := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(utils.Cfg.TeamSettings.RestrictCreationToDomains, "@", " ", -1), ",", " ", -1)))) + + matched := false + for _, d := range domains { + if strings.HasSuffix(email, "@"+d) { + matched = true + break + } + } + + if len(utils.Cfg.TeamSettings.RestrictCreationToDomains) > 0 && !matched { + c.Err = model.NewAppError("isTreamCreationAllowed", "Email must be from a specific domain (e.g. @example.com). Please ask your systems administrator for details.", "") + return false + } + + return true +} + func findTeamByName(c *Context, w http.ResponseWriter, r *http.Request) { m := model.MapFromJson(r.Body) diff --git a/config/config.json b/config/config.json index 768fd93565..572877d05a 100644 --- a/config/config.json +++ b/config/config.json @@ -105,6 +105,7 @@ "ReportProblemLink": "/static/help/configure_links.html", "TourLink": "/static/help/configure_links.html", "DefaultThemeColor": "#2389D7", - "DisableTeamCreation": true + "DisableTeamCreation": false, + "RestrictCreationToDomains": "mattermost.com, @spinpunch.com" } } diff --git a/docker/0.6/config_docker.json b/docker/0.6/config_docker.json index 2193a6540f..57ea1594c2 100644 --- a/docker/0.6/config_docker.json +++ b/docker/0.6/config_docker.json @@ -95,6 +95,7 @@ "ReportProblemLink": "/static/help/configure_links.html", "TourLink": "/static/help/configure_links.html", "DefaultThemeColor": "#2389D7", - "DisableTeamCreation": true + "DisableTeamCreation": true, + "RestrictCreationToDomains": "" } } diff --git a/utils/config.go b/utils/config.go index 9e5de93bf0..36301264cb 100644 --- a/utils/config.go +++ b/utils/config.go @@ -109,17 +109,18 @@ type PrivacySettings struct { } type TeamSettings struct { - MaxUsersPerTeam int - AllowPublicLink bool - AllowValetDefault bool - TermsLink string - PrivacyLink string - AboutLink string - HelpLink string - ReportProblemLink string - TourLink string - DefaultThemeColor string - DisableTeamCreation bool + MaxUsersPerTeam int + AllowPublicLink bool + AllowValetDefault bool + TermsLink string + PrivacyLink string + AboutLink string + HelpLink string + ReportProblemLink string + TourLink string + DefaultThemeColor string + DisableTeamCreation bool + RestrictCreationToDomains string } type Config struct { From 0418f762749f87862200a2f5cc00e0a3b91589a0 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 25 Aug 2015 14:40:44 -0700 Subject: [PATCH 3/4] Fixes PL-3 Restrict team creation to specific domains --- config/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.json b/config/config.json index 572877d05a..6c915e290c 100644 --- a/config/config.json +++ b/config/config.json @@ -106,6 +106,6 @@ "TourLink": "/static/help/configure_links.html", "DefaultThemeColor": "#2389D7", "DisableTeamCreation": false, - "RestrictCreationToDomains": "mattermost.com, @spinpunch.com" + "RestrictCreationToDomains": "" } } From 9abf980b0eadc51025282464b19d179d845b6769 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 27 Aug 2015 09:04:28 -0700 Subject: [PATCH 4/4] PL-3 fixing config files --- docker/0.6/config_docker.json | 4 +--- docker/dev/config_docker.json | 4 +++- docker/local/config_docker.json | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docker/0.6/config_docker.json b/docker/0.6/config_docker.json index 57ea1594c2..157120b998 100644 --- a/docker/0.6/config_docker.json +++ b/docker/0.6/config_docker.json @@ -94,8 +94,6 @@ "HelpLink": "/static/help/configure_links.html", "ReportProblemLink": "/static/help/configure_links.html", "TourLink": "/static/help/configure_links.html", - "DefaultThemeColor": "#2389D7", - "DisableTeamCreation": true, - "RestrictCreationToDomains": "" + "DefaultThemeColor": "#2389D7" } } diff --git a/docker/dev/config_docker.json b/docker/dev/config_docker.json index d336300caf..0fa51cfd47 100644 --- a/docker/dev/config_docker.json +++ b/docker/dev/config_docker.json @@ -94,6 +94,8 @@ "HelpLink": "/static/help/configure_links.html", "ReportProblemLink": "/static/help/configure_links.html", "TourLink": "/static/help/configure_links.html", - "DefaultThemeColor": "#2389D7" + "DefaultThemeColor": "#2389D7", + "DisableTeamCreation": false, + "RestrictCreationToDomains": "" } } diff --git a/docker/local/config_docker.json b/docker/local/config_docker.json index d336300caf..0fa51cfd47 100644 --- a/docker/local/config_docker.json +++ b/docker/local/config_docker.json @@ -94,6 +94,8 @@ "HelpLink": "/static/help/configure_links.html", "ReportProblemLink": "/static/help/configure_links.html", "TourLink": "/static/help/configure_links.html", - "DefaultThemeColor": "#2389D7" + "DefaultThemeColor": "#2389D7", + "DisableTeamCreation": false, + "RestrictCreationToDomains": "" } }