pihole

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DomainTypeAllow indicates a domain that is added to the allow list
	DomainTypeAllowExact int = 0
	// DomainTypeDeny indicates a domain that is added to the deny list
	DomainTypeDenyExact int = 1
	// DomainTypeAllowWildcard indicates a wildcard domain added to the allow list
	DomainTypeAllowWildcard int = 2
	// DomainTypeDenyWildcard indicates a wildcard domain added to the deny list
	DomainTypeDenyWildcard int = 3
)
View Source
const (
	// DomainOptionsAllow is a filter option corresponding to domains on the allowed list
	DomainOptionsAllow string = "allow"
	// DomainOptionsDeny is a filter option corresponding to domains on the deny list
	DomainOptionsDeny string = "deny"
)

Variables

View Source
var (
	// ErrLoginFailed is returned when a login attempt fails
	ErrLoginFailed = errors.New("login failed")
	// ErrClientValidationFailed
	ErrClientValidationFailed = errors.New("client validation failed")
	// ErrNotImplementedTokenClient is returned when a particular Pi-hole resource cannot be managed due to missing client configuration
	ErrNotImplementedTokenClient = errors.New("resource is not implemented for the API token client")
)

Functions

func Bool added in v0.0.5

func Bool(b bool) *bool

Bool is a helper to return pointer booleans

Types

type CNAMERecord added in v0.0.2

type CNAMERecord = pihole.CNAMERecord

type CNAMERecordList added in v0.0.2

type CNAMERecordList = pihole.CNAMERecordList

type CNAMERecordsListResponse added in v0.0.2

type CNAMERecordsListResponse struct {
	Data [][]string
}

func (CNAMERecordsListResponse) ToCNAMERecordList added in v0.0.3

func (rr CNAMERecordsListResponse) ToCNAMERecordList() CNAMERecordList

ToCNAMERecordList converts a CNAMERecordsListResponse into a CNAMERecordsList object.

type Client

type Client struct {
	URL       string
	UserAgent string
	// contains filtered or unexported fields
}

func New

func New(config Config) *Client

New returns a new Pi-hole client

func (Client) CreateCNAMERecord added in v0.0.3

func (c Client) CreateCNAMERecord(ctx context.Context, record *CNAMERecord) (*CNAMERecord, error)

CreateCNAMERecord handles CNAME record creation

func (Client) CreateDNSRecord

func (c Client) CreateDNSRecord(ctx context.Context, record *DNSRecord) (*DNSRecord, error)

CreateDNSRecord creates a pihole DNS record entry

func (Client) CreateGroup added in v0.0.5

func (c Client) CreateGroup(ctx context.Context, gr *GroupCreateRequest) (*Group, error)

CreateGroup creates a group with the passed attributes

func (Client) DeleteCNAMERecord added in v0.0.3

func (c Client) DeleteCNAMERecord(ctx context.Context, domain string) error

DeleteCNAMERecord handles CNAME record deletion for the passed domain

func (Client) DeleteDNSRecord

func (c Client) DeleteDNSRecord(ctx context.Context, domain string) error

DeleteDNSRecord deletes a pihole local DNS record by domain name

func (Client) DeleteGroup added in v0.0.5

func (c Client) DeleteGroup(ctx context.Context, name string) error

DeleteGroup deletes a group

func (Client) GetAdBlockerStatus

func (c Client) GetAdBlockerStatus(ctx context.Context) (*EnableAdBlock, error)

GetAdBlockerStatus returns whether pihole ad blocking is enabled or not

func (Client) GetCNAMERecord added in v0.0.3

func (c Client) GetCNAMERecord(ctx context.Context, domain string) (*CNAMERecord, error)

GetCNAMERecord returns a CNAMERecord for the passed domain if found

func (Client) GetDNSRecord

func (c Client) GetDNSRecord(ctx context.Context, domain string) (*DNSRecord, error)

GetDNSRecord searches the pihole local DNS records for the passed domain and returns a result if found

func (Client) GetGroup added in v0.0.5

func (c Client) GetGroup(ctx context.Context, name string) (*Group, error)

GetGroup returns a Pi-hole group by name

func (Client) GetGroupByID added in v0.0.9

func (c Client) GetGroupByID(ctx context.Context, id int64) (*Group, error)

GetGroupByID returns a Pi-hole group by ID

func (*Client) Init

func (c *Client) Init(ctx context.Context) error

Init sets fields on the client which are a product of pihole network requests or other side effects

func (Client) ListCNAMERecords added in v0.0.2

func (c Client) ListCNAMERecords(ctx context.Context) (CNAMERecordList, error)

ListCNAMERecords returns a list of the configured CNAME Pi-hole records

func (Client) ListDNSRecords

func (c Client) ListDNSRecords(ctx context.Context) (DNSRecordList, error)

ListDNSRecords Returns the list of custom DNS records configured in pihole

func (Client) ListDomains added in v0.0.7

func (c Client) ListDomains(ctx context.Context, opts ListDomainsOptions) (DomainList, error)

ListDomains returns a list of domains

func (Client) ListGroups added in v0.0.4

func (c Client) ListGroups(ctx context.Context) (GroupList, error)

ListGroups returns the list of gravity DB groups

func (*Client) Login added in v0.2.0

func (c *Client) Login(ctx context.Context) error

Login creates a session and sets the proper attributes on the client for session based requests (not api token reqeuests)

func (*Client) Request

func (c *Client) Request(ctx context.Context, method string, path string, data *url.Values) (*http.Request, error)

Request executes a basic unauthenticated http request

func (Client) RequestWithAuth

func (c Client) RequestWithAuth(ctx context.Context, method string, path string, data *url.Values) (*http.Request, error)

RequestWithAuth adds an auth token to the passed request

func (Client) RequestWithSession

func (c Client) RequestWithSession(ctx context.Context, method string, path string, data *url.Values) (*http.Request, error)

RequestWithSession executes a request with appropriate session authentication

func (Client) SetAdBlockEnabled

func (c Client) SetAdBlockEnabled(ctx context.Context, enable bool) (*EnableAdBlock, error)

SetAdBlockEnabled sets whether pihole ad blocking is enabled or not

func (Client) UpdateGroup added in v0.0.5

func (c Client) UpdateGroup(ctx context.Context, gr *GroupUpdateRequest) (*Group, error)

UpdateGroup updates a group resource with the passed attribute

type Config

type Config struct {
	Password  string
	URL       string
	UserAgent string
	Client    *http.Client
	APIToken  string
}

type CreateCNAMERecordResponse added in v0.0.3

type CreateCNAMERecordResponse struct {
	Success bool
	Message string
}

type CreateDNSRecordResponse

type CreateDNSRecordResponse struct {
	Success bool
	Message string
}

type DNSRecord

type DNSRecord = pihole.DNSRecord

type DNSRecordList

type DNSRecordList = pihole.DNSRecordList

type DNSRecordsListResponse

type DNSRecordsListResponse struct {
	Data [][]string
}

func (DNSRecordsListResponse) ToDNSRecordList

func (rr DNSRecordsListResponse) ToDNSRecordList() DNSRecordList

ToDNSRecordList converts a DNSRecordsListResponse into a DNSRecordList object.

type Domain added in v0.0.7

type Domain struct {
	ID           int64
	Type         string
	Enabled      bool
	Domain       string
	Comment      string
	DateAdded    time.Time
	DateModified time.Time
	Wildcard     bool
	GroupIDs     []int64
}

type DomainList added in v0.0.7

type DomainList []*Domain

type DomainResponse added in v0.0.7

type DomainResponse struct {
	ID           int64   `json:"id"`
	Type         int     `json:"type"`
	Enabled      int     `json:"enabled"`
	Domain       string  `json:"domain"`
	Comment      string  `json:"comment"`
	DateAdded    int64   `json:"date_added"`
	DateModified int64   `json:"date_modified"`
	Groups       []int64 `json:"groups"`
}

func (DomainResponse) ToDomain added in v0.0.7

func (d DomainResponse) ToDomain() *Domain

type DomainResponseList added in v0.0.7

type DomainResponseList struct {
	Data []*DomainResponse
}

func (DomainResponseList) ToDomainList added in v0.0.7

func (l DomainResponseList) ToDomainList() DomainList

type EnableAdBlock

type EnableAdBlock struct {
	Enabled bool
}

type EnableAdBlockResponse

type EnableAdBlockResponse struct {
	Status string
}

func (EnableAdBlockResponse) ToEnableAdBlock

func (eb EnableAdBlockResponse) ToEnableAdBlock() *EnableAdBlock

ToEnableAdBlock turns am EnableAdBlockResponse into an EnableAdBlock object

type Group added in v0.0.4

type Group struct {
	ID           int64
	Enabled      bool
	Name         string
	DateAdded    time.Time
	DateModified time.Time
	Description  string
}

type GroupBasicResponse added in v0.0.5

type GroupBasicResponse struct {
	Success bool
	Message string
}

type GroupCreateRequest added in v0.0.5

type GroupCreateRequest struct {
	Name        string
	Description string
}

type GroupList added in v0.0.4

type GroupList []*Group

type GroupResponse added in v0.0.4

type GroupResponse struct {
	ID           int64  `json:"id"`
	Enabled      int    `json:"enabled"`
	Name         string `json:"name"`
	DateAdded    int64  `json:"date_added"`
	DateModified int64  `json:"date_modified"`
	Description  string `json:"description"`
}

func (GroupResponse) ToGroup added in v0.0.4

func (gr GroupResponse) ToGroup() *Group

ToGroup converts a GroupResponse to a Group

type GroupResponseList added in v0.0.4

type GroupResponseList struct {
	Data []GroupResponse
}

func (GroupResponseList) ToGroupList added in v0.0.4

func (grl GroupResponseList) ToGroupList() GroupList

ToGroup converts a GroupResponseList to a GroupList

type GroupUpdateRequest added in v0.0.5

type GroupUpdateRequest struct {
	Name        string
	Enabled     *bool
	Description string
}

type ListDomainsOptions added in v0.0.7

type ListDomainsOptions struct {
	Type string
}

type NotFoundError added in v0.0.3

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

func NewNotFoundError added in v0.0.3

func NewNotFoundError(message string) *NotFoundError

New returns a new NotFoundError

func (*NotFoundError) Error added in v0.0.3

func (e *NotFoundError) Error() string

func (NotFoundError) Is added in v0.0.3

func (e NotFoundError) Is(target error) bool

Jump to

Keyboard shortcuts

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