Documentation
¶
Index ¶
- Constants
- func CheckSingBoxInstalled() bool
- func CloseFirewallPort(port int)
- func GenerateBasicSingBoxServerConfig(dataDir string, listenPort int) (*option.Options, error)
- func GenerateSingBoxConnectConfig(dataDir, publicIP, username string) ([]byte, error)
- func GetPublicIP() (string, error)
- func GetShadowsocksInboundConfig(singBoxServerConfig *option.Options) (*option.ShadowsocksInboundOptions, error)
- func OpenFirewallPort(port int)
- func ReadSingBoxServerConfig(dataDir string) (*option.Options, error)
- func RestartSingBox(dataDir string) error
- func RevokeUser(dataDir, username string) error
- func ValidateSingBoxConfig(dataDir string) error
- func WriteSingBoxServerConfig(dataDir string, opt *option.Options) error
Constants ¶
const SingBoxExe = "sing-box-extensions"
Variables ¶
This section is empty.
Functions ¶
func CheckSingBoxInstalled ¶
func CheckSingBoxInstalled() bool
CheckSingBoxInstalled checks if the 'sing-box' executable is available in the system's PATH.
func CloseFirewallPort ¶ added in v0.0.19
func CloseFirewallPort(port int)
CloseFirewallPort attempts to close the specified port using firewall-cmd. If permanent is true, the rule will be removed permanently. If NO_FIREWALLD is set or firewall-cmd is not found, it logs the information and returns.
func GenerateBasicSingBoxServerConfig ¶
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 ¶
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 ¶
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 OpenFirewallPort ¶ added in v0.0.19
func OpenFirewallPort(port int)
OpenFirewallPort attempts to open the specified port using firewall-cmd. If permanent is true, the rule will be added permanently. If NO_FIREWALLD is set or firewall-cmd is not found, it logs the information and returns.
func ReadSingBoxServerConfig ¶
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 ¶
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 ¶
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
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.
Types ¶
This section is empty.