squid-cbi.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. --[[
  2. LuCI Squid module
  3. Copyright (C) 2015, OpenWrt.org
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Author: Marko Ratkaj <marko.ratkaj@sartura.hr>
  9. ]]--
  10. local fs = require "nixio.fs"
  11. local sys = require "luci.sys"
  12. require "ubus"
  13. m = Map("squid", translate("Squid"))
  14. m.on_after_commit = function() luci.sys.call("/etc/init.d/squid restart") end
  15. s = m:section(TypedSection, "squid")
  16. s.anonymous = true
  17. s.addremove = false
  18. s:tab("general", translate("General Settings"))
  19. http_port = s:taboption("general", Value, "http_port", translate("Port"))
  20. http_port.datatype = "portrange"
  21. http_port.placeholder = "0-65535"
  22. visible_hostname = s:taboption("general", Value, "visible_hostname", translate("Visible Hostname"))
  23. visible_hostname.datatype="string"
  24. visible_hostname.placeholder = "OpenWrt"
  25. coredump_dir = s:taboption("general", Value, "coredump_dir", translate("Coredump files directory"))
  26. coredump_dir.datatype="string"
  27. coredump_dir.placeholder = "/tmp/squid"
  28. s:tab("advanced", translate("Advanced Settings"))
  29. squid_config_file = s:taboption("advanced", TextValue, "_data", "")
  30. squid_config_file.wrap = "off"
  31. squid_config_file.rows = 25
  32. squid_config_file.rmempty = false
  33. function squid_config_file.cfgvalue()
  34. local uci = require "luci.model.uci".cursor_state()
  35. local file = uci:get("squid", "squid", "config_file")
  36. if file then
  37. return fs.readfile(file) or ""
  38. else
  39. return ""
  40. end
  41. end
  42. function squid_config_file.write(self, section, value)
  43. if value then
  44. local uci = require "luci.model.uci".cursor_state()
  45. local file = uci:get("squid", "squid", "config_file")
  46. fs.writefile(file, value:gsub("\r\n", "\n"))
  47. end
  48. end
  49. return m