A Django-based captive portal for WiFi hotspots with M-Pesa payment integration.
SafariFi lets you monetize WiFi access by redirecting users to a login and payment portal when they connect to your hotspot. Built with Django and integrated with Safaricom’s Daraja API, it provides a simple and secure way to sell internet access using M-Pesa payments.
- Secure Django backend with configurable environment settings
- Captive portal redirection for Android, iOS, Windows, and Linux
- M-Pesa integration for real-time voucher purchase and validation
- Device-aware login flows
- Admin dashboard to manage users, vouchers, and payment logs
- Environment-based
SECRET_KEY
andDEBUG
settings - Proper
ALLOWED_HOSTS
configuration - Sample
.env
file for safer secret management
- Improved OS/device detection
- Wider support for captive portal triggers (e.g.,
http://captive.apple.com
,connectivitycheck.gstatic.com
)
- Fully functional M-Pesa client with:
- STK push
- Callback validation
- Transaction status checks
- Environment-variable-driven configuration
- Added missing
os
import insettings.py
- Fixed missing
include()
inurls.py
- Modularized and cleaned up M-Pesa client logic
Follow these steps to set up and run the project locally.
git clone https://github.com/occupyashanti/safariFi.git
cd safariFi
python -m venv venv
source venv/bin/activate
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
Create a .env
file in the project root (same level as manage.py
) and add the following (adjust values as needed):
SECRET_KEY=your_django_secret_key
DEBUG=True
ALLOWED_HOSTS=127.0.0.1,localhost
MPESA_CONSUMER_KEY=your_consumer_key
MPESA_CONSUMER_SECRET=your_consumer_secret
MPESA_SHORTCODE=your_shortcode
MPESA_PASSKEY=your_passkey
MPESA_CALLBACK_URL=https://yourdomain.com/api/payment/callback/
A sample .env.example
file is provided for reference.
python manage.py migrate
python manage.py createsuperuser
Follow the prompts to set up your admin login credentials.
python manage.py runserver
Visit http://127.0.0.1:8000/
in your browser. You can access the Django admin panel at http://127.0.0.1:8000/admin/
.