05442dd55f2f83a3187c2f1af72275a5919d5b6a
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_services / crontab.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
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 local fs = require "nixio.fs"
17 local cronfile = "/etc/crontabs/root"
18
19 f = SimpleForm("crontab", translate("a_s_crontab"), translate("a_s_crontab1"))
20
21 t = f:field(TextValue, "crons")
22 t.rmempty = true
23 t.rows = 10
24 function t.cfgvalue()
25 return fs.readfile(cronfile) or ""
26 end
27
28 function f.handle(self, state, data)
29 if state == FORM_VALID then
30 if data.crons then
31 fs.writefile(cronfile, data.crons:gsub("\r\n", "\n"))
32 end
33 end
34 return true
35 end
36
37 return f