blckr

Crates.ioblckr
lib.rsblckr
version0.1.2
created_at2025-08-31 05:19:38.528836+00
updated_at2025-12-11 04:26:29.483423+00
descriptionsimple rust website blocker cli for linux systems
homepage
repositoryhttps://github.com/adhanani05/blckr
max_upload_size
id1818169
size14,498
Aditya Dhanani (adhanani05)

documentation

README

blckr

Simple, fast CLI to block and unblock websites on Linux. Designed for quick focus sessions without heavyweight tooling. Includes persistent session history, user presets, and optional automated scheduling.


Install

From crates.io (recommended)

cargo install blckr
sudo install -Dm755 "$HOME/.cargo/bin/blckr" /usr/local/bin/blckr

From source

cargo build --release
sudo install -Dm755 target/release/blckr /usr/local/bin/blckr

Quick Start

Block a domain:

sudo blckr block example.com

Unblock a domain:

sudo blckr unblock example.com

Root privileges are required because the tool writes to /etc/hosts.


Usage

Syntax

blckr <action> <args>

Core Actions

block <domain>            Add block entries to /etc/hosts
unblock <domain>          Remove those exact entries

start <preset>            Begin a block session using a preset
stop                      End the current block session

stats                     Show analytics from SQLite session history

preset add <name> <sites...>
                          Create a reusable preset

schedule add <cron> <preset>
                          Schedule automatic sessions (cron syntax)

Examples

# Basic blocking
sudo blckr block twitter.com
sudo blckr block www.youtube.com
sudo blckr unblock twitter.com

# Create a preset
blckr preset add deepwork twitter.com reddit.com youtube.com

# Use the preset
sudo blckr start deepwork
sudo blckr stop

# Schedule daily focus sessions
blckr schedule add "0 9 * * 1-5" deepwork

How It Works

1. /etc/hosts modification

When blocking:

0.0.0.0 <domain>
::1     <domain>

These lines are appended only if the domain does not already appear anywhere in the file.

On unblock:

  • Only those exact lines are removed.

Idempotency

  • Blocking never duplicates existing lines.
  • Unblocking only removes the precise lines added by blckr.

SQLite Local Storage

All persistent state is stored in a local SQLite database (blckr.db):

sessions table

Tracks all blocking sessions.

Fields:

  • start_time
  • end_time
  • duration_minutes
  • sites_blocked
  • preset_used

Used for analytics and history.

presets table

Stores user-defined collections of sites.

Fields:

  • name
  • sites
  • default_duration

Lets you create consistent focus modes like “deepwork” or “nosocial.”

schedules table

Stores cron-style expressions for automated sessions.

Fields:

  • cron_expr
  • preset_name

Loaded on startup and registered as scheduled jobs.


Scheduling

blckr uses tokio-cron-scheduler to run automatic sessions.

On startup:

  1. All schedules are read from SQLite
  2. Each cron expression is registered
  3. When a cron trigger matches the system time, the preset starts

Note: The machine and blckr must be running for scheduled jobs to fire.


Notes and Limitations

  • Linux-only (/etc/hosts path is fixed)
  • Exact domain matching; no wildcard/subdomain support
  • No backfill of missed cron jobs (if laptop is off at trigger time)
  • DNS caches may require flushing
  • Browser DNS over HTTPS may bypass /etc/hosts

DNS Cache Notes

If domains still resolve, flush your DNS:

systemd-resolved:  sudo resolvectl flush-caches
nscd:              sudo systemctl restart nscd
NetworkManager:    sudo systemctl restart NetworkManager

Disable DNS over HTTPS in your browser.


Troubleshooting

Command not found: Ensure $HOME/.cargo/bin is in your PATH.

Permission denied: Use sudo for modifying /etc/hosts.

Domain still resolves after blocking:

  • flush DNS
  • disable DNS over HTTPS
  • check resolution using getent hosts <domain>
  • ensure /etc/nsswitch.conf has files before dns

Unblock failed: If lines were manually edited, remove them manually from /etc/hosts.


Uninstall

From crates.io:

cargo uninstall blckr

Remove the database:

rm -f blckr.db

Clean up any lingering /etc/hosts lines manually if needed.


Development

Build:

cargo build --release

Run (writes to /etc/hosts):

sudo cargo run -- block example.com

Contributing

Issues and PRs are welcome. Please keep changes minimal, predictable, and idempotent.


License

MIT

Commit count: 5

cargo fmt