fix: fixed, refactored and centralized launchers logic (closes #473)

This commit is contained in:
Simone Margaritelli 2019-10-31 14:14:13 +01:00
parent 96c617e152
commit 13064879e0
7 changed files with 77 additions and 40 deletions

View File

@ -1,15 +1,11 @@
#!/usr/bin/env bash
# start mon0
/usr/bin/monstart
source /usr/bin/pwnlib
# if usb0 or eth0 are up
if [[ $(ifconfig | grep usb0 | grep RUNNING) ]] || [[ !$(grep '1' /sys/class/net/eth0/carrier) ]]; then
# if override file exists, go into auto mode
if [ -f /root/.pwnagotchi-auto ]; then
# start mon0
start_monitor_interface
if is_auto_mode; then
/usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0
else
/usr/bin/bettercap -no-colors -caplet pwnagotchi-manual -iface mon0
fi
else
/usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0
/usr/bin/bettercap -no-colors -caplet pwnagotchi-manual -iface mon0
fi

View File

@ -1,10 +0,0 @@
#!/usr/bin/env bash
for i in $(seq 1 "$1");
do
echo 0 >/sys/class/leds/led0/brightness
sleep 0.3
echo 1 >/sys/class/leds/led0/brightness
sleep 0.3
done
echo 0 >/sys/class/leds/led0/brightness
sleep 0.3

View File

@ -1,2 +1,3 @@
#!/usr/bin/env bash
iw phy phy0 interface add mon0 type monitor && ifconfig mon0 up
source /usr/bin/pwnlib
start_monitor_interface

View File

@ -1,2 +1,3 @@
#!/usr/bin/env bash
ifconfig mon0 down && iw dev mon0 del
source /usr/bin/pwnlib
stop_monitor_interface

View File

@ -1,16 +1,11 @@
#!/usr/bin/env bash
# blink 10 times to signal ready state
/usr/bin/bootblink 10 &
source /usr/bin/pwnlib
# if usb0 or eth0 are up
if [[ $(ifconfig | grep usb0 | grep RUNNING) ]] || [[ !$(grep '1' /sys/class/net/eth0/carrier) ]]; then
# if override file exists, go into auto mode
if [ -f /root/.pwnagotchi-auto ]; then
rm /root/.pwnagotchi-auto
# blink 10 times to signal ready state
blink_led 10 &
if is_auto_mode; then
/usr/local/bin/pwnagotchi
else
/usr/local/bin/pwnagotchi --manual
fi
else
/usr/local/bin/pwnagotchi
/usr/local/bin/pwnagotchi --manual
fi

View File

@ -0,0 +1,54 @@
#!/usr/bin/env bash
# well ... it blinks the led
blink_led() {
for i in $(seq 1 "$1"); do
echo 0 >/sys/class/leds/led0/brightness
sleep 0.3
echo 1 >/sys/class/leds/led0/brightness
sleep 0.3
done
echo 0 >/sys/class/leds/led0/brightness
sleep 0.3
}
# starts mon0
start_monitor_interface() {
iw phy phy0 interface add mon0 type monitor && ifconfig mon0 up
}
# stops mon0
stop_monitor_interface() {
ifconfig mon0 down && iw dev mon0 del
}
# returns 0 if the specificed network interface is up
is_interface_up() {
if grep -qi 'up' /sys/class/net/$1/operstate; then
return 0
fi
return 1
}
# returns 0 if conditions for AUTO mode are met
is_auto_mode() {
# check override file first
if [ -f /root/.pwnagotchi-auto ]; then
# remove the override file if found
rm -rf /root/.pwnagotchi-auto
return 0
fi
# if usb0 is up, we're in MANU
if is_interface_up usb0; then
return 1
fi
# if eth0 is up (for other boards), we're in MANU
if is_interface_up eth0; then
return 1
fi
# no override, but none of the interfaces is up -> AUTO
return 0
}

View File

@ -19,6 +19,11 @@
"apt-get install -y ansible"
]
},
{
"type": "file",
"source": "data/usr/bin/pwnlib",
"destination": "/usr/bin/pwnlib"
},
{
"type": "file",
"source": "data/usr/bin/bettercap-launcher",
@ -34,11 +39,6 @@
"source": "data/usr/bin/monstop",
"destination": "/usr/bin/monstop"
},
{
"type": "file",
"source": "data/usr/bin/bootblink",
"destination": "/usr/bin/bootblink"
},
{
"type": "file",
"source": "data/usr/bin/monstart",