unifi

package module
v0.0.0-...-2c64fb9 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2017 License: Apache-2.0 Imports: 11 Imported by: 1

README

This is a Go package for interfacing with a UniFi controller.

GoDoc

This is at a very early stage.

Installation

To get it,

go get github.com/dsymonds/unifi

Demos

You will need to put auth information in $HOME/.unifi-auth that looks like

{"Username":"xxx","Password":"yyy","ControllerHost":"unifi"}

Don't forget to chmod 600 $HOME/.unifi-auth.

To do a quick test that will print out the clients on the default site,

go run demo/list-sta.go

There's another demo program that can enable/disable all the guest wireless networks for the default site,

go run demo/toggle-guest-wlan.go on

Caveats, acknowledgements

The UniFi API is not documented, so this is reverse engineered from a few sources:

Documentation

Overview

Package unifi provides programmatic access to UniFi hardware.

Index

Constants

This section is empty.

Variables

View Source
var DefaultAuthFile = filepath.Join(os.Getenv("HOME"), ".unifi-auth")

DefaultAuthFile is a default place to store authentication information. Pass this to FileAuthStore if an alternate path isn't required.

Functions

This section is empty.

Types

type API

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

API is an interface to a UniFi controller.

func NewAPI

func NewAPI(as AuthStore) (*API, error)

NewAPI constructs a new API.

func (*API) EnableWirelessNetwork

func (api *API) EnableWirelessNetwork(site, id string, enable bool) error

func (*API) ListClients

func (api *API) ListClients(site string) ([]Client, error)

func (*API) ListWirelessNetworks

func (api *API) ListWirelessNetworks(site string) ([]WirelessNetwork, error)

func (*API) WriteConfig

func (api *API) WriteConfig() error

WriteConfig writes the configuration to the configured AuthStore.

type Auth

type Auth struct {
	Username, Password string
	ControllerHost     string
	Cookies            []*http.Cookie
}

Auth holds the authentication information for accessing a UniFi controller.

type AuthStore

type AuthStore interface {
	Load() (*Auth, error)
	Save(*Auth) error
}

An AuthStore is an interface for loading and saving authentication information. See FileAuthStore for a file-based implementation.

func FileAuthStore

func FileAuthStore(filename string) AuthStore

FileAuthStore returns an AuthStore that stores authentication information in a named file.

type Client

type Client struct {
	ID       string `json:"_id"`
	Name     string `json:"name"`
	Hostname string `json:"hostname"`
	Wired    bool   `json:"is_wired"`

	MAC string `json:"mac"`
	IP  string `json:"ip"`

	LastSeen time.Time
}

func (*Client) UnmarshalJSON

func (c *Client) UnmarshalJSON(data []byte) error

type WirelessNetwork

type WirelessNetwork struct {
	ID      string `json:"_id"`
	Name    string `json:"name"`
	Enabled bool   `json:"enabled"`

	Security string `json:"security"`
	WPAMode  string `json:"wpa_mode"`

	Guest bool `json:"is_guest,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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