
(Ésta no es más que una versión en desarrollo como ejemplo de en qué
estamos trabajando y cómo lo estamos haciendo que no necesariamente
concordará de forma exacta con el código de la versión publicada en
cada release del programa)
#!/bin/bash
# DEFINICION DE ALGUNAS VARIABLES Y TEMPORALES
VERSION="v1.2"
URLPING="www.google.com"
Exec="exec.tmp"
Exec1="exec1.tmp"
REDelecta="REDelecta.tmp"
Scan="scan.tmp"
Scan1="scan1.tmp"
Scan2="scan2.tmp"
Scan3="scan3.tmp"
Int="int.tmp"
DHCPOUT="dhcpout.tmp"
README="README.TXT"
CONFIGURATOR="oswax.conf"
CONFIGU="conf.tmp"
MENUP="menup.tmp"
MACMENU="macmenu.tmp"
MAC="mac.tmp"
FAVORITOS="favoritos"
OSWADIR=".oswa"
FAVOR="favor.tmp"
NUEVARED="NuevaRed.tmp"
WEPK="wepk.tmp"
WEPYN="wepyn.tmp"
IPCONFMAN="ipconfman.tmp"
IPCONFMAN2="ipconfman2.tmp"
PINGEADO="pingeado.tmp"
IDIOMAelecto="idiomaelecto.tmp"
# LECTURA DE CONFIGURACION
IDIOMA=$(cat ~/$OSWADIR/$CONFIGURATOR | grep IDIOMA | cut -c8-)
DIALOG=$(cat ~/$OSWADIR/$CONFIGURATOR | grep DIALOG | cut -c8-)
PIDEIP=$(cat ~/$OSWADIR/$CONFIGURATOR | grep PIDEIP | cut -c8-)
WLAN=$(cat ~/$OSWADIR/$CONFIGURATOR | grep WLAN | cut -c6-)
DIALOG="$DIALOG --backtitle OSWAX"
# IDIOMA
idioma()
{
IDIOMASPOSIBLES="es Castellano en English"
# IDIOMA CASTELLANO
DCONFIGURAR="CONFIGURAR OSWAX"
DCUNO="Modo grafico - Xdialog"
DCDOS="Modo texto - dialog"
DCTRES="Desea utilizar OSWAX en modo grafico?"
DCWLAN="Introduzca el nombre de la interfaz de red que desee utilizar"
DCDHCP="Introduzca el comando para solicitar IP"
DCWEPUNO="Sin encriptacion"
DCWEPDOS="Introduzca la clave de encriptacion WEP"
DFAVORITAS="Redes FAVORITAS"
DFUNO="Estas son sus redes preconfiguradas:"
DNUEVA="NUEVA"
DNUEVAUNO="(Agregar nueva preconfiguracion)"
DNUEVADOS="Ponga el nombre de la nueva red favorita\n (solo alfanumerico sin espacios)"
DSCANNOW="Escanear ahora"
DAPNAME="Ponga el nombre del AP"
DNOMAC="No tocar la MAC"
DMACSHOW="Esta es su MAC actual:"
DMACASK="Desea cambiar la Mac de su tarjeta?"
DOLDMAC="Esta era la MAC original:"
DNEWMAC="Su nueva MAC es:"
DMACINT="Desea cambiar la Mac de su tarjeta \n antes de conectarse a la red favorita?"
DMACR="Poner una MAC aleatoria"
DMACM="Introducir manualmente la MAC"
DMACINPUT="Introduzca la MAC a utilizar \n con el formato:\n XX:XX:XX:XX:XX:XX"
DIPMAN="Configuracion manual"
DIPINT="Desea solicitar una IP por DHCP?"
DIPWAIT="Pidiendo IP...\n Por favor, tenga paciencia"
DWORKING="Estamos trabajando..."
DIPOK="EXITO :D"
DIPOKUNO="La peticion de IP parece haber tenido exito!!!\n "
DIPANS="Respuesta a la peticion DHCP"
DNETCHOSE="Elija la red a a la que desea conectarse."
DCUALQ="cualquiera"
DFIRST="Su primera vez en OSWAX"
DFIRSTONE="Parece ser la primera vez que ejecuta OSWAX.\n La
carpeta de configuracion del programa ha sido creada en su directorio
home bajo el nombre .oswa\n "
DERROR="ERROR :("
DMUSTBROOT=" Debe correr el programa como root o agregarlo a sudoers para ejecutarlo con un sudo."
DCHOSEMAIN="Que desea hacer?"
DEXIT="Salir"
DRETRY="Reintentar"
DRESTART="Reiniciar"
DWELCOME="Bienvenido a Oswax "
DMAINONE="Asistente DHCP"
DMAINONEP="Asistente Manual"
DMAINDOS="Redes favoritas"
DMAINTRES="Acerca de"
DMAINCUATRO="Configurar"
DMAINCINCO="Limpiar temporales"
DMAINCINCODONE="Archivos temporales eliminados"
DRESTARTINT="Desea reiniciar el proceso?"
DRETRYINT="La configuración no parece funcionar. \n Desea volver a intentarlo?"
DCHLANG="Seleccione su idioma (Castellano por defecto)"
REINSTALL="REINSTALACION"
SUREREINSTALL="Ha introducido el argumento -r al ejecutar
OSWAX.\n Quiere reinstalar el programa?\n\n Los archivos de favoritos y
configuracion se eliminaran."
# IDIOMA INGLES
if [ $IDIOMA == "en" ]
then
DCONFIGURAR="CONFIGURE OSWAX"
DCUNO="Graphical mode - Xdialog"
DCDOS="Text mode - dialog"
DCTRES="Do you want OSWAX to run in graphical mode?"
DCWLAN="Write the name of the interface you want to use"
DCDHCP="Write the command that will ask for an IP"
DCWEPUNO="No Encryptation"
DCWEPDOS="Write the WEP"
DFAVORITAS="Favourite Networks"
DFUNO="This are the networks you have preconfigured:"
DNUEVA="NEW"
DNUEVAUNO="(Add a new favourite)"
DNUEVADOS="Write the name of the new favourite (alphanumeric without blanks)"
DSCANNOW="Scan Now"
DAPNAME="Write the name of the AP"
DNOMAC="Don't change MAC"
DMACSHOW="Your current MAC:"
DMACASK="Do you want to change your MAC?"
DOLDMAC="This was the old MAC:"
DNEWMAC="This is the new MAC:"
DMACINT="Do you want to change MAC for connecting to this AP?"
DMACR="Use a random MAC"
DMACM="Use a concrete MAC"
DMACINPUT="Input the new MAC: \n XX:XX:XX:XX:XX:XX"
DIPMAN="Manual configuration"
DIPINT="Use DHCP?"
DIPWAIT="Asking for an IP...\n Please wait."
DWORKING="Currently working on it..."
DIPOK="SUCCESFULL :D"
DIPOKUNO="We have a new IP!!!\n "
DIPANS="DHCP client said:"
DNETCHOSE="Choose a network:"
DCUALQ="any"
DFIRST="First time running OSWAX"
DFIRSTONE="It seems to be the first time you run OSWAX.\n A
configuration folder has been created in your home called .oswa\n "
DERROR="ERROR :("
DMUSTBROOT="You must run OSWAX as root. Probably you want to add it to your sudoers file."
DCHOSEMAIN="What do you want to do?"
DEXIT="Out"
DRETRY="Retry"
DRESTART="Restart"
DWELCOME="Welcome to Oswax "
DMAINONE="Assistant"
DMAINDOS="Favourites"
DMAINTRES="About"
DMAINCUATRO="Configure"
DMAINCINCO="Clean temps"
DMAINCINCODONE="Temporary files deleted"
DRESTARTINT="Do you want to restart the assistant?"
DRETRYINT="Your network doesn't seem to be working.\n Do you want to try again?"
DCHLANG="Select language (default Spanish)"
fi
}
idioma
# FUNCIONES
# CONFIGURATOR
configurator()
{
$DIALOG --title "$DCONFIGURAR" --menu "$DCHLANG" 0 0 0 $IDIOMASPOSIBLES 2> $IDIOMAelecto
if [ $? == 0 ]
then
IDIOMA="$(cat $IDIOMAelecto)"
echo "IDIOMA=$(cat $IDIOMAelecto)" > $CONFIGURATOR
else
# OPCION POR DEFECTO
IDIOMA=es
echo "IDIOMA=es" > $CONFIGURATOR
fi
idioma
$DIALOG --title "$DCONFIGURAR" --yes-label "$DCUNO" --no-label "$DCDOS" --yesno "$DCTRES" 0 0
if [ $? == 0 ]
then
DIALOG="Xdialog --backtitle OSWAX"
echo "DIALOG=Xdialog" >> $CONFIGURATOR
else
DIALOG="dialog --backtitle OSWAX"
echo "DIALOG=dialog" >> $CONFIGURATOR
fi
$DIALOG --title "$DCONFIGURAR" --inputbox "$DCWLAN" 0 0 "wlan0" 2> $CONFIGU
if [ $? == 0 ]
then
echo "WLAN=$(cat $CONFIGU)" >> $CONFIGURATOR
fi
$DIALOG --title "$DCONFIGURAR" --inputbox "$DCDHCP" 0 0 "dhclient" 2> $CONFIGU
if [ $? == 0 ]
then
echo "PIDEIP=$(cat $CONFIGU)" >> $CONFIGURATOR
fi
menuprincipal
}
# PONER WEP
ponerwep()
{
$DIALOG --title OSWAX --defaultno --cancel-label "$DCWEPUNO" --inputbox "$DCWEPDOS" 7 50 0 2> $WEPK
if [ $? == 0 ]
then
iwconfig $WLAN key $(cat $WEPK)
fi
}
# REDES FAVORITAS
favoritos()
{
$DIALOG --title "$DFAVORITAS" --menu "$DFUNO" 0 0 0 "$DNUEVA"
"$DNUEVAUNO" $(ls $FAVORITOS/ | grep oswa | tr "\n" " " | sed 's/.oswa/
oswa/g') 2> $FAVOR
CFAV=$?
if [ $CFAV == 0 ]
then
if [ $(cat $FAVOR) == "$DNUEVA" ]
then
$DIALOG --title "$DNUEVA" --inputbox "$DNUEVADOS" 0 0 2> $NUEVARED
if [ $? == 0 ]
then
NAME=$(cat $NUEVARED)".oswa"
echo "#!/bin/bash" > $FAVORITOS/$NAME
$DIALOG --title "$DNUEVA" --cancel-label "$DSCANNOW" --inputbox "$DAPNAME" 0 0 2> $REDelecta
if [ $? == 1 ]
then
escanear
fi
$DIALOG --title OSWAX --defaultno --cancel-label "$DNOMAC"
--menu "$DMACINT" 0 0 0 r "$DMACR" m "$DMACM" 2> $MACMENU
MCM=$?
if [ $MCM == 0 ]
then
if [ "$(cat $MACMENU)" == "r" ]
then
echo "macchanger -r $WLAN" >> $FAVORITOS/$NAME
elif [ "$(cat $MACMENU)" == "m" ]
then
$DIALOG --title "OSWAX-Macchanger" --inputbox "$DMACINPUT" 0 0 2> $MAC
if [ $? == 0 ]
then
echo "macchanger $WLAN -m $(cat $MAC)" >> $FAVORITOS/$NAME
fi
fi
fi
echo "iwconfig $WLAN mode managed essid $(cat $REDelecta)" >> $FAVORITOS/$NAME
$DIALOG --cancel-label "$DIPMAN" --ok-label "DHCP" --yesno "$DIPINT" 0 0
if [ $? == 0 ]
then
echo "$PIDEIP $WLAN" >> $FAVORITOS/$NAME
elif [ $? == 1 ]
then
# TODO: PONER IP MANUALMENTE
$DIALOG --msgbox "$DWORKING" 0 0
fi
chmod ugo+x $FAVORITOS/$NAME
fi
else
RNAME=$(cat $FAVOR)
$FAVORITOS/$RNAME.oswa > $DHCPOUT
if [ "$(cat $DHCPOUT |grep ping)" == "" ]
then
$DIALOG --title "$DIPOK" --msgbox "$DIPOKUNO" 0 0
else
$DIALOG --title "$DIPANS" --exit-label Ok --textbox $DHCPOUT 0 0
fi
fi
fi
menuprincipal
}
# PETICION DHCP
conectardhcp()
{
(echo "1"
iwconfig $WLAN mode managed essid "$1"
sleep 0.5
echo "15"
sleep 0.5
echo "33"
$PIDEIP -q $WLAN > $DHCPOUT
echo "50"
sleep 0.5
echo "66"
ping -c 4 $URLPING | grep % > $PINGEADO
echo "75"
sleep 0.5
# SI, YA SE QUE ES UNA GILIPOLLEZ PERO AL CRECER MÁS POCO A POCO
HACE UN POCO MENOS FEO LO DE LA BARRA DE PROGRESO Y 2 SEGUNDOS EN TOTAL
DE NUESTRAS VIDAS NO VAN A NINGUNA PARTE... SI A ALGUNO LE MOLESTA
MUCHO COMENTA LOS 4 sleep 0.5 DE AQUI Y LISTO.
echo "99") | \
$DIALOG --title "DHCP" --gauge "$DIPWAIT" 10 40 0
}
# CONFIGURACION MANUAL (aún no funciona)
ipconfigman()
{
ifconfig $WLAN $IP netmask $NMASK up
SALIDA=$?
if [ $SALIDA == 1 ]
then
$DIALOG --msgbox "ERROR" 0 0
conectar $(cat $REDelecta)
fi
(echo "1"
iwconfig $WLAN mode managed essid "$(cat $REDelecta)"
echo "33"
route add -n $NETWORK netmask $NMASK $WLAN
route add default gw $GATEWAY
ifconfig $WLAN up
echo "66"
ping -c 4 $BCAST | grep % > $PINGEADO
echo "99") | \
$DIALOG --title "$DIPMAN" --gauge "$DIPMAN ..." 10 40 0
}
# TOMA DE DATOS MANUAL (aún no funciona)
conectarmanual()
{
if [ "$DIALOG" == "Xdialog --backtitle OSWAX" ]
then
$DIALOG --3inputsbox "$DIPMAN (1/2)." 0 0 "IP:"
"192.168.2.7" "Broadcast:" "192.168.1.255" "Netmask:"
"255.255.255.0" 2> $IPCONFMAN
CONTROL=$?
if [ $CONTROL == 1 ]
then
menuprincipal
elif [ $CONTROL == 0 ]
then
$DIALOG --3inputsbox "$DIPMAN (2/2)." 0 0 "Gateway:"
"192.168.1.1" "DNS:" "192.168.2.1" "Network:" ""
2>> $IPCONFMAN
cat $IPCONFMAN | tr "/" "\n" > $IPCONFMAN2
cat $IPCONFMAN2 > $IPCONFMAN
echo "IP
BCAST
NMASK
GWAY
DNS
NETWORK" > $IPCONFMAN2
IP="$(paste $IPCONFMAN2 $IPCONFMAN | grep IP | cut -c4-)"
BCAST="$(paste $IPCONFMAN2 $IPCONFMAN | grep BCAST | cut -c7-)"
IP="$(paste $IPCONFMAN2 $IPCONFMAN | grep NMASK | cut -c7-)"
GWAY="$(paste $IPCONFMAN2 $IPCONFMAN | grep GWAY | cut -c6-)"
DNS="$(paste $IPCONFMAN2 $IPCONFMAN | grep DNS | cut -c5-)"
NETWORK="$(paste $IPCONFMAN2 $IPCONFMAN | grep DNS | cut -c8-)"
CONTROL=$?
if [ $CONTROL == 1 ]
then
menuprincipal
elif [ $CONTROL == 0 ]
then
iwconfig $WLAN mode managed essid "$1"
ipconfigman "$1"
fi
fi
elif [ "$DIALOG" == "dialog --backtitle OSWAX" ]
then
$DIALOG --form "$DIPMAN" 0 0 0 "IP" 1 1 "192.168.2.7" 1 10
20 0 "Broadcast"
2 1 "192.168.1.255" 2 10 20 0 "Netmask" 3 1
"255.255.255.0" 3 10 20 0 "Gateway" 4 1 "192.168.2.1" 4 10 20 0
"DNS" 5 1 "192.168.2.1" 5 10 20 0 "NETWORK" 6 1 "" 6 10 20 0
2> $IPCONFMAN
CONTROL=$?
echo "IP
BCAST
NMASK
GWAY
DNS
NETWORK" > $IPCONFMAN2
IP="$(paste $IPCONFMAN2 $IPCONFMAN | grep IP | cut -c4-)"
BCAST="$(paste $IPCONFMAN2 $IPCONFMAN | grep BCAST | cut -c7-)"
IP="$(paste $IPCONFMAN2 $IPCONFMAN | grep NMASK | cut -c7-)"
GWAY="$(paste $IPCONFMAN2 $IPCONFMAN | grep GWAY | cut -c6-)"
DNS="$(paste $IPCONFMAN2 $IPCONFMAN | grep DNS | cut -c5-)"
NETWORK="$(paste $IPCONFMAN2 $IPCONFMAN | grep DNS | cut -c8-)"
if [ $CONTROL == 1 ]
then
menuprincipal
elif [ $CONTROL == 0 ]
then
iwconfig $WLAN mode managed essid "$1"
ipconfigman "$1"
fi
fi
}
# MACCHANGER
cambiamac()
{
$DIALOG --title OSWAX --defaultno --cancel-label "$DNOMAC" --menu
"$DMACSHOW \n $(macchanger $WLAN | grep Current | cut -c13-31) \n \n
$DMACASK" 0 0 0 r "$DMACR" m "$DMACM" 2> $MACMENU
MCM=$?
if [ $MCM == 0 ]
then
if [ "$(cat $MACMENU)" == "r" ]
then
$DIALOG --title "OSWAX-Macchanger" --msgbox "$DOLDMAC \n
$(macchanger $WLAN | grep Current | cut -c13-31)\n$DNEWMAC \n
$(macchanger -r $WLAN | grep Faked | cut -c13-31)" 0 0
elif [ "$(cat $MACMENU)" == "m" ]
then
$DIALOG --title "OSWAX-Macchanger" --inputbox "$DMACINPUT" 0 0 2> $MAC
if [ $? == 0 ]
then
macchanger $WLAN -m $(cat $MAC)
fi
fi
elif [ $MCM != 1 ]
then
exit 0
fi
}
# Escaneado, presentacion y eleccion de redes:
escanear()
{
# Formateado de la salida de iwlist:
RESCAN="r"
while [ "$RESCAN" == "r" ]
do
iwlist $WLAN scan > $Scan
cat $Scan | grep "Quality:" | cut -c29-34 > $Scan1
cat $Scan | grep "Encryption key" | cut -c36- > $Scan3
paste $Scan3 $Scan1 | tr "\t" "." | sed 's/on/WEP:Y../g' | sed 's/off/WEP:N../g' > $Scan2
cat $Scan | grep "ESSID" | cut -c27- > $Scan1
paste $Scan1 $Scan2 > $Scan
sort $Scan > $Scan1
uniq $Scan1 $Scan
cat $Scan | tr "\n" " " > $Scan1
echo "$DIALOG --title OSWAX --cancel-label Rescan --menu \"
$DNETCHOSE \\n ESSID.......Encryption..Quality\" 13 40 6
any $DCUALQ " > $Exec
cat $Scan1 >> $Exec
echo "2> $REDelecta" >> $Exec
echo $(cat $Exec) > $Exec1
mv $Exec1 $Exec
echo "echo \$? > $Int" >> $Exec
chmod 777 $Exec
./$Exec
if [ "$(cat $Int)" == "0" ]
then
RESCAN="n"
elif [ "$(cat $Int)" != "1" ]
then
exit 0
fi
done
cat $REDelecta | tr "\"" " " > $REDelecta
}
# COMPROBAR CONEXION
comprobarconexion()
{
if [ "$(cat $PINGEADO)" == "" ]
then
$DIALOG --title "ping www.google.com" --defaultno --ok-label
$DRESTART --cancel-label $DEXIT --yesno "Parece que no estamos
conectados a la internet. \n \n $DRESTARTINT" 0 0
CONTROL=$?
else
$DIALOG --title "ping www.google.com" --defaultno
--ok-label $DRESTART --cancel-label $DEXIT --yesno "Hemos hecho ping a
$URLPING : \n \n $(cat $PINGEADO) \n \n $DRESTARTINT" 0 0
CONTROL=$?
fi
if [ $CONTROL == 0 ]
then menuprincipal
else
rm *.tmp
exit 0
fi
}
# DIALOGO ACERCA DE
aboutdialog()
{
echo "OSWAX in Sourceforge:
http://oswax.sourceforge.com
----------------------------
Contact the author:
mailto:ozrocpablo@gmail.com
(say oswax in subject)
" > $README
$DIALOG --title "$DMAINTRES" --textbox "$README" 0 0
menuprincipal
}
# BORRAR ARCHIVOS TEMPORALES
limpiatemporales()
{
rm *.tmp
$DIALOG --title "$DMAINCINCO" --msgbox "$DMAINCINCODONE " 0 0
menuprincipal
}
# MENU PRINCIPAL
menuprincipal()
{
$DIALOG --title OSWAX --cancel-label $DEXIT --menu "$DWELCOME
$VERSION \n \n $DCHOSEMAIN" 16 30 0 "1d" "$DMAINONE" "1m" "$DMAINONEP"
"2" "$DMAINDOS" "3" "$DMAINTRES" "4" "$DMAINCUATRO" "5" "$DMAINCINCO"
2> $MENUP
if [ $? != 0 ]
then
rm *.tmp
exit 0
elif [ "$(cat $MENUP)" == "5" ]
then
limpiatemporales
elif [ "$(cat $MENUP)" == "4" ]
then
configurator
elif [ "$(cat $MENUP)" == "3" ]
then
aboutdialog
elif [ "$(cat $MENUP)" == "2" ]
then
favoritos
elif [ "$(cat $MENUP)" == "1d" ]
then
# ASISTENTE DE CONEXIÓN POR DHCP
escanear
cambiamac
cat $Scan | grep $(cat $REDelecta) | grep "WEP:Y" > $WEPYN
if [ "$(cat $WEPYN)" != "" ]
then
ponerwep
fi
conectardhcp "$(cat $REDelecta)"
comprobarconexion
elif [ "$(cat $MENUP)" == "1m" ]
then
escanear
cambiamac
cat $Scan | grep $(cat $REDelecta) | grep "WEP:Y" > $WEPYN
if [ "$(cat $WEPYN)" != "" ]
then
ponerwep
fi
conectarmanual "$(cat $REDelecta)"
else
rm *.tmp
exit 0
fi
}
# INSTALADOR
instalacion()
{
DIALOG="dialog"
mkdir ~/$OSWADIR
cd ~/$OSWADIR
mkdir $FAVORITOS
$DIALOG --title "$DFIRST" --msgbox "$DFIRSTONE" 0 0
configurator
aboutdialog
menuprincipal
}
# COMPROBAR PERMISOS (ROOT)
mustberoot()
{
if [ $(whoami) != "root" ]
then
$DIALOG --title "ERROR" --msgbox "You must be root" 0 0
exit 1
fi
}
# EJECUCION
cd ~/$OSWADIR
# COMPROBACION INSTALADO
if [ $? == 1 ]
then
instalacion
fi
# ARGUMENTO REINSTALACION
if [ "$1" == "-r" ]
then
$DIALOG --title $REINSTALL --defaultno --yesno "$SUREREINSTALL" 0 0
if [ $? == 0 ]
then
cd ~/
rm -r ~/$OSWADIR
instalacion
fi
fi
mustberoot
# ACTIVACION
iwconfig $WLAN mode managed
ifconfig $WLAN up
menuprincipal
Generated by SimpleDoc on 2006-02-14 21:27:36 GMT+01:00