basics.lua 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2011 Manuel Munz <freifunk at somakoma de>
  3. -- Licensed to the public under the Apache License 2.0.
  4. local fs = require "nixio.fs"
  5. local util = require "luci.util"
  6. local uci = require "luci.model.uci".cursor()
  7. local profiles = "/etc/config/profile_*"
  8. m = Map("freifunk", translate ("Community"))
  9. c = m:section(NamedSection, "community", "public", nil, translate("These are the basic settings for your local wireless community. These settings define the default values for the wizard and DO NOT affect the actual configuration of the router."))
  10. community = c:option(ListValue, "name", translate ("Community"))
  11. community.rmempty = false
  12. local profile
  13. for profile in fs.glob(profiles) do
  14. local name = uci:get_first(profile, "community", "name") or "?"
  15. community:value(string.gsub(profile, "/etc/config/profile_", ""), name)
  16. end
  17. n = Map("system", translate("Basic system settings"))
  18. function n.on_after_commit(self)
  19. luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "basics"))
  20. end
  21. b = n:section(TypedSection, "system")
  22. b.anonymous = true
  23. hn = b:option(Value, "hostname", translate("Hostname"))
  24. hn.rmempty = false
  25. hn.datatype = "hostname"
  26. loc = b:option(Value, "location", translate("Location"))
  27. loc.rmempty = false
  28. loc.datatype = "minlength(1)"
  29. lat = b:option(Value, "latitude", translate("Latitude"), translate("e.g.") .. " 48.12345")
  30. lat.datatype = "float"
  31. lat.rmempty = false
  32. lon = b:option(Value, "longitude", translate("Longitude"), translate("e.g.") .. " 10.12345")
  33. lon.datatype = "float"
  34. lon.rmempty = false
  35. --[[
  36. Opens an OpenStreetMap iframe or popup
  37. Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js
  38. ]]--
  39. local class = util.class
  40. local ff = uci:get("freifunk", "community", "name") or ""
  41. local co = "profile_" .. ff
  42. local deflat = uci:get_first("system", "system", "latitude") or uci:get_first(co, "community", "latitude") or 52
  43. local deflon = uci:get_first("system", "system", "longitude") or uci:get_first(co, "community", "longitude") or 10
  44. local zoom = 12
  45. if ( deflat == 52 and deflon == 10 ) then
  46. zoom = 4
  47. end
  48. OpenStreetMapLonLat = luci.util.class(AbstractValue)
  49. function OpenStreetMapLonLat.__init__(self, ...)
  50. AbstractValue.__init__(self, ...)
  51. self.template = "cbi/osmll_value"
  52. self.latfield = nil
  53. self.lonfield = nil
  54. self.centerlat = ""
  55. self.centerlon = ""
  56. self.zoom = "0"
  57. self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100"
  58. self.height = "600"
  59. self.popup = false
  60. self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap
  61. self.hidetext="X" -- text on button, that hides OSMap
  62. end
  63. osm = b:option(OpenStreetMapLonLat, "latlon", translate("Find your coordinates with OpenStreetMap"), translate("Select your location with a mouse click on the map. The map will only show up if you are connected to the Internet."))
  64. osm.latfield = "latitude"
  65. osm.lonfield = "longitude"
  66. osm.centerlat = uci:get_first("system", "system", "latitude") or deflat
  67. osm.centerlon = uci:get_first("system", "system", "longitude") or deflon
  68. osm.zoom = zoom
  69. osm.width = "100%"
  70. osm.height = "600"
  71. osm.popup = false
  72. osm.displaytext=translate("Show OpenStreetMap")
  73. osm.hidetext=translate("Hide OpenStreetMap")
  74. return m, n