User Tools

Site Tools


aruba_scripts
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


aruba_scripts [2010/02/11 23:51] (current) – created ginko
Line 1: Line 1:
 +====== Aruba Scripts ======
 +Scripts permettant plus ou moins la gestion de la connexion à un point d'accès wifi aruba.
 +===== Aruba login =====
 +<code bash>
 +#!/bin/bash
 +
 +# *** Aruba Login Script ***
 +#         * v1.7 *
 +
 +# Permet de se connecter automatiquement au wifi à sully avec le login:XXXXX et le password:xxxx.
 +
 +# *** Utilisation ***
 +# arg1: cmd > shell / else > notifications graphiques
 +# arg2: V > shell / else > log dans les fichiers "arg2_aruba_login_init.html" et "arg2_aruba_login_log.html"
 +
 +# *** Release Notes ***
 +#
 +# -v1.0: -Script fonctionnel
 +# -v1.1: -Ajout de la notification
 +# -v1.2: -Amélioration de la notification (icone)
 +# -Ajout des commentaires
 +# -v1.3: -Ajout de la notification de démarrage
 +# -v1.4: -Ajout du mode commande
 +# -v1.5: -Débuggage du mode commande
 +# -Parsing de l'argument 1
 +# -Redirection de la sortie de curl vers /dev/null
 +# -v1.6: -Ajout du mode verbose/log
 +# -Ajout de la rubrique "Utilisation"
 +# -v1.7: -Intégration du notificateur d'état à la demande (aruba_state)
 +# *********************
 +
 +# *** Initialisation des variables ***
 +msg_init="Initialisation..."
 +msg_ok="Connexion réussie"
 +msg_er="Connexion échouée"
 +user="XXXXX"
 +pass="xxxx"
 +connect_state=0
 +
 +if [ $1 ]; then
 + mode=$1
 +else
 + mode="graph"
 +fi
 +
 +# *** Notification de démarrage ***
 +if [ $mode = cmd ]; then
 + echo $msg_init
 +else
 + notify-send -t 3000 Aruba_login $msg_init
 +fi
 +
 +# *** Connexion ***
 +# -L active la gestion des redirections
 +# -b active la gestion des cookies
 +# -d permet d'envoyer des données via la méthode POST
 +if [ $2 ]; then
 + if [ $2 = V ]; then
 + curl -L -b cookie https://securelogin.arubanetworks.com/
 + curl -L -b cookie -d "user=$user&password=$pass&cmd=authenticate&Login=Log+In" https://securelogin.arubanetworks.com/cgi-bin/login
 + else
 + curl -L -b cookie https://securelogin.arubanetworks.com/ >${2}"_aruba_login_init.html"
 + curl -L -b cookie -d "user=$user&password=$pass&cmd=authenticate&Login=Log+In" https://securelogin.arubanetworks.com/cgi-bin/login >${2}"_aruba_login_log.html"
 + fi
 +else
 + curl -L -b cookie https://securelogin.arubanetworks.com/ >/dev/null
 + curl -L -b cookie -d "user=$user&password=$pass&cmd=authenticate&Login=Log+In" https://securelogin.arubanetworks.com/cgi-bin/login >/dev/null
 +fi
 +
 +# *** Notification ***
 +# Dépends du code de retour de la dernière commande.
 +if (( $? == 0 )); then
 + $connect_state=1
 + if [ $mode = cmd ]; then
 + echo $msg_ok
 + else
 + notify-send -i /usr/share/icons/gnome/scalable/status/connect_creating.svg Aruba_login "$msg_ok"
 + fi
 +else
 + $connect_state=2
 + if [ $mode = cmd ]; then
 + echo $msg_er
 + else
 + notify-send -i /usr/share/icons/gnome/scalable/status/gnome-netstatus-error.svg Aruba_login "$msg_er"
 + fi
 +fi
 +
 +#enregistrement de l'état de connexion
 +echo $connect_state >/home/ginko/.bin/connect_state
 +</code>
 +===== Aruba logout =====
 +<code bash>
 +#!/bin/bash
 +
 +# *** Aruba Logout Script ***
 +#          * v1.7 *
 +
 +# Permet de se déconnecter facilement du wifi à Sully
 +
 +# *** Utilisation ***
 +# arg1: cmd > shell / else > notifications graphiques
 +# arg2: V > shell / else > log dans le fichier "arg2_aruba_logout.html"
 +
 +# *** Release Notes ***
 +#
 +# -v1.0: -Script fonctionnel
 +# -v1.1: -Ajout de la notification
 +# -v1.2: -Amélioration de la notification (icone)
 +# -Ajout des commentaires
 +# -v1.3: -Ajout de la notification de démarrage
 +# -v1.4: -Ajout du mode commande
 +# -v1.5: -Débuggage du mode commande
 +# -Parsing de l'argument 1
 +# -Redirection de la sortie de curl vers /dev/null
 +# -v1.6: -Ajout du mode verbose/log
 +# -Ajout de la rubrique "Utilisation"
 +# -v1.7: -Intégration du notificateur d'état à la demande (aruba_state)
 +# *********************
 +
 +# *** Initialisation des variables ***
 +msg_init="Initialisation..."
 +msg_ok="Déconnexion réussie"
 +msg_er="Déconnexion échouée"
 +
 +connect_state=0
 +
 +if [ $1 ]; then
 + mode=$1
 +else
 + mode="graph"
 +fi
 +
 +# *** Notification de démarage ***
 +if [ $mode = cmd ]; then
 + echo $msg_init
 +else
 + notify-send -t 3000 Aruba_logout $msg_init
 +fi
 +
 +# *** Déconnexion ***
 +# -L active la gestion des redirections
 +if [ $2 ]; then
 + if [ $2 = V ]; then
 + curl -L https://securelogin.arubanetworks.com/cgi-bin/login?cmd=logout
 + else
 + curl -L https://securelogin.arubanetworks.com/cgi-bin/login?cmd=logout >${2}"_aruba_logout.html"
 + fi
 +else
 + curl -L https://securelogin.arubanetworks.com/cgi-bin/login?cmd=logout >/dev/null
 +fi
 +
 +# *** Notification ***
 +# Dépends du code de retour de la dernière commande.
 +if (( $? == 0 )); then
 + connect_state=0
 + if [ $mode = cmd ]; then
 + echo $msg_ok
 + else
 + notify-send -i /usr/share/icons/gnome/scalable/status/connect_no.svg Aruba_logout "$msg_ok"
 + fi
 +else
 + connect_state=2
 + if [ $mode = cmd ]; then
 + echo $msg_er
 + else
 + notify-send -i /usr/share/icons/gnome/scalable/status/dialog-error.svg Aruba_logout "$msg_er"
 + fi
 +fi
 +
 +#enregistrement de l'état de connexion
 +echo $connect_state >/home/ginko/.bin/connect_state
 +</code>
 +===== Aruba state =====
 +NB: Script non fonctionnel... le fichier de stockage de l'état reste bloqué dans l'état 0...
 +<code bash>
 +#!/bin/bash
 +
 +# *** Aruba state notification script ***
 +#                * v1.0 *
 +
 +# Permet l'a notification à la demande de l'état de la connexion
 +
 +# *** Utilisation ***
 +# L'information émise ne peut être correcte qu'après l'excecution d'aruba_log{in/out}
 +
 +# *** Release Notes ***
 +#
 +# -v1.0: -Script fonctionnel
 +#**********************
 +
 +state_file=$HOME/.bin/connect_state
 +msg_ko=unconnected
 +msg_ok=connected
 +msg_er=error
 +msg_ex="cannot read connect_state file"
 +msg_el="unknown state"
 +
 +if [ -r $state_file ]; then
 + state=`tail -n 1 $state_file`
 +else
 + state=3
 +fi
 +
 +if [ $1 ]; then
 + mode=$1
 +else
 + mode="graph"
 +fi
 +
 +if [ $mode = cmd ];then
 + if [ $state = 0 ]; then
 + echo $msg_ko
 + elif [ $state = 1 ]; then
 + echo $msg_ok
 + elif [ $state = 2 ]; then
 + echo $msg_er
 + elif [ $state = 3 ]; then
 + echo $msg_ex
 + else
 + echo $msg_el
 + fi
 +else
 + if [ $state = 0 ]; then
 + notify-send Aruba_State $msg_ko
 + elif [ $state = 1 ]; then
 + notify-send Aruba_State $msg_ok
 + elif [ $state = 2 ]; then
 + notify-send Aruba_State $msg_er
 + elif [ $state = 3 ]; then
 + notify-send Aruba_State $msg_ex
 + else
 + notify-send Aruba_State $msg_el
 + fi
 +fi
 +</code>
 +===== Aruba state reloaded =====
 +NB: pas totalement testé, notamment, que ce passe-t-il si l'on est redirigé? Bonne sortie ou pas?
 +<code bash>
 +#!/bin/bash
 +
 +# *** Aruba State Reloaded ***
 +
 +# Vérifie si l'ordinateur a accès à internet
 +
 +msg_ok=Connecté
 +msg_er="Non connecté"
 +score=0
 +
 +if [ $1 ];then
 + mode=$1
 +else
 + mode=graph
 +fi
 +
 +echo $score
 +echo init perdu
 +curl -m 30 perdu.com >/dev/null
 +
 +if [ $? = 0 ]; then
 + score=${score+1}
 +fi
 +echo $score
 +echo init google
 +curl -m 30 www.google.fr >/dev/null
 +
 +if [ $? = 0 ]; then
 + score=${score+1}
 +fi
 +echo $score
 +if [ $mode = cmd ];then
 + if [ $score = 2 ]; then
 + echo $msg_ok
 + else
 + echo $msg_er "$score tentatives réussies sur 2"
 + fi
 +else
 + if  [ $score = 2 ];then
 + notify-send State $msg_ok
 + else
 + notify-send "$msg_er" "$score tentatives réussies sur 2"
 + fi
 +fi
 +</code>
 +
  
aruba_scripts.txt · Last modified: 2010/02/11 23:51 by ginko