Guest User

Untitled

a guest
Oct 11th, 2016
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !/bin/bash
  2. # vars
  3.  
  4. /usr/bin/killall hostapd
  5. echo "sleep 5 sec"
  6. sleep 5
  7. /usr/bin/pkill /usr/sbin/hostapd-mana
  8. /usr/bin/pkill /usr/sbin/dnsmasq
  9. RED='\033[0;31m'
  10. NC='\033[0m'
  11. sed -i 's/127.0.0.1/8.8.8.8/g' /etc/resolv.conf
  12.  
  13. # Checks for a working internet connection by ping
  14. if ping -c 1 google.com >> /dev/null 2>&1; then
  15. echo -e "Pineapple seems to be: ${RED}ONLINE${NC}."
  16. upstream=br-lan
  17. phy=wlan0
  18. conf=/etc/mana-toolkit/hostapd-mana.conf
  19. dhcp_conf=/etc/mana-toolkit/dnsmasq-dhcpd.conf
  20.  
  21. # Setup interface and forward traffic
  22. echo '1' > /proc/sys/net/ipv4/ip_forward
  23. /sd/usr/sbin/ip addr flush dev $phy
  24. /sd/usr/sbin/ip addr add 10.0.0.1/24 dev $phy
  25. /sd/usr/sbin/ip link set $phy up
  26. /sd/usr/sbin/ip route add default via 10.0.0.1 dev $phy
  27.  
  28. # Starting MANA and DHCP server
  29. sed -i "s/^interface=.*$/interface=$phy/" $conf
  30. /usr/sbin/hostapd-mana $conf &
  31. /usr/sbin/dnsmasq -z -C $dhcp_conf -i $phy -I lo
  32.  
  33. # Add fking rule to table 1006
  34. for table in $(ip rule list | awk -F"lookup" '{print $2}');
  35. do
  36. DEF=`ip route show table $table|grep default|grep $upstream`
  37. if ! [ -z "$DEF" ]; then
  38. break
  39. fi
  40. done
  41. ip route add 10.0.0.0/24 dev $phy scope link table $table
  42.  
  43. # Save iptables
  44. /usr/sbin/iptables-save > /tmp/rules.txt
  45. # Flush
  46. /usr/sbin/iptables --policy INPUT ACCEPT
  47. /usr/sbin/iptables --policy FORWARD ACCEPT
  48. /usr/sbin/iptables --policy OUTPUT ACCEPT
  49. /usr/sbin/iptables -F
  50. /usr/sbin/iptables -F -t nat
  51. # Masquerade
  52. /usr/sbin/iptables -t nat -A POSTROUTING -o $upstream -j MASQUERADE
  53. /usr/sbin/iptables -A FORWARD -i $phy -o $upstream -j ACCEPT
  54. /usr/sbin/iptables -t nat -A PREROUTING -i $phy -p udp --dport 53 -j DNAT --to 10.0.0.1
  55.  
  56. /bin/echo -e "MANA has ${RED}started${NC} successfully! Press enter to kill it properly"
  57. read
  58. pkill dnsmasq
  59. pkill hostapd-mana
  60. # Restore
  61. iptables-restore < /tmp/rules.txt
  62. rm /tmp/rules.txt
  63. # Remove iface and routes
  64. ip addr flush dev $phy
  65. ip link set $phy down
  66. else
  67. echo -e "Pineapple seems to be: ${RED}OFFLINE${NC}."
  68. echo -e "MANA has been ${RED}stopped${NC}."
  69. exit 0
  70. fi
RAW Paste Data