Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions controllers/ext_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,23 @@ func getNetworkExtClients(w http.ResponseWriter, r *http.Request) {
}
err := user.Get(r.Context())
if err == nil {
userRole := &schema.UserRole{
ID: user.PlatformRoleID,
}
err := userRole.Get(r.Context())
if err != nil || !userRole.FullAccess {
filtered := []models.ExtClient{}
for _, ec := range extclients {
if logic.IsUserAllowedAccessToExtClient(username, ec) {
filtered = append(filtered, ec)
if user.PlatformRoleID != schema.Auditor {
userRole := &schema.UserRole{
ID: user.PlatformRoleID,
}
err := userRole.Get(r.Context())
if err != nil || !userRole.FullAccess {
if (user.PlatformRoleID == schema.PlatformUser && !logic.IsNetworkAdmin(user, network)) ||
user.PlatformRoleID != schema.PlatformUser {
var filtered []models.ExtClient
for _, ec := range extclients {
if logic.IsUserAllowedAccessToExtClient(username, ec) {
filtered = append(filtered, ec)
}
}
extclients = filtered
}
}
extclients = filtered
}
}
}
Expand Down Expand Up @@ -212,6 +217,24 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) {
return
}

username := r.Header.Get("user")
if r.Header.Get("ismaster") != "yes" {
user := &schema.User{
Username: username,
}
err := user.Get(r.Context())
if err == nil {
if user.PlatformRoleID != schema.SuperAdminRole &&
user.PlatformRoleID != schema.AdminRole &&
!(user.PlatformRoleID == schema.PlatformUser && logic.IsNetworkAdmin(user, networkid)) &&
user.Username != client.OwnerID {
err = fmt.Errorf("access denied")
logic.ReturnErrorResponse(w, r, logic.FormatError(err, logic.Forbidden))
return
}
}
}

gwnode, err := logic.GetNodeByID(client.IngressGatewayID)
if err != nil {
logger.Log(
Expand Down Expand Up @@ -389,10 +412,17 @@ Endpoint = %s
)

if params["type"] == "qr" {
bytes, err := qrcode.Encode(config, qrcode.Medium, -5)
bytes, err := qrcode.Encode(config, qrcode.Low, -5)
if err != nil {
logger.Log(1, r.Header.Get("user"), "failed to encode qr code: ", err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
if strings.Contains(err.Error(), "content too long to encode") {
logic.ReturnErrorResponse(w, r, logic.FormatError(
fmt.Errorf("config is too large to encode as a QR code; please use the file download instead"),
"badrequest",
))
} else {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
}
return
}
w.Header().Set("Content-Type", "image/png")
Expand Down
4 changes: 4 additions & 0 deletions logic/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ func GetSmtpPort() int {
return GetServerSettings().SmtpPort
}

func SmtpSkipTlsVerify() bool {
return GetServerSettings().SmtpSkipTlsVerify
}

func GetSenderEmail() string {
return GetServerSettings().EmailSenderAddr
}
Expand Down
1 change: 1 addition & 0 deletions logic/user_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var AddGlobalGroupOnRoleUpgrade = func(oldRole, newRole schema.UserRoleID, group
var PlatformRoleRequiresGroupEnforcement = func(role schema.UserRoleID) bool { return false }
var UserHasGlobalNetworksAdminMembership = func(user *schema.User) bool { return false }
var UserHasNetworkGroupAccess = func(user *schema.User, networkID string) bool { return false }
var IsNetworkAdmin = func(user *schema.User, networkID string) bool { return false }
var CanUserCreateNetwork = func(ctx context.Context, username string) bool { return true }
var EmailInit = func() {}

Expand Down
7 changes: 7 additions & 0 deletions migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,13 @@ func migrateSettings() {
if settings.StunServers == "" {
settings.StunServers = servercfg.GetStunServers()
}
if settings.SmtpHost != "" {
_, ok := settingsD["smtp_skip_tls_verify"]
if !ok {
// skip tls verification for older deployments when tls verification wasn't configurable.
settings.SmtpSkipTlsVerify = true
}
}
logic.UpsertServerSettings(settings)
}

Expand Down
1 change: 1 addition & 0 deletions models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ServerSettings struct {
EmailSenderPassword string `json:"email_sender_password"`
SmtpHost string `json:"smtp_host"`
SmtpPort int `json:"smtp_port"`
SmtpSkipTlsVerify bool `json:"smtp_skip_tls_verify"`
MetricInterval string `json:"metric_interval"`
MetricsPort int `json:"metrics_port"`
// IPDetectionInterval is the interval (in seconds) at which devices check for changes in public ip.
Expand Down
1 change: 1 addition & 0 deletions pro/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Init() {
SenderEmail: logic.GetSenderEmail(),
SendUser: logic.GetSenderUser(),
SenderPass: logic.GetEmaiSenderPassword(),
SkipVerify: logic.SmtpSkipTlsVerify(),
}
if smtpSender.SendUser == "" {
smtpSender.SendUser = smtpSender.SenderEmail
Expand Down
8 changes: 5 additions & 3 deletions pro/email/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type SmtpSender struct {
SenderEmail string
SendUser string
SenderPass string
SkipVerify bool
}

func (s *SmtpSender) SendEmail(ctx context.Context, n Notification, e Mail) error {
Expand All @@ -30,9 +31,10 @@ func (s *SmtpSender) SendEmail(ctx context.Context, n Notification, e Mail) erro
// Settings for SMTP server
d := gomail.NewDialer(s.SmtpHost, s.SmtpPort, s.SendUser, s.SenderPass)

// This is only needed when SSL/TLS certificate is not valid on server.
// In production this should be set to false.
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
d.TLSConfig = &tls.Config{
ServerName: s.SmtpHost,
InsecureSkipVerify: s.SkipVerify,
}

// Now send E-Mail
if err := d.DialAndSend(m); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pro/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func InitPro() {
logic.PlatformRoleRequiresGroupEnforcement = proLogic.PlatformRoleRequiresGroupEnforcement
logic.UserHasGlobalNetworksAdminMembership = proLogic.UserHasGlobalNetworksAdminMembership
logic.UserHasNetworkGroupAccess = proLogic.UserHasNetworkGroupAccess
logic.IsNetworkAdmin = proLogic.IsNetworkAdmin
logic.CanUserCreateNetwork = proLogic.CanUserCreateNetwork

logic.GetUserGroup = proLogic.GetUserGroup
Expand Down
6 changes: 1 addition & 5 deletions pro/logic/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,7 @@ func UpdateTag(req models.UpdateTagReq, newID models.TagID) {
}

// unassign old tag
if _, ok := extclient.Tags[req.ID]; ok {
if newID != "" {
delete(extclient.Tags, req.ID)
}
}
delete(extclient.Tags, req.ID)

// assign tag if in taggedExtclientIDs.
if _, ok := taggedExtclientIDs[extclient.ClientID]; ok {
Expand Down