Update my email addresses in the license headers
[project/luci.git] / applications / luci-app-splash / luasrc / model / cbi / splash / splashtext.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
3 -- Copyright 2010 Manuel Munz <freifunk@somakoma.de>
4 -- Licensed to the public under the Apache License 2.0.
5
6 local fs = require "nixio.fs"
7
8 local splashtextfile = "/usr/lib/luci-splash/splashtext.html"
9 local splashtextinclude = "/usr/lib/luci-splash/splashtextinclude.html"
10
11
12 f = SimpleForm("splashtext", translate("Edit the complete splash text"),
13 translate("You can enter your own text that is displayed to clients here.<br />" ..
14 "It is possible to use the following markers: " ..
15 "###COMMUNITY###, ###COMMUNITY_URL###, ###CONTACTURL###, ###LEASETIME###, ###LIMIT### and ###ACCEPT###."))
16
17 t = f:field(TextValue, "text")
18 t.rmempty = true
19 t.rows = 30
20 function t.cfgvalue()
21 return fs.readfile(splashtextfile) or ""
22 end
23
24 function f.handle(self, state, data)
25 if state == FORM_VALID then
26 if data.text then
27 fs.writefile(splashtextfile, data.text:gsub("\r\n", "\n"))
28 else
29 fs.unlink(splashtextfile)
30 end
31 end
32 return true
33 end
34
35 g = SimpleForm("splashtextinclude", translate("Include your own text in the default splash"),
36 translate("As an alternative to editing the complete splash text you can also just include some custom text in the default splash page by entering it here."))
37
38 t = g:field(TextValue, "text")
39 t.rmempty = true
40 t.rows = 30
41 function t.cfgvalue()
42 return fs.readfile(splashtextinclude) or ""
43 end
44
45 function g.handle(self, state, data)
46 if state == FORM_VALID then
47 if data.text then
48 fs.writefile(splashtextinclude, data.text:gsub("\r\n", "\n"))
49 else
50 fs.unlink(splashtextinclude)
51 end
52 end
53 return true
54 end
55
56
57 return f, g