printf"\n WiFi Pineapple detected. Please disconnect the WiFi Pineapple from\n this computer and $(tput bold)press any key$(tput sgr0) to continue with guided setup.\n "
read -r -sn1 anykey
guidedsetup
fi
hasiproute2=$(which ip)
if[["$?"==1]];then
printf"\n\n Configuration requires the 'iproute2' package (aka the 'ip' command).\n Please install 'iproute2' to continue.\n"; menu
fi
hasdefaultroute=$(ip route)
if[["$?"==1]];then
printf"\n No route detected. Check connection and try again.\n"; menu
sleep 5# Wait as the system is likely to rename interface. Sleeping rather than more advanced error handling becasue reasons. Try: dmesg | tail | grep -E 'asix.*renamed'
pineappleiface=$(ip addr | grep '00:[cC]0:[cC][aA]\|00:13:37' -B1 | awk {'print $2'}| head -1 | grep 'eth\|en'| sed 's/://g')
printf"\n Detected WiFi Pineapple on interface $(tput bold)$pineappleiface$(tput sgr0)\n";
read -r -p " Use the above detected WiFi Pineapple interface? [Y/n]? " pi
case$pi in
[yY][eE][sS]|[yY]|'')
spineapplelan=$pineappleiface
;;
[nN][oO]|[nN])
printf"\n Available Network Interfaces:\n"
ifaces=($(ip link show | grep -v link | awk {'print $2'}| sed 's/://g'| grep -v lo))
for i in "${!ifaces[@]}";do
printf" \t%s\t""${ifaces[$i]}"
printf"$(ip -4 addr show ${ifaces[$i]}| grep inet | awk {'print $2'}| head -1)\n"
done
read -r -p " Specify the WiFi Pineapple interface by name: " spineapplelan
;;
esac
savechanges
}
function advancedsetup {
printf"\n\
By default the WiFi Pineapple resides on the $(tput bold)172.16.42.0/24$(tput sgr0) network\n\
with the IP Address $(tput bold)172.16.42.1$(tput sgr0) and Ethernet default route $(tput bold)172.16.42.42$(tput sgr0).\n\n\
The WiFi Pineapple expects an Internet connection from 172.16.42.42 by\n\
default, which this script aids in configuring. These IP addresses may\n\
be changed if desired by modifying network configs on the WiFi Pineapple.\n\n"
read -r -p " Continue with advanced IP config [y/N]? " qcontinue
printf"\n Advanced IP settings will be saved for future sessions.\n Default settings may be restored by selecting Advanced IP settings and\n pressing [ENTER] when prompted for IP settings.\n\n Press any key to continue"
savechanges
;;
esac
}
function savechanges {
sed -i "s/^spineapplenmask.*/spineapplenmask=$spineapplenmask/"$0
sed -i "s&^spineapplenet.*&spineapplenet=$spineapplenet&"$0
sed -i "s/^spineapplelan.*/spineapplelan=$spineapplelan/"$0
sed -i "s/^spineapplewan.*/spineapplewan=$spineapplewan/"$0
sed -i "s/^spineapplegw.*/spineapplegw=$spineapplegw/"$0
sed -i "s/^spineapplehostip.*/spineapplehostip=$spineapplehostip/"$0
sed -i "s/^spineappleip.*/spineappleip=$spineappleip/"$0
sed -i "s/^sfirsttime.*/sfirsttime=0/"$0
sfirsttime=0
printf"\n Settings saved.\n"
showsettings
menu
}
#
# IP Forwarding Settings
#
function set_ip_forward {
echo"Setting-up IP forwarding rules..."
# Enable kernel IP forwarding
echo'1' > /proc/sys/net/ipv4/ip_forward
wp2net=`iptables -nv -L FORWARD | grep -i "WifiPineapple to Inetnet"`
net2wp=`iptables -nv -L FORWARD | grep -i "Inetnet to WifiPineapple"`
ifconfig $spineapplelan$spineapplehostip netmask $spineapplenmask up #Bring up Ethernet Interface directly connected to Pineapple
# IP Forwarding Settings
set_ip_forward
# remove default route
route del default
# add default gateway
route add default gw $spineapplegw$spineapplewan
printf"\n Browse to http://$spineappleip:1471\n\n"
exit
}
function bunny {
printf"\nNetmask $spineapplenmask\nPineapple Net $spineapplenet\nPineapple LAN $spineapplelan\nPineapple WAN $spineapplewan\nPineapple GW $spineapplegw\nPineapple IP $spineappleip\nHost IP $spineapplehostip\n"