Class: WmsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wms_controller.rb

Instance Method Summary collapse

Instance Method Details

#accessObject

Return 200 for direct accessible WMS and 404 for protected WMS



42
43
44
45
46
47
48
49
50
# File 'app/controllers/wms_controller.rb', line 42

def access
  accessible = public?(params[:service], host_zone(request.host))
  expires_in 2.minutes, :public => true
  if !accessible
    render :nothing => true, :status => 404
  else
    render :nothing => true
  end
end

#mapservObject



52
53
54
55
56
57
58
59
# File 'app/controllers/wms_controller.rb', line 52

def mapserv
  require 'lib/mapserver'
  @@wms = nil if Rails.env.development?
  path = File.expand_path(File.join(Rails.root, 'mapserver', 'maps', @zone))
  @@wms ||= Mapserver.new(nil, File.join(path, "#{params[:service]}.map"))
  status, type, body = @@wms.call(request.env)
  send_data body, :type => type['Content-Type'], :status => status, :disposition => 'inline'
end

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/wms_controller.rb', line 6

def show
  logger.debug "----> WMS call with user '#{current_user.try(:login)}'"

  topic_name = params[:service]
  topic = Topic.where(:name => topic_name).first
  add_sld_body(topic)
  add_filter(topic_name)

  #Send redirect for public services
  if MAPSERV_REDIRECT && request.get? && public?(topic_name, host_zone(request.host))
    url, path = mapserv_request_url(request)
    #expires_in 2.minutes, :public => true #FIXME: cache_path "wms-public-#{topic_name}-#{host_zone(request.host)}"
    redirect_to "#{url.scheme}://#{url.host}:#{url.port}#{path}"
    return
  end

  topic_accessible = topic && can?(:show, topic)
  wms_accessible = can?(:show, Wms.new(topic_name))

  if topic_accessible && !wms_accessible
    topic_accessible = session_ok?
    if !topic_accessible
      logger.info "----> WMS '#{topic_name}' not accessible without valid session!"
    end
  end
  if !topic_accessible && !wms_accessible && !print_request? # allow all topics for print servlet
    logger.info "----> Topic/WMS '#{topic_name}' not accessible with roles #{current_roles.roles.collect(&:name).join('+')}!"
    log_user_permissions(:show, topic) if topic
    log_user_permissions(:show, Wms.new(topic_name))
    request_http_basic_authentication('Secure WMS Login')
    return
  end
  call_wms(request)
end