This repository was archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathapi_internal.go
More file actions
73 lines (62 loc) · 1.93 KB
/
api_internal.go
File metadata and controls
73 lines (62 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package fritz
import (
"net/http"
"github.com/bpicode/fritzctl/httpread"
"github.com/bpicode/fritzctl/logger"
)
// Internal exposes Fritz!Box internal and undocumented API.
type Internal interface {
ListLanDevices() (*LanDevices, error)
ListLogs() (*MessageLog, error)
InternetStats() (*TrafficMonitoringData, error)
}
// NewInternal creates a Fritz/internal API from a given client.
func NewInternal(client *Client) Internal {
return &internal{client: client}
}
type internal struct {
client *Client
}
// ListLogs lists the log statements produced by the FRITZ!Box.
func (i *internal) ListLogs() (*MessageLog, error) {
url := i.
query().
query("mq_log", "logger:status/log").
build()
var logs MessageLog
err := httpread.JSON(i.getf(url), &logs)
return &logs, err
}
// ListLanDevices lists the basic data of the LAN devices.
func (i *internal) ListLanDevices() (*LanDevices, error) {
url := i.
query().
query("network", "landevice:settings/landevice/list(name,ip,mac,UID,dhcp,wlan,ethernet,active,wakeup,deleteable,source,online,speed,guest,url)").
build()
var devs LanDevices
err := httpread.JSON(i.getf(url), &devs)
return &devs, err
}
// InternetStats up/downstream statistics reported by the FRITZ!Box.
func (i *internal) InternetStats() (*TrafficMonitoringData, error) {
url := i.
inetStat().
query("useajax", "1").
query("action", "get_graphic").
build()
var data []TrafficMonitoringData
err := httpread.JSON(i.getf(url), &data)
return &data[0], err
}
func (i *internal) query() fritzURLBuilder {
return newURLBuilder(i.client.Config).path(queryURI).query("sid", i.client.SessionInfo.SID)
}
func (i *internal) inetStat() fritzURLBuilder {
return newURLBuilder(i.client.Config).path(inetStatURI).query("sid", i.client.SessionInfo.SID)
}
func (i *internal) getf(url string) func() (*http.Response, error) {
return func() (*http.Response, error) {
logger.Debug("GET", url)
return i.client.HTTPClient.Get(url)
}
}