pay tonek and mikrotick huu mfumo upo hosted ๐Ÿ“˜ S-NET WiFi Hotspot Management System - README ๐Ÿ“‹ Overview S-NET ni mfumo kamili wa Captive Portal kwa ajili ya kuuza internet kupitia vouchers na online payments (M-Pesa, Airtel, YAS, Halotel). Mfumo unaunganishwa na MikroTik Router na AzamPay kwa ajili ya malipo ya kielektroniki. ๐Ÿ—๏ธ Architecture text โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ INTERNET โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ WEB HOSTING (s-net.co.tz) โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Portal (PHP + HTML) โ”‚ โ”‚ โ”‚ โ”‚ - Voucher Login โ”‚ โ”‚ โ”‚ โ”‚ - Package Selection โ”‚ โ”‚ โ”‚ โ”‚ - Online Payment (AzamPay) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Admin Panel โ”‚ โ”‚ โ”‚ โ”‚ - Dashboard, Vouchers, Transactions, Active Users โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Database (MySQL) โ”‚ โ”‚ โ”‚ โ”‚ - vouchers, transactions, packages, active_sessions โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ (API Communication) โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ MIKROTIK ROUTER (192.168.88.1) โ”‚ โ”‚ - Hotspot Server โ”‚ โ”‚ - User Management (Physical Vouchers) โ”‚ โ”‚ - REST API (Port 8728) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ (WiFi) โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ CLIENTS โ”‚ โ”‚ - Laptops, Phones, Tablets โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ๐Ÿ“ Folder Structure text /home/snetcotz/public_html/ โ”œโ”€โ”€ portal/ # Captive Portal (Frontend) โ”‚ โ””โ”€โ”€ index.php # Portal page โ”œโ”€โ”€ admin/ # Admin Panel โ”‚ โ”œโ”€โ”€ index.php # Dashboard โ”‚ โ”œโ”€โ”€ vouchers.php # Voucher management โ”‚ โ”œโ”€โ”€ transactions.php # Transaction history โ”‚ โ”œโ”€โ”€ active.php # Active users โ”‚ โ”œโ”€โ”€ login.php # Admin login โ”‚ โ””โ”€โ”€ logout.php # Logout โ”œโ”€โ”€ api/ # API Endpoints โ”‚ โ”œโ”€โ”€ activate_voucher.php # Activate voucher โ”‚ โ”œโ”€โ”€ init_payment.php # Start payment โ”‚ โ”œโ”€โ”€ check_payment.php # Check payment status โ”‚ โ”œโ”€โ”€ webhook.php # AzamPay callback โ”‚ โ””โ”€โ”€ delete_expired.php # Delete expired vouchers โ”œโ”€โ”€ config/ # Configuration โ”‚ โ””โ”€โ”€ database.php # Main config file โ”œโ”€โ”€ includes/ # Classes & Functions โ”‚ โ”œโ”€โ”€ AzamPayAPI.php # AzamPay integration โ”‚ โ”œโ”€โ”€ MikroTikAPI.php # MikroTik API โ”‚ โ”œโ”€โ”€ functions.php # Helper functions โ”‚ โ””โ”€โ”€ RouterosAPI.class.php # MikroTik socket API โ”œโ”€โ”€ logs/ # Log files โ””โ”€โ”€ auto_login.php # Auto-login redirect ๐Ÿ”ง Requirements Component Requirement Web Server Apache/Nginx with PHP 7.4+ Database MySQL 5.7+ / MariaDB 10.2+ PHP Extensions mysqli, curl, json, openssl MikroTik RouterOS v6+ (v7 recommended for REST API) AzamPay Account Sandbox or Production credentials SSL Certificate Required for live mode (HTTPS) ๐Ÿš€ Installation Steps 1. Upload Files to Server bash # Upload all files to public_html folder # Ensure permissions are correct chmod 755 /home/snetcotz/public_html chmod 644 /home/snetcotz/public_html/**/*.php chmod 755 /home/snetcotz/public_html/logs 2. Create Database Via phpMyAdmin or command line: sql CREATE DATABASE snetcotz_snet_hotspot; USE snetcotz_snet_hotspot; Import the database schema (from the SQL file provided) 3. Configure Database Connection Edit /config/database.php: php define('DB_HOST', 'localhost'); define('DB_USER', 'snetcotz_swalehe'); define('DB_PASS', 'Your_Database_Password'); define('DB_NAME', 'snetcotz_snet_hotspot'); 4. Configure MikroTik A. Enable REST API (MikroTik v7+) bash /ip service enable rest-api /ip service set rest-api port=8728 /ip service set rest-api address=192.168.88.0/24 B. Setup Hotspot bash /ip hotspot setup # Select interface (bridge1 or wlan1) # Local network: 192.168.88.0/24 # DNS servers: 8.8.8.8, 8.8.4.4 C. Configure Walled Garden bash /ip hotspot walled-garden ip add dst-address=s-net.co.tz /ip hotspot walled-garden ip add dst-address=192.168.88.1 D. Set MikroTik Password in Config php // /config/database.php define('MIKROTIK_HOST', '192.168.88.1'); define('MIKROTIK_USER', 'admin'); define('MIKROTIK_PASS', 'your_mikrotik_password'); define('MIKROTIK_PORT', 8728); define('MIKROTIK_USE_REST', true); // For v7+ ๐Ÿ’ณ AzamPay Integration Step 1: Get AzamPay Credentials Login to AzamPay Portal (Sandbox) or Production Register your application Get: Client ID Client Secret API Key Step 2: Configure AzamPay in /config/database.php php // For SANDBOX (Testing) define('AZAMPAY_APP_NAME', 'SNET_WiFi'); define('AZAMPAY_CLIENT_ID', 'your_client_id'); define('AZAMPAY_CLIENT_SECRET', 'your_client_secret'); define('AZAMPAY_API_KEY', 'your_api_key'); define('AZAMPAY_ENVIRONMENT', 'SANDBOX'); define('AZAMPAY_API_BASE', 'https://sandbox.azampay.co.tz'); // For PRODUCTION (Live) // define('AZAMPAY_ENVIRONMENT', 'PRODUCTION'); // define('AZAMPAY_API_BASE', 'https://api.azampay.co.tz'); Step 3: Set Webhook URL in AzamPay Portal text https://s-net.co.tz/api/webhook.php Step 4: Set Demo Mode php // For testing (no real money) define('DEMO_MODE', true); // For live payments // define('DEMO_MODE', false); ๐Ÿ” Admin Panel Setup Default Login Credentials Field Value URL https://s-net.co.tz/admin/login.php Username admin Password admin123 Change Admin Password Edit /admin/login.php: php if ($username === 'admin' && $password === 'your_new_password') { // ... } ๐Ÿช How the System Works For Physical Vouchers (Prepaid) text 1. Admin creates vouchers in MikroTik WinBox 2. Customer buys voucher (cash payment to agent) 3. Customer connects to S-NET WiFi 4. Portal opens automatically 5. Customer enters voucher code 6. System verifies with MikroTik 7. Customer gets internet access For Online Payments (M-Pesa/Airtel/YAS/Halotel) text 1. Customer connects to S-NET WiFi 2. Portal opens โ†’ Select "Nunua Package" 3. Choose package (e.g., S-NET 24 HOURS) 4. Enter phone number โ†’ Click "Lipa & Uunganishe" 5. Receive STK Push โ†’ Enter PIN 6. Payment confirmed via webhook 7. Voucher generated automatically 8. Customer auto-connected to internet ๐Ÿ› ๏ธ MikroTik Configuration Details Enable REST API (MikroTik v7+) bash /ip service print /ip service enable [find name=rest-api] /ip service set rest-api port=8728 /ip service set rest-api address=0.0.0.0/0 Create Hotspot Profile bash /ip hotspot profile add name=snet hotspot-address=192.168.88.1 login-by=http-chap /ip hotspot set [find] profile=snet Create Hotspot Server bash /ip hotspot add name=hotspot1 interface=bridge1 address-pool=dhcp_pool1 profile=snet Add DNS Entry for Portal bash /ip dns static add name=s-net.co.tz address=192.168.88.1 ๐Ÿ“ฑ Portal Features Feature Description Voucher Login Enter voucher code only (no password) Package Purchase Select internet package Mobile Money M-Pesa, Airtel, YAS, Halotel STK Push Real payment prompt on phone Auto-Connect No voucher re-entry after payment Mobile Responsive Works on all devices ๐Ÿ–ฅ๏ธ Admin Panel Features Page Features Dashboard Statistics, charts, recent transactions Vouchers View, search, filter, delete expired Transactions View all payments, filter by date/status, export CSV Active Users See connected users, remaining time countdown Mobile Navigation Bottom nav bar on phones ๐Ÿ”„ Cron Jobs (Optional) Auto-delete expired vouchers (daily at 2 AM) bash 0 2 * * * php /home/snetcotz/public_html/cron/cleanup_vouchers.php Auto-update expired status (already in database.php) php // Runs on every page load in config/database.php @mysqli_query($conn, "UPDATE vouchers SET status = 'expired' WHERE status = 'active' AND expires_at < NOW()"); ๐Ÿงช Testing Test MikroTik Connection php // Create test file: /api/test_mikrotik.php checkHotspotUser('test123'); print_r($result); ?> Test AzamPay Connection php // Create test file: /api/test_azampay.php getAccessToken(); echo $token ? "โœ… Token: $token" : "โŒ Failed"; ?> ๐Ÿ› Troubleshooting Issue Solution Portal not opening Check Walled Garden in MikroTik Voucher not found Verify voucher exists in MikroTik MikroTik API error (401) Check password in MIKROTIK_PASS MikroTik API error (404) Enable REST API on MikroTik v7+ STK Push not received Check AzamPay credentials (Sandbox vs Production) Webhook not working Verify URL is HTTPS and accessible Admin white screen Check database connection and tables Physical voucher not working Verify checkHotspotUser() function ๐Ÿ“Š Database Tables Table Purpose vouchers All voucher codes and status transactions Payment history packages Internet packages (price, hours) active_sessions Currently connected users admin_users Admin login credentials webhook_logs AzamPay callback logs payment_logs API request/response logs ๐Ÿ”’ Security Notes Change default admin password Use HTTPS in production Keep AzamPay credentials secure Set proper file permissions (644 for files, 755 for folders) Disable display_errors in production (set to 0) Use environment variables (.env file) for sensitive data ๐Ÿ“ Environment Variables (.env) Create .env file in root: env DB_HOST=localhost DB_USER=snetcotz_swalehe DB_PASS=your_password DB_NAME=snetcotz_snet_hotspot AZAMPAY_CLIENT_ID=your_client_id AZAMPAY_CLIENT_SECRET=your_client_secret AZAMPAY_API_KEY=your_api_key AZAMPAY_ENVIRONMENT=SANDBOX MIKROTIK_HOST=192.168.88.1 MIKROTIK_USER=admin MIKROTIK_PASS=your_mikrotik_password DEMO_MODE=true ๐Ÿ“ž Support Contact Information Phone +255 786 933 185 WhatsApp +255 788 344 848 Website lawi.free.nf Email support@s-net.co.tz ๐Ÿ‘จโ€๐Ÿ’ป Credits Designed by: Lawi Rashidi System Name: S-NET (Solution for All Together) Version: 2.0 ๐Ÿ“„ License Copyright ยฉ 2026 S-NET. All rights reserved. ๐ŸŽ‰ Mfumo Uko Tayari Kwa Matumizi!