mirror of
				https://github.com/Ysurac/openmptcprouter-feeds.git
				synced 2025-03-09 15:40:03 +00:00 
			
		
		
		
	Test if wan gateway is up or down in status page
This commit is contained in:
		
							parent
							
								
									59d6990dd3
								
							
						
					
					
						commit
						8d1124f3b1
					
				
					 2 changed files with 23 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -243,7 +243,7 @@ function interfaces_status()
 | 
			
		|||
	    local interface = section[".name"]
 | 
			
		||||
	    local net = ntm:get_network(interface)
 | 
			
		||||
	    local ipaddr = net:ipaddr()
 | 
			
		||||
	    local gateway = section['gateway']
 | 
			
		||||
	    local gateway = section['gateway'] or ""
 | 
			
		||||
	    local multipath = section['multipath']
 | 
			
		||||
 | 
			
		||||
	    --if not ipaddr or not gateway then return end
 | 
			
		||||
| 
						 | 
				
			
			@ -263,6 +263,16 @@ function interfaces_status()
 | 
			
		|||
		    connectivity = 'ERROR'
 | 
			
		||||
	    end
 | 
			
		||||
 | 
			
		||||
	    local gw_ping
 | 
			
		||||
	    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
 | 
			
		||||
			    gw_ping = 'DOWN'
 | 
			
		||||
		    end
 | 
			
		||||
	    end
 | 
			
		||||
 | 
			
		||||
	    local publicIP = "-"
 | 
			
		||||
 | 
			
		||||
	    local latency = "-"
 | 
			
		||||
| 
						 | 
				
			
			@ -282,6 +292,7 @@ function interfaces_status()
 | 
			
		|||
		    qos = section['trafficcontrol'],
 | 
			
		||||
		    download = section['download'],
 | 
			
		||||
		    upload = section['upload'],
 | 
			
		||||
		    gw_ping = gw_ping,
 | 
			
		||||
	    }
 | 
			
		||||
 | 
			
		||||
	    if ifname:match("^tun.*") then
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,9 +24,9 @@
 | 
			
		|||
-- Small changes to make this work with OpenMPTCProuter
 | 
			
		||||
-%>
 | 
			
		||||
<%+header%>
 | 
			
		||||
<link rel="stylesheet" type="text/css" href="<%=resource%>/openmptcprouter/css/wanstatus.css"/>
 | 
			
		||||
<script type="text/javascript" src="<%=resource%>/seedrandom.js"></script>
 | 
			
		||||
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
 | 
			
		||||
<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(10, '/cgi-bin/luci/admin/system/openmptcprouter/interfaces_status', null,
 | 
			
		||||
		function(x, mArray)
 | 
			
		||||
| 
						 | 
				
			
			@ -162,6 +162,8 @@
 | 
			
		|||
					var whois   = mArray.wans[i].whois;
 | 
			
		||||
					var multipath = mArray.wans[i].multipath;
 | 
			
		||||
					var latency = mArray.wans[i].latency;
 | 
			
		||||
					var gateway = mArray.wans[i].gateway;
 | 
			
		||||
					var gw_ping = mArray.wans[i].gw_ping;
 | 
			
		||||
					// Generate template
 | 
			
		||||
					if(mArray.openmptcprouter.remote_from_lease == true && mArray.wans.length == 1)
 | 
			
		||||
					{
 | 
			
		||||
| 
						 | 
				
			
			@ -173,7 +175,12 @@
 | 
			
		|||
					var equipmentIcon = String.format('<embed id="modem_%s" onload="setColorSVG(\'modem_%s\', \'%s\')" src="<%=resource%>/modem.svg" />', mArray.wans[i].name, mArray.wans[i].name, mArray.wans[i].color);
 | 
			
		||||
					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 = String.format('ip address: <strong>%s</strong><br />multipath: %s', ipaddr,multipath);
 | 
			
		||||
					var content = "";
 | 
			
		||||
					if(gw_ping == 'DOWN')
 | 
			
		||||
					{
 | 
			
		||||
						statusMessage += 'Gateway DOWN<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)
 | 
			
		||||
					{
 | 
			
		||||
						content += String.format('<br />traffic control: %s/%s kbps (%s)', mArray.wans[i].download, mArray.wans[i].upload, mArray.wans[i].qos)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue