ports

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const PanelStateFile = "/var/lib/nftban/panels/enabled.conf"

PanelStateFile location

Variables

This section is empty.

Functions

func AddPortToFile

func AddPortToFile(filePath string, port int, protocol string) error

AddPortToFile adds a port rule to a configuration file

func LoadEnabledPanels added in v1.0.20

func LoadEnabledPanels() ([]string, error)

LoadEnabledPanels reads the panel state file and returns enabled panel names

func RemovePortFromFile

func RemovePortFromFile(filePath string, port int) error

RemovePortFromFile removes a port rule from a configuration file

func SetPanelEnabled added in v1.0.20

func SetPanelEnabled(panelName string, enabled bool) error

SetPanelEnabled updates the panel state file to enable/disable a panel

Types

type PanelConfig added in v1.0.20

type PanelConfig struct {
	Name       string // Panel name (directadmin, cpanel, plesk)
	Enabled    bool   // Whether panel is enabled
	ConfigFile string // Path to panel config file
	TCPIn      []int  // TCP input ports
	TCPOut     []int  // TCP output ports (for OUTPUT chain)
	UDPIn      []int  // UDP input ports
	UDPOut     []int  // UDP output ports (for OUTPUT chain)
}

PanelConfig represents a control panel's port configuration

func LoadPanelConfig added in v1.0.20

func LoadPanelConfig(configDir, panelName string) (*PanelConfig, error)

LoadPanelConfig loads port configuration for a specific panel by reading its bash config file

type PortConfig

type PortConfig struct {
	TCPPorts []int            // All TCP ports (from T and B rules)
	UDPPorts []int            // All UDP ports (from U and B rules)
	AllRules []PortRule       // All rules with metadata
	PortMap  map[int][]string // port -> protocols (for deduplication)
}

PortConfig holds all port rules loaded from configuration

func LoadAllPanelPorts added in v1.0.20

func LoadAllPanelPorts(configDir string) (*PortConfig, error)

LoadAllPanelPorts loads port configuration for all enabled panels

func LoadAllPorts added in v1.0.20

func LoadAllPorts(configDir string) (*PortConfig, error)

LoadAllPorts loads ports from BOTH ports.d/ directory AND enabled panel configs

func LoadPortsFromDirectory

func LoadPortsFromDirectory(dir string) (*PortConfig, error)

LoadPortsFromDirectory loads all port configuration files from a directory Expected format: PORT/PROTOCOL where PROTOCOL is T (TCP), U (UDP), or B (Both) Example: 22/T, 53/B, 80/T

func LoadPortsFromFile

func LoadPortsFromFile(filePath string) (*PortConfig, error)

LoadPortsFromFile loads port rules from a single configuration file

func (*PortConfig) GetAllPorts

func (c *PortConfig) GetAllPorts() []int

GetAllPorts returns all unique ports regardless of protocol

func (*PortConfig) GetTCPPorts

func (c *PortConfig) GetTCPPorts() []int

GetTCPPorts returns all TCP ports (from T and B rules)

func (*PortConfig) GetUDPPorts

func (c *PortConfig) GetUDPPorts() []int

GetUDPPorts returns all UDP ports (from U and B rules)

type PortRule

type PortRule struct {
	Port     int    // Port number (e.g., 22, 80, 443)
	Protocol string // "T" (TCP), "U" (UDP), or "B" (Both)
	Source   string // Config file where this rule came from
}

PortRule represents a single port rule

Jump to

Keyboard shortcuts

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