#!/bin/sh #------------------------------------------------------------------------------ # opt/files/srv/www/admin/status_wlan.cgi __FLI4LVER__ # # Creation: Karsten Horsmann 11.12.2005 # Last Update: $Id$ #------------------------------------------------------------------------------ # set_debug='yes' # get main helper functions . /srv/www/include/cgi-helper : ${FORM_action:=WLAN_cfg} # Security check_rights "wlan" "$FORM_action" tr='' tdz='' trz='' #------------------------------------------------------------------------------ #------------------------- Functions ------------------------------------------ #------------------------------------------------------------------------------ wlan_cfg_f() { echo '' for device in `iwconfig 2>/dev/null | sed -n '/^wlan[0-9]/s/ .*$//p'` do # Fuer jedes gefundene Device ein eigenes Form erstellen echo "" echo "" echo "" # Cleanup ESSID="";NICK="";FREQ="";MODE="";APMAC="";OWNMAC=""; eval `iwconfig $device | sed -n "s/.*\(ESSID\):\(\".*\"\).*Nickname:\(\".*\"\).*/\1=\2 ;NICK=\3/p s/.*\(Mode\):\(.*\).*Frequency:\(.*\) GHz.*.*Access Point: \(.*\)/\MODE=\2 ;FREQ=\3; APMAC=\4/p"` OWNMAC=`ip link show $device | sed -n 'y/abcdef/ABCDEF/;s/.*\(\([0-9A-F]\{2\}:\)\{5\}[0-9A-F]\{2\}\).\+/\1/p'` echo "$tr $_WLAN_cfg_essid $tdz $trz" echo "$tr $_WLAN_cfg_nick $tdz $trz" echo "$tr $_WLAN_cfg_channel $tdz $trz" echo -n "$tr $_WLAN_cfg_mode $tdz $trz" echo "$tr $_WLAN_cfg_ap $tdz $trz" echo "$tr $_WLAN_cfg_hwaddr $tdz $trz" echo "$tr $_WLAN_cfg_driver $tdz $drivername $trz" echo "$tr $_WLAN_cfg_update $tdz $(date -R) $trz" echo '' echo '' echo '' done echo "$tr$trz
$_WLAN_cfg_dev: $device
$_WLAN_cfg_name$_WLAN_cfg_value
" } wlan_sec_f() { echo '' for device in `iwconfig 2>/dev/null | sed -n '/^wlan[0-9]/s/ .*$//p'` do echo "" echo "" echo "" drivername='other' candomaster='no' candowpa='no' for i in /usr/local/wlan/detect_* do if [ "$drivername" = "other" ] then if [ -f "$i" ] then . $i fi fi done case $candowpa in yes) ssid="";scan_ssid="";key_mgmt="";psk="";wpa_passphrase="";wpa_pairwise="";wpa_key_mgmt="" # Noch zu tun: Durchsuche hostap nach Schluesseldaten, WEP Schluessel if [ -f /etc/wpa_supplicant.$device ] # Durchsuche wpa_supplicant.$device nach Schluesseldaten then eval `sed -n "s/^[[:space:]]*\(psk\|\(scan_\|\)ssid\|key_mgmt\)=\"*\([^\"]*\).*/\1='\3'/p" $trz" echo "$tr scan_ssid $tdz " # WPA-PSK okay. Was gibts noch? for i in WPA-PSK WPA-TKIP do echo -n "" ;; *) echo -n ">${i}" ;; esac done # zeige erstmal Sternchen, und auf Anfrage die Passphrase case x"$1" in xshow_plain) echo "$tr psk $tdz $trz" ;; x) echo "$tr psk $tdz $trz" echo '' ;; esac elif [ -f /etc/hostapd.$device ] then eval `sed -n "s/^[[:space:]]*\(wpa_passphrase\|\(wpa_pairwise_\|\)ssid\|wpa_key_mgmt\)=\"*\([^\"]*\).*/\1='\3'/p" $trz" case x"$1" in xshow_plain) echo "$tr wpa_passphrase $tdz $trz" ;; x) echo "$tr wpa_passphrase $tdz $trz" echo '' ;; esac fi ;; *) # Hier könnte WEP hin echo 'WEP kommt noch' ;; esac echo '' done echo "$tr$trz
$_WLAN_cfg_dev $device
$_WLAN_cfg_secname$_WLAN_cfg_value
" } wlan_scan_f() { echo "$_WLAN_cfg_update: $(date -R)" echo " " # haben wir wlanconfig an Board, dann sollten wir das nutzen if [ -x /usr/bin/wlanconfig ] then wlanconfigbin=yes fi for device in `iwconfig 2>/dev/null | sed -n '/^wlan[0-9]/s/ .*$//p'` do case x"$wlanconfigbin" in xyes) unset OWNMAC unset APMAC OWNMAC=`ip link show $device | sed -n 'y/abcdef/ABCDEF/;s/.*\(\([0-9A-F]\{2\}:\)\{5\}[0-9A-F]\{2\}\).\+/\1/p'` APMAC=`iwgetid -ar $device` if [ "$OWNMAC" = "$APMAC" ] # Ist es ein AP, dann ist die eigene MAC = die des APs then echo "wlanconfig $device list sta" wlanconfig $device list sta 2>/dev/null else # andere APs zeigen (bin client oder adhoc) echo "wlanconfig $device list ap" wlanconfig $device list ap 2>/dev/null # zeigt den scan leider gekürzt an echo " " echo "iwlist $device scan" iwlist $device scan 2>/dev/null fi ;; x) unset ISAP ISAP=`iw dev $device info | sed -n '/AP/p'` # Ist es ein AP, dann enthält die Statusmeldung "AP" if [ "$ISAP" = "" ] then echo "available access points" echo " " iw dev $device scan 2>/dev/null # andere APs zeigen (bin client oder adhoc) else echo "connected devices" echo " " iw dev $device station dump 2>/dev/null # Geräte auflisten, die mit dem FLI verbunden sind fi ;; esac done } #------------------------------------------------------------------------------ #------------------------- Actions without htmlheader ------------------------- #------------------------------------------------------------------------------ myname=`basename $0` case "$FORM_action" in "$_WLAN_cfg_scan_sv") unset file unset fname fname="WLAN_SEARCH_$(date +%F_%H%M%S).txt" file=$$wlan_scan_f.txt wlan_scan_f >/tmp/$$wlan_scan_f.txt # hier eventuell unix2dos sed ctype=application/download;filename=$file set -- `ls -l /tmp/$file` length=$5 echo "Content-Type: $ctype" echo "Content-Disposition: attachment; filename=$fname" echo "Content-Length: $length" echo cat /tmp/$$wlan_scan_f.txt && rm -f /tmp/$$wlan_scan_f.txt ;; esac #------------------------------------------------------------------------------ #------------------------- Actions with htmlheader ---------------------------- #------------------------------------------------------------------------------ show_html_header "$_WLAN_cfg_header-`eval echo '$_'$FORM_action`" maintabs="" case $FORM_action in WLAN_cfg|${_WLAN_cfg_refresh}) maintabs="${maintabs}\"${_WLAN_cfg}\" \"no\" " ;; *) maintabs="${maintabs}\"${_WLAN_cfg}\" \"${myname}\" " ;; esac case $FORM_action in WLAN_sec|${_WLAN_cfg_passplain}) maintabs="${maintabs}\"${_WLAN_sec}\" \"no\" " ;; *) maintabs="${maintabs}\"${_WLAN_sec}\" \"${myname}?action=WLAN_sec\" " ;; esac case $FORM_action in WLAN_scan) maintabs="${maintabs}\"${_WLAN_scan}\" \"no\" " ;; *) maintabs="${maintabs}\"${_WLAN_scan}\" \"${myname}?action=WLAN_scan\" " ;; esac eval show_tab_header $maintabs case "$FORM_action" in WLAN_sec) wlan_sec_f ;; "$_WLAN_cfg_passplain") wlan_sec_f show_plain ;; WLAN_scan) echo '
' echo '' echo '
' echo '
'
    wlan_scan_f >/tmp/$$wlan_scan_f.txt  || show_error "" "$_WLAN_cfg_write_err"
    cat /tmp/$$wlan_scan_f.txt  || show_error "" "$_WLAN_cfg_read_err"
    rm -f /tmp/$$wlan_scan_f.txt 
    echo '
' ;; WLAN_cfg) if [ ! -f /tmp/wlan_cfg_f.html ] then wlan_cfg_f >/tmp/wlan_cfg_f.html || show_error "" "$_WLAN_cfg_write_err" fi cat /tmp/wlan_cfg_f.html || show_error "" "$_WLAN_cfg_read_err" ;; "$_WLAN_cfg_refresh") rm -f /tmp/wlan_cfg_f.html 2>/dev/null if [ ! -f /tmp/wlan_cfg_f.html ] then wlan_cfg_f >/tmp/wlan_cfg_f.html || show_error "" "$_WLAN_cfg_write_err" fi cat /tmp/wlan_cfg_f.html || show_error "" "$_WLAN_cfg_read_err" ;; esac show_tab_footer show_html_footer