fluxion/lib/ap/hostapd.sh

99 lines
2.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# ================================================================
# Configuration Section
# ================================================================
APServiceConfigDirectory=$FLUXIONWorkspacePath
# ================================================================
#if [ "$APServiceVersion" ]; then return 0; fi
#readonly APServiceVersion="1.0"
2018-01-18 00:14:32 -07:00
function ap_service_stop() {
if [ "$APServicePID" ]; then
kill $APServicePID &> $FLUXIONOutputDevice
2017-12-31 09:02:12 -07:00
fi
2017-12-31 09:02:12 -07:00
APServicePID=""
}
2018-01-18 00:14:32 -07:00
function ap_service_reset() {
ap_service_stop
2017-12-31 09:02:12 -07:00
# Reset MAC address to original.
2018-01-18 00:14:32 -07:00
ifconfig $APServiceInterface down
2017-12-31 09:02:12 -07:00
sleep 0.5
2018-01-18 00:14:32 -07:00
macchanger -p $APServiceInterface &> $FLUXIONOutputDevice
2017-12-31 09:02:12 -07:00
sleep 0.5
2018-01-18 00:14:32 -07:00
ifconfig $APServiceInterface up
2017-12-31 09:02:12 -07:00
sleep 0.5
2018-01-18 00:14:32 -07:00
APServiceAccessInterface=""
APServiceChannel=""
APServiceMAC=""
APServiceSSID=""
APServiceInterfaceAddress=""
APServiceInterface=""
}
2018-01-18 00:14:32 -07:00
function ap_service_route() {
echo "APService: No custom routes for hostapd" > $FLUXIONOutputDevice
}
2018-01-18 00:14:32 -07:00
function ap_service_prep() {
if [ ${#@} -lt 5 ]; then return 1; fi
APServiceInterface=$1
APServiceInterfaceAddress=$2
APServiceSSID=$3
APServiceMAC=$4
APServiceChannel=$5
ap_service_stop
2017-12-31 09:02:12 -07:00
# Prepare the hostapd config file.
echo "\
2018-01-18 00:14:32 -07:00
interface=$APServiceInterface
driver=nl80211
2018-01-18 00:14:32 -07:00
ssid=$APServiceSSID
channel=$APServiceChannel" \
> "$APServiceConfigDirectory/$APServiceMAC-hostapd.conf"
2017-12-31 09:02:12 -07:00
# Spoof virtual interface MAC address.
2018-01-18 00:14:32 -07:00
ifconfig $APServiceInterface down
2017-12-31 09:02:12 -07:00
sleep 0.5
2018-01-18 00:14:32 -07:00
macchanger --mac=$APServiceMAC $APServiceInterface &> $FLUXIONOutputDevice
2017-12-31 09:02:12 -07:00
sleep 0.5
2018-01-18 00:14:32 -07:00
ifconfig $APServiceInterface up
2017-12-31 09:02:12 -07:00
sleep 0.5
2018-01-18 00:14:32 -07:00
# HostAPD sets the virtual interface mode
# to master, which is supported by dhcpd.
APServiceAccessInterface=$APServiceInterface
}
2018-01-18 00:14:32 -07:00
function ap_service_start() {
ap_service_stop
2018-01-18 00:14:32 -07:00
xterm $FLUXIONHoldXterm $TOP -bg "#000000" -fg "#FFFFFF" \
-title "FLUXION AP Service [hostapd]" -e \
hostapd "$APServiceConfigDirectory/$APServiceMAC-hostapd.conf" &
2017-12-31 09:02:12 -07:00
local parentPID=$!
2017-12-31 09:02:12 -07:00
# Wait till hostapd has started and its virtual interface is ready.
while [ ! "$APServicePID" ]; do
sleep 1
APServicePID=$(pgrep -P $parentPID)
done
2018-01-18 00:14:32 -07:00
ap_service_route
}
# FLUXSCRIPT END