Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixgo123 #1

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [bep]
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
branches: [master]
pull_request:
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.22.x, 1.23.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ matrix.go-version }}
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
shell: bash
- name: Install golint
run: go install golang.org/x/lint/golint@latest
shell: bash
- name: Update PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Fmt
if: matrix.platform != 'windows-latest' # :(
run: "diff <(gofmt -d .) <(printf '')"
shell: bash
- name: Vet
run: go vet ./...
- name: Staticcheck
run: staticcheck ./...
- name: Lint
run: golint ./...
- name: Test
run: go test -race ./...
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2017 Seth Davis https://curia.solutions/
Copyright (c) 2024 Bjørn Erik Pedersen https://bep.is/

MIT License

Expand Down
41 changes: 0 additions & 41 deletions Makefile

This file was deleted.

124 changes: 2 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# nogo

[![Linux Build Status](https://img.shields.io/travis/seedifferently/nogo.svg?style=flat-square&label=linux+build)](https://travis-ci.org/seedifferently/nogo)
[![Windows Build Status](https://img.shields.io/appveyor/ci/seedifferently/nogo.svg?style=flat-square&label=windows+build)](https://ci.appveyor.com/project/seedifferently/nogo)
## Notes


## Fork notes

I @bep will try to get this merged upstream at some point. I find this tool incredibly useful and have it running as a deamon service on my MacBook.
This is how I have it set up on my MacBook.

The below is the content of my `~/Library/LaunchAgents/is.bep.dns.plist` file. I have a `nogo.db` file in `~/config/nogo` and the `nogo` binary in `~/go/bin`. You obviously need to change the paths to your liking.

Expand Down Expand Up @@ -38,118 +33,3 @@ The below is the content of my `~/Library/LaunchAgents/is.bep.dns.plist` file. I
</plist>
```


## What?

`nogo` blocks access to various sites (ads, tracking, porn, gambling, etc) by
acting as a DNS proxy server with host blacklist support.

It requires minimal setup, and includes a simple web control panel for managing
the host blacklist.

![Screenshot](./screenshot.jpg?raw=true)


## Why?

I wanted an open source ad blocker solution that was more universal than a
browser plugin, and:

* Was easy to utilize with unrooted mobile devices (so that
[battery life could be conserved](https://lifehacker.com/ad-blockers-on-mobile-can-reduce-battery-drain-by-up-to-1764344384)).
* Had a basic web control panel and API for adding, removing, and "pausing"
hosts.
* Provided straightforward cross-platform support and acceptable performance (so
that I could run it from my Raspberry Pi).
* Could be used as a master host "blacklist" service for network-wide ad
blocking (e.g. by configuring the DNS on my router to point to `nogo`).


## How?

Simply [download a binary release](https://github.com/seedifferently/nogo/releases)
for your platform. Or, if you already have Go v1.8 or later installed you can
run: `go get github.com/seedifferently/nogo`

**Note:**

* Be sure to read the *Important post-install steps* outlined below.
* Since `nogo` binds to the DNS port 53 by default, it must be given access to
"privileged" ports (e.g. via `setcap` or `sudo`).
* Run with the `-help` switch for information on additional runtime options
(such as disabling or password protecting the web control panel).


For those who would rather clone the repo and build from source:

1. Install [Go](https://golang.org/doc/install) (requires v1.8 or later).

2. Clone the repo, then `cd` into it.

3. Install the dependencies by running `make deps`. Or if you don't have `make`:
* `go get github.com/miekg/dns`
* `go get github.com/boltdb/bolt`
* `go get github.com/pressly/chi`

4. Build the app by running `make`. Or if you don't have `make`: `go build`

5. Run the app: `sudo ./nogo`


### Important post-install steps:

#### 1. You must add hosts to the blacklist.

`nogo` doesn't ship with a built-in blacklist, so it won't block any hosts until
you add them.

There are currently two methods for adding hosts to the blacklist:

1. Navigate to the web control panel (default: `http://localhost:8080/`) and add
a host using the form.

2. Download a popular hosts list file (e.g. pick one from the list at
https://github.com/StevenBlack/hosts), and execute `nogo` with the `-import`
switch on its first run.


#### 2. You must reconfigure your DNS.

Your computer/mobile device/etc is probably set up by default to utilize a DNS
server which allows connections to any host. Unless you update your DNS
configuration to point to `nogo` (and *only* to `nogo`), nothing will change.

For those of you who may be unfamiliar with how to update your DNS
configuration, check out Google's guide for their DNS service here:
https://developers.google.com/speed/public-dns/docs/using

You can follow their instructions, but don't forget to substitute their DNS
service IP addresses with the sole IP address of the machine running `nogo`.

### Known Issues and Limitations

* The DNS proxy server utilizes a fairly basic configuration, so advanced
features such as EDNS and DNSSEC are not currently supported.
* Due to the fact that the web control panel utilizes a few modern techniques
(such as [flexbox][1] and the [Fetch API][2]), you may experience some issues
with its interface on non-current browsers.

[1]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes
[2]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API


## Who?

My name is Seth and I've been talking to machines in various languages since the
early 90s. If you find this useful and want to say thanks, feel free to
[tweet me][3]. If you'd prefer to give back in some way, you could
[buy me a beer][4], [share some Satoshi][5], or pass [my resume][6] on to
someone you know who is tackling interesting problems using technology.

[3]: https://twitter.com/seedifferently
[4]: https://paypal.me/seedifferently
[5]: https://coinbase.com/seedifferently
[6]: https://resume.sethdavis.name


Copyright (c) 2017 Seth Davis
27 changes: 0 additions & 27 deletions appveyor.yml

This file was deleted.

22 changes: 11 additions & 11 deletions dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"os"
"strings"

"github.com/boltdb/bolt"
"go.etcd.io/bbolt"
)

var errRecordNotFound = errors.New("record not found")
Expand Down Expand Up @@ -44,7 +44,7 @@
return r, nil
}

func (r *Record) Bind(req *http.Request) error {

Check failure on line 47 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

exported method Record.Bind should have comment or be unexported

Check failure on line 47 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

exported method Record.Bind should have comment or be unexported

Check failure on line 47 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, windows-latest)

exported method Record.Bind should have comment or be unexported

Check failure on line 47 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, ubuntu-latest)

exported method Record.Bind should have comment or be unexported

Check failure on line 47 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, macos-latest)

exported method Record.Bind should have comment or be unexported

Check failure on line 47 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, windows-latest)

exported method Record.Bind should have comment or be unexported
return nil
}

Expand All @@ -53,14 +53,14 @@
Disabled bool `json:"disabled"`
}

func (s *APISetting) Bind(req *http.Request) error {

Check failure on line 56 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

exported method APISetting.Bind should have comment or be unexported

Check failure on line 56 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

exported method APISetting.Bind should have comment or be unexported

Check failure on line 56 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, windows-latest)

exported method APISetting.Bind should have comment or be unexported

Check failure on line 56 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, ubuntu-latest)

exported method APISetting.Bind should have comment or be unexported

Check failure on line 56 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, macos-latest)

exported method APISetting.Bind should have comment or be unexported

Check failure on line 56 in dal.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, windows-latest)

exported method APISetting.Bind should have comment or be unexported
return nil
}

func (db *DB) keyCount() (int, error) {
var stats bolt.BucketStats
var stats bbolt.BucketStats

if err := db.View(func(tx *bolt.Tx) error {
if err := db.View(func(tx *bbolt.Tx) error {
// Get bucket stats
stats = tx.Bucket(blacklistKey).Stats()

Expand All @@ -75,7 +75,7 @@
func (db *DB) get(key string) (*Record, error) {
var r *Record

err := db.View(func(tx *bolt.Tx) error {
err := db.View(func(tx *bbolt.Tx) error {
var err error

v := tx.Bucket(blacklistKey).Get([]byte(strings.ToLower(key)))
Expand All @@ -98,7 +98,7 @@
}

func (db *DB) put(key string, r *Record) error {
err := db.Update(func(tx *bolt.Tx) error {
err := db.Update(func(tx *bbolt.Tx) error {
var err error
var v []byte

Expand All @@ -117,7 +117,7 @@
}

func (db *DB) delete(key string) error {
err := db.Update(func(tx *bolt.Tx) error {
err := db.Update(func(tx *bbolt.Tx) error {
return tx.Bucket(blacklistKey).Delete([]byte(strings.ToLower(key)))
})

Expand All @@ -126,12 +126,12 @@

func (db *DB) find(search string) map[string]*Record {
var err error
var recs = make(map[string]*Record)
recs := make(map[string]*Record)

if search != "" {
search = strings.ToLower(search)

db.View(func(tx *bolt.Tx) error {
db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket(blacklistKey)

b.ForEach(func(k, v []byte) error {
Expand Down Expand Up @@ -172,15 +172,15 @@

func (db *DB) getPaused() map[string]*Record {
var err error
var recs = make(map[string]*Record)
recs := make(map[string]*Record)

db.View(func(tx *bolt.Tx) error {
db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket(blacklistKey)

b.ForEach(func(k, v []byte) error {
var r *Record

if v == nil || len(v) == 0 {
if len(v) == 0 {
// Skip "sub-buckets" and empty values
return nil
}
Expand Down
Loading
Loading