#!/bin/sh #------------------------------------------------------------------------------ # status.cgi - Display Status of ISDN & DSL # # Creation: 17.01.2001 tg # Last Update: $Id$ # #------------------------------------------------------------------------------ # get main helper functions # set_debug=yes . /srv/www/include/cgi-helper # Functions show_connection_switch () { # Check for channel-bundling route=`imond-send "route" | sed 's/OK //; s/.$//'` links=`imond-send "links $route" | sed 's/OK //; s/.$//'` # Circuits circuits=`imond-send "circuits" | sed 's/.$//; s/OK //'` # check if a circuit is defined case $circuits in 0);; *) comm='' for i in `seq 1 $circuits` do comm=`if [ "$comm" != "" ]; then echo "$comm"; fi; echo "circuit $i"` done circuits=`imond-send "$comm" | grep -n 'OK' | sed 's/^/
  • /; s/.$/<\/a><\/li>/'` circuits="
  • Automatic (LCR)
  • $circuits" aktcirc=$route circuits=`echo "$circuits" | sed '/circuit='$aktcirc'/ s/
  • $_STAT_circuits:
  • $circuits" # Dialmode dialmode="
  • $_STAT_dm_auto
  • $_STAT_dm_manual
  • $_STAT_dm_off
  • " aktdialm=`imond-send "dialmode" | sed 's/OK //; s/.$//'` dialmode=`echo "$dialmode" | sed '/dialmode='$aktdialm'/ s/
  • $_STAT_dialmode:
  • $dialmode" # Dial/ Hangup echo '
    ' echo -n '' # Channel-Bundling? case $links in 0|ERR) ;; *) echo '
    ' echo -n '' ;; esac echo '
    ' echo '
    ' ;; esac } SEC_ACTION='view' case $FORM_action in "") headtitle="$_STAT_state" ;; *) ref="refresh=1;url=$myname" case $FORM_action in dialmode*) SEC_ACTION='dialmode' ;; circuit*) SEC_ACTION='circuit' ;; "$_STAT_dial"|"$_STAT_hangup") SEC_ACTION='dial' eval 'headtitle=$_'$FORM_action ;; "$_STAT_addlink"|"$_STAT_remlink") SEC_ACTION='link' eval 'headtitle=$_'$FORM_action ;; overview*) ref="" ;; esac ;; esac # Security check_rights "status" "$SEC_ACTION" show_html_header "$headtitle" "${ref}" case "$FORM_action" in "$_STAT_hangup") show_info "" "$_STAT_hangingup ... `imond-send "hangup"`" ;; "$_STAT_dial") show_info "" "$_STAT_dialing ... `imond-send "dial"`" ;; "$_STAT_addlink") route=`imond-send "route" | sed 's/OK //; s/.$//'` show_info "" "$_STAT_addinglink ... `imond-send "addlink $route"`" ;; "$_STAT_remlink") route=`imond-send "route" | sed 's/OK //; s/.$//'` show_info "" "$_STAT_removinglink ... `imond-send "removelink $route"`" ;; circuit) show_info "" "$_STAT_changingcirc $(echo "$FORM_circuit" | htmlspecialchars) ... `imond-send "route $FORM_circuit"`" ;; dialmode) show_info "" "$_STAT_changingdialmode \"$(echo "$FORM_dialmode" | htmlspecialchars)\" ...`imond-send "dialmode $FORM_dialmode"`" ;; esac #--------------------------------------------------------------------------------------------- #------------------------- Uptime ------------------------------------------------------------ #--------------------------------------------------------------------------------------------- show_tab_header "$_STAT_uptime" no uptime=`cat /proc/uptime | cut -f1 -d"." ` days=`expr $uptime / 86400` hours=`expr $uptime % 86400 / 3600 ` minutes=`expr $uptime % 3600 / 60` #seconds=`expr $uptime % 60` L_STAT_days=`expr length $_STAT_days` L_STAT_hours=`expr length $_STAT_hours` L_MN_and=`expr length $_MN_and` L_STAT_minutes=`expr length $_STAT_minutes` size=`expr $L_STAT_days + $L_STAT_hours + $L_MN_and + $L_STAT_minutes + 16` uptime="$days $_STAT_days, $hours $_STAT_hours $_MN_and $minutes $_STAT_minutes." echo "" echo "" echo '
    $HOSTNAME $_STAT_runningsince:
    ' show_tab_footer echo "
    " #--------------------------------------------------------------------------------------------- #------------------------- CPU-USAGE --------------------------------------------------------- #--------------------------------------------------------------------------------------------- cpu1m=`cat /proc/loadavg | cut -d " " -f 1` cpu5m=`cat /proc/loadavg | cut -d " " -f 2` cpu15m=`cat /proc/loadavg | cut -d " " -f 3` show_tab_header "$_STAT_cpuusage" no echo "" echo "" echo "" echo "
     1min 5min 15min
    $cpu1m$cpu5m$cpu15m
    " show_tab_footer echo "
    " if have_imond then set -- `imond-send "channels" "pppoe" "cpu" | sed 's/\(OK\|ERR\) //; s/.$//'` chan="$1" pppoe="$2" usage="$3" fi #--------------------------------------------------------------------------------------------- #------------------------- Last Call --------------------------------------------------------- #--------------------------------------------------------------------------------------------- # Check if telmond is running if ps | grep -q [t]elmond then set -- `telmond-send "" | sed 's/.$//'` case $1 in "") ;; *) LASTTIME="$1 $2" LASTFROM="$3" LASTTO="$4" # Find names in phonebook NAME=`grep "^$LASTFROM=" /etc/phonebook | cut -d"=" -f 2- | cut -d"," -f 1` if [ "$NAME" != "" ]; then LASTFROM="$NAME"; fi NAME=`grep "^$LASTTO=" /etc/phonebook | cut -d"=" -f 2- | cut -d"," -f 1` if [ "$NAME" != "" ]; then LASTTO="$NAME"; fi show_tab_header "$_STAT_lastcall" no echo '' echo '' echo '' echo '' echo "" echo "
    '$_STAT_lastcall':'$_STAT_from''$_STAT_to''$_MN_date' / '$_MN_time'
    $LASTFROM$LASTTO$LASTTIME
    " show_tab_footer echo "
    " ;; esac fi #--------------------------------------------------------------------------------------------- #------------------------- Connection-Status ------------------------------------------------- #--------------------------------------------------------------------------------------------- if have_imond then onl=0 devs='' for i in `seq 1 $chan` do devs="$devs $i" done case $pppoe in 1) devs="pppoe $devs" ;; esac # check if there are devices to display case $devs in "") ;; *) show_tab_header "$_STAT_connectionstate" no echo '' echo "" for i in $devs do cname= cdir= cip= conltime= cirate= corate= cibytes= cobytes= ctime= chtime= charge= conninfo=`imond-send "status $i" "phone $i" "inout $i" "ip $i" "online-time $i" "rate $i" "quantity $i" "time $i" "chargetime $i" "charge $i" | sed 's/OK //; s/.$//'` set -- $conninfo case $1 in Off*) cimg=rotaus #cibytes=`bytes2read $7 $8`B #cobytes=`bytes2read $9 ${10}`B ctime=${12} chtime=${13} charge=${14} ;; Call*) cimg=gelbaus cname=$2 #cibytes=`bytes2read $7 $8`B #cobytes=`bytes2read $9 ${10}`B ctime=${12} chtime=${13} charge=${14} ;; On*) cimg=gruenaus cname=$2 eval cdir='$_STAT_'$3 case $# in 14) cip=$4; shift 1 ;; esac conltime=$4 cirate=`bytes2read 0 $5`B/s corate=`bytes2read 0 $6`B/s cibytes=`bytes2read $7 $8`B cobytes=`bytes2read $9 ${10}`B ctime=${11} chtime=${12} charge=${13} onl=1 ;; esac form='' echo '' echo ' ' echo ' ' echo ' ' echo ' ' #echo ' ' #echo ' ' echo ' ' echo ' ' echo ' ' #echo ' ' #echo ' ' #echo ' ' echo '' done echo "
    $_STAT_state$_STAT_name$_STAT_direction$_STAT_ip $_STAT_ibytes$_STAT_obytes$_STAT_onltime
    '$form''$form''$form''$form''$form''$form''$form''$form''$form''$form''$form'
    " show_connection_switch show_tab_footer echo "
    " ;; esac fi #--------------------------------------------------------------------------------------------- #------------------------- DNS-Forwarder ----------------------------------------------------- #--------------------------------------------------------------------------------------------- if [ -f /etc/resolv.dnsmasq ] then show_tab_header "$_STAT_dnsforws" no echo '' resolver=`grep nameserver /etc/resolv.dnsmasq | cut -d " " -f 2` for i in $resolver do # lookup dns name of resolver, only if router is online if [ "$(fli4lctrl status)" = "online" ] then get_dns_name $i else res="n/a" fi echo "" done echo "
    IP'$_STAT_dnsname'
    $i$res
    " show_tab_footer echo '
    ' else # we use dns-forwarders with special ports if [ -f /etc/dnsmasq.d/dns_resolver.conf ] then show_tab_header "$_STAT_dnsforws" no echo '' while read line do eval tmpstr=`echo "$line" | cut -b 8- ` eval tmpip=`echo "$tmpstr" | cut -f 1 -d "#"` eval tmpport=`echo "$tmpstr" | cut -f 2 -d "#"` # if we have no port separated by # if [ "$tmpip" = "$tmpport" ] then tmpport="53" fi if [ "$tmpip" != "" ] then if [ "$(fli4lctrl status)" = "online" ] then get_dns_name $tmpip else res="n/a" fi echo "" fi done < /etc/dnsmasq.d/dns_resolver.conf echo "
    IP'$_STAT_dnsname'Port
    $tmpip$res$tmpport
    " show_tab_footer echo '
    ' fi fi #--------------------------------------------------------------------------------------------- #------------------------- ARP Table ------------------------------------------------- #--------------------------------------------------------------------------------------------- show_tab_header "$_STAT_arptable" no tooltipTitle='Interface' echo '' # Given output to parse: # "192.168.0.1 0x1 0x2 80:c6:ab:d8:9b:92 * wlan0" # "192.168.42.111 0x1 0x2 00:24:8c:07:6e:01 * eth1.1" # 1. Replace dots with spaces # "192 168 0 1 0x1 0x2 80:c6:ab:d8:9b:92 * wlan0" # "192 168 42 111 0x1 0x2 00:24:8c:07:6e:01 * eth1 1" # 2. Separate alphabetic characters from numeric characters followed by a space # with a space. This is necessary to be able to sort numeric by network interface # "192 168 0 1 0x1 0x2 80:c6:ab:d8:9b:92 * wlan0" # "192 168 42 111 0x1 0x2 00:24:8c:07:6e:01 * eth 1 1" # 3. Separate alphabetic characters from numeric characters at end of line with # a space. This is necessary to be able to sort numeric by network interface # "192 168 0 1 0x1 0x2 80:c6:ab:d8:9b:92 * wlan 0" # "192 168 42 111 0x1 0x2 00:24:8c:07:6e:01 * eth 1 1" # 4. Now sort in the following order: # - alphabetic # - by network device name # - numeric # - by network device number # - VLAN ID (if existing) # - IP part A # - IP part B # - IP part C # - IP part D # "192 168 42 111 0x1 0x2 00:24:8c:07:6e:01 * eth 1 1" # "192 168 0 1 0x1 0x2 80:c6:ab:d8:9b:92 * wlan 0" # 5. Exclude the headline by grep'ing "-v address" # 6. Read values sed -e "s/\./ /g" -e "s/\( [[:alpha:]]\{2,\}\)\([[:digit:]].* \)/\1 \2/g" -e "s/\( [[:alpha:]]\{2,\}\)\([[:digit:]].*$\)/\1 \2/g" /proc/net/arp | sort -k9 -k10n -k11n -k1n -k2n -k3n -k4n | grep -v address | while read ipA ipB ipC ipD hwtype flags mac foo devName devNo1 devNo2 do # Put IP values together ip=$ipA.$ipB.$ipC.$ipD # VLAN ID might be empty, so prevent the "." if [ -z "$devNo2" ] then dev=$devName$devNo1 else dev=$devName$devNo1.$devNo2 fi case $flags in 0x2) status="online";; *) status="offline"; mac="-";; esac get_dns_name $ip echo "" done echo "
    '$_STAT_state''$_STAT_name'IPMACInterface
    $status$res $ip$mac$dev
    " show_tab_footer echo '
    ' if have_imond then echo '
    ' #echo "$_MN_refresh ..." echo '' echo '
    ' fi show_html_footer