#! /bin/bash
# Program:	airoscript-ng                                                          
# Authors:	Base Code by Daouid; Mods & Tweaks by CurioCT and others; Continued by XayOn.
# Credits:      Hirte, Befa, Stouf, Mister_X, ASPj , Andrea, Pilotsnipes, darkAudax, Atheros support thx to green-freq
# Date of this version:	        27.11.2008
# Version of aircrack-ng required:  AIRCRACK-NG 1.0
# Dependencies: aircrack-ng, xterm|urxvt|gnome-terminal|..., awk, macchanger, drivers capable of injection (for injection =) ), mdk3 (optional), wlandecrypter (optional), jazzteldecrypter (optional), grep (included on almost all systems by default)

# Copyright (C) 2009 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.


# Sets ps3, wich will be shown after input in the select	
clear && PS3=`gettext 'Input number: '`

function confwarn {
echo -n -e "`gettext 'Youre going to use a config file on your home or current dir. 
This may be harmfull, for example, if your user have been 
compromised, and youre getting rights trought sudo, someone
can modify your config file to do something malicious as 
root. Be sure to check your home config file before using it. 
Defaults on /etc/airoscript-ng/airoscript-ng.conf should be ok so you can 
safely remove your ~/.airoscript-ng.conf\n\n
Do you really want to do it (yes/No): '`"
}

warntext="
Airoscript is provided under the gpl.\nI'm not responsible of the use anyone can give to airoscript,\nAiroscript is written for educational purpose in mind.
"

# Die if no root.
li=`tput lines`; cen=`expr $li / 2 + 2`; if [ "$UID" != 0 ]; then clear;echo -e "\E[3;22H===airoscript-ng===\E[$cen;15H\E[31mYou Must be root to use airoscript\E[39;49;00m\E[$li;20H"; exit 1; fi; 

# Get config.
if [ -e ~/.airoscript-ng/airoscript-ng.conf ]; then	
		if [ $HOME != "/root" ]; then confwarn; read response
			if [ "$response" = "yes" ]; then . ~/.airoscript-ng/airoscript-ng.conf
			else echo `gettext "Ok, please remove/rename your $HOME/.airoscript-ng/airoscript-ng.conf"`; exit; fi
		else . ~/.airoscript-ng/airoscript-ng.conf ; fi
	else
		if [ -e /etc/airoscript-ng/airoscript-ng.conf ]; then . /etc/airoscript-ng/airoscript-ng.conf
		else
			if [ -e /usr/local/etc/airoscript-ng/airoscript-ng.conf ]; then . /usr/local/etc/airoscript-ng/airoscript-ng.conf
			else
				if [ -e airoscript-ng.conf ]; then
					confwarn ; read response
					if [ "$response" = "yes" ]; then . airoscript-ng.conf
					else echo -e `gettext "Ok, please remove/rename your $HOME/.airoscript-ng.conf"`; exit; fi
				else echo -e `gettext "Error, no config file found, quitting"`; exit; fi
			fi
		fi
fi

# Check cardctl
if [ `uname -r|cut -d . -f 2` == "6" ]; then CARDCTL="pccardctl"
else CARDCTL="cardctl"; fi
# This is for auto resolution set.
if [ "$reson" ]; then export resonset=1; fi

cd $DUMP_PATH
if [ "$1" != "" ] ; then export TERMINAL=$1; fi
[[ -e $IFUNCTIONS ]] && . $IFUNCTIONS 
[[ -e $FUNCTIONS ]] && . $FUNCTIONS 

if [ "$DEBUG"  == 1 ]; then echo "Text domain dir is $TEXTDOMAINDIR and textdomain is $TEXTDOMAIN" ;fi
if [ -e $THEMEDIR/$THEME.theme ]; then . $THEMEDIR/$THEME.theme 
else
	echo -e "`gettext '[WARN] : theme file does not exists, using defaults...'`\n" 
	DUMPING_COLOR="#FFFFFF"; INJECTION_COLOR="#1DFF00"
	ASSOCIATION_COLOR="#FF0009"; DEAUTH_COLOR="#99CCFF"; BACKGROUND_COLOR="#000000"
fi

checkdir

if [ $SHOW_airoscript_WARNING ]; then echo -e $warntext"\n"; sleep 5; fi
if [ "$TERMINAL" = "screen" ] ; then
	if [ -e ~/.airoscript-ng/screen_has_started ]; then rm ~/.airoscript-ng-ng/screen_has_started
	else
		touch ~/.airoscript-ng/screen_has_started
		screen -S airoscript-ng -c $SCREENRC $0 screen
		$clear && echo `gettext 'airoscript-ng is terminating...'`; exit
	fi
fi

reso
debug
setinterface
checkforcemac

select choix in $CHOICES; do
    case "$choix" in
        1)choosetype;;
        2)select_ap;;
        3)witchattack;;
        4)witchcrack;;
        5)choosefake && menu ;;
        6)choosedeauth;;
        7)optionmenu;;
        8)injectmenu;;
        9)doauto;;
        10)doexit;;
        11)if [ $UNSTABLE = "1" ]; then $clear && unstablemenu; fi;;
        *)$clear && echo "`gettext 'ERROR: Wrong number entered'`";;
    esac
menu
done
