localsrv

package
v1.12.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package localsrv implements the "Local Services" tool: a set of small built-in servers (HTTP, TFTP, SSH/SFTP, FTP) that let other machines on the network reach files on this host. Each server runs in its own goroutine and streams log lines back to the frontend as Wails events.

Index

Constants

View Source
const (
	EventLog   = "localsrv:log"   // {service, id, message}
	EventState = "localsrv:state" // {service, id, running}
)

Event names emitted by local servers. Every payload carries "service" and "id".

Variables

This section is empty.

Functions

This section is empty.

Types

type Emitter

type Emitter func(name string, payload any)

Emitter forwards server events to the frontend (wired to Wails' event bus).

type FTPConfig

type FTPConfig struct {
	RootDir        string `json:"rootDir"`
	Port           int    `json:"port"`
	Username       string `json:"username"`
	Password       string `json:"password"`
	Anonymous      bool   `json:"anonymous"`
	UTF8           bool   `json:"utf8"`
	TimeoutSeconds int    `json:"timeoutSeconds"` // 0 = no auto-stop
}

FTPConfig holds the parameters for the FTP server.

type HTTPConfig

type HTTPConfig struct {
	RootDir        string `json:"rootDir"`
	Port           int    `json:"port"`
	ListDir        bool   `json:"listDir"`
	TimeoutSeconds int    `json:"timeoutSeconds"` // 0 = no auto-stop
}

HTTPConfig holds the parameters for the HTTP file server.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns the lifecycle of all running local servers (HTTP, TFTP, SSH, FTP). Each started server gets a unique id and a cancellable context; Stop/StopAll cancel the workers so no goroutines leak when the dialog closes or the app exits.

func NewManager

func NewManager() *Manager

func (*Manager) SetEventEmitter

func (m *Manager) SetEventEmitter(fn Emitter)

SetEventEmitter wires the manager to the frontend event bus.

func (*Manager) StartFTPServer

func (m *Manager) StartFTPServer(cfg FTPConfig) (string, error)

StartFTPServer starts an FTP server serving rootDir on the given port. Authentication is by username/password; when anonymous is true, any login is accepted. Returns the server id.

func (*Manager) StartHTTPServer

func (m *Manager) StartHTTPServer(cfg HTTPConfig) (string, error)

StartHTTPServer starts an HTTP file server serving rootDir on the given port. With listDir enabled, directory requests render the directory listing (index.html stays reachable under its explicit name). With listDir disabled, directory requests serve index.html when one is present and 404 when not. Returns the server id.

func (*Manager) StartNFSServer

func (m *Manager) StartNFSServer(cfg NFSConfig) (string, error)

StartNFSServer starts an experimental NFSv4 server backed by an in-memory filesystem. Any data written to the mount is lost when the server stops — real OS file-system support is tracked as a future enhancement. Returns the server id.

func (*Manager) StartS3Server

func (m *Manager) StartS3Server(cfg S3Config) (string, error)

StartS3Server starts an experimental S3-compatible server that exposes the local directory cfg.RootDir as an object store over the Amazon S3 REST API.

Buckets map to sub-directories of RootDir and objects map to files (the object key is the path relative to the bucket directory). Only a practical subset of S3 is implemented — enough for standard S3 clients (e.g. `mc --no-sign-request`, `aws s3 --no-sign-request`) to create buckets and upload / download / list / delete objects. Returns the server id.

The access/secret keys are accepted for compatibility with clients that send them, but signatures are not cryptographically verified (experimental).

func (*Manager) StartSSHServer

func (m *Manager) StartSSHServer(cfg SSHConfig) (string, error)

StartSSHServer starts an SSH server on the given port serving an interactive local shell, TCP forwarding and an SFTP subsystem restricted to rootDir. Authentication is by username/password; both are required — the shell grants full access to this machine. Returns the server id.

func (*Manager) StartTFTPServer

func (m *Manager) StartTFTPServer(cfg TFTPConfig) (string, error)

StartTFTPServer starts a TFTP server serving rootDir on the given UDP port. blockSize overrides the default 512-byte block size when the client requests option negotiation. Returns the server id.

func (*Manager) StartTelnetServer

func (m *Manager) StartTelnetServer(cfg TelnetConfig) (string, error)

StartTelnetServer starts a Telnet server listening on the given TCP port. Each incoming connection is authenticated with cfg.Password, then bridged to a local cmd.exe shell (Windows) or the default shell on other platforms. The password is required: the shell grants full access to this machine. Returns the server id.

func (*Manager) Stop

func (m *Manager) Stop(id string)

Stop cancels a running server. A no-op for unknown or finished ids, so the frontend can call it unconditionally.

func (*Manager) StopAll

func (m *Manager) StopAll()

StopAll cancels every running server (app-shutdown safety net).

type NFSConfig

type NFSConfig struct {
	Port           int `json:"port"`
	TimeoutSeconds int `json:"timeoutSeconds"` // 0 = no auto-stop
}

NFSConfig holds the parameters for the NFS server.

type S3Config

type S3Config struct {
	RootDir        string `json:"rootDir"`
	Port           int    `json:"port"`
	AccessKey      string `json:"accessKey"`
	SecretKey      string `json:"secretKey"`
	TimeoutSeconds int    `json:"timeoutSeconds"` // 0 = no auto-stop
}

S3Config holds the parameters for the S3-compatible server.

type SSHConfig

type SSHConfig struct {
	RootDir        string `json:"rootDir"`
	Port           int    `json:"port"`
	Username       string `json:"username"`
	Password       string `json:"password"`
	TimeoutSeconds int    `json:"timeoutSeconds"` // 0 = no auto-stop
}

SSHConfig holds the parameters for the SSH server (interactive shell + SFTP). Username and password are required: the shell grants full access to this machine.

type Service

type Service string

Service identifies one of the built-in servers.

const (
	ServiceHTTP   Service = "http"
	ServiceTFTP   Service = "tftp"
	ServiceSSH    Service = "ssh"
	ServiceFTP    Service = "ftp"
	ServiceTelnet Service = "telnet"
	ServiceNFS    Service = "nfs"
	ServiceS3     Service = "s3"
)

type TFTPConfig

type TFTPConfig struct {
	RootDir        string `json:"rootDir"`
	Port           int    `json:"port"`
	BlockSize      int    `json:"blockSize"`
	TimeoutSeconds int    `json:"timeoutSeconds"` // 0 = no auto-stop
}

TFTPConfig holds the parameters for the TFTP server.

type TelnetConfig

type TelnetConfig struct {
	Port           int    `json:"port"`
	Password       string `json:"password"`
	TimeoutSeconds int    `json:"timeoutSeconds"` // 0 = no auto-stop
}

TelnetConfig holds the parameters for the Telnet server. The password is required: the shell grants full access to this machine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址