diff options
author | Hannu Nyman <hannu.nyman@iki.fi> | 2017-05-18 12:10:14 +0300 |
---|---|---|
committer | Hannu Nyman <hannu.nyman@iki.fi> | 2017-05-18 12:10:14 +0300 |
commit | ad0585cbb42d10a9ddbe370636c5b30b1bdd0241 (patch) | |
tree | 4aa6cfbae0e017680e4828fc771042ec0849b6c0 /applications/luci-app-statistics | |
parent | d7d7503a39bdcc79edb1d1feed2524fc952da24d (diff) |
luci-app-statistics: check that uci config sections exist
A missing or faulty luci_statistics config file may prevent
LuCI access completely already at the login phase as
the statistics config is parsed already then.
The error is like:
.../statistics/datatree.lua:16: attempt to index upvalue 'sections' (a nil value)
User may be completely locked out of LuCI until he figures out
the need to have a proper luci_statistics config file.
Prevent the error by checking for the existence of
the uci config sections before trying to use values from them.
Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
(cherry picked from commit d04f667383ec2894a5ecefde7ad9284d07563a67)
Diffstat (limited to 'applications/luci-app-statistics')
-rw-r--r-- | applications/luci-app-statistics/luasrc/statistics/datatree.lua | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/applications/luci-app-statistics/luasrc/statistics/datatree.lua b/applications/luci-app-statistics/luasrc/statistics/datatree.lua index 806b054cb6..5176a19a22 100644 --- a/applications/luci-app-statistics/luasrc/statistics/datatree.lua +++ b/applications/luci-app-statistics/luasrc/statistics/datatree.lua @@ -13,9 +13,17 @@ local sections = uci:get_all("luci_statistics") Instance = util.class() function Instance.__init__( self, host ) - self._host = host or sections.collectd.Hostname or sys.hostname() - self._libdir = sections.collectd.PluginDir or "/usr/lib/collectd" - self._rrddir = sections.collectd_rrdtool.DataDir or "/tmp/rrd" + self._host = host or sys.hostname() + self._libdir = "/usr/lib/collectd" + self._rrddir = "/tmp/rrd" + + if sections and sections.collectd then + self._host = host or sections.collectd.Hostname or sys.hostname() + self._libdir = sections.collectd.PluginDir or "/usr/lib/collectd" + end + if sections and sections.collectd_rrdtool then + self._rrddir = sections.collectd_rrdtool.DataDir or "/tmp/rrd" + end self._libdir = self._libdir:gsub("/$","") self._rrddir = self._rrddir:gsub("/$","") |