#!/bin/bash # Script Automático para Configuração de Hotspot Social no MikroTik # Execute este script via SSH ou Terminal do RouterOS # ======================================== # CONFIGURAÇÕES INICIAIS - ALTERE AQUI # ======================================== # Nome da interface que será usada para o hotspot (ex: ether2, wlan1) HOTSPOT_INTERFACE="ether2" # Nome do seu Instagram (sem @) INSTAGRAM_USER="piratastoursparaty" # Configurações de rede HOTSPOT_NETWORK="192.168.10.0/24" HOTSPOT_GATEWAY="192.168.10.1" DHCP_POOL_START="192.168.10.100" DHCP_POOL_END="192.168.10.200" # Nome do estabelecimento/empresa BUSINESS_NAME="Escuna Cavendish" # DNS Servers DNS_PRIMARY="8.8.8.8" DNS_SECONDARY="8.8.4.4" echo "==========================================" echo " CONFIGURAÇÃO HOTSPOT SOCIAL MIKROTIK " echo "==========================================" echo "Interface: $HOTSPOT_INTERFACE" echo "Instagram: @$INSTAGRAM_USER" echo "Rede: $HOTSPOT_NETWORK" echo "==========================================" # ======================================== # 1. CONFIGURAÇÃO DA BRIDGE # ======================================== echo "1. Configurando Bridge..." /interface bridge add name=hotspot-bridge comment="Bridge para Hotspot Social" /interface bridge port add bridge=hotspot-bridge interface=$HOTSPOT_INTERFACE echo "✅ Bridge configurada" # ======================================== # 2. CONFIGURAÇÃO DE IP # ======================================== echo "2. Configurando endereços IP..." /ip address add address=$HOTSPOT_GATEWAY/24 interface=hotspot-bridge comment="IP do Hotspot" echo "✅ IP configurado" # ======================================== # 3. CONFIGURAÇÃO DHCP # ======================================== echo "3. Configurando DHCP Server..." # Criar pool de IPs /ip pool add name=hotspot-pool ranges=$DHCP_POOL_START-$DHCP_POOL_END comment="Pool para Hotspot" # Configurar rede DHCP /ip dhcp-server network add address=$HOTSPOT_NETWORK gateway=$HOTSPOT_GATEWAY dns-server=$DNS_PRIMARY,$DNS_SECONDARY comment="Rede Hotspot" # Criar servidor DHCP /ip dhcp-server add name=hotspot-dhcp interface=hotspot-bridge lease-time=1h address-pool=hotspot-pool disabled=no comment="DHCP Hotspot" echo "✅ DHCP configurado" # ======================================== # 4. PERFIS DE USUÁRIO # ======================================== echo "4. Criando perfis de usuário..." # Perfil Trial (15 minutos, 2M/1M) /ip hotspot user profile add name=trial-15min \ session-timeout=15m \ shared-users=1 \ rate-limit=2M/1M \ idle-timeout=5m \ keepalive-timeout=2m \ status-autorefresh=5m \ comment="Perfil Trial 15 minutos" # Perfil Social (4 horas, 5M/2M) /ip hotspot user profile add name=social-4h \ session-timeout=4h \ shared-users=1 \ rate-limit=5M/2M \ idle-timeout=10m \ keepalive-timeout=2m \ status-autorefresh=5m \ comment="Perfil Social 4 horas" # Perfil Premium (ilimitado, 10M/5M) /ip hotspot user profile add name=premium \ session-timeout=0 \ shared-users=1 \ rate-limit=10M/5M \ idle-timeout=0 \ keepalive-timeout=2m \ status-autorefresh=5m \ comment="Perfil Premium ilimitado" echo "✅ Perfis de usuário criados" # ======================================== # 5. PERFIL DO HOTSPOT # ======================================== echo "5. Configurando perfil do hotspot..." /ip hotspot profile add name=social-hotspot \ hotspot-address=$HOTSPOT_GATEWAY \ dns-name=login.wifi \ html-directory=hotspot \ http-proxy=0.0.0.0:0 \ login-by=trial,http-chap,https \ split-user-domain=no \ use-radius=no \ comment="Perfil Hotspot Social" echo "✅ Perfil do hotspot configurado" # ======================================== # 6. SERVIDOR HOTSPOT # ======================================== echo "6. Criando servidor hotspot..." /ip hotspot add name=social-hotspot \ interface=hotspot-bridge \ address-pool=hotspot-pool \ profile=social-hotspot \ idle-timeout=5m \ keepalive-timeout=2m \ addresses-per-mac=1 \ disabled=no \ comment="Servidor Hotspot Social" echo "✅ Servidor hotspot criado" # ======================================== # 7. WALLED GARDEN # ======================================== echo "7. Configurando Walled Garden..." # Sites permitidos sem autenticação /ip hotspot walled-garden add dst-host=*.facebook.com comment="Facebook" /ip hotspot walled-garden add dst-host=*.google.com comment="Google" /ip hotspot walled-garden add dst-host=*.googleapis.com comment="Google APIs" /ip hotspot walled-garden add dst-host=*.instagram.com comment="Instagram" /ip hotspot walled-garden add dst-host=*.cdninstagram.com comment="Instagram CDN" /ip hotspot walled-garden add dst-host=instagram.com comment="Instagram Principal" /ip hotspot walled-garden add dst-host=www.instagram.com comment="Instagram WWW" /ip hotspot walled-garden add dst-host=*.twitter.com comment="Twitter" /ip hotspot walled-garden add dst-host=*.linkedin.com comment="LinkedIn" /ip hotspot walled-garden add dst-host=*.github.com comment="GitHub" /ip hotspot walled-garden add dst-host=captive.apple.com comment="Apple Captive" /ip hotspot walled-garden add dst-host=connectivitycheck.gstatic.com comment="Android Check" /ip hotspot walled-garden add dst-host=*.microsoft.com comment="Microsoft" /ip hotspot walled-garden add dst-host=*.msftconnecttest.com comment="Windows Connectivity" echo "✅ Walled Garden configurado" # ======================================== # 8. USUÁRIOS PADRÃO # ======================================== echo "8. Criando usuários padrão..." # Usuário trial /ip hotspot user add name=trial password="" profile=trial-15min comment="Usuario trial gratuito" # Usuários de exemplo para teste /ip hotspot user add name=teste password=123456 profile=social-4h comment="Usuario de teste" /ip hotspot user add name=admin-test password=admin123 profile=premium comment="Usuario admin teste" echo "✅ Usuários padrão criados" # ======================================== # 9. REGRAS DE FIREWALL # ======================================== echo "9. Configurando firewall..." # Permitir hotspot /ip firewall filter add chain=input in-interface=hotspot-bridge action=accept comment="Permitir hotspot" # Bloquear acesso direto ao router (portas administrativas) /ip firewall filter add chain=input in-interface=hotspot-bridge dst-port=22,23,80,443,8291 action=drop comment="Bloquear admin do hotspot" # Rate limiting para evitar abuse /ip firewall filter add chain=forward connection-state=new connection-rate=20,1m action=drop comment="Rate limit hotspot" # Permitir DNS para usuários não autenticados /ip firewall filter add chain=input in-interface=hotspot-bridge protocol=udp dst-port=53 action=accept comment="DNS para hotspot" echo "✅ Firewall configurado" # ======================================== # 10. SCRIPTS UTILITÁRIOS # ======================================== echo "10. Criando scripts utilitários..." # Script de limpeza de usuários inativos /system script add name=cleanup_inactive_users source={ :log info "Iniciando limpeza de usuarios inativos"; :local count 0; :foreach user in=[/ip hotspot user find where profile="social-4h"] do={ :local username [/ip hotspot user get $user name]; :local isActive [:len [/ip hotspot active find where user=$username]]; :if ($isActive = 0) do={ :local lastSeen [/ip hotspot user get $user comment]; # Remover usuários que não se conectaram há mais de 7 dias # (lógica simplificada - pode ser expandida) :if ([:find $lastSeen "old"] >= 0) do={ /ip hotspot user remove $user; :set count ($count + 1); :log info ("Removido usuario inativo: " . $username); } } } :log info ("Limpeza concluida. Removidos: " . $count . " usuarios"); } comment="Limpa usuarios inativos" # Script de backup automático /system script add name=auto_backup source={ :local date [/system clock get date]; :local time [/system clock get time]; :local backupName ("hotspot_backup_" . $date . "_" . $time); /system backup save name=$backupName; /export file=("hotspot_config_" . $date . "_" . $time); :log info ("Backup criado: " . $backupName); } comment="Backup automatico do sistema" # Script de monitoramento /system script add name=hotspot_monitor source={ :local totalUsers [:len [/ip hotspot active find]]; :local trialUsers [:len [/ip hotspot active find where profile="trial-15min"]]; :local socialUsers [:len [/ip hotspot active find where profile="social-4h"]]; :local premiumUsers [:len [/ip hotspot active find where profile="premium"]]; :log info ("=== HOTSPOT STATUS ==="); :log info ("Total usuarios: " . $totalUsers); :log info ("Trial: " . $trialUsers); :log info ("Social: " . $socialUsers); :log info ("Premium: " . $premiumUsers); :log info ("======================"); } comment="Monitor de usuarios hotspot" echo "✅ Scripts utilitários criados" # ======================================== # 11. AGENDAMENTOS # ======================================== echo "11. Configurando agendamentos..." # Limpeza semanal de usuários inativos /system scheduler add name=weekly_cleanup interval=7d on-event=cleanup_inactive_users start-date=jan/01/1970 start-time=02:00:00 comment="Limpeza semanal" # Backup diário /system scheduler add name=daily_backup interval=1d on-event=auto_backup start-date=jan/01/1970 start-time=03:00:00 comment="Backup diario" # Monitoramento a cada hora /system scheduler add name=hourly_monitor interval=1h on-event=hotspot_monitor start-date=jan/01/1970 start-time=00:00:00 comment="Monitor por hora" echo "✅ Agendamentos configurados" # ======================================== # 12. CONFIGURAÇÕES DE LOG # ======================================== echo "12. Configurando logs..." # Habilitar logs do hotspot /system logging add topics=hotspot,info action=memory /system logging add topics=hotspot,warning action=memory /system logging add topics=hotspot,error action=memory echo "✅ Logs configurados" # ======================================== # 13. CRIAR ARQUIVOS HTML CUSTOMIZADOS # ======================================== echo "13. Gerando código HTML personalizado..." # Gerar login.html cat > /tmp/login.html << 'EOF' BUSINESS_NAME - WiFi Social
📶
📸 Siga nosso Instagram @INSTAGRAM_USER e ganhe internet premium!
👥 Conectar com Facebook 🔍 Conectar com Google
ou
Ao conectar, você concorda com nossos termos de uso.
Respeite os outros usuários e use a internet de forma responsável.
EOF # Gerar status.html cat > /tmp/status.html << 'EOF' BUSINESS_NAME - Conectado!
✅ Conectado com sucesso!
👤 Usuário: $(username)
⏰ Tempo restante: $(session-time-left)
🌐 Endereço IP: $(ip)
📱 Dispositivo: $(mac)
$(bytes-out-nice)
📤 Upload
$(bytes-in-nice)
📥 Download

🎉 Obrigado por se conectar!

Siga nosso Instagram para promoções exclusivas:

📸 Seguir @INSTAGRAM_USER

Redirecionamento automático em 10 segundos

EOF echo "✅ Arquivos HTML gerados em /tmp/" # ======================================== # 14. FINALIZAÇÃO # ======================================== echo "" echo "==========================================" echo " CONFIGURAÇÃO CONCLUÍDA COM SUCESSO! " echo "==========================================" echo "" echo "📋 PRÓXIMOS PASSOS:" echo "" echo "1. ⚠️ ALTERAR CONFIGURAÇÕES:" echo " - Editar este script e alterar:" echo " - INSTAGRAM_USER=\"$INSTAGRAM_USER\"" echo " - BUSINESS_NAME=\"$BUSINESS_NAME\"" echo "" echo "2. 📁 COPIAR ARQUIVOS HTML:" echo " - Login: /tmp/login.html → /flash/hotspot/login.html" echo " - Status: /tmp/status.html → /flash/hotspot/status.html" echo "" echo "3. 🔧 COMANDOS ÚTEIS:" echo " - Ver usuários ativos: /ip hotspot active print" echo " - Ver logs: /log print where topics~\"hotspot\"" echo " - Monitor: /system script run hotspot_monitor" echo " - Backup: /system script run auto_backup" echo "" echo "4. 🌐 ACESSAR HOTSPOT:" echo " - Conecte um dispositivo na interface $HOTSPOT_INTERFACE" echo " - Acesse qualquer site para ver a página de login" echo " - Teste com usuário: teste / senha: 123456" echo "" echo "5. 📱 INSTAGRAM:" echo " - Substitua INSTAGRAM_USER pelo seu username real" echo " - Teste o redirecionamento após o login" echo "" echo "==========================================" echo " 🎉 HOTSPOT SOCIAL ESTÁ PRONTO! 🎉 " echo "==========================================" # Mostrar resumo da configuração echo "" echo "📊 RESUMO DA CONFIGURAÇÃO:" echo "Interface: $HOTSPOT_INTERFACE" echo "Rede: $HOTSPOT_NETWORK" echo "Gateway: $HOTSPOT_GATEWAY" echo "Pool DHCP: $DHCP_POOL_START - $DHCP_POOL_END" echo "Instagram: @$INSTAGRAM_USER" echo "DNS: $DNS_PRIMARY, $DNS_SECONDARY" echo "" echo "✅ Configuração salva no sistema!" echo "✅ Scripts utilitários criados!" echo "✅ Agendamentos configurados!" echo "✅ Firewall aplicado!" echo "" # Executar teste inicial echo "🔍 EXECUTANDO TESTE INICIAL..." /system script run hotspot_monitor echo "" echo "🚀 Sistema pronto para uso!" echo "📞 Suporte: Verifique os logs em caso de problemas" echo ""