From b383ad24409692e64c505bc1fc881db861f5e27d Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 24 Jan 2025 13:44:01 -0800 Subject: [PATCH 1/5] Fix connparse for wsl connections --- pkg/remote/connparse/connparse.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/remote/connparse/connparse.go b/pkg/remote/connparse/connparse.go index 4f045e637c..1114c3dfd5 100644 --- a/pkg/remote/connparse/connparse.go +++ b/pkg/remote/connparse/connparse.go @@ -23,6 +23,7 @@ const ( ) var windowsDriveRegex = regexp.MustCompile(`^[a-zA-Z]:`) +var wslConnRegex = regexp.MustCompile(`^wsl://[^/]+`) type Connection struct { Scheme string @@ -117,12 +118,17 @@ func ParseURI(uri string) (*Connection, error) { remotePath = rest } } else { - split = strings.SplitN(rest, "/", 2) - host = split[0] - if len(split) > 1 { - remotePath = split[1] + if strings.HasPrefix(rest, "wsl://") { + host = wslConnRegex.FindString(rest) + remotePath = strings.TrimPrefix(rest, host) } else { - remotePath = "/" + split = strings.SplitN(rest, "/", 2) + host = split[0] + if len(split) > 1 { + remotePath = split[1] + } else { + remotePath = "/" + } } } From 0035b6c52cbc66eb7e3200ea712c12437b60d186 Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 24 Jan 2025 13:47:43 -0800 Subject: [PATCH 2/5] add jwt token back to wsl connections --- pkg/shellexec/shellexec.go | 4 ++++ pkg/util/shellutil/tokenswap.go | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/shellexec/shellexec.go b/pkg/shellexec/shellexec.go index 1f9324116a..93c866126c 100644 --- a/pkg/shellexec/shellexec.go +++ b/pkg/shellexec/shellexec.go @@ -262,6 +262,10 @@ func StartWslShellProc(ctx context.Context, termSize waveobj.TermSize, cmdStr st conn.Debugf(ctx, "packed swaptoken %s\n", packedToken) cmdCombined = fmt.Sprintf(`%s=%s %s`, wavebase.WaveSwapTokenVarName, packedToken, cmdCombined) } + jwtToken := cmdOpts.SwapToken.Env[wavebase.WaveJwtTokenVarName] + if jwtToken != "" { + cmdCombined = fmt.Sprintf(`%s=%s %s`, wavebase.WaveJwtTokenVarName, jwtToken, cmdCombined) + } log.Printf("full combined command: %s", cmdCombined) ecmd := exec.Command("wsl.exe", "~", "-d", client.Name(), "--", "sh", "-c", cmdCombined) if termSize.Rows == 0 || termSize.Cols == 0 { diff --git a/pkg/util/shellutil/tokenswap.go b/pkg/util/shellutil/tokenswap.go index 89a16c6183..339ec6445f 100644 --- a/pkg/util/shellutil/tokenswap.go +++ b/pkg/util/shellutil/tokenswap.go @@ -20,7 +20,6 @@ type TokenSwapEntry struct { Token string `json:"token"` SockName string `json:"sockname,omitempty"` RpcContext *wshrpc.RpcContext `json:"rpccontext,omitempty"` - JwtToken string `json:"jwttoken,omitempty"` Env map[string]string `json:"env,omitempty"` ScriptText string `json:"scripttext,omitempty"` Exp time.Time `json:"-"` From d5fa489555b9e4b2dbba023e69384efd46cdfd30 Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 24 Jan 2025 14:01:09 -0800 Subject: [PATCH 3/5] implement authenticatetokencommand in wshserver.go --- pkg/wshrpc/wshserver/wshserver.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/wshrpc/wshserver/wshserver.go b/pkg/wshrpc/wshserver/wshserver.go index edc7f76294..fd575872b9 100644 --- a/pkg/wshrpc/wshserver/wshserver.go +++ b/pkg/wshrpc/wshserver/wshserver.go @@ -28,6 +28,7 @@ import ( "github.com/wavetermdev/waveterm/pkg/remote/fileshare" "github.com/wavetermdev/waveterm/pkg/telemetry" "github.com/wavetermdev/waveterm/pkg/util/envutil" + "github.com/wavetermdev/waveterm/pkg/util/shellutil" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/util/wavefileutil" "github.com/wavetermdev/waveterm/pkg/waveai" @@ -51,6 +52,19 @@ func (*WshServer) WshServerImpl() {} var WshServerImpl = WshServer{} +// TODO remove this after implementing in multiproxy, just for wsl +func (ws *WshServer) AuthenticateTokenCommand(ctx context.Context, data wshrpc.CommandAuthenticateTokenData) (wshrpc.CommandAuthenticateRtnData, error) { + entry := shellutil.GetAndRemoveTokenSwapEntry(data.Token) + if entry == nil { + return wshrpc.CommandAuthenticateRtnData{}, fmt.Errorf("invalid token") + } + rtn := wshrpc.CommandAuthenticateRtnData{ + Env: entry.Env, + InitScriptText: entry.ScriptText, + } + return rtn, nil +} + func (ws *WshServer) TestCommand(ctx context.Context, data string) error { defer func() { panichandler.PanicHandler("TestCommand", recover()) From cee9251214de49e203a1a7e41d760b570097429e Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 24 Jan 2025 14:11:09 -0800 Subject: [PATCH 4/5] allow windows paths for bg --- frontend/app/app-bg.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/app-bg.tsx b/frontend/app/app-bg.tsx index 8b1006de21..2a06f6d220 100644 --- a/frontend/app/app-bg.tsx +++ b/frontend/app/app-bg.tsx @@ -54,7 +54,7 @@ function processBackgroundUrls(cssText: string): string { return; } // allow absolute paths - if (originalUrl.startsWith("/") || originalUrl.startsWith("~/")) { + if (originalUrl.startsWith("/") || originalUrl.startsWith("~/") || /^[a-zA-Z]:(\/|\\)/.test(originalUrl)) { const newUrl = encodeFileURL(originalUrl); node.value = newUrl; return; From d4d23d8e15fd2d5aafb65c6c40e0fa879f85d4d5 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 24 Jan 2025 14:11:30 -0800 Subject: [PATCH 5/5] save --- cmd/wsh/cmd/wshcmd-setbg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/wsh/cmd/wshcmd-setbg.go b/cmd/wsh/cmd/wshcmd-setbg.go index bbd2071352..be57b9abd8 100644 --- a/cmd/wsh/cmd/wshcmd-setbg.go +++ b/cmd/wsh/cmd/wshcmd-setbg.go @@ -140,7 +140,7 @@ func setBgRun(cmd *cobra.Command, args []string) (rtnErr error) { } // Create URL-safe path - escapedPath := strings.ReplaceAll(absPath, "\\", "\\\\") + escapedPath := filepath.ToSlash(absPath) escapedPath = strings.ReplaceAll(escapedPath, "'", "\\'") bgStyle = fmt.Sprintf("url('%s')", escapedPath)