Changeset 6534

Show
Ignore:
Timestamp:
11/23/10 01:11:00 (3 years ago)
Author:
jow
Message:

modules/admin-full: make menus work with no dnsmasq or firewall installed

Location:
luci/trunk/modules/admin-full/luasrc/model/cbi/admin_network
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua

    r6430 r6534  
    2020 
    2121arg[1] = arg[1] or "" 
     22 
     23local has_dnsmasq  = fs.access("/etc/config/dhcp") 
     24local has_firewall = fs.access("/etc/config/firewall") 
    2225 
    2326local has_3g     = fs.access("/usr/bin/gcom") 
     
    3134 
    3235m = Map("network", translate("Interfaces") .. " - " .. arg[1]:upper(), translate("On this page you can configure the network interfaces. You can bridge several interfaces by ticking the \"bridge interfaces\" field and enter the names of several network interfaces separated by spaces. You can also use <abbr title=\"Virtual Local Area Network\">VLAN</abbr> notation <samp>INTERFACE.VLANNR</samp> (<abbr title=\"for example\">e.g.</abbr>: <samp>eth0.1</samp>).")) 
    33 m:chain("firewall") 
    3436m:chain("wireless") 
     37 
     38if has_firewall then 
     39    m:chain("firewall") 
     40end 
    3541 
    3642nw.init(m.uci) 
     
    5763if has_6in4 or has_6to4 then s:tab("tunnel", translate("Tunnel Settings")) end 
    5864s:tab("physical", translate("Physical Settings")) 
    59 s:tab("firewall", translate("Firewall Settings")) 
     65if has_firewall then s:tab("firewall", translate("Firewall Settings")) end 
    6066 
    6167st = s:taboption("general", DummyValue, "__status", translate("Status")) 
     
    144150 
    145151 
    146 local fwd_to, fwd_from 
    147  
    148 fwzone = s:taboption("firewall", Value, "_fwzone", 
    149     translate("Create / Assign firewall-zone"), 
    150     translate("Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>create</em> field to define a new zone and attach the interface to it.")) 
    151  
    152 fwzone.template = "cbi/firewall_zonelist" 
    153 fwzone.network = arg[1] 
    154 fwzone.rmempty = false 
    155  
    156 function fwzone.cfgvalue(self, section) 
    157     self.iface = section 
    158     local z = fw:get_zone_by_network(section) 
    159     return z and z:name() 
    160 end 
    161  
    162 function fwzone.write(self, section, value) 
    163     local zone = fw:get_zone(value) 
    164  
    165     if not zone and value == '-' then 
    166         value = m:formvalue(self:cbid(section) .. ".newzone") 
    167         if value and #value > 0 then 
    168             zone = fw:add_zone(value) 
    169         else 
     152if has_firewall then 
     153    fwzone = s:taboption("firewall", Value, "_fwzone", 
     154        translate("Create / Assign firewall-zone"), 
     155        translate("Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>create</em> field to define a new zone and attach the interface to it.")) 
     156 
     157    fwzone.template = "cbi/firewall_zonelist" 
     158    fwzone.network = arg[1] 
     159    fwzone.rmempty = false 
     160 
     161    function fwzone.cfgvalue(self, section) 
     162        self.iface = section 
     163        local z = fw:get_zone_by_network(section) 
     164        return z and z:name() 
     165    end 
     166 
     167    function fwzone.write(self, section, value) 
     168        local zone = fw:get_zone(value) 
     169 
     170        if not zone and value == '-' then 
     171            value = m:formvalue(self:cbid(section) .. ".newzone") 
     172            if value and #value > 0 then 
     173                zone = fw:add_zone(value) 
     174            else 
     175                fw:del_network(section) 
     176            end 
     177        end 
     178 
     179        if zone then 
    170180            fw:del_network(section) 
     181            zone:add_network(section) 
    171182        end 
    172     end 
    173  
    174     if zone then 
    175         fw:del_network(section) 
    176         zone:add_network(section) 
    177183    end 
    178184end 
     
    508514 
    509515 
    510 m2 = Map("dhcp", "", "") 
    511 function m2.on_parse() 
    512     local has_section = false 
    513  
    514     m2.uci:foreach("dhcp", "dhcp", function(s) 
    515         if s.interface == arg[1] then 
    516             has_section = true 
    517             return false 
     516-- 
     517-- Display DNS settings if dnsmasq is available 
     518-- 
     519 
     520if has_dnsmasq then 
     521    m2 = Map("dhcp", "", "") 
     522    function m2.on_parse() 
     523        local has_section = false 
     524 
     525        m2.uci:foreach("dhcp", "dhcp", function(s) 
     526            if s.interface == arg[1] then 
     527                has_section = true 
     528                return false 
     529            end 
     530        end) 
     531 
     532        if not has_section then 
     533            m2.uci:section("dhcp", "dhcp", nil, { interface = arg[1], ignore = "1" }) 
     534            m2.uci:save("dhcp") 
    518535        end 
    519     end) 
    520  
    521     if not has_section then 
    522         m2.uci:section("dhcp", "dhcp", nil, { interface = arg[1], ignore = "1" }) 
    523         m2.uci:save("dhcp") 
    524     end 
    525 end 
    526  
    527 s = m2:section(TypedSection, "dhcp", translate("DHCP Server")) 
    528 s.addremove = false 
    529 s.anonymous = true 
    530 s:tab("general",  translate("General Setup")) 
    531 s:tab("advanced", translate("Advanced Settings")) 
    532  
    533 function s.filter(self, section) 
    534     return m2.uci:get("dhcp", section, "interface") == arg[1] 
    535 end 
    536  
    537 local ignore = s:taboption("general", Flag, "ignore", 
    538     translate("Ignore interface"), 
    539     translate("Disable <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> for " .. 
    540         "this interface.")) 
    541  
    542 ignore.rmempty = false 
    543  
    544 local start = s:taboption("general", Value, "start", translate("Start"), 
    545     translate("Lowest leased address as offset from the network address.")) 
    546 start.optional = true 
    547 start.datatype = "uinteger" 
    548 start.default = "100" 
    549  
    550 local limit = s:taboption("general", Value, "limit", translate("Limit"), 
    551     translate("Maximum number of leased addresses.")) 
    552 limit.optional = true 
    553 limit.datatype = "uinteger" 
    554 limit.default = "150" 
    555  
    556 local ltime = s:taboption("general", Value, "leasetime", translate("Leasetime"), 
    557     translate("Expiry time of leased addresses, minimum is 2 Minutes (<code>2m</code>).")) 
    558 ltime.rmempty = true 
    559 ltime.default = "12h" 
    560  
    561 local dd = s:taboption("advanced", Flag, "dynamicdhcp", 
    562     translate("Dynamic <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr>"), 
    563     translate("Dynamically allocate DHCP addresses for clients. If disabled, only " .. 
    564         "clients having static leases will be served.")) 
    565  
    566 dd.rmempty = false 
    567 function dd.cfgvalue(self, section) 
    568     return Flag.cfgvalue(self, section) or "1" 
    569 end 
    570  
    571 s:taboption("advanced", Flag, "force", translate("Force"), 
    572     translate("Force DHCP on this network even if another server is detected.")) 
    573  
    574 -- XXX: is this actually useful? 
    575 --s:taboption("advanced", Value, "name", translate("Name"), 
    576 --  translate("Define a name for this network.")) 
    577  
    578 mask = s:taboption("advanced", Value, "netmask", 
    579     translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"), 
    580     translate("Override the netmask sent to clients. Normally it is calculated " .. 
    581         "from the subnet that is served.")) 
    582  
    583 mask.optional = true 
    584 mask.datatype = "ip4addr" 
    585  
    586 s:taboption("advanced", DynamicList, "dhcp_option", translate("DHCP-Options"), 
    587     translate("Define additional DHCP options, for example \"<code>6,192.168.2.1," .. 
    588         "192.168.2.2</code>\" which advertises different DNS servers to clients.")) 
    589  
    590 for i, n in ipairs(s.children) do 
    591     if n ~= ignore then 
    592         n:depends("ignore", "") 
     536    end 
     537 
     538    s = m2:section(TypedSection, "dhcp", translate("DHCP Server")) 
     539    s.addremove = false 
     540    s.anonymous = true 
     541    s:tab("general",  translate("General Setup")) 
     542    s:tab("advanced", translate("Advanced Settings")) 
     543 
     544    function s.filter(self, section) 
     545        return m2.uci:get("dhcp", section, "interface") == arg[1] 
     546    end 
     547 
     548    local ignore = s:taboption("general", Flag, "ignore", 
     549        translate("Ignore interface"), 
     550        translate("Disable <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> for " .. 
     551            "this interface.")) 
     552 
     553    ignore.rmempty = false 
     554 
     555    local start = s:taboption("general", Value, "start", translate("Start"), 
     556        translate("Lowest leased address as offset from the network address.")) 
     557    start.optional = true 
     558    start.datatype = "uinteger" 
     559    start.default = "100" 
     560 
     561    local limit = s:taboption("general", Value, "limit", translate("Limit"), 
     562        translate("Maximum number of leased addresses.")) 
     563    limit.optional = true 
     564    limit.datatype = "uinteger" 
     565    limit.default = "150" 
     566 
     567    local ltime = s:taboption("general", Value, "leasetime", translate("Leasetime"), 
     568        translate("Expiry time of leased addresses, minimum is 2 Minutes (<code>2m</code>).")) 
     569    ltime.rmempty = true 
     570    ltime.default = "12h" 
     571 
     572    local dd = s:taboption("advanced", Flag, "dynamicdhcp", 
     573        translate("Dynamic <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr>"), 
     574        translate("Dynamically allocate DHCP addresses for clients. If disabled, only " .. 
     575            "clients having static leases will be served.")) 
     576 
     577    dd.rmempty = false 
     578    function dd.cfgvalue(self, section) 
     579        return Flag.cfgvalue(self, section) or "1" 
     580    end 
     581 
     582    s:taboption("advanced", Flag, "force", translate("Force"), 
     583        translate("Force DHCP on this network even if another server is detected.")) 
     584 
     585    -- XXX: is this actually useful? 
     586    --s:taboption("advanced", Value, "name", translate("Name"), 
     587    --  translate("Define a name for this network.")) 
     588 
     589    mask = s:taboption("advanced", Value, "netmask", 
     590        translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"), 
     591        translate("Override the netmask sent to clients. Normally it is calculated " .. 
     592            "from the subnet that is served.")) 
     593 
     594    mask.optional = true 
     595    mask.datatype = "ip4addr" 
     596 
     597    s:taboption("advanced", DynamicList, "dhcp_option", translate("DHCP-Options"), 
     598        translate("Define additional DHCP options, for example \"<code>6,192.168.2.1," .. 
     599            "192.168.2.2</code>\" which advertises different DNS servers to clients.")) 
     600 
     601    for i, n in ipairs(s.children) do 
     602        if n ~= ignore then 
     603            n:depends("ignore", "") 
     604        end 
    593605    end 
    594606end 
  • luci/trunk/modules/admin-full/luasrc/model/cbi/admin_network/wifi_add.lua

    r6441 r6534  
    1313]]-- 
    1414 
     15local fs   = require "nixio.fs" 
    1516local nw   = require "luci.model.network" 
    1617local fw   = require "luci.model.firewall" 
     
    1920 
    2021local iw = luci.sys.wifi.getiwinfo(http.formvalue("device")) 
     22 
     23local has_firewall = fs.access("/etc/config/firewall") 
    2124 
    2225if not iw then 
     
    9093newnet.datatype = "uciname" 
    9194 
    92 fwzone = m:field(Value, "_fwzone", 
    93     translate("Create / Assign firewall-zone"), 
    94     translate("Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>create</em> field to define a new zone and attach the interface to it.")) 
     95if has_firewall then 
     96    fwzone = m:field(Value, "_fwzone", 
     97        translate("Create / Assign firewall-zone"), 
     98        translate("Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>create</em> field to define a new zone and attach the interface to it.")) 
    9599 
    96 fwzone.template = "cbi/firewall_zonelist" 
    97 fwzone.default = m.hidden.mode == "Ad-Hoc" and "mesh" or "wan" 
     100    fwzone.template = "cbi/firewall_zonelist" 
     101    fwzone.default = m.hidden.mode == "Ad-Hoc" and "mesh" or "wan" 
     102end 
    98103 
    99104function newnet.parse(self, section) 
    100105    local net, zone 
     106 
    101107    local value = self:formvalue(section) 
    102     local zval  = fwzone:formvalue(section) 
     108    net = nw:add_network(value, { proto = "dhcp" }) 
    103109 
    104     net = nw:add_network(value, { proto = "dhcp" }) 
    105     zone = fw:get_zone(zval) 
     110    if has_firewall then 
     111        local zval  = fwzone:formvalue(section) 
     112        zone = fw:get_zone(zval) 
    106113 
    107     if not zone and zval == '-' then 
    108         zval = m:formvalue(fwzone:cbid(section) .. ".newzone") 
    109         if zval and #zval > 0 then 
    110             zone = fw:add_zone(zval) 
     114        if not zone and zval == '-' then 
     115            zval = m:formvalue(fwzone:cbid(section) .. ".newzone") 
     116            if zval and #zval > 0 then 
     117                zone = fw:add_zone(zval) 
     118            end 
    111119        end 
    112120    end 
     
    166174end 
    167175 
    168 function fwzone.cfgvalue(self, section) 
    169     self.iface = section 
    170     local z = fw:get_zone_by_network(section) 
    171     return z and z:name() 
     176if has_firewall then 
     177    function fwzone.cfgvalue(self, section) 
     178        self.iface = section 
     179        local z = fw:get_zone_by_network(section) 
     180        return z and z:name() 
     181    end 
    172182end 
    173183