π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Additional data for support dashboard
Neeraj Gupta25596854d3e1
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 480d21d32b..0424f0065d 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -627,6 +627,7 @@ func main() {QueueRepo: queueRepo,UserRepo: userRepo,CollectionRepo: collectionRepo,+ AuthenticatorRepo: authRepo,UserAuthRepo: userAuthRepo,UserController: userController,FamilyController: familyController,diff --git a/server/ente/admin.go b/server/ente/admin.goindex 97aa64fde6..4809d2c5fa 100644--- a/server/ente/admin.go+++ b/server/ente/admin.go@@ -36,6 +36,14 @@ type LogoutSessionReq struct {UserID int64 `json:"userID" binding:"required"`}+type TokenInfo struct {+ CreationTime int64 `json:"creationTime"`+ LastUsedTime int64 `json:"lastUsedTime"`+ UA string `json:"ua"`+ IsDeleted bool `json:"isDeleted"`+ App App `json:"app"`+}+func (a AdminOttReq) Validate() error {if !a.App.IsValid() {return errors.New("invalid app")diff --git a/server/pkg/api/admin.go b/server/pkg/api/admin.goindex a2e1b18165..f1e2d66ca4 100644--- a/server/pkg/api/admin.go+++ b/server/pkg/api/admin.go@@ -4,6 +4,7 @@ import ("errors""fmt""github.com/ente-io/museum/pkg/controller/remotestore"+ "github.com/ente-io/museum/pkg/repo/authenticator""net/http""strconv""strings"@@ -39,6 +40,7 @@ type AdminHandler struct {QueueRepo *repo.QueueRepositoryUserRepo *repo.UserRepositoryCollectionRepo *repo.CollectionRepository+ AuthenticatorRepo *authenticator.RepositoryUserAuthRepo *repo.UserAuthRepositoryFileRepo *repo.FileRepositoryBillingRepo *repo.BillingRepository@@ -571,6 +573,14 @@ func (h *AdminHandler) attachSubscription(ctx *gin.Context, userID int64, responif err == nil {response["details"] = details}+ tokenInfos, err := h.UserAuthRepo.GetUserTokenInfo(userID)+ if err == nil {+ response["tokens"] = tokenInfos+ }+ authEntryCount, err := h.AuthenticatorRepo.GetAuthCodeCount(ctx, userID)+ if err == nil {+ response["authCodes"] = authEntryCount+ }}func (h *AdminHandler) ClearOrphanObjects(c *gin.Context) {diff --git a/server/pkg/repo/authenticator/entity.go b/server/pkg/repo/authenticator/entity.goindex 056d0043ba..d47892212f 100644--- a/server/pkg/repo/authenticator/entity.go+++ b/server/pkg/repo/authenticator/entity.go@@ -89,6 +89,16 @@ func (r *Repository) Update(ctx context.Context, userID int64, req model.UpdateEreturn nil}+// GetAuthCodeCount returns the count of the authenticator entries for the given user+func (r *Repository) GetAuthCodeCount(ctx context.Context, userID int64) (int64, error) {+ var count int64+ err := r.DB.QueryRowContext(ctx, `SELECT count(*) FROM authenticator_entity WHERE user_id = $1 and is_deleted = FALSE`, userID).Scan(&count)+ if err != nil {+ return 0, stacktrace.Propagate(err, "failed to get auth code count")+ }+ return count, nil+}+// GetDiff returns the &{[]ente.TotpEntity} which have been added or// modified after the given sinceTimefunc (r *Repository) GetDiff(ctx context.Context, userID int64, sinceTime int64, limit int16) ([]model.Entity, error) {diff --git a/server/pkg/repo/userauth.go b/server/pkg/repo/userauth.goindex 03d597072d..b7fa8c88d1 100644--- a/server/pkg/repo/userauth.go+++ b/server/pkg/repo/userauth.go@@ -48,6 +48,24 @@ func (repo *UserAuthRepository) GetTokenCreationTime(token string) (int64, errorreturn result, nil}+func (repo *UserAuthRepository) GetUserTokenInfo(userID int64) ([]ente.TokenInfo, error) {+ rows, err := repo.DB.Query(`SELECT creation_time, last_used_at, user_agent, is_deleted, app FROM tokens WHERE user_id = $1 AND is_deleted = false`, userID)+ if err != nil {+ return nil, stacktrace.Propagate(err, "")+ }+ defer rows.Close()+ tokenInfos := make([]ente.TokenInfo, 0)+ for rows.Next() {+ var tokenInfo ente.TokenInfo+ err := rows.Scan(&tokenInfo.CreationTime, &tokenInfo.LastUsedTime, &tokenInfo.UA, &tokenInfo.IsDeleted, &tokenInfo.App)+ if err != nil {+ return nil, stacktrace.Propagate(err, "")+ }+ tokenInfos = append(tokenInfos, tokenInfo)+ }+ return tokenInfos, nil+}+// GetValidOTTs returns the list of OTTs that haven't expired for a given userfunc (repo *UserAuthRepository) GetValidOTTs(emailHash string, app ente.App) ([]string, error) {rows, err := repo.DB.Query(`SELECT ott FROM otts WHERE email_hash = $1 AND app = $2 AND expiration_time > $3`,