diff --git a/luci-theme-openmptcprouter/luasrc/view/themes/openmptcprouter/header.htm b/luci-theme-openmptcprouter/luasrc/view/themes/openmptcprouter/header.htm index f78ae2af1..2119ab857 100644 --- a/luci-theme-openmptcprouter/luasrc/view/themes/openmptcprouter/header.htm +++ b/luci-theme-openmptcprouter/luasrc/view/themes/openmptcprouter/header.htm @@ -46,7 +46,7 @@
diff --git a/openmptcprouter/files/etc/uci-defaults/1920-omr-network b/openmptcprouter/files/etc/uci-defaults/1920-omr-network new file mode 100755 index 000000000..40ac946bf --- /dev/null +++ b/openmptcprouter/files/etc/uci-defaults/1920-omr-network @@ -0,0 +1,297 @@ +#!/bin/sh +. /lib/functions.sh + +_setup_macaddr() { + uci -q get "network.$1.macaddr" >/dev/null && return + uci -q set "network.$1.macaddr=$2" +} + +_setup_macvlan() { + uci -q get "network.$1_dev.ifname" >/dev/null && return + + # do not create macvlan for vlan + local _ifname + _ifname=$(uci -q get "network.$1.ifname") + case "$_ifname" in + eth*.*) return ;; + esac + + uci -q batch <<-EOF + set network.$1_dev=device + set network.$1_dev.name=$1 + set network.$1_dev.type=macvlan + set network.$1_dev.ifname=$_ifname + set network.$1.ifname=$1 + set network.$1.type=macvlan + set network.$1.masterintf=$_ifname + set macvlan.$1=macvlan + set macvlan.$1.name=$1 + set macvlan.$1.ifname=$_ifname + EOF + _macaddr=$(uci -q get "network.$1.macaddr") + _setup_macaddr "$1_dev" "${_macaddr:-auto$(date +%s)}" +} + +_setup_macvlan_update() { + uci -q get "network.$1_dev.ifname" >/dev/null || return + + uci -q batch <<-EOF + set macvlan.$1=macvlan + set macvlan.$1.ifname=$_ifname + commit macvlan + EOF +} + +_setup_mptcp_handover_to_on() { + if [ "$(uci -q get network.$1.multipath)" = "handover" ]; then + uci -q set network.$1.multipath=on + fi + if [ "$(uci -q get openmptcprouter.$1.multipath)" = "handover" ]; then + uci -q set openmptcprouter.$1.multipath=on + fi +} + +_setup_multipath_off() { + uci -q get "network.$1.multipath" >/dev/null && return + uci -q set "network.$1.multipath=off" +} + +_setup_wan_interface() { + uci -q batch <<-EOF + set network.$1=interface + set network.$1.ifname=$2 + set network.$1.proto=static + set network.$1.ip4table=wan + set network.$1.multipath=$3 + set network.$1.defaultroute=0 + commit network + add_list firewall.@zone[1].network=$1 + commit firewall + EOF + [ -n "$4" ] && uci -q set network.$1.type=$4 +} + +config_load network +config_foreach _setup_macvlan_update interface +config_foreach _setup_mptcp_handover_to_on interface + +if [ "$(uci -q show network.lan | grep multipath)" != "" ]; then + exit 0 +fi + +lanif="eth0" +if [ "$(grep rockchip /etc/os-release)" != "" ]; then + lanif="eth1" +elif [ -d /sys/class/net/lan0 -o -n "$(ip link | grep ' lan0')" ] && [ -d /sys/class/net/wan -o -n "$(ip link | grep ' wan@')" -o -n "$(ip link | grep ' wan:')" ]; then + lanif="wan" +elif [ -d /sys/class/net/lan1 -o -n "$(ip link | grep ' lan1')" ] && [ -d /sys/class/net/wan -o -n "$(ip link | grep ' wan@')" -o -n "$(ip link | grep ' wan:')" ]; then + lanif="wan" +elif [ -d /sys/class/net/lan ] || [ -n "$(ip link | grep ' lan')" ]; then + lanif="lan" +elif [ "$(swconfig list 2>&1 | grep switch0)" != "" ] && [ -d '/sys/class/net/eth1.5' ]; then + lanif="eth1.5" + uci -q batch <<-EOF + set network.@switch_vlan[0]=switch_vlan + set network.@switch_vlan[0].device='switch0' + set network.@switch_vlan[0].vlan=1 + set network.@switch_vlan[0].vid=1 + set network.@switch_vlan[0].ports='3 5t' + add network switch_vlan + set network.@switch_vlan[1].device='switch0' + set network.@switch_vlan[1].vlan=2 + set network.@switch_vlan[1].vid=2 + set network.@switch_vlan[1].ports='2 5t' + add network switch_vlan + set network.@switch_vlan[2].device='switch0' + set network.@switch_vlan[2].vlan=3 + set network.@switch_vlan[2].vid=3 + set network.@switch_vlan[2].ports='1 5t' + add network switch_vlan + set network.@switch_vlan[3].device='switch0' + set network.@switch_vlan[3].vlan=4 + set network.@switch_vlan[3].vid=4 + set network.@switch_vlan[3].ports='0 5t' + add network switch_vlan + set network.@switch_vlan[4].device='switch0' + set network.@switch_vlan[4].vlan=5 + set network.@switch_vlan[4].vid=5 + set network.@switch_vlan[4].ports='4 6t' + EOF +elif [ "$(swconfig list 2>&1 | grep switch0)" != "" ] && [ -d /sys/class/net/eth1 ]; then + lanif="eth1" +elif [ ! -d /sys/class/net/eth1 ] && [ -d /sys/class/net/eth0 ]; then + lanif="eth0" +fi +uci -q batch <<-EOF +delete network.lan.type +set network.lan=interface +set network.lan.proto=static +set network.lan.ipaddr=192.168.100.1 +set network.lan.netmask=255.255.255.0 +set network.lan.ifname=${lanif} +set network.lan.metric=2048 +set network.lan.ipv6=0 +set network.lan.delegate=0 +EOF + +uci -q batch <<-EOF +delete network.none +delete network.wan +delete network.if6rd +reorder network.loopback=0 +reorder network.globals=1 +reorder network.lan=2 +set network.globals.multipath=enable +EOF + +# Set the ip rule for the lan with a pref of 100 +uci -q show network.lan_rule >/dev/null || \ + uci -q batch <<-EOF + set network.lan_rule=rule + set network.lan_rule.lookup=lan + set network.lan_rule.priority=100 + EOF + +if [ "$(uci -q get network.vpn0.proto)" = "none" ]; then + uci -q delete network.vpn0 +fi + +config_load network +config_foreach _setup_multipath_off interface + +# Add the lan as a named routing table +if ! grep -s -q "lan" /etc/iproute2/rt_tables; then + echo "50 lan" >> /etc/iproute2/rt_tables +fi +uci -q set network.lan.ip4table='lan' + +#uci -q set "network.lan.ip6assign=64" + +# Create WAN interfaces +if [ "$(uci -q show network.wan1 | grep multipath)" = "" ] && [ -z "$(uci -q get network.wan1.multipath)" ]; then + if [ "$(grep rockchip /etc/os-release)" != "" ]; then + _setup_wan_interface wan1 eth0 master macvlan + _setup_wan_interface wan2 eth0 on macvlan + _setup_macvlan wan1 + _setup_macvlan wan2 + elif [ "$(swconfig list 2>&1 | grep switch0)" != "" ]; then + _setup_wan_interface wan1 eth0.1 master + _setup_wan_interface wan2 eth0.2 on + _setup_wan_interface wan3 eth0.3 on + _setup_wan_interface wan4 eth0.4 on + elif [ -d /sys/class/net/wan ] || [ -n "$(ip link | grep ' wan:')" ] || [ -n "$(ip link | grep ' wan@')" ]; then + if [ -d /sys/class/net/lan0 -o -n "$(ip link | grep ' lan0')" ] && [ -d /sys/class/net/lan1 -o -n "$(ip link | grep ' lan1')" ]; then + _setup_wan_interface wan1 lan0 master + _setup_wan_interface wan2 lan1 on + + _macaddr=$(uci -q get "network.lan0.macaddr") + _setup_macaddr "wan1" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + _macaddr=$(uci -q get "network.lan1.macaddr") + _setup_macaddr "wan2" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + if [ -d /sys/class/net/lan2 ] || [ -n "$(ip link | grep ' lan2')" ]; then + _setup_wan_interface wan3 lan2 on + _macaddr=$(uci -q get "network.lan2.macaddr") + _setup_macaddr "wan3" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + if [ -d /sys/class/net/lan3 ] || [ -n "$(ip link | grep ' lan3')" ]; then + _setup_wan_interface wan4 lan3 on + _macaddr=$(uci -q get "network.lan3.macaddr") + _setup_macaddr "wan4" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + fi + fi + elif [ -d /sys/class/net/lan1 -o -n "$(ip link | grep ' lan1')" ] && [ -d /sys/class/net/lan2 -o -n "$(ip link | grep ' lan2')" ]; then + _setup_wan_interface wan1 lan1 master + _setup_wan_interface wan2 lan2 on + + _macaddr=$(uci -q get "network.lan1.macaddr") + _setup_macaddr "wan1" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + _macaddr=$(uci -q get "network.lan2.macaddr") + _setup_macaddr "wan2" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + if [ -d /sys/class/net/lan3 ] || [ -n "$(ip link | grep ' lan3')" ]; then + _setup_wan_interface wan3 lan3 on + _macaddr=$(uci -q get "network.lan3.macaddr") + _setup_macaddr "wan3" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + if [ -d /sys/class/net/lan4 ] || [ -n "$(ip link | grep ' lan4')" ]; then + _setup_wan_interface wan4 lan4 on + _macaddr=$(uci -q get "network.lan4.macaddr") + _setup_macaddr "wan4" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + fi + fi + else + _setup_wan_interface wan1 wan master macvlan + _setup_wan_interface wan2 wan on macvlan + _setup_macvlan wan1 + _setup_macvlan wan2 + fi + elif [ -d /sys/class/net/wan1 ] || [ -n "$(ip link | grep ' wan1')" ]; then + if [ -d /sys/class/net/wan2 ] || [ -n "$(ip link | grep ' wan2')" ]; then + _setup_wan_interface wan1 wan1 master + _setup_wan_interface wan2 wan2 on + + _macaddr=$(uci -q get "network.wan1.macaddr") + _setup_macaddr "wan1" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + _macaddr=$(uci -q get "network.wan2.macaddr") + _setup_macaddr "wan2" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + + if [ -d /sys/class/net/wan3 ] || [ -n "$(ip link | grep ' wan3')" ]; then + _setup_wan_interface wan3 wan3 on + _macaddr=$(uci -q get "network.wan3.macaddr") + _setup_macaddr "wan3" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + if [ -d /sys/class/net/wan4 ] || [ -n "$(ip link | grep ' wan4')" ]; then + _setup_wan_interface wan4 wan4 on + _macaddr=$(uci -q get "network.wan4.macaddr") + _setup_macaddr "wan4" "${_macaddr:-$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/' -e 's/^\(.\)[13579bdf]/\10/')}" + fi + fi + else + _setup_wan_interface wan1 wan1 master macvlan + _setup_wan_interface wan2 wan1 on macvlan + _setup_macvlan wan1 + _setup_macvlan wan2 + fi + elif [ -d /sys/class/net/eth1 ] || [ -n "$(ip link | grep ' eth1:')" ]; then + if [ -d /sys/class/net/eth2 ] || [ -n "$(ip link | grep ' eth2:')" ]; then + _setup_wan_interface wan1 eth1 master + _setup_wan_interface wan2 eth2 on + if [ -d /sys/class/net/eth3 ] || [ -n "$(ip link | grep ' eth3:')" ]; then + _setup_wan_interface wan3 eth3 on + fi + if [ -d /sys/class/net/eth4 ] || [ -n "$(ip link | grep ' eth4:')" ]; then + _setup_wan_interface wan4 eth4 on + fi + if [ -d /sys/class/net/eth5 ] || [ -n "$(ip link | grep ' eth5:')" ]; then + _setup_wan_interface wan5 eth5 on + fi + if [ -d /sys/class/net/eth6 ] || [ -n "$(ip link | grep ' eth6:')" ]; then + _setup_wan_interface wan6 eth6 on + fi + if [ -d /sys/class/net/eth7 ] || [ -n "$(ip link | grep ' eth7:')" ]; then + _setup_wan_interface wan7 eth7 on + fi + if [ -d /sys/class/net/eth8 ] || [ -n "$(ip link | grep ' eth8:')" ]; then + _setup_wan_interface wan8 eth8 on + fi + else + _setup_wan_interface wan1 eth1 master macvlan + _setup_wan_interface wan2 eth1 on macvlan + _setup_macvlan wan1 + _setup_macvlan wan2 + fi + elif [ -d /sys/class/net/eth0.1 ] && [ -d /sys/class/net/eth0.2 ]; then + _setup_wan_interface wan1 eth0.1 master + _setup_wan_interface wan2 eth0.2 on + else + _setup_wan_interface wan1 eth0 master macvlan + _setup_wan_interface wan2 eth0 on macvlan + _setup_macvlan wan1 + _setup_macvlan wan2 + fi + #uci -q batch <<-EOF + #add network route6 + #set network.@route6[-1].interface='lan' + #set network.@route6[-1].target='::/0' + #EOF +fi +uci -q commit macvlan +uci -q commit network +rm -f /tmp/luci-indexcache +exit 0 diff --git a/openmptcprouter/files/usr/lib/lua/luci/admin_status/index.html b/openmptcprouter/files/usr/lib/lua/luci/admin_status/index.html deleted file mode 100644 index a02b56eee..000000000 --- a/openmptcprouter/files/usr/lib/lua/luci/admin_status/index.html +++ /dev/null @@ -1,825 +0,0 @@ -<%# - Copyright 2008 Steven Barth - Copyright 2008-2011 Jo-Philipp Wich - Licensed to the public under the Apache License 2.0. --%> - -<% - local fs = require "nixio.fs" - local util = require "luci.util" - local stat = require "luci.tools.status" - local ver = require "luci.version" - - local has_ipv6 = fs.access("/usr/sbin/ip6tables") - local has_dhcp = fs.access("/etc/config/dhcp") - local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0) - - local sysinfo = luci.util.ubus("system", "info") or { } - local boardinfo = luci.util.ubus("system", "board") or { } - local unameinfo = nixio.uname() or { } - - local meminfo = sysinfo.memory or { - total = 0, - free = 0, - buffered = 0, - shared = 0 - } - - local mem_cached = luci.sys.exec("sed -e '/^Cached: /!d; s#Cached: *##; s# kB##g' /proc/meminfo") - - local swapinfo = sysinfo.swap or { - total = 0, - free = 0 - } - - local has_dsl = fs.access("/etc/init.d/dsl_control") - - if luci.http.formvalue("status") == "1" then - local ntm = require "luci.model.network".init() - local wan = ntm:get_wannet() - local wan6 = ntm:get_wan6net() - - local conn_count = tonumber( - fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0 - - local conn_max = tonumber(luci.sys.exec( - "sysctl -n -e net.nf_conntrack_max net.ipv4.netfilter.ip_conntrack_max" - ):match("%d+")) or 4096 - - local user_info = luci.sys.exec("cat /proc/net/arp | grep 'br-lan' | grep '0x2' | wc -l") - - local cpu_usage = (luci.sys.exec("expr 100 - $(top -n 1 | grep 'CPU:' | awk -F '%' '{print$4}' | awk -F ' ' '{print$2}')") or "6") .. "%" - - local rv = { - cpuusage = cpu_usage, - userinfo = user_info, - uptime = sysinfo.uptime or 0, - localtime = os.date(), - loadavg = sysinfo.load or { 0, 0, 0 }, - memory = meminfo, - memcached = mem_cached, - swap = swapinfo, - connmax = conn_max, - conncount = conn_count, - leases = stat.dhcp_leases(), - leases6 = stat.dhcp6_leases(), - wifinets = stat.wifi_networks(), - temperinfo = luci.util.exec("sensors | grep 'temp1' | cut -c15-24 "), - buildinfo = " 2020-09-23 Build By ccbcfan " - } - - if wan then - rv.wan = { - ipaddr = wan:ipaddr(), - gwaddr = wan:gwaddr(), - netmask = wan:netmask(), - dns = wan:dnsaddrs(), - expires = wan:expires(), - uptime = wan:uptime(), - proto = wan:proto(), - ifname = wan:ifname(), - link = wan:adminlink() - } - end - - if wan6 then - rv.wan6 = { - ip6addr = wan6:ip6addr(), - gw6addr = wan6:gw6addr(), - dns = wan6:dns6addrs(), - ip6prefix = wan6:ip6prefix(), - uptime = wan6:uptime(), - proto = wan6:proto(), - ifname = wan6:ifname(), - link = wan6:adminlink() - } - end - - if has_dsl then - local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat") - local dsl_func = loadstring(dsl_stat) - if dsl_func then - rv.dsl = dsl_func() - end - end - - luci.http.prepare_content("application/json") - luci.http.write_json(rv) - - return - elseif luci.http.formvalue("hosts") == "1" then - luci.http.prepare_content("application/json") - luci.http.write_json(luci.sys.net.host_hints()) - - return - end --%> - -<%+header%> - - - - -

<%:Status%>

- -
- <%:System%> - - - - - - - - - - - - - -
<%:Hostname%><%=luci.sys.hostname() or "?"%>
<%:Model%><%=pcdata(boardinfo.model or "AArch64")%> <%=luci.sys.exec("cat /etc/bench.log") or " "%>
<%:Architecture%><%=pcdata(boardinfo.system or "?")%> x <%=luci.sys.exec("cat /proc/cpuinfo | grep 'processor' | wc -l") or "1"%>
<%:Firmware Version%> - <%=pcdata(ver.distname)%> <%=pcdata(ver.distversion)%> / - <%=pcdata(ver.luciname)%> (<%=pcdata(ver.luciversion)%>) -
<%:Kernel Version%><%=unameinfo.release or "?"%>
<%:Local Time%>-
<%:Uptime%>-
<%:Load Average%>-
<%:CPU usage (%)%>-
<%:CPU 温 度(°C)%>-
<%:固件信息%>-
-
- -
- <%:Memory%> - - - - -
<%:Total Available%>-
<%:Buffered%>-
-
- -<% if swapinfo.total > 0 then %> -
- <%:Swap%> - - - - -
<%:Total Available%>-
<%:Free%>-
-
-<% end %> - -
- <%:Network%> - - - - <% if has_ipv6 then %> - - <% end %> - - -
<%:IPv4 WAN Status%> - - - -

?
<%:Collecting data...%>
-
<%:IPv6 WAN Status%> - - - -

?
<%:Collecting data...%>
-
<%:Online Users%>0
<%:Active Connections%>-
-
- -<% if has_dhcp then %> -
- <%:DHCP Leases%> - - - - - - - - - - - -
<%:Hostname%><%:IPv4-Address%><%:MAC-Address%><%:Leasetime remaining%>

<%:Collecting data...%>
-
- -<% if has_ipv6 then %> - -<% end %> -<% end %> - -<% if has_dsl then %> -
- <%:DSL%> - - -
<%:DSL Status%> - - - -

?
<%:Collecting data...%>
-
-
-<% end %> - -<% if has_wifi then %> -
- <%:Wireless%> - - - -
<%:Collecting data...%>
-
-<% end %> - -<%+footer%> -oter%> \ No newline at end of file