luci-mod-admin-full: restrict DSL xfer_mode and line_mode options to VDSL modems
authorJo-Philipp Wich <jo@mein.io>
Fri, 10 Nov 2017 13:36:38 +0000 (14:36 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 10 Nov 2017 13:36:38 +0000 (14:36 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/network.lua

index 22f7c5f..bd01bda 100644 (file)
@@ -3,14 +3,21 @@
 -- Licensed to the public under the Apache License 2.0.
 
 local fs = require "nixio.fs"
 -- Licensed to the public under the Apache License 2.0.
 
 local fs = require "nixio.fs"
+local json = require "luci.jsonc"
 
 m = Map("network", translate("Interfaces"))
 m.pageaction = false
 m:section(SimpleSection).template = "admin_network/iface_overview"
 
 if fs.access("/etc/init.d/dsl_control") then
 
 m = Map("network", translate("Interfaces"))
 m.pageaction = false
 m:section(SimpleSection).template = "admin_network/iface_overview"
 
 if fs.access("/etc/init.d/dsl_control") then
-       dsl = m:section(TypedSection, "dsl", translate("DSL"))
+       local ok, boarddata = pcall(json.parse, fs.readfile("/etc/board.json"))
+       local modemtype = (ok == true)
+               and (type(boarddata) == "table")
+               and (type(boarddata.dsl) == "table")
+               and (type(boarddata.dsl.modem) == "table")
+               and boarddata.dsl.modem.type
 
 
+       dsl = m:section(TypedSection, "dsl", translate("DSL"))
        dsl.anonymous = true
 
        annex = dsl:option(ListValue, "annex", translate("Annex"))
        dsl.anonymous = true
 
        annex = dsl:option(ListValue, "annex", translate("Annex"))
@@ -37,15 +44,17 @@ if fs.access("/etc/init.d/dsl_control") then
        tone:value("b", translate("B43 + B43C"))
        tone:value("bv", translate("B43 + B43C + V43"))
 
        tone:value("b", translate("B43 + B43C"))
        tone:value("bv", translate("B43 + B43C + V43"))
 
-       xfer_mode = dsl:option(ListValue, "xfer_mode", translate("Encapsulation mode"))
-       xfer_mode:value("", translate("auto"))
-       xfer_mode:value("atm", translate("ATM (Asynchronous Transfer Mode)"))
-       xfer_mode:value("ptm", translate("PTM/EFM (Packet Transfer Mode)"))
+       if modemtype == "vdsl" then
+               xfer_mode = dsl:option(ListValue, "xfer_mode", translate("Encapsulation mode"))
+               xfer_mode:value("", translate("auto"))
+               xfer_mode:value("atm", translate("ATM (Asynchronous Transfer Mode)"))
+               xfer_mode:value("ptm", translate("PTM/EFM (Packet Transfer Mode)"))
 
 
-       line_mode = dsl:option(ListValue, "line_mode", translate("DSL line mode"))
-       line_mode:value("", translate("auto"))
-       line_mode:value("adsl", translate("ADSL"))
-       line_mode:value("vdsl", translate("VDSL"))
+               line_mode = dsl:option(ListValue, "line_mode", translate("DSL line mode"))
+               line_mode:value("", translate("auto"))
+               line_mode:value("adsl", translate("ADSL"))
+               line_mode:value("vdsl", translate("VDSL"))
+       end
 
        firmware = dsl:option(Value, "firmware", translate("Firmware File"))
 
 
        firmware = dsl:option(Value, "firmware", translate("Firmware File"))