diff --git a/rooter/0protocols/luci-proto-3x/Makefile b/rooter-builds/0protocols/luci-proto-3x/Makefile similarity index 100% rename from rooter/0protocols/luci-proto-3x/Makefile rename to rooter-builds/0protocols/luci-proto-3x/Makefile diff --git a/rooter/0protocols/luci-proto-3x/files/usr/lib/lua/luci/model/cbi/admin_network/proto_3x.lua b/rooter-builds/0protocols/luci-proto-3x/files/usr/lib/lua/luci/model/cbi/admin_network/proto_3x.lua similarity index 100% rename from rooter/0protocols/luci-proto-3x/files/usr/lib/lua/luci/model/cbi/admin_network/proto_3x.lua rename to rooter-builds/0protocols/luci-proto-3x/files/usr/lib/lua/luci/model/cbi/admin_network/proto_3x.lua diff --git a/rooter/0protocols/luci-proto-3x/files/usr/lib/lua/luci/model/network/proto_3x.lua b/rooter-builds/0protocols/luci-proto-3x/files/usr/lib/lua/luci/model/network/proto_3x.lua similarity index 100% rename from rooter/0protocols/luci-proto-3x/files/usr/lib/lua/luci/model/network/proto_3x.lua rename to rooter-builds/0protocols/luci-proto-3x/files/usr/lib/lua/luci/model/network/proto_3x.lua diff --git a/rooter/0protocols/luci-proto-3x/files/www/luci-static/resources/protocol/3x.js b/rooter-builds/0protocols/luci-proto-3x/files/www/luci-static/resources/protocol/3x.js similarity index 100% rename from rooter/0protocols/luci-proto-3x/files/www/luci-static/resources/protocol/3x.js rename to rooter-builds/0protocols/luci-proto-3x/files/www/luci-static/resources/protocol/3x.js diff --git a/rooter/0protocols/luci-proto-mbim/Makefile b/rooter-builds/0protocols/luci-proto-mbim/Makefile similarity index 100% rename from rooter/0protocols/luci-proto-mbim/Makefile rename to rooter-builds/0protocols/luci-proto-mbim/Makefile diff --git a/rooter/0protocols/luci-proto-mbim/files/usr/lib/lua/luci/model/cbi/admin_network/proto_mbim.lua b/rooter-builds/0protocols/luci-proto-mbim/files/usr/lib/lua/luci/model/cbi/admin_network/proto_mbim.lua similarity index 100% rename from rooter/0protocols/luci-proto-mbim/files/usr/lib/lua/luci/model/cbi/admin_network/proto_mbim.lua rename to rooter-builds/0protocols/luci-proto-mbim/files/usr/lib/lua/luci/model/cbi/admin_network/proto_mbim.lua diff --git a/rooter/0protocols/luci-proto-mbim/files/usr/lib/lua/luci/model/network/proto_mbim.lua b/rooter-builds/0protocols/luci-proto-mbim/files/usr/lib/lua/luci/model/network/proto_mbim.lua similarity index 100% rename from rooter/0protocols/luci-proto-mbim/files/usr/lib/lua/luci/model/network/proto_mbim.lua rename to rooter-builds/0protocols/luci-proto-mbim/files/usr/lib/lua/luci/model/network/proto_mbim.lua diff --git a/rooter/0protocols/luci-proto-mbim/files/www/luci-static/resources/protocol/mbim.js b/rooter-builds/0protocols/luci-proto-mbim/files/www/luci-static/resources/protocol/mbim.js similarity index 100% rename from rooter/0protocols/luci-proto-mbim/files/www/luci-static/resources/protocol/mbim.js rename to rooter-builds/0protocols/luci-proto-mbim/files/www/luci-static/resources/protocol/mbim.js diff --git a/rooter-builds/ext-huasifei/Makefile b/rooter-builds/ext-huasifei/Makefile new file mode 100644 index 0000000..c0e4c1d --- /dev/null +++ b/rooter-builds/ext-huasifei/Makefile @@ -0,0 +1,43 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-huasifei +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-huasifei + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+luci +ext-rooter-basic +pingtest +ext-blacklist +ext-blockport \ + +extramenu +ext-domain \ + +luci-app-ddns +ddns-scripts \ + +luci-app-rootervpn +ext-wireguard \ + +webconsole +bwmon +464xlat \ + +iptables-mod-hashlimit \ + +ca-bundle +ca-certificates +libustream-wolfssl \ + +luci-app-ksmbd +usb-storage \ + +ext-p910nd +kmod-sched-cake +luci-app-nft-qos \ + +ext-command +ext-speedtest +luci-app-guestwifi \ + +openvpn-easy-rsa +openvpn-openssl \ + +ext-extra +luci-app-hotspot +luci-app-wol \ + +usbmuxd +libusbmuxd-utils +libimobiledevice-utils +kmod-usb-net-ipheth \ + +qlog +luci-ssl +usbutils +openssl-util +irqbalance +ext-splashconfig \ + +nano +picocom +wpad +wget +qfirehose + TITLE:=ROOter support w/o MWan3 for Huasifei + PKGARCH:=all +endef + +define Package/ext-huasifei/description + Helper scripts to enable ROOter support for Huasifei +endef + + +define Build/Compile +endef + +$(eval $(call BuildPackage,ext-huasifei)) diff --git a/rooter-builds/ext-huasifei16/Makefile b/rooter-builds/ext-huasifei16/Makefile new file mode 100644 index 0000000..5bf634f --- /dev/null +++ b/rooter-builds/ext-huasifei16/Makefile @@ -0,0 +1,30 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-huasifei16 +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-huasifei16 + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+ext-huasifei \ + +luci-app-mwan3 +luci-app-dnsmasq-ipset + TITLE:=ROOter support w/o MWan3 for Huasifei + PKGARCH:=all +endef + +define Package/ext-huasifei16/description + Helper scripts to enable ROOter support for Huasifei +endef + + +define Build/Compile +endef + +$(eval $(call BuildPackage,ext-huasifei16)) diff --git a/rooter-builds/ext-rbsxtr/Makefile b/rooter-builds/ext-rbsxtr/Makefile new file mode 100644 index 0000000..e71c30d --- /dev/null +++ b/rooter-builds/ext-rbsxtr/Makefile @@ -0,0 +1,37 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-rbsxtr +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-rbsxtr + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+luci +luci-compat +ext-rooter-basic \ + +luci-app-rootervpn +ext-wireguard \ + +bwmon +464xlat \ + +ca-bundle +ca-certificates +libustream-wolfssl \ + +luci-app-sqm +kmod-sched-cake \ + +ext-command +ext-speedtest \ + +openvpn-easy-rsa +openvpn-openssl \ + +ext-extra \ + +nano +picocom +wget +webconsole + TITLE:=ROOter support for RBSXTR routers + PKGARCH:=all +endef + +define Package/ext-rbsxtr/description + Helper scripts to enable ROOter support for RBSXTR routers +endef + + +define Build/Compile +endef + +$(eval $(call BuildPackage,ext-rbsxtr)) diff --git a/rooter-builds/ext-rbsxtr16/Makefile b/rooter-builds/ext-rbsxtr16/Makefile new file mode 100644 index 0000000..e71c30d --- /dev/null +++ b/rooter-builds/ext-rbsxtr16/Makefile @@ -0,0 +1,37 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-rbsxtr +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-rbsxtr + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+luci +luci-compat +ext-rooter-basic \ + +luci-app-rootervpn +ext-wireguard \ + +bwmon +464xlat \ + +ca-bundle +ca-certificates +libustream-wolfssl \ + +luci-app-sqm +kmod-sched-cake \ + +ext-command +ext-speedtest \ + +openvpn-easy-rsa +openvpn-openssl \ + +ext-extra \ + +nano +picocom +wget +webconsole + TITLE:=ROOter support for RBSXTR routers + PKGARCH:=all +endef + +define Package/ext-rbsxtr/description + Helper scripts to enable ROOter support for RBSXTR routers +endef + + +define Build/Compile +endef + +$(eval $(call BuildPackage,ext-rbsxtr)) diff --git a/rooter-builds/ext-rooter-lite/Makefile b/rooter-builds/ext-rooter-lite/Makefile new file mode 100644 index 0000000..44d866d --- /dev/null +++ b/rooter-builds/ext-rooter-lite/Makefile @@ -0,0 +1,43 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-rooter-lite +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-rooter-lite + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+luci +ext-rooter-basic +pingtest +ext-logo \ + +luci-app-ddns +ddns-scripts \ + +luci-app-rootervpn +ext-wireguard \ + +bwmon +464xlat +webconsole \ + +ext-theme +luci-theme-argon +luci-theme-argondark +ext-login \ + +luci-theme-tomato \ + +ca-bundle +ca-certificates +libustream-wolfssl \ + +luci-app-ksmbd +usb-storage \ + +ext-p910nd +luci-app-sqm +kmod-sched-cake +luci-app-nft-qos \ + +ext-command +ext-speedtest \ + +openvpn-easy-rsa +openvpn-openssl \ + +ext-extra +luci-app-hotspot +luci-app-wol +luci-app-guestwifi \ + +usbmuxd +libusbmuxd-utils +libimobiledevice-utils +kmod-usb-net-ipheth \ + +qlog +luci-ssl +usbutils +openssl-util +irqbalance +ext-splashconfig \ + +nano +picocom +wpad-openssl +wget +qfirehose +luci-app-vpnbypass +ext-simplegps + TITLE:=ROOter support w/o MWan3 for 16meg and larger routers + PKGARCH:=all +endef + +define Package/ext-rooter-lite/description + Helper scripts to enable ROOter w/o MWan3 on 16meg and larger routers +endef + + +define Build/Compile +endef + +$(eval $(call BuildPackage,ext-rooter-lite)) diff --git a/rooter-builds/ext-rooter16/Makefile b/rooter-builds/ext-rooter16/Makefile new file mode 100644 index 0000000..39a5d41 --- /dev/null +++ b/rooter-builds/ext-rooter16/Makefile @@ -0,0 +1,44 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-rooter16 +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-rooter16 + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+luci +ext-rooter-basic +pingtest +ext-logo \ + +luci-app-mwan3 +luci-app-dnsmasq-ipset \ + +luci-app-ddns +ddns-scripts \ + +luci-app-rootervpn +ext-wireguard \ + +bwmon +464xlat +webconsole \ + +ext-theme +luci-theme-argon +luci-theme-argondark \ + +luci-theme-tomato +ext-login \ + +ca-bundle +ca-certificates +libustream-wolfssl \ + +luci-app-ksmbd +usb-storage \ + +ext-p910nd +luci-app-sqm +kmod-sched-cake +luci-app-nft-qos \ + +ext-command +ext-speedtest +luci-app-guestwifi \ + +openvpn-easy-rsa +openvpn-openssl \ + +ext-extra +luci-app-hotspot +luci-app-wol \ + +usbmuxd +libusbmuxd-utils +libimobiledevice-utils +kmod-usb-net-ipheth \ + +qlog +luci-ssl +usbutils +openssl-util +irqbalance +ext-splashconfig \ + +nano +picocom +wpad-openssl +wget +qfirehose +luci-app-vpnbypass +ext-simplegps + TITLE:=ROOter support for 16meg and larger routers + PKGARCH:=all +endef + +define Package/ext-rooter16/description + Helper scripts to enable ROOter on 16meg and larger routers +endef + + +define Build/Compile +endef + +$(eval $(call BuildPackage,ext-rooter16)) diff --git a/rooter-builds/ext-rooter4/Makefile b/rooter-builds/ext-rooter4/Makefile new file mode 100644 index 0000000..dab4ab8 --- /dev/null +++ b/rooter-builds/ext-rooter4/Makefile @@ -0,0 +1,38 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-rooter4 +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-rooter4 + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+luci +ext-rooter-basic +ext-logo \ + +ca-bundle +ca-certificates \ + +luci-app-sqm +kmod-sched-cake \ + +luci-app-ddns +ddns-scripts \ + +ext-command +ext-p910nd +luci-app-guestwifi \ + +luci-app-hotspot +ext-extra \ + +picocom +wget +nano +464xlat + TITLE:=install basic ROOter routers + PKGARCH:=all +endef + +define Package/ext-rooter4/description + Helper scripts to install basic ROOter routers +endef + +define Build/Compile +endef + +define Package/ext-rooter4/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,ext-rooter4)) diff --git a/rooter-builds/ext-rooter4/files/etc/config/failover b/rooter-builds/ext-rooter4/files/etc/config/failover new file mode 100644 index 0000000..c626526 --- /dev/null +++ b/rooter-builds/ext-rooter4/files/etc/config/failover @@ -0,0 +1,15 @@ + +config policy 'faillist' + +config tracker 'failover' + option reliability '1' + option count '1' + option pingtime '5' + option pingwait '7' + option down '2' + option up '2' + list trackip '8.8.8.8' + +config enabled 'enabled' + option enabled '0' + diff --git a/rooter-builds/ext-rooter4/files/etc/flash b/rooter-builds/ext-rooter4/files/etc/flash new file mode 100644 index 0000000..8ff4fad --- /dev/null +++ b/rooter-builds/ext-rooter4/files/etc/flash @@ -0,0 +1 @@ +FLASH="4" diff --git a/rooter-builds/ext-rooter4/files/usr/lib/lua/luci/controller/failover.lua b/rooter-builds/ext-rooter4/files/usr/lib/lua/luci/controller/failover.lua new file mode 100644 index 0000000..28bcb0b --- /dev/null +++ b/rooter-builds/ext-rooter4/files/usr/lib/lua/luci/controller/failover.lua @@ -0,0 +1,39 @@ +module("luci.controller.failover", package.seeall) + +function index() + local page + + if not nixio.fs.access("/etc/config/failover") then + return + end + + page = entry({"admin", "network", "failover"}, cbi("rooter/failover"), "Internet Failover", 600) + page.dependent = true + + entry({"admin", "network", "get_fstatus"}, call("action_get_fstatus")) +end + +function action_get_fstatus() + local file + mArray = {} + file = io.open("/tmp/wanstatus", "r") + if file == nil then + mArray["wan"] = " " + else + mArray["wan"] = file:read("*line") + mArray["winter"] = file:read("*line") + mArray["wstatus"] = file:read("*line") + file:close() + end + file = io.open("/tmp/modemstatus", "r") + if file == nil then + mArray["modem"] = " " + else + mArray["modem"] = file:read("*line") + mArray["minter"] = file:read("*line") + mArray["mstatus"] = file:read("*line") + file:close() + end + luci.http.prepare_content("application/json") + luci.http.write_json(mArray) +end diff --git a/rooter-builds/ext-rooter4/files/usr/lib/lua/luci/model/cbi/rooter/failover.lua b/rooter-builds/ext-rooter4/files/usr/lib/lua/luci/model/cbi/rooter/failover.lua new file mode 100644 index 0000000..dff96a7 --- /dev/null +++ b/rooter-builds/ext-rooter4/files/usr/lib/lua/luci/model/cbi/rooter/failover.lua @@ -0,0 +1,140 @@ +local utl = require "luci.util" +local uci = require "luci.model.uci".cursor() + +function cbiAddWan(field) + i = 0 + uci.cursor():foreach("failover", "member", + function (section) + line = section[".name"] + s, e = line:find("Modem") + if s == nil then + field:value(section[".name"]) + if i == 0 then + field.default = section[".name"] + end + i = 1 + end + end + ) +end + +function cbiAddModem(field) + i = 0 + uci.cursor():foreach("failover", "member", + function (section) + line = section[".name"] + s, e = line:find("Modem") + if s ~= nil then + field:value(section[".name"]) + if i == 0 then + field.default = section[".name"] + end + i = 1 + end + end + ) +end + +m = Map("failover", translate("Internet Connection Failover"), translate("Enable a connection failover system between two Internet sources.")) + +m.on_after_commit = function(self) + luci.sys.call("/usr/lib/rooter/luci/failchk.sh") +end + +enabl = m:section(NamedSection, "enabled", "enabled", "") + enabl.addremove = false + enabl.dynamic = false + +e = enabl:option(Flag, "enabled", translate("Failover Enabled")) +e.rmempty = false + +policy = m:section(NamedSection, "faillist", "policy", "") + policy.addremove = false + policy.dynamic = false + +use_wan = policy:option(ListValue, "use_wan", translate("Primary Internet Source"), + translate("Select Primary Internet source.")) + cbiAddWan(use_wan) + +use_modem = policy:option(ListValue, "use_modem", translate("Secondary Internet Source"), + translate("Select Secondary (Backup) Internet source.")) + cbiAddModem(use_modem) + +tracker = m:section(NamedSection, "failover", "tracker", "") + tracker.addremove = false + tracker.dynamic = false + +reliability = tracker:option(Value, "reliability", translate("Tracking reliability"), + translate("Acceptable values: 1-100. This many Tracking IP addresses must respond for the source to be deemed up")) + reliability.datatype = "range(1, 100)" + reliability.default = "1" + +count = tracker:option(ListValue, "count", translate("Ping count")) + count.default = "1" + count:value("1") + count:value("2") + count:value("3") + count:value("4") + count:value("5") + +interval = tracker:option(ListValue, "pingtime", translate("Ping interval"), + translate("Amount of time between tracking tests")) + interval.default = "5" + interval:value("5", translate("5 seconds")) + interval:value("10", translate("10 seconds")) + interval:value("20", translate("20 seconds")) + interval:value("30", translate("30 seconds")) + interval:value("60", translate("1 minute")) + interval:value("300", translate("5 minutes")) + interval:value("600", translate("10 minutes")) + interval:value("900", translate("15 minutes")) + interval:value("1800", translate("30 minutes")) + interval:value("3600", translate("1 hour")) + +timeout = tracker:option(ListValue, "pingwait", translate("Ping timeout")) + timeout.default = "2" + timeout:value("1", translate("1 second")) + timeout:value("2", translate("2 seconds")) + timeout:value("3", translate("3 seconds")) + timeout:value("4", translate("4 seconds")) + timeout:value("5", translate("5 seconds")) + timeout:value("6", translate("6 seconds")) + timeout:value("7", translate("7 seconds")) + timeout:value("8", translate("8 seconds")) + timeout:value("9", translate("9 seconds")) + timeout:value("10", translate("10 seconds")) + +down = tracker:option(ListValue, "down", translate("Interface down"), + translate("Interface will be deemed down after this many failed ping tests in a row")) + down.default = "2" + down:value("1") + down:value("2") + down:value("3") + down:value("4") + down:value("5") + down:value("6") + down:value("7") + down:value("8") + down:value("9") + down:value("10") + +up = tracker:option(ListValue, "up", translate("Interface up"), + translate("Downed interface will be deemed up after this many successful ping tests in a row")) + up.default = "2" + up:value("1") + up:value("2") + up:value("3") + up:value("4") + up:value("5") + up:value("6") + up:value("7") + up:value("8") + up:value("9") + up:value("10") + +cb2 = tracker:option(DynamicList, "trackip", translate("Tracking IP"), + translate("This IP address will be pinged to dermine if the link is up or down.")) + cb2.datatype = "ipaddr" + +return m + diff --git a/rooter-builds/ext-rooter4/files/usr/lib/rooter/connect/failover.sh b/rooter-builds/ext-rooter4/files/usr/lib/rooter/connect/failover.sh new file mode 100644 index 0000000..68d7052 --- /dev/null +++ b/rooter-builds/ext-rooter4/files/usr/lib/rooter/connect/failover.sh @@ -0,0 +1,188 @@ +#!/bin/sh +. /lib/functions.sh + +ROOTER=/usr/lib/rooter + +log() { + logger -t "Failover System" "$@" +} + +log "Failover System is Started" + +ifname1="ifname" +if [ -e /etc/newstyle ]; then + ifname1="device" +fi + +i=1 +STAT="0" +track_ips= +WAN_STATUS="0" +MODEM_STATUS="0" +MODEM_IFUP=true +rm -f /tmp/wanstatus +rm -f /tmp/modemstatus +rm -f /tmp/mdown$CURRMODEM + +get_interface() { + OX=$1 + case $OX in + "Wan" ) + inter="wan" + ;; + "Hotspot" ) + inter="wwan" + ;; + * ) + inter="wan${OX:5}" + ;; + esac + uci set failover.$OX.interface=$inter +} + +ping_interface() { + interf=$(uci get failover.$1.interface) + if [ $interf = "wwan" ]; then + IFN="$(ubus -S call network.wireless status | jsonfilter -e '@.*.interfaces[@.config.mode="sta"].${ifname1}')" + else + IFN=$(uci get network.$interf.${ifname1}) + fi + if [ ! -z $IFN ]; then + STAT="1" + host_up_count=0 + score_up=$UP + score_dwn=$DOWN + lost=0 + while true; do + if [ ! -z "$track_ips" ]; then + for track_ip in $track_ips; do + ping -I $IFN -c $COUNT -W $TIMEOUT -s 4 -q $track_ip &> /dev/null + if [ $? -eq 0 ]; then + let host_up_count++ + else + let lost++ + fi + done + if [ $host_up_count -lt $RELIAB ]; then + let score_dwn-- + score_up=$UP + if [ $score_dwn -eq 0 ]; then + STAT="1" + break + fi + else + let score_up-- + score_dwn=$DOWN + if [ $score_up -eq 0 ]; then + STAT="2" + break + fi + fi + else + log "No Tracking IP, stopping Failover" + exit + fi + host_up_count=0 + sleep $INTERVAL + done + else + STAT="0" + fi +} + +make_status() { + name=$2 + status=$3 + interface=$(uci get failover.$name.interface) + echo "$name" > /tmp/$1"status" + echo "$interface" >> /tmp/$1"status" + case $status in + "0" ) + echo "disabled" >> /tmp/$1"status" + ;; + "1" ) + echo "offline" >> /tmp/$1"status" + ;; + "2" ) + echo "online" >> /tmp/$1"status" + ;; + "3" ) + echo "onlinedwn" >> /tmp/$1"status" + ;; + esac +} + +list_track_ips() { + track_ips="$1 $track_ips" +} + +rm -f /tmp/wanstatus +rm -f /tmp/modemstatus + +config_load failover +config_list_foreach "failover" "trackip" list_track_ips + +use_wan=$(uci get failover.faillist.use_wan) +get_interface $use_wan +use_modem=$(uci get failover.faillist.use_modem) +get_interface $use_modem +uci commit failover + +interf=$(uci get failover.$use_wan.interface) +uci set network.$interf.metric="99" +uci commit network +ifup $interf + +TIMEOUT=$(uci get failover.failover.pingwait) +INTERVAL=$(uci get failover.failover.pingtime) +RELIAB=$(uci get failover.failover.reliability) +DOWN=$(uci get failover.failover.down) +UP=$(uci get failover.failover.up) +COUNT=$(uci get failover.failover.count) + +while true; do + use_wan=$(uci get failover.faillist.use_wan) + use_modem=$(uci get failover.faillist.use_modem) + ping_interface $use_wan + make_status "wan" $use_wan $STAT + WAN_STATUS=$STAT + if [ $WAN_STATUS = "2" ];then + if [ $MODEM_IFUP = true -a $MODEM_STATUS == "2" ]; then + MODEM_IFUP=false + MODEM_STATUS="3" + ifdown $(uci get failover.$use_modem.interface) + fi + else + if [ $MODEM_IFUP = false -a $MODEM_STATUS != "0" ]; then + MODEM_IFUP=true + MODEM_STATUS="2" + ifup $(uci get failover.$use_modem.interface) + sleep 10 + fi + fi + + if [ $MODEM_STATUS != "3" ]; then + ping_interface $use_modem + make_status "modem" $use_modem $STAT + MODEM_STATUS=$STAT + MODEM_IFUP=true + if [ $STAT = "1" ]; then + echo "0" > /tmp/mdown$CURRMODEM + else + rm -f /tmp/mdown$CURRMODEM + fi + else + interf=$(uci get failover.$use_modem.interface) + IFN=$(uci get network.$interf.${ifname1}) + if [ -z $IFN ]; then + MODEM_IFUP=false + make_status "modem" $use_modem "0" + MODEM_STATUS="0" + else + make_status "modem" $use_modem "3" + MODEM_STATUS="3" + MODEM_IFUP=false + fi + fi + sleep 10 +done diff --git a/rooter-builds/ext-rooter4/files/usr/lib/rooter/luci/failchk.sh b/rooter-builds/ext-rooter4/files/usr/lib/rooter/luci/failchk.sh new file mode 100644 index 0000000..5adcc0f --- /dev/null +++ b/rooter-builds/ext-rooter4/files/usr/lib/rooter/luci/failchk.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter + +log() { + logger -t "Failover Check" "$@" +} + +jkillall failover.sh +ENB=$(uci get failover.enabled.enabled) +if [ $ENB = "1" ]; then + if [ -e $ROOTER/connect/failover.sh ]; then + log "Restarting Failover System" + $ROOTER/connect/failover.sh & + fi +fi diff --git a/rooter-builds/ext-rooter8-vpn/Makefile b/rooter-builds/ext-rooter8-vpn/Makefile new file mode 100644 index 0000000..eafb5b5 --- /dev/null +++ b/rooter-builds/ext-rooter8-vpn/Makefile @@ -0,0 +1,36 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-rooter8-vpn +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-rooter8-vpn + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+luci +ext-rooter4 +bwmon \ + +luci-app-rootervpn +ext-wireguard + TITLE:=basic ROOter support for 8meg routers + PKGARCH:=all +endef + +define Package/ext-rooter8-vpn/description + basic ROOter support for 8meg routers +endef + + +define Build/Compile +endef + +define Package/ext-rooter8-vpn/install + $(CP) ./files/* $(1)/ + + +endef + +$(eval $(call BuildPackage,ext-rooter8-vpn)) diff --git a/rooter-builds/ext-rooter8-vpn/files/etc/flash8 b/rooter-builds/ext-rooter8-vpn/files/etc/flash8 new file mode 100644 index 0000000..c80ef7f --- /dev/null +++ b/rooter-builds/ext-rooter8-vpn/files/etc/flash8 @@ -0,0 +1 @@ +FLASH="8" diff --git a/rooter-builds/ext-rooterbcm16/Makefile b/rooter-builds/ext-rooterbcm16/Makefile new file mode 100644 index 0000000..e726380 --- /dev/null +++ b/rooter-builds/ext-rooterbcm16/Makefile @@ -0,0 +1,44 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-rooterbcm16 +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-rooterbcm16 + SECTION:=utils + CATEGORY:=ROOter + DEPENDS:=+luci +ext-rooter-basic +ext-logo \ + +luci-app-mwan3 +luci-app-dnsmasq-ipset \ + +luci-app-ddns +ddns-scripts \ + +luci-app-rootervpn +ext-wireguard \ + +webconsole +bwmon +464xlat \ + +ext-theme +luci-theme-argon +luci-theme-argondark \ + +luci-theme-tomato +ext-login \ + +ca-bundle +ca-certificates +libustream-wolfssl \ + +luci-app-ksmbd +usb-storage \ + +ext-p910nd +luci-app-sqm +kmod-sched-cake +luci-app-nft-qos \ + +ext-command +ext-speedtest +luci-app-guestwifi \ + +openvpn-easy-rsa +openvpn-openssl \ + +ext-extra +luci-app-wol \ + +usbmuxd +libusbmuxd-utils +libimobiledevice-utils +kmod-usb-net-ipheth \ + +qlog +luci-ssl +usbutils +openssl-util +irqbalance +ext-splashconfig \ + +nano +picocom +wpad +wget +qfirehose +luci-app-vpnbypass + TITLE:=ROOter support for 16meg and larger Broadcom routers w/o Hotspot Manager + PKGARCH:=all +endef + +define Package/ext-rooterbcm16/description + Helper scripts to enable ROOter on 16meg and larger Broadcom routers w/o Hotspot Manager +endef + + +define Build/Compile +endef + +$(eval $(call BuildPackage,ext-rooterbcm16)) diff --git a/rooter-extra/ext-netselect/Makefile b/rooter-extra/ext-netselect/Makefile new file mode 100644 index 0000000..17993e7 --- /dev/null +++ b/rooter-extra/ext-netselect/Makefile @@ -0,0 +1,33 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-netselect +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-netselect + SECTION:=utils + CATEGORY:=ROOter + SUBMENU:=Optional Applications + TITLE:=support for Network Selection + PKGARCH:=all +endef + +define Package/ext-netselect/description + Helper scripts to enable Network Selection +endef + + +define Build/Compile +endef + +define Package/ext-netselect/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,ext-netselect)) diff --git a/rooter-extra/ext-netselect/files/usr/lib/lua/luci/controller/netroam.lua b/rooter-extra/ext-netselect/files/usr/lib/lua/luci/controller/netroam.lua new file mode 100644 index 0000000..3a6f502 --- /dev/null +++ b/rooter-extra/ext-netselect/files/usr/lib/lua/luci/controller/netroam.lua @@ -0,0 +1,73 @@ +module("luci.controller.netroam", package.seeall) + +I18N = require "luci.i18n" +translate = I18N.translate + +function index() + entry({"admin", "modem", "netroam"}, template("netroam/netroam"), translate("Network Selection"), 39) + entry({"admin", "netroam", "getconnect"}, call("action_getconnect")) + entry({"admin", "netroam", "getscan"}, call("action_getscan")) + entry({"admin", "netroam", "connect"}, call("action_connect")) +end + +function action_getconnect() + local rv ={} + + connect = luci.model.uci.cursor():get("modem", "modem1", "connected") + rv['connected'] = connect + + luci.http.prepare_content("application/json") + luci.http.write_json(rv) +end + +function action_getscan() + local netw = {} + local netmc = {} + local netlong = {} + local netavail = {} + local rv ={} + + os.execute("/usr/lib/netroam/getcops.sh") + + file = io.open("/tmp/copseqxx", "r") + mfile = io.open("/tmp/copseqmc", "r") + lfile = io.open("/tmp/copseqlg", "r") + afile = io.open("/tmp/copseqav", "r") + if file ~= nil then + rv["data"] = "1" + indx = 0 + repeat + line = file:read("*line") + if line == nil then + break + end + mline = mfile:read("*line") + netw[indx] = line + netmc[indx] = mline + lline = lfile:read("*line") + netlong[indx] = lline + aline = afile:read("*line") + netavail[indx] = aline + indx = indx +1 + until 1 == 0 + rv['network'] = netw + rv['mccmnc'] = netmc + rv['long'] = netlong + rv['avail'] = netavail + rv['indx'] = tostring(indx) + file:close() + mfile:close() + lfile:close() + afile:close() + else + rv["data"] = "0" + end + + luci.http.prepare_content("application/json") + luci.http.write_json(rv) +end + +function action_connect() + local set = luci.http.formvalue("set") + os.execute("/usr/lib/netroam/doconnect.sh " .. set) +end \ No newline at end of file diff --git a/rooter-extra/ext-netselect/files/usr/lib/lua/luci/view/netroam/netroam.htm b/rooter-extra/ext-netselect/files/usr/lib/lua/luci/view/netroam/netroam.htm new file mode 100644 index 0000000..4306737 --- /dev/null +++ b/rooter-extra/ext-netselect/files/usr/lib/lua/luci/view/netroam/netroam.htm @@ -0,0 +1,261 @@ +<%+header%> + + + +
+
+

<%:Network Selection%>

+
+ + + +
+ <%:Scanning%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +<%+footer%> \ No newline at end of file diff --git a/rooter-extra/ext-netselect/files/usr/lib/netroam/compress.lua b/rooter-extra/ext-netselect/files/usr/lib/netroam/compress.lua new file mode 100644 index 0000000..192152b --- /dev/null +++ b/rooter-extra/ext-netselect/files/usr/lib/netroam/compress.lua @@ -0,0 +1,136 @@ +#!/usr/bin/lua + +function trim(s) + return (s:gsub("^%s*(.-)%s*$", "%1")) +end + +lang = trim(arg[1]) +copseq = "/tmp/copseq" +netw = {} +netwa = {} +long = {} +mccmnc = {} +freq = {} +germ = 0 + +file = io.open(copseq, "r") +i = 0 +repeat + line = file:read("*line") + if line == nil then + break + end + if line == "2" then + if lang == "de" then + netw[i] = "( Aktuelles Netzwerk )" + else + netw[i] = "( Current Network )" + end + end + if line == "1" then + if lang == "de" then + netw[i] = "( Verfügbares Netzwerk )" + else + netw[i] = "( Availible Network )" + end + end + if line == "3" then + if lang == "de" then + netw[i] = "( Verbotenes Netzwerk )" + else + netw[i] = "( Forbidden Network )" + end + end + if line == "0" then + if lang == "de" then + netw[i] = "( Unbekanntes Netzwerk )" + else + netw[i] = "( Unknown Network )" + end + end + netwa[i] = line + line = file:read("*line") + long[i] = line + line = file:read("*line") + line = file:read("*line") + mccmnc[i] = line + line = file:read("*line") + freq[i] = line + i = i + 1 +until 1==0 +file:close() +maxlen = 0 +for j = 0, i-1 do + nlen = string.len(long[j]) + if nlen > maxlen then + maxlen = nlen + end +end +for j = 0, i-1 do + name = long[j] .. " " + long[j] = string.sub(name, 1, maxlen + 1) +end +list = 0 +netfnd = {} +netmcc = {} +netfreq = {} +netavail = {} +netlong = {} +for j = 0, i-1 do + if list == 0 then + netfnd[list] = long[j] .. netw[j] .. " " + netmcc[list] = mccmnc[j] + netfreq[list] = freq[j] + netavail[list] = netwa[j] + netlong[list] = long[j] + list = list + 1 + else + match = 0 + for k = 0, list-1 do + if mccmnc[j] == netmcc[k] then + match = 1 + indx = k + break + end + end + if match == 1 then + k = indx + if netfreq[k] == "7" and freq[j] == "2" then + netfreq[k] = "9" + end + if netfreq[k] == "2" and freq[j] == "7" then + netfreq[k] = "9" + end + else + netfnd[list] = long[j] .. netw[j] .. " " + netmcc[list] = mccmnc[j] + netfreq[list] = freq[j] + netavail[list] = netwa[j] + netlong[list] = long[j] + list = list + 1 + end + end +end +tfile = io.open(copseq .. "xx", "w") +file = io.open(copseq .. "mc", "w") +lfile = io.open(copseq .. "lg", "w") +afile = io.open(copseq .. "av", "w") +for k = 0, list-1 do + if netfreq[k] == "9" then + netfnd[k] = netfnd[k] .. "3G/LTE MCC/MNC - " .. string.sub(netmcc[k], 1, 3) .. " " .. string.sub(netmcc[k], 4) + end + if netfreq[k] == "2" then + netfnd[k] = netfnd[k] .. "3G MCC/MNC - " .. string.sub(netmcc[k], 1, 3) .. " " .. string.sub(netmcc[k], 4) + end + if netfreq[k] == "7" then + netfnd[k] = netfnd[k] .. "LTE MCC/MNC - " .. string.sub(netmcc[k], 1, 3) .. " " .. string.sub(netmcc[k], 4) + end + tfile:write(netfnd[k], "\n") + file:write(netmcc[k], "\n") + lfile:write(netavail[k], "\n") + afile:write(netlong[k], "\n") +end +tfile:close() +file:close() +lfile:close() +afile:close() \ No newline at end of file diff --git a/rooter-extra/ext-netselect/files/usr/lib/netroam/doconnect.sh b/rooter-extra/ext-netselect/files/usr/lib/netroam/doconnect.sh new file mode 100644 index 0000000..4fe18ab --- /dev/null +++ b/rooter-extra/ext-netselect/files/usr/lib/netroam/doconnect.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + logger -t "ROAM" "$@" +} + +mccmnc=$1 + +log "Disconnect modem" + +CURRMODEM=1 +uci set modem.modem$CURRMODEM.connected=0 +uci commit modem +INTER=$(uci get modem.modeminfo$CURRMODEM.inter) + +jkillall getsignal$CURRMODEM +rm -f $ROOTER_LINK/getsignal$CURRMODEM +jkillall con_monitor$CURRMODEM +rm -f $ROOTER_LINK/con_monitor$CURRMODEM +ifdown wan$INTER + +PROT=$(uci get modem.modem$CURRMODEM.proto) +CPORT=$(uci get modem.modem$CURRMODEM.commport) + +case $PROT in +"30" ) + ATCMDD="AT+CFUN=0" + $ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD" + ;; +"3" ) + WDMNX=$(uci get modem.modem$CURRMODEM.wdm) + umbim -n -t 3 -d /dev/cdc-wdm$WDMNX disconnect + ;; +* ) + $ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "reset.gcom" "$CURRMODEM" + ;; +esac + +log "Lock to network" + +mcc=${mccmnc:0:3} +mnc=${mccmnc:3} + +ATCMDD="AT+COPS=1,2,\"$mccmnc\",7" +echo "ATCMDD=\"$ATCMDD\"" > /tmp/rlock + +log "Reconnect Modem" + +$ROOTER_LINK/create_proto$CURRMODEM $CURRMODEM 1 & + diff --git a/rooter-extra/ext-netselect/files/usr/lib/netroam/getcops.sh b/rooter-extra/ext-netselect/files/usr/lib/netroam/getcops.sh new file mode 100644 index 0000000..e420c74 --- /dev/null +++ b/rooter-extra/ext-netselect/files/usr/lib/netroam/getcops.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + logger -t "ROAM" "$@" +} + +CURRMODEM=1 +CPORT=$(uci get modem.modem$CURRMODEM.commport) +connect=$(uci get modem.modem$CURRMODEM.connected) +if [ "$connect" != "1" ]; then + exit 0 +fi + +ATCMDD="AT+COPS=?" +#export TIMEOUT="120" +OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") +#export TIMEOUT="5" +OX=$(echo "$OX " | sed -e "s!+COPS: !+COPS:,!g") +OX=$(echo "$OX" | grep "+COPS:") +if [ -z "$OX" ]; then + rm -f /tmp/copseq + exit 0 +fi + +CNT=2 +rm -f /tmp/copseq +while [ true ]; do + CCNT=$CNT + AVAIL=$(echo $OX | cut -d, -f$CCNT) + NXT=$(echo "$AVAIL" | grep "(") + if [ ! -z "$NXT" ]; then + AVAIL="${AVAIL#(}" + let "CCNT=$CCNT+1" + LONG=$(echo $OX | cut -d, -f$CCNT) + temp="${LONG%\"}" + LONG="${temp#\"}" + let "CCNT=$CCNT+1" + SHORT=$(echo $OX | cut -d, -f$CCNT) + temp="${SHORT%\"}" + SHORT="${temp#\"}" + let "CCNT=$CCNT+1" + NUMER=$(echo $OX | cut -d, -f$CCNT) + temp="${NUMER%\"}" + NUMER="${temp#\"}" + let "CCNT=$CCNT+1" + ACT=$(echo $OX | cut -d, -f$CCNT) + ACT="${ACT%)}" + echo "$AVAIL" >> /tmp/copseq + echo "$LONG" >> /tmp/copseq + echo "$SHORT" >> /tmp/copseq + echo "$NUMER" >> /tmp/copseq + echo "$ACT" >> /tmp/copseq + let "CNT=$CCNT+1" + else + break + fi +done +lang=$(uci -q get luci.main.lang) +/usr/lib/netroam/compress.lua $lang diff --git a/rooter-extra/ext-netselect/files/usr/lib/netroam/lock.sh b/rooter-extra/ext-netselect/files/usr/lib/netroam/lock.sh new file mode 100644 index 0000000..49bcc03 --- /dev/null +++ b/rooter-extra/ext-netselect/files/usr/lib/netroam/lock.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + logger -t "ROAM" "$@" +} + +CURRMODEM=$1 +CPORT=$(uci get modem.modem$CURRMODEM.commport) + +if [ -e /tmp/rlock ]; then + source /tmp/rlock + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + log "$OX" + rm -f /tmp/rlock +fi \ No newline at end of file diff --git a/rooter-extra/ext-simplegps/Makefile b/rooter-extra/ext-simplegps/Makefile new file mode 100644 index 0000000..88e3924 --- /dev/null +++ b/rooter-extra/ext-simplegps/Makefile @@ -0,0 +1,34 @@ +#Owned by DairyMan@Whirlpool +# +#Copyright GNU act. +include $(TOPDIR)/rules.mk + +PKG_NAME:=ext-simplegps +PKG_VERSION:=1.000 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Created by DM/makefile by Cobia@whirlpool +include $(INCLUDE_DIR)/package.mk + +define Package/ext-simplegps + SECTION:=utils + CATEGORY:=ROOter + SUBMENU:=Optional Applications + DEPENDS:=+msmtp + TITLE:=support for gps + PKGARCH:=all +endef + +define Package/ext-simplegps/description + Helper scripts to enable gps +endef + + +define Build/Compile +endef + +define Package/ext-simplegps/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,ext-simplegps)) diff --git a/rooter-extra/ext-simplegps/files/etc/havegps b/rooter-extra/ext-simplegps/files/etc/havegps new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/rooter-extra/ext-simplegps/files/etc/havegps @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/rooter-extra/ext-simplegps/files/usr/lib/gps/convert.lua b/rooter-extra/ext-simplegps/files/usr/lib/gps/convert.lua new file mode 100644 index 0000000..c4101fc --- /dev/null +++ b/rooter-extra/ext-simplegps/files/usr/lib/gps/convert.lua @@ -0,0 +1,26 @@ +#!/usr/bin/lua + +ldeg = arg[1] +lmin = arg[2] +lsecd = arg[3] +lhemi = arg[4] +sect = arg[5] + +lmin = lmin / 60 +if sect == nil then + lsecd = (lsecd * 6) /1000 +end +lsec = lsecd / 3600 +ldegree = ldeg + lmin + lsec +if lhemi == "S" then + ldegree = -ldegree +end +if lhemi == "W" then + ldegree = -ldegree +end + +sdeg = string.format("%.4f",ldegree) + +local tfile = io.open("/tmp/latlon", "w") +tfile:write("CONVERT=\"", sdeg, "\"") +tfile:close() \ No newline at end of file diff --git a/rooter-extra/ext-simplegps/files/usr/lib/gps/gps.sh b/rooter-extra/ext-simplegps/files/usr/lib/gps/gps.sh new file mode 100644 index 0000000..b6e6bb7 --- /dev/null +++ b/rooter-extra/ext-simplegps/files/usr/lib/gps/gps.sh @@ -0,0 +1,75 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + logger -t "GPS" "$@" +} + +ifname1="ifname" +if [ -e /etc/newstyle ]; then + ifname1="device" +fi + +chksierra() { + SIERRAID=0 + if [ $idV = 1199 ]; then + case $idP in + "68aa"|"68a2"|"68a3"|"68a9"|"68b0"|"68b1" ) + SIERRAID=1 + ;; + "68c0"|"9040"|"9041"|"9051"|"9054"|"9056"|"90d3" ) + SIERRAID=1 + ;; + "9070"|"907b"|"9071"|"9079"|"901c"|"9091"|"901f"|"90b1" ) + SIERRAID=1 + ;; + esac + elif [ $idV = 114f -a $idP = 68a2 ]; then + SIERRAID=1 + elif [ $idV = 413c -a $idP = 81a8 ]; then + SIERRAID=1 + elif [ $idV = 413c -a $idP = 81b6 ]; then + SIERRAID=1 + fi +} + +CURRMODEM=$1 +idV=$(uci -q get modem.modem$CURRMODEM.idV) +idP=$(uci -q get modem.modem$CURRMODEM.idP) +CPORT=$(uci get modem.modem$CURRMODEM.commport) + +log "Running GPS script" + +QUECTEL=false +if [ "$idV" = "2c7c" ]; then + QUECTEL=true +elif [ "$idV" = "05c6" ]; then + QUELST="9090,9003,9215" + if [[ $(echo "$QUELST" | grep -o "$idP") ]]; then + QUECTEL=true + fi +fi +if $QUECTEL; then + if [ -e /usr/lib/gps/quectel.sh ]; then + result=`ps | grep -i "quectel.sh" | grep -v "grep" | wc -l` + if [ $result -lt 1 ]; then + /usr/lib/gps/quectel.sh $CURRMODEM & + fi + fi + return +fi + +chksierra +if [ $SIERRAID -eq 1 ]; then + if [ -e /usr/lib/gps/sierra.sh ]; then + result=`ps | grep -i "sierra.sh" | grep -v "grep" | wc -l` + if [ $result -lt 1 ]; then + /usr/lib/gps/sierra.sh $CURRMODEM & + fi + fi + return +fi + + diff --git a/rooter-extra/ext-simplegps/files/usr/lib/gps/gpskill.sh b/rooter-extra/ext-simplegps/files/usr/lib/gps/gpskill.sh new file mode 100644 index 0000000..ff1a140 --- /dev/null +++ b/rooter-extra/ext-simplegps/files/usr/lib/gps/gpskill.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +CURRMODEM=$1 +ROOTER=/usr/lib/rooter +CPORT=$(uci get modem.modem$CURRMODEM.commport) +PID=$(ps | grep "[q]uectel.sh $CURRMODEM" | awk '{print $1}') +if [ -n "$PID" ]; then + kill -9 $PID + ATCMDD="AT+QGPSEND" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + rm -f /tmp/gps + rm -f /tmp/gpsdata + rm -f /tmp/gpsdata1 +fi +PID=$(ps | grep "[s]ierra.sh $CURRMODEM" | awk '{print $1}') +if [ -n "$PID" ]; then + kill -9 $PID + ATCMDD="AT!GPSEND=0" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + rm -f /tmp/gps + rm -f /tmp/gpsdata + rm -f /tmp/gpsdata1 +fi diff --git a/rooter-extra/ext-simplegps/files/usr/lib/gps/processq.sh b/rooter-extra/ext-simplegps/files/usr/lib/gps/processq.sh new file mode 100644 index 0000000..56e629b --- /dev/null +++ b/rooter-extra/ext-simplegps/files/usr/lib/gps/processq.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + logger -t "Quectel GPS" "$@" +} + +OX=$1 + +if [ -z "$OX" ]; then + if [ -e /tmp/lastgps ]; then + OX=$(cat /tmp/lastgps) + else + exit 0 + fi +else + OX=$(cat /tmp/gpsox) + echo "$OX" > /tmp/lastgps +fi + +O=$(echo "$OX" | grep "+QGPSLOC:") +if [ -z "$O" ]; then + exit 0 +fi +OX=$(echo $O" " | tr ":" ",") + +LAT=$(echo $OX | cut -d, -f3) +LON=$(echo $OX | cut -d, -f4) + +llen=$(expr length "$LAT") +if [ $llen -eq 10 ]; then + LAT="0"$LAT +fi +if [ $llen -eq 9 ]; then + LAT="00"$LAT +fi +llen=$(expr length "$LON") +if [ $llen -eq 10 ]; then + LON="0"$LON +fi +if [ $llen -eq 9 ]; then + LON="00"$LON +fi + +latdeg=${LAT:0:3} +latmin=${LAT:3:2} +latsec=${LAT:6:4} +lathemi=${LAT:10:1} +londeg=${LON:0:3} +lonmin=${LON:3:2} +lonsec=${LON:6:4} +lonhemi=${LON:10:1} +lathemid=$lathemi +lonhemid=$lonhemi + +let "latsecd=$latsec*6/1000" +let "lonsecd=$lonsec*6/1000" + +latdeg="${latdeg#"${latdeg%%[!0]*}"}" +latmin="${latmin#"${latmin%%[!0]*}"}" +if [ $lathemi = "S" ]; then + lathemi="South" +else + lathemi="North" +fi +delatitude=$latdeg" Deg "$latmin" Min "$latsecd" Sec "$lathemi +if [ $lonhemi = "E" ]; then + lonhemi="East" +else + lonhemi="West" +fi +londeg="${londeg#"${londeg%%[!0]*}"}" +lonmin="${lonmin#"${lonmin%%[!0]*}"}" +delongitude=$londeg" Deg "$lonmin" Min "$lonsecd" Sec "$lonhemi +/usr/lib/gps/convert.lua $latdeg $latmin $latsec $lathemid +source /tmp/latlon +dlatitude=$CONVERT +/usr/lib/gps/convert.lua $londeg $lonmin $lonsec $lonhemid +source /tmp/latlon +dlongitude=$CONVERT + +lat="$delatitude ( $dlatitude )" +long="$delongitude ( $dlongitude )" +echo 'LATITUDE="'"$lat"'"' >> /tmp/gpsdata +echo 'LONGITUDE="'"$long"'"' >> /tmp/gpsdata + +echo "$lat" > /tmp/gpsdata1 +echo "$long" >> /tmp/gpsdata1 + +echo "0" > /tmp/gps \ No newline at end of file diff --git a/rooter-extra/ext-simplegps/files/usr/lib/gps/processs.sh b/rooter-extra/ext-simplegps/files/usr/lib/gps/processs.sh new file mode 100644 index 0000000..a586368 --- /dev/null +++ b/rooter-extra/ext-simplegps/files/usr/lib/gps/processs.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + logger -t "Quectel GPS" "$@" +} + +OX=$1 + +if [ -z "$OX" ]; then + if [ -e /tmp/lastgps ]; then + OX=$(cat /tmp/lastgps) + else + exit 0 + fi +else + OX=$(cat /tmp/gpsox) + echo "$OX" > /tmp/lastgps +fi + +O=$(echo "$OX" | grep "at!gpsloc?") +if [ -z "$O" ]; then + exit 0 +fi + +CURRMODEM=1 +CPORT=$(uci get modem.modem$CURRMODEM.commport) +ATCMDD="at!gpssatinfo?" +OY=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") +echo "$OY" > /tmp/satgps +Y=$(cat /tmp/satgps) +OY=$(echo $Y" " | tr " " ",") + + +OX=$(echo $OX" " | tr " " ",") +LATD=$(echo $OX | cut -d, -f3) +LATM=$(echo $OX | cut -d, -f5) +LATS=$(echo $OX | cut -d, -f7) +LATH=$(echo $OX | cut -d, -f9) + +LOND=$(echo $OX | cut -d, -f12) +LONM=$(echo $OX | cut -d, -f14) +LONS=$(echo $OX | cut -d, -f16) +LONH=$(echo $OX | cut -d, -f18) +lathemid=$LATH +lonhemid=$LONH + +if [ $LATH = "S" ]; then + LATH="South" +else + LATH="North" +fi +if [ $LONH = "E" ]; then + LONH="East" +else + LONH="West" +fi +delatitude=$LATD" Deg "$LATM" Min "$LATS" Sec "$LATH +delongitude=$LOND" Deg "$LONM" Min "$LONS" Sec "$LONH +/usr/lib/gps/convert.lua $LATD $LATM $LATS $lathemid 1 +source /tmp/latlon +dlatitude=$CONVERT +/usr/lib/gps/convert.lua $LOND $LONM $LONS $lonhemid 1 +source /tmp/latlon +dlongitude=$CONVERT + +lat="$delatitude ( $dlatitude )" +long="$delongitude ( $dlongitude )" +echo 'LATITUDE="'"$lat"'"' >> /tmp/gpsdata +echo 'LONGITUDE="'"$long"'"' >> /tmp/gpsdata + +echo "$lat" > /tmp/gpsdata1 +echo "$long" >> /tmp/gpsdata1 + +echo "0" > /tmp/gps diff --git a/rooter-extra/ext-simplegps/files/usr/lib/gps/quectel.sh b/rooter-extra/ext-simplegps/files/usr/lib/gps/quectel.sh new file mode 100644 index 0000000..ce82c54 --- /dev/null +++ b/rooter-extra/ext-simplegps/files/usr/lib/gps/quectel.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + logger -t "Quectel GPS" "$@" +} + +ifname1="ifname" +if [ -e /etc/newstyle ]; then + ifname1="device" +fi + +CURRMODEM=$1 +if [ $CURRMODEM = "2" ]; then + exit 0 +fi +CPORT=$(uci get modem.modem$CURRMODEM.commport) +rm -f /tmp/gps +rm -f /tmp/lastgps +if [ -z "$CPORT" ]; then + exit 0 +fi + +ATCMDD="AT+QGPS?" +OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") +err=$(echo "$OX" | grep "+QGPS: 1") +if [ -z "$err" ]; then + ATCMDD="AT+QGPS=1" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") +fi + +log "GPS setup and waiting" + +ATCMDD="AT+QCFG=\"gpsdrx\"" +OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") +err=$(echo "$OX" | grep "0") +if [ -n "$err" ]; then + ATCMDD="AT+QCFG=\"gpsdrx\",1" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") +fi +ATCMDD="AT+QGPSCFG=\"outport\",\"none\"" +OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + +while true; do + refresh=30 + ATCMDD="AT+QGPSLOC=0" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + err=$(echo "$OX" | grep "ERROR") + if [ -z "$err" ]; then + echo "$OX" > /tmp/gpsox + result=`ps | grep -i "processq.sh" | grep -v "grep" | wc -l` + if [ $result -lt 1 ]; then + /usr/lib/gps/processq.sh 1 + fi + sleep $refresh + else + sleep 5 + fi +done diff --git a/rooter-extra/ext-simplegps/files/usr/lib/gps/sierra.sh b/rooter-extra/ext-simplegps/files/usr/lib/gps/sierra.sh new file mode 100644 index 0000000..3da42d0 --- /dev/null +++ b/rooter-extra/ext-simplegps/files/usr/lib/gps/sierra.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + logger -t "Sierra GPS" "$@" +} + +ifname1="ifname" +if [ -e /etc/newstyle ]; then + ifname1="device" +fi + +CURRMODEM=$1 +CPORT=$(uci get modem.modem$CURRMODEM.commport) +rm -f /tmp/gps +rm -f /tmp/lastgps +if [ -z "$CPORT" ]; then + exit 0 +fi + +ATCMDD="AT!CUSTOM?" +OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + +GPSsel=$(echo $OX | grep "GPSSEL") +GPSenable=$(echo $OX | grep "GPSENABLE") +if [ -z "$GPSsel" -o -z "$GPSenable" ]; then + ATCMDD="AT!ENTERCND=\"A710\"" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + if [ -z "$GPSsel" ]; then + ATCMDD="at!custom=\"GPSSEL\",1" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + fi + if [ -z "$GPSenable" ]; then + ATCMDD="at!custom=\"GPSENABLE\",1" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + ATCMDD="AT+CFUN=0;+CFUN=1,1" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + exit + fi + ATCMDD="AT!ENTERCND=\"AWRONG\"" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") +fi + +ATCMDD="AT!GPSTRACK=1,240,30,1000,5" +OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + +while true; do + refresh=30 + ATCMDD="at!gpsloc?" + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + err=$(echo "$OX" | grep "Not Available") + if [ -z "$err" ]; then + echo "$OX" > /tmp/gpsox + result=`ps | grep -i "processs.sh" | grep -v "grep" | wc -l` + if [ $result -lt 1 ]; then + /usr/lib/gps/processs.sh 1 + fi + sleep $refresh + else + sleep 5 + fi +done diff --git a/rooter-extra/mesh11sd/Makefile b/rooter-extra/mesh11sd/Makefile new file mode 100644 index 0000000..567e06d --- /dev/null +++ b/rooter-extra/mesh11sd/Makefile @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# Copyright (C) 2022 BlueWave Projects and Services +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=mesh11sd +PKG_VERSION:=1.2.0 +PKG_RELEASE:=$(AUTORELEASE) + +PKG_MAINTAINER:=Rob White +PKG_LICENSE:=GPL-2.0-or-later +PKG_LICENSE_FILES:=LICENSE + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/opennds/mesh11sd/tar.gz/v$(PKG_VERSION)? +PKG_HASH:=b719eaacf63eb3684d0cd6a026f4357a4f400f2339f5d5a6cf74ba3744fe30d8 +PKG_BUILD_DIR:=$(BUILD_DIR)/mesh11sd-$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk + +define Package/mesh11sd + SUBMENU:=Captive Portals + SECTION:=net + CATEGORY:=Network + TITLE:=Dynamic 802.11s Mesh Configuration Daemon + PKGARCH:=all + URL:=https://github.com/opennds/mesh11sd +endef + +define Package/mesh11sd/description + Mesh11sd is a dynamic parameter configuration daemon for 802.11s mesh networks. + It was originally designed to leverage 802.11s mesh networking at Captive Portal venues. + This is the open source version and it enables easy and automated mesh network operation with multiple mesh nodes. + It allows all mesh parameters supported by the wireless driver to be set in the uci config file. + Settings take effect immediately without having to restart the wireless network. + Default settings give rapid and reliable layer 2 mesh convergence. + Without mesh11sd, many mesh parameters cannot be set in the uci wireless config file as the mesh interface must be up before the parameters can be set. + Some of those that are supported, would fail to be implemented when the network is (re)started resulting in errors or dropped nodes. + The mesh11sd daemon dynamically checks configured parameters and sets them as required. + This version does not require a Captive Portal to be running. +endef + +define Package/mesh11sd/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/mesh11sd $(1)/usr/sbin + $(INSTALL_CONF) $(PKG_BUILD_DIR)/linux_openwrt/mesh11sd/files/etc/config/mesh11sd $(1)/etc/config/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/linux_openwrt/mesh11sd/files/etc/init.d/mesh11sd $(1)/etc/init.d/ +endef + +define Package/mesh11sd/conffiles +/etc/config/mesh11sd +endef + +define Build/Compile +endef + +$(eval $(call BuildPackage,mesh11sd)) diff --git a/rooter-extra/speedtestpp/Makefile b/rooter-extra/speedtestpp/Makefile new file mode 100644 index 0000000..06fa629 --- /dev/null +++ b/rooter-extra/speedtestpp/Makefile @@ -0,0 +1,42 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=speedtestpp +PKG_VERSION:=1.14 +PKG_RELEASE:=$(AUTORELEASE) + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://github.com/taganaka/SpeedTest.git +PKG_SOURCE_DATE:=2021-12-06 +PKG_SOURCE_VERSION:=0f63cfbf7ce8d64ea803bf143b957eae76323405 +PKG_MIRROR_HASH:=4221584dc3e1e31f2560ef347298a2bcca3ac2331049970b7bd7d742e4e1825f + +PKG_MAINTAINER:=Oskari Rauta +PKG_LICENSE:=MIT + +CMAKE_INSTALL:=1 + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/nls.mk +include $(INCLUDE_DIR)/cmake.mk + +CMAKE_OPTIONS += -DCMAKE_BUILD_TYPE=Release . + +define Package/speedtestpp + SECTION:=net + CATEGORY:=Network + TITLE:=speedtest++ + DEPENDS:=+libcurl +libxml2 +libopenssl +libstdcpp $(ICONV_DEPENDS) + CONFLICTS:=python3-speedtest-cli + URL:=https://github.com/taganaka/SpeedTest +endef + +define Package/speedtestpp/description + Yet another unofficial speedtest.net client cli interface +endef + +define Package/speedtestpp/install + $(INSTALL_DIR) $(1)/usr/bin + $(CP) $(PKG_INSTALL_DIR)/usr/bin/SpeedTest $(1)/usr/bin/speedtest +endef + +$(eval $(call BuildPackage,speedtestpp)) diff --git a/rooter/0basicapps/ext-extra/files/usr/lib/rooter/luci/reboot.sh b/rooter/0basicapps/ext-extra/files/usr/lib/rooter/luci/reboot.sh index eac8962..68bbee7 100644 --- a/rooter/0basicapps/ext-extra/files/usr/lib/rooter/luci/reboot.sh +++ b/rooter/0basicapps/ext-extra/files/usr/lib/rooter/luci/reboot.sh @@ -24,7 +24,7 @@ if [ $PARM = "1" ]; then let "TH = $HOUR * 4" let "TMP1 = $SDHOUR - $TH" let "MIN = $TMP1 * 15" - echo "$MIN $HOUR * * * sleep 70 && touch /etc/banner && reboot -f" > /etc/cronbase + echo "$MIN $HOUR * * * sleep 70 && touch /etc/banner && /usr/lib/rooter/luci/rebootmodem.sh" > /etc/cronbase else rm -f /etc/cronbase fi diff --git a/rooter/0basicapps/usb-storage/files/usr/lib/sdcard/sdcard.sh b/rooter/0basicapps/usb-storage/files/usr/lib/sdcard/sdcard.sh index 257d915..180c7ab 100644 --- a/rooter/0basicapps/usb-storage/files/usr/lib/sdcard/sdcard.sh +++ b/rooter/0basicapps/usb-storage/files/usr/lib/sdcard/sdcard.sh @@ -1,7 +1,7 @@ #!/bin/sh log() { - logger -t "sdcard" "$@" + modlog "sdcard" "$@" } h721() { @@ -16,62 +16,45 @@ h721() { fi } -wg1608() { +ws1208() { if [ $1 = "add" ]; then - echo timer > /sys/class/leds/zbt-wg3526:green:signal/trigger - echo 1000 > /sys/class/leds/zbt-wg3526:green:signal/delay_on - echo 0 > /sys/class/leds/zbt-wg3526:green:signal/delay_off + echo none > /sys/class/leds/usb/trigger + echo 1 > /sys/class/leds/usb/brightness else - echo timer > /sys/class/leds/zbt-wg3526:green:signal/trigger - echo 0 > /sys/class/leds/zbt-wg3526:green:signal/delay_on - echo 1000 > /sys/class/leds/zbt-wg3526:green:signal/delay_off - fi -} - -ws7915() { - if [ $1 = "add" ]; then - echo timer > /sys/class/leds/sys/trigger - echo 1000 > /sys/class/leds/sys/delay_on - echo 0 > /sys/class/leds/sys/delay_off - else - echo timer > /sys/class/leds/sys/trigger - echo 0 > /sys/class/leds/sys/delay_on - echo 1000 > /sys/class/leds/sys/delay_off + echo none > /sys/class/leds/usb/trigger + echo 0 > /sys/class/leds/usb/brightness fi } ws1688() { if [ $1 = "add" ]; then - echo timer > /sys/class/leds/usb/trigger - echo 1000 > /sys/class/leds/usb/delay_on - echo 0 > /sys/class/leds/usb/delay_off + echo none > /sys/class/leds/usb/trigger + echo 1 > /sys/class/leds/usb/brightness else - echo timer > /sys/class/leds/usb/trigger - echo 0 > /sys/class/leds/usb/delay_on - echo 1000 > /sys/class/leds/usb/delay_off + echo none > /sys/class/leds/usb/trigger + echo 0 > /sys/class/leds/usb/brightness fi } ACTION=$1 model=$(cat /tmp/sysinfo/model) - case $ACTION in "add"|"remove" ) mod=$(echo $model | grep "H721") - if [ $mod ]; then + if [ ! -z "$mod" ]; then h721 $ACTION fi - mod=$(echo $model | grep "WG1608") - if [ $mod ]; then - wg1608 $ACTION + mod=$(echo $model | grep "WS1208V2") + if [ ! -z "$mod" ]; then + ws1208 $ACTION fi - mod=$(echo $model | grep "WS7915") - if [ $mod ]; then - ws7915 $ACTION + mod=$(echo $model | grep "WS1218") + if [ ! -z "$mod" ]; then + ws1208 $ACTION fi - + mod=$(echo $model | grep "WS1688") - if [ $mod ]; then + if [ ! -z "$mod" ]; then ws1688 $ACTION fi ;; diff --git a/rooter/0basicsupport/ext-sms/files/usr/lib/lua/luci/controller/sms.lua b/rooter/0basicsupport/ext-sms/files/usr/lib/lua/luci/controller/sms.lua index aa9dc01..a610dd6 100644 --- a/rooter/0basicsupport/ext-sms/files/usr/lib/lua/luci/controller/sms.lua +++ b/rooter/0basicsupport/ext-sms/files/usr/lib/lua/luci/controller/sms.lua @@ -5,14 +5,14 @@ translate = I18N.translate function index() local fs = require "nixio.fs" - - - - if not fs.stat("/etc/nosms") then - local page - page = entry({"admin", "modem", "sms"}, template("rooter/sms"), translate("短信功能"), 35) - page.dependent = true - + local multilock = luci.model.uci.cursor():get("custom", "multiuser", "multi") or "0" + local rootlock = luci.model.uci.cursor():get("custom", "multiuser", "root") or "0" + if (multilock == "0") or (multilock == "1" and rootlock == "1") then + if not fs.stat("/etc/nosms") then + local page + page = entry({"admin", "modem", "sms"}, template("rooter/sms"), translate("SMS Messaging"), 35) + page.dependent = true + end end entry({"admin", "modem", "check_read"}, call("action_check_read")) @@ -21,6 +21,7 @@ function index() entry({"admin", "modem", "change_sms"}, call("action_change_sms")) entry({"admin", "modem", "change_smsdn"}, call("action_change_smsdn")) entry({"admin", "modem", "change_smsflag"}, call("action_change_smsflag")) + entry({"admin", "modem", "delall_sms"}, call("action_delall_sms")) end function trim(s) @@ -71,12 +72,16 @@ function action_send_sms() luci.http.write_json(rv) end +function action_delall_sms() + smsnum = luci.model.uci.cursor():get("modem", "general", "smsnum") + os.execute("/usr/lib/sms/delall.sh " .. smsnum) +end + function action_del_sms() - local set = tonumber(luci.http.formvalue("set")) - if set ~= nil and set > 0 then - set = set - 1; + local set = luci.http.formvalue("set") + if set ~= nil then smsnum = luci.model.uci.cursor():get("modem", "general", "smsnum") - os.execute("/usr/lib/sms/delsms.sh " .. smsnum .. " " .. set) + os.execute("/usr/lib/sms/delsms.sh " .. smsnum .. " " .. set) os.execute("touch /tmp/smswakeup" .. smsnum) end end @@ -122,7 +127,7 @@ function action_check_read() line = file:read("*line") full = full .. line if k < i then - full = full .. '
' + full = full .. '\n' end end else @@ -157,4 +162,3 @@ function action_change_smsflag() local set = tonumber(luci.http.formvalue("set")) os.execute("/usr/lib/sms/toggle.sh " .. set) end - diff --git a/rooter/0basicsupport/ext-sms/files/usr/lib/lua/luci/view/rooter/sms.htm b/rooter/0basicsupport/ext-sms/files/usr/lib/lua/luci/view/rooter/sms.htm index fda6d81..d266219 100644 --- a/rooter/0basicsupport/ext-sms/files/usr/lib/lua/luci/view/rooter/sms.htm +++ b/rooter/0basicsupport/ext-sms/files/usr/lib/lua/luci/view/rooter/sms.htm @@ -22,30 +22,30 @@ if ( ss == "0" ) { clearListBox("smsList"); - document.getElementById('message').innerHTML=""; + document.getElementById('message').value=""; document.getElementById('total').innerHTML=""; document.getElementById('used').innerHTML=""; document.getElementById('mslots').innerHTML=""; document.getElementById('menb').checked=false; - document.getElementById('supported').innerHTML="<%:模块未适配短信支持/未连接到模块%>"; + document.getElementById('supported').innerHTML="<%:SMS Not Supported/No Modem%>"; } if ( ss == "1" ) { clearListBox("smsList"); - document.getElementById('message').innerHTML=""; + document.getElementById('message').value=""; document.getElementById('total').innerHTML=""; document.getElementById('used').innerHTML=""; document.getElementById('mslots').innerHTML=""; document.getElementById('menb').checked=false; - document.getElementById('supported').innerHTML="<%:您有未读的短信,请前往查看%>"; + document.getElementById('supported').innerHTML="<%:Waiting to Read Messages%>"; } if ( ss == "3" ) { - document.getElementById('supported').innerHTML="<%:消息读取有问题%>"; + document.getElementById('supported').innerHTML="<%:Message Read Problem%>"; } if ( ss == "2" ) { - document.getElementById('supported').innerHTML="<%:存在的短信%>"; + document.getElementById('supported').innerHTML="<%:Messages Present%>"; clearListBox("smsList"); document.getElementById('total').innerHTML=rv.max; document.getElementById('used').innerHTML=rv.used; @@ -75,7 +75,7 @@ } if (rv.used == "0") { - document.getElementById('supported').innerHTML="<%:SIM卡上没有短信%>"; + document.getElementById('supported').innerHTML="<%:No Messages Present on SIM%>"; } else { @@ -86,7 +86,7 @@ var i; for(i=0;i"); + alert("<%:You must enter a phone number!!%>"); return false; } s = s.trim(); if ( isNaN(s) == true ) { - alert("<%:错误的电话号码!!%>"); + alert("<%:Invalid phone number!!%>"); return false; } var num = s.concat(" "); @@ -203,7 +203,7 @@ } num = num.concat(t); alert("<%:SMS will be queued for processing.\nA status update will follow.%>"); - document.getElementById("sstat").innerHTML="<%:状态 :消息正在发送%>"; + document.getElementById("sstat").innerHTML="<%:Sending Message. Please Wait%>"; XHR.get('<%=luci.dispatcher.build_url("admin", "modem", "send_sms")%>', { set: num }, function(x, rv) @@ -214,6 +214,92 @@ } ); } + + function readcheck() + { + XHR.get('<%=luci.dispatcher.build_url("admin", "modem", "check_read")%>', null, + function(x, rv) + { + var ss = rv.ready; + document.getElementById('message').style.color = "initial"; + document.getElementById('conntype').innerHTML=rv.conntype; + if ( ss == "1" ) + { + clearListBox("smsList"); + document.getElementById('message').value=""; + document.getElementById('total').innerHTML=""; + document.getElementById('used').innerHTML=""; + document.getElementById('supported').innerHTML="<%:Waiting to Read Messages%>"; + } + if ( ss == "3" ) + { + document.getElementById('supported').innerHTML="<%:Message Read Problem%>"; + } + if ( ss == "2" ) + { + document.getElementById('supported').innerHTML="<%:Messages Present%>"; + clearListBox("smsList"); + document.getElementById('total').innerHTML=rv.max; + document.getElementById('used').innerHTML=rv.used; + var line=rv.line; + var arr=(line.split("\x1D")); + var len = arr.length; + indx = 0; + var i; + for(i=0;i indx-1 ) + { + selectline = indx -1 ; + } + select.value = selectline; + document.getElementById('message').value=ttext[selectline]; + } + } + } + } + ); + } + + function delallsms() + { + var r=confirm("<%:Do you really want to delete all SMS?%>"); + if (r==false) + { + return false; + } + clearListBox("smsList"); + document.getElementById('message').style.color = "red"; + document.getElementById('message').value="<%:All Messages will be deleted. It may take some time before the list is updated.%>"; + XHR.get('<%=luci.dispatcher.build_url("admin", "modem", "delall_sms")%>', + null, + function() + { + readcheck(); + } + ); + } function delsms() { @@ -221,84 +307,21 @@ { return false; } - var r=confirm("<%:确认删除选中消息 ?%>"); + var r=confirm("<%:Delete the selected message?%>"); if (r==false) { return false; } var s = document.getElementById("smsList").value; var dx = index[s]; - dx = dx + 1; clearListBox("smsList"); document.getElementById('message').style.color = "red"; - document.getElementById('message').innerHTML="<%:短信将被删除,同步到列表可能会很久(反复提交删除申请一样很久)%>"; + document.getElementById('message').value="<%:Message will be deleted. It may take some time before the list is updated.%>"; XHR.get('<%=luci.dispatcher.build_url("admin", "modem", "del_sms")%>', { set: dx }, function() { - XHR.get('<%=luci.dispatcher.build_url("admin", "modem", "check_read")%>', null, - function(x, rv) - { - var ss = rv.ready; - document.getElementById('message').style.color = "initial"; - document.getElementById('conntype').innerHTML=rv.conntype; - if ( ss == "1" ) - { - clearListBox("smsList"); - document.getElementById('message').innerHTML=""; - document.getElementById('total').innerHTML=""; - document.getElementById('used').innerHTML=""; - document.getElementById('supported').innerHTML="<%:您有未读的短信,请前往查看%>"; - } - if ( ss == "3" ) - { - document.getElementById('supported').innerHTML="<%:消息读取有问题%>"; - } - if ( ss == "2" ) - { - document.getElementById('supported').innerHTML="<%:存在短信%>"; - clearListBox("smsList"); - document.getElementById('total').innerHTML=rv.max; - document.getElementById('used').innerHTML=rv.used; - var line=rv.line; - var arr=(line.split("\x1D")); - var len = arr.length; - indx = 0; - var i; - for(i=0;i indx-1 ) - { - selectline = indx -1 ; - } - select.value = selectline; - document.getElementById('message').innerHTML=ttext[selectline]; - } - } - } - } - ); + readcheck(); } ); } @@ -350,7 +373,7 @@ function(x, rv) { btn.disabled = false; - btn.value = '<%:下一个模块%>'; + btn.value = '<%:Next Modem%>'; } ); @@ -393,28 +416,28 @@
-

<%:短信收发页面%>

-
<%:通过模块发送和接收文本消息%>
+

<%:SMS Messaging%>

+
<%:Send and Receive Text Messages Through Your Modem%>
- <%:通信模块信息%> + <%:Modem Information%>
    - + - +
    - <%:收到的短信%> + <%:Received Messages%> - - + + @@ -427,11 +450,11 @@
    <%:SIM可存放的短信空间 (条)%>
    <%:已使用的SIM短信空间 (条)%>
    <%:Total SIM Message Slots%>
    <%:Used SIM Message Slots%>
     
    - + - + @@ -442,15 +465,22 @@
     
    <%:启用模块到SIM卡的短信传输%>
    <%:Enable SMS transfer from modem to SIM%>
    <%:模块上的未读信息数量%>
    <%:Unread SMS count on modem%>
     
     
    + + + + + + + +
      
    - - + + - - - + + @@ -467,26 +497,29 @@
    <%:已读状态%>
    <%:发件人%>
    <%:Read%>
    <%:Sender%>
    <%:Date%>
    <%:时间%>
    <%:短信%>
    <%:Time%>
    <%:Message%>
    - - - + + + +
    <%:短信内容 :%>
       
      <%:Message :%>
      + +  
      - - - + + +
       
      - <%:短信会话%> + <%:Send Messages%> - + @@ -494,7 +527,6 @@
      <%:收件人 :%>
      <%:Send To :%>
       
      - @@ -511,7 +543,7 @@
      - + @@ -522,4 +554,3 @@ <%+footer%> - diff --git a/rooter/0basicsupport/ext-sms/files/usr/lib/sms/delall.sh b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/delall.sh new file mode 100644 index 0000000..aa0c50b --- /dev/null +++ b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/delall.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +ROOTER=/usr/lib/rooter + +log() { + modlog "Delete SMS" "$@" +} + +CURRMODEM=$1 +COMMPORT="/dev/ttyUSB"$(uci get modem.modem$CURRMODEM.commport) +SMSLOC=$(uci -q get modem.modem$CURRMODEM.smsloc) + +LOCKDIR="/tmp/smslock$CURRMODEM" +PIDFILE="${LOCKDIR}/PID" + +while [ 1 -lt 6 ]; do + if mkdir "${LOCKDIR}" &>/dev/null; then + echo "$$" > "${PIDFILE}" + ATCMDD="AT+CPMS=\"$SMSLOC\";+CMGD=1,4" + OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + log "$OX" + uci set modem.modem$CURRMODEM.smsnum=999 + uci commit modem + break + else + OTHERPID="$(cat "${PIDFILE}")" + if [ $? = 0 ]; then + if ! kill -0 $OTHERPID &>/dev/null; then + rm -rf "${LOCKDIR}" + fi + fi + sleep 1 + fi +done +rm -rf "${LOCKDIR}" \ No newline at end of file diff --git a/rooter/0basicsupport/ext-sms/files/usr/lib/sms/delsms.sh b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/delsms.sh index 5294092..a8ccfc8 100644 --- a/rooter/0basicsupport/ext-sms/files/usr/lib/sms/delsms.sh +++ b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/delsms.sh @@ -3,12 +3,13 @@ ROOTER=/usr/lib/rooter log() { - logger -t "Delete SMS" "$@" + modlog "Delete SMS" "$@" } CURRMODEM=$1 shift 1 SLOTS="$@" +log "$SLOTS" COMMPORT="/dev/ttyUSB"$(uci get modem.modem$CURRMODEM.commport) @@ -17,13 +18,14 @@ SMSLOC=$(uci -q get modem.modem$CURRMODEM.smsloc) LOCKDIR="/tmp/smslock$CURRMODEM" PIDFILE="${LOCKDIR}/PID" -while [ 1 -lt 6 ]; do +while [ true ]; do if mkdir "${LOCKDIR}" &>/dev/null; then echo "$$" > "${PIDFILE}" for SLOT in $SLOTS do ATCMDD="AT+CPMS=\"$SMSLOC\";+CMGD=$SLOT" OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + log "$OX" done uci set modem.modem$CURRMODEM.smsnum=999 uci commit modem diff --git a/rooter/0basicsupport/ext-sms/files/usr/lib/sms/merge.lua b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/merge.lua new file mode 100644 index 0000000..0d3eebe --- /dev/null +++ b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/merge.lua @@ -0,0 +1,190 @@ +#!/usr/bin/lua + +function ltrim(s) + return s:match'^%s*(.*)' +end + +file=arg[1] +filet=arg[1] + +overall = {} + +cntr = 1 +filein = io.open(file, "r") +maxslot = -1 +repeat + message = {} + local line = filein:read("*line") + if line == nil then + break + end + if cntr < 2 then + maxused = line + line = filein:read("*line") + maxslots = line + cntr=2 + else + message['slot'] = line + message['phone'] = filein:read("*line") + nline = filein:read("*line") + message['nline'] = nline + nline = tonumber(nline) + nc = nline + ncntr = 1 + msg="" + message['msgnum'] = "xxx" + message['msgord'] = "xxx" + message['msgmax'] = "xxx" + lines = filein:read("*line") + if lines == nil then + s = nil + else + s, msgnum, msgord, msgmax = lines:match("(Msg# (%d+),(%d+)/(%d+))") + end + if s == nil then + nc = nc + 1 + else + message['msgnum'] = msgnum + message['msgord'] = msgord + message['msgmax'] = msgmax + lines = filein:read("*line") + end + msg = lines + if nc > 2 then + for i=1,nc-2,1 + do + lines = filein:read("*line") + if lines == "" then + msg = msg .. "\n" + else + msg = msg .. "\n" .. lines + end + end + --print(nln, msg) + --msg = msg .. "\n" + end + message['msg'] = msg + message['numlines'] = nc - 1 + sht = filein:read("*line") + s, sht1, sht2 = sht:match("((.*)Msg# %d+,%d+/%d%s*(.*))") + if s ~= nil then + sht = sht1 .. sht2 + end + message['short'] = sht + overall[message['slot']] = message + if maxslot < tonumber(message['slot']) then + maxslot = tonumber(message['slot']) + end + end +until 1==0 +filein:close() + +fileout = io.open(filet, "w") +fileout:write(maxused, "\n") +fileout:write(maxslots, "\n") + +for i=0,maxslot,1 +do + msgbuild = {} + shortmsg = {} + if overall[tostring(i)] ~= nil then + --print(i, overall[tostring(i)]['msgnum']) + if overall[tostring(i)]['msgnum'] == "xxx" then + fileout:write(overall[tostring(i)]['slot'], "\n") + fileout:write(overall[tostring(i)]['phone'], "\n") + fileout:write(overall[tostring(i)]['nline'], "\n") + fileout:write(overall[tostring(i)]['msg'], "\n") + fileout:write(overall[tostring(i)]['short'], "\n") + else + msgnum = overall[tostring(i)]['msgnum'] + msgtmp = overall[tostring(i)]['slot'] + msgord = overall[tostring(i)]['msgord'] + msgmax = tonumber(overall[tostring(i)]['msgmax']) + msg = overall[tostring(i)]['msg'] + numlines = overall[tostring(i)]['numlines'] + --print(numlines) + msgbuild[overall[tostring(i)]['msgord']] = overall[tostring(i)]['msg'] + shortmsg[overall[tostring(i)]['msgord']] = overall[tostring(i)]['short'] + for j=i+1,maxslot,1 + do + if overall[tostring(j)] ~= nil then + if overall[tostring(j)]['msgnum'] == msgnum then + numlines = numlines + (overall[tostring(j)]['numlines']) + --print(overall[tostring(j)]['numlines']) + msgtmp = msgtmp .. " " .. overall[tostring(j)]['slot'] + msgbuild[overall[tostring(j)]['msgord']] = overall[tostring(j)]['msg'] + shortmsg[overall[tostring(j)]['msgord']] = overall[tostring(j)]['short'] + overall[tostring(j)] = nil + end + end + end + msg="" + mflg = 0 + short = nil + for j=1,msgmax,1 + do + if msgbuild[tostring(j)] ~= nil then + msg = msg .. msgbuild[tostring(j)] + if short == nil then + short = shortmsg[tostring(j)] + end + else + mflg = 1 + end + end + fileout:write(msgtmp, "\n") + fileout:write(overall[tostring(i)]['phone'], "\n") + if mflg == 0 then + s, preshort = short:match("((.* %d+%-%d+%-%d+ %d+:%d+:%d+%s+[+-]%d+h ))") + if preshort ~= nil then + stxt = '' + j = 0 + k = 1 + ch = '' + while j < 20 do + ch = string.byte(msg:sub(k, k)) + if ch == nil then + j = 20 + elseif ch == 10 or ch == 13 then + stxt = stxt .. ' ' + k = k + 1 + elseif ch < 127 then + stxt = stxt .. string.char(ch) + k = k + 1 + elseif ch < 0xE0 then + stxt = stxt .. msg:sub(k, k + 1) + k = k + 2 + elseif ch < 0xF0 then + stxt = stxt .. msg:sub(k, k + 2) + k = k + 3 + else + stxt = stxt .. msg:sub(k, k + 3) + k = k + 4 + end + j = j + 1 + end + if preshort:sub(1, 1) == ' ' then + jj = 49 + else + jj = 51 + end + short = (preshort .. ' '):sub(1, jj) .. stxt .. " ..." + end + else + msg = "Partial Message : " .. msg + t = short:gsub("%s+", " ") + short = "Partial Message " .. t + end + endc = string.sub(msg, -2) + if endc == "\n\n" then + mlen = msg:len() - 2 + msg = string.sub(msg,1,mlen) + end + local _,n = msg:gsub("\n","") + fileout:write(tostring(n+1), "\n") + fileout:write(msg, "\n") + fileout:write(short, "\n") + end + end +end +fileout:close() diff --git a/rooter/0basicsupport/ext-sms/files/usr/lib/sms/processsms b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/processsms index 8826bb2..898a2fb 100644 --- a/rooter/0basicsupport/ext-sms/files/usr/lib/sms/processsms +++ b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/processsms @@ -72,6 +72,11 @@ while true; do SX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") USED=$(echo "$SX" | cut -d, -f1 | grep -o "[0-9]\{1,3\}") MESCc="$USED" + if [ -n "$MESCc" -a "$MESCc" != "$MESC" ]; then + MESC=$MESCc + uci set modem.sms.slots=$MESC + uci commit modem + fi MAXED=$(echo "$SX" | cut -d, -f2 | grep -o "[0-9]\{1,3\}") fi if [ $SMSLOC == "SM" ]; then @@ -79,11 +84,6 @@ while true; do SX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") USED=$(echo "$SX" | cut -d, -f1 | grep -o "[0-9]\{1,3\}") MAXED=$(echo "$SX" | cut -d, -f2 | grep -o "[0-9]\{1,3\}") - if [ -n "$MESCc" -a "$MESCc" != "$MESC" ]; then - MESC=$MESCc - uci set modem.sms.slots=$MESC - uci commit modem - fi if [ $USED == $MAXED -a $MEM3 == "SM" ]; then ATCMDD="AT+CPMS=\"SM\",\"SM\",\"ME\"" OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") @@ -101,8 +101,12 @@ while true; do fi if [ $USED -eq $(uci get modem.modem$CURRMODEM.smsnum) ] && [ $HH -eq $(date +%H) ]; then if [ $MEM3 == "SM" -a $USED -lt $MAXED -a $MESC -gt 0 -a $(uci -q get modem.sms.menable) == 1 ]; then - ATCMDD="AT+CPMS=\"ME\";+CMGR=$MESLOT;+CPMS=\"SM\"" + ATCMDD="AT+CPMS=\"ME\"" OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + ATCMDD="AT+CMGR=$MESLOT" + OX=$OX$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + ATCMDD="AT+CPMS=\"SM\"" + OX=$OX$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") Rstat=$(echo "$OX" | grep -o "+CMGR:[^,]\+" | grep -o "[0-3]") PDU=$(echo "$OX" | grep -o "[0-9A-F]\{30,\}") PDUL=$(echo "$OX" | grep -o "+CMGR:.*" | grep -o ",[0-9]\{1,\}" | grep -o "[0-9]\{1,3\}") diff --git a/rooter/0basicsupport/ext-sms/files/usr/lib/sms/smsread.lua b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/smsread.lua index c881724..da252d3 100644 --- a/rooter/0basicsupport/ext-sms/files/usr/lib/sms/smsread.lua +++ b/rooter/0basicsupport/ext-sms/files/usr/lib/sms/smsread.lua @@ -507,6 +507,9 @@ function parseDeliver() if timezone:sub(-2, -1) == '.0' then timezone = timezone:sub(1, -3) end + if #timezone == 2 then + timezone = ' ' .. timezone + end m_time = str_buf .. ' ' .. timezone .. 'h' m_pdu_ptr = m_pdu_ptr:sub(7) if octet2bin_check(m_pdu_ptr) < 0 then @@ -855,6 +858,7 @@ else end tfile:close() end +os.execute("/usr/lib/sms/merge.lua " .. tfname) os.execute("mv " .. tfname .. " /tmp/smstext" .. modemn) if #delslots > 0 then diff --git a/rooter/0drivers/rmbim/files/lib/netifd/proto/mbim.sh b/rooter/0drivers/rmbim/files/lib/netifd/proto/mbim.sh index 436635a..362e6bd 100644 --- a/rooter/0drivers/rmbim/files/lib/netifd/proto/mbim.sh +++ b/rooter/0drivers/rmbim/files/lib/netifd/proto/mbim.sh @@ -328,14 +328,22 @@ _proto_mbim_setup() { log "Failed to connect to network" return 1 fi + log "Save Connect Data" + uci set modem.modem$CURRMODEM.mdevice=$device + uci set modem.modem$CURRMODEM.mapn=$apn + uci set modem.modem$CURRMODEM.mipt=$itp + uci set modem.modem$CURRMODEM.mauth=$auth + uci set modem.modem$CURRMODEM.musername=$username + uci set modem.modem$CURRMODEM.mpassword=$password + uci commit modem tid=$((tid + 1)) - log "Get IP config" CONFIG=$(umbim $DBG -n -t $tid -d $device config) || { log "config failed" return 1 } + log "IP config $CONFIG" IP=$(echo -e "$CONFIG"|grep "ipv4address"|grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)") GATE=$(echo -e "$CONFIG"|grep "ipv4gateway"|grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)") @@ -467,6 +475,10 @@ _proto_mbim_setup() { # SIGNAL=$(umbim $DBG -n -t $tid -d $device signal) # CSQ=$(echo "$SIGNAL" | awk '/rssi:/ {print $2}') + if [ -e $ROOTER/modem-led.sh ]; then + $ROOTER/modem-led.sh $CURRMODEM 3 + fi + $ROOTER/log/logger "Modem #$CURRMODEM Connected" log "Modem $CURRMODEM Connected" @@ -540,7 +552,8 @@ _proto_mbim_setup() { $ROOTER/timezone.sh & fi fi - CLB=$(uci -q get modem.modeminfo$CURRMODEM.lb) + #CLB=$(uci -q get modem.modeminfo$CURRMODEM.lb) + CLB=1 if [ -e /etc/config/mwan3 ]; then INTER=$(uci get modem.modeminfo$CURRMODEM.inter) if [ -z $INTER ]; then @@ -577,6 +590,8 @@ proto_mbim_setup() { CPORT=$(uci get modem.modem$CURRMODEM.commport) ATCMDD="AT+COPS=0" OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + #log "Restart Modem" + #/usr/lib/rooter/luci/restart.sh $CURRMODEM sleep 5 } diff --git a/rooter/0drivers/rqmi/Makefile b/rooter/0drivers/rqmi/Makefile index 0674e1f..68ecffb 100644 --- a/rooter/0drivers/rqmi/Makefile +++ b/rooter/0drivers/rqmi/Makefile @@ -5,9 +5,9 @@ PKG_RELEASE:=$(AUTORELEASE) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL=$(PROJECT_GIT)/project/uqmi.git -PKG_SOURCE_DATE:=2022-05-04 -PKG_SOURCE_VERSION:=56cb2d4056fef132ccf78dfb6f3074ae5d109992 -PKG_MIRROR_HASH:=cc832b5318805df8c8387a3650f250dee72d5f1dbda4e4866b5503e186b2210c +PKG_SOURCE_DATE:=2021-11-06 +PKG_SOURCE_VERSION:=6f956265167945267d676c99f123a8c822f0a77b +PKG_MIRROR_HASH:=1dbe14a28ec59b364dbde5dea9e10ed1c5c3eda274b6c7690c793a06643acf3e PKG_MAINTAINER:=Matti Laakso PKG_LICENSE:=GPL-2.0 @@ -22,7 +22,7 @@ define Package/rqmi SECTION:=net CATEGORY:=ROOter SUBMENU:=Drivers - DEPENDS:=+libubox +libblobmsg-json +kmod-usb-net +kmod-usb-net-qmi-wwan +wwan + DEPENDS:=+libubox +libblobmsg-json +kmod-usb-net +kmod-usb-net-qmi-wwan +wwan +luci-proto-qmi TITLE:=Control utility for mobile broadband modems endef @@ -32,11 +32,7 @@ define Package/rqmi/description endef TARGET_CFLAGS += \ - -I$(STAGING_DIR)/usr/include \ - -ffunction-sections \ - -fdata-sections \ - -Wno-error=dangling-pointer \ - -Wno-error=maybe-uninitialized + -I$(STAGING_DIR)/usr/include -ffunction-sections -fdata-sections TARGET_LDFLAGS += -Wl,--gc-sections diff --git a/rooter/0drivers/rqmi/files/lib/netifd/proto/qmi.sh b/rooter/0drivers/rqmi/files/lib/netifd/proto/qmi.sh new file mode 100644 index 0000000..158b5d0 --- /dev/null +++ b/rooter/0drivers/rqmi/files/lib/netifd/proto/qmi.sh @@ -0,0 +1,596 @@ +#!/bin/sh + +[ -n "$INCLUDE_ONLY" ] || { + . /lib/functions.sh + . ../netifd-proto.sh + init_proto "$@" +} + +ROOTER=/usr/lib/rooter +ROOTER_LINK="/tmp/links" + +log() { + modlog "QMI Connect $CURRMODEM" "$@" +} + +log "Starting QMI" + +proto_qmi_init_config() { + available=1 + no_device=1 + proto_config_add_string "device:device" + proto_config_add_string apn + proto_config_add_string auth + proto_config_add_string username + proto_config_add_string password + proto_config_add_string pincode + proto_config_add_int delay + proto_config_add_string modes + proto_config_add_string pdptype + proto_config_add_int profile + proto_config_add_boolean dhcp + proto_config_add_boolean dhcpv6 + proto_config_add_boolean autoconnect + proto_config_add_int plmn + proto_config_add_int timeout + proto_config_add_int mtu + proto_config_add_defaults +} + +proto_qmi_setup() { + local interface="$1" + local dataformat connstat plmn_mode mcc mnc + local device apn auth username password pincode delay modes pdptype + local profile dhcp dhcpv6 autoconnect plmn timeout mtu $PROTO_DEFAULT_OPTIONS + local ip4table ip6table + local cid_4 pdh_4 cid_6 pdh_6 + local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6 + + if [ ! -f /tmp/bootend.file ]; then + return 0 + fi + + CURRMODEM=$(uci -q get network.$interface.currmodem) + uci set modem.modem$CURRMODEM.connected=0 + uci commit modem + rm -f $ROOTER_LINK/reconnect$CURRMODEM + jkillall getsignal$CURRMODEM + rm -f $ROOTER_LINK/getsignal$CURRMODEM + jkillall con_monitor$CURRMODEM + rm -f $ROOTER_LINK/con_monitor$CURRMODEM + jkillall mbim_monitor$CURRMODEM + rm -f $ROOTER_LINK/mbim_monitor$CURRMODEM + + json_get_vars device apn auth username password pincode delay modes + json_get_vars pdptype profile dhcp dhcpv6 autoconnect plmn ip4table + json_get_vars ip6table timeout mtu $PROTO_DEFAULT_OPTIONS + + case $auth in + "0" ) + auth= + ;; + "1" ) + auth="pap" + ;; + "2" ) + auth="chap" + ;; + "*" ) + auth= + ;; + esac + + [ "$timeout" = "" ] && timeout="10" + + [ "$metric" = "" ] && metric="0" + + [ -n "$ctl_device" ] && device=$ctl_device + + [ -n "$device" ] || { + log "No control device specified" + proto_notify_error "$interface" NO_DEVICE + proto_set_available "$interface" 0 + return 1 + } + + [ -n "$delay" ] && sleep "$delay" + + device="$(readlink -f $device)" + [ -c "$device" ] || { + log "The specified control device does not exist" + proto_notify_error "$interface" NO_DEVICE + proto_set_available "$interface" 0 + return 1 + } + + devname="$(basename "$device")" + devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)" + ifname="$( ls "$devpath"/net )" + [ -n "$ifname" ] || { + log "The interface could not be found." + proto_notify_error "$interface" NO_IFACE + proto_set_available "$interface" 0 + return 1 + } + + [ -n "$mtu" ] && { + log "Setting MTU to $mtu" + /sbin/ip link set dev $ifname mtu $mtu + } + + timeout=1 + + # Cleanup current state if any + uqmi -s -d "$device" --stop-network 0xffffffff --autoconnect > /dev/null 2>&1 + + # Go online + uqmi -s -d "$device" --set-device-operating-mode online > /dev/null 2>&1 + + # Set IP format + uqmi -s -d "$device" --set-data-format 802.3 > /dev/null 2>&1 + uqmi -s -d "$device" --wda-set-data-format 802.3 > /dev/null 2>&1 + if [ $RAW -eq 1 ]; then + dataformat='"raw-ip"' + else + if [ $idV = 1199 -a $idP = 9055 ]; then + $ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "reset.gcom" "$CURRMODEM" + dataformat='"802.3"' + uqmi -s -d "$device" --set-data-format 802.3 + uqmi -s -d "$device" --wda-set-data-format 802.3 + else + dataformat=$(uqmi -s -d "$device" --wda-get-data-format) + fi + fi + log "WDA-GET-DATA-FORMAT is $dataformat" + + if [ "$dataformat" = '"raw-ip"' ]; then + + [ -f /sys/class/net/$ifname/qmi/raw_ip ] || { + log "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip" + return 1 + } + + log "Device does not support 802.3 mode. Informing driver of raw-ip only for $ifname .." + echo "Y" > /sys/class/net/$ifname/qmi/raw_ip + fi + + uqmi -s -d "$device" --sync > /dev/null 2>&1 + + uqmi -s -d "$device" --network-register > /dev/null 2>&1 + + log "Waiting for network registration" + sleep 1 + local registration_timeout=0 + local registration_state="" + while true; do + registration_state=$(uqmi -s -d "$device" --get-serving-system 2>/dev/null | jsonfilter -e "@.registration" 2>/dev/null) + log "Registration State : $registration_state" + [ "$registration_state" = "registered" ] && break + + if [ "$registration_state" = "searching" ] || [ "$registration_state" = "not_registered" ]; then + if [ "$registration_timeout" -lt "$timeout" ] || [ "$timeout" = "0" ]; then + [ "$registration_state" = "searching" ] || { + log "Device stopped network registration. Restart network registration" + uqmi -s -d "$device" --network-register > /dev/null 2>&1 + } + let registration_timeout++ + sleep 1 + continue + fi + log "Network registration failed, registration timeout reached" + else + # registration_state is 'registration_denied' or 'unknown' or '' + log "Network registration failed (reason: '$registration_state')" + fi + + proto_notify_error "$interface" NETWORK_REGISTRATION_FAILED + proto_block_restart "$interface" + return 1 + done + + [ -n "$modes" ] && uqmi -s -d "$device" --set-network-modes "$modes" > /dev/null 2>&1 + + pdptype="ipv4v6" + IPVAR=$(uci -q get modem.modem$CURRMODEM.pdptype) + case "$IPVAR" in + "IP" ) + pdptype="ipv4" + ;; + "IPV6" ) + pdptype="ipv6" + ;; + "IPV4V6" ) + pdptype="ipv4v6" + ;; + esac + + pdptype=$(echo "$pdptype" | awk '{print tolower($0)}') + [ "$pdptype" = "ip" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] || pdptype="ip" + if [ "$pdptype" = "ip" ]; then + [ -z "$autoconnect" ] && autoconnect=1 + [ "$autoconnect" = 0 ] && autoconnect="" + else + [ "$autoconnect" = 1 ] || autoconnect="" + fi + + isplist=$(uci -q get modem.modeminfo$CURRMODEM.isplist) + apn2=$(uci -q get modem.modeminfo$CURRMODEM.apn2) + for isp in $isplist + do + NAPN=$(echo $isp | cut -d, -f2) + NPASS=$(echo $isp | cut -d, -f4) + CID=$(echo $isp | cut -d, -f5) + NUSER=$(echo $isp | cut -d, -f6) + NAUTH=$(echo $isp | cut -d, -f7) + if [ "$NPASS" = "nil" ]; then + NPASS="NIL" + fi + if [ "$NUSER" = "nil" ]; then + NUSER="NIL" + fi + if [ "$NAUTH" = "nil" ]; then + NAUTH="0" + fi + apn=$NAPN + username="$NUSER" + password="$NPASS" + auth=$NAUTH + case $auth in + "0" ) + auth="none" + ;; + "1" ) + auth="pap" + ;; + "2" ) + auth="chap" + ;; + "*" ) + auth="none" + ;; + esac + + + if [ ! -e /etc/config/isp ]; then + log "Connect to network using $NAPN" + else + log "Connect to network" + fi + + if [ ! -e /etc/config/isp ]; then + log "Connection Parameters : $NAPN $auth $username $password" + fi + conn=0 + + [ "$pdptype" = "ip" -o "$pdptype" = "ipv4v6" ] && { + cid_4=$(uqmi -s -d "$device" --get-client-id wds) + if ! [ "$cid_4" -eq "$cid_4" ] 2> /dev/null; then + log "Unable to obtain client ID" + fi + } + uqmi -s -d "$device" --set-client-id wds,"$cid_4" --set-ip-family ipv4 > /dev/null 2>&1 + v4s=0 + pdh_4=$(uqmi -s -d "$device" --set-client-id wds,"$cid_4" \ + --start-network \ + ${apn:+--apn $apn} \ + ${auth:+--auth-type $auth} \ + ${username:+--username $username} \ + ${password:+--password $password} \ + ${autoconnect:+--autoconnect}) + log "IPv4 Connection returned : $pdh_4" + CONN4=$(uqmi -s -d "$device" --set-client-id wds,"$cid_4" --get-current-settings) + log "GET-CURRENT-SETTINGS is $CONN4" + # pdh_4 is a numeric value on success + if ! [ "$pdh_4" -eq "$pdh_4" ] 2> /dev/null; then + log "Unable to connect IPv4" + v4s=0 + else + # Check data connection state + v4s=1 + conn=1 + fi + + [ "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && { + cid_6=$(uqmi -s -d "$device" --get-client-id wds) + if ! [ "$cid_6" -eq "$cid_6" ] 2> /dev/null; then + log "Unable to obtain client ID" + #proto_notify_error "$interface" NO_CID + fi + } + + uqmi -s -d "$device" --set-client-id wds,"$cid_6" --set-ip-family ipv6 > /dev/null 2>&1 + v6s=0 + pdh_6=$(uqmi -s -d "$device" --set-client-id wds,"$cid_6" \ + --start-network \ + ${apn:+--apn $apn} \ + ${auth:+--auth-type $auth} \ + ${username:+--username $username} \ + ${password:+--password $password} \ + ${autoconnect:+--autoconnect}) + log "IPv6 Connection returned : $pdh_6" + + # pdh_6 is a numeric value on success + if ! [ "$pdh_6" -eq "$pdh_6" ] 2> /dev/null; then + log "Unable to connect IPv6" + v6s=0 + else + # Check data connection state + CONN6=$(uqmi -s -d "$device" --set-client-id wds,"$cid_6" --get-current-settings) + log "GET-CURRENT-SETTINGS is $CONN6" + v6s=1 + conn=1 + fi + if [ $conn -eq 1 ]; then + break; + fi + done + + if [ $conn -eq 0 ]; then + proto_notify_error "$interface" CALL_FAILED + return 1 + else + log "Setting up $ifname" + proto_init_update "$ifname" 1 + proto_set_keep 1 + proto_add_data + [ -n "$pdh_4" ] && { + json_add_string "cid_4" "$cid_4" + json_add_string "pdh_4" "$pdh_4" + } + [ -n "$pdh_6" ] && { + json_add_string "cid_6" "$cid_6" + json_add_string "pdh_6" "$pdh_6" + } + proto_close_data + proto_send_update "$interface" + + zone="$(fw3 -q network "$interface" 2>/dev/null)" + dhcp=0 + dhcpv6=0 + + [ "$v6s" -eq 1 ] && { + if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then + json_load "$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)" + json_select ipv6 + json_get_var ip_6 ip + json_get_var gateway_6 gateway + json_get_var dns1_6 dns1 + json_get_var dns2_6 dns2 + json_get_var ip_prefix_length ip-prefix-length + + proto_init_update "$ifname" 1 + proto_set_keep 1 + proto_add_ipv6_address "$ip_6" "128" + proto_add_ipv6_prefix "${ip_6}/${ip_prefix_length}" + proto_add_ipv6_route "$gateway_6" "128" + [ "$defaultroute" = 0 ] || proto_add_ipv6_route "::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}" + [ "$peerdns" = 0 ] || { + proto_add_dns_server "$dns1_6" + proto_add_dns_server "$dns2_6" + } + [ -n "$zone" ] && { + proto_add_data + json_add_string zone "$zone" + proto_close_data + } + proto_send_update "$interface" + v6dns="$dns1_6 $dns2_6" + log "IPv6 address : $ip_6" + log "IPv6 DNS : $v6dns" + else + json_init + json_add_string name "${interface}_6" + json_add_string ifname "@$interface" + json_add_string proto "dhcpv6" + [ -n "$ip6table" ] && json_add_string ip6table "$ip6table" + proto_add_dynamic_defaults + # RFC 7278: Extend an IPv6 /64 Prefix to LAN + json_add_string extendprefix 1 + [ -n "$zone" ] && json_add_string zone "$zone" + json_close_object + ubus call network add_dynamic "$(json_dump)" + fi + } + + [ "$v4s" -eq 1 ] && { + if [ "$dhcp" = 0 ]; then + json_load "$(uqmi -s -d $device --set-client-id wds,$cid_4 --get-current-settings)" + json_select ipv4 + json_get_var ip_4 ip + json_get_var gateway_4 gateway + json_get_var dns1_4 dns1 + json_get_var dns2_4 dns2 + json_get_var subnet_4 subnet + + proto_init_update "$ifname" 1 + proto_set_keep 1 + proto_add_ipv4_address "$ip_4" "$subnet_4" + proto_add_ipv4_route "$gateway_4" "128" + [ "$defaultroute" = 0 ] || proto_add_ipv4_route "0.0.0.0" 0 "$gateway_4" + [ "$peerdns" = 0 ] || { + proto_add_dns_server "$dns1_4" + proto_add_dns_server "$dns2_4" + } + [ -n "$zone" ] && { + proto_add_data + json_add_string zone "$zone" + proto_close_data + } + proto_send_update "$interface" + log "IPv4 address : $ip_4" + log "IPv4 DNS : $dns1_4 $dns2_4" + else + json_init + json_add_string name "${interface}_4" + json_add_string ifname "@$interface" + json_add_string proto "dhcp" + [ -n "$ip4table" ] && json_add_string ip4table "$ip4table" + proto_add_dynamic_defaults + [ -n "$zone" ] && json_add_string zone "$zone" + json_close_object + ubus call network add_dynamic "$(json_dump)" + fi + } + + if [ -n "$ip_6" -a -z "$ip_4" ]; then + log "Running IPv6-only mode" + nat46=1 + fi + if [[ $(echo "$ip_6" | grep -o "^[23]") ]]; then + # Global unicast IP acquired + v6cap=1 + elif + [[ $(echo "$ip_6" | grep -o "^[0-9a-fA-F]\{1,4\}:") ]]; then + # non-routable address + v6cap=2 + else + v6cap=0 + fi + if [ $v4s -eq 0 -a $v6s -eq 1 ]; then + INTER=$(uci get modem.modem$CURRMODEM.inter) + if [ "$v6cap" -gt 0 ]; then + zone="$(fw3 -q network "$interface" 2>/dev/null)" + fi + if [ "$v6cap" = 2 ]; then + log "Adding IPv6 dynamic interface" + json_init + json_add_string name "${interface}_6" + json_add_string ${ifname1} "@$interface" + json_add_string proto "dhcpv6" + json_add_string extendprefix 1 + [ -n "$zone" ] && json_add_string zone "$zone" + [ "$nat46" = 1 ] || json_add_string iface_464xlat 0 + json_add_boolean peerdns 0 + json_add_array dns + for DNSV in $(echo "$v6dns"); do + json_add_string "" "$DNSV" + done + json_close_array + proto_add_dynamic_defaults + json_close_object + ubus call network add_dynamic "$(json_dump)" + elif + [ "$v6cap" = 1 -a "$nat46" = 1 ]; then + log "Adding 464XLAT (CLAT) dynamic interface" + json_init + json_add_string name "CLAT$INTER" + json_add_string proto "464xlat" + json_add_string tunlink "${interface}" + [ -n "$zone" ] && json_add_string zone "$zone" + proto_add_dynamic_defaults + json_close_object + ubus call network add_dynamic "$(json_dump)" + fi + fi + if [ -e $ROOTER/modem-led.sh ]; then + $ROOTER/modem-led.sh $CURRMODEM 3 + fi + + log "Modem $CURRMODEM Connected" + COMMPORT=$(uci get modem.modem$CURRMODEM.commport) + if [ ! -z $COMMPORT ]; then + $ROOTER/sms/check_sms.sh $CURRMODEM & + ln -s $ROOTER/signal/modemsignal.sh $ROOTER_LINK/getsignal$CURRMODEM + # send custom AT startup command + if [ $(uci -q get modem.modeminfo$CURRMODEM.at) -eq "1" ]; then + ATCMDD=$(uci -q get modem.modeminfo$CURRMODEM.atc) + if [ ! -z "${ATCMDD}" ]; then + OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD") + OX=$($ROOTER/common/processat.sh "$OX") + ERROR="ERROR" + if `echo ${OX} | grep "${ERROR}" 1>/dev/null 2>&1` + then + log "Error sending custom AT command: $ATCMDD with result: $OX" + else + log "Sent custom AT command: $ATCMDD with result: $OX" + fi + fi + fi + fi + ln -s $ROOTER/connect/reconnect.sh $ROOTER_LINK/reconnect$CURRMODEM + $ROOTER_LINK/getsignal$CURRMODEM $CURRMODEM $PROT & + ln -s $ROOTER/connect/conmon.sh $ROOTER_LINK/con_monitor$CURRMODEM + $ROOTER_LINK/con_monitor$CURRMODEM $CURRMODEM & + uci set modem.modem$CURRMODEM.connected=1 + uci commit modem + + if [ -e $ROOTER/connect/postconnect.sh ]; then + $ROOTER/connect/postconnect.sh $CURRMODEM + fi + + if [ -e $ROOTER/timezone.sh ]; then + TZ=$(uci -q get modem.modeminfo$CURRMODEM.tzone) + if [ "$TZ" = "1" ]; then + $ROOTER/timezone.sh & + fi + fi + CLB=1 + if [ -e /etc/config/mwan3 ]; then + INTER=$(uci get modem.modeminfo$CURRMODEM.inter) + if [ -z $INTER ]; then + INTER=0 + else + if [ $INTER = 0 ]; then + INTER=$CURRMODEM + fi + fi + ENB=$(uci -q get mwan3.wan$CURRMODEM.enabled) + if [ ! -z $ENB ]; then + if [ $CLB = "1" ]; then + uci set mwan3.wan$INTER.enabled=1 + else + uci set mwan3.wan$INTER.enabled=0 + fi + uci commit mwan3 + /usr/sbin/mwan3 restart + fi + fi + rm -f /tmp/usbwait + + return 0 + fi +} + +qmi_wds_stop() { + local cid="$1" + local pdh="$2" + + [ -n "$cid" ] || return + + uqmi -s -d "$device" --set-client-id wds,"$cid" \ + --stop-network 0xffffffff \ + --autoconnect > /dev/null 2>&1 + + [ -n "$pdh" ] && { + uqmi -s -d "$device" --set-client-id wds,"$cid" \ + --stop-network "$pdh" > /dev/null 2>&1 + } + + uqmi -s -d "$device" --set-client-id wds,"$cid" \ + --release-client-id wds > /dev/null 2>&1 +} + +proto_qmi_teardown() { + local interface="$1" + + local device cid_4 pdh_4 cid_6 pdh_6 + json_get_vars device + + [ -n "$ctl_device" ] && device=$ctl_device + + log "Stopping network $interface" + + json_load "$(ubus call network.interface.$interface status)" + json_select data + json_get_vars cid_4 pdh_4 cid_6 pdh_6 + + qmi_wds_stop "$cid_4" "$pdh_4" + qmi_wds_stop "$cid_6" "$pdh_6" + + proto_init_update "*" 0 + proto_send_update "$interface" +} + +[ -n "$INCLUDE_ONLY" ] || { + add_protocol qmi +} diff --git a/rooter/0drivers/rqmi/files/usr/lib/rooter/qmi/connectqmi.sh b/rooter/0drivers/rqmi/files/usr/lib/rooter/qmi/connectqmi.sh deleted file mode 100644 index 7dc6d02..0000000 --- a/rooter/0drivers/rqmi/files/usr/lib/rooter/qmi/connectqmi.sh +++ /dev/null @@ -1,293 +0,0 @@ -#!/bin/sh - -ROOTER=/usr/lib/rooter - -log() { - modlog "QMI Connect $CURRMODEM" "$@" -} - - . /lib/functions.sh - . /lib/netifd/netifd-proto.sh - -CURRMODEM=$1 -devname=$2 -device=/dev/$2 -auth=$3 -NAPN=$4 -username=$5 -password=$6 -RAW=$7 -DHCP=$8 -pincode=$9 - -enb=$(uci -q get custom.connect.ipv6) -if [ -z $enb ]; then - enb="1" -fi - -ifname1="ifname" -if [ -e /etc/newstyle ]; then - ifname1="device" -fi - -INTER=$(uci -q get modem.modem$CURRMODEM.inter) -interface="wan"$INTER - -case $auth in - "0" ) - auth="none" - ;; - "1" ) - auth="pap" - ;; - "2" ) - auth="chap" - ;; - *) - auth="none" - ;; -esac - -if [ $username = NIL ]; then - username= -fi -if [ $password = NIL ]; then - password= -fi - -ifname="$(ls /sys/class/usbmisc/$devname/device/net/)" - -#while uqmi -s -d "$device" --get-pin-status | grep '"UIM uninitialized"' > /dev/null; do -# sleep 1; -#done - -[ -n "$pincode" ] && { - uqmi -s -d "$device" --verify-pin1 "$pincode" || { - log "Unable to verify PIN" - ret=1 - } -} - -uqmi -s -d "$device" --stop-network 0xffffffff --autoconnect > /dev/null & sleep 5 ; kill -9 $! -uqmi -s -d "$device" --set-device-operating-mode online > /dev/null 2>&1 & sleep 5 ; kill -9 $! - -if [ $RAW -eq 1 ]; then - DATAFORM='"raw-ip"' -else - if [ $idV = 1199 -a $idP = 9055 ]; then - $ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "reset.gcom" "$CURRMODEM" - DATAFORM='"802.3"' - uqmi -s -d "$device" --set-data-format 802.3 - uqmi -s -d "$device" --wda-set-data-format 802.3 - else - log "getting data format" - DATAFORM=$(uqmi -s -d "$device" --wda-get-data-format) - fi -fi - -log "WDA-GET-DATA-FORMAT is $DATAFORM" -if [ "$DATAFORM" = '"raw-ip"' ]; then - [ -f /sys/class/net/$ifname/qmi/raw_ip ] || { - log "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip" - ret=1 - } - echo "Y" > /sys/class/net/$ifname/qmi/raw_ip -fi - -log "Query radio state" -uqmi -s -d "$device" --get-signal-info | grep -q "Information unavailable" & sleep 5 ; kill -9 $! -STATUS=$? - -[ "$STATUS" -ne 0 ] || { - sleep 1 - log "Setting FCC Auth" - uqmi -s -d "$device" --fcc-auth & sleep 5 ; kill -9 $! - sleep 1 - } - -uqmi -s -d "$device" --sync > /dev/null 2>&1 & sleep 5 ; kill -9 $! - -#uqmi -s -d "$device" --network-register > /dev/null 2>&1 - -log "Waiting for network registration" -td=0 -while uqmi -s -d "$device" --get-serving-system | grep '"searching"' > /dev/null; do - sleep 5; - tid=$((tid + 1)) - if [ $tid -gt 2 ]; then - uqmi -s -d "$device" --stop-network 0xffffffff --autoconnect > /dev/null & sleep 10 ; kill -9 $! - exit 1 - fi -done - -cid=`uqmi -s -d "$device" --get-client-id wds` -[ $? -ne 0 ] && { - log "Unable to obtain client ID" - ret=1 -} - -uqmi -s -d "$device" --set-client-id wds,"$cid" --set-ip-family ipv4 > /dev/null - -isplist=$(uci -q get modem.modeminfo$CURRMODEM.isplist) -apn2=$(uci -q get modem.modeminfo$CURRMODEM.apn2) -for isp in $isplist - do - NAPN=$(echo $isp | cut -d, -f2) - NPASS=$(echo $isp | cut -d, -f4) - CID=$(echo $isp | cut -d, -f5) - NUSER=$(echo $isp | cut -d, -f6) - NAUTH=$(echo $isp | cut -d, -f7) - if [ "$NPASS" = "nil" ]; then - NPASS="NIL" - fi - if [ "$NUSER" = "nil" ]; then - NUSER="NIL" - fi - if [ "$NAUTH" = "nil" ]; then - NAUTH="0" - fi - username="$NUSER" - password="$NPASS" - auth=$NAUTH - case $auth in - "0" ) - auth="none" - ;; - "1" ) - auth="pap" - ;; - "2" ) - auth="chap" - ;; - "*" ) - auth="none" - ;; - esac - - if [ ! -e /etc/config/isp ]; then - log "Connect to network using $NAPN" - else - log "Connect to network" - fi - - if [ ! -e /etc/config/isp ]; then - log "$NAPN $auth $username $password" - fi - - conn=0 - tidd=0 - tcnt=4 - while true; do - ST=$(uqmi -s -d "$device" --set-client-id wds,"$cid" --start-network ${NAPN:+--apn $NAPN} ${auth:+--auth-type $auth} \ - ${username:+--username $username} ${password:+--password $password}) - log "Connection returned : $ST" - CONN=$(uqmi -s -d "$device" --get-data-status) - log "Status is $CONN" - if [[ $(echo "$CONN" | grep -o "disconnected") ]]; then - sleep 1 - tidd=$((tidd + 1)) - if [ $tidd -gt $tcnt ]; then - break - fi - else - conn=1 - break - fi - done - if [ $conn -eq 1 ]; then - break; - fi - done - -if [[ -z $(echo "$CONN" | grep -o "disconnected") ]]; then - ret=0 - - CONN4=$(uqmi -s -d "$device" --set-client-id wds,"$cid" --get-current-settings) - log "GET-CURRENT-SETTINGS is $CONN4" - - if [ $enb = "1" ]; then - cid6=`uqmi -s -d "$device" --get-client-id wds` - [ $? -ne 0 ] && { - log "Unable to obtain client ID" - ret=1 - } - - uqmi -s -d "$device" --set-client-id wds,"$cid6" --set-ip-family ipv6 > /dev/null - ST6=$(uqmi -s -d "$device" --set-client-id wds,"$cid6" --start-network ${NAPN:+--apn $NAPN} ${auth:+--auth-type $auth} \ - ${username:+--username $username} ${password:+--password $password}) - log "IPv6 Connection returned : $ST6" - CONN6=$(uqmi -s -d "$device" --set-client-id wds,"$cid6" --get-current-settings) - CONF6=$(jsonfilter -s $CONN6 -e '@.ipv6') - if [ -n "$CONF6" ];then - log "IPv6 settings are $CONF6" - touch /tmp/ipv6supp$INTER - else - rm -f /tmp/ipv6supp$INTER - fi - fi - - if [ $DATAFORM = '"raw-ip"' ]; then - log "Handle raw-ip" - json_load "$CONN4" - json_select ipv4 - json_get_vars ip subnet gateway dns1 dns2 - if [ $enb = "1" ]; then - if [ -n "$CONF6" ]; then - json_load "$CONN6" - json_select ipv6 - json_get_var ip_6 ip - json_get_var gateway_6 gateway - json_get_var dns1_6 dns1 - json_get_var dns2_6 dns2 - json_get_var ip_prefix_length ip-prefix-length - fi - fi - - if [ -s /tmp/v4dns$INTER -o -s /tmp/v6dns$INTER ]; then - pdns=1 - if [ -s /tmp/v4dns$INTER ]; then - v4dns=$(cat /tmp/v4dns$INTER 2>/dev/null) - fi - if [ $enb = "1" ]; then - if [ -s /tmp/v6dns$INTER ]; then - v6dns=$(cat /tmp/v6dns$INTER 2>/dev/null) - fi - fi - else - v4dns="$dns1 $dns2" - if [ $enb = "1" ]; then - v6dns="$dns1_6 $dns2_6" - echo "$v6dns" > /tmp/v6dns$INTER - fi - fi - - if [ $DHCP -eq 0 ]; then - log Applying IP settings to wan$INTER - uci delete network.wan$INTER - uci set network.wan$INTER=interface - uci set network.wan$INTER.proto=static - uci set network.wan$INTER.${ifname1}=$ifname - uci set network.wan$INTER.metric=$INTER"0" - uci set network.wan$INTER.ipaddr=$ip/$subnet - uci set network.wan$INTER.gateway='0.0.0.0' - uci set network.wan$INTER.dns="$v4dns" - uci commit network - uci set modem.modem$CURRMODEM.interface=$ifname - uci commit modem - else - proto_init_update "$ifname" 1 - proto_set_keep 1 - proto_add_ipv4_address "$ip" "$subnet" - proto_add_ipv4_route "0.0.0.0" 0 - for DNSV in $(echo "$v4dns"); do - proto_add_dns_server "$DNSV" - done - proto_send_update "$interface" - fi - fi -else - uqmi -s -d "$device" --stop-network 0xffffffff --autoconnect > /dev/null & sleep 10 ; kill -9 $! - ret=1 -fi - -exit $ret diff --git a/rooter/0optionalapps/bwallocate/files/usr/lib/lua/luci/model/cbi/fullmenu/bwmenu.lua b/rooter/0optionalapps/bwallocate/files/usr/lib/lua/luci/model/cbi/fullmenu/bwmenu.lua index 4b4d4ab..9fcc8d9 100644 --- a/rooter/0optionalapps/bwallocate/files/usr/lib/lua/luci/model/cbi/fullmenu/bwmenu.lua +++ b/rooter/0optionalapps/bwallocate/files/usr/lib/lua/luci/model/cbi/fullmenu/bwmenu.lua @@ -238,7 +238,7 @@ btn.inputtitle = translate("Send Test of Text or Email") btn.inputstyle = "apply" btn:depends("text", "1") function btn.write() - luci.sys.call("/usr/lib/bwmon/dotext.sh") + luci.sys.call("/usr/lib/bwmon/dotext.sh &") end b4 = s:option(DummyValue, "blank", " "); diff --git a/rooter/0optionalapps/bwmon/files/etc/config/bwmon b/rooter/0optionalapps/bwmon/files/etc/config/bwmon index 9d45a80..a95254d 100644 --- a/rooter/0optionalapps/bwmon/files/etc/config/bwmon +++ b/rooter/0optionalapps/bwmon/files/etc/config/bwmon @@ -4,6 +4,17 @@ config general 'general' option backup '30' option enabled '1' - config bwwan 'bwwan' - option wan '0' \ No newline at end of file + option wan '1' + +config backup 'backup' + option dailytotal '0' + option dailyrx '0' + option dailytx '0' + option montotal '0' + option monrx '0' + option montx '0' + option days '1' + option year '0' + option month '0' + option day '0' \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/etc/init.d/bwmon b/rooter/0optionalapps/bwmon/files/etc/init.d/bwmon index 925a8ea..10e79d2 100644 --- a/rooter/0optionalapps/bwmon/files/etc/init.d/bwmon +++ b/rooter/0optionalapps/bwmon/files/etc/init.d/bwmon @@ -6,13 +6,23 @@ START=60 start() { WX=$(uci -q get custom.bwallocate.lock) if [ "$WX" = "1" ]; then - uci set bwmon.general.enabled=$enable + uci set bwmon.general.enabled=1 uci commit bwmon fi - /usr/lib/bwmon/wrtbwmon.sh & - /usr/lib/bwmon/create.sh & + WX=$(uci -q get bwmon.backup) + if [ -z "$WX" ]; then + uci set bwmon.backup='backup' + uci set bwmon.backup.dailytotal='0' + uci set bwmon.backup.dailyrx='0' + uci set bwmon.backup.dailytx='0' + uci set bwmon.backup.montotal='0' + uci set bwmon.backup.monrx='0' + uci set bwmon.backup.montx='0' + uci set bwmon.backup.days='1' + uci set bwmon.backup.year='0' + uci set bwmon.backup.month='0' + uci set bwmon.backup.day='0' + uci commit bwmon + fi + /usr/lib/bwmon/bwmon.sh & } - -stop() { - rmdir -f /tmp/WRTbmon -} \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/allocate.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/allocate.sh index 58b4c22..a4cee40 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/allocate.sh +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/allocate.sh @@ -12,10 +12,10 @@ if [ $amount != "0" ]; then else sleep 3 fi -result=`ps | grep -i "create_data.lua" | grep -v "grep" | wc -l` +result=`ps | grep -i "createdata.lua" | grep -v "grep" | wc -l` while [ $result -ge 1 ]; do sleep 2 - result=`ps | grep -i "create_data.lua" | grep -v "grep" | wc -l` + result=`ps | grep -i "createdata.lua" | grep -v "grep" | wc -l` done -lua /usr/lib/bwmon/create_data.lua +lua /usr/lib/bwmon/createdata.lua diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/amtleft.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/amtleft.lua index ee530db..695c26c 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/amtleft.lua +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/amtleft.lua @@ -5,15 +5,15 @@ function ltrim(s) end function calc(total) - if total < 1000 then - tstr = string.format("%.2f", total) + if total < 1000000 then + tstr = string.format("%.2f", total/1000) tfm = " K" else if total < 1000000 then - tstr = string.format("%.2f", total/1000) + tstr = string.format("%.2f", total/1000000) tfm = " MB" else - tstr = string.format("%.2f", total/1000000) + tstr = string.format("%.2f", total/1000000000) tfm = " GB" end end @@ -21,10 +21,16 @@ function calc(total) return ltrim(str) end -aamt = arg[1] -uamt = arg[2] -amt = aamt - uamt -amts = calc(amt) +aamt = tonumber(arg[1]) +uamt = tonumber(arg[2]) +if uamt > aamt then + amt = uamt - aamt + amts = calc(amt) + amts = "-" .. amts +else + amt = aamt - uamt + amts = calc(math.abs(amt)) +end tfile = io.open("/tmp/amtleft", "w") tfile:write(amts, "\n") tfile:close() \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup-daily.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup-daily.lua deleted file mode 100644 index c9f579e..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup-daily.lua +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/lua - -dailyUsageDB = arg[1] - -bw = {} -maclist = {} - -file = io.open(dailyUsageDB, "r") -i = 0 -repeat - line = file:read("*line") - if line == nil then - break - end - s, e = line:find("\"mac\":\"") - bs, be = line:find("\"", e+1) - mac = line:sub(e+1, bs-1) - if bw[mac] == nil then - maclist[i] = mac - i = i + 1 - bw[mac] = {} - bw[mac]['down'] = 0 - bw[mac]['offdown'] = 0 - bw[mac]['up'] = 0 - bw[mac]['offup'] = 0 - end - s, e = line:find("\"down\":\"") - bs, be = line:find("\"", e+1) - down = tonumber(line:sub(e+1, bs-1)) - bw[mac]['down'] = bw[mac]['down'] + down - s, e = line:find("\"up\":\"") - bs, be = line:find("\"", e+1) - up = tonumber(line:sub(e+1, bs-1)) - bw[mac]['up'] = bw[mac]['up'] + up - s, e = line:find("\"offdown\":\"") - bs, be = line:find("\"", e+1) - offdown = tonumber(line:sub(e+1, bs-1)) - bw[mac]['offdown'] = bw[mac]['offdown'] + offdown - s, e = line:find("\"offup\":\"") - bs, be = line:find("\"", e+1) - offup = tonumber(line:sub(e+1, bs-1)) - bw[mac]['offup'] = bw[mac]['offup'] + offup - s, e = line:find("\"ip\":\"") - bs, be = line:find("\"", e+1) - bw[mac]['ip'] = line:sub(e+1, bs-1) - s, e = line:find("\"name\":\"") - bs, be = line:find("\"", e+1) - bw[mac]['name'] = line:sub(e+1, bs-1) -until 1==0 -file:close() - -j=0 -file = io.open(dailyUsageDB .. ".bk", "w") -while maclist[j] ~= nil do - mac = maclist[j] - dline = "\"mac\":\"" .. mac .. "\",\"down\":\"" .. bw[mac]['down'] .. "\",\"up\":\"" .. bw[mac]['up'] .. "\",\"offdown\":\"0\",\"offup\":\"0\",\"ip\":\"" .. bw[mac]['ip'] .. "\",\"name\":\"" .. bw[mac]['name'] .. "\"" - file:write(dline, "\n") - j = j + 1 -end -file:close() - diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup-mon.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup-mon.lua deleted file mode 100644 index 5d8e883..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup-mon.lua +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/lua - -monthUsageDB = arg[1] - -tfile = io.open(monthUsageDB .. ".bk", "w") -tfile:close() - -file = io.open(monthUsageDB, "r") - -repeat - line = file:read("*line") - if line == nil then - break - end - s, e = line:find("start day") - if s ~= nil then - maclist = {} - bw = {} - i = 0 - startday = line - repeat - line = file:read("*line") - if line == nil then - break - end - s, e = line:find("end day") - if s ~= nil then - endday = line - break - end - s, e = line:find("\"mac\":\"") - bs, be = line:find("\"", e+1) - mac = line:sub(e+1, bs-1) - if bw[mac] == nil then - maclist[i] = mac - i = i + 1 - bw[mac] = {} - bw[mac]['down'] = 0 - bw[mac]['offdown'] = 0 - bw[mac]['up'] = 0 - bw[mac]['offup'] = 0 - end - s, e = line:find("\"down\":\"") - bs, be = line:find("\"", e+1) - down = tonumber(line:sub(e+1, bs-1)) - bw[mac]['down'] = bw[mac]['down'] + down - s, e = line:find("\"up\":\"") - bs, be = line:find("\"", e+1) - up = tonumber(line:sub(e+1, bs-1)) - bw[mac]['up'] = bw[mac]['up'] + up - s, e = line:find("\"offdown\":\"") - bs, be = line:find("\"", e+1) - offdown = tonumber(line:sub(e+1, bs-1)) - bw[mac]['offdown'] = bw[mac]['offdown'] + offdown - s, e = line:find("\"offup\":\"") - bs, be = line:find("\"", e+1) - offup = tonumber(line:sub(e+1, bs-1)) - bw[mac]['offup'] = bw[mac]['offup'] + offup - s, e = line:find("\"ip\":\"") - bs, be = line:find("\"", e+1) - bw[mac]['ip'] = line:sub(e+1, bs-1) - s, e = line:find("\"name\":\"") - bs, be = line:find("\"", e+1) - bw[mac]['name'] = line:sub(e+1, bs-1) - until 1==0 - -- day data - j=0 - tfile = io.open(monthUsageDB .. ".bk", "a") - tfile:write(startday, "\n") - while maclist[j] ~= nil do - mac = maclist[j] - dline = "\"mac\":\"" .. mac .. "\",\"down\":\"" .. bw[mac]['down'] .. "\",\"up\":\"" .. bw[mac]['up'] .. "\",\"offdown\":\"0\",\"offup\":\"0\",\"ip\":\"" .. bw[mac]['ip'] .. "\",\"name\":\"" .. bw[mac]['name'] .. "\"" - tfile:write(dline, "\n") - j = j + 1 - end - tfile:write(endday, "\n") - tfile:close() - end - -until 1==0 -file:close() \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup.sh deleted file mode 100644 index dba2368..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/backup.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -log() { - logger -t "wrtbwmon" "$@" -} - -# parameters -# -btype=$1 -cDay=$2 -monthlyUsageDB=$3 -dailyUsageDB=$4 -monthlyUsageBack=$5 -dailyUsageBack=$6 -pDay=$7 - -/usr/lib/bwmon/backup-daily.lua $dailyUsageDB -/usr/lib/bwmon/backup-mon.lua $monthlyUsageDB -cp -f $monthlyUsageDB".bk" $monthlyUsageDB -cp -f $dailyUsageDB".bk" $dailyUsageDB - -echo "start day $cDay" >> $monthlyUsageDB".bk" -cat $dailyUsageDB".bk" >> $monthlyUsageDB".bk" -echo "end day $cDay" >> $monthlyUsageDB".bk" - -enb=$(uci -q get bwmon.general.enabled) - -if [ $btype = "backup" ]; then - if [ "$enb" = "1" ]; then - cp -f $monthlyUsageDB".bk" $monthlyUsageBack - cp -f $dailyUsageDB".bk" $dailyUsageBack - fi -else - if [ $btype = "daily" ]; then - cp -f $monthlyUsageDB".bk" $monthlyUsageDB - if [ "$enb" = "1" ]; then - cp -f $monthlyUsageDB".bk" $monthlyUsageBack - fi - fi -fi - -rm -f $dailyUsageDB".bk" - -bwday=$(uci -q get modem.modeminfo1.bwday) -if [ ! -z "$bwday" ]; then - if [ $bwday = $pDay -a $bwday != "0" ]; then - if [ -e /usr/lib/bwmon/sendsms ]; then - /usr/lib/bwmon/sendsms.sh - fi - fi -fi \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/bwmon.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/bwmon.sh new file mode 100644 index 0000000..094c774 --- /dev/null +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/bwmon.sh @@ -0,0 +1,378 @@ +#!/bin/sh +. /usr/share/libubox/jshn.sh +. /lib/functions.sh + +log() { + modlog "wrtbwmon" "$@" +} + +ifname1="ifname" +if [ -e /etc/newstyle ]; then + ifname1="device" +fi + +networkFuncs=/lib/functions/network.sh +uci=`which uci 2>/dev/null` +nslookup=`which nslookup 2>/dev/null` +nvram=`which nvram 2>/dev/null` +binDir=/usr/sbin + +setbackup() { + extn=$(uci -q get bwmon.general.external) + if [ "$extn" = "0" ]; then + backPath=/usr/lib/bwmon/bwdata/ + else + if [ -e "$extn""/" ]; then + backPath=$extn"/data/" + else + backPath=/usr/lib/bwmon/bwdata/ + uci set bwmon.general.external="0" + uci commit bwmon + fi + fi + if [ ! -e "$backpath" ]; then + mkdir -p $backPath + fi +} + +detectIF() +{ + if [ -f "$networkFuncs" ]; then + IF=`. $networkFuncs; network_get_device netdev $1; echo $netdev` + [ -n "$IF" ] && echo $IF && return + fi + + if [ -n "$uci" -a -x "$uci" ]; then + IF=`$uci get network.${1}.$ifname 2>/dev/null` + [ $? -eq 0 -a -n "$IF" ] && echo $IF && return + fi + + if [ -n "$nvram" -a -x "$nvram" ]; then + IF=`$nvram get ${1}_$ifname 2>/dev/null` + [ $? -eq 0 -a -n "$IF" ] && echo $IF && return + fi +} + +detectWAN() +{ + [ -n "$WAN_IF" ] && echo $WAN_IF && return + wan=$(detectIF wan) + [ -n "$wan" ] && echo $wan && return + wan=$(ip route show 2>/dev/null | grep default | sed -re '/^default/ s/default.*dev +([^ ]+).*/\1/') + [ -n "$wan" ] && echo $wan && return + [ -f "$networkFuncs" ] && wan=$(. $networkFuncs; network_find_wan wan; echo $wan) + [ -n "$wan" ] && echo $wan && return +} + +device_get_stats() { + iface=$1 + st=$(ubus -v call network.interface.$iface status) + json_init + json_load "$st" + json_get_var iface l3_device + json_get_var status up + if [ $status = "1" ]; then + js="{ \"name\": \"$iface\" }" + st=$(ubus -v call network.device status "$js") + json_init + json_load "$st" + json_select statistics &>/dev/null + json_get_var val $2 + else + val="0" + fi + echo $val +} + +update() { + interfaces="" + wan=$(detectWAN) + C1=$(uci -q get modem.modem1.connected) + C2=$(uci -q get modem.modem2.connected) + if [ "$C1" = "1" ]; then + interfaces="wan1" + fi + if [ "$C2" = "1" ]; then + interfaces="interfaces wan2" + fi + WW=$(uci -q get bwmon.bwwan.wan) + if [ "$WW" -eq 1 ]; then + interfaces="$interfaces wan wwan2 wwan5" + fi + + val="0" + rxval="0" + txval="0" + for interface in $interfaces; do + rval=$(device_get_stats $interface "rx_bytes") + let rxval=$rxval+$rval + tval=$(device_get_stats $interface "tx_bytes") + let txval=$txval+$tval + done + +#log "Offset $offsetotal $offsetrx $offsettx" + orxval=$rxval + otxval=$txval + let xval=$rxval+$txval + otot=$xval + let val=$val+$xval +#log "Update $val $rxval $txval" + let rxval=$rxval-$offsetrx + let txval=$txval-$offsettx + let val=$val-$offsetotal + rtxval=$val + # backup daily values + let ttotal=$basedailytotal+$val + let trx=$basedailyrx+$rxval + let ttx=$basedailytx+$txval + echo "$ttotal" > $dataPath"daily.js" + echo "$trx" >> $dataPath"daily.js" + echo "$ttx" >> $dataPath"daily.js" + cd=$cDay + if [ $cd -lt 10 ]; then + ct="0"$cd + fi + dt="$cYear-$cMonth-$cd" + echo "$dt" >> $dataPath"daily.js" + # backup monthly values + let mtotal=$basemontotal+$val + let mrx=$basemonrx+$rxval + let mtx=$basemontx+$txval + alloc=$(uci -q get custom.bwallocate.allocate) + if [ -z "$alloc" ]; then + alloc=1000000000 + else + alloc=$alloc"000000000" + fi + /usr/lib/bwmon/excede.sh $mtotal $alloc + if [ -e /usr/lib/bwmon/period.sh ]; then + /usr/lib/bwmon/period.sh "$mtotal" + fi +} + +createAmt() +{ + while [ true ]; do + valid=$(cat /var/state/dnsmasqsec) + st=$(echo "$valid" | grep "ntpd says time is valid") + if [ ! -z "$st" ]; then + break + fi + sleep 10 + done + cYear=$(uci -q get bwmon.backup.year) + if [ "$cYear" = '0' ]; then + cYear=$(date +%Y) + cDay=$(date +%d) + cMonth=$(date +%m) + uci set bwmon.backup.year=$cYear + uci set bwmon.backup.month=$cMonth + uci set bwmon.backup.day=$cDay + uci commit bwmon + else + cYear=$(uci -q get bwmon.backup.year) + cMonth=$(uci -q get bwmon.backup.month) + cDay=$(uci -q get bwmon.backup.day) + fi + basedailytotal=$(uci -q get bwmon.backup.dailytotal) + basedailyrx=$(uci -q get bwmon.backup.dailyrx) + basedailytx=$(uci -q get bwmon.backup.dailytx) + basemontotal=$(uci -q get bwmon.backup.montotal) + basemonrx=$(uci -q get bwmon.backup.monrx) + basemontx=$(uci -q get bwmon.backup.montx) + if [ -z "$1" ]; then + offsetotal='0' + offsetrx='0' + offsettx='0' + else + offsetotal=$otot + offsetrx=$orxval + offsettx=$otxval + fi +} + +checkTime() +{ + pDay=$(date +%d) + pYear=$(date +%Y) + pMonth=$(date +%m) +#pDay=$(uci -q get bwmon.backup.tday) + if [ "$cDay" -ne "$pDay" ]; then +#log "Day Changed" + # save to periodic + /usr/lib/bwmon/createdata.lua + bt=$(uci -q get custom.bwday) + if [ -z "$bt" ]; then + uci set custom.bwday='bwday' + fi + uci set custom.bwday.bwday=$(convert_bytes $mtotal) + uci commit custom + bwday=$(uci -q get modem.modeminfo1.bwday) + if [ ! -z "$bwday" ]; then + if [ $bwday = $pDay -a $bwday != "0" ]; then + if [ -e /usr/lib/bwmon/sendsms ]; then + /usr/lib/bwmon/sendsms.sh & + fi + fi + fi + # backup month + offsetotal=$rtxval + offsetrx=$rxval + offsettx=$txval +#log "Offset $offsetotal $offsetrx $offsettx" + uci set bwmon.backup.montotal=$mtotal + uci set bwmon.backup.monrx=$mrx + uci set bwmon.backup.montx=$mtx + # clear daily + basedailytotal='0' + uci set bwmon.backup.dailytotal='0' + basedailyrx='0' + uci set bwmon.backup.dailyrx='0' + basedailytx='0' + uci set bwmon.backup.dailytx='0' + # increase days + days=$(uci -q get bwmon.backup.days) + let days=$days+1 + uci set bwmon.backup.days=$days + # day and date + uci set bwmon.backup.year=$pYear + uci set bwmon.backup.month=$pMonth + uci set bwmon.backup.day=$pDay + uci commit bwmon + basemontotal=$(uci -q get bwmon.backup.montotal) + basemonrx=$(uci -q get bwmon.backup.monrx) + basemontx=$(uci -q get bwmon.backup.montx) + cDay=$pDay + cMonth=$pMonth + cYear=$pYear + roll=$(uci -q get custom.bwallocate.rollover) + [ -z $roll ] && roll=1 + if [ "$roll" -eq "$pDay" ]; then +#log "Month Change" + # clear monthly + basemontotal='0' + mtotal='0' + uci set bwmon.backup.montotal='0' + basemonrx='0' + mrx='0' + uci set bwmon.backup.monrx='0' + basemontx='0' + mtx='0' + uci -q get bwmon.backup.montx='0' + # reset days + uci set bwmon.backup.days='1' + uci commit bwmon + uci set custom.texting.used='0' + uci commit custom + if [ -e /usr/lib/bwmon/periodreset.sh ]; then + /usr/lib/bwmon/periodreset.sh + fi + fi + fi +} +checkBackup() +{ + CURRTIME=$(date +%s) + let ELAPSE=CURRTIME-STARTIMEZ + bs=$(uci -q get bwmon.general.backup) +#bs="1" + let "bs=$bs*60" + backup_time=$bs + en=$(uci -q get bwmon.general.enabled) + if [ "$en" = '1' ]; then + if [ $ELAPSE -gt $backup_time ]; then + STARTIMEZ=$CURRTIME + # save monthly + uci set bwmon.backup.montotal=$mtotal + uci set bwmon.backup.monrx=$mrx + uci set bwmon.backup.montx=$mtx + # save daily + uci set bwmon.backup.dailytotal=$ttotal + uci set bwmon.backup.dailyrx=$trx + uci set bwmon.backup.dailytx=$ttx + # save day and date + uci set bwmon.backup.year=$cYear + uci set bwmon.backup.month=$cMonth + uci set bwmon.backup.day=$cDay + # total days + uci commit bwmon +#log "Backup $mtotal $val" + fi + fi +} + +convert_bytes() { + local val=$1 + rm -f /tmp/bytes + /usr/lib/bwmon/convertbytes.lua $val + source /tmp/bytes + echo "$BYTES" +} + +createGUI() +{ + days=$(uci -q get bwmon.backup.days) + echo "$days" > /tmp/bwdata + tb=$(convert_bytes $mtotal) + echo "$mtotal" >> /tmp/bwdata + echo "$tb" >> /tmp/bwdata + tb=$(convert_bytes $mrx) + echo "$mrx" >> /tmp/bwdata + echo "$tb" >> /tmp/bwdata + tb=$(convert_bytes $mtx) + echo "$mtx" >> /tmp/bwdata + echo "$tb" >> /tmp/bwdata + let ptotal=$mtotal/$days + let ptotal=$ptotal*30 + tb=$(convert_bytes $ptotal) + echo "$ptotal" >> /tmp/bwdata + echo "$tb" >> /tmp/bwdata + alloc=$(uci -q get custom.bwallocate.allocate) + pass=$(uci -q get custom.bwallocate.password) + if [ -z "$alloc" ]; then + alloc=1000000000 + pass="password" + else + alloc=$alloc"000000000" + fi + tb=$(convert_bytes $alloc) + echo "$alloc" >> /tmp/bwdata + echo "$tb" >> /tmp/bwdata + echo "$pass" >> /tmp/bwdata + echo "0" >> /tmp/bwdata +} + +basePath="/tmp/bwmon/" +mkdir -p $basePath"bwdata" +dataPath=$basePath"bwdata/" +setbackup +STARTIMEX=$(date +%s) +STARTIMEY=$(date +%s) +STARTIMEZ=$(date +%s) +update_time=20 + +createAmt +while [ true ] ; do + update + if [ -e /tmp/bwchange ]; then + newamt=$(cat /tmp/bwchange) + rm -f /tmp/bwchange + uci set bwmon.backup.dailytotal=$newamt + uci set bwmon.backup.dailyrx=$newamt + uci set bwmon.backup.dailytx=0 + uci set bwmon.backup.montotal=$newamt + uci set bwmon.backup.monrx=$newamt + uci set bwmon.backup.montx=0 + uci commit bwmon + createAmt 1 + mtotal=0 + mrx=0 + mtx=0 + createGUI + fi + checkTime + checkBackup + createGUI +#log "$(convert_bytes $mtotal) $(convert_bytes $mrx) $(convert_bytes $mtx) $(convert_bytes $val) $(convert_bytes $rxval) $(convert_bytes $txval)" + sleep $update_time +done \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/cleanup.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/cleanup.lua deleted file mode 100644 index 2c5d764..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/cleanup.lua +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/lua - -filepost = "-mac_data.js" -dirname = '/usr/lib/bwmon/data' - -function clean() - nummon = 0 - months = {} - f = io.popen('/bin/ls ' .. dirname) - for name in f:lines() do - s, e = name:find(filepost) - if s ~= nil then - nummon = nummon + 1 - months[nummon] = dirname .. "/" .. name - end - end - f:close() - - count = 1 - if nummon > 0 then - for i=nummon,1,-1 do - if count > 3 then - os.execute("rm -f " .. months[i]) - end - count = count + 1 - end - end -end - -clean() -dirname = '/tmp/bwmon/data' -clean() \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/convertbytes.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/convertbytes.lua new file mode 100644 index 0000000..a3d69a4 --- /dev/null +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/convertbytes.lua @@ -0,0 +1,30 @@ +#!/usr/bin/lua + +bytes=arg[1] + +function ltrim(s) + return s:match'^%s*(.*)' +end + +function calc(total) + if total < 1000000 then + tstr = string.format("%.2f", total) + tstr = string.format("%.2f", total/1000) + tfm = " K" + else + if total < 1000000000 then + tstr = string.format("%.2f", total/1000000) + tfm = " MB" + else + tstr = string.format("%.2f", total/1000000000) + tfm = " GB" + end + end + str = tstr .. tfm + return ltrim(str) +end + +conbytes = "BYTES='" .. calc(tonumber(bytes)) .. "'" +tfile = io.open("/tmp/bytes", "w") +tfile:write(conbytes, "\n") +tfile:close() \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/create.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/create.sh deleted file mode 100644 index 348d873..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/create.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -log() { - logger -t "createdata" "$@" -} - -lua /usr/lib/bwmon/create_data.lua -sleep 60 -while [ true ] -do - result=`ps | grep -i "create_data.lua" | grep -v "grep" | wc -l` - if [ $result -lt 1 ]; then - lua /usr/lib/bwmon/create_data.lua - fi - sleep 60 -done \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/create_data.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/create_data.lua deleted file mode 100644 index fc3fba8..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/create_data.lua +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/lua - -dirname = '/tmp/bwmon/data' -filepost = "-mac_data.js.bk" -bw = {} -maclist = {} -devices = {} -totaldevices = 0 -totaldown = 0 -totalup = 0 -total = 0 - -printf = function(s,...) - local ss = s:format(...) - os.execute("/usr/lib/rooter/logprint.sh " .. ss) -end - -function ltrim(s) - return s:match'^%s*(.*)' -end - -function calc(total) - if total < 1000 then - tstr = string.format("%.2f", total) - tfm = " K" - else - if total < 1000000 then - tstr = string.format("%.2f", total/1000) - tfm = " MB" - else - tstr = string.format("%.2f", total/1000000) - tfm = " GB" - end - end - str = tstr .. tfm - return ltrim(str) -end - -function monthly(datafile) - file = io.open(datafile, "r") - i = 0 - dayx = 0 - repeat - line = file:read("*line") - if line == nil then - break - end - s, e = line:find("start day") - if s ~= nil then - dayx = dayx + 1 - repeat - line = file:read("*line") - s, e = line:find("end day") - if s ~= nil then - break - end - s, e = line:find("\"mac\":\"") - bs, be = line:find("\"", e+1) - mac = line:sub(e+1, bs-1) - if bw[mac] == nil then - maclist[i] = mac - i = i + 1 - bw[mac] = {} - bw[mac]['down'] = 0 - bw[mac]['offdown'] = 0 - bw[mac]['up'] = 0 - bw[mac]['offup'] = 0 - end - s, e = line:find("\"down\":\"") - bs, be = line:find("\"", e+1) - down = tonumber(line:sub(e+1, bs-1)) - bw[mac]['down'] = bw[mac]['down'] + down - s, e = line:find("\"up\":\"") - bs, be = line:find("\"", e+1) - up = tonumber(line:sub(e+1, bs-1)) - bw[mac]['up'] = bw[mac]['up'] + up - s, e = line:find("\"offdown\":\"") - bs, be = line:find("\"", e+1) - offdown = tonumber(line:sub(e+1, bs-1)) - bw[mac]['offdown'] = bw[mac]['offdown'] + offdown - s, e = line:find("\"offup\":\"") - bs, be = line:find("\"", e+1) - offup = tonumber(line:sub(e+1, bs-1)) - bw[mac]['offup'] = bw[mac]['offup'] + offup - s, e = line:find("\"ip\":\"") - bs, be = line:find("\"", e+1) - bw[mac]['ip'] = line:sub(e+1, bs-1) - s, e = line:find("\"name\":\"") - bs, be = line:find("\"", e+1) - bw[mac]['name'] = line:sub(e+1, bs-1) - until 1==0 - end - until 1==0 - file:close() - return dayx -end - -function totals(bw, maclist, dayz) - totaldown = 0 - totalup = 0 - utotaldown = 0 - utotalup = 0 - j=0 - while maclist[j] ~= nil do - totaldown = totaldown + bw[maclist[j]]['down'] - totalup = totalup + bw[maclist[j]]['up'] - utotaldown = utotaldown + bw[maclist[j]]['offdown'] - utotalup = utotalup + bw[maclist[j]]['offup'] - j = j + 1 - end - total = totalup + totaldown - ptotal = (total / dayz) * 30 -end - -function showdevices(bw, maclist) - k = 0 - while maclist[k] ~= nil do - k = k + 1 - end - if k > 0 then - j = 0 - while maclist[j] ~= nil do - dtot = bw[maclist[j]]['down'] + bw[maclist[j]]['up'] - devices[j] = bw[maclist[j]]['ip'] .."|" .. maclist[j] - devices[j] = devices[j] .. "|" .. calc(bw[maclist[j]]['down']) .. "|" .. calc(bw[maclist[j]]['up']) - devices[j] = devices[j] .. "|" .. calc(dtot) .. "|" .. bw[maclist[j]]['name'] - j = j + 1 - end - end - totaldevices = j -end - -os.execute("echo 0 > /tmp/lockbw") -dataname = nil -f = io.popen('/bin/ls ' .. dirname) -for name in f:lines() do - s, e = name:find(filepost) - if s ~= nil then - dataname = dirname .. "/" .. name - end -end -f:close() - -if dataname ~= nil then - days = monthly(dataname) - totals(bw, maclist, days) - tfile = io.open("/tmp/bwdata", "w") - tfile:write(days, "\n") - tfile:write(tostring(total), "\n") - tfile:write(calc(total), "\n") - tfile:write(tostring(totaldown), "\n") - tfile:write(calc(totaldown), "\n") - tfile:write(tostring(totalup), "\n") - tfile:write(calc(totalup), "\n") - tfile:write(tostring(ptotal), "\n") - tfile:write(calc(ptotal), "\n") - -- - -- allocated bandwidth in K - -- - bwallo='rm -f /tmp/bwallo; x=$(uci -q get custom.bwallocate.allocate); echo $x >> /tmp/bwallo; x=$(uci -q get custom.bwallocate.password); echo $x >> /tmp/bwallo' - os.execute(bwallo) - file = io.open("/tmp/bwallo", "r") - if file == nil then - allo = 1000000000 - passw = "password" - else - allos = file:read("*line") - allo = tonumber(allos) * 1000000 - passw = file:read("*line") - file:close() - end - tfile:write(tostring(allo), "\n") - tfile:write(calc(allo), "\n") - tfile:write(passw, "\n") - - showdevices(bw, maclist) - tfile:write(tostring(totaldevices), "\n") - if totaldevices > 0 then - for i=0, totaldevices-1 do - tfile:write(devices[i], "\n") - end - end - tfile:close() -else - tfile = io.open("/tmp/bwdata", "w") - tfile:write("0\n") - tfile:write("0\n") - tfile:close() -end -os.execute("rm -f /tmp/lockbw") -os.execute("/usr/lib/bwmon/excede.sh " .. tostring(total) .. " " .. tostring(allo) .. " " .. tostring(ptotal)) -os.execute("/usr/lib/bwmon/savetot.sh \"" .. calc(total) .. "\"") -os.execute("/usr/lib/bwmon/perday.lua") diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/createdata.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/createdata.lua new file mode 100644 index 0000000..66b459c --- /dev/null +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/createdata.lua @@ -0,0 +1,127 @@ +#!/usr/bin/lua + +monthly = '/usr/lib/bwmon/data/monthly.data' +datafile='/tmp/bwmon/bwdata/daily.js' +monline = {} +monlist = {} + +function ltrim(s) + return s:match'^%s*(.*)' +end + +function calc(total) + if total < 1000000 then + tstr = string.format("%.2f", total) + tstr = string.format("%.2f", total/1000) + tfm = " K" + else + if total < 1000000000 then + tstr = string.format("%.2f", total/1000000) + tfm = " MB" + else + tstr = string.format("%.2f", total/1000000000) + tfm = " GB" + end + end + str = tstr .. tfm + return ltrim(str) +end + +local function bubblesort(a) + repeat + local swapped = false + for i = 1, table.getn(a) do + if a[i - 1] < a[i] then + a[i], a[i - 1] = a[i - 1], a[i] + swapped = true + end -- if + end -- for + until swapped == false +end + +function ConBytes(line) + local s, e, bs, be + s, e = line:find(" ") + bs, be = line:find("K", e+1) + if bs == nil then + bs, be = line:find("MB", e+1) + if bs == nil then + val = tonumber(line:sub(1, e-1)) * 1000000000 + else + val = tonumber(line:sub(1, e-1)) * 1000000 + end + else + val = tonumber(line:sub(1, e-1)) * 1000 + end + return val +end + +kdwn = 0 +kup = 0 +ktotal = 0 +file = io.open(datafile, "r") +if file ~= nil then + total = file:read("*line") + dwn = file:read("*line") + up = file:read("*line") + lin = file:read("*line") + file:close() + kdwn = tonumber(dwn) + kup = tonumber(up) + ktotal = tonumber(total) + dwn = calc(tonumber(dwn)) + up = calc(tonumber(up)) + total = calc(tonumber(total)) + print(ktotal, kdwn, kup) + dataline = lin .. "|" .. dwn .. "|" .. up .. "|" .. total + print(dataline) + monline[lin] = dataline + monlist[0] = lin + ksize = 1 +end +k = 1 +tfile = io.open(monthly, "r") +if tfile ~= nil then + ksize = tfile:read("*line") + ksize = tostring(tonumber(ksize) + 1) + kdwn1 = tfile:read("*line") + kdwn1=ConBytes(kdwn1) + kdwn = (kdwn1 + kdwn) + kup1 = tfile:read("*line") + kup1=ConBytes(kup1) + kup = (kup1 + kup) + ktotal1 = tfile:read("*line") + ktotal1=ConBytes(ktotal1) + ktotal = (ktotal1 + ktotal) + repeat + line = tfile:read("*line") + if line == nil then + break + end + s, e = line:find("|") + ymd = line:sub(1, s-1) + monline[ymd] = line + monlist[k] = ymd + k = k + 1 + until 1==0 + tfile:close() + bubblesort(monlist) +end +if k > 30 then + k = 30 +end + +tfile = io.open(monthly, "w") +tfile:write(tostring(k), "\n") +tfile:write(calc(kdwn), "\n") +tfile:write(calc(kup), "\n") +tfile:write(calc(ktotal), "\n") +for j = 0,k-1 +do + lin = monlist[j] + dataline = monline[lin] + print(dataline) + tfile:write(dataline, "\n") +end +tfile:close() +--os.execute("uci set custom.bwday.bwday=" .. calc(ktotal) .. ";uci commit custom") diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/datainc.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/datainc.lua index 6ef57c4..ba93fce 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/datainc.lua +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/datainc.lua @@ -4,7 +4,7 @@ prev = arg[1] -- previous increment in GB incr = arg[2] -- fixed increment in GB used = arg[3] -- amt used in Kb -used = used / 1000000 -- used in GB +used = used / 1000000000 -- used in GB current = prev + incr running = "0" if used >= current then diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/dataper.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/dataper.lua index d5d0527..a287094 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/dataper.lua +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/dataper.lua @@ -4,10 +4,11 @@ alloc = arg[1] -- allocate increment in GB per = arg[2] -- fixed percentage in GB used = arg[3] -- amt used in Kb -used = used / 10000 -- used in GB -percent = used / alloc +--used = used / 10000 -- used in GB +percent = (used / alloc) * 100 + running = "0" -if percent >= per then +if percent >= tonumber(per) then running = "1" end diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/dotext.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/dotext.sh index 651c410..2aecaca 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/dotext.sh +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/dotext.sh @@ -2,11 +2,11 @@ . /lib/functions.sh log() { - logger -t "TEXTING" "$@" + logger -t "TEXTING" "$@" } getbw() { - alloc=$(uci -q get custom.bwallocate.allocate)"000000" + alloc=$(uci -q get custom.bwallocate.allocate)"000000000" if [ -e /tmp/bwdata ]; then while IFS= read -r line; do days=$line diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/excede.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/excede.sh index 5c9af09..f1e0679 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/excede.sh +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/excede.sh @@ -22,73 +22,84 @@ do_throttle() { fi } -lock=$(uci -q get custom.bwallocate.lock) -if [ $lock = "1" ]; then - enb=$(uci -q get custom.bwallocate.enabled) - if [ $enb = '1' ]; then - allocate=$2 - total=$1 - /usr/lib/bwmon/block 0 - action=$(uci -q get custom.bwallocate.action) - if [ -z $action ]; then - action=0 - fi - if [ ! -e /usr/lib/throttle/throttle.sh ]; then - action=0 - fi - if [ $action != "2" ]; then - if [ $total -gt $allocate ]; then - if [ $action = "0" ]; then - if [ -e /etc/nodogsplash/control ]; then - /etc/nodogsplash/control block +bb="$(uci -q get custom.bwallocate.manual)" +if [ "$bb" != "1" ]; then + lock=$(uci -q get custom.bwallocate.lock) + if [ $lock = "1" ]; then + enb=$(uci -q get custom.bwallocate.enabled) + if [ $enb = '1' ]; then + allocate=$2 + total=$1 + /usr/lib/bwmon/block 0 + action=$(uci -q get custom.bwallocate.action) + if [ -z $action ]; then + action=0 + fi + if [ ! -e /usr/lib/throttle/throttle.sh ]; then + action=0 + fi + uci set custom.bwallocate.status='0' + uci commit custom + if [ $action != "2" ]; then + if [ $total -gt $allocate ]; then + if [ $action = "0" ]; then + if [ -e /etc/nodogsplash/control ]; then + /etc/nodogsplash/control block + else + /usr/lib/bwmon/block 1 + fi + uci set custom.bwallocate.status='1' + uci commit custom else - /usr/lib/bwmon/block 1 + down=$(uci -q get custom.bwallocate.down) + if [ -z $down ]; then + down=5 + fi + up=$(uci -q get custom.bwallocate.up) + if [ -z $up ]; then + up=2 + fi + /usr/lib/throttle/throttle.sh start $down $up + uci set custom.bwallocate.status='2' + uci commit custom fi else - down=$(uci -q get custom.bwallocate.down) - if [ -z $down ]; then - down=5 + if [ -e /usr/lib/throttle/throttle.sh ]; then + /usr/lib/throttle/throttle.sh stop fi - up=$(uci -q get custom.bwallocate.up) - if [ -z $up ]; then - up=2 + if [ -e /etc/nodogsplash/control ]; then + /etc/nodogsplash/control unblock fi - /usr/lib/throttle/throttle.sh start $down $up + /usr/lib/bwmon/block 0 fi else - if [ -e /usr/lib/throttle/throttle.sh ]; then - /usr/lib/throttle/throttle.sh stop + meth=$(uci -q get custom.bwallocate.meth) + if [ -z $meth ]; then + meth="0" fi - if [ -e /etc/nodogsplash/control ]; then - /etc/nodogsplash/control unblock + if [ $meth = "0" ]; then + amt=$total + else + amt=$3 fi - /usr/lib/bwmon/block 0 - fi - else - meth=$(uci -q get custom.bwallocate.meth) - if [ -z $meth ]; then - meth="0" - fi - if [ $meth = "0" ]; then - amt=$total - else - amt=$3 - fi - speed="0" - baselimit="0" - config_load custom - config_foreach do_throttle throttle - if [ $speed != "0" ]; then - /usr/lib/bwmon/float.lua "$speed" - source /tmp/float - /usr/lib/throttle/throttle.sh start $SPEED $SPEED 1 - log "Throttled to $speed Mbps" - else - if [ -e /usr/lib/throttle/throttle.sh ]; then - /usr/lib/throttle/throttle.sh stop + speed="0" + baselimit="0" + config_load custom + config_foreach do_throttle throttle + if [ $speed != "0" ]; then + /usr/lib/bwmon/float.lua "$speed" + source /tmp/float + /usr/lib/throttle/throttle.sh start $SPEED $SPEED 1 + log "Throttled to $speed Mbps" + uci set custom.bwallocate.status='2' + uci commit custom + else + if [ -e /usr/lib/throttle/throttle.sh ]; then + /usr/lib/throttle/throttle.sh stop + fi fi + fi - fi fi fi \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/external.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/external.sh index 9b11296..9120d58 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/external.sh +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/external.sh @@ -13,12 +13,9 @@ if [ "$ext" = "$external" ]; then else uci set bwmon.general.external=$external uci commit bwmon - PID=$(ps |grep "wrtbwmon.sh" | grep -v grep |head -n 1 | awk '{print $1}') - PID1=$(ps |grep "create.sh" | grep -v grep |head -n 1 | awk '{print $1}') + PID=$(ps |grep "bwmon.sh" | grep -v grep |head -n 1 | awk '{print $1}') if [ ! -z "$PID" ]; then kill -9 $PID - kill -9 $PID1 fi - /usr/lib/bwmon/wrtbwmon.sh & - /usr/lib/bwmon/create.sh & + /usr/lib/bwmon/bwmon.sh & fi \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/genline.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/genline.sh new file mode 100644 index 0000000..825d222 --- /dev/null +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/genline.sh @@ -0,0 +1,64 @@ +#!/bin/sh +. /usr/share/libubox/jshn.sh +. /lib/functions.sh + +genline() { + MONLIST=$MONLIST"" + t1="" + t2="" + t3="" + t4="" + t5="" + MONLIST=$MONLIST$t1$t2$t3$t4$t5"" +} + +bwdata() { + START="-" + END="-" + header=0 + while IFS= read -r line; do + if [ $header -eq 0 ]; then + days=$line + read -r line + DOWN=$line + read -r line + UP=$line + read -r line + TOTAL=$line + read -r line + line=$(echo $line" " | tr "|" ",") + END=$(echo $line | cut -d, -f1) + START=$END + updata=$(echo $line | cut -d, -f2) + downdata=$(echo $line | cut -d, -f3) + totaldata=$(echo $line | cut -d, -f4) + genline + read -r line + header=1 + if [ -z "$line" ]; then + break + fi + fi + line=$(echo $line" " | tr "|" ",") + START=$(echo $line | cut -d, -f1) + updata=$(echo $line | cut -d, -f2) + downdata=$(echo $line | cut -d, -f3) + totaldata=$(echo $line | cut -d, -f4) + genline + + done < /usr/lib/bwmon/data/monthly.data +} + + MONLIST="" + rm -f /tmp/monlist + rm -f /tmp/montot + if [ -e /usr/lib/bwmon/data/monthly.data ]; then + bwdata + echo $MONLIST > /tmp/monlist + echo $days > /tmp/montot + echo $DOWN >> /tmp/montot + echo $UP >> /tmp/montot + echo $TOTAL >> /tmp/montot + + fi + \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/perday.lua b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/perday.lua deleted file mode 100644 index 1f133ef..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/perday.lua +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/bin/lua - -function ltrim(s) - return s:match'^%s*(.*)' -end - -function calc(total) - if total < 1000 then - tstr = string.format("%.2f", total) - tfm = " K" - else - if total < 1000000 then - tstr = string.format("%.2f", total/1000) - tfm = " MB" - else - tstr = string.format("%.2f", total/1000000) - tfm = " GB" - end - end - str = tstr .. tfm - return ltrim(str) -end - -local function bubblesort(a) - repeat - local swapped = false - for i = 1, table.getn(a) do - if a[i - 1] < a[i] then - a[i], a[i - 1] = a[i - 1], a[i] - swapped = true - end -- if - end -- for - until swapped == false -end - -function ConBytes(line) - local s, e, bs, be - s, e = line:find(" ") - bs, be = line:find("K", e+1) - if bs == nil then - bs, be = line:find("MB", e+1) - if bs == nil then - val = tonumber(line:sub(1, e-1)) * 1000000 - else - val = tonumber(line:sub(1, e-1)) * 1000 - end - else - val = tonumber(line:sub(1, e-1)) - end - return val -end - -dirname = '/usr/lib/bwmon/data' -filepost = "-mac_data.js" -monthly = dirname .. "/monthly.data" -daylist = {} -dayline = {} -monlist = {} -monline = {} - -dataname = nil -f = io.popen('/bin/ls ' .. dirname) -for name in f:lines() do - s, e = name:find(filepost) - if s ~= nil then - dataname = name - end -end -f:close() - -if dataname ~= nil then - yearmon = dataname:sub(1, 7) - datafile = dirname .. "/" .. dataname - file = io.open(datafile, "r") - i = 0 - repeat - line = file:read("*line") - if line == nil then - break - end - s, e = line:find("start day") - if s ~= nil then - day = line:sub(e+1) - nday = tonumber(day) - day= tostring(nday) - if nday < 10 then - day = "0" .. day - end - yearmonday = yearmon .. "-" .. day - - daydwn = 0 - dayup = 0 - repeat - line = file:read("*line") - s, e = line:find("end day") - if s ~= nil then - dayt = dayup + daydwn - if dayt > 0 then - daylist[i] = yearmonday - i = i + 1 - dayline[yearmonday] = {} - dayline[yearmonday]['down'] = daydwn - dayline[yearmonday]['up'] = dayup - dayline[yearmonday]['total'] = dayup + daydwn - end - break - end - s, e = line:find("\"down\":\"") - bs, be = line:find("\"", e+1) - daydwn = daydwn + tonumber(line:sub(e+1, bs-1)) - s, e = line:find("\"up\":\"") - bs, be = line:find("\"", e+1) - dayup = dayup + tonumber(line:sub(e+1, bs-1)) - until 1==0 - end - until 1==0 - - if i > 0 then - tfile = io.open(monthly, "r") - if tfile == nil then - for j = 0,i-1 - do - lin = daylist[j] - monlist[j] = lin - monline[lin] = {} - dwn = calc(dayline[lin]['down']) - up = calc(dayline[lin]['up']) - total = calc(dayline[lin]['total']) - dataline = lin .. "|" .. dwn .. "|" .. up .. "|" .. total - monline[lin]['data'] = dataline - end - k = i - else - k = 0 - ksize = tfile:read("*line") - kdwn = tfile:read("*line") - kup = tfile:read("*line") - ktotal = tfile:read("*line") - repeat - line = tfile:read("*line") - if line == nil then - break - end - ymd = line:sub(1,10) - monlist[k] = ymd - k = k + 1 - monline[ymd] = {} - monline[ymd]['data'] = line - until 1==0 - tfile:close() - - for j = 0,i-1 - do - lin = daylist[j] - if monline[lin] == nil then - monlist[k] = lin - k = k + 1 - monline[lin] = {} - end - dwn = calc(dayline[lin]['down']) - up = calc(dayline[lin]['up']) - total = calc(dayline[lin]['total']) - dataline = lin .. "|" .. dwn .. "|" .. up .. "|" .. total - monline[lin]['data'] = dataline - end - end - - bubblesort(monlist) - - tfile = io.open(monthly, "w") - if k > 30 then - k = 30 - end - tfile:write(tostring(k), "\n") - fdown = 0 - fup = 0 - ftotal = 0 - for j = 0,k-1 - do - lin = monlist[j] - dataline = monline[lin]['data'] - s, e = dataline:find("|") - if s ~= nil then - bs, be = dataline:find("|", e+1) - fdown = ConBytes(dataline:sub(e+1, be-1)) + fdown - s, e = dataline:find("|", be+1) - fup = ConBytes(dataline:sub(be+1, e-1)) + fup - ftotal = ConBytes(dataline:sub(e+1)) + ftotal - end - end - tfile:write(calc(fdown), "\n") - tfile:write(calc(fup), "\n") - tfile:write(calc(ftotal), "\n") - for j = 0,k-1 - do - lin = monlist[j] - dataline = monline[lin]['data'] - tfile:write(dataline, "\n") - end - tfile:close() - end - - file:close() -end \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/process.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/process.sh index 42e38b6..f4e4d7d 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/process.sh +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/process.sh @@ -3,18 +3,3 @@ log() { logger -t "BWmon Process" "$@" } - -running=0 -if [ -e "/tmp/WRTbmon" ]; then - running=1 -fi - -sleep 5 - -if [ $running = 0 ]; then - log "Enable BandWidthMonitor" - /usr/lib/bwmon/wrtbwmon.sh & -fi - - - diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/savetot.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/savetot.sh deleted file mode 100644 index 1a780ba..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/savetot.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -log() { - logger -t "save total" "$@" -} - -total=$1 - -uci set custom.bwday.bwday="$total" -uci commit custom \ No newline at end of file diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/textbw.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/textbw.sh index 5d9d589..1234862 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/textbw.sh +++ b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/textbw.sh @@ -2,7 +2,7 @@ . /lib/functions.sh log() { - logger -t "TEXTING" "$@" + modlog "TEXTING" "$@" } checktime() { @@ -60,7 +60,7 @@ checktime() { } getbw() { - alloc=$(uci -q get custom.bwallocate.allocate)"000000" + alloc=$(uci -q get custom.bwallocate.allocate)"000000000" if [ -e /tmp/bwdata ]; then while IFS= read -r line; do days=$line @@ -96,7 +96,7 @@ checkper() { istime=$(checktime) if [ $istime = '1' ]; then prev=$(uci -q get custom.texting.used) - per=$(uci -q get custom.bwallocate.percent) + per=$(uci -q get custom.texting.percent) persent=$(uci -q get custom.bwallocate.persent) if [ "$persent" != "1" ]; then getbw @@ -141,7 +141,7 @@ do if [ $running = "1" ]; then EN=$(uci -q get custom.texting.text) if [ $EN = "1" ]; then - /usr/lib/bwmon/dotext.sh + /usr/lib/bwmon/dotext.sh & sleep $delay fi else diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/wrtbwmon.sh b/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/wrtbwmon.sh deleted file mode 100644 index 55e3924..0000000 --- a/rooter/0optionalapps/bwmon/files/usr/lib/bwmon/wrtbwmon.sh +++ /dev/null @@ -1,508 +0,0 @@ -#!/bin/sh - -setbackup() { - extn=$(uci -q get bwmon.general.external) - if [ "$extn" = "0" ]; then - backPath=/usr/lib/bwmon/data/ - else - if [ -e "$extn""/" ]; then - backPath=$extn"/data/" - else - backPath=/usr/lib/bwmon/data/ - uci set bwmon.general.external="0" - uci commit bwmon - fi - fi - if [ ! -e "$backpath" ]; then - mkdir -p $backPath - fi -} - -LAN_TYPE=$(uci get network.lan.ipaddr | awk -F. ' { print $1"."$2 }') -LEASES_FILE=/tmp/dhcp.leases -lockDir=/tmp/WRTbmon - -ifname="ifname" -source /etc/openwrt_release -twone=$(echo "$DISTRIB_RELEASE" | grep "21.02") -if [ ! -z "$twone" ]; then - ifname="device" -fi - - -[ ! -d "$lockDir" ] && mkdir "$lockDir" -basePath="/tmp/bwmon/" -mkdir -p $basePath"data" -dataPath=$basePath"data/" -setbackup -lockDir1=/tmp/wrtbwmon1.lock -lockDir=/tmp/wrtbwmon.lock -mkdir -p "$lockDir" -pidFile=$lockDir/pid -STARTIMEX=$(date +%s) -STARTIMEY=$(date +%s) -STARTIMEZ=$(date +%s) -cYear=$(date +%Y) -cDay=$(date +%d) -cMonth=$(date +%m) -setup_time=60 -update_time=60 -bs=$(uci -q get bwmon.general.backup) -let "bs=$bs*60" -backup_time=$bs -pause=30 -unlimited="peak" - -networkFuncs=/lib/functions/network.sh -uci=`which uci 2>/dev/null` -nslookup=`which nslookup 2>/dev/null` -nvram=`which nvram 2>/dev/null` -binDir=/usr/sbin -chains='INPUT OUTPUT FORWARD' -DEBUG= -interfaces='eth0' # in addition to detected WAN -DB="/tmp/usage.db" -mode= - -log() { - logger -t "wrtbwmon" "$@" -} - -header="#mac,ip,iface,in,out,total,first_date,last_date" - -createDbIfMissing() -{ - [ ! -f "$DB" ] && rm -f $DB;echo $header > "$DB" -} - -checkWAN() -{ - [ -z "$wan" ] && return -} - -lookup() -{ - MAC=$1 - IP=$2 - userDB=$3 - for USERSFILE in $userDB /tmp/dhcp.leases /tmp/dnsmasq.conf /etc/dnsmasq.conf /etc/hosts; do - [ -e "$USERSFILE" ] || continue - case $USERSFILE in - /tmp/dhcp.leases ) - USER=$(grep -i "$MAC" $USERSFILE | cut -f4 -s -d' ') - ;; - /etc/hosts ) - USER=$(grep "^$IP " $USERSFILE | cut -f2 -s -d' ') - ;; - * ) - USER=$(grep -i "$MAC" "$USERSFILE" | cut -f2 -s -d,) - ;; - esac - [ "$USER" = "*" ] && USER= - [ -n "$USER" ] && break - done - if [ -n "$DO_RDNS" -a -z "$USER" -a "$IP" != "NA" -a -n "$nslookup" ]; then - USER=`$nslookup $IP $DNS | awk '!/server can/{if($4){print $4; exit}}' | sed -re 's/[.]$//'` - fi - [ -z "$USER" ] && USER=${MAC} - echo $USER -} - -detectIF() -{ - if [ -f "$networkFuncs" ]; then - IF=`. $networkFuncs; network_get_device netdev $1; echo $netdev` - [ -n "$IF" ] && echo $IF && return - fi - - if [ -n "$uci" -a -x "$uci" ]; then - IF=`$uci get network.${1}.$ifname 2>/dev/null` - [ $? -eq 0 -a -n "$IF" ] && echo $IF && return - fi - - if [ -n "$nvram" -a -x "$nvram" ]; then - IF=`$nvram get ${1}_$ifname 2>/dev/null` - [ $? -eq 0 -a -n "$IF" ] && echo $IF && return - fi -} - -detectLAN() -{ - [ -e /sys/class/net/br-lan ] && echo br-lan && return - lan=$(detectIF lan) - [ -n "$lan" ] && echo $lan && return -} - -detectWAN() -{ - [ -n "$WAN_IF" ] && echo $WAN_IF && return - wan=$(detectIF wan) - [ -n "$wan" ] && echo $wan && return - wan=$(ip route show 2>/dev/null | grep default | sed -re '/^default/ s/default.*dev +([^ ]+).*/\1/') - [ -n "$wan" ] && echo $wan && return - [ -f "$networkFuncs" ] && wan=$(. $networkFuncs; network_find_wan wan; echo $wan) - [ -n "$wan" ] && echo $wan && return -} - -lock() -{ - attempts=0 - while [ $attempts -lt 10 ]; do - mkdir $lockDir1 2>/dev/null && break - attempts=$((attempts+1)) - pid=`cat $pidFile 2>/dev/null` - if [ -n "$pid" ]; then - if [ -d "/proc/$pid" ]; then - [ -n "$DEBUG" ] && echo "WARNING: Lockfile detected but process $(cat $pidFile) does not exist !" - rm -rf $lockDir1 - else - sleep 1 - fi - fi - done - mkdir $lockDir1 2>/dev/null - echo $$ > $pidFile - [ -n "$DEBUG" ] && echo $$ "got lock after $attempts attempts" - trap '' INT -} - -unlock() -{ - rm -rf $lockDir1 - [ -n "$DEBUG" ] && echo $$ "released lock" - trap "rm -f /tmp/*_$$.tmp; kill $$" INT -} - -# chain -newChain() -{ - chain=$1 - # Create the RRDIPT_$chain chain (it doesn't matter if it already exists). - iptables -t mangle -N RRDIPT_$chain 2> /dev/null - - # Add the RRDIPT_$chain CHAIN to the $chain chain if not present - iptables -t mangle -C $chain -j RRDIPT_$chain 2>/dev/null - if [ $? -ne 0 ]; then - [ -n "$DEBUG" ] && echo "DEBUG: iptables chain misplaced, recreating it..." - iptables -t mangle -I $chain -j RRDIPT_$chain - fi -} - -# chain tun -newRuleIF() -{ - chain=$1 - IF=$2 - - #!@todo test - if [ "$chain" = "OUTPUT" ]; then - cmd="iptables -t mangle -o $IF -j RETURN" - eval $cmd " -C RRDIPT_$chain 2>/dev/null" || eval $cmd " -A RRDIPT_$chain" - elif [ "$chain" = "INPUT" ]; then - cmd="iptables -t mangle -i $IF -j RETURN" - eval $cmd " -C RRDIPT_$chain 2>/dev/null" || eval $cmd " -A RRDIPT_$chain" - fi -} - -accounting(){ - LAN_IFACE="br-lan" - WAN_IFACE=$1 - LAN_IP=$(uci -q get network.lan.ipaddr) - SERVER_IP=$(echo $LAN_IP | cut -d . -f 1,2,3).0 - INTERNAL_NETMASK="$SERVER_IP/24" - - # create the ACCOUNTING chains - iptables -w -N ACCOUNTING_BLOCK 2> /dev/null - iptables -w -N ACCOUNTING_IN 2> /dev/null - iptables -w -N ACCOUNTING_OUT 2> /dev/null - check=0 - # check if accounting rule for ethernet wan not exist, add it - checks=$(iptables -w -L FORWARD -v -n | grep "ACCOUNTING" | grep "$WAN_IFACE") - [ -z "$checks" ] && check=1 - - # check if jumps to the ACCOUNTING chains are still at the start of the FORWARD chain - iptables -w -L FORWARD --line-numbers -n | grep "ACCOUNTING" | grep "^1 " - if [ $? -ne 0 -o "$check" = "1" ]; then - # remove old jump rules - iptables -w -D FORWARD $(iptables -w -L FORWARD --line-numbers | grep ACCOUNTING | grep -m 1 -o "[0-9]*") - while [ $? -eq 0 ]; do - iptables -w -D FORWARD $(iptables -w -L FORWARD --line-numbers | grep ACCOUNTING | grep -m 1 -o "[0-9]*") - done - # insert new jump rules at start of FORWARD chain - if [ -n "$WAN_IFACE" ] - then - iptables -w -I FORWARD -i ${WAN_IFACE} -j ACCOUNTING_IN - iptables -w -I FORWARD -o ${WAN_IFACE} -j ACCOUNTING_OUT - fi - iptables -w -I FORWARD -j ACCOUNTING_BLOCK - fi - - #For each host in the ARP table - grep ${LAN_IFACE} /proc/net/arp | while read IP TYPE FLAGS MAC MASK IFACE - do - #Add iptables rules (if non existing). - iptables -w -nL ACCOUNTING_IN | grep "${IP} " > /dev/null - if [ $? -ne 0 ]; then - iptables -w -I ACCOUNTING_IN -d ${IP} -s ${INTERNAL_NETMASK} -j RETURN - iptables -w -I ACCOUNTING_IN -d ${IP} ! -s ${INTERNAL_NETMASK} -j RETURN - fi - - iptables -w -nL ACCOUNTING_OUT | grep "${IP} " > /dev/null - if [ $? -ne 0 ]; then - iptables -w -I ACCOUNTING_OUT -s ${IP} -d ${INTERNAL_NETMASK} -j RETURN - iptables -w -I ACCOUNTING_OUT -s ${IP} ! -d ${INTERNAL_NETMASK} -j RETURN - fi - done -} - -setup() -{ - for chain in $chains; do - newChain $chain - done - - wan=$(detectWAN) - checkWAN - wan1=$(detectIF wan1) - wan2=$(detectIF wan2) - C1=$(uci -q get modem.modem1.connected) - C2=$(uci -q get modem.modem2.connected)$C1 - if [ ! -z $C2 ]; then - interfaces="$wan1 $wan2" - WW=$(uci -q get bwmon.bwwan.wan) - if [ "$WW" = "1" ]; then - interfaces=$interfaces $wan" wwan" - fi - else - WW=$(uci -q get bwmon.bwwan.wan) - if [ "$WW" = "1" ]; then - interfaces="$wan wwan" - else - return - fi - fi - - # track local data - for chain in INPUT OUTPUT; do - for interface in $interfaces; do - [ -n "$interface" ] && [ -e "/sys/class/net/$interface" ] && newRuleIF $chain $interface - #if [ -e /etc/bwlock ]; then - accounting $interface - #fi - done - done - - # this will add rules for hosts in arp table - update $dailyUsageDB - - rm -f /tmp/*_$$.tmp -} - -update() -{ - createDbIfMissing - checkWAN - PERTOTAL=0 - - > /tmp/iptables_$$.tmp - lock - # only zero our own chains - for chain in $chains; do - iptables -nvxL RRDIPT_$chain -t mangle -Z >> /tmp/iptables_$$.tmp - done - # the iptables and readDB commands have to be separate. Otherwise, - # they will fight over iptables locks - awk -v mode="$mode" -v interfaces=\""$interfaces"\" -f $binDir/readDB.awk \ - $DB \ - /proc/net/arp \ - /tmp/iptables_$$.tmp - - while read L1 - do - MAC=$(echo ${L1} | cut -f1 -d, ) - if [ $MAC != "#mac" ]; then - MAC=$(echo ${L1} | cut -f1 -d, ) - IP=$(echo ${L1} | cut -f2 -d, ) - IN=$(echo ${L1} | cut -f4 -d, ) - IN=$((${IN}/1000)) - OUT=$(echo ${L1} | cut -f5 -d, ) - OUT=$((${OUT}/1000)) - TOTAL=$(echo ${L1} | cut -f6 -d, ) - TOTAL=$((${TOTAL}/1000)) - let PERTOTAL=PERTOTAL+TOTAL - if [ $TOTAL -gt 0 -a $IP != "NA" ]; then - for USERSFILE in /tmp/dhcp.leases /tmp/dnsmasq.conf /etc/dnsmasq.conf /etc/hosts; do - [ -e "$USERSFILE" ] || continue - case $USERSFILE in - /tmp/dhcp.leases ) - NAME=$(grep -i "$MAC" $USERSFILE | cut -f4 -s -d' ') - ;; - /etc/hosts ) - NAME=$(grep "^$IP " $USERSFILE | cut -f2 -s -d' ') - ;; - * ) - NAME=$(grep -i "$MAC" "$USERSFILE" | cut -f2 -s -d,) - ;; - esac - [ "$NAME" = "*" ] && NAME= - [ -n "$NAME" ] && break - done - if [ -z $NAME ]; then - NAME="*" - fi - - echo "\"mac\":\""${MAC}"\"","\"down\":\""${IN}"\"","\"up\":\""${OUT}"\"","\"offdown\":\""0"\"","\"offup\":\""0"\"","\"ip\":\""${IP}"\"","\"name\":\""${NAME}"\"" >> ${1} - fi - fi - done < $DB - if [ -e /usr/lib/bwmon/period.sh ]; then - /usr/lib/bwmon/period.sh "$PERTOTAL" - fi - unlock -} - - -createFiles() -{ - while [ -e /tmp/lockbw ]; do - sleep 1 - done - echo "0" > /tmp/lockbw - while [ ! -e $backPath*"mac_data.js" ]; do - valid=$(cat /var/state/dnsmasqsec) - st=$(echo "$valid" | grep "ntpd says time is valid") - if [ ! -z "$st" ]; then - break - fi - sleep 10 - done - dailyUsageDB="$dataPath$cYear-$cMonth-$cDay-daily_data.js" - dailyUsageBack="$backPath$cYear-$cMonth-$cDay-daily_data.js" - if [ ! -f $dailyUsageBack ]; then - rm -f $backPath*"daily_data.js" - touch $dailyUsageDB - touch $dailyUsageBack - else - cp -f $dailyUsageBack $dailyUsageDB - fi - monthlyUsageDB="$dataPath$cYear-$cMonth-mac_data.js" - monthlyUsageBack="$backPath$cYear-$cMonth-mac_data.js" - if [ -f $monthlyUsageBack ]; then - cp -f $monthlyUsageBack $monthlyUsageDB".bk" - sed "/start day $cDay/,/end day $cDay/d" $monthlyUsageDB".bk" > $monthlyUsageDB - cp -f $monthlyUsageBack $monthlyUsageDB".bk" - else - rm -f $backPath*"mac_data.js" - touch $monthlyUsageDB - touch $monthlyUsageBack - /usr/lib/bwmon/backup.sh "backup" $cDay $monthlyUsageDB $dailyUsageDB $monthlyUsageBack $dailyUsageBack - fi - rm -f /tmp/lockbw -} - -shutDown() -{ - while [ -e /tmplockbw ]; do - sleep 1 - done - echo "0" > /tmp/lockbw - /usr/lib/bwmon/backup.sh "backup" $cDay $monthlyUsageDB $dailyUsageDB $monthlyUsageBack $dailyUsageBack - lua /usr/lib/bwmon/cleanup.lua - rm -f /tmp/lockbw -} - -checkSetup() -{ - CURRTIME=$(date +%s) - let ELAPSE=CURRTIME-STARTIMEX - if [ $ELAPSE -gt $setup_time ]; then - STARTIMEX=$CURRTIME - setup - /usr/lib/bwmon/backup.sh "setup" $cDay $monthlyUsageDB $dailyUsageDB $monthlyUsageBack $dailyUsageBack - fi -} - -checkUpdate() -{ - CURRTIME=$(date +%s) - let ELAPSE=CURRTIME-STARTIMEY - if [ $ELAPSE -gt $update_time ]; then - STARTIMEY=$CURRTIME - update $dailyUsageDB $unlimited - fi -} - -checkBackup() -{ - CURRTIME=$(date +%s) - let ELAPSE=CURRTIME-STARTIMEZ - bs=$(uci -q get bwmon.general.backup) - let "bs=$bs*60" - backup_time=$bs - if [ $ELAPSE -gt $backup_time ]; then - STARTIMEZ=$CURRTIME - shutDown - fi -} - -checkTime() -{ - while [ -e /tmplockbw ]; do - sleep 1 - done - echo "0" > /tmp/lockbw - pDay=$(date +%d) - pYear=$(date +%Y) - pMonth=$(date +%m) - if [ "$cDay" -ne "$pDay" ]; then - /usr/lib/bwmon/backup.sh "daily" $cDay $monthlyUsageDB $dailyUsageDB $monthlyUsageBack $dailyUsageBack - - cDay=$pDay - cMonth=$pMonth - cYear=$pYear - monthlyUsageBack="$backPath$cYear-$cMonth-mac_data.js" - if [ ! -e $monthlyUsageBack ]; then - rm -f $backPath*"mac_data.js" - fi - rm -f $dataPath[[:digit:]][[:digit:]][[:digit:]][[:digit:]]"-"[[:digit:]][[:digit:]]"-"[[:digit:]][[:digit:]]-daily_data.js - rm -f $backPath[[:digit:]][[:digit:]][[:digit:]][[:digit:]]"-"[[:digit:]][[:digit:]]"-"[[:digit:]][[:digit:]]-daily_data.js - roll=$(uci -q get custom.bwallocate.rollover) - [ -z $roll ] && roll=1 - if [ "$roll" -eq "$pDay" ]; then - rm -f $monthlyUsageDB - rm -f $backPath*"mac_data.js" - monthlyUsageDB="$dataPath$cYear-$cMonth-mac_data.js" - monthlyUsageBack="$backPath$cYear-$cMonth-mac_data.js" - touch $monthlyUsageDB - uci set custom.texting.used='0' - uci commit custom - if [ -e /usr/lib/bwmon/periodreset.sh ]; then - /usr/lib/bwmon/periodreset.sh - fi - fi - rm -f $dailyUsageDB - rm -f $backPath*"daily_data.js" - dailyUsageDB="$dataPath$cYear-$cMonth-$cDay-daily_data.js" - touch $dailyUsageDB - dailyUsageBack="$backPath$cYear-$cMonth-$cDay-daily_data.js" - fi - rm -f /tmp/lockbw -} - -createFiles -setup -while [ -d $lockDir ]; do - checkSetup - checkTime - checkBackup - n=0 - while [ true ] ; do - n=$(($n + 1)) - if [ ! -d "$lockDir" ]; then - shutDown - exit 0 - fi - [ "$n" -gt "$pause" ] && break; - sleep 1 - done -done diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/lua/luci/controller/bwmon.lua b/rooter/0optionalapps/bwmon/files/usr/lib/lua/luci/controller/bwmon.lua index ac269e8..f17f5a2 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/lua/luci/controller/bwmon.lua +++ b/rooter/0optionalapps/bwmon/files/usr/lib/lua/luci/controller/bwmon.lua @@ -51,6 +51,23 @@ function action_check_bw() end end file:close() + os.execute("/usr/lib/bwmon/genline.sh") + file = io.open("/tmp/monlist", "r") + if file ~= nil then + line = file:read("*all") + rv["genline"] = line + file:close() + file = io.open("/tmp/montot", "r") + if file ~= nil then + rv['gendays'] = file:read("*line") + rv['gendwn'] = file:read("*line") + rv['genupn'] = file:read("*line") + rv['gentotal'] = file:read("*line") + file:close() + end + else + rv['gendays'] = '0' + end else rv['days'] = 0 end diff --git a/rooter/0optionalapps/bwmon/files/usr/lib/lua/luci/view/bwmon/bwmon.htm b/rooter/0optionalapps/bwmon/files/usr/lib/lua/luci/view/bwmon/bwmon.htm index 2664efd..a7ab40e 100644 --- a/rooter/0optionalapps/bwmon/files/usr/lib/lua/luci/view/bwmon/bwmon.htm +++ b/rooter/0optionalapps/bwmon/files/usr/lib/lua/luci/view/bwmon/bwmon.htm @@ -60,25 +60,10 @@ var backflg = "0"; document.getElementById("allocatet").style.display=""; document.getElementById("bwenb").disabled=true; document.getElementById("bwinter").disabled=true; - document.getElementById("apply2").disabled=true; + document.getElementById("bwflag").disabled=true; bwe = true; if ( backflg == "0" ) { - if ( rv.external == "0" ) - { - bwe = false - document.getElementById("exflag").innerHTML="<%:Internal%>"; - document.getElementById("exflag").style.fontWeight = "bold" ; - document.getElementById("exflag").style.fontSize = "large" ; - } - else - { - document.getElementById("exflag").innerHTML=rv.external; - document.getElementById("exflag").style.fontWeight = "bold" ; - document.getElementById("exflag").style.fontSize = "small" ; - } - //if ( backflg == "0" ) - //{ document.getElementById("bwinter").value = rv.backup; backflg = "1"; } @@ -113,25 +98,10 @@ var backflg = "0"; document.getElementById("allocatet").style.display="none"; document.getElementById("bwenb").disabled=false; document.getElementById("bwinter").disabled=false; - document.getElementById("apply2").disabled=false; + document.getElementById("bwflag").disabled=false; bwe = true; if ( backflg == "0" ) { - if ( rv.external == "0" ) - { - bwe = false - document.getElementById("exflag").innerHTML="<%:Internal%>"; - document.getElementById("exflag").style.fontWeight = "bold" ; - document.getElementById("exflag").style.fontSize = "large" ; - } - else - { - document.getElementById("exflag").innerHTML=rv.external; - document.getElementById("exflag").style.fontWeight = "bold" ; - document.getElementById("exflag").style.fontSize = "small" ; - } - //if ( backflg == "0" ) - //{ document.getElementById("bwinter").value = rv.backup; backflg = "1"; } @@ -177,42 +147,6 @@ var backflg = "0"; document.getElementById("password").value=rv.password; - var tbl = document.getElementById('datar'); - while (tbl.rows.length > 1) - tbl.deleteRow(1); - - msize = rv.macsize; - maclist = rv.maclist; - if ( msize !== "0" ) - { - size = parseFloat(msize); - for (i = 0; i < size; i++) - { - partsArray = maclist[i].split('|'); - tr = tbl.insertRow(-1); - row3 = tr.insertCell(-1); - row3.innerHTML = '
      ' + partsArray[0] + '
      ' - row3.style.width = '160px' ; - row3 = tr.insertCell(-1); - row3.innerHTML = '
      ' + partsArray[5] + '
      ' - row3.style.width = '200px' ; - row3 = tr.insertCell(-1); - row3.innerHTML = '
      ' + partsArray[1] + '
      ' - row3.style.width = '160px' ; - row3 = tr.insertCell(-1); - row3.innerHTML = '
      ' + partsArray[2] + '
      ' - row3.style.width = '150px' ; - row3 = tr.insertCell(-1); - row3.innerHTML = '
      ' + partsArray[3] + '
      ' - row3.style.width = '150px' ; - row3 = tr.insertCell(-1); - row3.innerHTML = '
      ' + partsArray[4] + '
      ' - row3.style.width = '150px' ; - } - } - - document.getElementById("datar").style.display = ""; - } else { @@ -226,6 +160,23 @@ var backflg = "0"; document.getElementById("report").style.visibility="hidden"; document.getElementById("report").style.display="none"; } + + + gendays = rv.gendays; + if ( gendays != '0' ) + { + genline = rv.genline; + gendwn = rv.gendwn; + genup = rv.genupn + gentotal = rv.gentotal + document.getElementById("datar2").innerHTML=genline; + document.getElementById("stdate").innerHTML="" + gendays + ""; + document.getElementById("bdwn").innerHTML="" + gentotal + ""; + } + else + { + document.getElementById("stdate").innerHTML="" + "No Data" + ""; + } } XHR.get('<%=luci.dispatcher.build_url("admin", "nlbw", "check_bw")%>', @@ -244,52 +195,10 @@ var backflg = "0"; } ); - - function done() { - document.getElementById("popup").style.display = "none"; - document.getElementById("apply2").disabled=true; - var r = document.getElementById("pass").value; - if ( r == "" ) - { - document.getElementById("exflag").innerHTML="<%:Internal%>"; - document.getElementById("exflag").style.fontWeight = "bold" ; - document.getElementById("exflag").style.fontSize = "large" ; - r = "0"; - } - else - { - mnti = r.indexOf("/mnt/"); - mntl = r.length; - if ( mnti == -1 || mntl < 6 ) - { - alert("<%:Invalid External Path. Reverting to Internal.%>"); - r = "0"; - document.getElementById("exflag").innerHTML="<%:Internal%>"; - document.getElementById("exflag").style.fontWeight = "bold" ; - document.getElementById("exflag").style.fontSize = "large" ; - } - else - { - document.getElementById("exflag").innerHTML=r; - document.getElementById("exflag").style.fontWeight = "bold" ; - document.getElementById("exflag").style.fontSize = "small" ; - } - } - XHR.get('<%=luci.dispatcher.build_url("admin", "nlbw", "change_external")%>', - { set: r }, - function() - { - } - ); - document.getElementById("pass").value=""; - document.getElementById("apply2").disabled=false; - return false; - }; function unlock(btn) { document.getElementById("popup").style.display = "block"; - document.getElementById("apply2").disabled=true; return false; } @@ -421,6 +330,8 @@ var backflg = "0"; display:none; } + +
      <%:Extra Internet Sources%> @@ -483,11 +394,6 @@ var backflg = "0";
      - - - - -
      <%:短信发送状态 :%>
      <%:Sending Status :%>
         
        $START
        $updata
        $downdata
        $totaldata
        <%:Backup Storage Location%>
        @@ -588,18 +494,41 @@ var backflg = "0"; -
        - +
        +

        Last 30 Day Bandwidth Usage

        + +
        - - - - - - + + + + + + + + + + + +
        <%:IP Address%>
        <%:Name%>
        <%:MAC Address%>
        <%:Bandwidth Down%>
        <%:Bandwidth Up%>
        <%:Bandwidth Total%>
        <%:Days in Period%>
        <%:Bandwidth Used%>
        <%:%>
        <%:%>
        - +
        +
        + + + + + + + +
        <%:Date%>
        <%:Bandwidth Down%>
        <%:Bandwidth Up%>
        <%:Bandwidth Total%>
        +
        diff --git a/rooter/0optionalapps/ext-speedtest/files/usr/lib/lua/luci/view/speedtest/speedtest.htm b/rooter/0optionalapps/ext-speedtest/files/usr/lib/lua/luci/view/speedtest/speedtest.htm index 8f731de..c15c145 100644 --- a/rooter/0optionalapps/ext-speedtest/files/usr/lib/lua/luci/view/speedtest/speedtest.htm +++ b/rooter/0optionalapps/ext-speedtest/files/usr/lib/lua/luci/view/speedtest/speedtest.htm @@ -21,10 +21,10 @@
        <%:A Speed Test using OpenSpeedTest that runs in the browser%>
        - - - - + + + + diff --git a/rooter/0optionalapps/ext-wireguard/files/etc/init.d/wireguard b/rooter/0optionalapps/ext-wireguard/files/etc/init.d/wireguard index 4e49b81..16a34ce 100644 --- a/rooter/0optionalapps/ext-wireguard/files/etc/init.d/wireguard +++ b/rooter/0optionalapps/ext-wireguard/files/etc/init.d/wireguard @@ -84,4 +84,9 @@ start() { config_load wireguard config_foreach chk_start wireguard + if [ -e /etc/crontabs/root ]; then + sed -i '/wireguard_watchdog/d' /etc/crontabs/root + fi + echo '* * * * * /usr/bin/wireguard_watchdog' >> /etc/crontabs/root + /etc/init.d/cron restart } \ No newline at end of file diff --git a/rooter/0optionalapps/ext-wireguard/files/usr/lib/lua/luci/model/cbi/wireguard-client.lua b/rooter/0optionalapps/ext-wireguard/files/usr/lib/lua/luci/model/cbi/wireguard-client.lua index ec041aa..45e2216 100644 --- a/rooter/0optionalapps/ext-wireguard/files/usr/lib/lua/luci/model/cbi/wireguard-client.lua +++ b/rooter/0optionalapps/ext-wireguard/files/usr/lib/lua/luci/model/cbi/wireguard-client.lua @@ -59,6 +59,11 @@ pkey = s:option(Value, "privatekey", translate("Private Key :"), translate("Priv pkey.rmempty = true; pkey.optional=false; +il = s:option(ListValue, "wginter", translate("Interface to Use :")); +il:value("0", translate("WG0")) +il:value("1", translate("WG1")) +il.default="0" + bl = s:option(ListValue, "auto", translate("Start on Boot :")); bl:value("0", translate("No")) bl:value("1", translate("Yes")) diff --git a/rooter/0optionalapps/ext-wireguard/files/usr/lib/lua/luci/view/wireguard/wireguard.htm b/rooter/0optionalapps/ext-wireguard/files/usr/lib/lua/luci/view/wireguard/wireguard.htm index d207f05..cf7544e 100644 --- a/rooter/0optionalapps/ext-wireguard/files/usr/lib/lua/luci/view/wireguard/wireguard.htm +++ b/rooter/0optionalapps/ext-wireguard/files/usr/lib/lua/luci/view/wireguard/wireguard.htm @@ -40,10 +40,14 @@ XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "vpn", "wirestatus")%>', null, function(x, data) { + both = {}; + bothbp={}; + iii = 1; for (var key in data) { if (!data.hasOwnProperty(key)) { continue; } var ifname = key; var iface = data[key]; + var s = ""; if (iface.public_key == '(none)') { s += '<%:Interface does not have a public key!%>'; @@ -65,7 +69,16 @@ iface.fwmark ); } - document.getElementById("iinfo").innerHTML = s; + if ( iii == 1 ) + { + document.getElementById("iinfo").innerHTML = s; + document.getElementById("leg").innerHTML = ifname; + } + else + { + document.getElementById("iinfo1").innerHTML = s; + document.getElementById("leg1").innerHTML = ifname; + } for (var i = 0, ilen = iface.peers.length; i < ilen; i++) { var peer = iface.peers[i]; var s = String.format( @@ -105,9 +118,18 @@ bytes_to_str(peer.transfer_rx), bytes_to_str(peer.transfer_tx) ); - document.getElementById("config").innerHTML = icon; - document.getElementById("info").innerHTML = s; + if ( iii == 1 ) + { + document.getElementById("config").innerHTML = icon; + document.getElementById("info").innerHTML = s; + } + else + { + document.getElementById("config1").innerHTML = icon; + document.getElementById("info1").innerHTML = s; + } } + iii = iii + 1; } }); //]]> @@ -116,9 +138,16 @@
        - <%:Interface%> WG0 - -
        +
        + + + + + + +
        +
        <%:Interface %>
        +
          
        @@ -147,6 +176,52 @@
         
        + + + + + + + +
        +
        <%:Interface %>
        +
          
        + + + + + + + + + + + + + + + +
          +
        <%:Configuration%>
        +
           +
        + <%:Collecting data...%> +
        +
          +
        <%:Peer%>
        +
           +
        + <%:Collecting data...%> +
        +
        +
        diff --git a/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/conf.sh b/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/conf.sh index 436e1f5..5c36ca2 100644 --- a/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/conf.sh +++ b/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/conf.sh @@ -1,5 +1,9 @@ #!/bin/sh +log() { + modlog "Wireguard Conf" "$@" +} + name=$1 file=$2 auto=$3 @@ -25,6 +29,13 @@ extract() { if [ ! -z "$PRK" ]; then PreSharedKey=$(echo $PRK | cut -d, -f3) fi + INTER=$(echo "$line" | grep "WGinterface" | tr " " ",") + if [ ! -z "$INTER" ]; then + wginter=$(echo $INTER | cut -d, -f3) + if [ "$wginter" -gt 1 ]; then + wginter="1" + fi + fi PRK=$(echo "$line" | grep "Address" | tr " " "#") if [ ! -z "$PRK" ]; then if [ -z $Address ]; then @@ -73,6 +84,8 @@ sed -i -e "s!PresharedKey= !PresharedKey=!g" $file sed -i -e "s!PresharedKey=!PresharedKey = !g" $file sed -i -e "s!Address= !Address=!g" $file sed -i -e "s!Address=!Address = !g" $file +sed -i -e "s!WGinterface=!WGinterface = !g" $file +sed -i -e "s!WGinterface= !WGinterface = !g" $file sed -i -e "s!dns= !dns=!g" $file sed -i -e "s!dns=!dns = !g" $file sed -i -e "s!DNS= !DNS=!g" $file @@ -94,7 +107,9 @@ extract "$linex" PRK=$(echo "$endpoint" | tr ":" ",") endpoint=$(echo $PRK | cut -d, -f1) sport=$(echo $PRK | cut -d, -f2) - +if [ -z "$wginter" ]; then + wginter="0" +fi uci delete wireguard.$name uci set wireguard.$name=wireguard uci set wireguard.$name.auto=$auto @@ -105,6 +120,7 @@ uci set wireguard.$name.presharedkey="$PreSharedKey" uci set wireguard.$name.port="$listenport" uci set wireguard.$name.addresses="$Address" uci set wireguard.$name.dns="$dns" +uci set wireguard.$name.wginter="$wginter" uci set wireguard.$name.publickey="$PublicKey" uci set wireguard.$name.endpoint_host="$endpoint" uci set wireguard.$name.ips="$allowedips" diff --git a/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/create.sh b/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/create.sh index 9d41829..143abe6 100644 --- a/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/create.sh +++ b/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/create.sh @@ -33,6 +33,11 @@ do_create() { if [ ! -z $mtu ]; then echo "MTU = "$mtu >> ${PKI_DIR}/package/wg.conf fi + config_get wginter $config wginter + if [ -z"$wginter"]; then + wginter=0 + fi + echo "PrivateKey = "$wginter >> ${PKI_DIR}/package/wg.conf echo " " >> ${PKI_DIR}/package/wg.conf echo "[Peer]" >> ${PKI_DIR}/package/wg.conf PUB=$(uci get wireguard."$WG".publickey) diff --git a/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/startvpn.sh b/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/startvpn.sh index 352032d..3e00972 100644 --- a/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/startvpn.sh +++ b/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/startvpn.sh @@ -20,11 +20,12 @@ chk_zone() { do_dns() { cdns=$1 - ldns=$(uci -q get network.wg0.dns) + local ifce=$2 + ldns=$(uci -q get network.wg$ifce.dns) ex=$(echo "$ldns" | grep "$cdns") if [ -z $ex ]; then - log "Add DNS $cdns to WG0" - uci add_list network.wg0.dns="$cdns" + log "Add DNS $cdns to WG$ifce" + uci add_list network.wg$ifce.dns="$cdns" uci commit network /etc/init.d/network reload fi @@ -87,8 +88,9 @@ create_speer() { create_cpeer() { local config=$1 + local ifce=$2 - uci set network.$config="wireguard_wg0" + uci set network.$config="wireguard_wg$ifce" publickey=$(uci -q get wireguard."$config".publickey) uci set network.$config.public_key="$publickey" @@ -176,50 +178,51 @@ handle_server() { } handle_client() { - config_foreach do_delete wireguard_wg0 + ifce=$1 + config_foreach do_delete wireguard_wg$ifce - uci delete network.wg0 - uci set network.wg0="interface" - uci set network.wg0.proto="wireguard" + uci delete network.wg$ifce + uci set network.wg$ifce="interface" + uci set network.wg$ifce.proto="wireguard" auto=$(uci -q get wireguard."$WG".auto) if [ -z $auto ]; then auto="0" fi - uci set network.wg0.auto="$auto" + uci set network.wg$ifce.auto="$auto" mtu=$(uci -q get wireguard."$WG".mtu) if [ ! -z $mtu ]; then - uci set network.wg0.mtu="$mtu" + uci set network.wg$ifce.mtu="$mtu" fi dns=$(uci -q get wireguard."$WG".dns) if [ ! -z $dns ]; then - do_dns $dns + do_dns $dns $ifce fi port=$(uci -q get wireguard."$WG".port) if [ -z $port ]; then port="51280" fi - uci set network.wg0.listen_port="$port" + uci set network.wg$ifce.listen_port="$port" do_port $port udp privatekey=$(uci -q get wireguard."$WG".privatekey) - uci set network.wg0.private_key="$privatekey" + uci set network.wg$ifce.private_key="$privatekey" ips=$(uci -q get wireguard."$WG".addresses)"," cips=$(echo $ips | cut -d, -f1) i=1 while [ ! -z "$cips" ] do - uci add_list network.wg0.addresses="$cips" + uci add_list network.wg$ifce.addresses="$cips" i=$((i+1)) cips=$(echo "$ips" | cut -d, -f"$i") if [ -z "$cips" ]; then break fi done - uci add_list network.wg0.addresses="::/0" + uci add_list network.wg$ifce.addresses="::/0" - create_cpeer $WG + create_cpeer $WG $ifce uci commit network } @@ -298,17 +301,19 @@ if [ $SERVE = "0" ]; then else running=$(uci -q get wireguard.settings.client) log "Client running $running" - if [ $running = 1 ]; then - exit 0 + + INTER=$(uci -q get wireguard."$WG".wginter) + if [ -z "$INTER" ]; then + INTER=0 fi UDP=$(uci -q get wireguard."$WG".udptunnel) if [ $UDP = 1 ]; then udp_client $WG fi - handle_client + handle_client $INTER uci commit network log "Start Interface" - ifup wg0 + ifup wg$INTER sleep 2 uci set wireguard.settings.client="1" fi diff --git a/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/stopvpn.sh b/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/stopvpn.sh index 91e80dc..9e56adf 100644 --- a/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/stopvpn.sh +++ b/rooter/0optionalapps/ext-wireguard/files/usr/lib/wireguard/stopvpn.sh @@ -44,15 +44,19 @@ if [ $SERVE = "0" ]; then uci add_list network.wg1.addresses="" uci commit network else - ifdown wg0 + INTER=$(uci -q get wireguard."$WG".wginter) + if [ -z "$INTER" ]; then + INTER=0 + fi + ifdown wg$INTER uci set wireguard.settings.client="0" - uci delete network.wg0 - uci set network.wg0=interface - uci set network.wg0.proto="wireguard" - uci set network.wg0.auto="0" - uci set network.wg0.private_key="" - uci set network.wg0.listen_port="" - uci add_list network.wg0.addresses="" + uci delete network.wg$INTER + uci set network.wg$INTER=interface + uci set network.wg$INTER.proto="wireguard" + uci set network.wg$INTER.auto="0" + uci set network.wg$INTER.private_key="" + uci set network.wg$INTER.listen_port="" + uci add_list network.wg$INTER.addresses="" uci commit network fi UDP=$(uci get wireguard."$WG".udptunnel) diff --git a/rooter/0optionalapps/ext-zerotier/files/etc/init.d/zerofire b/rooter/0optionalapps/ext-zerotier/files/etc/init.d/zerofire index 05b8693..ff04ca0 100644 --- a/rooter/0optionalapps/ext-zerotier/files/etc/init.d/zerofire +++ b/rooter/0optionalapps/ext-zerotier/files/etc/init.d/zerofire @@ -34,4 +34,8 @@ check_config () { start() { check_config + if [ -s /etc/config/zerotier ]; then + gr_backup=`grep "^/etc/config/zerotier" /etc/sysupgrade.conf` + [ -z $gr_backup ] && echo "/etc/config/zerotier" >> /etc/sysupgrade.conf + fi } \ No newline at end of file diff --git a/rooter/0optionalapps/ext-zerotier/files/usr/lib/lua/luci/controller/zerotier.lua b/rooter/0optionalapps/ext-zerotier/files/usr/lib/lua/luci/controller/zerotier.lua index 74c997b..fc390f5 100644 --- a/rooter/0optionalapps/ext-zerotier/files/usr/lib/lua/luci/controller/zerotier.lua +++ b/rooter/0optionalapps/ext-zerotier/files/usr/lib/lua/luci/controller/zerotier.lua @@ -6,6 +6,7 @@ translate = I18N.translate function index() local fs = require "nixio.fs" local lock = luci.model.uci.cursor():get("custom", "menu", "full") + local default = luci.model.uci.cursor():get("custom", "menu", "default") local multilock = luci.model.uci.cursor():get("custom", "multiuser", "multi") or "0" local rootlock = luci.model.uci.cursor():get("custom", "multiuser", "root") or "0" if (multilock == "0") or (multilock == "1" and rootlock == "1") then @@ -16,8 +17,13 @@ function index() page = entry({"admin", "adminmenu", "zerotier"}, template("zerotier/zerotier"), translate("Zerotier"), 7) page.dependent = true else - page = entry({"admin", "adminmenu", "zerotier"}, template("zerotier/zerotier"), translate("---Router ID"), 7) - page.dependent = true + if default == "1" then + page = entry({"admin", "adminmenu", "zerotier"}, template("zerotier/zerotier"), translate("Zerotier"), 7) + page.dependent = true + else + page = entry({"admin", "adminmenu", "zerotier"}, template("zerotier/zerotier"), translate("---Router ID"), 7) + page.dependent = true + end end end end diff --git a/rooter/0optionalapps/luci-app-hotspot/files/etc/hotplug.d/iface/99-travelmate-iface b/rooter/0optionalapps/luci-app-hotspot/files/etc/hotplug.d/iface/99-travelmate-iface index 1e1c211..7253a27 100644 --- a/rooter/0optionalapps/luci-app-hotspot/files/etc/hotplug.d/iface/99-travelmate-iface +++ b/rooter/0optionalapps/luci-app-hotspot/files/etc/hotplug.d/iface/99-travelmate-iface @@ -1,12 +1,17 @@ #!/bin/sh -if [ "$ACTION" = ifup -a "$INTERFACE" = "wwan" ]; then +log() { + wifilog "IFACE" "$@" +} + +wif=$(uci -q get travelmate.global.freq) +if [ "$ACTION" = ifup -a "$INTERFACE" = "wwan$wif" ]; then exit 1 fi -if [ "$ACTION" = ifdown -a "$INTERFACE" = "wwan" ]; then +if [ "$ACTION" = ifdown -a "$INTERFACE" = "wwan$wif" ]; then + wifilog "HOTSPOT" "hotplug (iface): action='$ACTION' interface='$INTERFACE'" conn=$(uci -q get travelmate.global.connecting) - wif=$(uci -q get travelmate.global.freq) if [ "$conn" != "1" ]; then uci -q set wireless.wwan$wif.ssid="Hotspot Manager Interface" uci -q set wireless.wwan$wif.encryption="none" @@ -17,23 +22,39 @@ if [ "$ACTION" = ifdown -a "$INTERFACE" = "wwan" ]; then ubus call network reload disa=$(uci -q get travelmate.global.ssid) # check for disconnect or lost connection - if [ "$disa" != "7" ]; then - uci set travelmate.global.ssid="9" # lost connection - reconn=$(uci -q get travelmate.global.reconn) - if [ "$reconn" != "0" ]; then - lost=$(uci -q get travelmate.global.lost) - if [ $reconn -eq 99 ]; then - lost="1" - fi - if [ $lost -le $reconn ]; then - let lost=$lost+1 - uci set travelmate.global.lost=$lost - uci set travelmate.global.delay="30" - uci commit travelmate - /usr/lib/hotspot/travelmate.sh & - exit 0 + if [ "$disa" != "8" ]; then + if [ "$disa" != "7" ]; then + uci set travelmate.global.ssid="9" # lost connection + reconn=$(uci -q get travelmate.global.reconn) + if [ "$reconn" != "0" ]; then + lost=$(uci -q get travelmate.global.lost) + if [ $reconn -eq 99 ]; then + lost="1" + fi + if [ $lost -le $reconn ]; then + let lost=$lost+1 + uci set travelmate.global.lost=$lost + uci set travelmate.global.delay="30" + uci commit travelmate + sleep 10 + PID=$(ps |grep "travelmate.sh" | grep -v grep |head -n 1 | awk '{print $1}') + if [ ! -z "$PID" ]; then + kill -9 $PID + fi + /usr/lib/hotspot/travelmate.sh & + exit 0 + fi fi fi + else + uci set travelmate.global.ssid="9" + uci commit travelmate + PID=$(ps |grep "travelmate.sh" | grep -v grep |head -n 1 | awk '{print $1}') + if [ ! -z "$PID" ]; then + kill -9 $PID + fi + /usr/lib/hotspot/travelmate.sh & + exit 0 fi uci set travelmate.global.trm_enabled="0" uci commit travelmate diff --git a/rooter/0optionalapps/luci-app-hotspot/files/etc/init.d/travelmate b/rooter/0optionalapps/luci-app-hotspot/files/etc/init.d/travelmate index 7357870..8d5cefe 100644 --- a/rooter/0optionalapps/luci-app-hotspot/files/etc/init.d/travelmate +++ b/rooter/0optionalapps/luci-app-hotspot/files/etc/init.d/travelmate @@ -34,7 +34,7 @@ do_radio() { config_get channel $1 channel config_get hwmode $1 hwmode - if [ $hwmode = "11g" ]; then + if [ $channel -lt 20 ]; then w2=$(uci -q get wireless.wwan2.device) if [ -z $w2 ]; then uci set wireless.wwan2=wifi-iface @@ -69,12 +69,16 @@ log "Hotspot Firewall" if [ -z $PRO ]; then uci set network.wwan2=interface uci set network.wwan2.proto=dhcp + uci set network.wwan2.metric='2' uci set network.wwan26=interface uci set network.wwan26.proto=dhcpv6 + uci set network.wwan26.metric='2' uci set network.wwan5=interface uci set network.wwan5.proto=dhcp + uci set network.wwan5.metric='2' uci set network.wwan56=interface uci set network.wwan56.proto=dhcpv6 + uci set network.wwan56.metric='2' uci commit network fi config_load firewall diff --git a/rooter/0optionalapps/luci-app-hotspot/files/usr/lib/hotspot/enable.sh b/rooter/0optionalapps/luci-app-hotspot/files/usr/lib/hotspot/enable.sh index e2b645f..53cb608 100644 --- a/rooter/0optionalapps/luci-app-hotspot/files/usr/lib/hotspot/enable.sh +++ b/rooter/0optionalapps/luci-app-hotspot/files/usr/lib/hotspot/enable.sh @@ -22,6 +22,10 @@ if [ $SET = "1" ]; then uci -q set wireless.wwan$wif.key= uci set wireless.wwan$wif.ssid="Hotspot Manager Interface" uci -q commit wireless + PID=$(ps |grep "travelmate.sh" | grep -v grep |head -n 1 | awk '{print $1}') + if [ ! -z "$PID" ]; then + kill -9 $PID + fi /usr/lib/hotspot/travelmate.sh & fi else diff --git a/rooter/0optionalapps/luci-app-hotspot/files/usr/lib/hotspot/travelmate.sh b/rooter/0optionalapps/luci-app-hotspot/files/usr/lib/hotspot/travelmate.sh index a31d4e0..a0de802 100644 --- a/rooter/0optionalapps/luci-app-hotspot/files/usr/lib/hotspot/travelmate.sh +++ b/rooter/0optionalapps/luci-app-hotspot/files/usr/lib/hotspot/travelmate.sh @@ -22,7 +22,7 @@ trm_iw=1 trm_auto=$(uci -q get travelmate.global.trm_auto) check_wwan() { - uci set travelmate.global.ssid="0" + uci set travelmate.global.ssid="8" wif=$(uci -q get travelmate.global.freq) if [ -z "$wif" ]; then uci set travelmate.global.freq="2" @@ -309,6 +309,9 @@ f_main() uci commit travelmate uci -q set wireless.wwan$wif.ssid="$ssid" uci -q set wireless.wwan$wif.encryption=$encrypt + if [ "$encrypt" = "none" ]; then + key="" + fi uci -q set wireless.wwan$wif.key=$key uci -q set wireless.wwan$wif.disabled=0 uci -q commit wireless @@ -381,8 +384,10 @@ f_main() # No connection to any in list cnt=$((cnt+1)) if [ $reconn -gt 0 ]; then - f_log "info " "Sleep before retrying" - sleep 30 + if [ ${cnt} -lt $reconn ]; then + f_log "info " "Sleep before retrying" + sleep 30 + fi fi # repeat scan and connect done diff --git a/rooter/0optionalapps/pingtest/files/etc/config/ping b/rooter/0optionalapps/pingtest/files/etc/config/ping new file mode 100644 index 0000000..3a40a23 --- /dev/null +++ b/rooter/0optionalapps/pingtest/files/etc/config/ping @@ -0,0 +1,11 @@ + +config ping 'ping' + option enable '0' + option delay '40' + option conn '1' + option interval '20' + option type '1' + option ipv41 'http://www.google.com/' + option ipv6 'http://www.example.org/' + option ipv42 'https://github.com' + diff --git a/rooter/0optionalapps/pingtest/files/etc/init.d/pingtest b/rooter/0optionalapps/pingtest/files/etc/init.d/pingtest new file mode 100644 index 0000000..32cc726 --- /dev/null +++ b/rooter/0optionalapps/pingtest/files/etc/init.d/pingtest @@ -0,0 +1,14 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2013 OpenWrt.org + +START=99 +USE_PROCD=1 + +log() { + logger -t "pingtest" "$@" +} + +start_service() +{ + /usr/lib/custom/test_ping.sh & +} diff --git a/rooter/0optionalapps/pingtest/files/usr/lib/custom/johns_ping.sh b/rooter/0optionalapps/pingtest/files/usr/lib/custom/johns_ping.sh index 32af6cb..e128f53 100644 --- a/rooter/0optionalapps/pingtest/files/usr/lib/custom/johns_ping.sh +++ b/rooter/0optionalapps/pingtest/files/usr/lib/custom/johns_ping.sh @@ -19,6 +19,62 @@ tping() { fi } +doping() { + TYPE=$(uci get ping.ping.type) + if [ $TYPE = "1" ]; then + log "Curl" + RETURN_CODE_1=$(curl -s -m 10 -s -o /dev/null -w "%{http_code}" $ipv41) + RETURN_CODE_2=$(curl -s --ipv6 -m 10 -s -o /dev/null -w "%{http_code}" $ipv6) + RETURN_CODE_3=$(curl -s -m 10 -s -o /dev/null -w "%{http_code}" $ipv42) + else + log "Ping" + tping "$ipv41"; RETURN_CODE_1=$tmp + tping "$ipv6" "-6"; RETURN_CODE_2=$tmp + tping "$ipv42"; RETURN_CODE_3=$tmp + fi +} + +ptest() { + tries=0 + status=0 + while [ $tries -lt $1 ] + do + CONN=$(uci -q get modem.modem$CURRMODEM.connected) + if [ $CONN = "1" ]; then + uci set ping.ping.conn="4" + uci commit ping + doping + if [[ "$RETURN_CODE_1" != "200" && "$RETURN_CODE_2" != "200" && "$RETURN_CODE_3" != "200" ]]; then + uci set ping.ping.conn="1" + uci commit ping + status=1 + return + fi + log "Second Ping Test Good" + uci set ping.ping.conn="2" + uci commit ping + status=0 + return + else + sleep 20 + tries=$((tries+1)) + fi + done + status=1 +} + +ipv41=$(uci -q get ping.ping.ipv41) +if [ -z "$ipv41" ]; then + ipv41="http://www.google.com/" +fi +ipv42=$(uci -q get ping.ping.ipv42) +if [ -z "$ipv42" ]; then + ipv42="https://github.com" +fi +ipv6=$(uci -q get ping.ping.ipv6) +if [ -z "$ipv6" ]; then + ipv6="http://ipv6.google.com" +fi uci set ping.ping.conn="4" uci commit ping @@ -26,70 +82,37 @@ CURRMODEM=1 CPORT=$(uci -q get modem.modem$CURRMODEM.commport) DELAY=$(uci get ping.ping.delay) -TYPE=$(uci get ping.ping.type) -if [ $TYPE = "1" ]; then -log "Curl" - RETURN_CODE_1=$(curl -m 10 -s -o /dev/null -w "%{http_code}" http://www.google.com/) - RETURN_CODE_2=$(curl --ipv6 -m 10 -s -o /dev/null -w "%{http_code}" http://www.example.org/) - RETURN_CODE_3=$(curl -m 10 -s -o /dev/null -w "%{http_code}" https://github.com) -else -log "Ping" - tping "http://www.google.com/"; RETURN_CODE_1=$tmp - tping "http://www.example.org/" "-6"; RETURN_CODE_2=$tmp - tping "https://github.com"; RETURN_CODE_3=$tmp -fi +doping if [[ "$RETURN_CODE_1" != "200" && "$RETURN_CODE_2" != "200" && "$RETURN_CODE_3" != "200" ]]; then log "Bad Ping Test" - if [ $TYPE = "1" ]; then - tping "http://www.google.com/"; RETURN_CODE_1=$tmp - tping "http://www.example.org/" "-6"; RETURN_CODE_2=$tmp - tping "https://github.com"; RETURN_CODE_3=$tmp - else - RETURN_CODE_1=$(curl -m 10 -s -o /dev/null -w "%{http_code}" http://www.google.com/) - RETURN_CODE_2=$(curl --ipv6 -m 10 -s -o /dev/null -w "%{http_code}" http://www.example.org/) - RETURN_CODE_3=$(curl -m 10 -s -o /dev/null -w "%{http_code}" https://github.com) - fi + doping if [[ "$RETURN_CODE_1" != "200" && "$RETURN_CODE_2" != "200" && "$RETURN_CODE_3" != "200" ]]; then log "Second Bad Ping Test" uci set ping.ping.conn="3" uci commit ping - ATCMDD="AT+CFUN=1,1" - $ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD" + log "Restart Network" + /usr/lib/rooter/luci/restart.sh $CURRMODEM 10 sleep $DELAY - tries=0 - while [ $tries -lt 9 ] - do - CONN=$(uci -q get modem.modem$CURRMODEM.connected) - if [ $CONN = "1" ]; then - uci set ping.ping.conn="4" - uci commit ping - if [ $TYPE = "1" ]; then - log "Curl" - RETURN_CODE_1=$(curl -m 10 -s -o /dev/null -w "%{http_code}" http://www.google.com/) - RETURN_CODE_2=$(curl --ipv6 -m 10 -s -o /dev/null -w "%{http_code}" http://www.example.org/) - RETURN_CODE_3=$(curl -m 10 -s -o /dev/null -w "%{http_code}" https://github.com) - else - log "Ping" - tping "http://www.google.com/"; RETURN_CODE_1=$tmp - tping "http://www.example.org/" "-6"; RETURN_CODE_2=$tmp - tping "https://github.com"; RETURN_CODE_3=$tmp - fi - if [[ "$RETURN_CODE_1" != "200" && "$RETURN_CODE_2" != "200" && "$RETURN_CODE_3" != "200" ]]; then - uci set ping.ping.conn="1" - uci commit ping - reboot -f - fi - log "Second Ping Test Good" + ptest 3 + if [ $status -eq 0 ]; then + log "Good Ping after Network Restart" + uci set ping.ping.conn="2" + uci commit ping + exit 0 + else + log "Hard Restart" + /usr/lib/rooter/luci/restart.sh $CURRMODEM 11 + ptest 9 + if [ $status -eq 0 ]; then + log "Good Ping after Hard Restart" uci set ping.ping.conn="2" uci commit ping exit 0 else - sleep 20 - tries=$((tries+1)) + reboot -f fi - done - reboot -f + fi fi else log "Good Ping" diff --git a/rooter/0optionalapps/pingtest/files/usr/lib/lua/luci/model/cbi/ping.lua b/rooter/0optionalapps/pingtest/files/usr/lib/lua/luci/model/cbi/ping.lua index bb52017..c1a894f 100644 --- a/rooter/0optionalapps/pingtest/files/usr/lib/lua/luci/model/cbi/ping.lua +++ b/rooter/0optionalapps/pingtest/files/usr/lib/lua/luci/model/cbi/ping.lua @@ -39,4 +39,16 @@ d1:value("100", "100 seconds") d1:value("120", "120 seconds") d1.default=40 +ipv41 = d:option(Value, "ipv41", translate("IPv4 Server :"), translate("First IPv4 server to ping")); +ipv41.rmempty = true; +ipv41.optional=false; + +ipv42 = d:option(Value, "ipv42", translate("IPv4 Server :"), translate("Second IPv4 server to ping")); +ipv42.rmempty = true; +ipv42.optional=false; + +ipv6 = d:option(Value, "ipv6", translate("IPv6 Server :"), translate("IPv6 server to ping")); +ipv6.rmempty = true; +ipv6.optional=false; + return m \ No newline at end of file diff --git a/rooter/0optionalapps/qfirehose/src/firehose_protocol.c b/rooter/0optionalapps/qfirehose/src/firehose_protocol.c index 25c6ea1..7116cde 100644 --- a/rooter/0optionalapps/qfirehose/src/firehose_protocol.c +++ b/rooter/0optionalapps/qfirehose/src/firehose_protocol.c @@ -20,8 +20,9 @@ #define error_return() do {dbg_time("%s %s %d fail\n", __FILE__, __func__, __LINE__); return __LINE__; } while(0) int recv_sc600y_configure_num = 1; -extern int g_is_sc600y_chip; - +extern const char *q_device_type; +static int fh_recv_cmd_sk[2]; + extern unsigned q_erase_all_before_download; extern int update_transfer_bytes(long long bytes_cur); extern int show_progress(); @@ -41,12 +42,12 @@ struct fh_configure_cmd { struct fh_erase_cmd { const char *type; - uint32_t PAGES_PER_BLOCK; - uint32_t SECTOR_SIZE_IN_BYTES; - char label[32]; + //uint32_t PAGES_PER_BLOCK; + //uint32_t SECTOR_SIZE_IN_BYTES; + //char label[32]; uint32_t last_sector; uint32_t num_partition_sectors; - uint32_t physical_partition_number; + //uint32_t physical_partition_number; uint32_t start_sector; }; @@ -54,12 +55,12 @@ struct fh_program_cmd { const char *type; char *filename; uint32_t filesz; - uint32_t PAGES_PER_BLOCK; + //uint32_t PAGES_PER_BLOCK; uint32_t SECTOR_SIZE_IN_BYTES; - char label[32]; - uint32_t last_sector; + //char label[32]; + //uint32_t last_sector; uint32_t num_partition_sectors; - uint32_t physical_partition_number; + //uint32_t physical_partition_number; uint32_t start_sector; }; @@ -88,7 +89,6 @@ struct fh_cmd_header { struct fh_vendor_defines { const char *type; // "vendor" - char buffer[256]; }; struct fh_cmd { @@ -103,7 +103,7 @@ struct fh_cmd { struct fh_vendor_defines vdef; }; int part_upgrade; - char xml_original_data[300]; + char xml_original_data[512]; }; struct fh_data { @@ -111,8 +111,9 @@ struct fh_data { const void *usb_handle; unsigned MaxPayloadSizeToTargetInBytes; unsigned fh_cmd_count; + unsigned fh_patch_count; unsigned ZlpAwareHost; - struct fh_cmd fh_cmd_table[128]; //AG525 have more than 64 partition + struct fh_cmd fh_cmd_table[256]; //AG525 have more than 64 partition unsigned xml_tx_size; unsigned xml_rx_size; @@ -120,9 +121,7 @@ struct fh_data { char xml_rx_buf[1024]; }; -static const char * fh_xml_get_value(const char *xml_line, const char *key) { - static char value[64]; - +static const char * fh_xml_find_value(const char *xml_line, const char *key, char **ppend) { char *pchar = strstr(xml_line, key); char *pend; @@ -143,45 +142,69 @@ static const char * fh_xml_get_value(const char *xml_line, const char *key) { dbg_time("%s: no end %s in %s\n", __func__, "\"", xml_line); return NULL; } + + *ppend = pend; + return pchar; +} + +static const char * fh_xml_get_value(const char *xml_line, const char *key) { + static char value[64]; + char *pend; + const char *pchar = fh_xml_find_value(xml_line, key, &pend); + + if (!pchar) { + return NULL; + } strncpy(value, pchar, pend - pchar); value[pend - pchar] = '\0'; - //dbg_time("%s=%s\n", key, value); - return value; } +static void fh_xml_set_value(char *xml_line, const char *key, unsigned value) { + char *pend; + const char *pchar = fh_xml_find_value(xml_line, key, &pend); + char *tmp_line = strdup(xml_line); + char value_str[32]; + + if (!pchar || !tmp_line) { + return; + } + + snprintf(value_str, sizeof(value_str), "%u", value); + tmp_line[pchar - xml_line] = '\0'; + strcat(tmp_line, value_str); + strcat(tmp_line, pend); + + strcpy(xml_line, tmp_line); + free(tmp_line); +} + static int fh_parse_xml_line(const char *xml_line, struct fh_cmd *fh_cmd) { const char *pchar = NULL; - char *pret; + size_t len = strlen(xml_line); memset(fh_cmd, 0, sizeof( struct fh_cmd)); + strcpy(fh_cmd->xml_original_data, xml_line); + if (fh_cmd->xml_original_data[len - 1] == '\n') + fh_cmd->xml_original_data[len - 1] = '\0'; + if (strstr(xml_line, "vendor=\"quectel\"")) { fh_cmd->vdef.type = "vendor"; - snprintf(fh_cmd->vdef.buffer, sizeof(fh_cmd->vdef.buffer), "%.255s", xml_line); return 0; } else if (!strncmp(xml_line, "erase.type = "erase"; - if ((pchar = fh_xml_get_value(xml_line, "PAGES_PER_BLOCK"))) - fh_cmd->erase.PAGES_PER_BLOCK = atoi(pchar); - if ((pchar = fh_xml_get_value(xml_line, "SECTOR_SIZE_IN_BYTES"))) - fh_cmd->erase.SECTOR_SIZE_IN_BYTES = atoi(pchar); if (strstr(xml_line, "last_sector")) { - if ((pchar = fh_xml_get_value(xml_line, "last_sector"))) + if ((pchar = fh_xml_get_value(xml_line, "last_sector"))) fh_cmd->erase.last_sector = atoi(pchar); - if (strstr(xml_line, "label")) { - if ((pchar = fh_xml_get_value(xml_line, "label"))) - strcpy(fh_cmd->erase.label, pchar); - } } - if ((pchar = fh_xml_get_value(xml_line, "num_partition_sectors"))) - fh_cmd->erase.num_partition_sectors = strtoul(pchar, &pret, 10); - if ((pchar = fh_xml_get_value(xml_line, "physical_partition_number"))) - fh_cmd->erase.physical_partition_number = atoi(pchar); if ((pchar = fh_xml_get_value(xml_line, "start_sector"))) fh_cmd->erase.start_sector = atoi(pchar); + if ((pchar = fh_xml_get_value(xml_line, "num_partition_sectors"))) + fh_cmd->erase.num_partition_sectors = atoi(pchar); + return 0; } else if (!strncmp(xml_line, "program.PAGES_PER_BLOCK = atoi(pchar); - if ((pchar = fh_xml_get_value(xml_line, "SECTOR_SIZE_IN_BYTES"))) - fh_cmd->program.SECTOR_SIZE_IN_BYTES = atoi(pchar); - if (strstr(xml_line, "last_sector")) { - if ((pchar = fh_xml_get_value(xml_line, "last_sector"))) - fh_cmd->program.last_sector = atoi(pchar); - if (strstr(xml_line, "label")) { - if ((pchar = fh_xml_get_value(xml_line, "label"))) - strcpy(fh_cmd->program.label, pchar); - } - } - if ((pchar = fh_xml_get_value(xml_line, "num_partition_sectors"))) - fh_cmd->program.num_partition_sectors = atoi(pchar); - if ((pchar = fh_xml_get_value(xml_line, "physical_partition_number"))) - fh_cmd->program.physical_partition_number = atoi(pchar); - if ((pchar = fh_xml_get_value(xml_line, "start_sector"))) - fh_cmd->program.start_sector = atoi(pchar); - } - else - { - if ((pchar = fh_xml_get_value(xml_line, "start_sector"))) - fh_cmd->program.start_sector = atoi(pchar); - if ((pchar = fh_xml_get_value(xml_line, "num_partition_sectors"))) - fh_cmd->program.num_partition_sectors = atoi(pchar); - if ((pchar = fh_xml_get_value(xml_line, "SECTOR_SIZE_IN_BYTES"))) - fh_cmd->program.SECTOR_SIZE_IN_BYTES = atoi(pchar); - strcpy(fh_cmd->xml_original_data, xml_line); - } + } + if ((pchar = fh_xml_get_value(xml_line, "start_sector"))) + fh_cmd->program.start_sector = atoi(pchar); + if ((pchar = fh_xml_get_value(xml_line, "num_partition_sectors"))) + fh_cmd->program.num_partition_sectors = atoi(pchar); + if ((pchar = fh_xml_get_value(xml_line, "SECTOR_SIZE_IN_BYTES"))) + fh_cmd->program.SECTOR_SIZE_IN_BYTES = atoi(pchar); return 0; } else if (!strncmp(xml_line, "patch.type = "patch"; - if ((pchar = fh_xml_get_value(xml_line, "filename"))) - { - fh_cmd->patch.filename = strdup(pchar); - if(fh_cmd->patch.filename[0] == '\0' || strncasecmp(fh_cmd->patch.filename, "DISK",4)) - {//some fw version have blank program line, ignore it. - return -1; - } - } - strcpy(fh_cmd->xml_original_data, xml_line); - + pchar = fh_xml_get_value(xml_line, "filename"); + if (pchar && strcmp(pchar, "DISK")) + return -1; return 0; } else if (!strncmp(xml_line, "xml_tx_buf, fh_data->xml_tx_size, fp)) { char *xml_line = strstr(fh_data->xml_tx_buf, "<"); - - if (xml_line && strstr(xml_line, "")) { - if (strstr(xml_line, "/>") < strstr(xml_line, "") && strstr(xml_line, ""); + + if (c_end) { + /* + + + + */ + char *tmp = strstr(xml_line, "/>"); + if (tmp && (tmp < c_start || tmp > c_end)) { + memset(c_start, ' ', c_end - c_start + strlen("-->")); + goto __fh_parse_xml_line; + } + + continue; + } + else { + /* + + --> + */ + do { + if (fgets(fh_data->xml_tx_buf, fh_data->xml_tx_size, fp) == NULL) { break; }; + xml_line = fh_data->xml_tx_buf; + } while (!strstr(xml_line, "-->") && strstr(xml_line, " +
        +
        + + + +
        +
        +
        +
        + +
        +
        +
        +
        + +
        <%=headername or "?"%>
        +
        +
        +
        +
        +
        +
        + <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%> +
        +

        <%:No password set!%>

        +

        <%:There is no password set on this router. Go to System->Administration to create password.%> +

        + <% if disp.lookup("admin/system/admin") then %> + + <% end %> +
        + <%- end -%> + + + + diff --git a/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/header_login.htm b/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/header_login.htm new file mode 100644 index 0000000..62fedfb --- /dev/null +++ b/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/header_login.htm @@ -0,0 +1,116 @@ +<%# + edge is a clean HTML5 theme for LuCI. It is based on luci-theme-material edge Template + + luci-theme-edge + Copyright 2020 Jerrykuku + + Have a bug? Please create an issue here on GitHub! + https://github.com/jerrykuku/luci-theme-edge/issues + + luci-theme-material: + Copyright 2015 Lutty Yang + + Agron Theme + https://demos.creative-tim.com/edge-dashboard/index.html + + Licensed to the public under the Apache License 2.0 +-%> + +<% + local sys = require "luci.sys" + local util = require "luci.util" + local http = require "luci.http" + local disp = require "luci.dispatcher" + + local boardinfo = util.ubus("system", "board") + local node = disp.context.dispatched + local fs = require "nixio.fs" + local nutil = require "nixio.util" + local uci = require 'luci.model.uci'.cursor() + + -- send as HTML5 + http.prepare_content("text/html") + + math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 9))) + + -- Custom settings + local mode = 'normal' + local dark_css = fs.readfile('/www/luci-static/argon/css/dark.css') + local bar_color = '#5e72e4' + local primary, dark_primary, blur_radius, blur_radius_dark, blur_opacity + if fs.access('/etc/config/argon') then + primary = uci:get_first('argon', 'global', 'primary') + dark_primary = uci:get_first('argon', 'global', 'dark_primary') + blur_radius = uci:get_first('argon', 'global', 'blur') + blur_radius_dark = uci:get_first('argon', 'global', 'blur_dark') + blur_opacity = uci:get_first('argon', 'global', 'transparency') + blur_opacity_dark = uci:get_first('argon', 'global', 'transparency_dark') + mode = uci:get_first('argon', 'global', 'mode') + bar_color = mode == 'dark' and dark_primary or primary + end + +-%> + + + + + + + <%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> + - LuCI + + + + + + + + + + + - LuCI"> + - LuCI"> + + + + + + + + + + + + + + + <% if node and node.css then %> + + <% end -%> + <% if css then %> + + <% end -%> + + + + + + + +"> + \ No newline at end of file diff --git a/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/out_header_login.htm b/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/out_header_login.htm new file mode 100644 index 0000000..c550b21 --- /dev/null +++ b/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/out_header_login.htm @@ -0,0 +1,38 @@ +<%# + Copyright 2008 Steven Barth + Copyright 2008-2019 Jo-Philipp Wich + Licensed to the public under the Apache License 2.0. +-%> + +<% + if not luci.dispatcher.context.template_header_sent then + include("themes/" .. theme .. "/header_login") + luci.dispatcher.context.template_header_sent = true + end + + local applyconf = luci.config and luci.config.apply +%> + + + + diff --git a/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/sysauth.htm b/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/sysauth.htm new file mode 100644 index 0000000..e401c3d --- /dev/null +++ b/rooter/0themes/luci-theme-argon/luasrc/view/themes/argon/sysauth.htm @@ -0,0 +1,276 @@ +<%# + Argon is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI and Argon Template + + luci-theme-argon + Copyright 2020 Jerryk + + Have a bug? Please create an issue here on GitHub! + https://github.com/jerrykuku/luci-theme-argon/issues + + luci-theme-bootstrap: + Copyright 2008 Steven Barth + Copyright 2008-2016 Jo-Philipp Wich + Copyright 2012 David Menting + + MUI: + https://github.com/muicss/mui + + Agron Theme + https://demos.creative-tim.com/argon-dashboard/index.html + + Licensed to the public under the Apache License 2.0 +-%> + +<%+header_login%> +<% + local util = require "luci.util" + local uci = require "luci.model.uci".cursor() + logosize = uci:get("custom", "logo", "size") + if logosize == nil then + logosize = "small" + end + + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end + + local boardinfo = util.ubus("system", "board") + if boardinfo.model == nil then + boardinfo.model = " " + end + if file_exists("/etc/custom") then + file = io.open("/etc/custom", "r") + board = file:read("*line") + model = file:read("*line") + hostname = file:read("*line") + file:close() + else + board = boardinfo.model + model = boardinfo.model + end + local headername = "" + local file = io.open("/etc/header_msg", "r") + if file ~= nil then + line = file:read("*line") + line = line:gsub("", model) + headername = headername .. line + line = file:read("*line") + line = file:read("*line") + linex = file:read("*line") + if linex ~= nil then + img_name = resource .. linex + else + img_name = resource .. "/img/tomato.png" + end + file:close() + end + + local fs = require "nixio.fs" + local nutil = require "nixio.util" + + function glob(...) + local iter, code, msg = fs.glob(...) + if iter then + return nutil.consume(iter) + else + return nil, code, msg + end + end + + function getExtension(str) + return str:match(".+%.(%w+)$") + end + + local bgcount = 0 + local currentBg = {} + local bgs,attr = {} + local theme_dir = "/luci-static/background/" + for i, f in ipairs(glob("/www" .. theme_dir .. "*")) do + attr = fs.stat(f) + if attr then + local ext = getExtension(fs.basename(f)) + if ext == "jpg" or ext == "png" or ext == "gif" or ext == "mp4" then + local bg = {} + bg.type = ext + bg.url = theme_dir .. fs.basename(f) + table.insert(bgs,bg) + bgcount = bgcount + 1 + end + end + end + + if bgcount > 0 then + currentBg = bgs[math.random(1,bgcount)] + end + + iframe = uci:get("iframe", "login", "logframe") + if iframe == nil then + iframe = "0" + end + if iframe == "1" then + os.execute("/usr/lib/iframe/update.sh") + ifloc = uci:get("iframe", "login", "logtype") + ifimg = "/luci-static/img/" .. uci:get("iframe", "login", "logimage") + ifr = true + else + ifr = false + end + +%> + + + + + + \ No newline at end of file diff --git a/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/header.htm b/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/header.htm new file mode 100644 index 0000000..0a34e6f --- /dev/null +++ b/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/header.htm @@ -0,0 +1,306 @@ +<%# + Argon is a clean HTML5 theme for LuCI. It is based on luci-theme-material Argon Template + + luci-theme-argon + Copyright 2020 Jerrykuku + + Have a bug? Please create an issue here on GitHub! + https://github.com/jerrykuku/luci-theme-argon/issues + + luci-theme-material: + Copyright 2015 Lutty Yang + + Agron Theme + https://demos.creative-tim.com/argon-dashboard/index.html + + Licensed to the public under the Apache License 2.0 +-%> + +<% + local sys = require "luci.sys" + local util = require "luci.util" + local http = require "luci.http" + local disp = require "luci.dispatcher" + + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end + + local boardinfo = util.ubus("system", "board") + if boardinfo.model == nil then + boardinfo.model = " " + end + if file_exists("/etc/custom") then + file = io.open("/etc/custom", "r") + board = file:read("*line") + model = file:read("*line") + hostname = file:read("*line") + file:close() + else + board = boardinfo.model + model = boardinfo.model + end + local headername = "      " + local file = io.open("/etc/header_msg", "r") + if file ~= nil then + line = file:read("*line") + line = line:gsub("", model) + line = line:gsub(" ", " ") + headername = headername .. line + line = file:read("*line") + linex = file:read("*line") + if linex ~= nil then + img_name = resource .. linex + else + img_name = resource .. "/img/header.png" + end + file:close() + end + + local node = disp.context.dispatched + + local fs = require "nixio.fs" + local nutil = require "nixio.util" + local uci = require 'luci.model.uci'.cursor() + + -- send as HTML5 + http.prepare_content("text/html") + math.randomseed(os.time()) + + -- Custom settings + local mode = 'normal' + local dark_css = fs.readfile('/www/luci-static/argondark/css/dark.css') + local bar_color = '#5e72e4' + local primary, dark_primary, blur_radius, blur_radius_dark, blur_opacity + if fs.access('/etc/config/argondark') then + primary = uci:get_first('argondark', 'global', 'primary') + dark_primary = uci:get_first('argondark', 'global', 'dark_primary') + blur_radius = uci:get_first('argondark', 'global', 'blur') + blur_radius_dark = uci:get_first('argondark', 'global', 'blur_dark') + blur_opacity = uci:get_first('argondark', 'global', 'transparency') + blur_opacity_dark = uci:get_first('argondark', 'global', 'transparency_dark') + mode = uci:get_first('argondark', 'global', 'mode') + bar_color = mode == 'dark' and dark_primary or primary + end +-%> + + + + + + + <%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> + - LuCI + + + + + + + + + + + - LuCI"> + - LuCI"> + + + + + + + + + + + + + + + <% if node and node.css then %> + + <% end -%> + <% if css then %> + + <% end -%> + + + + + + + + +"> + +
        + +
        +
        +
        +
        + +
        <%=headername or "?"%>
        +
        +
        +
        +
        +
        +
        + <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%> +
        +

        <%:No password set!%>

        +

        <%:There is no password set on this router. Go to System->Administration to create password.%> +

        + <% if disp.lookup("admin/system/admin") then %> + + <% end %> +
        + <%- end -%> + + + + diff --git a/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/header_login.htm b/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/header_login.htm new file mode 100644 index 0000000..dbe6608 --- /dev/null +++ b/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/header_login.htm @@ -0,0 +1,116 @@ +<%# + edge is a clean HTML5 theme for LuCI. It is based on luci-theme-material edge Template + + luci-theme-edge + Copyright 2020 Jerrykuku + + Have a bug? Please create an issue here on GitHub! + https://github.com/jerrykuku/luci-theme-edge/issues + + luci-theme-material: + Copyright 2015 Lutty Yang + + Agron Theme + https://demos.creative-tim.com/edge-dashboard/index.html + + Licensed to the public under the Apache License 2.0 +-%> + +<% + local sys = require "luci.sys" + local util = require "luci.util" + local http = require "luci.http" + local disp = require "luci.dispatcher" + + local boardinfo = util.ubus("system", "board") + local node = disp.context.dispatched + local fs = require "nixio.fs" + local nutil = require "nixio.util" + local uci = require 'luci.model.uci'.cursor() + + -- send as HTML5 + http.prepare_content("text/html") + + math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 9))) + + -- Custom settings + local mode = 'normal' + local dark_css = fs.readfile('/www/luci-static/argondark/css/dark.css') + local bar_color = '#5e72e4' + local primary, dark_primary, blur_radius, blur_radius_dark, blur_opacity + if fs.access('/etc/config/argondark') then + primary = uci:get_first('argondark', 'global', 'primary') + dark_primary = uci:get_first('argondark', 'global', 'dark_primary') + blur_radius = uci:get_first('argondark', 'global', 'blur') + blur_radius_dark = uci:get_first('argondark', 'global', 'blur_dark') + blur_opacity = uci:get_first('argondark', 'global', 'transparency') + blur_opacity_dark = uci:get_first('argondark', 'global', 'transparency_dark') + mode = uci:get_first('argondark', 'global', 'mode') + bar_color = mode == 'dark' and dark_primary or primary + end + +-%> + + + + + + + <%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> + - LuCI + + + + + + + + + + + - LuCI"> + - LuCI"> + + + + + + + + + + + + + + + <% if node and node.css then %> + + <% end -%> + <% if css then %> + + <% end -%> + + + + + + + +"> + \ No newline at end of file diff --git a/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/out_header_login.htm b/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/out_header_login.htm new file mode 100644 index 0000000..c550b21 --- /dev/null +++ b/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/out_header_login.htm @@ -0,0 +1,38 @@ +<%# + Copyright 2008 Steven Barth + Copyright 2008-2019 Jo-Philipp Wich + Licensed to the public under the Apache License 2.0. +-%> + +<% + if not luci.dispatcher.context.template_header_sent then + include("themes/" .. theme .. "/header_login") + luci.dispatcher.context.template_header_sent = true + end + + local applyconf = luci.config and luci.config.apply +%> + + + + diff --git a/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/sysauth.htm b/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/sysauth.htm new file mode 100644 index 0000000..e401c3d --- /dev/null +++ b/rooter/0themes/luci-theme-argondark/files/usr/lib/lua/luci/view/themes/argondark/sysauth.htm @@ -0,0 +1,276 @@ +<%# + Argon is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI and Argon Template + + luci-theme-argon + Copyright 2020 Jerryk + + Have a bug? Please create an issue here on GitHub! + https://github.com/jerrykuku/luci-theme-argon/issues + + luci-theme-bootstrap: + Copyright 2008 Steven Barth + Copyright 2008-2016 Jo-Philipp Wich + Copyright 2012 David Menting + + MUI: + https://github.com/muicss/mui + + Agron Theme + https://demos.creative-tim.com/argon-dashboard/index.html + + Licensed to the public under the Apache License 2.0 +-%> + +<%+header_login%> +<% + local util = require "luci.util" + local uci = require "luci.model.uci".cursor() + logosize = uci:get("custom", "logo", "size") + if logosize == nil then + logosize = "small" + end + + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end + + local boardinfo = util.ubus("system", "board") + if boardinfo.model == nil then + boardinfo.model = " " + end + if file_exists("/etc/custom") then + file = io.open("/etc/custom", "r") + board = file:read("*line") + model = file:read("*line") + hostname = file:read("*line") + file:close() + else + board = boardinfo.model + model = boardinfo.model + end + local headername = "" + local file = io.open("/etc/header_msg", "r") + if file ~= nil then + line = file:read("*line") + line = line:gsub("", model) + headername = headername .. line + line = file:read("*line") + line = file:read("*line") + linex = file:read("*line") + if linex ~= nil then + img_name = resource .. linex + else + img_name = resource .. "/img/tomato.png" + end + file:close() + end + + local fs = require "nixio.fs" + local nutil = require "nixio.util" + + function glob(...) + local iter, code, msg = fs.glob(...) + if iter then + return nutil.consume(iter) + else + return nil, code, msg + end + end + + function getExtension(str) + return str:match(".+%.(%w+)$") + end + + local bgcount = 0 + local currentBg = {} + local bgs,attr = {} + local theme_dir = "/luci-static/background/" + for i, f in ipairs(glob("/www" .. theme_dir .. "*")) do + attr = fs.stat(f) + if attr then + local ext = getExtension(fs.basename(f)) + if ext == "jpg" or ext == "png" or ext == "gif" or ext == "mp4" then + local bg = {} + bg.type = ext + bg.url = theme_dir .. fs.basename(f) + table.insert(bgs,bg) + bgcount = bgcount + 1 + end + end + end + + if bgcount > 0 then + currentBg = bgs[math.random(1,bgcount)] + end + + iframe = uci:get("iframe", "login", "logframe") + if iframe == nil then + iframe = "0" + end + if iframe == "1" then + os.execute("/usr/lib/iframe/update.sh") + ifloc = uci:get("iframe", "login", "logtype") + ifimg = "/luci-static/img/" .. uci:get("iframe", "login", "logimage") + ifr = true + else + ifr = false + end + +%> + + + + + + + diff --git a/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/header.htm b/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/header.htm new file mode 100644 index 0000000..e91b72b --- /dev/null +++ b/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/header.htm @@ -0,0 +1,254 @@ +<%# + Material is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI + + luci-theme-material + Copyright 2015-2017 Lutty Yang + + Have a bug? Please create an issue here on GitHub! + https://github.com/LuttyYang/luci-theme-material/issues + + luci-theme-bootstrap: + Copyright 2008 Steven Barth + Copyright 2008-2016 Jo-Philipp Wich + Copyright 2012 David Menting + + MUI: + https://github.com/muicss/mui + + Licensed to the public under the Apache License 2.0 +-%> + +<% + local sys = require "luci.sys" + local util = require "luci.util" + local http = require "luci.http" + local disp = require "luci.dispatcher" + + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end + + local boardinfo = util.ubus("system", "board") + if boardinfo.model == nil then + boardinfo.model = " " + end + if file_exists("/etc/custom") then + file = io.open("/etc/custom", "r") + board = file:read("*line") + model = file:read("*line") + hostname = file:read("*line") + file:close() + else + board = boardinfo.model + model = boardinfo.model + end + local headername = "      " + local file = io.open("/etc/header_msg", "r") + if file ~= nil then + line = file:read("*line") + line = line:gsub("", model) + line = line:gsub(" ", " ") + headername = headername .. line + line = file:read("*line") + if line ~= nil then + img_name = resource .. line + else + img_name = resource .. "/img/header.png" + end + file:close() + end + + local node = disp.context.dispatched + + -- send as HTML5 + http.prepare_content("text/html") +-%> + + + + + <%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI + + + + + + + - LuCI"> + - LuCI"> + + + <% if node and node.css then %> + + <% end -%> + <% if css then %> + + <% end -%> + + + + + +"> +
        + +
        +
        +
        <%:Collecting data...%>
        + +
        +
        +
        +
        + <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%> +
        +

        <%:No password set!%>

        +

        <%:There is no password set on this router. Go to System->Administration to create password.%>

        + <% if disp.lookup("admin/system/admin") then %> + + <% end %> +
        + <%- end -%> + + + + diff --git a/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/header_login.htm b/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/header_login.htm new file mode 100644 index 0000000..d94c002 --- /dev/null +++ b/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/header_login.htm @@ -0,0 +1,123 @@ +<%# + edge is a clean HTML5 theme for LuCI. It is based on luci-theme-material edge Template + + luci-theme-edge + Copyright 2020 Jerrykuku + + Have a bug? Please create an issue here on GitHub! + https://github.com/jerrykuku/luci-theme-edge/issues + + luci-theme-material: + Copyright 2015 Lutty Yang + + Agron Theme + https://demos.creative-tim.com/edge-dashboard/index.html + + Licensed to the public under the Apache License 2.0 +-%> + +<% + local sys = require "luci.sys" + local util = require "luci.util" + local http = require "luci.http" + local disp = require "luci.dispatcher" + + local boardinfo = util.ubus("system", "board") + local node = disp.context.dispatched + local fs = require "nixio.fs" + local nutil = require "nixio.util" + local uci = require 'luci.model.uci'.cursor() + + -- send as HTML5 + http.prepare_content("text/html") + + math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 9))) + + -- Custom settings + local mode = 'normal' + local dark_css = fs.readfile('/www/luci-static/material/css/dark.css') + local bar_color = '#5e72e4' + local primary, dark_primary, blur_radius, blur_radius_dark, blur_opacity + if fs.access('/etc/config/material') then + primary = uci:get_first('material', 'global', 'primary') + dark_primary = uci:get_first('material', 'global', 'dark_primary') + blur_radius = uci:get_first('material', 'global', 'blur') + blur_radius_dark = uci:get_first('material', 'global', 'blur_dark') + blur_opacity = uci:get_first('material', 'global', 'transparency') + blur_opacity_dark = uci:get_first('material', 'global', 'transparency_dark') + mode = uci:get_first('material', 'global', 'mode') + bar_color = mode == 'dark' and dark_primary or primary + end + +-%> + + + + + + + <%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> + - LuCI + + + + + + + + + + + - LuCI"> + - LuCI"> + + + + + + + + + + + + + + + <% if node and node.css then %> + + <% end -%> + <% if css then %> + + <% end -%> + + + + + + + +"> + \ No newline at end of file diff --git a/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/out_header_login.htm b/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/out_header_login.htm new file mode 100644 index 0000000..c550b21 --- /dev/null +++ b/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/out_header_login.htm @@ -0,0 +1,38 @@ +<%# + Copyright 2008 Steven Barth + Copyright 2008-2019 Jo-Philipp Wich + Licensed to the public under the Apache License 2.0. +-%> + +<% + if not luci.dispatcher.context.template_header_sent then + include("themes/" .. theme .. "/header_login") + luci.dispatcher.context.template_header_sent = true + end + + local applyconf = luci.config and luci.config.apply +%> + + + + diff --git a/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/sysauth.htm b/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/sysauth.htm new file mode 100644 index 0000000..bd61bf8 --- /dev/null +++ b/rooter/0themes/luci-theme-material/files/usr/lib/lua/luci/view/themes/material/sysauth.htm @@ -0,0 +1,276 @@ +<%# + Argon is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI and Argon Template + + luci-theme-argon + Copyright 2020 Jerryk + + Have a bug? Please create an issue here on GitHub! + https://github.com/jerrykuku/luci-theme-argon/issues + + luci-theme-bootstrap: + Copyright 2008 Steven Barth + Copyright 2008-2016 Jo-Philipp Wich + Copyright 2012 David Menting + + MUI: + https://github.com/muicss/mui + + Agron Theme + https://demos.creative-tim.com/argon-dashboard/index.html + + Licensed to the public under the Apache License 2.0 +-%> + +<%+header_login%> +<% + local util = require "luci.util" + local uci = require "luci.model.uci".cursor() + logosize = uci:get("custom", "logo", "size") + if logosize == nil then + logosize = "small" + end + + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end + + local boardinfo = util.ubus("system", "board") + if boardinfo.model == nil then + boardinfo.model = " " + end + if file_exists("/etc/custom") then + file = io.open("/etc/custom", "r") + board = file:read("*line") + model = file:read("*line") + hostname = file:read("*line") + file:close() + else + board = boardinfo.model + model = boardinfo.model + end + local headername = "" + local file = io.open("/etc/header_msg", "r") + if file ~= nil then + line = file:read("*line") + line = line:gsub("", model) + headername = headername .. line + line = file:read("*line") + line = file:read("*line") + linex = file:read("*line") + if linex ~= nil then + img_name = resource .. linex + else + img_name = resource .. "/img/tomato.png" + end + file:close() + end + + local fs = require "nixio.fs" + local nutil = require "nixio.util" + + function glob(...) + local iter, code, msg = fs.glob(...) + if iter then + return nutil.consume(iter) + else + return nil, code, msg + end + end + + function getExtension(str) + return str:match(".+%.(%w+)$") + end + + local bgcount = 0 + local currentBg = {} + local bgs,attr = {} + local theme_dir = "/luci-static/background/" + for i, f in ipairs(glob("/www" .. theme_dir .. "*")) do + attr = fs.stat(f) + if attr then + local ext = getExtension(fs.basename(f)) + if ext == "jpg" or ext == "png" or ext == "gif" or ext == "mp4" then + local bg = {} + bg.type = ext + bg.url = theme_dir .. fs.basename(f) + table.insert(bgs,bg) + bgcount = bgcount + 1 + end + end + end + + if bgcount > 0 then + currentBg = bgs[math.random(1,bgcount)] + end + + iframe = uci:get("iframe", "login", "logframe") + if iframe == nil then + iframe = "0" + end + if iframe == "1" then + os.execute("/usr/lib/iframe/update.sh") + ifloc = uci:get("iframe", "login", "logtype") + ifimg = "/luci-static/img/" .. uci:get("iframe", "login", "logimage") + ifr = true + else + ifr = false + end + +%> + +