luci-0.11: merge outstanding trunk changes
[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
19 f = SimpleForm("splashtext", translate("Edit Splash text"),
20 translate("You can enter your own text that is displayed to clients here.<br />" ..
21 "It is possible to use the following markers: " ..
22 "###COMMUNITY###, ###COMMUNITY_URL###, ###CONTACTURL###, ###LEASETIME###, ###LIMIT### and ###ACCEPT###."))
23
24 t = f:field(TextValue, "text")
25 t.rmempty = true
26 t.rows = 30
27 function t.cfgvalue()
28 return fs.readfile(splashtextfile) or ""
29 end
30
31 function f.handle(self, state, data)
32 if state == FORM_VALID then
33 if data.text then
34 fs.writefile(splashtextfile, data.text:gsub("\r\n", "\n"))
35 else
36 fs.unlink(splashtextfile)
37 end
38 end
39 return true
40 end
41
42 return f