#!/bin/bash ############################################################# # Script de commande du point d'accès et client wifi # # sur device HOTSPOT_IF avec DHCP et NAT # # Compatible Atlas Jeedom et networkManager # # Stefjm le 16/02/20265 # # 1 paramètre pour la fonction à appeler # ############################################################# # Inclusion du fichier de configuration HotspotConfig.sh source /var/www/html/plugins/script/data/HotspotConfig.sh ScanWifi(){ sudo nmcli dev wifi rescan } ListeWifi(){ nmcli -f IN-USE,SSID,CHAN,RATE,SIGNAL device wifi list } ActiverRadio(){ sudo nmcli radio wifi on } DesactiverRadio(){ sudo nmcli radio wifi off } Radio(){ sudo nmcli radio wifi | awk '{if($1=="enabled") print 1; else print 0;}' } Eth0(){ nmcli device | grep '^eth0' } ActiverEth0(){ sudo nmcli con up id 'ethernet-eth0' } Connecter(){ sudo nmcli device connect $HOTSPOT_IF } Deconnecter(){ sudo nmcli device disconnect $HOTSPOT_IF } DeviceWifi(){ echo $HOTSPOT_IF } EtatDevice(){ nmcli -t -f TYPE,STATE device | grep -q '^wifi:connected' && echo 1 || echo 0 } ActiverHotspot(){ sudo nmcli connection up hotspot } ActiverClientWifi(){ sudo nmcli connection up client-wifi } Hotspot(){ nmcli connection | grep wlan0 | awk '{if($3=="wifi" && $1=="hotspot") print 1;else print 0;}' } ClientWifi(){ nmcli connection | grep wlan0 | awk '{if($3=="wifi" && $1=="client-wifi") print 1;else print 0;}' } Devices(){ echo Devices nmcli device } Connexions(){ echo Connexions nmcli -f NAME,TYPE,DEVICE connection } Adresses(){ echo Adresses IP ip addr show | grep "inet " | cut -d'/' -f1 | cut -d't' -f2 | grep -v "127." } IPPasserelle(){ echo IP Passerelle ip route show default | grep -m1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' } Routes(){ echo Routes ip route | grep -v "169.254." } PasserelleConnectee(){ ping -c 1 -W 1 $(ip route show default | grep -m1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+') >/dev/null 2>&1 && echo 1||echo 0 } # Appel de la fonction $1