mirror of https://github.com/hak5/shark-files.git
commit
8dc7469f35
|
@ -1,17 +1,65 @@
|
|||
#!/bin/bash
|
||||
|
||||
function show_usage() {
|
||||
echo "Usage: $0 [DHCP_CLIENT|DHCP_SERVER]"
|
||||
echo "Usage: $0 [DHCP_CLIENT|DHCP_SERVER|AUTO]"
|
||||
echo ""
|
||||
}
|
||||
|
||||
function shut_it_all_down() {
|
||||
#we are restarting, possibly with new config, or reversing dhcp roles
|
||||
#kill 'em all, let the user sort them out
|
||||
/etc/init.d/odhcpd stop
|
||||
pkill -9 dnsmasq #odhcpd starts dnsmasq but fails to stop it
|
||||
pkill -9 udhcpc #this is the observed dhcp client
|
||||
pkill -9 odhcpcd #just in case
|
||||
}
|
||||
|
||||
function configure_client() {
|
||||
shut_it_all_down
|
||||
uci set network.lan.proto='dhcp'
|
||||
}
|
||||
|
||||
function configure_server() {
|
||||
shut_it_all_down
|
||||
uci set network.lan.proto='static'
|
||||
uci set network.lan.ipaddr='172.16.24.1'
|
||||
uci set network.lan.netmask='255.255.255.0'
|
||||
uci set network.lan.ip6assign='60'
|
||||
/etc/init.d/odhcpd start
|
||||
}
|
||||
|
||||
function blink() {
|
||||
count 3
|
||||
while [ "${count}" -gt 0 ]; do
|
||||
LED "${1}"
|
||||
sleep 0.25
|
||||
LED "${2}"
|
||||
sleep 0.25
|
||||
count=$((count-1))
|
||||
done
|
||||
}
|
||||
|
||||
case $1 in
|
||||
"DHCP_CLIENT")
|
||||
uci set network.lan.proto='dhcp'
|
||||
configure_client
|
||||
;;
|
||||
"DHCP_SERVER")
|
||||
uci set network.lan.proto='none'
|
||||
/etc/init.d/odhcpd start
|
||||
configure_server
|
||||
;;
|
||||
"AUTO")
|
||||
#make sure nothing interferes
|
||||
shut_it_all_down
|
||||
#this will exit 0 if a dhcp discovery/request packet is seen, and 124 if not
|
||||
sniffed="$(timeout -t 15 tcpdump -Z nobody -i eth0 -c 3 udp src port 68 and udp dst port 67 -v 2>&1)"
|
||||
if echo "${sniffed}" | grep -q 'DHCP-Message Option 53, length 1: Discover' && \
|
||||
! echo "${sniffed}" | grep -q 'DHCP-Message Option 53, length 1: Request'; then
|
||||
#we saw a dhcp discover but no dhcp request, so someone wants a dhcp server and didn't find one
|
||||
configure_server
|
||||
echo 'blink SETUP Y' | at now
|
||||
else
|
||||
configure_client
|
||||
echo 'blink SETUP W' | at now
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
show_usage
|
||||
|
|
|
@ -197,16 +197,19 @@ function enter_idle_mode() {
|
|||
while true
|
||||
do
|
||||
if [[ $MODE = "ARMING" ]] || [[ $MODE = "OFF" ]]; then
|
||||
#ARMING mode is basically always idle which means this overrides user LED
|
||||
#status once per second. Don't override user status with idle status.
|
||||
#pgrep LED > /dev/null || /usr/bin/LED whatever
|
||||
BATTERY_STATE=$(/usr/bin/BATTERY)
|
||||
case $BATTERY_STATE in
|
||||
"charging")
|
||||
/usr/bin/LED B SLOW
|
||||
pgrep LED > /dev/null || /usr/bin/LED B SLOW
|
||||
;;
|
||||
"full")
|
||||
/usr/bin/LED B
|
||||
pgrep LED > /dev/null || /usr/bin/LED B
|
||||
;;
|
||||
*)
|
||||
/usr/bin/LED Y SLOW
|
||||
pgrep LED > /dev/null || /usr/bin/LED Y SLOW
|
||||
if [[ $MODE = "OFF" ]]; then
|
||||
sleep 2 && halt
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue