app/controllers/admin/pages_dialogs_controller.rb in refinerycms-pages-0.9.9.7 vs app/controllers/admin/pages_dialogs_controller.rb in refinerycms-pages-0.9.9.8
- old
+ new
@@ -46,30 +46,30 @@
@resource_area_selected = is_resource_link
end
end
def test_url
- unless params[:url].blank?
- url = URI.parse(params[:url])
- if url.host.nil? && params[:url].start_with?('/')
- url.host = URI.parse(request.url).host
- end
+ begin
+ timeout(5) do
+ unless params[:url].blank?
+ url = URI.parse(params[:url])
+ if url.host.nil? && params[:url].start_with?('/')
+ url.host = URI.parse(request.url).host
+ end
- http = Net::HTTP.new(url.host)
- request = Net::HTTP::Get.new(url.path.blank? ? "/" : url.path)
+ result = case Net::HTTP.get_response(url)
+ when Net::HTTPSuccess, Net::HTTPRedirection
+ 'success'
+ else
+ 'failure'
+ end
- response = http.request request
-
- render :json => {:result => case response
- when Net::HTTPSuccess, Net::HTTPRedirection
- 'success'
- else
- 'failure'
- end }
- end
-
+ render :json => {:result => result}
+ end
+ end
rescue
render :json => {:result => 'failure'}
+ end
end
def test_email
unless params[:email].blank?
valid = params[:email] =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i