Giter Club home page Giter Club logo

uisp-mikrotik-freeradius's Introduction

UISP MikroTik & FreeRadius Integration Script

This script allows Internet Service Providers which use UISP to suspend client traffic transiting their MikroTik routers. It also allows for restricting DHCP leases to only the equipment IPs of known customers.

Purpose

This is primarily meant to be a starting point for your own integration. It assumes certain things like that you have a dual stack IPv4/IPv6 network. You can modify the code to suit your needs.

Requirements

  • A self-hosted UISP instance (not hosted by Ubiquiti)
  • A VM to run this on, running Ubuntu Server 22.04 or more recent.
  • FreeRadius installed on the same VM
  • A MikroTik Edge Router (to block suspended IPs, do NAT)
  • 1 or more MikroTik routers acting as your DHCP server
  • MikroTik ROS on these routers can be v6 or v7

Overview

How it works

This script pulls customer IP addresses from UISP. Customer equipment MAC addresses are added to FreeRadius' allowed MAC addresses. This allows you to do basic DHCP auth to prevent unauthorized DHCP leases. You would toggle the radius option for your DHCP server and enable radius for the mikrotiks that hand out your DHCP leases. Define your DHCP server mikrotiks in mikrotikDHCPRouterList.csv For suspended customers, their corresponding IP addresses are added to a MikroTik firewall list "uisp_suspended".

Suspended clients will have traffic redirected to your UISP instance IP address via this NAT rule.

add action=dst-nat chain=dstnat comment="UISP Suspension" dst-port=80 \
    protocol=tcp src-address-list=uisp_suspended to-addresses=1.2.3.4 \
    to-ports=81
add action=dst-nat chain=dstnat dst-port=443 protocol=tcp src-address-list=\
    uisp_suspended to-addresses=1.2.3.4 to-ports=81

Add this to the top of your firewall NAT entries, replacing 1.2.3.4 with your local UISP server IP address.

Suspended clients will have any non-UISP traffic blocked by these rules (add them to the top of your firewall filter list):

/ip firewall filter
add action=drop chain=forward comment=\
    "UISP Auto Suspension via RADIUS server script" dst-address-list=\
    uisp_suspended in-interface-list=WAN
add action=drop chain=forward out-interface-list=WAN src-address-list=\
    uisp_suspended

Make sure WAN corresponds to an appropriate WAN interface list on your MikroTik Edge

Settings

Modify configFile.py to match your network and UISP settings.

Test functionality

Test functionality first using sudo python3 scheduled.py

Once you have it able to run successfully, proceed to create a systemd service.

Running as a service

Create a systemd file /etc/systemd/system/uispRadius.service by modifying the file uispRadius.service included in this project. Replace YOUR_USER with your user.

Then run sudo systemctl daemon-reload And sudo systemctl enable uispRadius sudo systemctl start uispRadius

uisp-mikrotik-freeradius's People

Contributors

rchac avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.