Merge pull request #278 from nmav/ocserv
[project/luci.git] / applications / luci-splash / luasrc / model / cbi / splash / splashtext.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6 Copyright 2010 Manuel Munz <freifunk@somakoma.de>
7
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13 ]]--
14
15 local fs = require "nixio.fs"
16
17 local splashtextfile = "/usr/lib/luci-splash/splashtext.html"
18 local splashtextinclude = "/usr/lib/luci-splash/splashtextinclude.html"
19
20
21 f = SimpleForm("splashtext", translate("Edit the complete splash text"),
22 translate("You can enter your own text that is displayed to clients here.<br />" ..
23 "It is possible to use the following markers: " ..
24 "###COMMUNITY###, ###COMMUNITY_URL###, ###CONTACTURL###, ###LEASETIME###, ###LIMIT### and ###ACCEPT###."))
25
26 t = f:field(TextValue, "text")
27 t.rmempty = true
28 t.rows = 30
29 function t.cfgvalue()
30 return fs.readfile(splashtextfile) or ""
31 end
32
33 function f.handle(self, state, data)
34 if state == FORM_VALID then
35 if data.text then
36 fs.writefile(splashtextfile, data.text:gsub("\r\n", "\n"))
37 else
38 fs.unlink(splashtextfile)
39 end
40 end
41 return true
42 end
43
44 g = SimpleForm("splashtextinclude", translate("Include your own text in the default splash"),
45 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."))
46
47 t = g:field(TextValue, "text")
48 t.rmempty = true
49 t.rows = 30
50 function t.cfgvalue()
51 return fs.readfile(splashtextinclude) or ""
52 end
53
54 function g.handle(self, state, data)
55 if state == FORM_VALID then
56 if data.text then
57 fs.writefile(splashtextinclude, data.text:gsub("\r\n", "\n"))
58 else
59 fs.unlink(splashtextinclude)
60 end
61 end
62 return true
63 end
64
65
66 return f, g