router

package
v0.0.0-...-fdbed69 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PageDeviceInfo = "status_dev_info_t.gch"
	PagePONStatus  = "pon_status_link_info_t.gch"
	PageWANStatus  = "IPv46_status_wan2_if_t.gch"
	PageWLANStatus = "status_wlanm_info1_t.gch"
	PageLANStatus  = "pon_status_lan_info_t.gch"
	PageVoIPStatus = "status_voip_4less_t.gch"
)

Status pages

View Source
const (
	PageWANConfig   = "IPv46_net_wan2_conf_t.gch"
	PagePortBinding = "net_portbinding_t.gch"
)

Network - WAN pages

View Source
const (
	PageWLANBasic    = "net_wlanm_conf1_t.gch"
	PageWLANSSID     = "net_wlanm_essid1_t.gch"
	PageWLANSecurity = "net_wlanm_secrity1_t.gch"
	PageWLANACL      = "net_wlanm_acl1_t.gch"
	PageWLANAssocDev = "net_wlanm_assoc1_t.gch"
	PageWLANWMM      = "net_wlanm_wmm1_t.gch"
	PageWLANWPS      = "net_wlanm_wps1_t.gch"
)

Network - WLAN pages

View Source
const (
	PageDHCPServer  = "net_dhcp_dynamic_t.gch"
	PageDHCPBinding = "net_dhcp_bind_t.gch"
	PageDHCPPortSvc = "net_dhcp_portservice_t.gch"
)

Network - LAN pages

View Source
const (
	PagePONLOID = "pon_net_ponloid_t.gch"
	PagePONSN   = "pon_net_sn_t.gch"
)

Network - PON pages

View Source
const (
	PageRouteDefault = "net_route_default_t.gch"
	PageStaticRoute  = "net_route_static_t.gch"
	PagePolicyRoute  = "net_route_policy_t.gch"
	PageRouteTable   = "net_route_table_t.gch"
)

Network - Routing pages

View Source
const (
	PageFirewall    = "sec_firewall_conf_t.gch"
	PageIPFilter    = "sec_portfilter_conf_t.gch"
	PageMACFilter   = "sec_macfilter_conf_t.gch"
	PageURLFilter   = "sec_url_filter_t.gch"
	PageServiceCtrl = "sec_service_ctrl_t.gch"
	PageALG         = "sec_alg_conf_t.gch"
)

Security pages

View Source
const (
	PageDDNS        = "app_ddns_conf_t.gch"
	PageDMZ         = "app_dmz_conf_t.gch"
	PageUPnP        = "app_upnp_conf_t.gch"
	PageUPnPMapping = "app_upnp_portmap_t.gch"
	PagePortForward = "app_virtual_conf_t.gch"
	PagePortTrigger = "app_port_trigger_t.gch"
	PageDNSService  = "app_dns_conf_t.gch"
	PageSNTP        = "app_sntp_conf_t.gch"
	PageUSBStorage  = "app_usb_storage_t.gch"
	PageSamba       = "app_samba_conf_t.gch"
	PageFTP         = "app_ftp_conf_t.gch"
)

Application pages

View Source
const (
	PageTR069        = "net_tr069_basic_t.gch"
	PageUserMgmt     = "manager_aduser_conf_t.gch"
	PageLoginTimeout = "manager_login_timeout_t.gch"
	PageReboot       = "manager_dev_conf_t.gch"
	PageSWUpgrade    = "manager_dev_version_t.gch"
	PageConfigMgmt   = "manager_dev_conf_backup_t.gch"
	PageLogMgmt      = "manager_log_conf_t.gch"
	PagePing         = "manager_dev_ping_t.gch"
	PageTraceroute   = "manager_dev_traceroute_t.gch"
	PageARPMacTable  = "manager_arp_table_t.gch"
)

Administration pages

Variables

This section is empty.

Functions

func AddIPFilterRule

func AddIPFilterRule(client *Client, rule IPFilterRule) (bool, error)

AddIPFilterRule adds a new IP filter rule.

func AddMACFilterRule

func AddMACFilterRule(client *Client, rule MACFilterRule) (bool, error)

AddMACFilterRule adds a new MAC filter rule.

func AddPortForwardRule

func AddPortForwardRule(client *Client, rule PortForwardRule) (bool, error)

AddPortForwardRule adds a new port forwarding rule.

func AddURLFilterRule

func AddURLFilterRule(client *Client, rule URLFilterRule) (bool, error)

AddURLFilterRule adds a new URL filter rule.

func ChangePassword

func ChangePassword(client *Client, oldPass, newPass, confirmPass string) (bool, error)

ChangePassword changes the router admin/user password.

func CreateWANConnection

func CreateWANConnection(client *Client, conn WANConnection) (bool, error)

CreateWANConnection creates a new WAN connection.

func Decrypt

func Decrypt(encryptedBase64 string, sessionToken string) (string, error)

Decrypt decrypts an AES-CBC ZeroPadding encrypted string (as used by CryptoJS in the router's web UI). The encrypted string is base64-encoded.

func DeleteIPFilterRule

func DeleteIPFilterRule(client *Client, ruleName string) (bool, error)

DeleteIPFilterRule deletes an IP filter rule by name.

func DeleteMACFilterRule

func DeleteMACFilterRule(client *Client, srcMAC string) (bool, error)

DeleteMACFilterRule deletes a MAC filter rule by source MAC.

func DeletePortForwardRule

func DeletePortForwardRule(client *Client, ruleName string) (bool, error)

DeletePortForwardRule deletes a port forwarding rule by name.

func DeleteURLFilterRule

func DeleteURLFilterRule(client *Client, urlStr string) (bool, error)

DeleteURLFilterRule deletes a URL filter rule by URL.

func DeleteWANConnection

func DeleteWANConnection(client *Client, connName string) (bool, error)

DeleteWANConnection deletes a WAN connection by name.

func DisplayStatusItem

func DisplayStatusItem(client *Client, pageName string) ([]string, error)

DisplayStatusItem fetches a status page and returns formatted lines. Uses custom parsers when available, falls back to generic table parser.

func Encrypt

func Encrypt(plaintext string, sessionToken string) (string, error)

Encrypt encrypts a plaintext string using AES-CBC ZeroPadding (CryptoJS compatible). Returns a base64-encoded ciphertext string.

func FactoryReset

func FactoryReset(client *Client) (bool, error)

FactoryReset sends a factory reset command.

func FetchARPTable

func FetchARPTable(client *Client) (string, error)

FetchARPTable fetches the ARP table from the router.

func FetchTimeout

func FetchTimeout(client *Client) (int, error)

FetchTimeout retrieves the current session timeout value in minutes.

func FetchWANConfig

func FetchWANConfig(client *Client) (string, error)

FetchWANConfig fetches WAN connection configuration page.

func FormatDDNSSettings

func FormatDDNSSettings(s *DDNSSettings) string

FormatDDNSSettings formats DDNS settings for display.

func FormatDHCPLeases

func FormatDHCPLeases(leases []DHCPLease) string

FormatDHCPLeases formats DHCP leases for display.

func FormatDHCPSettings

func FormatDHCPSettings(s *DHCPSettings) string

FormatDHCPSettings formats DHCP settings for display.

func FormatDMZSettings

func FormatDMZSettings(s *DMZSettings) string

FormatDMZSettings formats DMZ settings for display.

func FormatFirewallSettings

func FormatFirewallSettings(s *FirewallSettings) string

FormatFirewallSettings formats firewall settings for display.

func FormatIPFilterRules

func FormatIPFilterRules(rules []IPFilterRule) string

FormatIPFilterRules formats IP filter rules for display.

func FormatLogs

func FormatLogs(logs []LogEntry, limit int) string

FormatLogs formats log entries for display.

func FormatMACFilterRules

func FormatMACFilterRules(rules []MACFilterRule) string

FormatMACFilterRules formats MAC filter rules for display.

func FormatPortForwardRules

func FormatPortForwardRules(rules []PortForwardRule) string

FormatPortForwardRules formats port forwarding rules for display.

func FormatUPnPSettings

func FormatUPnPSettings(s *UPnPSettings) string

FormatUPnPSettings formats UPnP settings for display.

func FormatURLFilterRules

func FormatURLFilterRules(rules []URLFilterRule) string

FormatURLFilterRules formats URL filter rules for display.

func FormatWANConnections

func FormatWANConnections(conns []WANConnection) string

FormatWANConnections formats WAN connections for display.

func FormatWiFiBasicSettings

func FormatWiFiBasicSettings(s *WiFiBasicSettings) string

FormatWiFiBasicSettings formats WiFi basic settings for display.

func GenerateQR

func GenerateQR(data string) (string, error)

GenerateQR generates an ASCII QR code string for terminal display. Uses a simple encoding approach — falls back to manual rendering if external QR library is not available.

func ParseGenericTable

func ParseGenericTable(html string) []string

ParseGenericTable extracts key-value pairs from a table with tdleft/tdright classes.

func Ping

func Ping(client *Client, host string) (string, error)

Ping runs a ping test from the router.

func ReadResponseBody

func ReadResponseBody(resp *http.Response) string

ReadResponseBody reads the full response body and returns it as a string.

func Reboot

func Reboot(client *Client) (bool, error)

Reboot sends a reboot command to the router.

func RebootDevice

func RebootDevice(client *Client) (bool, error)

RebootDevice sends a reboot command.

func SHA256Hex

func SHA256Hex(text string) string

SHA256Hex returns the hex-encoded SHA256 hash of the input string.

func SetDDNSSettings

func SetDDNSSettings(client *Client, settings DDNSSettings) (bool, error)

SetDDNSSettings updates DDNS configuration.

func SetDHCPSettings

func SetDHCPSettings(client *Client, settings DHCPSettings) (bool, error)

SetDHCPSettings updates DHCP server configuration.

func SetDMZSettings

func SetDMZSettings(client *Client, settings DMZSettings) (bool, error)

SetDMZSettings updates DMZ configuration.

func SetFirewallSettings

func SetFirewallSettings(client *Client, settings FirewallSettings) (bool, error)

SetFirewallSettings updates firewall configuration.

func SetPortForwardEnable

func SetPortForwardEnable(client *Client, ruleName string, enable bool) (bool, error)

SetPortForwardEnable enables or disables a port forwarding rule.

func SetTimeout

func SetTimeout(client *Client, minutes int) (bool, error)

SetTimeout changes the session timeout (1-30 minutes).

func SetUPnPSettings

func SetUPnPSettings(client *Client, settings UPnPSettings) (bool, error)

SetUPnPSettings updates UPnP configuration.

func SetWiFiBasicSettings

func SetWiFiBasicSettings(client *Client, settings WiFiBasicSettings) (bool, error)

SetWiFiBasicSettings updates WiFi basic configuration.

func SetWiFiChannel

func SetWiFiChannel(client *Client, channel string) (bool, error)

SetWiFiChannel sets the WiFi channel.

func SetWiFiPassword

func SetWiFiPassword(client *Client, password string) (bool, error)

SetWiFiPassword changes the Wi-Fi password (WPA KeyPassphrase).

func SetWiFiRFMode

func SetWiFiRFMode(client *Client, enabled bool) (bool, error)

SetWiFiRFMode enables or disables the WiFi radio.

func SetWiFiSSID

func SetWiFiSSID(client *Client, ssid string) (bool, error)

SetWiFiSSID changes the Wi-Fi SSID name.

func SetWiFiTransmitPower

func SetWiFiTransmitPower(client *Client, power string) (bool, error)

SetWiFiTransmitPower sets the WiFi transmit power.

Types

type Client

type Client struct {
	Host         string
	Username     string
	Password     string
	BaseURL      string
	SessionToken string
	// contains filtered or unexported fields
}

Client manages HTTP communication with the ZTE router.

func NewClient

func NewClient(host, username, password string) (*Client, error)

NewClient creates a new router client with the given credentials.

func (*Client) GetPage

func (c *Client) GetPage(pageName string) (string, error)

GetPage fetches a .gch page from the router using the active session. It also refreshes the session_token from the response.

func (*Client) Login

func (c *Client) Login() (bool, error)

Login authenticates with the router using the reverse-engineered flow: 1. GET login page to extract dynamic tokens 2. Generate random number, hash password with SHA256 3. POST login credentials 4. GET template.gch to establish session and extract session_token

func (*Client) PostAction

func (c *Client) PostAction(pageName string, formData string) (string, error)

PostAction sends a form POST to a specific .gch page.

type DDNSSettings

type DDNSSettings struct {
	Enabled       bool
	ServiceType   string // dipc, dyndns, DtDNS, No-IP
	Server        string
	Username      string
	Password      string
	WANConnection string
	Domain        string
}

DDNSSettings holds DDNS configuration.

func FetchDDNSSettings

func FetchDDNSSettings(client *Client) (*DDNSSettings, error)

FetchDDNSSettings fetches DDNS configuration.

type DHCPLease

type DHCPLease struct {
	MACAddress string
	IPAddress  string
	LeaseTime  string
	HostName   string
	Port       string
}

DHCPLease represents an active DHCP lease.

func FetchDHCPLeases

func FetchDHCPLeases(client *Client) ([]DHCPLease, error)

FetchDHCPLeases fetches active DHCP leases from the DHCP page.

type DHCPSettings

type DHCPSettings struct {
	Enabled    bool
	LANIP      string
	SubnetMask string
	StartIP    string
	EndIP      string
	DNSServer1 string
	DNSServer2 string
	DNSServer3 string
	DefaultGW  string
	LeaseTime  string
	AssignISP  bool
}

DHCPSettings holds DHCP server configuration.

func FetchDHCPSettings

func FetchDHCPSettings(client *Client) (*DHCPSettings, error)

FetchDHCPSettings fetches DHCP server configuration.

type DMZSettings

type DMZSettings struct {
	Enabled       bool
	WANConnection string
	MACMapping    bool
	HostIP        string
}

DMZSettings holds DMZ configuration.

func FetchDMZSettings

func FetchDMZSettings(client *Client) (*DMZSettings, error)

FetchDMZSettings fetches DMZ configuration.

type DeviceInfo

type DeviceInfo struct {
	Model             string
	SerialNumber      string
	HardwareVersion   string
	SoftwareVersion   string
	BootLoaderVersion string
	PONSerialNumber   string
	BatchNumber       string
}

DeviceInfo holds basic router identification.

func ParseDeviceInfo

func ParseDeviceInfo(html string) DeviceInfo

ParseDeviceInfo extracts model, serial number, hardware/software version, etc.

type FirewallSettings

type FirewallSettings struct {
	AntiHacking bool
	Level       string // Off, Low, Middle, High
}

FirewallSettings holds firewall configuration.

func FetchFirewallSettings

func FetchFirewallSettings(client *Client) (*FirewallSettings, error)

FetchFirewallSettings fetches firewall configuration.

type IPFilterRule

type IPFilterRule struct {
	Enabled      bool
	Name         string
	Protocol     string // TCP, UDP, TCP AND UDP, ICMP, ANY
	SrcIPStart   string
	SrcIPEnd     string
	DstIPStart   string
	DstIPEnd     string
	SrcPortStart string
	SrcPortEnd   string
	DstPortStart string
	DstPortEnd   string
	Ingress      string // LAN, WAN connection name
	Egress       string // LAN, WAN connection name
	Mode         string // Discard, Permit
}

IPFilterRule represents an IP filter rule.

func FetchIPFilterRules

func FetchIPFilterRules(client *Client) ([]IPFilterRule, error)

FetchIPFilterRules fetches all IP filter rules.

type LANPort

type LANPort struct {
	Port        string
	Status      string
	Speed       string
	Mode        string
	PacketsRx   string
	BytesRx     string
	PacketsTx   string
	BytesTx     string
	ErrorFrames string
}

LANPort holds Ethernet port details.

func FetchLANStatus

func FetchLANStatus(client *Client) ([]LANPort, error)

FetchLANStatus fetches Ethernet port details.

func ParseLANStatus

func ParseLANStatus(html string) []LANPort

ParseLANStatus extracts Ethernet port status from HTML tables.

type LogEntry

type LogEntry struct {
	Timestamp string
	Level     string
	Message   string
}

LogEntry represents a system log entry.

func FetchLogs

func FetchLogs(client *Client) ([]LogEntry, error)

FetchLogs fetches system logs from the router.

type MACFilterRule

type MACFilterRule struct {
	Enabled  bool
	Mode     string // Discard
	Type     string // Bridge, Route, Bridge+Route
	Protocol string // IP, ARP, RARP, PPPoE, ALL
	SrcMAC   string
	DstMAC   string
}

MACFilterRule represents a MAC filter rule.

func FetchMACFilterRules

func FetchMACFilterRules(client *Client) ([]MACFilterRule, error)

FetchMACFilterRules fetches all MAC filter rules.

type PONStatus

type PONStatus struct {
	GPONState   string
	RxPower     string // dBm
	TxPower     string // dBm
	Voltage     string // uV
	BiasCurrent string // uA
	Temperature string // C
}

PONStatus holds optical module readings.

func ParsePONStatus

func ParsePONStatus(html string) PONStatus

ParsePONStatus extracts optical power, state, and module details.

type PortForwardRule

type PortForwardRule struct {
	Enabled        bool
	Name           string
	Protocol       string // TCP, UDP, TCP AND UDP
	WANHostStartIP string
	WANHostEndIP   string
	WANConnection  string
	WANStartPort   string
	WANEndPort     string
	MACMapping     bool
	LANHostIP      string
	LANStartPort   string
	LANEndPort     string
}

PortForwardRule represents a single port forwarding rule.

func FetchPortForwardRules

func FetchPortForwardRules(client *Client) ([]PortForwardRule, error)

FetchPortForwardRules fetches all port forwarding rules.

type StatusPageParser

type StatusPageParser func(html string) []string

StatusPageParser is a function that parses a specific page and returns display lines.

type SystemStatus

type SystemStatus struct {
	Device DeviceInfo
	PON    PONStatus
	WAN    WANStatus
	WLANs  []WLANInterface
	LANs   []LANPort
}

SystemStatus is the consolidated status snapshot.

func FetchStatus

func FetchStatus(client *Client) (*SystemStatus, error)

FetchStatus fetches and consolidates full system status.

type UPnPSettings

type UPnPSettings struct {
	Enabled           bool
	IPv4WANConnection string
	AdvPeriod         string // minutes
	AdvTTL            string // hops
}

UPnPSettings holds UPnP configuration.

func FetchUPnPSettings

func FetchUPnPSettings(client *Client) (*UPnPSettings, error)

FetchUPnPSettings fetches UPnP configuration.

type URLFilterRule

type URLFilterRule struct {
	Enabled bool
	Mode    string // Discard, Permit
	URL     string
}

URLFilterRule represents a URL filter rule.

func FetchURLFilterRules

func FetchURLFilterRules(client *Client) ([]URLFilterRule, error)

FetchURLFilterRules fetches all URL filter rules.

type WANConnection

type WANConnection struct {
	Name         string
	Type         string // Route, Bridge
	ServiceList  string // INTERNET, TR069, VoIP, etc.
	MTU          string
	LinkType     string // PPP, IP
	IPVersion    string // IPv4, IPv6, IPv4/v6
	PPPTransType string // PPPoE
	Username     string
	Password     string
	AuthType     string // Auto, PAP, CHAP
	ConnTrigger  string // Always On, On Demand, Manual
	NATEnabled   bool
	VLANEnabled  bool
	VLANID       string
	Status       string // Connected, Disconnected
	IPAddress    string
}

WANConnection holds WAN connection details.

func FetchWANConnections

func FetchWANConnections(client *Client) ([]WANConnection, error)

FetchWANConnections fetches list of WAN connections from the status page.

type WANStatus

type WANStatus struct {
	ConnectionName   string
	IPVersion        string
	NAT              string
	IPAddress        string
	SubnetMask       string
	Gateway          string
	DNS              string
	ConnectionStatus string
	OnlineDuration   string
	DisconnectReason string
	WANMAC           string
}

WANStatus holds WAN connection details.

func ParseWANStatus

func ParseWANStatus(html string) WANStatus

ParseWANStatus extracts WAN connection details from the status page. The WAN page uses <input id="..." value="..."> elements rather than Transfer_meaning.

type WLANInterface

type WLANInterface struct {
	Index       int
	Enabled     bool
	SSIDName    string
	AuthType    string
	EncryptType string
	MACAddress  string
	PacketsRx   string
	PacketsTx   string
	BytesRx     string
	BytesTx     string
	ErrorsRx    string
	ErrorsTx    string
	DiscardedRx string
	DiscardedTx string
	Channel     string
	RadioStatus bool
}

WLANInterface holds Wi-Fi interface details.

func FetchWLANStatus

func FetchWLANStatus(client *Client) ([]WLANInterface, error)

FetchWLANStatus fetches Wi-Fi interface details.

func ParseWLANStatus

func ParseWLANStatus(html string) []WLANInterface

ParseWLANStatus extracts Wi-Fi interface details for all 4 SSIDs.

type WLANSecurity

type WLANSecurity struct {
	SSID        string
	Password    string
	AuthType    string
	EncryptType string
	BeaconType  string
}

WLANSecurity holds Wi-Fi security configuration.

func FetchWLANSecurity

func FetchWLANSecurity(client *Client) (*WLANSecurity, error)

FetchWLANSecurity fetches and decrypts Wi-Fi security settings.

type WiFiBasicSettings

type WiFiBasicSettings struct {
	RFMode         string // Enabled, Disabled, Scheduled
	Mode           string // 802.11 mode
	Country        string
	BandWidth      string // 20MHz, 40MHz, Auto
	Channel        string // Auto, 1-13
	SGIEnabled     bool
	BeaconInterval string
	TransmitPower  string // 100%, 80%, 60%, 40%, 20%
	QoSType        string // Disabled, WMM, SSID
	RTSThreshold   string
	DTIMInterval   string
}

WiFiBasicSettings holds WiFi basic configuration.

func FetchWiFiBasicSettings

func FetchWiFiBasicSettings(client *Client) (*WiFiBasicSettings, error)

FetchWiFiBasicSettings fetches WiFi basic configuration.

Jump to

Keyboard shortcuts

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