Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
9 changes: 6 additions & 3 deletions share/afp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion share/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
11 changes: 7 additions & 4 deletions share/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 11 additions & 6 deletions share/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}