Sign inSign up

xpyctee/hotspot-mikrotik

By xpyctee

Updated 10 months ago

Image
Networking
Web servers
0

1.7K

xpyctee/hotspot-mikrotik repository overview

Hotspot Mikrotik

This project provides a backend hotspot web application deployed in a Docker container and a web template for the Mikrotik hotspot.

Installation

Installing the Template on MikroTik
  1. Download the MikroTik web template files from the repository under examples/mikrotik_redirect.
  2. Edit the action attribute of the redirect form to set the hotspot.server.url to your server’s IP address or DNS name.

To customize the template, refer to the MikroTik Hotspot Customization Documentation.

  1. To ensure proper backend operation, include the following required input fields:
<!-- Required inputs – do not remove -->
<input type="hidden" name="mac" value="$(mac)">
<input type="hidden" name="link-orig" value="$(link-orig)">
<input type="hidden" name="link-login-only" value="$(link-login-only)">
<!-- Required inputs – do not remove -->
  1. These inputs are required for the CHAP authentication method:
<!--$(if chap-id)-->
<input type="hidden" name="chap-id" value="$(chap-id)">
<input type="hidden" name="chap-challenge" value="$(chap-challenge)">
<!--$(endif)-->
  1. Upload the mikrotik_redirect template folder to your MikroTik files.
MikroTik Hotspot Configuration
  • Create a hotspot profile:
    • Set HTML Directory to mikrotik_redirect
    • Enable HTTP CHAP, MAC Cookie
  • Create hotspot users and profiles for employees and guests.

‼️WARTNING‼️ Don't use HTTP PAP and HTTPS, because these methods transmit the user's password in plain text. In the future, I plan to change the authorization method, but for now, please avoid using these methods for security reasons.

Configurations:
  1. Hotspot profile, using mac-cookie and http-chap is required:
/ip hotspot profile add html-directory=flash/mikrotik_redirect login-by=mac-cookie,http-chap[,https ssl-certificate=hotspot-certificate] ...
  1. Employees, with required name=employee of the user, but you can edit the user password in the backend configuration. The parameter mac-cookie-timeout can be set as needed, default for employees is 30d:
/ip hotspot user profile add name=employees add-mac-cookie=yes mac-cookie-timeout=30d ...
/ip hotspot user add name=employee password=supersecret profile=employees ...
  1. Guests, with required name=guest of the user, but you can edit the password in the backend configuration. The parameter mac-cookie-timeout can be set as needed, default for guests is 1d:
/ip hotspot user profile add name=guests add-mac-cookie=yes mac-cookie-timeout=1d ...
/ip hotspot user add name=guest password=secret profile=guests ...

For more detail read Mikrotik Hotspot User Documentation

Installing the Backend
Prepare PostgresSQL
docker run -d \
    --name hotspot-db \
    -e POSTGRES_DB=hotspot \
    -e POSTGRES_USER=hotspot \
    -e POSTGRES_PASSWORD=OmegaSuperSecret \
    postgres

This command runs a PostgresSQL container named hotspot-db with specific environment variables for database setup.

Create Hotspot container

Start a hotspot backend web-interface container as follows:

docker run -d \
    --name hotspot-app \
    -v /path/to/config:/hotspot/config \
    xpyctee/hotspot-mikrotik:latest-postgres

This command starts a hotspot backend container named hotspot-app with a volume mounted for configuration.

Environment Variables
VariableDescriptionExample Value
DEBUGEnables or disables debug mode.true
HOTSPOT_COMPANY_NAMEThe name of the company displayed in the application."No-name LTD"
HOTSPOT_LANGUAGELanguage for the application."en"
HOTSPOT_DB_URLDatabase connection URL using SQLAlchemy format."postgresql://hotspot:[email protected]:5432/hotspot"
HOTSPOT_ADMIN_USERNAMEUsername for the admin user."admin"
HOTSPOT_ADMIN_PASSWORDPassword for the admin user."admin"
HOTSPOT_GUEST_PASSWORDDefault password for guest users."secret"
HOTSPOT_GUEST_DELAYDuration for guest user access."24h"
HOTSPOT_EMPLOYEE_PASSWORDDefault password for employee users."supersecret"
HOTSPOT_EMPLOYEE_DELAYDuration for employee user access."30d"
HOTSPOT_SENDER_TYPEType of SMS sender (e.g., mikrotik, huawei, smsru)."mikrotik"
HOTSPOT_SENDER_URLURL for the SMS sender API."https://admin:@182.168.88.1/"
FLASK_SECRET_KEYSecret key for Flask application security."your-secret-key"
CACHE_URLURL for the cache server (e.g., Memcached or Redis)."memcached://localhost:11211"
CACHE_SIZECache size in megabytes."1024"
GUNICORN_WORKERSNumber of Gunicorn workers for handling requests."4"
GUNICORN_LOG_LEVELLog level for Gunicorn (e.g., debug, info, warning)."info"
GUNICORN_ADDRAddress for Gunicorn to bind to."[::]"
GUNICORN_PORTPort for Gunicorn to listen on."8080"
Config Examples

Default we have some sms senders:

  1. Mikrotik - Send SMS use Mikrotik RESTful API (Required ROS7).
  2. HUAWEI Modem - Send SMS use HUAWEI Modem's API.
  3. sms.ru - Russian service for SMS sending.

Maybe expand in the future. Examples of APIs see in examples/config

Settings.yaml

For example use mikrotik api configuration file saved in: config/settings.yaml:

settings:
  company_name: No-name LTD
  language: en
  db_url: postgresql://hotspot:[email protected]:5432/hotspot  # OPTIONAL. Url for connect database use SQLAlchemy URL, by default used sqlite db, file created after start in config directory
  cache_url: memcached://localhost:11211 # OPTIONAL. Url for connect cache use URL, by default used in-memory cache
  admin:
    user:
      username: admin
      password: admin  # Default password is admin
  sender:
    type: mikrotik
    url: https://admin:@182.168.88.1/  # Url for REST api of mikrotik RoS Version >=7.9
  hotspot_users:
    guest:
      password: secret # Default password for guests used in mikrotik /ip hotspot user add password=secret ...
      delay: 24h # Hours. You can use suffixes such as: w, d, m, s. Without a suffix, the default is hours.
    employee:
      password: supersecret # Default password for employees used in mikrotik /ip hotspot user add password=supersecret ...
      delay: 30d # Days. You can use suffixes such as: w, d, m, s. Without a suffix, the default is hours.

This YAML configuration file provides settings for the Mikrotik API, company details, and user configurations.

License

This project is licensed under the MIT License.

Authors

Tag summary

Content type

Image

Digest

sha256:6de6315ce

Size

103 MB

Last updated

10 months ago

docker pull xpyctee/hotspot-mikrotik