procrastiproxy

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

Overview

Go Report Card CircleCI

Procrastiproxy Open-Source reverse proxy

Procrastiproxy is a simple, configurable proxy that helps you focus by blocking distracting websites.

curl https://raw.githubusercontent.com/zackproser/procrastiproxy/main/install.sh | bash

Example: block reddit and twitter during work hours

procrastiproxy --block reddit.com,twitter.com

Procrastiproxy implements an in-memory, mutable list for tracking hosts that should be blocked. This in-memory list allows for fast (O(1) or "constant time") look-ups of blocked hosts.

graph TD
A[User] -->|Itches to browse something distracting| B(GET reddit.com/)
B --> C(Procrastiproxy)
C --> D{Should this request be allowed?}
D -->|It's not working hours| E(Allow Request)
D -->|It's time to work!| F(Access denied!)

Getting started

Install with one command

To install procrastiproxy as a command-line interface (CLI) tool, you can execute the install script:

curl https://raw.githubusercontent.com/zackproser/procrastiproxy/main/install.sh | bash

Install as a library

You can import procrastiproxy into your own project:

import github.com/zackproser/procrastiproxy

Install via Go

You can install and use procrastiproxy as a command line interface (CLI) tool:

go install github.com/zackproser/procrastiproxy

Build from source and run locally

go build -o procrastiproxy ./cmd

./procrastiproxy --port 8001

Features

Configurable and dynamic block list

The block list is kept in-memory and is implemented as a map for fast lookups. You can set your baseline block list in .procrastiproxy.yaml. It can be modified at runtime via the admin control endpoints described below.

Admin control

Make a request to the <server-root>/admin/ path, passing either block or unblock followed by a host, like so:

Add a new host to the block list

curl http://localhost:8001/admin/block/reddit.com

Remove a host from the block list

curl http://localhost:8001/admin/unblock/reddit.com

Office hours

If a request is made to procrastiproxy within the configured office hours, the request will be examined and blocked if its host is on the block list. If a request is made to procrastiproxy outside of the configured office hours, it will be allowed.

Running tests

Procrastiproxy comes complete with tests to verify its functionality.

go test

Documentation

Overview

Copyright © 2022 Zack Proser zackproser@gmail.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var DefaultNow = time.Now

DefaultNow is the default implementation of Procrastiproxy's Now function, as we want procrastiproxy to return the actual time during normal operations. In testing, we override this method with static values (e.g., 9:00PM or 3:23 AM) in test cases to simulate different wall-times for verifiying procrastiproxy's behavior

Functions

func AddHostToBlockList

func AddHostToBlockList(list *List, hosts ...string)

Build the fast, in-memory list of blocked hosts from the configured values

func RunCLI

func RunCLI() error

RunCLI is the main entrypoint for the procrastiproxy package

func RunServer

func RunServer(args []string)

func SlicesAreEqual added in v0.0.6

func SlicesAreEqual(a, b []string) bool

Types

type AdminCommand

type AdminCommand struct {
	Command string
	Host    string
}

type EmptyBlockListError added in v0.0.6

type EmptyBlockListError struct{}

func (EmptyBlockListError) Error added in v0.0.6

func (err EmptyBlockListError) Error() string

type InvalidTimeFormatError added in v0.0.6

type InvalidTimeFormatError struct {
	FlagName   string
	Value      string
	Underlying error
}

func (InvalidTimeFormatError) Error added in v0.0.6

func (err InvalidTimeFormatError) Error() string

type List

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

func GetList

func GetList() *List

GetList returns the list singleton

func NewList

func NewList() *List

func (*List) Add

func (l *List) Add(item string)

Add appends an item to the list

func (*List) All

func (l *List) All() []string

All returns every member of the list

func (*List) Clear added in v0.0.6

func (l *List) Clear()

Clear resets the list, deleting all members

func (*List) Contains

func (l *List) Contains(item string) bool

Contains returns true if the supplied item is a member of the list

func (*List) Length added in v0.0.6

func (l *List) Length() int

Length returns the number of members in the list

func (*List) Remove

func (l *List) Remove(item string)

Remove deletes an item from the list

type Procrastiproxy

type Procrastiproxy struct {
	Now  func() time.Time
	List *List
	ProxyTimeSettings
}

func NewProcrastiproxy

func NewProcrastiproxy() *Procrastiproxy

func (*Procrastiproxy) ConfigureProxyTimeSettings

func (p *Procrastiproxy) ConfigureProxyTimeSettings(bts, bet string)

func (*Procrastiproxy) GetList added in v0.0.6

func (p *Procrastiproxy) GetList() *List

func (*Procrastiproxy) GetProxyTimeSettings

func (p *Procrastiproxy) GetProxyTimeSettings() ProxyTimeSettings

func (*Procrastiproxy) WithinBlockWindow

func (p *Procrastiproxy) WithinBlockWindow(now time.Time) bool

type ProxyTimeSettings

type ProxyTimeSettings struct {
	Timezone       string
	BlockStartTime string
	BlockEndTime   string
	DefaultLayout  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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