crontab.lua 898 B

1234567891011121314151617181920212223242526272829303132
  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. local fs = require "nixio.fs"
  5. local cronfile = "/etc/crontabs/root"
  6. f = SimpleForm("crontab", translate("Scheduled Tasks"),
  7. translate("This is the system crontab in which scheduled tasks can be defined.") ..
  8. translate("<br/>Note: you need to manually restart the cron service if the " ..
  9. "crontab file was empty before editing."))
  10. t = f:field(TextValue, "crons")
  11. t.rmempty = true
  12. t.rows = 10
  13. function t.cfgvalue()
  14. return fs.readfile(cronfile) or ""
  15. end
  16. function f.handle(self, state, data)
  17. if state == FORM_VALID then
  18. if data.crons then
  19. fs.writefile(cronfile, data.crons:gsub("\r\n", "\n"))
  20. luci.sys.call("/usr/bin/crontab %q" % cronfile)
  21. else
  22. fs.writefile(cronfile, "")
  23. end
  24. end
  25. return true
  26. end
  27. return f