freebox

package module
v0.0.0-...-78a2740 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 12 Imported by: 0

README

go-freebox

GoDoc

🔧 Freebox API v4 client in Golang, deviated sensibly from moul's version

About

This is golang api binding for Freebox. It's a subset including:

  • Login and authroization request
  • AirMedia
  • Call Entries
  • Contact

There's also a cli application demonstrating the API.

Install

go get -u github.com/juju2013/go-freebox

GOFBX_TOKEN= go run github.com/juju2013/go-freebox/cmd/freebox

Usage

The API make use of the following environ variables:

  • GOFBX_ID, GOFBX_NAME: any string you like
  • GOFBX_TOKEN: Authorization token, dpends on values of ID and NAME
  • GOFBX_LOGLEVEL: can be INFO, DEBUG, WARN and ERROR, default to INFO
Authorization

To use the API, you need first to get a GOFBX_TOKEN:

  • Give a value to GOFBX_ID and GOFBX_NAME, the auth token depends on them
  • Unset GOFBX_TOKEN, Call Authorize(), the Freebox device will prompt you on the small LCD display to accept/deny, accept then and the token will be found in Client.App.token (and also printed)
  • Set GOFBX_TOKEN to this token and you won't need to do the authorization again

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AirMediaReceiver

type AirMediaReceiver struct {
	Capabilities struct {
		Photo  bool `json:"photo"`
		Screen bool `json:"screen"`
		Audio  bool `json:"audio"`
		Video  bool `json:"video"`
	} `json:"capabilities"`
	Name              string `json:"name"`
	PasswordProtected bool   `json:"password_protected"`
}

Airmedia

type ApiVersion

type ApiVersion struct {
	FreeboxID  string `json:"uid",omitempty`
	DeviceName string `json:"device_name",omitempty`
	Version    string `json:"api_version",omitempty`
	BaseURL    string `json:"api_base_url",omitempty`
	DeviceType string `json:"device_type",omitempty`
}

ApiVersion is returned by requesting `GET /api_version`

func (*ApiVersion) ApiCode

func (a *ApiVersion) ApiCode() string

type App

type App struct {
	Identifier string `json:"app_id",omitempty`
	Name       string `json:"app_name",omitempty`
	Version    string `json:"app_version",omitempty`
	DeviceName string `json:"device_name",omitempty`
	// contains filtered or unexported fields
}

type CallEntry

type CallEntry struct {
	Number    string `json:"number"`
	Type      string `json:"type"`
	ID        int    `json:"id"`
	Duration  int    `json:"duration"`
	Datetime  Epoch  `json:"datetime"`
	ContactID int    `json:"contact_id"`
	LineID    int    `json:"line_id"`
	Name      string `json:"name"`
	New       bool   `json:"new"`
}

Airmedia

type Client

type Client struct {
	URL string

	App App
	// contains filtered or unexported fields
}

Client is the Freebox API client

func New

func New() *Client

New returns a `Client` object with standard configuration

func (*Client) ApiVersion

func (c *Client) ApiVersion() *ApiVersion

ApiVersion returns an `ApiVersion` structure field with the configuration fetched during `Connect()`

func (*Client) Authorize

func (c *Client) Authorize() error

func (*Client) Connect

func (c *Client) Connect() error

Connect tries to contact the Freebox API, and fetches API versions

func (*Client) DownloadsStats

func (c *Client) DownloadsStats() (*apiResultDownloadsStats, error)

func (*Client) GetAirMediaReceivers

func (c *Client) GetAirMediaReceivers() ([]AirMediaReceiver, error)

func (*Client) GetCallEntrie

func (c *Client) GetCallEntrie(id int) (CallEntry, error)

Get a call

func (*Client) GetCallEntries

func (c *Client) GetCallEntries() ([]CallEntry, error)

Get call log

func (*Client) GetContact

func (c *Client) GetContact(id int) (CallEntry, error)

Get a contact

func (*Client) GetContacts

func (c *Client) GetContacts() ([]ContactEntry, error)

Get all contacts

func (*Client) GetDhcpConfig

func (c *Client) GetDhcpConfig() (*DhcpConfig, error)

Get the current DHCP configuration

func (*Client) GetDhcpDynamicLease

func (c *Client) GetDhcpDynamicLease() ([]DhcpDynamicLease, error)

Get the list of DHCP dynamic leases

func (*Client) GetDhcpStaticLease

func (c *Client) GetDhcpStaticLease() ([]DhcpStaticLease, error)

Get the list of DHCP static leases

func (*Client) GetLanBrowserInterface

func (c *Client) GetLanBrowserInterface(nic string) ([]LanBrowserInterface, error)

func (*Client) GetLanBrowserInterfaces

func (c *Client) GetLanBrowserInterfaces() ([]LanBrowserInterfaces, error)

func (*Client) GetLanConfig

func (c *Client) GetLanConfig() (*LanConfig, error)

Get LanConfig

func (*Client) GetResource

func (c *Client) GetResource(resource string, authenticated bool) ([]byte, error)

GetApiResource performs low-level GET request on the Freebox API

func (*Client) GetResult

func (c *Client) GetResult(uri string, payload interface{}) error

func (*Client) Login

func (c *Client) Login() error

func (*Client) MarkAllRead

func (c *Client) MarkAllRead() error

Mark all as read

func (*Client) MarkRead

func (c *Client) MarkRead(id int) error

Mark as read

func (*Client) PostResource

func (c *Client) PostResource(resource string, data interface{}, authenticated bool) ([]byte, error)

PostResource post data and returns body

func (*Client) PutResource

func (c *Client) PutResource(resource string, data interface{}, authenticated bool) ([]byte, error)

PostResource post data and returns body

type ConnectionStatus

type ConnectionStatus struct {
	Type          string `json:"type"`
	RateDown      int    `json:"rate_down"`
	BytesUp       int64  `json:"bytes_up"`
	Ipv4PortRange []int  `json:"ipv4_port_range"`
	RateUp        int    `json:"rate_up"`
	BandwidthUp   int    `json:"bandwidth_up"`
	Ipv6          string `json:"ipv6"`
	BandwidthDown int    `json:"bandwidth_down"`
	Media         string `json:"media"`
	State         string `json:"state"`
	BytesDown     int64  `json:"bytes_down"`
	Ipv4          string `json:"ipv4"`
}

type ConnectionStatusFull

type ConnectionStatusFull struct {
	Type          string `json:"type"`
	RateDown      int    `json:"rate_down"`
	BytesUp       int64  `json:"bytes_up"`
	Ipv4PortRange []int  `json:"ipv4_port_range"`
	RateUp        int    `json:"rate_up"`
	BandwidthUp   int    `json:"bandwidth_up"`
	Ipv6          string `json:"ipv6"`
	BandwidthDown int    `json:"bandwidth_down"`
	Media         string `json:"media"`
	State         string `json:"state"`
	BytesDown     int64  `json:"bytes_down"`
	Ipv4          string `json:"ipv4"`
}

type ContactEntry

type ContactEntry struct {
	LastName string `json:"last_name"`
	Company  string `json:"company"`
	PhotoURL string `json:"photo_url"`
	ID       int    `json:"id"`
	Birthday string `json:"birthday"`
	Numbers  []struct {
		Number    string `json:"number"`
		Type      string `json:"type"`
		ID        int    `json:"id"`
		ContactID int    `json:"contact_id"`
		IsDefault bool   `json:"is_default"`
		IsOwn     bool   `json:"is_own"`
	} `json:"numbers"`
	LastUpdate  Epoch  `json:"last_update"`
	DisplayName string `json:"display_name"`
	Notes       string `json:"notes"`
	FirstName   string `json:"first_name"`
}

Airmedia

type DhcpConfig

type DhcpConfig struct {
	Enabled         bool     `json:"enabled"`
	Gateway         string   `json:"gateway"`
	StickyAssign    bool     `json:"sticky_assign"`
	IPRangeEnd      string   `json:"ip_range_end"`
	Netmask         string   `json:"netmask"`
	DNS             []string `json:"dns"`
	AlwaysBroadcast bool     `json:"always_broadcast"`
	IPRangeStart    string   `json:"ip_range_start"`
}

DhcpConfig

type DhcpDynamicLease

type DhcpDynamicLease struct {
	Mac            string   `json:"mac"`
	Host           DhcpHost `json:"host"`
	RefreshTime    int      `json:"refresh_time"`
	Hostname       string   `json:"hostname"`
	AssignTime     int      `json:"assign_time"`
	LeaseRemaining int      `json:"lease_remaining"`
	IsStatic       bool     `json:"is_static"`
	IP             string   `json:"ip"`
}

type DhcpHost

type DhcpHost struct {
	L2Ident struct {
		ID   string `json:"id"`
		Type string `json:"type"`
	} `json:"l2ident"`
	Active     bool `json:"active"`
	Persistent bool `json:"persistent"`
	Names      []struct {
		Name   string `json:"name"`
		Source string `json:"source"`
	} `json:"names"`
	VendorName        string `json:"vendor_name"`
	HostType          string `json:"host_type"`
	Interface         string `json:"interface"`
	ID                string `json:"id"`
	LastTimeReachable int    `json:"last_time_reachable"`
	PrimaryNameManual bool   `json:"primary_name_manual"`
	DefaultName       string `json:"default_name"`
	L3Connectivities  []struct {
		Addr              string `json:"addr"`
		Active            bool   `json:"active"`
		Reachable         bool   `json:"reachable"`
		LastActivity      int    `json:"last_activity"`
		Af                string `json:"af"`
		LastTimeReachable int    `json:"last_time_reachable"`
	} `json:"l3connectivities"`
	Reachable    bool `json:"reachable"`
	LastActivity int  `json:"last_activity"`
	AccessPoint  struct {
		Mac                 string `json:"mac"`
		Type                string `json:"type"`
		ConnectivityType    string `json:"connectivity_type"`
		UID                 string `json:"uid"`
		EthernetInformation struct {
			Duplex string `json:"duplex"`
			Speed  string `json:"speed"`
			Link   string `json:"link"`
		} `json:"ethernet_information"`
	} `json:"access_point"`
	PrimaryName string `json:"primary_name"`
}

type DhcpStaticLease

type DhcpStaticLease struct {
	Mac      string   `json:"mac"`
	Comment  string   `json:"comment"`
	Hostname string   `json:"hostname"`
	ID       string   `json:"id"`
	Host     DhcpHost `json:"host"`
	IP       string   `json:"ip"`
}

type Epoch

type Epoch time.Time

Special handler from epoch to time

func (Epoch) String

func (e Epoch) String() string

func (*Epoch) UnmarshalJSON

func (e *Epoch) UnmarshalJSON(data []byte) error

type LanBrowserInterface

type LanBrowserInterface struct {
	L2Ident struct {
		ID   string `json:"id"`
		Type string `json:"type"`
	} `json:"l2ident"`
	Active            bool   `json:"active"`
	ID                string `json:"id"`
	LastTimeReachable int    `json:"last_time_reachable"`
	Persistent        bool   `json:"persistent"`
	Names             []struct {
		Name   string `json:"name"`
		Source string `json:"source"`
	} `json:"names"`
	VendorName       string `json:"vendor_name"`
	L3Connectivities []struct {
		Addr              string `json:"addr"`
		Active            bool   `json:"active"`
		Af                string `json:"af"`
		Reachable         bool   `json:"reachable"`
		LastActivity      int    `json:"last_activity"`
		LastTimeReachable int    `json:"last_time_reachable"`
	} `json:"l3connectivities"`
	Reachable         bool   `json:"reachable"`
	LastActivity      int    `json:"last_activity"`
	PrimaryNameManual bool   `json:"primary_name_manual"`
	PrimaryName       string `json:"primary_name"`
}

list of hosts on a given interface

type LanBrowserInterfaces

type LanBrowserInterfaces struct {
	Name      string `json:"name"`
	HostCount int    `json:"host_count"`
}

browsable LAN interfaces

type LanConfig

type LanConfig struct {
	NameDNS     string `json:"name_dns"`
	NameMdns    string `json:"name_mdns"`
	Name        string `json:"name"`
	Mode        string `json:"mode"`
	NameNetbios string `json:"name_netbios"`
	IP          string `json:"ip"`
}

Lan configuration

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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