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(*policy.img_src, "*", :blob)
22 policy.script_src(*policy.script_src, "dev.virtualearth.net", :unsafe_eval)
23 policy.style_src(*policy.style_src, :unsafe_inline)
27 session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless Settings.status == "database_readonly" || Settings.status == "database_offline"
31 lon, lat, zoom = ShortLink.decode(params[:code])
32 new_params = params.except(:host, :controller, :action, :code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
36 new_params[:mlat] = lat
37 new_params[:mlon] = lon
40 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
41 new_params[:anchor] += "&layers=#{params[:layers]}" if params.key? :layers
43 options = new_params.to_unsafe_h.to_options
45 path = if params.key? :node
46 node_path(params[:node], options)
47 elsif params.key? :way
48 way_path(params[:way], options)
49 elsif params.key? :relation
50 relation_path(params[:relation], options)
51 elsif params.key? :changeset
52 changeset_path(params[:changeset], options)
61 expires_in 7.days, :public => true
62 @key = YAML.load_file(Rails.root.join("config/key.yml"))
63 @key.each_value do |layer_data|
64 layer_data.each do |entry|
65 entry["name"] = Array(entry["name"])
67 layer_data.each_cons(2) do |entry, next_entry|
68 entry["max_zoom"] = next_entry["min_zoom"] - 1 if entry["name"] == next_entry["name"] && !entry["max_zoom"] && next_entry["min_zoom"]
71 render :layout => false
75 editor = preferred_editor
79 render :action => :index, :layout => map_layout
87 bbox = Node.visible.find(params[:node]).bbox.to_unscaled
88 @lat = bbox.centre_lat
89 @lon = bbox.centre_lon
92 bbox = Way.visible.find(params[:way]).bbox.to_unscaled
93 @lat = bbox.centre_lat
94 @lon = bbox.centre_lon
97 note = Note.visible.find(params[:note])
101 elsif params[:gpx] && current_user
102 trace = Trace.visible_to(current_user).find(params[:gpx])
103 @lat = trace.latitude
104 @lon = trace.longitude
107 rescue ActiveRecord::RecordNotFound
108 # don't try and derive a location from a missing/deleted object
113 @locale = params[:copyright_locale] || I18n.locale
121 @locale = params[:about_locale] || I18n.locale
125 @local_chapters = Community.where(:type => "osm-lc").where.not(:id => "OSMF")
131 flash.now[:warning] = if Settings.status == "database_offline"
132 t("layouts.osm_offline")
134 t("layouts.osm_read_only")
136 render :html => nil, :layout => true
140 render :html => RichText.new(params[:type], params[:text]).to_html
144 render :layout => false
149 def redirect_browse_params
151 redirect_to node_path(params[:node])
153 redirect_to way_path(params[:way])
154 elsif params[:relation]
155 redirect_to relation_path(params[:relation])
157 redirect_to note_path(params[:note])
159 redirect_to search_path(:query => params[:query])
163 def redirect_map_params
166 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}" if params[:lat] && params[:lon]
169 anchor << "layers=#{params.delete(:layers)}"
170 elsif params.delete(:notes) == "yes"
174 redirect_to params.to_unsafe_h.merge(:only_path => true, :anchor => anchor.join("&")) if anchor.present?