1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-14 19:41:51 +00:00

Add IPv6 check and fixes

This commit is contained in:
Ycarus 2018-05-18 09:40:50 +02:00
parent 602aa8a127
commit 5e6e31e5c7
5 changed files with 224 additions and 26 deletions

View file

@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI Support for OpenMPTCProuter
LUCI_DEPENDS:=+luci-lib-json
LUCI_DEPENDS:=+luci-lib-json +rdisc6
PKG_LICENSE:=GPLv3
include ../luci/luci.mk

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

@ -170,7 +170,11 @@ function get_ip(interface)
return ip
end
-- This function come from OverTheBox by OVH with very small changes
-- This function come from OverTheBox by OVH with some changes
-- Copyright 2015 OVH <OverTheBox@ovh.net>
-- Simon Lelievre (simon.lelievre@corp.ovh.com)
-- Sebastien Duponcheel <sebastien.duponcheel@ovh.net>
-- Under GPL3+
function interfaces_status()
local ut = require "luci.util"
local ntm = require "luci.model.network".init()
@ -192,7 +196,7 @@ function interfaces_status()
-- dns
mArray.openmptcprouter["dns"] = false
local dns_test = sys.exec("dig openmptcprouter.com | grep 'ANWER: 0'")
local dns_test = sys.exec("dig openmptcprouter.com | grep 'ANSWER: 0'")
if dns_test == "" then
mArray.openmptcprouter["dns"] = true
end
@ -289,20 +293,43 @@ function interfaces_status()
local connectivity
local multipath_state = ut.trim(sys.exec("multipath " .. ifname .. " | grep deactivated"))
if multipath_state == "" and ifname ~= "" then
connectivity = 'OK'
connectivity = 'OK'
else
connectivity = 'ERROR'
end
if ipaddr == "" then
connectivity = 'ERROR'
end
local gw_ping
-- Detect WAN gateway status
local gw_ping = 'UP'
if gateway ~= "" then
local gw_ping_test = ut.trim(sys.exec("ping -W 1 -c 1 " .. gateway .. " | grep '100% packet loss'"))
if gw_ping_test == "" then
gw_ping = 'UP'
else
if gw_ping_test ~= "" then
gw_ping = 'DOWN'
if connectivity == "OK" then
connectivity = 'WARNING'
connectivity = 'WARNING'
end
end
end
-- Detect if WAN get an IPv6
local ipv6_discover = 'NONE'
if tonumber((sys.exec("sysctl net.ipv6.conf.all.disable_ipv6")):match(" %d+")) == 0 then
local ipv6_result = _ipv6_discover(ifname)
if type(ipv6_result) == "table" and #ipv6_result > 0 then
local ipv6_addr_test
for k,v in ipairs(ipv6_result) do
if v.RecursiveDnsServer then
ipv6_addr_test = sys.exec('ip -6 addr | grep ' .. v.RecursiveDnsServer)
end
end
if ipv6_addr_test == "" then
ipv6_discover = 'DETECTED'
if connectivity == "OK" then
connectivity = 'WARNING'
end
end
end
end
@ -313,20 +340,21 @@ function interfaces_status()
local data = {
label = section['label'] or interface,
name = interface,
link = net:adminlink(),
ifname = ifname,
ipaddr = ipaddr,
gateway = gateway,
multipath = section['multipath'],
status = connectivity,
wanip = publicIP,
latency = latency,
whois = asn and asn.as_description or "unknown",
qos = section['trafficcontrol'],
download = section['download'],
upload = section['upload'],
gw_ping = gw_ping,
name = interface,
link = net:adminlink(),
ifname = ifname,
ipaddr = ipaddr,
gateway = gateway,
multipath = section['multipath'],
status = connectivity,
wanip = publicIP,
latency = latency,
whois = asn and asn.as_description or "unknown",
qos = section['trafficcontrol'],
download = section['download'],
upload = section['upload'],
gw_ping = gw_ping,
ipv6_discover = ipv6_discover,
}
if ifname:match("^tun.*") then
@ -338,4 +366,65 @@ function interfaces_status()
luci.http.prepare_content("application/json")
luci.http.write_json(mArray)
end
end
-- This come from OverTheBox by OVH
-- Copyright 2015 OVH <OverTheBox@ovh.net>
-- Simon Lelievre (simon.lelievre@corp.ovh.com)
-- Sebastien Duponcheel <sebastien.duponcheel@ovh.net>
-- Under GPL3+
function _ipv6_discover(interface)
local result = {}
--local ra6_list = (sys.exec("rdisc6 -nm " .. interface))
local ra6_list = (sys.exec("rdisc6 -n1 " .. interface))
-- dissect results
local lines = {}
local index = {}
ra6_list:gsub('[^\r\n]+', function(c)
table.insert(lines, c)
if c:match("Hop limit") then
table.insert(index, #lines)
end
end)
local ra6_result = {}
for k,v in ipairs(index) do
local istart = v
local iend = index[k+1] or #lines
local entry = {}
for i=istart,iend - 1 do
local level = lines[i]:find('%w')
local line = lines[i]:sub(level)
local param, value
if line:match('^from') then
param, value = line:match('(from)%s+(.*)$')
else
param, value = line:match('([^:]+):(.*)$')
-- Capitalize param name and remove spaces
param = param:gsub("(%a)([%w_']*)", function(first, rest) return first:upper()..rest:lower() end):gsub("[%s-]",'')
param = param:gsub("%.$", '')
-- Remove text between brackets, seconds and spaces
value = value:lower()
value = value:gsub("%(.*%)", '')
value = value:gsub("%s-seconds%s-", '')
value = value:gsub("^%s+", '')
value = value:gsub("%s+$", '')
end
if entry[param] == nil then
entry[param] = value
elseif type(entry[param]) == "table" then
table.insert(entry[param], value)
else
old = entry[param]
entry[param] = {}
table.insert(entry[param], old)
table.insert(entry[param], value)
end
end
table.insert(ra6_result, entry)
end
return ra6_result
end

View file

@ -22,13 +22,14 @@
-- Copyright 2018 Ycarus (Yannick Chabanois) ycarus@zugaina.org
--
-- Small changes to make this work with OpenMPTCProuter
-- New features: DNS detection, IPv6 route received,...
-%>
<%+header%>
<link rel="stylesheet" type="text/css" href="<%=resource%>/openmptcprouter/css/wanstatus.css?v=git-18.120.38690-2678b12"/>
<script type="text/javascript" src="<%=resource%>/seedrandom.js?v=git-18.120.38690-2678b12"></script>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.120.38690-2678b12"></script>
<script type="text/javascript">//<![CDATA[
XHR.poll(15, '/cgi-bin/luci/admin/system/openmptcprouter/interfaces_status', null,
XHR.poll(20, '/cgi-bin/luci/admin/system/openmptcprouter/interfaces_status', null,
function(x, mArray)
{
var status = document.getElementById('openmptcprouter_status');
@ -176,6 +177,7 @@
var latency = mArray.wans[i].latency;
var gateway = mArray.wans[i].gateway;
var gw_ping = mArray.wans[i].gw_ping;
var ipv6_discover = mArray.wans[i].ipv6_discover;
// Generate template
if(mArray.openmptcprouter.remote_from_lease == true && mArray.wans.length == 1)
{
@ -188,10 +190,18 @@
var title = mArray.wans[i].label + " (" + mArray.wans[i].gateway + ")";
//var content = String.format('%s<br />wan address: <strong>%s</strong><br />whois: %s<br />latency: %s ms<br />multipath: %s', stat, wanip, whois, latency, multipath);
var content = "";
if(ipaddr == '')
{
statusMessage += 'No IP defined<br />'
}
if(gw_ping == 'DOWN')
{
statusMessage += 'Gateway DOWN<br />'
}
if(ipv6_discover == 'DETECTED')
{
statusMessage += 'IPv6 route received<br />'
}
content += String.format('ip address: <strong>%s</strong><br />multipath: %s', ipaddr,multipath);
if(mArray.wans[i].qos && mArray.wans[i].download > 0 && mArray.wans[i].upload > 0)
{
@ -302,6 +312,6 @@
<h2><%:Network overview%></h2>
<fieldset id="interface_field" class="cbi-section">
<!-- <legend><%:Network overview%></legen> -->
<div id="openmptcprouter_status"></div>
<div id="openmptcprouter_status"><img src="<%=resource%>/spinner.gif" /></div>
</fieldset>
<%+footer%>

99
ndisc6/Makefile Normal file
View file

@ -0,0 +1,99 @@
#
# Copyright (C) 2006-2012 OpenWrt.org
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=ndisc6
PKG_VERSION:=1.0.3
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=http://www.remlab.net/files/ndisc6
PKG_HASH:=0f41d6caf5f2edc1a12924956ae8b1d372e3b426bd7b11eed7d38bc974eec821
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
define Package/ndisc
SECTION:=ipv6
CATEGORY:=IPv6
SUBMENU:=IPv6 discovery tools
TITLE:=IPv6 discovery tools
URL:=http://www.remlab.net/ndisc6/
DEPENDS:=+libpthread +librt
endef
define Package/ndisc/description
IPv6 discovery tools
endef
define Package/ndisc6
$(call Package/ndisc)
TITLE:=An ICMPv6 neighbour discovery tool
endef
define Package/ndisc6/description
An ICMPv6 neighbour discovery tools
endef
define Package/rdisc6
$(call Package/ndisc)
TITLE:=An ICMPv6 router discovery tool
endef
define Package/rdisc6/description
An ICMPv6 router discovery tool
endef
define Package/traceroute6
$(call Package/ndisc)
TITLE:=An IPv6-based traceroute implementation
endef
define Package/traceroute6/description
An IPv6-based traceroute implementation
endef
define Package/rdnssd
$(call Package/ndisc)
TITLE:=DNS server discovery daemon
endef
define Package/rdnssd/description
A recursive DNS server discovery daemon gathering
information through stateless IPv6 autoconfiguration (RFC5006)
endef
TARGET_CFLAGS += -std=c99
define Package/ndisc6/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/ndisc6 $(1)/usr/bin/
endef
define Package/rdisc6/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/rdisc6 $(1)/usr/bin/
endef
define Package/traceroute6/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{rl,tcp}traceroute6 $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/tracert6 $(1)/usr/bin/
endef
define Package/rdnssd/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/rdnssd $(1)/usr/sbin/
endef
$(eval $(call BuildPackage,ndisc6))
$(eval $(call BuildPackage,rdisc6))
$(eval $(call BuildPackage,traceroute6))
$(eval $(call BuildPackage,rdnssd))