[PATCH] luci-mod-admin-full: 802.11r AP-WDS mode enable
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / backupfiles.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
4
5 if luci.http.formvalue("cbid.luci.1._list") then
6         luci.http.redirect(luci.dispatcher.build_url("admin/system/flashops/backupfiles") .. "?display=list")
7 elseif luci.http.formvalue("cbid.luci.1._edit") then
8         luci.http.redirect(luci.dispatcher.build_url("admin/system/flashops/backupfiles") .. "?display=edit")
9         return
10 end
11
12 m = SimpleForm("luci", translate("Backup file list"))
13 m:append(Template("admin_system/backupfiles"))
14
15 if luci.http.formvalue("display") ~= "list" then
16         f = m:section(SimpleSection, nil, translate("This is a list of shell glob patterns for matching files and directories to include during sysupgrade. Modified files in /etc/config/ and certain other configurations are automatically preserved."))
17
18         l = f:option(Button, "_list", translate("Show current backup file list"))
19         l.inputtitle = translate("Open list...")
20         l.inputstyle = "apply"
21
22         c = f:option(TextValue, "_custom")
23         c.rmempty = false
24         c.cols = 70
25         c.rows = 30
26
27         c.cfgvalue = function(self, section)
28                 return nixio.fs.readfile("/etc/sysupgrade.conf")
29         end
30
31         c.write = function(self, section, value)
32                 value = value:gsub("\r\n?", "\n")
33                 return nixio.fs.writefile("/etc/sysupgrade.conf", value)
34         end
35 else
36         m.submit = false
37         m.reset  = false
38
39         f = m:section(SimpleSection, nil, translate("Below is the determined list of files to backup. It consists of changed configuration files marked by opkg, essential base files and the user defined backup patterns."))
40
41         l = f:option(Button, "_edit", translate("Back to configuration"))
42         l.inputtitle = translate("Close list...")
43         l.inputstyle = "link"
44
45
46         d = f:option(DummyValue, "_detected")
47         d.rawhtml = true
48         d.cfgvalue = function(s)
49                 local list = io.popen(
50                         "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
51                         "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
52                         "opkg list-changed-conffiles ) | sort -u"
53                 )
54
55                 if list then
56                         local files = { "<ul>" }
57
58                         while true do
59                                 local ln = list:read("*l")
60                                 if not ln then
61                                         break
62                                 else
63                                         files[#files+1] = "<li>"
64                                         files[#files+1] = luci.util.pcdata(ln)
65                                         files[#files+1] = "</li>"
66                                 end
67                         end
68
69                         list:close()
70                         files[#files+1] = "</ul>"
71
72                         return table.concat(files, "")
73                 end
74
75                 return "<em>" .. translate("No files found") .. "</em>"
76         end
77
78 end
79
80 return m