Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Update alert message

Neeraj Gupta96a990f2ce48
diff --git a/server/pkg/api/admin.go b/server/pkg/api/admin.go
index 0614a18be6..fd964daf07 100644
--- a/server/pkg/api/admin.go
+++ b/server/pkg/api/admin.go
@@ -23,6 +23,7 @@ import (
storagebonusCtrl "github.com/ente-io/museum/pkg/controller/storagebonus"
"github.com/ente-io/museum/pkg/controller/user"
"github.com/ente-io/museum/pkg/utils/auth"
+ emailUtil "github.com/ente-io/museum/pkg/utils/email"
"github.com/ente-io/museum/pkg/utils/time"
"github.com/gin-contrib/requestid"
"github.com/sirupsen/logrus"
@@ -32,7 +33,6 @@ import (
"github.com/ente-io/museum/ente"
"github.com/ente-io/museum/pkg/repo"
- emailUtil "github.com/ente-io/museum/pkg/utils/email"
"github.com/ente-io/museum/pkg/utils/handler"
"github.com/gin-gonic/gin"
)
@@ -570,9 +570,10 @@ func (h *AdminHandler) GetEmailsFromHashes(c *gin.Context) {
}
type adminAlertContext struct {
- ID int64
- Email string
- HasTOTP bool
+ ID int64
+ Email string
+ MaskedEmail string
+ HasTOTP bool
}
func (h *AdminHandler) notifyAdminAction(adminID int64, format string, args ...interface{}) {
@@ -580,6 +581,8 @@ func (h *AdminHandler) notifyAdminAction(adminID int64, format string, args ...i
adminIdentifier := fmt.Sprintf("%d", adminID)
if err != nil {
logrus.WithError(err).WithField("admin_id", adminID).Warn("failed to fetch admin details for admin action alert")
+ } else if adminCtx.MaskedEmail != "" {
+ adminIdentifier = adminCtx.MaskedEmail
} else if adminCtx.Email != "" {
adminIdentifier = adminCtx.Email
}
@@ -597,14 +600,15 @@ func (h *AdminHandler) getAdminAlertContext(adminID int64) (adminAlertContext, e
}
hasTOTP := user.IsTwoFactorEnabled != nil && *user.IsTwoFactorEnabled
return adminAlertContext{
- ID: adminID,
- Email: user.Email,
- HasTOTP: hasTOTP,
+ ID: adminID,
+ Email: user.Email,
+ MaskedEmail: emailUtil.GetMaskedEmailWithHint(user.Email),
+ HasTOTP: hasTOTP,
}, nil
}
func (h *AdminHandler) alertIfAdminMissing2FA(ctx adminAlertContext) {
- if ctx.HasTOTP || h.PasskeyController == nil {
+ if h.PasskeyController == nil {
return
}
passkeys, err := h.PasskeyController.GetPasskeys(ctx.ID)
@@ -615,12 +619,21 @@ func (h *AdminHandler) alertIfAdminMissing2FA(ctx adminAlertContext) {
if len(passkeys) > 0 {
return
}
- identifier := ctx.Email
+ identifier := ctx.MaskedEmail
+ if identifier == "" {
+ identifier = ctx.Email
+ }
if identifier == "" {
identifier = fmt.Sprintf("%d", ctx.ID)
}
+ icon := "⚠️"
+ message := "is missing passkey 2FA even though TOTP is enabled. Please register a passkey."
+ if !ctx.HasTOTP {
+ icon = "🚨"
+ message = "does not have TOTP or passkey 2FA enabled. Please protect your account with a passkey"
+ }
h.DiscordController.NotifyAdminAction(
- fmt.Sprintf("Admin (%s) does not have TOTP or passkey 2FA enabled. Please configure 2FA at the earliest.", identifier))
+ fmt.Sprintf("%s Admin (%s) %s", icon, identifier, message))
}
func (h *AdminHandler) attachSubscription(ctx *gin.Context, userID int64, response gin.H) {
diff --git a/server/pkg/controller/stripe.go b/server/pkg/controller/stripe.go
index 60c64e5d92..98de73fa85 100644
--- a/server/pkg/controller/stripe.go
+++ b/server/pkg/controller/stripe.go
@@ -763,7 +763,7 @@ func (c *StripeController) handleStripeError(err error, userID int64, context st
if stripeError.Type == stripe.ErrorTypeInvalidRequest {
// Send Discord alert with details
alertMsg := fmt.Sprintf(
- "🚨 Stripe Invalid Request Error\n"+
+ "⚠️ Stripe Invalid Request Error\n"+
"**Context:** %s\n"+
"**User ID:** %d\n"+
"**Error Code:** %s\n"+
diff --git a/server/pkg/utils/email/email.go b/server/pkg/utils/email/email.go
index 0478e68a5d..792234c72f 100644
--- a/server/pkg/utils/email/email.go
+++ b/server/pkg/utils/email/email.go
@@ -354,6 +354,48 @@ func GetMaskedEmail(email string) string {
}
}
+// GetMaskedEmailWithHint masks both the username and non-TLD domain segments while keeping helpful hints.
+func GetMaskedEmailWithHint(email string) string {
+ email = strings.TrimSpace(email)
+ at := strings.LastIndex(email, "@")
+ if at <= 0 || at == len(email)-1 {
+ return "[invalid_email]"
+ }
+ local := email[:at]
+ domain := email[at+1:]
+
+ maskedLocal := maskEmailSegment(local)
+ if domain == "" {
+ return maskedLocal + "@[invalid_domain]"
+ }
+
+ domainParts := strings.Split(domain, ".")
+ if len(domainParts) == 1 {
+ return fmt.Sprintf("%s@%s", maskedLocal, maskEmailSegment(domainParts[0]))
+ }
+
+ tld := domainParts[len(domainParts)-1]
+ mainParts := domainParts[:len(domainParts)-1]
+ for i, part := range mainParts {
+ mainParts[i] = maskEmailSegment(part)
+ }
+ return fmt.Sprintf("%s@%s.%s", maskedLocal, strings.Join(mainParts, "."), tld)
+}
+
+func maskEmailSegment(segment string) string {
+ segment = strings.TrimSpace(segment)
+ if segment == "" {
+ return "*"
+ }
+ if len(segment) == 1 {
+ return segment + "*"
+ }
+ if len(segment) == 2 {
+ return segment[:1] + "*"
+ }
+ return segment[:1] + strings.Repeat("*", len(segment)-2) + segment[len(segment)-1:]
+}
+
// getMailBody generates the mail html body from provided template and data
func getMailBody(templateName string, templateData map[string]interface{}) (string, error) {
htmlbody := new(bytes.Buffer)