Changeset 2185


Ignore:
Timestamp:
Sep 19, 2012, 3:28:54 PM (7 years ago)
Author:
matthijs
Message:

luci-openvpn: Don't allow duplicate static addresses.

This prevents the webui from saving when two clients have the same
static IP address selected.

References: #1180

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/luci/applications/luci-openvpn/luasrc/model/cbi/openvpn.lua

    r2184 r2185  
    7272end
    7373
     74function s.parse(self, novld)
     75        -- Make sure each address is only used only once. We could have
     76        -- created an ip.validate function, but when that returns nil to
     77        -- indicate an invalid value, the old value is shown again,
     78        -- making the feedback to the user confusing. By directly
     79        -- setting ip.error, we get the "invalid" feedback, without
     80        -- throwing away the formvalue.
     81        local in_use = {}
     82        ip.error = ip.error or {}
     83        for i, section in ipairs(self:cfgsections()) do
     84                ip_val = ip:formvalue(section)
     85                if ip_val and #ip_val > 0 then
     86                        other_section = in_use[ip_val]
     87                        -- If this address is in use by another section,
     88                        -- mark both as invalid
     89                        if other_section then
     90                                ip.error[section] = "duplicate"
     91                                ip.error[other_section] = "duplicate"
     92                                ip.map.save = false
     93                        end
     94                        in_use[ip_val] = section
     95                end
     96        end
     97
     98        -- Let TypedSection.parse do the regular handling
     99        TypedSection.parse(self, novld)
     100end
     101
    74102download = s:option(Button, "configuration", translate("config", "Configuration"))
    75103-- Use a custom template so we can use different texts on the button and
Note: See TracChangeset for help on using the changeset viewer.