GoFritzBox

package module
v0.0.0-...-3f819eb Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: AGPL-3.0 Imports: 15 Imported by: 1

README

GoFritzBox

GoFritzBox is a Golang utility to read or modify Fritz!Box parameters.

Why it is not complete?

Because AVMDE didn't release a documentation for its APIs, building this library is very hard and I won't waste my time building functions that nobody will use.

Dude! There's no good documentation!

Nice point, I really appreciate your attention.
I don't really know what some things are due to the very confusing APIs. I've tried to do my best, you'll have some happy time trying to figure out what's going on.

Some features are ignored!

Yes, send an email to AVM asking for decent APIs, then I can do something about it.
In the same response object there are things with the same name and a different type, I can't work with them in Golang.

Supported features:

  • Login
  • LoadInfo
  • GetStats
  • GetLogs
  • GetAssistanceData
  • Disconnect
  • GetDSLInfo

If you need any other feature you can open an issue and I will try to add it.
Soon, ways to edit the Fritz!Box configuration will be added with an auto CRC32 signature.

Example

package main

import (
	"fmt"

	"github.com/LucaTheHacker/GoFritzBox"
)

func main() {
	session, err := GoFritzBox.Login("http://IP", "USERNAME", "PASSWORD")
	if err != nil {
		panic(err)
	}

	data, err := session.LoadInfo()
	if err != nil {
		panic(err)
	}
	fmt.Println("Fritz!OS version: ", data.FritzOS.Version)

	stats, err := session.GetStats()
	if err != nil {
		panic(err)
	}

	stats.Load()
	fmt.Println(stats.DownstreamTotal)
	fmt.Println(stats.UpstreamTotal)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Changelog

type Changelog struct {
	DeviceName       string  `json:"deviceName"`
	FritzOSVersion   float32 `json:"fritzOsVersion,string"`
	ConnectionStatus bool    `json:"connectionStatus"`
	ProductName      string  `json:"productName"`
	IFrame           string  `json:"iframeUrl"`
}

Changelog contains infos about the Fritz!Box

type Comfort

type Comfort struct {
	Functions []ComfortFunc `json:"func"`
	Any       bool          `json:"anyComfort"`
}

Comfort contains infos about Fritz!Box ComfortFunc

type ComfortFunc

type ComfortFunc struct {
	Name    string `json:"linktxt"`
	Details string `json:"details"`
	Link    string `json:"link"`
}

ComfortFunc contains infos about a Comfort Function

type Connection

type Connection struct {
	Status    string   `json:"status"`
	RunAccess bool     `json:"runAccess"`
	IPList    []IPList `json:"ipList"`
}

type ConnectionData

type ConnectionData struct {
	ExternApValue  string `json:"externApValue"`
	Modell         string `json:"modell"`
	IsDebug        bool   `json:"isDebug"`
	LineLength     int64  `json:"lineLength"`
	ExternAPHeader string `json:"externAPHeader"`
	ExternApText   string `json:"externApText"`
	Line           []Line `json:"line"`
	Version        string `json:"version"`
	Versiontext    string `json:"versiontext"`
	DsRate         string `json:"dsRate"`
	UsRate         string `json:"usRate"`
}

type DSL

type DSL struct {
	Txt         string `json:"txt"`
	Led         string `json:"led"`
	Title       string `json:"title"`
	DiagStopPID string `json:"diag_stop_pid"`
	DiagActive  int    `json:"diag_active,string"`
	AddDiag     string `json:"addDiag"`
	Link        string `json:"link"`
	Upload      string `json:"up"`
	Download    string `json:"down"`
}

DSL contains infos about the connection status

type Data

type Data struct {
	NasLink          string           `json:"naslink"`
	FritzOS          *FritzOS         `json:"fritzos"`
	LANDevices       []*LANDevice     `json:"active"`
	Webdav           int              `json:"webdav,string"`
	Manual           string           `json:"MANUAL_URL"`
	Language         string           `json:"language"`
	AVM              string           `json:"AVM_URL"`
	USBConnect       string           `json:"usbconnect"`
	Foncalls         *Foncalls        `json:"foncalls"`
	VPN              *VPN             `json:"vpn"`
	Internet         *Internet        `json:"internet"`
	DSL              *DSL             `json:"dsl"`
	ServicePortalURL string           `json:"SERVICEPORTAL_URL"`
	Comfort          *Comfort         `json:"comfort"`
	Changelog        *Changelog       `json:"changelog"`
	TamCalls         *TamCalls        `json:"tamcalls"`
	Lan              *External        `json:"lan"`
	Log              *Logs            `json:"log"`
	Filter           int              `json:"filter,string"`
	USB              *External        `json:"usb"`
	FonNum           *External        `json:"fonnum"`
	NewsURL          string           `json:"NEWSLETTER_URL"`
	Net              *Net             `json:"net"`
	Dect             *External        `json:"dect"`
	WLanRaw          *json.RawMessage `json:"wlan"`
	Diag             *Diag            `json:"diag"`
	WLanBool         bool             ``
	WLan             WLan             ``
	ConnectionData   *ConnectionData  `json:"connectionData"`
}

Data contains data about the Fritz!Box WLan needs to be decoded manually, check the type before unmarhsal to WLan or WLanBool

type Device

type Device struct {
	Classes string `json:"classes"`
	Type    string `json:"type"`
	Name    string `json:"name"`
	URL     string `json:"url"`
}

Device contains infos about a device in the LAN

type Diag

type Diag struct {
	Type        string `json:"type"`
	IsBoxOnline bool   `json:"is_box_online"`
	Status      string `json:"status"`
	Result      Result `json:"result"`
	ID          string `json:"id"`
}

type External

type External struct {
	Txt   string `json:"txt"`
	Led   string `json:"led"`
	Title string `json:"title"`
	Link  string `json:"link"`
}

type Foncalls

type Foncalls struct {
	ActiveCalls string `json:"activecalls"`
	Calls       string `json:"-"` // See issue #1
	CallsToday  int    `json:"callsToday,string"`
	Count       int    `json:"count_all"`
	CountToday  int    `json:"count_today"`
}

Foncalls contains info about Calls

type FritzOS

type FritzOS struct {
	Name           string  `json:"Productname"`
	NoPWD          bool    `json:"NoPwd"`
	Defaults       bool    `json:"ShowDefaults"`
	Expert         int     `json:"expert_mode,string"`
	FBName         string  `json:"fb_name"`
	Version        float32 `json:"nspver,string"`
	Labor          bool    `json:"isLabor"`
	TFADisabled    bool    `json:"twofactor_disabled"`
	FirmwareSigned bool    `json:"FirmwareSigned"`
	ShowUpdate     bool    `json:"showUpdate"`
	Updatable      bool    `json:"isUpdateAvail"`
	Energy         int     `json:"energy,string"`
	BoxDate        string  `json:"boxDate"`
}

FritzOS contains infos about the current Fritz!OS version

type IPList

type IPList struct {
	ShowShapedrate bool   `json:"showShapedrate"`
	Date           string `json:"date"`
	IP             string `json:"ip"`
	Ipv6Active     bool   `json:"ipv6Active"`
	DSLite         bool   `json:"DSLite"`
	Time           string `json:"time"`
	IsConnected    bool   `json:"isConnected"`
	Provider       string `json:"provider"`
	Mode           string `json:"mode"`
	IProtocol      string `json:"iProtocol"`
	IsIPClient     bool   `json:"isIpClient"`
}

type Internet

type Internet struct {
	Txt            []string  `json:"txt"`
	Led            string    `json:"led"`
	Online         bool      ``
	Title          string    `json:"title"`
	DownloadString string    `json:"down"`
	Download       int64     ``
	UploadString   string    `json:"up"`
	Upload         int64     ``
	SecondaryLink  string    `json:"link2"`
	Link           string    `json:"link"`
	Provider       string    ``
	ConnectionTime time.Time ``
}

Internet contains data about the internet connection

func (*Internet) Sanitize

func (i *Internet) Sanitize()

Sanitize sanitizes the Internet struct by cleaning bad values and generating data from other values

type LANDevice

type LANDevice struct {
	MAC       string        `json:"mac"`
	Type      string        `json:"type"`
	ConnInfo  []interface{} `json:"conn_info"`
	UID       string        `json:"UID"`
	State     string        `json:"state"`
	Port      string        `json:"port"`
	Name      string        `json:"name"`
	Model     string        `json:"model"`
	Url       string        `json:"url"`
	Classes   string        `json:"classes"`
	IPv4      LANDeviceIPv4 `json:"ipv4"`
	IsTrusted bool          `json:"isTrusted,omitempty"`
}

type LANDeviceIPv4

type LANDeviceIPv4 struct {
	Node     string `json:"_node"`
	AddrType string `json:"addrtype"`
	DHCP     string `json:"dhcp"`
	LastUsed string `json:"lastused"`
	IP       string `json:"ip"`
}

type Line

type Line struct {
	State            string `json:"state"`
	TimePrefix       string `json:"timePrefix"`
	TrainState       string `json:"trainState"`
	Mode             string `json:"mode"`
	TrainStatePrefix string `json:"trainStatePrefix"`
	Time             string `json:"time"`
}

type Logs

type Logs [][]string

func (*Logs) Filter

func (l *Logs) Filter(filter int) Logs

Filter filters Logs by type 0 -> All, 1 -> System, 2 -> Internet, 3 -> Phone, 4 -> Wifi, 5 -> USB

type Net

type Net struct {
	UnmeshedDevices bool      `json:"anyUnmeshedDevices"`
	Count           int       `json:"count"`
	ActiveCount     int       `json:"active_count"`
	More            string    `json:"more_link"`
	Devices         *[]Device `json:"devices"`
}

Net contains infos about Device connected to the Fritz!Box

type RequestData

type RequestData struct {
	PID  string `json:"pid"`
	Data Data   `json:"data"`
	// Hide []Hide `json:"hide"` Removed for security reasons, check issue #1
	// Time []Time `json:"time"` Removed for security reasons, check issue #1
	SID string `json:"sid"`
}

RequestData contains data about the usual Fritz!Box answer

type Result

type Result struct {
	Connection Connection `json:"connection"`
}

type SessionInfo

type SessionInfo struct {
	SID       string      `xml:"SID"`
	Challenge string      `xml:"Challenge"`
	EndPoint  string      ``
	BlockTime int         `xml:"BlockTime"`
	Lang      string      ``
	Rights    interface{} `` // Not Implemented
}

SessionInfo contains info about the current Session SID is the session ID Challenge is a part of the hash used for the Login EndPoint is the endpoint used to do the HTTP requests BlockTime is the cooldown needed after a wrong login, you need to handle it properly, Lang is the lang that the Fritz!Box will use. Usually it's a useless parameters for API, but not on Fritz!OS otherwise all the logins will fail, with the correct authentication as well

func Login

func Login(endpoint, username, password string) (SessionInfo, error)

Login does a login on the Fritz!Box Returns SessionInfo in case of success

func (*SessionInfo) Disconnect

func (s *SessionInfo) Disconnect() error

Disconnect disconnects your Fritz!Box from the internet This is usually used to change your IP address The prodecure can require up to 30 seconds, after that the internet connection will be re-enabled

func (*SessionInfo) GetAssistanceData

func (s *SessionInfo) GetAssistanceData() ([]byte, error)

GetAssistanceData returns the firmwarecfg file useful to generate HLog/QLN graphs

func (*SessionInfo) GetDSLInfo

func (s *SessionInfo) GetDSLInfo() (*ConnectionData, error)

GetDSLInfo returns ConnectionData about your DSL Connection

func (*SessionInfo) GetDiagnosisInternetConnection

func (s *SessionInfo) GetDiagnosisInternetConnection() (*Diag, error)

GetDiagnosisInternetConnection returns TODO: Documentation

func (*SessionInfo) GetLANDevices

func (s *SessionInfo) GetLANDevices() ([]*LANDevice, error)

GetLANDevices returns a list of LANDevice

func (*SessionInfo) GetLogs

func (s *SessionInfo) GetLogs() (Logs, error)

GetLogs returns Logs of the Fritz!Box activity

func (*SessionInfo) GetStats

func (s *SessionInfo) GetStats() (Stats, error)

GetStats returns Stats to build the usage graph

func (*SessionInfo) LoadInfo

func (s *SessionInfo) LoadInfo() (Data, error)

LoadInfo returns general Data about the Fritz!Box

type Stats

type Stats struct {
	DownstreamMax       int     `json:"ds_bps_curr_max"`
	UpstreamMax         int     `json:"us_bps_curr_max"`
	DownstreamCapacity  int     `json:"downstream"`
	UpstreamCapacity    int     `json:"upstream"`
	StaticDownstreamMax int     `json:"ds_bps_max"`
	StaticUpstreamMax   int     `json:"us_bps_max"`
	Dynamic             bool    `json:"dynamic"`
	Node                string  `json:"_node"`
	Mode                string  `json:"mode"`
	Name                string  `json:"name"`
	DownstreamInternet  [19]int `json:"ds_bps_curr"`
	DownstreamIPTV      [19]int `json:"ds_mc_bps_curr"`
	DownstreamGuest     [19]int `json:"ds_guest_bps_curr"`
	UpstreamRealTime    [19]int `json:"us_realtime_bps_curr"`
	UpstreamPriority    [19]int `json:"us_important_bps_curr"`
	UpstreamNormal      [19]int `json:"us_default19_bps_curr"`
	UpstreamBackground  [19]int `json:"us_background_bps_curr"`
	UpstreamGuest       [19]int `json:"guest_us_bps"`
	DownstreamTotal     [19]int ``
	UpstreamTotal       [19]int ``
}

Stats contains infos about the current connection usage These infos are used to build the connection graph

func (*Stats) Load

func (s *Stats) Load()

Load adds Total values to Stats, useful to get the Total internet usage

type TamCalls

type TamCalls struct {
	Calls      string `json:"calls"`
	Configured bool   `json:"tam_configured"`
	Count      int    `json:"count"`
	CallsToday int    `json:"callsToday,string"`
}

type VPN

type VPN struct {
	Elements []interface{} `json:"elements"`
	Title    string        `json:"title"`
	Link     string        `json:"link"`
}

VPN contains infos about the VPN

type WLan

type WLan struct {
	Txt     string `json:"txt"`
	Led     string `json:"led"`
	Title   string `json:"title"`
	Link    string `json:"link"`
	Tooltip string `json:"tooltip"`
}

WLan contains infos about the Wireless Lan

Jump to

Keyboard shortcuts

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