root/luci/trunk/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua @ 6698

Revision 6698, 3.1 KB (checked in by jow, 2 years ago)

modules/admin-full: fixup newlines when storing sysupgrade.conf

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2008 Steven Barth <steven@midlink.org>
5Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
6
7Licensed under the Apache License, Version 2.0 (the "License");
8you may not use this file except in compliance with the License.
9You may obtain a copy of the License at
10
11    http://www.apache.org/licenses/LICENSE-2.0
12
13$Id$
14]]--
15
16require("luci.config")
17m = Map("luci", translate("Web <abbr title=\"User Interface\">UI</abbr>"), translate("Here you can customize the settings and the functionality of <abbr title=\"Lua Configuration Interface\">LuCI</abbr>."))
18
19local fs = require "nixio.fs"
20
21-- force reload of global luci config namespace to reflect the changes
22function m.commit_handler(self)
23    package.loaded["luci.config"] = nil
24    require("luci.config")
25end
26
27
28c = m:section(NamedSection, "main", "core", translate("General"))
29
30l = c:option(ListValue, "lang", translate("Language"))
31l:value("auto")
32
33local i18ndir = luci.i18n.i18ndir .. "base."
34for k, v in luci.util.kspairs(luci.config.languages) do
35    local file = i18ndir .. k:gsub("_", "-")
36    if k:sub(1, 1) ~= "." and fs.access(file .. ".lmo") then
37        l:value(k, v)
38    end
39end
40
41t = c:option(ListValue, "mediaurlbase", translate("Design"))
42for k, v in pairs(luci.config.themes) do
43    if k:sub(1, 1) ~= "." then
44        t:value(v, k)
45    end
46end
47
48u = m:section(NamedSection, "uci_oncommit", "event", translate("Post-commit actions"),
49 translate("These commands will be executed automatically when a given <abbr title=\"Unified Configuration Interface\">UCI</abbr> configuration is committed allowing changes to be applied instantly."))
50u.dynamic = true
51
52
53f = m:section(NamedSection, "main", "core", translate("Files to be kept when flashing a new firmware"))
54
55f:tab("detected", translate("Detected Files"),
56    translate("The following files are detected by the system and will be kept automatically during sysupgrade"))
57
58f:tab("custom", translate("Custom Files"),
59    translate("This is a list of shell glob patterns for matching files and directories to include during sysupgrade"))
60
61d = f:taboption("detected", DummyValue, "_detected", translate("Detected files"))
62d.rawhtml = true
63d.cfgvalue = function(s)
64    local list = io.popen(
65        "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
66        "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
67        "opkg list-changed-conffiles ) | sort -u"
68    )
69
70    if list then
71        local files = { "<ul>" }
72
73        while true do
74            local ln = list:read("*l")
75            if not ln then
76                break
77            else
78                files[#files+1] = "<li>"
79                files[#files+1] = luci.util.pcdata(ln)
80                files[#files+1] = "</li>"
81            end
82        end
83
84        list:close()
85        files[#files+1] = "</ul>"
86
87        return table.concat(files, "")
88    end
89
90    return "<em>" .. translate("No files found") .. "</em>"
91end
92
93c = f:taboption("custom", TextValue, "_custom", translate("Custom files"))
94c.rmempty = false
95c.cols = 70
96c.rows = 30
97
98c.cfgvalue = function(self, section)
99    return nixio.fs.readfile("/etc/sysupgrade.conf")
100end
101
102c.write = function(self, section, value)
103    value = value:gsub("\r\n?", "\n")
104    return nixio.fs.writefile("/etc/sysupgrade.conf", value)
105end
106
107return m
Note: See TracBrowser for help on using the browser.