From fa8db1d80ef259c294d36fd41447c8f101d92872 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 4 Apr 2023 23:24:08 -0700 Subject: [PATCH] limit screen sharing to 50 commands --- pkg/sstore/dbops.go | 22 ++++++---------------- pkg/sstore/sstore.go | 3 +++ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/pkg/sstore/dbops.go b/pkg/sstore/dbops.go index 517a94625..3d6f9833f 100644 --- a/pkg/sstore/dbops.go +++ b/pkg/sstore/dbops.go @@ -2437,22 +2437,6 @@ func PurgeHistoryByIds(ctx context.Context, historyIds []string) ([]*HistoryItem }) } -func CanScreenWebShare(screen *ScreenType) error { - if screen == nil { - return fmt.Errorf("cannot share screen, not found") - } - if screen.ShareMode == ShareModeWeb { - return fmt.Errorf("screen is already shared to web") - } - if screen.ShareMode != ShareModeLocal { - return fmt.Errorf("screen cannot be shared, invalid current share mode %q (must be local)", screen.ShareMode) - } - if screen.Archived { - return fmt.Errorf("screen cannot be shared, must un-archive before sharing") - } - return nil -} - func ScreenWebShareStart(ctx context.Context, screenId string, shareOpts ScreenWebShareOpts) error { return WithTx(ctx, func(tx *TxWrap) error { query := `SELECT screenid FROM screen WHERE screenid = ?` @@ -2466,6 +2450,12 @@ func ScreenWebShareStart(ctx context.Context, screenId string, shareOpts ScreenW if shareMode != ShareModeLocal { return fmt.Errorf("screen cannot be shared, invalid current share mode %q (must be local)", shareMode) } + query = `SELECT count(*) FROM line WHERE screenid = ? AND NOT archived` + lineCount := tx.GetInt(query, screenId) + if lineCount > MaxWebShareLineCount { + return fmt.Errorf("screen cannot be shared, limited to a maximum of %d lines", MaxWebShareLineCount) + go UpdateCurrentActivity(context.Background(), ActivityUpdate{WebShareLimit: 1}) + } query = `UPDATE screen SET sharemode = ?, webshareopts = ? WHERE screenid = ?` tx.Exec(query, ShareModeWeb, quickJson(shareOpts), screenId) insertScreenNewUpdate(tx, screenId) diff --git a/pkg/sstore/sstore.go b/pkg/sstore/sstore.go index 825ccc15d..70df63582 100644 --- a/pkg/sstore/sstore.go +++ b/pkg/sstore/sstore.go @@ -33,6 +33,7 @@ const LineTypeText = "text" const LineNoHeight = -1 const DBFileName = "prompt.db" const DBFileNameBackup = "backup.prompt.db" +const MaxWebShareLineCount = 50 const DefaultSessionName = "default" const LocalRemoteAlias = "local" @@ -177,6 +178,7 @@ type ActivityUpdate struct { HistoryView int BookmarksView int NumConns int + WebShareLimit int BuildTime string } @@ -201,6 +203,7 @@ type TelemetryData struct { HistoryView int `json:"historyview,omitempty"` BookmarksView int `json:"bookmarksview,omitempty"` NumConns int `json:"numconns"` + WebShareLimit int `json:"websharelimit,omitempty"` } func (tdata TelemetryData) Value() (driver.Value, error) {