crontab.lua 918 B

123456789101112131415161718192021222324252627282930313233
  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. f.forcewrite = true
  12. t.rmempty = true
  13. t.rows = 10
  14. function t.cfgvalue()
  15. return fs.readfile(cronfile) or ""
  16. end
  17. function f.handle(self, state, data)
  18. if state == FORM_VALID then
  19. if data.crons then
  20. fs.writefile(cronfile, data.crons:gsub("\r\n", "\n"))
  21. luci.sys.call("/usr/bin/crontab %q" % cronfile)
  22. else
  23. fs.writefile(cronfile, "")
  24. end
  25. end
  26. return true
  27. end
  28. return f