| 23 | | |
|---|
| 24 | | # additional information variables |
|---|
| 25 | | hideinfo="|hidden" |
|---|
| 26 | | ifconfig |grep ppp0 >>/dev/null |
|---|
| 27 | | if [ $? = 0 ]; then |
|---|
| 28 | | ip=$(/sbin/ifconfig ppp0 | grep inet | awk '{print $2}'| awk -F : '{print $2}') |
|---|
| 29 | | rx=$(/sbin/ifconfig ppp0 | grep 'RX bytes' | awk -F : '{print $2}' | awk -F' T' '{print $1}') |
|---|
| 30 | | tx=$(/sbin/ifconfig ppp0 | grep 'RX bytes' | awk -F : '{print $3}') |
|---|
| 31 | | resconf=$(cat /etc/dnsmasq.conf 2>/dev/null | grep "^resolv-file=" | cut -d'=' -f 2) |
|---|
| 32 | | resconf="${resconf:-"/etc/resolv.conf"}" |
|---|
| 33 | | dns_servers=$(cat "$resconf" 2>/dev/null | awk 'BEGIN{ dns_count=0 }; /nameserver/ { dns_count++; print "field|@TR<<DNS Server>> " dns_count "|dns_server_" dns_count; print "string|" $2 }') |
|---|
| 34 | | fi |
|---|
| 35 | | |
|---|
| 36 | | # keepalive variables |
|---|
| 37 | | hidekeepalive="|hidden" |
|---|
| 38 | | [ -e /tmp/keepalive.log ] && { |
|---|
| 39 | | hidekeepalive= |
|---|
| 40 | | } |
|---|
| 41 | | |
|---|
| 42 | | # pppd log variables |
|---|
| 43 | | hidelog="|hidden" |
|---|
| 44 | | [ $(logread | grep -i pppd | wc -l) -ne 0 ] && { |
|---|
| 45 | | hidelog= |
|---|
| 46 | | } |
|---|
| 47 | | |
|---|
| 48 | | # determine connection state and action |
|---|
| | 23 | ############ determine connection state and action |
|---|
| 80 | | # content |
|---|
| | 55 | ############ variables |
|---|
| | 56 | # get additional connection information |
|---|
| | 57 | getconnectioninfo() { |
|---|
| | 58 | ip=$(/sbin/ifconfig ppp0 | grep inet | awk '{print $2}'| awk -F : '{print $2}') |
|---|
| | 59 | rx=$(/sbin/ifconfig ppp0 | grep 'RX bytes' | awk -F : '{print $2}' | awk -F' T' '{print $1}') |
|---|
| | 60 | tx=$(/sbin/ifconfig ppp0 | grep 'RX bytes' | awk -F : '{print $3}') |
|---|
| | 61 | resconf=$(cat /etc/dnsmasq.conf 2>/dev/null | grep "^resolv-file=" | cut -d'=' -f 2) |
|---|
| | 62 | resconf="${resconf:-"/etc/resolv.conf"}" |
|---|
| | 63 | dns_servers=$(cat "$resconf" 2>/dev/null | awk 'BEGIN{ dns_count=0 }; /nameserver/ { dns_count++; print "field|@TR<<DNS Server>> " dns_count "|dns_server_" dns_count; print "string|" $2 }') |
|---|
| | 64 | } |
|---|
| | 65 | |
|---|
| | 66 | # get additional card information |
|---|
| | 67 | getcardinfo() { |
|---|
| | 68 | |
|---|
| | 69 | # the comgt package has changed the executable |
|---|
| | 70 | comgt=$(which comgt 2>/dev/null) |
|---|
| | 71 | empty "$comgt" && comgt=$(which gcom 2>/dev/null) |
|---|
| | 72 | |
|---|
| | 73 | # determine the card ports |
|---|
| | 74 | wwan_device="$(nvram get wwan_device)" |
|---|
| | 75 | modem_data_port=${wwan_device:-"/dev/usb/tts/0"} |
|---|
| | 76 | modem_control_ports="/dev/usb/tts/2 /dev/noz2" |
|---|
| | 77 | for port in $modem_control_ports |
|---|
| | 78 | do |
|---|
| | 79 | [ -e "$port" ] && { |
|---|
| | 80 | modem_control_port=$port |
|---|
| | 81 | } |
|---|
| | 82 | done |
|---|
| | 83 | |
|---|
| | 84 | case "$(nvram get wwan_type)" in |
|---|
| | 85 | gsm) |
|---|
| | 86 | info=$($comgt -d "$modem_control_port" -s /usr/lib/webif/comgt.webif 2>/dev/null) |
|---|
| | 87 | signal=$(echo "$info" | grep "+CSQ:" | cut -d: -f2 | cut -d, -f1) |
|---|
| | 88 | ;; |
|---|
| | 89 | cdma) |
|---|
| | 90 | if [ $1 = "disconnected" ]; then |
|---|
| | 91 | # only if disconnected |
|---|
| | 92 | signal=$($comgt -sd "$modem_data_port" /usr/lib/webif/comgt-cdma.webif 2>/dev/null) |
|---|
| | 93 | else |
|---|
| | 94 | hideif_connected_cdma="|hidden" |
|---|
| | 95 | fi |
|---|
| | 96 | ;; |
|---|
| | 97 | esac |
|---|
| | 98 | |
|---|
| | 99 | # calculate signal strength in db and percentage |
|---|
| | 100 | if [ -n "$signal" -a "$signal" != "99" ]; then |
|---|
| | 101 | signaldb="$((109-signal*2))" |
|---|
| | 102 | signalpercent=$(((128-$signaldb)*100/81)) |
|---|
| | 103 | else |
|---|
| | 104 | signaldb="128" |
|---|
| | 105 | signalpercent="0" |
|---|
| | 106 | fi |
|---|
| | 107 | } |
|---|
| | 108 | |
|---|
| | 109 | ############# options on page load |
|---|
| | 110 | # if connected |
|---|
| | 111 | [ -e "/tmp/lock/LCK..usb_tts_"* ] && { |
|---|
| | 112 | getconnectioninfo |
|---|
| | 113 | getcardinfo connected |
|---|
| | 114 | hideif_connected="|hidden" |
|---|
| | 115 | } || { |
|---|
| | 116 | #if disconnected |
|---|
| | 117 | getcardinfo disconnected |
|---|
| | 118 | hideif_disconnected="|hidden" |
|---|
| | 119 | } |
|---|
| | 120 | |
|---|
| | 121 | # if pppd log is empty |
|---|
| | 122 | [ $(logread | grep -c pppd) -eq 0 ] && { |
|---|
| | 123 | hide_pppd="|hidden" |
|---|
| | 124 | } |
|---|
| | 125 | |
|---|
| | 126 | # if keepalive log is empty |
|---|
| | 127 | [ -e /tmp/keepalive.log ] || { |
|---|
| | 128 | hide_keepalive="|hidden" |
|---|
| | 129 | } |
|---|
| | 130 | |
|---|
| | 131 | ############# content |
|---|