summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/autowifi/wifi_keys1
-rwxr-xr-xusr/bin/autowifi2
-rwxr-xr-xusr/bin/autowifi_dryrun101
-rw-r--r--usr/lib/autowifi/lib/network2
-rw-r--r--usr/lib/autowifi/lib/plugin_core2
5 files changed, 81 insertions, 27 deletions
diff --git a/etc/autowifi/wifi_keys b/etc/autowifi/wifi_keys
deleted file mode 100644
index ef66cf3e..00000000
--- a/etc/autowifi/wifi_keys
+++ /dev/null
@@ -1 +0,0 @@
-#SSID|MAC|BANDWIDTH|KEY
diff --git a/usr/bin/autowifi b/usr/bin/autowifi
index 673a7a0a..6b9a090c 100755
--- a/usr/bin/autowifi
+++ b/usr/bin/autowifi
@@ -170,7 +170,7 @@ else
check_internet || loop_cracks_over_networks
while sleep 10; do
- if ! check_internet; then
+ if ! check_gateway; then
loop_cracks_over_networks
fi
done
diff --git a/usr/bin/autowifi_dryrun b/usr/bin/autowifi_dryrun
index c9867106..68e38a8f 100755
--- a/usr/bin/autowifi_dryrun
+++ b/usr/bin/autowifi_dryrun
@@ -1,38 +1,61 @@
-#!/bin/sh
-# ENV:
-# the root directory (e.g. root=$PWD/../../ if run from here )
+#!/bin/sh
cd $(dirname $(readlink -f $0))
-test "${1:-}" = 'quiet' && exec 2>&-
+
interface=${interface:-wlan0}
root=${root:-../../}
crackdir=$root/usr/lib/autowifi/plugins
wifi_keys=$root/etc/autowifi/wifi_keys
wifi_log=$root/var/log/autowifi.log
+painmode=${painmode:-}
# exists() run_hooks()
. $root/usr/lib/autowifi/lib/core
+
+. $root/usr/lib/autowifi/lib/network
+
# start_wpa_supplicant()
. $root/usr/lib/autowifi/lib/wpa_supplicant
-crack_wifi(){
- #SSID MAC FREQ ENCRYPTION
-
- ALL_RET=1
- for hack in $(find $root/usr/lib/autowifi/plugins -type f | sort -n); do
- printf "%s" "Trying $(basename $hack) against $1 : " >&2
- key=$($hack "$@");
- ret=$?
- if [ $ret -eq 0 ];then
- echo "success!" >&2
- echo $1|$2|$encr|$key
- ALL_RET=0
- else
- echo "fail ..." >&2
+
+find_count_of_ssid(){
+ c=0
+ for i in `seq 1 $WIFI_COUNT`; do
+ eval SSID=\${ESSID_${i}}
+ if [ "$SSID" = "$1" ]; then
+ c+=1
+ echo "$i"
fi
done
- return $ALL_RET
+ if [ $c -eq 0 ];then
+ exit 1
+ fi
+ exit 0
+}
+
+
+connect_to_network_by_ssid(){
+ find_count_of_ssid "$1" | (while read i
+ do
+ loop_over_cracks "$i" && exit 0
+ done;exit 1)
+ if [ $? -eq 0 ]; then
+ exit 0
+ fi
+ echo "no network found :("
+ exit 1
+}
+
+connect_with_pw(){
+ find_count_of_ssid "$1" | (while read i
+ do
+ KEY="$2"
+ eval connect \"\${MAC_${i}}\" \"\${ESSID_${i}}\" \${ENCRYPTION_${i}} \"\${KEY}\"
+ if [ $? -eq 0 ]; then
+ exit 0
+ fi
+ done;exit 1)
}
wifi_init(){
wpa_supplicant_is_usable || start_wpa_supplicant /tmp/autowifi.wpa_supplicant
@@ -40,12 +63,44 @@ wifi_init(){
. /tmp/${interface}.scan
}
loop_over_networks(){
- wifi_init
- echo "SSID:MAC:FREQ:ENCRYPTION:key"
+ wifi_init
for i in `seq 1 $WIFI_COUNT`; do
- eval crack_wifi \"\${ESSID_${i}}\" \${MAC_${i}} \${FREQ_${i}} \${ENCRYPTION_${i}}
+ loop_over_cracks "$i"
+ if [ $? -eq 0 ]; then
+ return 0
+ fi
done
}
-loop_over_networks
+loop_over_cracks(){
+ i=$1
+ KEY=''
+ for crack in $(find $crackdir -type f | sort -u); do
+ KEY="$(eval root=$root painmode=$painmode \$crack \"\${ESSID_${i}}\" \"\${MAC_${i}}\" \${FREQ_${i}} \${ENCRYPTION_${i}})"
+ if [ $? -eq 0 ]; then
+ eval echo \"\${MAC_${i}}\" \"\${ESSID_${i}}\" \${ENCRYPTION_${i}} \"\${KEY}\"
+ fi
+ done
+ return 1
+}
+loop_cracks_over_networks(){
+ wifi_init
+ for crack in $(find $crackdir -type f | sort -u); do
+ for i in `seq 1 $WIFI_COUNT`; do
+ KEY="$(eval root=$root \$crack \"\${ESSID_${i}}\" \"\${MAC_${i}}\" \${FREQ_${i}} \${ENCRYPTION_${i}})"
+ if [ $? -eq 0 ]; then
+ eval echo \"\${MAC_${i}}\" \"\${ESSID_${i}}\" \${ENCRYPTION_${i}} \"\${KEY}\"
+ fi
+ done
+ done
+
+}
+
+wifi_init
+if [ -n "$1" ]; then
+ echo cracking $1
+ connect_to_network_by_ssid "$1"
+else
+ loop_cracks_over_networks
+fi
diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network
index c21f0db0..a0105120 100644
--- a/usr/lib/autowifi/lib/network
+++ b/usr/lib/autowifi/lib/network
@@ -1,7 +1,7 @@
#!/bin/sh
check_gateway(){
- ping -c 1 -w 5 $(ip route | awk '/default/{print $3}')
+ ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') >/dev/null
}
check_internet(){
# TODO determine the loader, either wget or curl
diff --git a/usr/lib/autowifi/lib/plugin_core b/usr/lib/autowifi/lib/plugin_core
index 700d15f8..e79a3c05 100644
--- a/usr/lib/autowifi/lib/plugin_core
+++ b/usr/lib/autowifi/lib/plugin_core
@@ -37,5 +37,5 @@ check_vendor_mac(){
return 1
}
check_painmode(){
- test -n "${painmode:-}" && echo "painmode required">&2 && exit 1
+ test -z "${painmode:-}" && echo "painmode required" && exit 1
}