From 40d8290361bff123e0b44defa0f199708b89093b Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 14 Mar 2013 18:34:57 +0100 Subject: Adds a new remote_ip_address methode to figure out the remote IP address. #245 --- app/controllers/application_controller.rb | 4 ++++ app/controllers/config_polycom_controller.rb | 4 ++-- app/controllers/config_siemens_controller.rb | 2 +- app/controllers/config_snom_controller.rb | 4 ++-- app/controllers/gs_nodes_controller.rb | 2 +- app/controllers/trigger_controller.rb | 2 +- app/views/switchboard_entries/_switchboard_entry.html.haml | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d1d918e..12bea54 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -110,6 +110,10 @@ class ApplicationController < ActionController::Base redirect_to log_in_path, :alert => 'Access denied! You need to login first.' end end + + def request_remote_ip + request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip + end private diff --git a/app/controllers/config_polycom_controller.rb b/app/controllers/config_polycom_controller.rb index fd730e3..ca314c2 100644 --- a/app/controllers/config_polycom_controller.rb +++ b/app/controllers/config_polycom_controller.rb @@ -67,8 +67,8 @@ class ConfigPolycomController < ApplicationController if ! request.env['HTTP_USER_AGENT'].index('polycom') Rails.logger.info "---> User-Agent indicates not a Polycom phone (#{request.env['HTTP_USER_AGENT'].inspect})" else - Rails.logger.info "---> Phone #{@mac_address.inspect}, IP address #{request.remote_ip.inspect}" - @phone.update_attributes({ :ip_address => request.remote_ip }) + Rails.logger.info "---> Phone #{@mac_address.inspect}, IP address #{request_remote_ip.inspect}" + @phone.update_attributes({ :ip_address => request_remote_ip }) end xml_applications_url = "#{request.protocol}#{request.host_with_port}/config_polycom/#{@phone.id}/0" diff --git a/app/controllers/config_siemens_controller.rb b/app/controllers/config_siemens_controller.rb index 1966d49..7d5eb3f 100644 --- a/app/controllers/config_siemens_controller.rb +++ b/app/controllers/config_siemens_controller.rb @@ -146,7 +146,7 @@ class ConfigSiemensController < ApplicationController country = 'US' language = 'en' if ! @phone.nil? - @phone.update_attributes(:ip_address => request.remote_ip) + @phone.update_attributes(:ip_address => request_remote_ip) @sip_account = @phone.sip_accounts.where(:sip_accountable_type => @phone.phoneable_type, :sip_accountable_id => @phone.phoneable_id).first diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb index ae58ab8..8db1d57 100644 --- a/app/controllers/config_snom_controller.rb +++ b/app/controllers/config_snom_controller.rb @@ -233,8 +233,8 @@ class ConfigSnomController < ApplicationController if ! request.env['HTTP_USER_AGENT'].index('snom') Rails.logger.info "---> User-Agent indicates not a Snom phone (#{request.env['HTTP_USER_AGENT'].inspect})" else - Rails.logger.info "---> Phone #{@mac_address.inspect}, IP address #{request.remote_ip.inspect}" - @phone.update_attributes({ :ip_address => request.remote_ip }) + Rails.logger.info "---> Phone #{@mac_address.inspect}, IP address #{request_remote_ip.inspect}" + @phone.update_attributes({ :ip_address => request_remote_ip }) end @softkeys = Array.new() diff --git a/app/controllers/gs_nodes_controller.rb b/app/controllers/gs_nodes_controller.rb index 17c9e8b..6a5e0a6 100644 --- a/app/controllers/gs_nodes_controller.rb +++ b/app/controllers/gs_nodes_controller.rb @@ -48,7 +48,7 @@ class GsNodesController < ApplicationController end def sync - if !GsNode.where(:ip_address => request.remote_ip).first + if !GsNode.where(:ip_address => request_remote_ip).first render( :status => 404, :layout => false, diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index b8db4c9..623ea94 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -97,7 +97,7 @@ class TriggerController < ApplicationController # sip_account.switchboard_entries.each do |switchboard_entry| new_html = ActionController::Base.helpers.escape_javascript(render_to_string("switchboard_entries/_switchboard_entry", :layout => false, :locals => {:switchboard_entry => switchboard_entry})) - PrivatePub.publish_to("/switchboards/#{switchboard_entry.switchboard.id}", "$('#switchboard_entry_id_" + switchboard_entry.id.to_s + ".replaceWith('#{new_html}');") + PrivatePub.publish_to("/switchboards/#{switchboard_entry.switchboard.id}", "$('#switchboard_entry_id_" + switchboard_entry.id.to_s + "').replaceWith('#{new_html}');") end render( diff --git a/app/views/switchboard_entries/_switchboard_entry.html.haml b/app/views/switchboard_entries/_switchboard_entry.html.haml index 8d8e747..b2b6bff 100644 --- a/app/views/switchboard_entries/_switchboard_entry.html.haml +++ b/app/views/switchboard_entries/_switchboard_entry.html.haml @@ -2,7 +2,7 @@ %div.thumbnail %a.thumbnail{:href => tenant_user_path(switchboard_entry.sip_account.sip_accountable.current_tenant, switchboard_entry.sip_account.sip_accountable)} - if switchboard_entry.sip_account.sip_accountable.image? - = image_tag(switchboard_entry.sip_account.sip_accountable.image_url(:mini).to_s, :class => 'img-rounded') + = image_tag(switchboard_entry.sip_account.sip_accountable.image_url(:small).to_s, :class => 'img-rounded') - else - if switchboard_entry.sip_account.sip_accountable.male? = image_tag 'icons/user-male-16x.png', :class => 'img-rounded' -- cgit v1.2.3