glinet

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 11 Imported by: 0

README

glinet-client-go

A Go client to access GL.iNet routers. Based on v4 firmware.

Usage

import glinet "github.com/ryanrishi/glinet-client-go"

Run examples

Most examples require authentication. Set GLINET_USERNAME and GLINET_PASSWORD environment variables.

If running through GoLand, I recommend using the EnvFile plugin.

Authentication Overview

$ curl -XPOST http://192.168.8.1/rpc -d '{"jsonrpc": "2.0", "id": 1, "method": "challenge", "params": {"username": "root"}}'
{"id":1,"jsonrpc":"2.0","result":{"salt":"1Aa2BbC3","alg":1,"nonce":"asdflkjasdflkj"}}
$ openssl passwd -1 -salt $salt $GLINET_PASSWORD | tee >hash
$ echo -n "root:$hash:$nonce" | md5sum | tee>login_hash
$ curl -XPOST http://192.168.8.1/rpc -d '{"jsonrpc": "2.0", "id": 1, "method": "login", "params": {"username": "root", "hash": "$login_hash"}}' | jq '.result'
{ "sid": ... }

Documentation

Index

Constants

View Source
const (
	Version = "v0.0.4"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AdGuardService

type AdGuardService service

func (*AdGuardService) GetAdGuardConfig

func (s *AdGuardService) GetAdGuardConfig() (*GetAdGuardConfigResponse, error)

func (*AdGuardService) SetAdGuardConfig

func (s *AdGuardService) SetAdGuardConfig(Enabled bool) error

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string

	Sid string

	// services
	AdGuard *AdGuardService
	Digest  *DigestService
	System  *SystemService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(username string, password []byte) *Client

func NewClientUnauthenticated

func NewClientUnauthenticated() *Client

func NewClientWithHost

func NewClientWithHost(host string, username string, password []byte) *Client

func (*Client) CallWithInterface

func (c *Client) CallWithInterface(method string, params, result interface{}) error

func (*Client) CallWithInterfaceSlice

func (c *Client) CallWithInterfaceSlice(method string, params []interface{}, result interface{}) error

func (*Client) CallWithStringSlice

func (c *Client) CallWithStringSlice(method string, params []string, result interface{}) error

type DigestService

type DigestService service

func (*DigestService) Challenge

func (s *DigestService) Challenge(username string) (*challengeResponse, error)

func (*DigestService) Login

func (s *DigestService) Login(username string, password []byte) (*loginResponse, error)

type GetAdGuardConfigResponse

type GetAdGuardConfigResponse struct {
	Enabled bool `json:"enabled"`
}

type GetSystemStatusResponse

type GetSystemStatusResponse struct {
	Network []struct {
		Online    bool   `json:"online"`
		Up        bool   `json:"up"`
		Interface string `json:"interface"`
	} `json:"network"`
	Wifi []struct {
		Guest   bool   `json:"guest"`
		Ssid    string `json:"ssid"`
		Up      bool   `json:"up"`
		Channel int    `json:"channel"`
		Band    string `json:"band"`
		Name    string `json:"name"`
		Passwd  string `json:"passwd"`
	} `json:"wifi"`
	Service []struct {
		Status  int    `json:"status"`
		PeerId  int    `json:"peer_id,omitempty"`
		Name    string `json:"name"`
		GroupId int    `json:"group_id,omitempty"`
	} `json:"service"`
	Client []struct {
		CableTotal    int `json:"cable_total"`
		WirelessTotal int `json:"wireless_total"`
	} `json:"client"`
	System struct {
		LanIp           string    `json:"lan_ip"`
		DDNSEnabled     bool      `json:"ddns_enabled"`
		TZOffset        string    `json:"tzoffset"`
		GuestIp         string    `json:"guest_ip"`
		FlashApp        int       `json:"flash_app"`
		FlashTotal      int       `json:"flash_total"`
		MemoryTotal     int       `json:"memory_total"`
		MemoryFree      int       `json:"memory_free"`
		Ipv6Enabled     bool      `json:"ipv6_enabled"`
		MemoryBuffCache int       `json:"memory_buff_cache"`
		Uptime          int       `json:"uptime"`
		LoadAverage     []float64 `json:"load_average"`
		CPU             struct {
			Temperature int `json:"temperature"`
		} `json:"cpu"`
		Mode      int `json:"mode"`
		FlashFree int `json:"flash_free"`
		Timestamp int `json:"timestamp"`
	} `json:"system"`
}

type GetSystemTimezoneConfigResponse

type GetSystemTimezoneConfigResponse struct {
	Zonename            string `json:"zonename"`
	TZOffset            string `json:"tzoffset"`
	AutoTimezoneEnabled bool   `json:"autotimezone_enabled"`
	Localtime           int    `json:"localtime"`
	Timezone            string `json:"timezone"`
}

type SetAdGuardConfigRequest

type SetAdGuardConfigRequest struct {
	Enabled bool `json:"enabled"`
}

type SystemService

type SystemService service

func (*SystemService) GetStatus

func (s *SystemService) GetStatus() (*GetSystemStatusResponse, error)

func (*SystemService) GetTimezoneConfig

func (s *SystemService) GetTimezoneConfig() (*GetSystemTimezoneConfigResponse, error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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