luci-mod-dashboard: prevent null or undefined 'ifc'
authorPaul Donald <newtwen+github@gmail.com>
Tue, 30 Apr 2024 14:01:26 +0000 (16:01 +0200)
committerPaul Donald <newtwen+github@gmail.com>
Tue, 30 Apr 2024 14:01:26 +0000 (16:01 +0200)
This can happen on factory fresh settings, or a box not yet connected.

follow-up fix for c75232d8d29ba5a9cc5c07c3fff65248f12f1b08

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js

index f5002df84dcf28e30364f7aedbe2c03d532d3983..4cc671da52687532d4636298359a082f2128d23b 100644 (file)
@@ -153,24 +153,25 @@ return baseclass.extend({
                 }
 
                var ifc = data[min_metric_i];
-
-               if (v6) {
-                       var uptime = ifc.getUptime();
-                       this.params.internet.v6.uptime.value = (uptime > 0) ? '%t'.format(uptime) : '-';
-                       this.params.internet.v6.ipprefixv6.value =  ifc.getIP6Prefix() || '-';
-                       this.params.internet.v6.gatewayv6.value =  ifc.getGateway6Addr() || '-';
-                       this.params.internet.v6.protocol.value=  ifc.getI18n() || E('em', _('Not connected'));
-                       this.params.internet.v6.addrsv6.value = ifc.getIP6Addrs() || [ '-' ];
-                       this.params.internet.v6.dnsv6.value = ifc.getDNS6Addrs() || [ '-' ];
-                       this.params.internet.v6.connected.value = ifc.isUp();
-               } else {
-                       var uptime = ifc.getUptime();
-                       this.params.internet.v4.uptime.value = (uptime > 0) ? '%t'.format(uptime) : '-';
-                       this.params.internet.v4.protocol.value=  ifc.getI18n() || E('em', _('Not connected'));
-                       this.params.internet.v4.gatewayv4.value =  ifc.getGatewayAddr() || '0.0.0.0';
-                       this.params.internet.v4.connected.value = ifc.isUp();
-                       this.params.internet.v4.addrsv4.value = ifc.getIPAddrs() || [ '-'];
-                       this.params.internet.v4.dnsv4.value = ifc.getDNSAddrs() || [ '-' ];
+               if(ifc){
+                       if (v6) {
+                               var uptime = ifc.getUptime();
+                               this.params.internet.v6.uptime.value = (uptime > 0) ? '%t'.format(uptime) : '-';
+                               this.params.internet.v6.ipprefixv6.value =  ifc.getIP6Prefix() || '-';
+                               this.params.internet.v6.gatewayv6.value =  ifc.getGateway6Addr() || '-';
+                               this.params.internet.v6.protocol.value=  ifc.getI18n() || E('em', _('Not connected'));
+                               this.params.internet.v6.addrsv6.value = ifc.getIP6Addrs() || [ '-' ];
+                               this.params.internet.v6.dnsv6.value = ifc.getDNS6Addrs() || [ '-' ];
+                               this.params.internet.v6.connected.value = ifc.isUp();
+                       } else {
+                               var uptime = ifc.getUptime();
+                               this.params.internet.v4.uptime.value = (uptime > 0) ? '%t'.format(uptime) : '-';
+                               this.params.internet.v4.protocol.value=  ifc.getI18n() || E('em', _('Not connected'));
+                               this.params.internet.v4.gatewayv4.value =  ifc.getGatewayAddr() || '0.0.0.0';
+                               this.params.internet.v4.connected.value = ifc.isUp();
+                               this.params.internet.v4.addrsv4.value = ifc.getIPAddrs() || [ '-'];
+                               this.params.internet.v4.dnsv4.value = ifc.getDNSAddrs() || [ '-' ];
+                       }
                }
        },