Merge pull request #528 from nmav/no-vpn
authorChristian Schoenebeck <christian.schoenebeck@gmail.com>
Sun, 1 Nov 2015 16:19:26 +0000 (17:19 +0100)
committerChristian Schoenebeck <christian.schoenebeck@gmail.com>
Sun, 1 Nov 2015 16:19:26 +0000 (17:19 +0100)
ocserv: removed unnecessary option and add proxy arp option

modules/luci-base/luasrc/cbi.lua
modules/luci-base/luasrc/view/cbi/value.htm

index a009095..b5b2c8d 100644 (file)
@@ -1471,6 +1471,7 @@ function Value.__init__(self, ...)
        self.template  = "cbi/value"
        self.keylist = {}
        self.vallist = {}
+       self.readonly = nil
 end
 
 function Value.reset_values(self)
@@ -1484,6 +1485,10 @@ function Value.value(self, key, val)
        table.insert(self.vallist, tostring(val))
 end
 
+function Value.parse(self, section, novld)
+       if self.readonly then return end
+       AbstractValue.parse(self, section, novld)
+end
 
 -- DummyValue - This does nothing except being there
 DummyValue = class(AbstractValue)
@@ -1528,17 +1533,25 @@ function Flag.__init__(self, ...)
 end
 
 -- A flag can only have two states: set or unset
-function Flag.parse(self, section)
+function Flag.parse(self, section, novld)
        local fexists = self.map:formvalue(
                FEXIST_PREFIX .. self.config .. "." .. section .. "." .. self.option)
 
        if fexists then
                local fvalue = self:formvalue(section) and self.enabled or self.disabled
                local cvalue = self:cfgvalue(section)
-               if fvalue ~= self.default or (not self.optional and not self.rmempty) then
-                       self:write(section, fvalue)
-               else
+               local val_err
+               fvalue, val_err = self:validate(fvalue, section)
+               if not fvalue then
+                       if not novld then
+                               self:add_error(section, "invalid", val_err)
+                       end
+                       return
+               end
+               if fvalue == self.default and (self.optional or self.rmempty) then
                        self:remove(section)
+               else
+                       self:write(section, fvalue)
                end
                if (fvalue ~= cvalue) then self.section.changed = true end
        else
@@ -1550,7 +1563,9 @@ end
 function Flag.cfgvalue(self, section)
        return AbstractValue.cfgvalue(self, section) or self.default
 end
-
+function Flag.validate(self, value)
+       return value
+end
 
 --[[
 ListValue - A one-line value predefined in a list
index d1a7bea..8a08e08 100644 (file)
@@ -1,7 +1,8 @@
 <%+cbi/valueheader%>
        <input type="<%=self.password and 'password" class="cbi-input-password' or 'text" class="cbi-input-text' %>" onchange="cbi_d_update(this.id)"<%=
                attr("name", cbid) .. attr("id", cbid) .. attr("value", self:cfgvalue(section) or self.default) ..
-               ifattr(self.size, "size") .. ifattr(self.placeholder, "placeholder")
+               ifattr(self.size, "size") .. ifattr(self.placeholder, "placeholder") ..
+               ifattr(self.readonly, "readonly") .. ifattr(self.maxlength, "maxlength")
        %> />
        <% if self.password then %><img src="<%=resource%>/cbi/reload.gif" style="vertical-align:middle" title="<%:Reveal/hide password%>" onclick="var e = document.getElementById('<%=cbid%>'); e.type = (e.type=='password') ? 'text' : 'password';" /><% end %>
        <% if #self.keylist > 0 or self.datatype then -%>