Git Product home page Git Product logo

focus's Introduction

Focus.py helps you keep focused by applying schedulable firewall rules to distracting websites. An example firewall rule looks like this:

def domain_reddit_com(dt):
    return dt.hour == 21 # allow from 9-10pm

Starting

Linux

Add the following line to the top of your /etc/resolv.conf, before any other nameservers:

nameserver 127.0.0.1

Mac OS X

Go to System Preferences -> Network -> Advanced -> DNS and add 127.0.0.1 as your DNS server.


Now start Focus:

sudo python focus.py &

Filtering Domains

Firewall rules involving schedules and timeframes can get complicated fast. For this reason, the scheduling specification is pure Python, so you can make your filtering rules as simple or as complex as you want.

The default filter rules is created on first startup in /etc/focus_blacklist.py:

import re

def domain_ycombinator_com(dt):
    # return dt.hour % 2 # every other hour
    return False

def domain_reddit_com(dt):
    # return dt.hour in (12, 21) # at noon-1pm, or from 9-10pm
    return False
    
def domain_facebook_com(dt):
    return False

def default(domain, dt):
    # do something with regular expressions here?
    return True

The format is simple; Just define a function named like the domain you want to block, preceeded by "domain_". Have it take a single datetime object and have it return True or False. In the body, you can write whatever logic makes the most sense for you. Maybe you want to write your own Pomodoro routine, or maybe you want to scrape your google calendar for exam dates, and block certain websites on those dates.

For sites without their own scheduler function, the default() function is called.

There's no need to restart Focus if you redefine your schedules.

Configuration

Focus.py tries to start with a sensible configuration, but if you need to change it, edit /etc/focus.json.conf

How it works

Focus.py is, at its core, a DNS server. By making it your primary nameserver, it receives all DNS lookup requests. Based on the domain name being requested, it either responds with a "fail ip" address (blocked), or passes the request on to your other nameservers (not blocked). In both cases, Focus adjusts the TTL of each DNS response so that the service requesting the DNS lookup will do minimal caching on the IP, allowing Focus's filtering rules to be more immediate.

FAQ

  • Q: I started Focus, but it's not blacklisting the site I picked.

  • A: Your browser may be caching that site's ip. Give it a few minutes.

  • Q: Why do I need to start Focus with sudo?

  • A: Focus needs to listen on a privileged port as a DNS server.

  • Q: How do I stop Focus?

  • A: Focus writes its process id to /var/run/focus.py.pid. Kill the process using this process id.

focus's People

Contributors

ikke avatar kjagiello avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.