homehub

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2018 License: MIT Imports: 17 Imported by: 2

README

Home Hub Client

CircleCI license

A golang client that can interact with BT Home Hub routers. Refer to the compatibility matrix to see the firmware versions supported by each release. The master branch is currently proven against firmware versions SG4B1000B540 and SG4B1A006100.

At present, only a small set of the available APIs have been implemented.

If you're looking for a command line implementation of this library, check out my Home Hub CLI.

Usage

package main

import (
	"fmt"
	"github.com/jamesnetherton/homehub-client"
)

func main() {
	hub := homehub.New("http://192.168.1.254", "admin", "p4ssw0rd")
	hub.Login()

	version, err := hub.Version()
	if err == nil {
		fmt.Printf("Home Hub Version = %s", version)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BandwidthLog added in v0.4.0

type BandwidthLog struct {
	Entries []BandwidthLogEntry
}

BandwidthLog defines a Home Hub device bandwidth log history

type BandwidthLogEntry added in v0.4.0

type BandwidthLogEntry struct {
	MACAddress        string
	Date              string
	DownloadMegabytes int
	UploadMegabytes   int
}

BandwidthLogEntry defines a Home Hub bandwidth log entry

type ConnectionDetail added in v0.3.0

type ConnectionDetail struct {
	UID                 int    `json:"uid,omitempty"`
	ConnectionTimestamp string `json:"ConnectionTimestamp,omitempty"`
	DisconnectTimestamp string `json:"DisconnectionTimestamp,omitempty"`
}

ConnectionDetail defines connection information related to a device connected to the Home Hub

type DeviceDetail added in v0.3.0

type DeviceDetail struct {
	UID                            int                `json:"uid,omitempty"`
	Alias                          string             `json:"Alias,omitempty"`
	PhysicalAddress                string             `json:"PhysAddress,omitempty"`
	IPAddress                      string             `json:"IPAddress,omitempty"`
	AddressSource                  string             `json:"AddressSource,omitempty"`
	DHCPClient                     string             `json:"DHCPClient,omitempty"`
	LeaseTimeRemaining             int                `json:"LeaseTimeRemaining,omitempty"`
	AssociatedDevice               string             `json:"AssociatedDevice,omitempty"`
	HostName                       string             `json:"HostName,omitempty"`
	Active                         bool               `json:"Active,omitempty"`
	LeaseStart                     int                `json:"LeaseStart,omitempty"`
	LeaseDuration                  int                `json:"LeaseDuration,omitempty"`
	InterfaceType                  string             `json:"InterfaceType,omitempty"`
	DetectedDeviceType             string             `json:"DetectedDeviceType,omitempty"`
	LastStateChange                string             `json:"LastStateChange,omitempty"`
	UserFriendlyName               string             `json:"UserFriendlyName,omitempty"`
	UserHostName                   string             `json:"UserHostName,omitempty"`
	UserDeviceType                 string             `json:"UserDeviceType,omitempty"`
	BlacklistEnable                bool               `json:"BlacklistEnable,omitempty"`
	UnblockHours                   int                `json:"UnblockHoursCount,omitempty"`
	Blacklisted                    bool               `json:"Blacklisted,omitempty"`
	BlacklistStatus                bool               `json:"BlacklistStatus,omitempty"`
	BlacklistedAccordingToSchedule bool               `json:"BlacklistedAccordingToSchedule,omitempty"`
	Hidden                         bool               `json:"Hidden,omitempty"`
	IPv4Addresses                  []IPAddress        `json:"IPv4Addresses,omitempty"`
	IPv6Addresses                  []IPAddress        `json:"IPv6Addresses,omitempty"`
	LastConnections                []ConnectionDetail `json:"LastConnections,omitempty"`
	ConnectionsAtLastReboot        int                `json:"ConnectionsNbreAtLastReboot,omitempty"`
}

DeviceDetail defines a device connected to the Home Hub

type EventLog added in v0.3.0

type EventLog struct {
	Entries []EventLogEntry
}

EventLog defines a Home Hub event log history

type EventLogEntry added in v0.3.0

type EventLogEntry struct {
	Timestamp string
	Type      string
	Category  string
	Message   string
}

EventLogEntry defines a Home Hub event log entry

type Hub

type Hub interface {
	BandwidthMonitor() (result *BandwidthLog, err error)
	BroadbandProductType() (result string, err error)
	ConnectedDevices() (result []DeviceDetail, err error)
	DataPumpVersion() (result string, err error)
	DataReceived() (result int64, err error)
	DataSent() (result int64, err error)
	DeviceInfo(id int) (result *DeviceDetail, err error)
	DhcpAuthoritative() (result bool, err error)
	DhcpPoolStart() (result string, err error)
	DhcpPoolEnd() (result string, err error)
	DhcpSubnetMask() (result string, err error)
	DownstreamSyncSpeed() (result int, err error)
	EnableDebug(enable bool)
	EnableDhcpAuthoritative(enable bool) (err error)
	EventLog() (result *EventLog, err error)
	HardwareVersion() (result string, err error)
	InternetConnectionStatus() (result string, err error)
	LightBrightness() (result int, err error)
	LightBrightnessSet(brightness int) (err error)
	LightEnable(enable bool) (err error)
	LightStatus() (result string, err error)
	LocalTime() (result string, err error)
	Login() (success bool, err error)
	MaintenanceFirmwareVersion() (result string, err error)
	NatRules() (result []NatRule, err error)
	NatRule(id int) (result *NatRule, err error)
	NatRuleCreate(natRule *NatRule) (err error)
	NatRuleDelete(id int) (err error)
	NatRuleUpdate(natRule NatRule) (err error)
	PublicIPAddress() (result string, err error)
	PublicSubnetMask() (result string, err error)
	Reboot() (err error)
	SambaIP() (result string, err error)
	SambaHost() (result string, err error)
	SerialNumber() (result string, err error)
	SoftwareVersion() (result string, err error)
	UpstreamSyncSpeed() (result int, err error)
	Version() (result string, err error)
	WiFiFrequency24Ghz() (result *WiFiFrequency, err error)
	WiFiFrequency24GhzChannelSet(channel int) (err error)
	WiFiFrequency5Ghz() (result *WiFiFrequency, err error)
	WiFiFrequency5GhzChannelSet(channel int) (err error)
	WiFiSecurityMode() (result string, err error)
	WiFiSSID() (result string, err error)
}

Hub defines an interface for a Home Hub client

func New

func New(URL string, username string, password string) Hub

New creates a new Hub client for interacting with the router

type HubClient added in v0.9.0

type HubClient struct {
	// contains filtered or unexported fields
}

HubClient represents a Home Hub client for interacting with the router

func (*HubClient) BandwidthMonitor added in v0.9.0

func (h *HubClient) BandwidthMonitor() (result *BandwidthLog, err error)

BandwidthMonitor returns bandwidth statistics for devices that have connected to the router

func (*HubClient) BroadbandProductType added in v0.9.0

func (h *HubClient) BroadbandProductType() (result string, err error)

BroadbandProductType returns the last used wan interface type. For BT this equates to the broadband product type

func (*HubClient) ConnectedDevices added in v0.9.0

func (h *HubClient) ConnectedDevices() (result []DeviceDetail, err error)

ConnectedDevices returns information about any devices connected to the router

func (*HubClient) DataPumpVersion added in v0.9.0

func (h *HubClient) DataPumpVersion() (result string, err error)

DataPumpVersion returns the DSL line firmware version

func (*HubClient) DataReceived added in v0.9.0

func (h *HubClient) DataReceived() (result int64, err error)

DataReceived returns the the total data bytes received

func (*HubClient) DataSent added in v0.9.0

func (h *HubClient) DataSent() (result int64, err error)

DataSent returns the total data bytes sent

func (*HubClient) DeviceInfo added in v0.9.0

func (h *HubClient) DeviceInfo(id int) (result *DeviceDetail, err error)

DeviceInfo returns infomation about a device matching the specified id

func (*HubClient) DhcpAuthoritative added in v0.9.0

func (h *HubClient) DhcpAuthoritative() (result bool, err error)

DhcpAuthoritative returns whether the hub is the authoritive DHCP server

func (*HubClient) DhcpPoolEnd added in v0.9.0

func (h *HubClient) DhcpPoolEnd() (result string, err error)

DhcpPoolEnd returns DHCP pool end IP adress

func (*HubClient) DhcpPoolStart added in v0.9.0

func (h *HubClient) DhcpPoolStart() (result string, err error)

DhcpPoolStart returns DHCP pool start IP adress

func (*HubClient) DhcpSubnetMask added in v0.9.0

func (h *HubClient) DhcpSubnetMask() (result string, err error)

DhcpSubnetMask returns DHCP subnet mask

func (*HubClient) DownstreamSyncSpeed added in v0.9.0

func (h *HubClient) DownstreamSyncSpeed() (result int, err error)

DownstreamSyncSpeed returns the speed at which the router is downloading data

func (*HubClient) EnableDebug added in v0.9.0

func (h *HubClient) EnableDebug(enable bool)

EnableDebug causes HTTP client request and responses to be output to the console

func (*HubClient) EnableDhcpAuthoritative added in v0.9.0

func (h *HubClient) EnableDhcpAuthoritative(enable bool) (err error)

EnableDhcpAuthoritative toggles whether the hub is the authoritive DHCP server

func (*HubClient) EventLog added in v0.9.0

func (h *HubClient) EventLog() (result *EventLog, err error)

EventLog returns the events that have taken place on the router since it was last reset

func (*HubClient) HardwareVersion added in v0.9.0

func (h *HubClient) HardwareVersion() (result string, err error)

HardwareVersion returns the router hardware version

func (*HubClient) InternetConnectionStatus added in v0.9.0

func (h *HubClient) InternetConnectionStatus() (result string, err error)

InternetConnectionStatus returns the internet connection status

func (*HubClient) LightBrightness added in v0.9.0

func (h *HubClient) LightBrightness() (result int, err error)

LightBrightness returns the router LED brightness percentage

func (*HubClient) LightBrightnessSet added in v0.9.0

func (h *HubClient) LightBrightnessSet(brightness int) (err error)

LightBrightnessSet sets the router LED brightness percentage

func (*HubClient) LightEnable added in v0.9.0

func (h *HubClient) LightEnable(enable bool) (err error)

LightEnable toggles the status of the router LED lights

func (*HubClient) LightStatus added in v0.9.0

func (h *HubClient) LightStatus() (result string, err error)

LightStatus returns the router LED light satus

func (*HubClient) LocalTime added in v0.9.0

func (h *HubClient) LocalTime() (result string, err error)

LocalTime returns the local time from the router NTP server

func (*HubClient) Login added in v0.9.0

func (h *HubClient) Login() (success bool, err error)

Login authenticates a user

func (*HubClient) MaintenanceFirmwareVersion added in v0.9.0

func (h *HubClient) MaintenanceFirmwareVersion() (result string, err error)

MaintenanceFirmwareVersion returns the maintenance firmware version

func (*HubClient) NatRule added in v0.9.0

func (h *HubClient) NatRule(id int) (result *NatRule, err error)

NatRule returns an IPV4 firewall NAT rule matching the specified id

func (*HubClient) NatRuleCreate added in v0.9.0

func (h *HubClient) NatRuleCreate(natRule *NatRule) (err error)

NatRuleCreate creates an IPV4 firewall NAT rule

func (*HubClient) NatRuleDelete added in v0.9.0

func (h *HubClient) NatRuleDelete(id int) (err error)

NatRuleDelete deletes an IPV4 firewall NAT rule

func (*HubClient) NatRuleUpdate added in v0.9.0

func (h *HubClient) NatRuleUpdate(natRule NatRule) (err error)

NatRuleUpdate updates an existing IPV4 firewall NAT rule

func (*HubClient) NatRules added in v0.9.0

func (h *HubClient) NatRules() (result []NatRule, err error)

NatRules returns IPV4 firewall NAT rules

func (*HubClient) PublicIPAddress added in v0.9.0

func (h *HubClient) PublicIPAddress() (result string, err error)

PublicIPAddress returns the router public IP address

func (*HubClient) PublicSubnetMask added in v0.9.0

func (h *HubClient) PublicSubnetMask() (result string, err error)

PublicSubnetMask returns the router public subnet mask

func (*HubClient) Reboot added in v0.9.0

func (h *HubClient) Reboot() (err error)

Reboot restarts the router

func (*HubClient) SambaHost added in v0.9.0

func (h *HubClient) SambaHost() (result string, err error)

SambaHost returns a comma delimited list of samba host names

func (*HubClient) SambaIP added in v0.9.0

func (h *HubClient) SambaIP() (result string, err error)

SambaIP returns the samba share IP address

func (*HubClient) SerialNumber added in v0.9.0

func (h *HubClient) SerialNumber() (result string, err error)

SerialNumber returns the router serial number

func (*HubClient) SoftwareVersion added in v0.9.0

func (h *HubClient) SoftwareVersion() (result string, err error)

SoftwareVersion returns the router software version

func (*HubClient) UpstreamSyncSpeed added in v0.9.0

func (h *HubClient) UpstreamSyncSpeed() (result int, err error)

UpstreamSyncSpeed returns the speed at which the router is uploading data

func (*HubClient) Version added in v0.9.0

func (h *HubClient) Version() (result string, err error)

Version returns the router version

func (*HubClient) WiFiFrequency24Ghz added in v0.9.0

func (h *HubClient) WiFiFrequency24Ghz() (result *WiFiFrequency, err error)

WiFiFrequency24Ghz returns information about the WiFI 2.4GHz frequency

func (*HubClient) WiFiFrequency24GhzChannelSet added in v0.9.0

func (h *HubClient) WiFiFrequency24GhzChannelSet(channel int) (err error)

WiFiFrequency24GhzChannelSet sets the operating channel for the 2.4Ghz frequency

func (*HubClient) WiFiFrequency5Ghz added in v0.9.0

func (h *HubClient) WiFiFrequency5Ghz() (result *WiFiFrequency, err error)

WiFiFrequency5Ghz returns information about the WiFI 5GHz frequency

func (*HubClient) WiFiFrequency5GhzChannelSet added in v0.9.0

func (h *HubClient) WiFiFrequency5GhzChannelSet(channel int) (err error)

WiFiFrequency5GhzChannelSet sets the operating channel for the 5Ghz frequency

func (*HubClient) WiFiSSID added in v0.9.0

func (h *HubClient) WiFiSSID() (result string, err error)

WiFiSSID returns the WiFi service set identifier

func (*HubClient) WiFiSecurityMode added in v0.9.0

func (h *HubClient) WiFiSecurityMode() (result string, err error)

WiFiSecurityMode returns the WiFi security mode in use

type IPAddress added in v0.3.0

type IPAddress struct {
	UID       int    `json:"uid,omitempty"`
	IPAddress string `json:"IPAddress,omitempty"`
	Active    bool   `json:"Active,omitempty"`
}

IPAddress defines an IPV4 or IPV6 address

type NatRule added in v0.5.0

type NatRule struct {
	UID                   int    `json:"uid"`
	Enable                bool   `json:"Enable"`
	Alias                 string `json:"Alias"`
	ExternalInterface     string `json:"ExternalInterface"`
	AllExternalInterfaces bool   `json:"AllExternalInterfaces"`
	LeaseDuration         int    `json:"LeaseDuration"`
	RemoteHost            string `json:"RemoteHost"`
	ExternalPort          int    `json:"ExternalPort"`
	ExternalPortEndRange  int    `json:"ExternalPortEndRange"`
	InternalInterface     string `json:"InternalInterface"`
	InternalPort          int    `json:"InternalPort"`
	Protocol              string `json:"Protocol"`
	Service               string `json:"Service"`
	InternalClient        string `json:"InternalClient"`
	Description           string `json:"Description"`
	Creator               string `json:"Creator"`
	Target                string `json:"Target"`
	LeaseStart            string `json:"LeaseStart"`
}

NatRule represents a Home Hub NAT port forwarding rule

type WiFiFrequency added in v0.7.0

type WiFiFrequency struct {
	UID                int    `json:"uid"`
	Enable             bool   `json:"Enable"`
	Alias              string `json:"Alias"`
	Status             string `json:"Status"`
	SupportedStandards string `json:"SupportedStandards"`
	OperatingStandards string `json:"OperatingStandards"`
	AvailableChannels  string `json:"ChannelsInUse"`
	Channel            int    `json:"Channel"`
}

WiFiFrequency represents a Home Hub wireless frequency

Jump to

Keyboard shortcuts

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