diff --git a/cmd/run.go b/cmd/run.go index aa7ec62..17a4aa3 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -101,7 +101,7 @@ var runCmd = &cobra.Command{ lg := slog.With("backend", shareBackendFlag) - shareURI, err := backend.Apply(sharePWD, &share.VMShareContext{ + shareURL, fullURL, err := backend.Apply(sharePWD, &share.VMShareContext{ Instance: i, FileManager: fm, NetTapCtx: tapCtx, @@ -113,7 +113,19 @@ var runCmd = &cobra.Command{ lg.Info("Started the network share successfully") - fmt.Fprintf(os.Stderr, "===========================\n[Network File Share Config]\nThe network file share was started. Please use the credentials below to connect to the file server.\n\nType: "+strings.ToUpper(shareBackendFlag)+"\nURL: %v\nUsername: linsk\nPassword: %v\n===========================\n", shareURI, sharePWD) + fmt.Fprintf(os.Stderr, "===========================\n"+ + "[Network File Share Config]\n"+ + "The network file share was started. Please use the credentials below to connect to the file server.\n\n"+ + "Type: %v\n"+ + "URL: %v\n"+ + "Username: linsk\n"+ + "Password: %v\n", strings.ToUpper(shareBackendFlag), shareURL, sharePWD) + + if fullURL != "" { + fmt.Fprintf(os.Stderr, "Full URL: %v\n", fullURL) + } + + fmt.Fprintf(os.Stderr, "===========================\n") ctxWait := true diff --git a/share/afp.go b/share/afp.go index 33bab32..ac0d8ca 100644 --- a/share/afp.go +++ b/share/afp.go @@ -47,11 +47,14 @@ func NewAFPBackend(uc *UserConfiguration) (Backend, *VMShareOptions, error) { }, nil } -func (b *AFPBackend) Apply(sharePWD string, vc *VMShareContext) (string, error) { +func (b *AFPBackend) Apply(sharePWD string, vc *VMShareContext) (string, string, error) { err := vc.FileManager.StartAFP(sharePWD) if err != nil { - return "", errors.Wrap(err, "start afp server") + return "", "", errors.Wrap(err, "start afp server") } - return "afp://" + net.JoinHostPort(b.listenIP.String(), fmt.Sprint(b.sharePort)) + "/linsk", nil + shareURL := "afp://" + net.JoinHostPort(b.listenIP.String(), fmt.Sprint(b.sharePort)) + "/linsk" + fullURL := "afp://linsk:" + sharePWD + "@" + net.JoinHostPort(b.listenIP.String(), fmt.Sprint(b.sharePort)) + "/linsk" + + return shareURL, fullURL, nil } diff --git a/share/backend.go b/share/backend.go index 056f5fd..a724f1b 100644 --- a/share/backend.go +++ b/share/backend.go @@ -19,7 +19,7 @@ package share type NewBackendFunc func(uc *UserConfiguration) (Backend, *VMShareOptions, error) type Backend interface { - Apply(sharePWD string, vc *VMShareContext) (string, error) + Apply(sharePWD string, vc *VMShareContext) (shareURL string, fullURL string, err error) } var backends = map[string]NewBackendFunc{ diff --git a/share/ftp.go b/share/ftp.go index adfae9e..c490919 100644 --- a/share/ftp.go +++ b/share/ftp.go @@ -63,15 +63,18 @@ func NewFTPBackend(uc *UserConfiguration) (Backend, *VMShareOptions, error) { }, nil } -func (b *FTPBackend) Apply(sharePWD string, vc *VMShareContext) (string, error) { +func (b *FTPBackend) Apply(sharePWD string, vc *VMShareContext) (string, string, error) { if vc.NetTapCtx != nil { - return "", fmt.Errorf("net taps are unsupported in ftp") + return "", "", fmt.Errorf("net taps are unsupported in ftp") } err := vc.FileManager.StartFTP(sharePWD, b.sharePort+1, b.passivePortCount, b.extIP) if err != nil { - return "", errors.Wrap(err, "start ftp server") + return "", "", errors.Wrap(err, "start ftp server") } - return "ftp://" + b.extIP.String() + ":" + fmt.Sprint(b.sharePort), nil + shareURL := "ftp://" + net.JoinHostPort(b.extIP.String(), fmt.Sprint(b.sharePort)) + fullURL := "ftp://linsk:" + sharePWD + "@" + net.JoinHostPort(b.extIP.String(), fmt.Sprint(b.sharePort)) + + return shareURL, fullURL, nil } diff --git a/share/smb.go b/share/smb.go index d54ab63..e890ced 100644 --- a/share/smb.go +++ b/share/smb.go @@ -60,18 +60,18 @@ func NewSMBBackend(uc *UserConfiguration) (Backend, *VMShareOptions, error) { }, nil } -func (b *SMBBackend) Apply(sharePWD string, vc *VMShareContext) (string, error) { +func (b *SMBBackend) Apply(sharePWD string, vc *VMShareContext) (string, string, error) { if b.sharePort != nil && vc.NetTapCtx != nil { - return "", fmt.Errorf("conflict: configured to use a forwarded port but a net tap configuration was detected") + return "", "", fmt.Errorf("conflict: configured to use a forwarded port but a net tap configuration was detected") } if b.sharePort == nil && vc.NetTapCtx == nil { - return "", fmt.Errorf("no net tap configuration found") + return "", "", fmt.Errorf("no net tap configuration found") } err := vc.FileManager.StartSMB(sharePWD) if err != nil { - return "", errors.Wrap(err, "start smb server") + return "", "", errors.Wrap(err, "start smb server") } var shareURL string @@ -85,8 +85,13 @@ func (b *SMBBackend) Apply(sharePWD string, vc *VMShareContext) (string, error) shareURL = "smb://" + net.JoinHostPort(vc.NetTapCtx.Net.GuestIP.String(), fmt.Sprint(smbPort)) + "/linsk" } default: - return "", fmt.Errorf("no port forwarding and net tap configured") + return "", "", fmt.Errorf("no port forwarding and net tap configured") } - return shareURL, nil + if osspecifics.IsWindows() { + return shareURL, "", nil // No full URL on Windows + } + + fullURL := strings.Replace(shareURL, "smb://", "smb://linsk:"+sharePWD+"@", 1) + return shareURL, fullURL, nil }