Merge pull request #1671 from dibdot/travelmate
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / crontab.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2008-2013 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
4
5 local fs = require "nixio.fs"
6 local cronfile = "/etc/crontabs/root" 
7
8 f = SimpleForm("crontab", translate("Scheduled Tasks"),
9         translate("This is the system crontab in which scheduled tasks can be defined.") ..
10         translate("<br/>Note: you need to manually restart the cron service if the " ..
11                 "crontab file was empty before editing."))
12
13 t = f:field(TextValue, "crons")
14 t.rmempty = true
15 t.rows = 10
16 function t.cfgvalue()
17         return fs.readfile(cronfile) or ""
18 end
19
20 function f.handle(self, state, data)
21         if state == FORM_VALID then
22                 if data.crons then
23                         fs.writefile(cronfile, data.crons:gsub("\r\n", "\n"))
24                         luci.sys.call("/usr/bin/crontab %q" % cronfile)
25                 else
26                         fs.writefile(cronfile, "")
27                 end
28         end
29         return true
30 end
31
32 return f