22258a93729855ec589ec7fc33f96ab487ee6eae
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_system / backupfiles.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16
17 if luci.http.formvalue("cbid.luci.1._list") then
18         luci.http.redirect(luci.dispatcher.build_url("admin/system/flashops/backupfiles") .. "?display=list")
19 elseif luci.http.formvalue("cbid.luci.1._edit") then
20         luci.http.redirect(luci.dispatcher.build_url("admin/system/flashops/backupfiles") .. "?display=edit")
21         return
22 end
23
24 m = SimpleForm("luci", "%s - %s - %s" %{ translate("System"), translate("Flash operations"), translate("Backup file list") })
25 m:append(Template("admin_system/backupfiles"))
26
27 if luci.http.formvalue("display") ~= "list" then
28         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."))
29
30         l = f:option(Button, "_list", translate("Show current backup file list"))
31         l.inputtitle = translate("Open list...")
32         l.inputstyle = "apply"
33
34         c = f:option(TextValue, "_custom")
35         c.rmempty = false
36         c.cols = 70
37         c.rows = 30
38
39         c.cfgvalue = function(self, section)
40                 return nixio.fs.readfile("/etc/sysupgrade.conf")
41         end
42
43         c.write = function(self, section, value)
44                 value = value:gsub("\r\n?", "\n")
45                 return nixio.fs.writefile("/etc/sysupgrade.conf", value)
46         end
47 else
48         m.submit = false
49         m.reset  = false
50
51         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."))
52
53         l = f:option(Button, "_edit", translate("Back to configuration"))
54         l.inputtitle = translate("Close list...")
55         l.inputstyle = "link"
56
57
58         d = f:option(DummyValue, "_detected")
59         d.rawhtml = true
60         d.cfgvalue = function(s)
61                 local list = io.popen(
62                         "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
63                         "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
64                         "opkg list-changed-conffiles ) | sort -u"
65                 )
66
67                 if list then
68                         local files = { "<ul>" }
69
70                         while true do
71                                 local ln = list:read("*l")
72                                 if not ln then
73                                         break
74                                 else
75                                         files[#files+1] = "<li>"
76                                         files[#files+1] = luci.util.pcdata(ln)
77                                         files[#files+1] = "</li>"
78                                 end
79                         end
80
81                         list:close()
82                         files[#files+1] = "</ul>"
83
84                         return table.concat(files, "")
85                 end
86
87                 return "<em>" .. translate("No files found") .. "</em>"
88         end
89
90 end
91
92 return m