common

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AdminExpirationTime = time.Date(2900, 1, 1, 0, 0, 0, 0, time.UTC)

AdminExpirationTime defines a far-future expiration date for the initial admin token.

Functions

func CheckSingBoxInstalled

func CheckSingBoxInstalled() bool

CheckSingBoxInstalled checks if the 'sing-box' executable is available in the system's PATH.

func GenerateBasicSingBoxServerConfig

func GenerateBasicSingBoxServerConfig(dataDir string, listenPort int) (*option.Options, error)

GenerateBasicSingBoxServerConfig creates a minimal initial sing-box server configuration. It sets up logging, a single Shadowsocks inbound listener (on a specified or random port) with a generated password, and writes the configuration to file.

func GenerateSingBoxConnectConfig

func GenerateSingBoxConnectConfig(dataDir, publicIP, username string) ([]byte, error)

GenerateSingBoxConnectConfig creates a sing-box client configuration JSON for a specific user. It reads the server's sing-box config, finds or creates the user's Shadowsocks credentials, constructs a client config pointing to the server's public IP and Shadowsocks port, and returns the marshalled JSON configuration. If the user doesn't exist, they are added to the server config, and sing-box is restarted.

func GetPublicIP

func GetPublicIP() (string, error)

GetPublicIP attempts to determine the server's public IP address by querying several external services. It iterates through a predefined list of "what's my IP" services and returns the first successful result. If all attempts fail, it returns an error.

func GetShadowsocksInboundConfig

func GetShadowsocksInboundConfig(singBoxServerConfig *option.Options) (*option.ShadowsocksInboundOptions, error)

GetShadowsocksInboundConfig extracts the Shadowsocks inbound options from a given sing-box configuration. It assumes the first inbound defined in the config is the relevant Shadowsocks inbound.

func ReadSingBoxServerConfig

func ReadSingBoxServerConfig(dataDir string) (*option.Options, error)

ReadSingBoxServerConfig reads and parses the sing-box server configuration from "sing-box-config.json" located in the specified data directory. It uses sing-box's internal JSON parsing capabilities.

func RestartSingBox

func RestartSingBox(dataDir string) error

RestartSingBox restarts the sing-box service. It either uses `systemctl restart sing-box` or, if noSystemd is true, kills any existing sing-box process and starts a new one directly using the configuration file in the data directory.

func RevokeUser

func RevokeUser(dataDir, username string) error

RevokeUser removes a user from the sing-box Shadowsocks inbound configuration. It reads the current config, finds the user by name in the first inbound's user list, removes them, writes the updated config back, and restarts the sing-box service.

func ValidateSingBoxConfig added in v0.0.3

func ValidateSingBoxConfig(dataDir string) error

ValidateSingBoxConfig uses the 'sing-box check' command to validate the syntax of the configuration file located at "sing-box-config.json" in the data directory.

func WriteSingBoxServerConfig

func WriteSingBoxServerConfig(dataDir string, opt *option.Options) error

WriteSingBoxServerConfig marshals the provided sing-box options into JSON and writes it to "sing-box-config.json" in the specified data directory.

Types

type ServerConfig

type ServerConfig struct {
	// ExternalIP is the publicly accessible IP address of the server.
	ExternalIP string `json:"external_ip"`
	// Port is the port number the API server listens on.
	Port int `json:"port"`
	// AccessToken is the initial administrative access token.
	AccessToken string `json:"access_token"`
	// HMACSecret is the secret key used for signing and verifying JWT tokens.
	HMACSecret []byte `json:"hmac_secret"`
}

ServerConfig holds the core configuration for the Lantern Server Manager API server.

func GenerateServerConfig

func GenerateServerConfig(dataDir string, listenPort int) (*ServerConfig, error)

GenerateServerConfig creates a new initial server configuration. It attempts to detect the public IP, generates a random API port if not provided, creates a strong HMAC secret, generates an initial admin access token with a very long expiration time, and writes the configuration to "server.json" in the specified data directory.

func ReadServerConfig

func ReadServerConfig(dataDir string) (*ServerConfig, error)

ReadServerConfig reads the server configuration from the "server.json" file located in the specified data directory. It unmarshalls the JSON data into a ServerConfig struct and performs basic validation.

func (*ServerConfig) GetNewServerURL

func (c *ServerConfig) GetNewServerURL() string

GetNewServerURL generates the URL used by the Lantern VPN app to configure a new private server. It includes the server's external IP, API port, and the admin access token.

func (*ServerConfig) GetQR

func (c *ServerConfig) GetQR() string

GetQR generates a string representation of a QR code for the server URL. This QR code can be scanned by the Lantern VPN app.

Jump to

Keyboard shortcuts

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