#!/bin/bash
# 🎯 MikroTik RouterOS 6.49.19 - Complete Setup Guide
# ====================================================

echo "🔧 COMPLETE SETUP FOR RouterOS 6.49.19 (hAP lite)"
echo "=================================================="
echo ""
echo "Your RouterOS doesn't support direct http-cookie-auth-url parameters,"
echo "but we can achieve the same result with a custom login page!"
echo ""

echo "✅ STEP 1: Add Walled Garden Rule"
echo "================================="
echo "This allows clients to reach your API before login:"
echo ""
echo "In router CLI (at root prompt):"
echo "/ip hotspot walled-garden add dst-host=api.kitonga.klikcell.com"
echo ""
echo "Alternative with specific port:"
echo "/ip hotspot walled-garden add dst-host=api.kitonga.klikcell.com dst-port=443"
echo ""

echo "✅ STEP 2: Upload Custom Login Page"
echo "===================================="
echo "Your modified login.html is ready at:"
echo "/Users/macbookair/Desktop/kitonga/hotspot_html/login.html"
echo ""
echo "Upload methods:"
echo ""
echo "Option A - Web Interface:"
echo "1. Go to: http://192.168.0.173"
echo "2. Files > Hotspot > login.html"
echo "3. Upload your modified file"
echo ""
echo "Option B - FTP/SCP:"
echo "scp /Users/macbookair/Desktop/kitonga/hotspot_html/login.html admin@192.168.0.173:/hotspot/"
echo ""
echo "Option C - Drag & Drop (Winbox):"
echo "Use Winbox > Files > hotspot folder"
echo ""

echo "✅ STEP 3: Test the Flow"
echo "========================"
echo "1. Connect device to WiFi hotspot"
echo "2. Browser redirects to login page"
echo "3. Enter phone number (e.g., 255700000000)"
echo "4. JavaScript validates with Django API"
echo "5. If payment OK → RouterOS logs user in"
echo "6. If payment needed → user sees error"
echo ""

echo "🔍 VERIFICATION COMMANDS"
echo "========================"
echo "Check walled garden:"
echo "/ip hotspot walled-garden print"
echo ""
echo "Check active users:"
echo "/ip hotspot active print"
echo ""
echo "Check hotspot logs:"
echo "/log print where topics~\"hotspot\""
echo ""

echo "🎯 HOW IT WORKS"
echo "==============="
echo "1. User connects → Router shows custom login page"
echo "2. User enters phone → JavaScript calls Django API"
echo "3. Django checks payment → Returns 200 (OK) or 403 (denied)"
echo "4. If OK → JavaScript submits form to RouterOS"
echo "5. RouterOS creates hotspot session"
echo "6. User gets internet access!"
echo ""

echo "🚀 COMMANDS TO RUN NOW"
echo "======================"
echo "1. Add walled garden:"
echo "   /ip hotspot walled-garden add dst-host=api.kitonga.klikcell.com"
echo ""
echo "2. Upload login.html to router's /hotspot/ directory"
echo ""
echo "3. Test with a real device!"
echo ""

echo "📊 MONITORING"
echo "============="
echo "• Django Admin: https://api.kitonga.klikcell.com/admin/"
echo "• Router Logs: /log print where topics~\"hotspot\""
echo "• Active Sessions: /ip hotspot active print"
echo ""

echo "✅ READY TO GO LIVE!"
echo "===================="
echo "Your WiFi billing system is now configured for RouterOS 6.49.19!"
echo "The JavaScript-based authentication will work perfectly with your setup."
