fbxapi

package module
v0.0.0-...-ccb3ab5 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: BSD-3-Clause Imports: 28 Imported by: 1

README

fbxapi

WIP French ISP Free Freebox API implementation in golang.

Use at your own risk, yadda, yadda yadda Mainly used in fbxcli

Documentation

Index

Constants

View Source
const AUTHHEADER = "X-Fbx-App-Auth"
View Source
const AUTH_STATUS_GRANTED = "granted"
View Source
const AUTH_STATUS_PENDING = "pending"
View Source
const CTHEADER = "Content-Type"
View Source
const FreeboxRootCA = `` /* 2003-byte string literal not displayed */
View Source
const HTTP_METHOD_DELETE = "DELETE"
View Source
const HTTP_METHOD_GET = "GET"
View Source
const HTTP_METHOD_POST = "POST"
View Source
const HTTP_METHOD_PUT = "PUT"
View Source
const IPV4 = "ipv4"
View Source
const MULTICASTDNSADDR = "224.0.0.251:5353"
View Source
const PROTO_HTTP = "http"
View Source
const PROTO_HTTPS = "https"
View Source
const PROTO_WS = "ws"
View Source
const PROTO_WSS = "wss"
View Source
const SERVICE = "_fbx-api._tcp"

Variables

View Source
var AddDownloadEP = &Endpoint{
	Verb: HTTP_METHOD_POST,
	Url:  "downloads/add/",
}

AddDownloadEP endpoint definition Output: Download

View Source
var AuthorizeEP = &Endpoint{
	Verb:         HTTP_METHOD_POST,
	Url:          "login/authorize",
	BodyRequired: true,
}
View Source
var ConnectionEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "connection/",
}
View Source
var ConnectionLogEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "connection/logs/",
}

Undocumented

View Source
var CurrentFTPConfigEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "ftp/config/",
}
View Source
var DeleteDownloadEP = &Endpoint{
	Verb: HTTP_METHOD_DELETE,
	Url:  "downloads/{{.id}}/",
}

DeleteDownloadEP endpoint definition

View Source
var DlEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "dl/{{.path}}",
}
View Source
var DownloadsEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "downloads/",
}

DownloadsEP endpoint definition Output: []Download

View Source
var EraseDownloadEP = &Endpoint{
	Verb: HTTP_METHOD_DELETE,
	Url:  "downloads/{{.id}}/erase",
}

EraseDownloadEP endpoint definition

View Source
var InfoEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "fs/info/{{.path}}",
}
View Source
var InterfaceEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "lan/browser/{{.iface}}/",
}

InterfaceEP endpoint definition Output: []LanHost

View Source
var InterfaceHostEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "lan/browser/{{.iface}}/{{.host_id}}",
}

InterfaceHostEP endpoint definition Output: LanHost

View Source
var InterfacesEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "lan/browser/interfaces/",
}

InterfacesEP endpoint definition Output: []InterfaceStat

View Source
var LanConfigEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "lan/config/",
}

LanConfigEP endpoint definition Output: LanConfig

View Source
var LoginEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "login/",
}
View Source
var LogoutEP = &Endpoint{
	Verb: HTTP_METHOD_POST,
	Url:  "login/logout/",
}
View Source
var LsEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "fs/ls/{{.path}}",
}
View Source
var RebootEP = &Endpoint{
	Verb: HTTP_METHOD_POST,
	Url:  "system/reboot/",
}
View Source
var SessionEP = &Endpoint{
	Verb: HTTP_METHOD_POST,
	Url:  "login/session/",
}
View Source
var ShareEP = &Endpoint{
	Verb: HTTP_METHOD_POST,
	Url:  "share_link/",
}
View Source
var SystemEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "system/",
}
View Source
var TasksEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "fs/tasks/",
}
View Source
var TrackAuthorizeEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "login/authorize/{{.track_id}}",
}
View Source
var UlEP = &Endpoint{
	Verb: HTTP_METHOD_GET,
	Url:  "ws/upload",
}
View Source
var UpdateFTPConfigEP = &Endpoint{
	Verb:         HTTP_METHOD_PUT,
	Url:          "ftp/config/",
	BodyRequired: true,
}
View Source
var WakeOnLanEP = &Endpoint{
	Verb:         HTTP_METHOD_POST,
	Url:          "lan/wol/{{.iface}}/",
	BodyRequired: true,
}

WakeOnLanEP endpoint definition Output: nil

Functions

func APIVersionToInt

func APIVersionToInt(apiVersion string) (int, error)

func ComputePassword

func ComputePassword(key, challenge string) string

func EncodePath

func EncodePath(path string) string

func EndpointTester

func EndpointTester(t *testing.T, ep *Endpoint, data interface{}, urlparams map[string]string, body interface{})

func MdnsDiscover

func MdnsDiscover(fbChan chan<- *Freebox)

func MdnsResolve

func MdnsResolve(domain string) (host net.IP, err error)

func ResultFromResponse

func ResultFromResponse(resp *APIResponse, result interface{}) (err error)

func SelectRequestMethod

func SelectRequestMethod(updateMethod string, fn func(interface{}) bool, data interface{}) (method string, body []byte, err error)

Types

type APIResponse

type APIResponse struct {
	Success   bool            `json:"success"`
	Msg       string          `json:"msg"`
	UID       string          `json:"uid"`
	ErrorCode string          `json:"error_code"`
	Result    json.RawMessage `json:"result"`
}

type APIVersion

type APIVersion struct {
	UID                  string `json:"uid"`
	DeviceName           string `json:"device_name"`
	DeviceType           string `json:"device_type"`
	APIBaseURL           string `json:"api_base_url"`
	APIVersion           string `json:"api_version"`
	RemoteHTTPSAvailable bool   `json:"https_available"`
	RemoteHTTPSPort      int    `json:"https_port"`
	RemoteAPIDomain      string `json:"api_domain"`
}

type App

type App struct {
	ID      string
	Name    string
	Version string
	Token   string
}

type Authorization

type Authorization struct {
	AppToken string `json:"app_token"`
	TrackID  int    `json:"track_id"`
}

type AuthorizationState

type AuthorizationState struct {
	Status       string `json:"status"`
	Challenge    string `json:"challenge"`
	PasswordSalt string `json:"password_salt"` // Undocumented
}

type Client

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

func (*Client) Dl

func (c *Client) Dl(path string) (resp *http.Response, err error)

func (*Client) Info

func (c *Client) Info(path string) (respFileInfo *FileInfo, err error)

func (*Client) Login

func (c *Client) Login() (respLogin *RespLogin, err error)

func (*Client) Logout

func (c *Client) Logout() (err error)

func (*Client) Ls

func (c *Client) Ls(path string, onlyFolder, countSubFolder, removeHidden bool) (respFileInfo []FileInfo, err error)

func (*Client) Query

func (c *Client) Query(ep *Endpoint) Query

func (*Client) Register

func (c *Client) Register(tokenReq *TokenRequest) (respAuth *Authorization, err error)

func (*Client) Session

func (c *Client) Session(reqSess ReqSession) (respSess *RespSession, err error)

func (*Client) Upload

func (c *Client) Upload(path, destDir string) (err error)

func (*Client) WithSession

func (c *Client) WithSession(session *Session) *Client

type ConnectionLog

type ConnectionLog struct {
	State         string `json:"state"`
	Type          string `json:"type"`
	BandwidthDown int    `json:"bw_down,omitempty"`
	BandwidthUp   int    `json:"bw_up,omitempty"`
	Link          string `json:"link,omitempty"`
	ID            int    `json:"id"`
	Date          int    `json:"date"`
	Conn          string `json:"conn,omitempty"`
}

Undocumented

type ConnectionStatus

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

type Download

type Download struct {
	ID              int    `json:"id"`
	Type            string `json:"type"`
	Name            string `json:"name"`
	Status          string `json:"status"`
	Size            int    `json:"size"`
	QueuePos        int    `json:"queue_pos"`
	IOPriority      string `json:"io_priority"`
	TXBytes         int    `json:"tx_bytes"`
	RXBytes         int    `json:"rx_bytes"`
	TXRate          int    `json:"tx_rate"`
	RXRate          int    `json:"rx_rate"`
	TXPct           int    `json:"tx_pct"`
	RXPct           int    `json:"rx_pct"`
	Error           string `json:"error"`
	CreatedTS       int    `json:"created_ts"`
	ETA             int    `json:"eta"`
	DownloadDir     string `json:"download_dir"`
	StopRatio       int    `json:"stop_ratio"`
	ArchivePassword string `json:"stop_ratio"`
	InfoHash        string `json:"info_hash"`
	PieceLength     int    `json:"piece_length"`
}

type DownloadReq

type DownloadReq struct {
	DownloadUrl     string `json:"download_url,omitempty"`
	DownloadUrlList string `json:"download_url_list,omitempty"`
	DownloadDir     string `json:"download_dir"`
	Recursive       bool   `json:"recursive,omitempty"`
	Username        string `json:"username,omitempty"`
	Password        string `json:"password,omitempty"`
	ArchivePassword string `json:"archive_password,omitempty"`
	Cookies         string `json:"cookies,omitempty"`
}

type DownloadTask

type DownloadTask struct {
	ID int `json:"id"`
}

type Endpoint

type Endpoint struct {
	Verb         string
	Url          string
	BodyRequired bool
	RespStruct   interface{}
}

type FSTask

type FSTask struct {
	ID             int    `json:"id"`
	Type           string `json:"type"`
	State          string `json:"state"`
	Error          string `json:"error"`
	CreatedTS      int    `json:"created_ts"`
	StartedTS      int    `json:"started_ts"`
	DoneTS         int    `json:"done_ts"`
	Duration       int    `json:"duration"`
	Progress       int    `json:"progress"`
	ETA            int    `json:"eta"`
	From           string `json:"from"`
	To             string `json:"to"`
	NFiles         int    `json:"nfiles"`
	NFilesDone     int    `json:"nfiles_done"`
	TotalBytes     int    `json:"total_bytes"`
	TotalBytesDone int    `json:"total_bytes_done"`
	CurrBytes      int    `json:"curr_bytes"`
	Rate           int    `json:"rate"`
}

type FTPConfig

type FTPConfig struct {
	Enabled             bool   `json:"enabled"`
	AllowAnonymous      bool   `json:"allow_anonymous"`
	AllowAnonymousWrite bool   `json:"allow_anonymous_write"`
	WeakPassword        bool   `json:"weak_password"`
	AllowRemoteAccess   bool   `json:"allow_remote_access"`
	PortCtrl            int    `json:"port_ctrl"`
	PortData            int    `json:"port_data"`
	RemoteDomain        string `json:"remote_domain"`
}

type FileInfo

type FileInfo struct {
	Path         string `json:"path"`
	Name         string `json:"name"`
	MimeType     string `json:"mimetype"`
	Type         string `json:"type"`
	Size         int    `json:"size"`
	Modification int    `json:"modification"`
	Index        int    `json:"index"`
	Link         bool   `json:"link"`
	Target       string `json:"target"`
	Hidden       bool   `json:"hidden"`
	FolderCount  int    `json:"foldercount"`
	FileCount    int    `json:"filecount"`
	Parent       string `json:"parent"`
}

type FileUpload

type FileUpload struct {
	ID         int    `json:"id"`
	Size       int    `json:"size"`
	Uploaded   int    `json:"uploaded"`
	Status     string `json:"status"`
	StartDate  int    `json:"start_date"`
	LastUpdate int    `json:"last_update"`
	UploadName string `json:"upload_name"`
	Dirname    string `json:"dirname"`
}

type FileUploadChunkResponse

type FileUploadChunkResponse struct {
	WSResponse
	Result FileUploadChunkResult `json:"result,omitempty"`
}

type FileUploadChunkResult

type FileUploadChunkResult struct {
	TotalLen  int  `json:"total_len"`
	Complete  bool `json:"complete,omitempty"`
	Cancelled bool `json:"cancelled,omitempty"`
}

type FileUploadStartAction

type FileUploadStartAction struct {
	WSRequest
	Size     int    `json:"size"`
	Dirname  string `json:"dirname"`
	Filename string `json:"filename"`
	Force    string `json:"force"`
}

type Freebox

type Freebox struct {
	Host string
	Port int
	APIVersion
	Authorization
}

func HttpDiscover

func HttpDiscover(host string, port int) (freebox *Freebox, err error)

func NewFreebox

func NewFreebox(host string, port int) *Freebox

func NewFromServiceEntry

func NewFromServiceEntry(service *mdns.ServiceEntry) (fb *Freebox)

func (*Freebox) NewClient

func (fb *Freebox) NewClient() *Client

func (*Freebox) NewSession

func (fb *Freebox) NewSession() (sess *Session, err error)

func (*Freebox) OpenSession

func (fb *Freebox) OpenSession(app *App) (client *Client, err error)

func (*Freebox) Register

func (fb *Freebox) Register(app *App) (respAuth *Authorization, err error)

type InterfaceStat

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

type LanConfig

type LanConfig struct {
	IP          net.IP `json:"ip"`
	Name        string `json:"name"`
	NameDNS     string `json:"name_dns"`
	NameMDNS    string `json:"name_mdns"`
	NameNETBIOS string `json:"name_netbios"`
	Mode        string `json:"mode"` // documentation is wrong, field called type
}

type LanHost

type LanHost struct {
	ID                string                  `json:"id"`
	PrimaryName       string                  `json:"primary_name"`
	HostType          string                  `json:"host_type"`
	PrimaryNameManual bool                    `json:"primary_name_manual"`
	L2Ident           LanHostL2Ident          `json:"l2ident"`
	VendorName        string                  `json:"vendor_name"`
	Persistent        bool                    `json:"persistent"`
	Reachable         bool                    `json:"reachable"`
	LastTimeReachable int                     `json:"last_time_reachable"`
	Active            bool                    `json:"active"`
	LastActivity      int                     `json:"last_activity"`
	Names             []LanHostName           `json:"names"`
	L3Connectivities  []LanHostL3Connectivity `json:"l3connectivities"`
	Interface         string                  `json:"interface"` // not documented
}

func (*LanHost) GetIPv4s

func (lh *LanHost) GetIPv4s() (ips []string)

type LanHostL2Ident

type LanHostL2Ident struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

type LanHostL3Connectivity

type LanHostL3Connectivity struct {
	Addr              string `json:"addr"`
	Af                string `json:"af"`
	Active            bool   `json:"active"`
	Reachable         bool   `json:"reachable"`
	LastActivity      int    `json:"last_activity"`
	LastTimeReachable int    `json:"last_time_reachable"`
}

type LanHostName

type LanHostName struct {
	Name   string `json:"name"`
	Source string `json:"source"`
}

type Query

type Query struct {
	Client   *Client
	Endpoint *Endpoint
	// contains filtered or unexported fields
}

func (Query) As

func (q Query) As(params map[string]string) Query

func (Query) Do

func (q Query) Do(endStruct interface{}) (err error)

func (Query) DoRequest

func (q Query) DoRequest() (resp *http.Response, err error)

func (Query) Inspect

func (q Query) Inspect(resp *APIResponse) Query

func (Query) WS

func (q Query) WS() (conn *websocket.Conn, err error)

func (Query) WithBody

func (q Query) WithBody(body interface{}) Query

func (Query) WithFormBody

func (q Query) WithFormBody(body interface{}) Query

func (Query) WithParams

func (q Query) WithParams(params url.Values) Query

type ReqHost

type ReqHost struct {
	ID          string `json:"id"`
	PrimaryName string `json:"primary_name"`
}

type ReqSession

type ReqSession struct {
	AppId    string `json:"app_id"`
	Password string `json:"password"`
}

type ReqWoL

type ReqWoL struct {
	Mac      string `json:"mac"`
	Password string `json:"password"`
}

type RespLogin

type RespLogin struct {
	LoggedIn     bool   `json:"logged_in"`
	Challenge    string `json:"challenge"`
	PasswordSalt string `json:"password_salt"`
}

type RespSession

type RespSession struct {
	Token       string          `json:"session_token"`
	Challenge   string          `json:"challenge"`
	Permissions map[string]bool `json:"permissions"`
}

type Session

type Session struct {
	*APIVersion
	*RespSession
	Version int
}
type ShareLink struct {
	Token    string `json:"token,omitempty"`
	Path     string `json:"path,omitempty"`
	Name     string `json:"name,omitempty"`
	Expire   int    `json:"expire"`
	FullURL  string `json:"fullurl,omitempty"`
	Internal int    `json:"internal"` // Undocumented
}

type SystemConfig

type SystemConfig struct {
	FirmwareVersion  string `json:"firmware_version"`
	Mac              string `json:"mac"`
	Serial           string `json:"serial"`
	Uptime           string `json:"uptime"`
	UptimeVal        int    `json:"uptime_val"`
	BoardName        string `json:"board_name"`
	TempCPUm         int    `json:"temp_cpum"`
	TempSW           int    `json:"temp_sw"`
	TempCPUb         int    `json:"temp_cpub"`
	FanRPM           int    `json:"fan_rpm"`
	BoxAuthenticated bool   `json:"box_authenticated"`
	DiskStatus       string `json:"disk_status"`
	BoxFlavor        string `json:"box_flavor"`
	UserMainStorage  string `json:"user_main_storage"`
}

type TokenRequest

type TokenRequest struct {
	AppId      string `json:"app_id"`
	AppName    string `json:"app_name"`
	AppVersion string `json:"app_version"`
	DeviceName string `json:"device_name"`
}

type WSNotification

type WSNotification struct {
	Action  string          `json:"action"`
	Success bool            `json:"success"`
	Source  string          `json:"source"`
	Event   string          `json:"event"`
	Result  json.RawMessage `json:"result"`
}

type WSRequest

type WSRequest struct {
	RequestID int    `json:"request_id,omitempty"`
	Action    string `json:"action"`
}

type WSResponse

type WSResponse struct {
	RequestID int             `json:"request_id,omitempty"`
	Action    string          `json:"action"`
	Success   bool            `json:"success"`
	Result    json.RawMessage `json:"result"`
	ErrorCode string          `json:"error_code"`
	Msg       string          `json:"msg"`
}

Jump to

Keyboard shortcuts

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