Danja Vasiliev il y a 10 ans
Parent
commit
5b62fd0e36

+ 19 - 0
openwrt/auto_scp.sh

@@ -0,0 +1,19 @@
+#!/bin/bash
+## watch files recursively for changes 
+## and scp to DEST
+##
+## assumes that DEST host has key based auth enabled,
+## otherwise password will be prompted everytime
+
+CMD='FILE=%f; DEST_FILE=${FILE#*/*/};
+scp $FILE superglue:/$DEST_FILE; 
+if [ $? -eq 0 ]; then 
+  play -q -n synth 0.1 tri 5000.0 gain -15;
+else
+  play -q -n synth 0.1 tri 1000.0 gain -10;
+fi' 
+
+#CMD='echo %f'
+
+iwatch -c "eval $CMD" -e modify -X '\.sw.?' -r .
+

+ 16 - 25
openwrt/common/opt/lib/cgi/admin2.cgi

@@ -363,24 +363,7 @@ doUci() {
   fi
 }
 
-getStat() {
-  . /usr/share/libubox/jshn.sh
-  local _IFACE=$1
-  local _IFSTAT=$(runSuid ubus call network.interface.wan status 2>/dev/null)
-  logThis "$_IFSTAT"
-  json_get_type _IFSTAT ipv4_address
-  if json_get_type _IFSTAT ipv4_address && [[ "$_IFSTAT" == 'array' ]]; then
-    json_select ipv4_address
-    json_get_type _IFSTAT 1
-    if [[ "$_IFSTAT" == 'object' ]]; then
-      json_select 1
-      json_get_var IP4 address
-      json_get_var Subnet4 mask
-      [[ "$IP4" != '' ]] && [[ "$Subnet4" != '' ]] && IP4="$IP4/$Subnet4"
-    fi
-  fi
-  logThis $IP4
-}
+. /opt/lib/scripts/jshn-helper.sh
 
 ## call with argument to inject additional lines
 ## ie: htmlhead "<meta http-equiv='refresh' content='2;URL=http://${HTTP_REFERER}'>"
@@ -419,6 +402,7 @@ if [[ "${REQUEST_METHOD^^}" == "POST" ]]; then
                 *rebootnow) rebootNow;;
                       *wan) wanSet;;
                    *uptime) upTime;;
+                   *iwscan) iwScan;;
                          *) logThis 'bad action'; headerPrint 405; 
                             echo 'no such thing'; exit 1;;
   esac
@@ -431,16 +415,23 @@ htmlHead
 sgver=$(cat /etc/superglue_version)
 devmod=$(cat /etc/superglue_model)
 openwrt=$(cat /etc/openwrt_version)
-wanifname=$(doUci get wanifname || echo 'wlan0') ## TODO fix this
+
+IFS=","
+wan=( $(ifaceStat wan) )
+IFS=$OFS
+
+#wanifname=$(doUci get wanifname || echo 'wlan0') ## TODO fix this
+wanifname=${wan[3]}
 wanproto=$(doUci get wanproto)
-wanipaddr=$(doUci get wanipaddr) 
-wannetmask=$(doUci get wannetmask)
+#wanipaddr=$(doUci get wanipaddr) 
+wanipaddr=${wan[0]}
+#wannetmask=$(doUci get wannetmask)
+wangw=${wan[2]}
+wandns=${wan[5]}
+wanuptime=${wan[4]}
 wanssid=$(doUci get wanssid)
 wankey=$(doUci get wankey)
 
-wanifname='eth0'
-
-ipaddr="$(runSuid ifconfig $wanifname | sed -n '/dr:/{;s/.*dr://;s/ .*//;p;}')"
 %>
 
 <body>
@@ -453,7 +444,7 @@ ipaddr="$(runSuid ifconfig $wanifname | sed -n '/dr:/{;s/.*dr://;s/ .*//;p;}')"
 </section>
 
 <section>
-  <h2>Internet connection: <% _echo $ipaddr %></h3>
+  <h2>Internet connection: <% _echo "IP:$wanipaddr, Gateway:$wangw, DNS:$wandns, up for $wanuptime seconds" %></h3>
   <form method='post' action='/admin/wan' name='wan' id='wanconf'>
   <div style='display:inline-flex'>
   <div style='display:inline-block;'>

+ 0 - 2
openwrt/common/opt/lib/resources/admin/admin.js

@@ -57,12 +57,10 @@ function wanChange(e) {
 
 function ajaxReq(url, method, data, callback) {
   var xmlDoc = new XMLHttpRequest();
-
   xmlDoc.open(url, method, true);
   if (method == 'POST') {
     xmlDoc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   }
-
   xmlDoc.onreadystatechange = function() {
     if (xmlDoc.readyState === 4 && xmlDoc.status === 200) {
       callback(xmlDoc);

+ 12 - 0
openwrt/common/opt/lib/scripts/iw-scan.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+function iwScan() {
+  set -o noglob
+  local AP S
+  while read -r AP; do
+    [[ "${AP//'SSID: '*}" == '' ]] && printf '%b' "${AP/'SSID: '}\n"
+    [[ "${AP//'signal: '*}" == '' ]] && ( S=( ${AP/'signal: '} ); printf '%b' "${S[0]},";)
+    [[ "${AP//'last seen: '*}" == '' ]] && ( S=( ${AP/'last seen: '} ); printf '%b' "${S[0]},";)
+  done <<< "$(iw wlan0 scan)"
+  set +o noglob
+}

+ 92 - 0
openwrt/common/opt/lib/scripts/jshn-helper.sh

@@ -0,0 +1,92 @@
+#!/bin/bash
+
+ifaceStat() {
+  . /usr/share/libubox/jshn.sh
+  local _IFACE=$1
+  local _STATUS="$(runSuid ubus call network.interface.$_IFACE status 2>/dev/null)"
+  if [[ "$_STATUS" != "" ]]; then
+    local State=""
+    local Iface=""
+    local Uptime=""
+    local IP4=""
+    local IP6=""
+    local Subnet4=""
+    local Subnet6=""
+    local Gateway4=""
+    local Gateway6=""
+    local DNS=""
+    local Protocol=""
+    json_load "${_STATUS:-{}}"
+    json_get_var State up
+    json_get_var Uptime uptime
+    json_get_var Iface l3_device
+    json_get_var Protocol proto
+
+    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
+      json_select ipv4_address
+      json_get_type Status 1
+      if [ "$Status" = object ]; then
+        json_select 1
+        json_get_var IP4 address
+        json_get_var Subnet4 mask
+        [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4,$Subnet4"
+      fi
+    fi
+    json_select
+    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
+      json_select ipv6_address
+      json_get_type Status 1
+      if [ "$Status" = object ]; then
+        json_select 1
+        json_get_var IP6 address
+        json_get_var Subnet6 mask
+        [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6,$Subnet6"
+      fi
+    fi
+    json_select
+    if json_get_type Status route && [ "$Status" = array ]; then
+      json_select route
+      local Index="1"
+      while json_get_type Status $Index && [ "$Status" = object ]; do
+        json_select "$((Index++))"
+        json_get_var Status target
+        case "$Status" in
+          0.0.0.0)
+            json_get_var Gateway4 nexthop;;
+          ::)
+          json_get_var Gateway6 nexthop;;
+        esac
+       json_select ".."
+      done  
+    fi
+    json_select
+    if json_get_type Status dns_server && [ "$Status" = array ]; then
+      json_select dns_server
+      local Index="1"
+      while json_get_type Status $Index && [ "$Status" = string ]; do
+        json_get_var Status "$((Index++))"
+        DNS="${DNS:+$DNS }$Status"
+      done
+    fi
+    if [ "$State" == "1" ]; then
+      [ "$IP4" != "" ] && _echo "$IP4,$Gateway4," 
+      [ "$IP6" != "" ] && _echo "$IP6,$Gateway6,"
+    _echo "$Iface,$Uptime,"
+    [ "$DNS" != "" ] && _echo "$DNS"
+    fi
+  fi
+
+#  json_get_type _IFSTAT ipv4_address
+#  if json_get_type _IFSTAT ipv4_address && [[ "$_IFSTAT" == 'array' ]]; then
+#    json_select ipv4_address
+#    json_get_type _IFSTAT 1
+#    if [[ "$_IFSTAT" == 'object' ]]; then
+#      json_select 1
+#      json_get_var IP4 address
+#      json_get_var Subnet4 mask
+#      [[ "$IP4" != '' ]] && [[ "$Subnet4" != '' ]] && IP4="$IP4/$Subnet4"
+#    fi
+#  fi
+#  logThis $IP4
+}
+