fritzbox

package
v0.0.0-...-8c89a97 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSid is an invalid session in order to perform and
	// identify logouts.
	DefaultSid = "0000000000000000"
	// DefaultExpires is the amount of time of inactivity before
	// the FRITZ!Box automatically closes a session.
	DefaultExpires = 10 * time.Minute
)

Variables

View Source
var (
	// ErrInvalidCred is the error returned by Auth when
	// login attempt is not successful.
	ErrInvalidCred = errors.New("fritzbox: invalid credentials")

	// ErrExpiredSess means that client was too long inactive.
	ErrExpiredSess = errors.New("fritzbox: session expired")
)

Functions

This section is empty.

Types

type Client

type Client struct {

	// Base URL for requests. Defaults to the local fritzbox, but
	// can be set to a domain endpoint to use with an external FRITZ!Box.
	// BaseURL should always be specified with a trailing slash.
	BaseURL *url.URL
	// contains filtered or unexported fields
}

A Client manages communication with the FRITZ!Box

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new FRITZ!Box client. If a nil httpClient is provided, http.DefaultClient will be used. To use an external FRITZ!Box with a self-signed certificate, provide an http.Client that will be able to perform insecure connections (such as InsecureSkipVerify flag).

func (*Client) Auth

func (c *Client) Auth(username, password string) error

Auth sends a auth request and returns an error, if any. Session is stored in client in order to perform requests with authentification.

func (*Client) Close

func (c *Client) Close()

Close closes the current session

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends a request and returns the response. The response is either JSON decoded or XML encoded and stored in the value pointed to by v, or returned as an error, if any.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string,
	data url.Values) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by data is Query encoded and included as the request body in order to perform form requests.

func (*Client) String

func (c *Client) String() string

type Session

type Session struct {
	XMLName   xml.Name      `xml:"SessionInfo"`
	Sid       string        `xml:"SID"`
	Challenge string        `xml:"Challenge"`
	BlockTime time.Duration `xml:"BlockTime"`

	// Rights' representation is a little bit tricky
	// TODO: Write UnmarshalXML to merge them
	RightsName   []string `xml:"Rights>Name"`
	RightsAccess []int8   `xml:"Rights>Access"`

	// Session expires after 10 minutes
	Expires time.Time `xml:"-"`
	// contains filtered or unexported fields
}

Session represents a FRITZ!Box session

func NewSession

func NewSession(c *Client) *Session

NewSession returns a new FRITZ!Box session.

func (*Session) Auth

func (s *Session) Auth(username, password string) error

Auth sends the Response (Challenge-Response) to the FRITZ!Box and returns an error, if any.

func (*Session) Close

func (s *Session) Close()

Close closes a session

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired returns true if session is expired

func (*Session) Open

func (s *Session) Open() error

Open retrieves the challenge from FRITZ!Box.

func (*Session) Refresh

func (s *Session) Refresh() error

Refresh updates expires

func (*Session) String

func (s *Session) String() string

Jump to

Keyboard shortcuts

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