3e1b9d85d04e579fb3001a01e78fd2047d6486f3
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_system / crontab.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008-2013 Jo-Philipp Wich <xm@subsignal.org>
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("Scheduled Tasks"), translate("This is the system crontab in which scheduled tasks can be defined."))
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                         luci.sys.call("/usr/bin/crontab %q" % cronfile)
33                 end
34         end
35         return true
36 end
37
38 return f