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
16 session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless Settings.status == "database_readonly" || Settings.status == "database_offline"
20 lon, lat, zoom = ShortLink.decode(params[:code])
21 new_params = params.except(:host, :controller, :action, :code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
25 new_params[:mlat] = lat
26 new_params[:mlon] = lon
29 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
30 new_params[:anchor] += "&layers=#{params[:layers]}" if params.key? :layers
32 options = new_params.to_unsafe_h.to_options
34 path = if params.key? :node
35 node_path(params[:node], options)
36 elsif params.key? :way
37 way_path(params[:way], options)
38 elsif params.key? :relation
39 relation_path(params[:relation], options)
40 elsif params.key? :changeset
41 changeset_path(params[:changeset], options)
50 expires_in 7.days, :public => true
51 @key = YAML.load_file(Rails.root.join("config/key.yml"))
52 @key.each_value do |layer_data|
53 layer_data.each do |entry|
54 entry["name"] = Array(entry["name"])
56 layer_data.each_cons(2) do |entry, next_entry|
57 entry["max_zoom"] = next_entry["min_zoom"] - 1 if entry["name"] == next_entry["name"] && !entry["max_zoom"] && next_entry["min_zoom"]
60 render :layout => false
64 editor = preferred_editor
68 render :action => :index, :layout => map_layout
74 if %w[id].include?(editor)
75 append_content_security_policy_directives(
76 :frame_src => %w[blob:]
82 bbox = Node.visible.find(params[:node]).bbox.to_unscaled
83 @lat = bbox.centre_lat
84 @lon = bbox.centre_lon
87 bbox = Way.visible.find(params[:way]).bbox.to_unscaled
88 @lat = bbox.centre_lat
89 @lon = bbox.centre_lon
92 note = Note.visible.find(params[:note])
96 elsif params[:gpx] && current_user
97 trace = Trace.visible_to(current_user).find(params[:gpx])
99 @lon = trace.longitude
102 rescue ActiveRecord::RecordNotFound
103 # don't try and derive a location from a missing/deleted object
108 @locale = params[:copyright_locale] || I18n.locale
116 @locale = params[:about_locale] || I18n.locale
120 @local_chapters = Community.where(:type => "osm-lc").where.not(:id => "OSMF")
126 flash.now[:warning] = if Settings.status == "database_offline"
127 t("layouts.osm_offline")
129 t("layouts.osm_read_only")
131 render :html => nil, :layout => true
135 render :html => RichText.new(params[:type], params[:text]).to_html
139 append_content_security_policy_directives(
140 :connect_src => %w[*],
141 :img_src => %w[* blob:],
142 :script_src => %w[dev.virtualearth.net 'unsafe-eval'],
143 :style_src => %w['unsafe-inline']
146 render :layout => false
151 def redirect_browse_params
153 redirect_to node_path(params[:node])
155 redirect_to way_path(params[:way])
156 elsif params[:relation]
157 redirect_to relation_path(params[:relation])
159 redirect_to note_path(params[:note])
161 redirect_to search_path(:query => params[:query])
165 def redirect_map_params
168 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}" if params[:lat] && params[:lon]
171 anchor << "layers=#{params.delete(:layers)}"
172 elsif params.delete(:notes) == "yes"
176 redirect_to params.to_unsafe_h.merge(:only_path => true, :anchor => anchor.join("&")) if anchor.present?