shell

package
v0.0.0-...-4a743d4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package contains internal logic and processing of utilities before launch.

Package describes the operation of the server's internal utilities.

Index

Constants

View Source
const (
	// Add Rules.
	SysctlIpv4Up string = "sysctl -w net.ipv4.ip_forward=1"
	SysctlIpv6Up string = "sysctl -w net.ipv6.conf.all.forwarding=1"
	// Delete Rules.
	SysctlIpv4Down string = "sysctl -w net.ipv4.ip_forward=0"
	SysctlIpv6Down string = "sysctl -w net.ipv6.conf.all.forwarding=0"
	// Check Rules.
	SysctlIpv4Check string = "sysctl net.ipv4.ip_forward"
	SysctlIpv6Check string = "sysctl net.ipv6.conf.all.forwarding"
	// Execute Rules.
	SysctlRules string = "sysctl -p"
)
View Source
const (
	// Command: ip.
	IpJSON      string = "ip -j addr"
	IpBriefJSON string = "ip -j -br addr"

	// Command: iptables.
	IptablesFirewall string = "iptables -L -v -n"
	IptablesNat      string = "iptables -t nat -L -v"
)

Variables

This section is empty.

Functions

func FormatCmdAwgAddPeer

func FormatCmdAwgAddPeer(iface, pk, aips, kp, epoint string) string

Function creates the 'awg set <interface> peer <publicKey> allowed-ips <allowedIPs> [persistent-keepalive <keepalive>] [endpoint <endpoint>]' command string. This command is used to add a new peer to a specified WireGuard interface, optionally including persistent keepalive and endpoint settings.

func FormatCmdAwgDeletePeer

func FormatCmdAwgDeletePeer(iface, pk string) string

func FormatCmdAwgShow

func FormatCmdAwgShow(iface string) string

Function creates the 'awg show <interface>' command string. This command is used to display the configuration and status of a specific WireGuard interface.

func FormatCmdAwgUpdatePort

func FormatCmdAwgUpdatePort(iface, port string) string

Function creates the 'awg set <interface> listen-port <port>' command string. This command is used to update the listening port of a specific WireGuard interface.

func FormatCmdAwgUpdatePrivateKey

func FormatCmdAwgUpdatePrivateKey(iface, pk string) string

Function creates the 'awg set <interface> private-key <(echo '<privateKey>')' command string. This command is used to set the private key for a specific WireGuard interface using a secure shell redirection.

func FormatCmdIpAddrDev

func FormatCmdIpAddrDev(iface, ip string, flag IpFlagString) string

Function generates the `ip` command to add or remove an IP address.

func FormatCmdIpLinkDelete

func FormatCmdIpLinkDelete(iface string) string

Function generate the `ip` command when deleting.

func FormatCmdIpLinkSet

func FormatCmdIpLinkSet(iface string, flag IpFlagString) string

Function generates the `ip` command to control the status of the network interface.

func FormatCmdIpShowJSON

func FormatCmdIpShowJSON(iface string) string

Function constructs the 'ip link show' command for a given interface.

func FormatCmdIptablesFirewall

func FormatCmdIptablesFirewall(flag IpFlagString, osIface, wgIface string) string

Function generates the `iptables` command to manage the firewall rules.

func FormatCmdIptablesFirewallPort

func FormatCmdIptablesFirewallPort(flag IpFlagString, dport string) string

Function generates an iptables command to manage (add/remove) an INGRESS rule for UDP traffic on the specified destination port.

func FormatCmdIptablesNat

func FormatCmdIptablesNat(flag IpFlagString, osIface, subnet string) string

Function generates the `iptables` command to manage the NAT rules.

func GetNetInterfaceNameLinux

func GetNetInterfaceNameLinux() string

Function to get active Linux network interface.

func ShellCommand

func ShellCommand(cmd string, shell bool) error

Function of executing commands in the system shell.

func ShellCommandOutput

func ShellCommandOutput(cmd string) (*bytes.Buffer, error)

Function executes a command in the system shell and returns the combined stdout and stderr output. Returns the output of the command as a *bytes.Buffer and an error, if any.

Types

type IpFlagString

type IpFlagString string
const (
	IpUp        IpFlagString = "up"
	IpDown      IpFlagString = "down"
	IpAdd       IpFlagString = "add"
	IpDel       IpFlagString = "del"
	IpTablesAdd IpFlagString = "A"
	IpTablesDel IpFlagString = "D"
)

Jump to

Keyboard shortcuts

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