Merge pull request #473 from ekaitz-zarraga/fix-luci-failsafe
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / ipkg.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
4
5 local ipkgfile = "/etc/opkg.conf"
6 local distfeeds = "/etc/opkg/distfeeds.conf"
7 local customfeeds = "/etc/opkg/customfeeds.conf"
8
9 f = SimpleForm("ipkgconf", translate("OPKG-Configuration"), translate("General options for opkg"))
10
11 f:append(Template("admin_system/ipkg"))
12
13 t = f:field(TextValue, "lines")
14 t.rows = 10
15 function t.cfgvalue()
16         return nixio.fs.readfile(ipkgfile) or ""
17 end
18
19 function t.write(self, section, data)
20         return nixio.fs.writefile(ipkgfile, data:gsub("\r\n", "\n"))
21 end
22
23 function f.handle(self, state, data)
24         return true
25 end
26
27 g = SimpleForm("distfeedconf", translate("Distribution feeds"),
28         translate("Build/distribution specific feed definitions. This file will NOT be preserved in any sysupgrade."))
29
30 d = g:field(TextValue, "lines2")
31 d.rows = 10
32 function d.cfgvalue()
33         return nixio.fs.readfile(distfeeds) or ""
34 end
35
36 function d.write(self, section, data)
37         return nixio.fs.writefile(distfeeds, data:gsub("\r\n", "\n"))
38 end
39
40 function g.handle(self, state, data)
41         return true
42 end
43
44 h = SimpleForm("customfeedconf", translate("Custom feeds"),
45         translate("Custom feed definitions, e.g. private feeds. This file can be preserved in a sysupgrade."))
46
47 c = h:field(TextValue, "lines3")
48 c.rows = 10
49 function c.cfgvalue()
50         return nixio.fs.readfile(customfeeds) or ""
51 end
52
53 function c.write(self, section, data)
54         return nixio.fs.writefile(customfeeds, data:gsub("\r\n", "\n"))
55 end
56
57 function h.handle(self, state, data)
58         return true
59 end
60
61 return f, g, h