1 class SiteController < ApplicationController
3 layout :map_layout, :only => [:index, :export]
5 before_action :authorize_web
6 before_action :set_locale
7 before_action :redirect_browse_params, :only => :index
8 before_action :redirect_map_params, :only => [:index, :edit, :export]
9 before_action :require_oauth, :only => [:index]
10 before_action :require_user, :only => [:id]
11 before_action :update_totp, :only => [:index]
13 authorize_resource :class => false
15 content_security_policy(:only => :edit) do |policy|
16 policy.frame_src(*policy.frame_src, :blob)
19 content_security_policy(:only => :id) do |policy|
20 policy.connect_src("*")
21 policy.img_src("*", :blob)
22 policy.style_src(*policy.style_src, :unsafe_inline)
26 session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless Settings.status == "database_readonly" || Settings.status == "database_offline"
30 lon, lat, zoom = ShortLink.decode(params[:code])
31 new_params = params.except(:host, :controller, :action, :code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
35 new_params[:mlat] = lat
36 new_params[:mlon] = lon
39 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
40 new_params[:anchor] += "&layers=#{params[:layers]}" if params.key? :layers
42 options = new_params.to_unsafe_h.to_options
44 path = if params.key? :node
45 node_path(params[:node], options)
46 elsif params.key? :way
47 way_path(params[:way], options)
48 elsif params.key? :relation
49 relation_path(params[:relation], options)
50 elsif params.key? :changeset
51 changeset_path(params[:changeset], options)
60 expires_in 7.days, :public => true
61 @key = YAML.load_file(Rails.root.join("config/key.yml"))
62 @key.each_value do |layer_data|
63 layer_data.each do |entry|
64 entry["name"] = Array(entry["name"])
66 layer_data.each_cons(2) do |entry, next_entry|
67 entry["max_zoom"] = next_entry["min_zoom"] - 1 if entry["name"] == next_entry["name"] && !entry["max_zoom"] && next_entry["min_zoom"]
70 render :layout => false
74 editor = preferred_editor
78 render :action => :index, :layout => map_layout
86 bbox = Node.visible.find(params[:node]).bbox.to_unscaled
87 @lat = bbox.centre_lat
88 @lon = bbox.centre_lon
91 bbox = Way.visible.find(params[:way]).bbox.to_unscaled
92 @lat = bbox.centre_lat
93 @lon = bbox.centre_lon
96 note = Note.visible.find(params[:note])
100 elsif params[:gpx] && current_user
101 trace = Trace.visible_to(current_user).find(params[:gpx])
102 @lat = trace.latitude
103 @lon = trace.longitude
106 rescue ActiveRecord::RecordNotFound
107 # don't try and derive a location from a missing/deleted object
112 @locale = params[:copyright_locale] || I18n.locale
120 @locale = params[:about_locale] || I18n.locale
124 @local_chapters = Community.where(:type => "osm-lc").where.not(:id => "OSMF")
130 flash.now[:warning] = if Settings.status == "database_offline"
131 t("layouts.osm_offline")
133 t("layouts.osm_read_only")
135 render :html => nil, :layout => true
139 render :html => RichText.new(params[:type], params[:text]).to_html
143 render :layout => false
148 def redirect_browse_params
150 redirect_to node_path(params[:node])
152 redirect_to way_path(params[:way])
153 elsif params[:relation]
154 redirect_to relation_path(params[:relation])
156 redirect_to note_path(params[:note])
158 redirect_to search_path(:query => params[:query])
162 def redirect_map_params
165 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}" if params[:lat] && params[:lon]
168 anchor << "layers=#{params.delete(:layers)}"
169 elsif params.delete(:notes) == "yes"
173 redirect_to params.to_unsafe_h.merge(:only_path => true, :anchor => anchor.join("&")) if anchor.present?