pihole

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 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

func Bool(b bool) *bool

Bool is a helper to return pointer booleans

Types

type CNAMERecord

type CNAMERecord = pihole.CNAMERecord

type CNAMERecordList

type CNAMERecordList = pihole.CNAMERecordList

type CNAMERecordsListResponse

type CNAMERecordsListResponse struct {
	Data [][]string
}

func (CNAMERecordsListResponse) ToCNAMERecordList

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

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

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

CreateGroup creates a group with the passed attributes

func (Client) DeleteCNAMERecord

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

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

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

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

GetGroup returns a Pi-hole group by name

func (Client) GetGroupByID

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

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

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

ListDomains returns a list of domains

func (Client) ListGroups

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

ListGroups returns the list of gravity DB groups

func (*Client) Login

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

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

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

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

type DomainList []*Domain

type DomainResponse

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

func (d DomainResponse) ToDomain() *Domain

type DomainResponseList

type DomainResponseList struct {
	Data []*DomainResponse
}

func (DomainResponseList) ToDomainList

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

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

type GroupBasicResponse

type GroupBasicResponse struct {
	Success bool
	Message string
}

type GroupCreateRequest

type GroupCreateRequest struct {
	Name        string
	Description string
}

type GroupList

type GroupList []*Group

type GroupResponse

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

func (gr GroupResponse) ToGroup() *Group

ToGroup converts a GroupResponse to a Group

type GroupResponseList

type GroupResponseList struct {
	Data []GroupResponse
}

func (GroupResponseList) ToGroupList

func (grl GroupResponseList) ToGroupList() GroupList

ToGroup converts a GroupResponseList to a GroupList

type GroupUpdateRequest

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

type ListDomainsOptions

type ListDomainsOptions struct {
	Type string
}

type NotFoundError

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

func NewNotFoundError

func NewNotFoundError(message string) *NotFoundError

New returns a new NotFoundError

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (NotFoundError) Is

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