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 :update_totp, :only => [:index]
12 authorize_resource :class => false
15 session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless Settings.status == "database_readonly" || Settings.status == "database_offline"
19 lon, lat, zoom = ShortLink.decode(params[:code])
20 new_params = params.except(:code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
24 new_params[:mlat] = lat
25 new_params[:mlon] = lon
29 new_params[:controller] = "browse"
30 new_params[:action] = "node"
31 new_params[:id] = params[:node]
32 elsif params.key? :way
33 new_params[:controller] = "browse"
34 new_params[:action] = "way"
35 new_params[:id] = params[:way]
36 elsif params.key? :relation
37 new_params[:controller] = "browse"
38 new_params[:action] = "relation"
39 new_params[:id] = params[:relation]
40 elsif params.key? :changeset
41 new_params[:controller] = "browse"
42 new_params[:action] = "changeset"
43 new_params[:id] = params[:changeset]
45 new_params[:controller] = "site"
46 new_params[:action] = "index"
49 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
50 new_params[:anchor] += "&layers=#{params[:layers]}" if params.key? :layers
52 redirect_to new_params.to_unsafe_h
56 expires_in 7.days, :public => true
57 render :layout => false
61 editor = preferred_editor
65 render :action => :index, :layout => map_layout
71 if %w[potlatch potlatch2].include?(editor)
72 append_content_security_policy_directives(
73 :connect_src => %w[*],
75 :plugin_types => %w[application/x-shockwave-flash],
76 :script_src => %w['unsafe-inline']
78 elsif %w[id].include?(editor)
79 append_content_security_policy_directives(
80 :frame_src => %w[blob:]
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
128 render :html => RichText.new(params[:type], params[:text]).to_html
132 append_content_security_policy_directives(
133 :connect_src => %w[*],
134 :img_src => %w[* blob:],
135 :script_src => %w[dev.virtualearth.net 'unsafe-eval'],
136 :style_src => %w['unsafe-inline']
139 render :layout => false
144 def redirect_browse_params
146 redirect_to node_path(params[:node])
148 redirect_to way_path(params[:way])
149 elsif params[:relation]
150 redirect_to relation_path(params[:relation])
152 redirect_to browse_note_path(params[:note])
154 redirect_to search_path(:query => params[:query])
158 def redirect_map_params
161 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}" if params[:lat] && params[:lon]
164 anchor << "layers=#{params.delete(:layers)}"
165 elsif params.delete(:notes) == "yes"
169 redirect_to params.to_unsafe_h.merge(:anchor => anchor.join("&")) if anchor.present?