diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-15 17:04:28 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-15 17:04:28 +0100 |
commit | 27281dca56fd1c7fb03efd70f9d0f5dfc5f869d2 (patch) | |
tree | 043b4a8e75d1970fd131e7a93f34cbf93bd867d1 /modules/luci-base/luasrc/cbi.lua | |
parent | eaf961fa70fdb39cc84d67d2512c2daea9207b69 (diff) |
luci-base: prevent CBI map save on invalid values (#618)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-base/luasrc/cbi.lua')
-rw-r--r-- | modules/luci-base/luasrc/cbi.lua | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/modules/luci-base/luasrc/cbi.lua b/modules/luci-base/luasrc/cbi.lua index 2f97539ab..738431b14 100644 --- a/modules/luci-base/luasrc/cbi.lua +++ b/modules/luci-base/luasrc/cbi.lua @@ -385,41 +385,45 @@ function Map.parse(self, readinput, ...) Node.parse(self, ...) - self:_run_hooks("on_save", "on_before_save") - for i, config in ipairs(self.parsechain) do - self.uci:save(config) - end - self:_run_hooks("on_after_save") - if (not self.proceed and self.flow.autoapply) or luci.http.formvalue("cbi.apply") then - self:_run_hooks("on_before_commit") + if self.save then + self:_run_hooks("on_save", "on_before_save") for i, config in ipairs(self.parsechain) do - self.uci:commit(config) + self.uci:save(config) + end + self:_run_hooks("on_after_save") + if (not self.proceed and self.flow.autoapply) or luci.http.formvalue("cbi.apply") then + self:_run_hooks("on_before_commit") + for i, config in ipairs(self.parsechain) do + self.uci:commit(config) + + -- Refresh data because commit changes section names + self.uci:load(config) + end + self:_run_hooks("on_commit", "on_after_commit", "on_before_apply") + if self.apply_on_parse then + self.uci:apply(self.parsechain) + self:_run_hooks("on_apply", "on_after_apply") + else + -- This is evaluated by the dispatcher and delegated to the + -- template which in turn fires XHR to perform the actual + -- apply actions. + self.apply_needed = true + end - -- Refresh data because commit changes section names - self.uci:load(config) + -- Reparse sections + Node.parse(self, true) end - self:_run_hooks("on_commit", "on_after_commit", "on_before_apply") - if self.apply_on_parse then - self.uci:apply(self.parsechain) - self:_run_hooks("on_apply", "on_after_apply") - else - -- This is evaluated by the dispatcher and delegated to the - -- template which in turn fires XHR to perform the actual - -- apply actions. - self.apply_needed = true + for i, config in ipairs(self.parsechain) do + self.uci:unload(config) + end + if type(self.commit_handler) == "function" then + self:commit_handler(self:submitstate()) end - - -- Reparse sections - Node.parse(self, true) - end - for i, config in ipairs(self.parsechain) do - self.uci:unload(config) - end - if type(self.commit_handler) == "function" then - self:commit_handler(self:submitstate()) end - if self.proceed then + if not self.save then + self.state = FORM_INVALID + elseif self.proceed then self.state = FORM_PROCEED elseif self.changed then self.state = FORM_CHANGED |