restrictions

package
v0.0.0-...-b712c99 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DndPrefix used throughout the domain restrictions to identify which are maintained by the program.
	DndDomainPrefix = "#dnd"
	// DndApplication prefix identify which resources were created by the program to restrict the appliations.
	DndApplicationPrefix = "com.dnd."
)

Variables

View Source
var (
	// ErrPartialSync is returned when not all items could be checked
	// for a 100% synchronization.
	ErrPartialSync = errors.New("partially synchronized state")

	// ErrPartialCommit is returned when not all items could be commited
	// at the OS level, meaning not all items from the configuration
	// will take effect.
	ErrPartialCommit = errors.New("partially commited state")
)
View Source
var TypeFromString = map[string]Type{
	"Domain":      Domain,
	"Application": Application,
}

Functions

func ConfigPath

func ConfigPath() string

func CreateConfigDir

func CreateConfigDir() error

func WriteConfig

func WriteConfig(c *Config) error

Types

type Config

type Config struct {
	// LastCommited is the latest commited config
	LastCommited *Config `json:"LastCommited,omitempty"`
	// Version of the config
	Version int64
	// Currently stored restrictions.
	Restrictions map[Type]List
}

func ReadConfig

func ReadConfig() (*Config, error)

type Diff

type Diff struct {
	Type    Type
	Matched []any
	Missing []any
	Delete  []any
}

func (*Diff) Commit

func (d *Diff) Commit() error

func (*Diff) Print

func (d *Diff) Print(w io.Writer)

type List

type List string

List is a comma separated list of values that describe addresses that must restricted

func (List) Append

func (l List) Append(v string) List

Appends the new element to the list.

func (List) Empty

func (l List) Empty() bool

func (List) Items

func (l List) Items() []string

Returns the items of the list.

func (List) Remove

func (l List) Remove(v string) (List, bool)

Remove deletes the first occurence of v in the list.

type RApplication

type RApplication struct {
	Pattern string
}

func NewApplication

func NewApplication(item string) RApplication

func SyncApplications

func SyncApplications() ([]RApplication, error)

type RDomain

type RDomain struct {
	Restrictions []struct {
		IP      string
		Domains []string
		Raw     string
	}
	// contains filtered or unexported fields
}

RDomain is a domain restrictions that will block access to the specified domains, such as www.google.com etc.

func NewDomain

func NewDomain(item string) RDomain

func SyncDomains

func SyncDomains() ([]RDomain, error)

func (RDomain) Equal

func (d RDomain) Equal(o RDomain) bool

func (RDomain) String

func (d RDomain) String() string

type Type

type Type uint8

Type of a BlockedItem.

const (
	Invalid Type = iota
	// Represents a domain name that should be blocked.
	Domain
	// Represents application installed on the system that should
	// not be able to run.
	Application
	TypeEnd
)

func (Type) Diff

func (t Type) Diff(l List) (Diff, error)

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

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