crontab.lua 769 B

1234567891011121314151617181920212223242526272829
  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"), translate("This is the system crontab in which scheduled tasks can be defined."))
  7. t = f:field(TextValue, "crons")
  8. t.rmempty = true
  9. t.rows = 10
  10. function t.cfgvalue()
  11. return fs.readfile(cronfile) or ""
  12. end
  13. function f.handle(self, state, data)
  14. if state == FORM_VALID then
  15. if data.crons then
  16. fs.writefile(cronfile, data.crons:gsub("\r\n", "\n"))
  17. luci.sys.call("/usr/bin/crontab %q" % cronfile)
  18. else
  19. fs.writefile(cronfile, "")
  20. end
  21. end
  22. return true
  23. end
  24. return f