sysproxy

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package sysproxy toggles the operating system's HTTP/HTTPS proxy so that every application on the machine sends its traffic through pano.

On macOS the package drives /usr/sbin/networksetup. Before it changes anything it snapshots the proxy configuration of every enabled network service to a small JSON state file; Disable (and RestoreStale after a crash) put the exact previous settings back and delete the file. The presence of the state file is therefore the single source of truth for "pano owns the system proxy right now".

On other operating systems Manager.Supported reports false and Enable returns an error pointing at the per-process alternatives (pano run --, or the HTTP_PROXY/HTTPS_PROXY environment variables).

Index

Constants

This section is empty.

Variables

View Source
var DefaultBypass = []string{"localhost", "127.0.0.1", "*.local", "169.254/16"}

DefaultBypass lists the destinations that must never be routed through the proxy. They are always merged into the bypass list written by Enable.

View Source
var ErrUnsupported = errors.New("sysproxy: changing the system proxy is not supported on this OS; " +
	"use `pano run -- <cmd>` or set HTTP_PROXY/HTTPS_PROXY for the processes you want to capture")

ErrUnsupported is returned by Enable on platforms where pano cannot change the system proxy.

Functions

This section is empty.

Types

type Manager

type Manager interface {
	// Supported reports whether this build and host can change the system
	// proxy at all.
	Supported() bool

	// Enable snapshots the current settings of every enabled network service
	// to the state file BEFORE changing anything, then points the HTTP and
	// HTTPS proxies of each service at host:port and sets the bypass domain
	// list. The bypass list written is the union of the service's existing
	// list, DefaultBypass and bypass.
	//
	// It also turns off automatic proxy configuration (PAC URL and WPAD
	// auto-discovery) on every service: Chrome and most macOS apps use a PAC
	// INSTEAD of the manual proxies, so leaving one on (a corporate agent's,
	// say) would silently route traffic around pano. Disable puts it back.
	//
	// If a snapshot already exists (pano is already enabled, or a previous
	// daemon crashed without restoring) it is kept rather than overwritten,
	// so a later Disable still restores the settings that predate pano.
	Enable(ctx context.Context, host string, port int, bypass []string) error

	// Disable restores the snapshot — the exact previous host, port and
	// enabled state of every service — and deletes the state file. It is
	// idempotent: with no state file there is nothing to do. Per-service
	// failures do not stop the restore of the remaining services; they are
	// joined into the returned error and the state file is kept so the
	// restore can be retried.
	Disable(ctx context.Context) error

	// Status reports the current state: whether a snapshot exists (pano set
	// the proxy), which services currently point at host:port, and a short
	// human-readable detail line.
	Status(ctx context.Context, host string, port int) (api.SysProxy, error)

	// RestoreStale restores the previous settings if a state file exists. It
	// is used at daemon start and by `pano doctor` to clean up after a crash.
	// It reports whether anything was restored.
	RestoreStale(ctx context.Context) (bool, error)
}

Manager toggles the OS-level HTTP/HTTPS proxy. Implementations are safe for concurrent use; Enable, Disable and RestoreStale are serialised.

func New

func New(statePath string, logger *slog.Logger) Manager

New returns a Manager for this platform. Changing the system proxy is only implemented on macOS; elsewhere the returned Manager reports Supported() == false and Enable returns ErrUnsupported.

Jump to

Keyboard shortcuts

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