summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r--modules/luci-base/luasrc/cbi.lua27
-rw-r--r--modules/luci-base/luasrc/view/cbi/error.htm19
2 files changed, 44 insertions, 2 deletions
diff --git a/modules/luci-base/luasrc/cbi.lua b/modules/luci-base/luasrc/cbi.lua
index 34de44a5f..45c91890a 100644
--- a/modules/luci-base/luasrc/cbi.lua
+++ b/modules/luci-base/luasrc/cbi.lua
@@ -12,6 +12,7 @@ require("luci.http")
local fs = require("nixio.fs")
local uci = require("luci.model.uci")
local datatypes = require("luci.cbi.datatypes")
+local dispatcher = require("luci.dispatcher")
local class = util.class
local instanceof = util.instanceof
@@ -307,8 +308,30 @@ function Map.__init__(self, config, ...)
self.changed = false
- if not self.uci:load(self.config) then
- error("Unable to read UCI data: " .. self.config)
+ local path = "%s/%s" %{ self.uci:get_confdir(), self.config }
+ if fs.stat(path, "type") ~= "reg" then
+ fs.writefile(path, "")
+ end
+
+ local ok, err = self.uci:load(self.config)
+ if not ok then
+ local url = dispatcher.build_url(unpack(dispatcher.context.request))
+ local source = self:formvalue("cbi.source")
+ if type(source) == "string" then
+ fs.writefile(path, source:gsub("\r\n", "\n"))
+ ok, err = self.uci:load(self.config)
+ if ok then
+ luci.http.redirect(url)
+ end
+ end
+ self.save = false
+ end
+
+ if not ok then
+ self.template = "cbi/error"
+ self.error = err
+ self.source = fs.readfile(path) or ""
+ self.pageaction = false
end
end
diff --git a/modules/luci-base/luasrc/view/cbi/error.htm b/modules/luci-base/luasrc/view/cbi/error.htm
new file mode 100644
index 000000000..2acb96924
--- /dev/null
+++ b/modules/luci-base/luasrc/view/cbi/error.htm
@@ -0,0 +1,19 @@
+<div class="cbi-map" id="cbi-<%=self.config%>">
+ <% if self.title and #self.title > 0 then %><h2><a id="content" name="content"><%=self.title%></a></h2><% end %>
+ <% if self.description and #self.description > 0 then %><div class="cbi-map-descr"><%=self.description%></div><% end %>
+
+ <p class="alert-message danger">
+ <%: The configuration file could not be loaded due to the following error: %><br />
+ <code><%=pcdata(self.error)%></code>
+ </p>
+
+ <textarea name="cbi.source" style="width:100%; margin-bottom:1em" rows="<%=math.max(self.source:cmatch("\n"), 10)%>"><%=pcdata(self.source)%></textarea>
+
+ <p class="alert-message">
+ <%: Edit the raw configuration data above to fix any error and hit "Save" to reload the page. %>
+ </p>
+
+ <div class="cbi-page-actions">
+ <input class="cbi-button cbi-button-apply" type="submit" name="cbi.save" value="<%:Save%>" />
+ </div>
+</div>