Merge pull request #4200 from zhanhb/luci-app-acme
[project/luci.git] / modules / luci-mod-system / 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.forcewrite = true
24 c.rmempty = true
25 c.cols = 70
26 c.rows = 30
27
28 c.cfgvalue = function(self, section)
29 return nixio.fs.readfile("/etc/sysupgrade.conf")
30 end
31
32 m.handle = function(self, state, data)
33 if state == FORM_VALID then
34 if data._custom then
35 nixio.fs.writefile("/etc/sysupgrade.conf", data._custom:gsub("\r\n", "\n"))
36 else
37 nixio.fs.writefile("/etc/sysupgrade.conf", "")
38 end
39 end
40 return true
41 end
42 else
43 m.submit = false
44 m.reset = false
45
46 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."))
47
48 l = f:option(Button, "_edit", translate("Back to configuration"))
49 l.inputtitle = translate("Close list...")
50 l.inputstyle = "link"
51
52
53 d = f:option(DummyValue, "_detected")
54 d.rawhtml = true
55 d.cfgvalue = function(s)
56 local list = io.popen(
57 "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
58 "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
59 "opkg list-changed-conffiles ) | sort -u"
60 )
61
62 if list then
63 local files = { "<ul>" }
64
65 while true do
66 local ln = list:read("*l")
67 if not ln then
68 break
69 else
70 files[#files+1] = "<li>"
71 files[#files+1] = luci.xml.pcdata(ln)
72 files[#files+1] = "</li>"
73 end
74 end
75
76 list:close()
77 files[#files+1] = "</ul>"
78
79 return table.concat(files, "")
80 end
81
82 return "<em>" .. translate("No files found") .. "</em>"
83 end
84
85 end
86
87 return m