Coder Social home page Coder Social logo

openwrtfw-ha's Introduction

openwrtfw-ha

Integrates OpenWRT firewall with HomeAssistant via MQTT

This is a project in alpha stage. Use at your own risk.

My main goal was to be able to restrict internet access to my 4 year old child on his tablet and on our Roku. OpenWRT has parental controls but they need to be activated by set times which was not working for us. I was logging in into openWRT and activating/deactivating the rules manually. Needless to say, the setup was not intuitive and my wife was not willing to learn it.

I took inspiration in the following tutorial: https://medium.com/@arturlr/using-iot-button-to-control-my-kids-internet-usage-5bd825c1da76

I did not feel particulary inspired to buy an Amazon IOT device, keep batteries for it. In addition, by using iptables directly it breaks the LUCI firewall status display. It is not persistent, and a reboot of the router will revert to the default configuration with no visual feedback of the firewall status.

So I decided to use a software switch, one provided by HomeAssistant. I already have a dashboard where I control lights. I could make a dashboard for controlling the activation/deactivation of firework rules; and will provide visual feedback of the rule status. Individual dashboards can be assigned for determined users which should log in to the system. So potentially in a few years I could give him access to the lighting system and still preserve my internet authority. For the future I am thinking of getting a pin device for his room (https://ezzwave.com/ge-z-wave-plus-hinge-pin-smart-door-sensor) and just allow his internet to be active when the door is open (I guess after 13-14 years old, there is no more point in being the internet control tzar)

For this project I am using un-encrypted mqtt and the firewall rules are based on MAC Addresses. I guess that if he uses wireshark to sniff the MQTT messages or is able to spoof his MAC Address he will be able to overcome the system. I am not expecting him to develop those skill yet and if he does, he will have earned his access.

Other Uses

  • allow/disallow a port forward
    • access to a webserver/ftp server just when you need it.
  • turn on/off a DMZ
  • block your IOT devices from the internet but have an easy way to re-connect them for OTA upgrades
  • with some modifications may allow to report your connectivity to HA.. external IP address, connection speed, etc.

Requirements

OpenWRT - I am using OpenWrt 19.07.2 r10947-65030d81f3

HomeAssistant with configured mosquitto broker and working mqtt integration (you could also run mosquitto broker on openwrt and have HomeAssistant connect to it)

Install dependencies

opkg update

opkg install mosquitto mosquitto-client libmosquitto grep

obtain parse_yaml.sh parser (https://gist.github.com/pkuczynski/8665367)

Setup - OpenWRT

  1. install depependencies using opkg as above
  2. Configure the rules using LUCI or UCI
  3. use the ssh interface to determine which rules you want to control. Use the command "uci show firewall"
  4. make a directory /etc/iot/
  5. copy announcer.sh, listner2.sh, firewall_mqtt.yml, and parse_yaml.sh (see github link above) to your new directory
  6. make the .sh files executable
    • chmod +x announcer.sh
    • chmod +x listner2.sh
    • chmod +x parse_yaml.sh
  7. modify the firewall_mqtt.yml file to your needs.
  8. Create startup script to execute announcer.sh upon device initiation. (working on it, will publish it when ready)

Once you have this, execute announcer.sh from the /etc/iot directory. If everything goes well, the script will announce itself to the mqtt broker.

Setup - HomeAssistant

HA will get the message and will create the proper entities. The entities will not appear as a "new integration". However, they will be available automatically. Just add a button card. The entity name will be switch.name, where name is the name you used in the firewall_mqtt.yml file.

openwrtfw-ha's People

Contributors

robviauc avatar

Stargazers

 avatar  avatar  avatar  avatar somename123 avatar Marc avatar

Watchers

 avatar  avatar

Forkers

tthanhxuan skons

openwrtfw-ha's Issues

issue: yaml file not parsed correctly

It looks like the inline comments in the yaml file are not removed on parsing. They should be (its in the yaml specs) but for some reason they arent. It looks like the problem is in the parse_yaml.sh script.

I'm looking for a workarround and expect that removing all comments could work. will report back when I've tried it

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.