Merge branch 'develop' into feature/rails4
This commit is contained in:
commit
f2401fe793
6 changed files with 237 additions and 95 deletions
|
@ -291,11 +291,8 @@ class App.Navigation extends App.Controller
|
||||||
|
|
||||||
items = data.recent_viewed
|
items = data.recent_viewed
|
||||||
|
|
||||||
# load user collection
|
# load collections
|
||||||
App.Collection.load( type: 'User', data: data.users )
|
App.Event.trigger 'loadAssets', data.assets
|
||||||
|
|
||||||
# load ticket collection
|
|
||||||
App.Collection.load( type: 'Ticket', data: data.tickets )
|
|
||||||
|
|
||||||
# remove old views
|
# remove old views
|
||||||
NavBarRight = @Config.get( 'NavBarRight' ) || {}
|
NavBarRight = @Config.get( 'NavBarRight' ) || {}
|
||||||
|
|
|
@ -8,17 +8,11 @@ class LongPollingController < ApplicationController
|
||||||
new_connection = false
|
new_connection = false
|
||||||
|
|
||||||
# check client id
|
# check client id
|
||||||
client_id = client_id_check
|
client_id = client_id_verify
|
||||||
if !client_id
|
if !client_id
|
||||||
new_connection = true
|
new_connection = true
|
||||||
client_id = client_id_gen
|
client_id = client_id_gen
|
||||||
log 'notice', "new client connection", client_id
|
log 'notice', "new client connection", client_id
|
||||||
else
|
|
||||||
# cerify client id
|
|
||||||
if !client_id_verify
|
|
||||||
render :json => { :error => 'Invalid client_id in send!' }, :status => :unprocessable_entity
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if !params['data']
|
if !params['data']
|
||||||
params['data'] = {}
|
params['data'] = {}
|
||||||
|
@ -109,13 +103,13 @@ class LongPollingController < ApplicationController
|
||||||
def message_receive
|
def message_receive
|
||||||
|
|
||||||
# check client id
|
# check client id
|
||||||
if !client_id_verify
|
client_id = client_id_verify
|
||||||
|
if !client_id
|
||||||
render :json => { :error => 'Invalid client_id receive!' }, :status => :unprocessable_entity
|
render :json => { :error => 'Invalid client_id receive!' }, :status => :unprocessable_entity
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# check queue to send
|
# check queue to send
|
||||||
client_id = client_id_check
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
# update last ping
|
# update last ping
|
||||||
|
@ -153,18 +147,16 @@ class LongPollingController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def client_id_check
|
|
||||||
return params[:client_id].to_s if params[:client_id]
|
|
||||||
return
|
|
||||||
end
|
|
||||||
def client_id_gen
|
def client_id_gen
|
||||||
rand(9999999999).to_s
|
rand(9999999999).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def client_id_verify
|
def client_id_verify
|
||||||
return if !params[:client_id]
|
return if !params[:client_id]
|
||||||
sessions = Sessions.sessions
|
sessions = Sessions.sessions
|
||||||
return if !sessions.include?( params[:client_id].to_s )
|
return if !sessions.include?( params[:client_id].to_s )
|
||||||
return true
|
return params[:client_id].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def log( level, data, client_id = '-' )
|
def log( level, data, client_id = '-' )
|
||||||
|
|
|
@ -4,8 +4,8 @@ class GeoLocation::Gmaps
|
||||||
|
|
||||||
def self.geocode(address)
|
def self.geocode(address)
|
||||||
url = "http://maps.googleapis.com/maps/api/geocode/json?address=#{CGI::escape address}&sensor=true"
|
url = "http://maps.googleapis.com/maps/api/geocode/json?address=#{CGI::escape address}&sensor=true"
|
||||||
response = Net::HTTP.get_response( URI.parse(url) )
|
response = UserAgent.request(url)
|
||||||
return if ! response.kind_of? Net::HTTPSuccess
|
return if !response.success?
|
||||||
|
|
||||||
result = JSON.parse( response.body )
|
result = JSON.parse( response.body )
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ class GeoLocation::Gmaps
|
||||||
|
|
||||||
def self.reverse_geocode(lat,lng)
|
def self.reverse_geocode(lat,lng)
|
||||||
url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&sensor=true"
|
url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&sensor=true"
|
||||||
response = Net::HTTP.get_response( URI.parse(url) )
|
response = UserAgent.request(url)
|
||||||
return if ! response.kind_of? Net::HTTPSuccess
|
return if !response.success?
|
||||||
|
|
||||||
result = JSON.parse( response.body )
|
result = JSON.parse( response.body )
|
||||||
|
|
||||||
|
|
|
@ -4,67 +4,34 @@ module Import::OTRS
|
||||||
def self.request(part)
|
def self.request(part)
|
||||||
url = Setting.get('import_otrs_endpoint') + '/' + part + ';Key=' + Setting.get('import_otrs_endpoint_key')
|
url = Setting.get('import_otrs_endpoint') + '/' + part + ';Key=' + Setting.get('import_otrs_endpoint_key')
|
||||||
puts 'GET: ' + url
|
puts 'GET: ' + url
|
||||||
# response = Net::HTTP.get_response( URI.parse(url), { :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE } )
|
response = UserAgent.request(
|
||||||
uri = URI.parse(url)
|
url,
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
{
|
||||||
|
:user => Setting.get('import_otrs_user'),
|
||||||
if url =~ /https/i
|
:password => Setting.get('import_otrs_password'),
|
||||||
http.use_ssl = true
|
},
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
)
|
||||||
end
|
if !response.success?
|
||||||
request = Net::HTTP::Get.new(uri.request_uri)
|
puts "ERROR: #{response.error}"
|
||||||
|
|
||||||
# http basic auth (if needed)
|
|
||||||
user = Setting.get('import_otrs_user');
|
|
||||||
password = Setting.get('import_otrs_password');
|
|
||||||
if user && user != '' && password && password != ''
|
|
||||||
request.basic_auth user, password
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
|
||||||
response = http.request(request)
|
|
||||||
# puts 'R:' + response.body.to_s
|
|
||||||
rescue Exception => e
|
|
||||||
puts "can't get #{url}"
|
|
||||||
puts e.inspect
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if !response
|
|
||||||
raise "Can't connect to #{url}, got no response!"
|
|
||||||
end
|
|
||||||
if response.code.to_s != '200'
|
|
||||||
raise "Connection to #{url} failed, '#{response.code.to_s}'!"
|
|
||||||
end
|
|
||||||
return response
|
return response
|
||||||
end
|
end
|
||||||
def self.post(base, data)
|
def self.post(base, data)
|
||||||
url = Setting.get('import_otrs_endpoint') + '/' + base
|
url = Setting.get('import_otrs_endpoint') + '/' + base
|
||||||
data['Key'] = Setting.get('import_otrs_endpoint_key')
|
data['Key'] = Setting.get('import_otrs_endpoint_key')
|
||||||
puts 'POST: ' + url
|
puts 'POST: ' + url
|
||||||
uri = URI.parse(url)
|
response = UserAgent.request(
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
url,
|
||||||
|
{
|
||||||
if url =~ /https/i
|
:method => 'post',
|
||||||
http.use_ssl = true
|
:user => Setting.get('import_otrs_user'),
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
:password => Setting.get('import_otrs_password'),
|
||||||
end
|
},
|
||||||
request = Net::HTTP::Post.new(uri.request_uri)
|
)
|
||||||
|
if !response.success?
|
||||||
# http basic auth (if needed)
|
puts "ERROR: #{response.error}"
|
||||||
user = Setting.get('import_otrs_user');
|
return
|
||||||
password = Setting.get('import_otrs_password');
|
|
||||||
if user && user != '' && password && password != ''
|
|
||||||
request.basic_auth user, password
|
|
||||||
end
|
|
||||||
|
|
||||||
request.set_form_data(data)
|
|
||||||
response = http.request(request)
|
|
||||||
|
|
||||||
if !response
|
|
||||||
raise "Can't connect to #{url}, got no response!"
|
|
||||||
end
|
|
||||||
if response.code.to_s != '200'
|
|
||||||
raise "Connection to #{url} failed, '#{response.code.to_s}'!"
|
|
||||||
end
|
end
|
||||||
return response
|
return response
|
||||||
end
|
end
|
||||||
|
@ -77,7 +44,7 @@ module Import::OTRS
|
||||||
def self.auth(username, password)
|
def self.auth(username, password)
|
||||||
response = post( "public.pl", { :Action => 'Export', :Type => 'Auth', :User => username, :Pw => password } )
|
response = post( "public.pl", { :Action => 'Export', :Type => 'Auth', :User => username, :Pw => password } )
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
|
|
||||||
result = json(response)
|
result = json(response)
|
||||||
return result
|
return result
|
||||||
|
@ -86,7 +53,7 @@ module Import::OTRS
|
||||||
def self.session(session_id)
|
def self.session(session_id)
|
||||||
response = post( "public.pl", { :Action => 'Export', :Type => 'SessionCheck', :SessionID => session_id } )
|
response = post( "public.pl", { :Action => 'Export', :Type => 'SessionCheck', :SessionID => session_id } )
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
|
|
||||||
result = json(response)
|
result = json(response)
|
||||||
return result
|
return result
|
||||||
|
@ -105,7 +72,7 @@ module Import::OTRS
|
||||||
|
|
||||||
response = request("public.pl?Action=Export")
|
response = request("public.pl?Action=Export")
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
|
|
||||||
#self.ticket('156115')
|
#self.ticket('156115')
|
||||||
#return
|
#return
|
||||||
|
@ -189,7 +156,7 @@ module Import::OTRS
|
||||||
url = "public.pl?Action=Export;Type=TicketDiff;Limit=30"
|
url = "public.pl?Action=Export;Type=TicketDiff;Limit=30"
|
||||||
response = request( url )
|
response = request( url )
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
result = json(response)
|
result = json(response)
|
||||||
self._ticket_result(result)
|
self._ticket_result(result)
|
||||||
end
|
end
|
||||||
|
@ -201,7 +168,7 @@ module Import::OTRS
|
||||||
}
|
}
|
||||||
response = request( url )
|
response = request( url )
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
|
|
||||||
result = json(response)
|
result = json(response)
|
||||||
self._ticket_result(result)
|
self._ticket_result(result)
|
||||||
|
@ -528,7 +495,7 @@ module Import::OTRS
|
||||||
def self.ticket_state
|
def self.ticket_state
|
||||||
response = request( "public.pl?Action=Export;Type=State" )
|
response = request( "public.pl?Action=Export;Type=State" )
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
|
|
||||||
result = json(response)
|
result = json(response)
|
||||||
# puts result.inspect
|
# puts result.inspect
|
||||||
|
@ -585,7 +552,7 @@ module Import::OTRS
|
||||||
def self.ticket_priority
|
def self.ticket_priority
|
||||||
response = request( "public.pl?Action=Export;Type=Priority" )
|
response = request( "public.pl?Action=Export;Type=Priority" )
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
|
|
||||||
result = json(response)
|
result = json(response)
|
||||||
map = {
|
map = {
|
||||||
|
@ -629,7 +596,7 @@ module Import::OTRS
|
||||||
def self.ticket_group
|
def self.ticket_group
|
||||||
response = request( "public.pl?Action=Export;Type=Queue" )
|
response = request( "public.pl?Action=Export;Type=Queue" )
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
|
|
||||||
result = json(response)
|
result = json(response)
|
||||||
map = {
|
map = {
|
||||||
|
@ -673,7 +640,7 @@ module Import::OTRS
|
||||||
def self.user
|
def self.user
|
||||||
response = request( "public.pl?Action=Export;Type=User" )
|
response = request( "public.pl?Action=Export;Type=User" )
|
||||||
return if !response
|
return if !response
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
result = json(response)
|
result = json(response)
|
||||||
map = {
|
map = {
|
||||||
:ChangeTime => :updated_at,
|
:ChangeTime => :updated_at,
|
||||||
|
@ -739,7 +706,7 @@ module Import::OTRS
|
||||||
response = request( "public.pl?Action=Export;Type=Customer;Count=100;Offset=#{count}" )
|
response = request( "public.pl?Action=Export;Type=Customer;Count=100;Offset=#{count}" )
|
||||||
return if !response
|
return if !response
|
||||||
count = count + 3000
|
count = count + 3000
|
||||||
return if response.code.to_s != '200'
|
return if !response.success?
|
||||||
result = json(response)
|
result = json(response)
|
||||||
map = {
|
map = {
|
||||||
:ChangeTime => :updated_at,
|
:ChangeTime => :updated_at,
|
||||||
|
|
12
lib/rss.rb
12
lib/rss.rb
|
@ -7,14 +7,8 @@ module Rss
|
||||||
|
|
||||||
begin
|
begin
|
||||||
puts 'fetch rss...'
|
puts 'fetch rss...'
|
||||||
response = Net::HTTP.get_response( URI.parse(url) )
|
response = UserAgent.request(url)
|
||||||
|
if !response.success?
|
||||||
# check if redirect is needed
|
|
||||||
if response.kind_of? Net::HTTPRedirection
|
|
||||||
url = response.header['location']
|
|
||||||
response = Net::HTTP.get_response( URI.parse( url ) )
|
|
||||||
end
|
|
||||||
if ! response.kind_of? Net::HTTPSuccess
|
|
||||||
raise "Can't fetch '#{url}', http code: #{response.code.to_s}"
|
raise "Can't fetch '#{url}', http code: #{response.code.to_s}"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -42,4 +36,4 @@ module Rss
|
||||||
|
|
||||||
return items
|
return items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
192
lib/user_agent.rb
Normal file
192
lib/user_agent.rb
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
require 'net/http'
|
||||||
|
require 'net/https'
|
||||||
|
require 'net/ftp'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
|
class UserAgent
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
http/https/ftp calls
|
||||||
|
|
||||||
|
result = UserAgent.request( 'ftp://host/some_dir/some_file.bin' )
|
||||||
|
|
||||||
|
result = UserAgent.request( 'http://host/some_dir/some_file.bin' )
|
||||||
|
|
||||||
|
result = UserAgent.request( 'https://host/some_dir/some_file.bin' )
|
||||||
|
|
||||||
|
result = UserAgent.request( 'http://host/some_dir/some_file.bin', { :method => 'post', :data => { :param1 => 123 } } )
|
||||||
|
|
||||||
|
returns
|
||||||
|
|
||||||
|
result # result object
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
|
||||||
|
def self.request(url, options = {})
|
||||||
|
|
||||||
|
uri = URI.parse(url)
|
||||||
|
case uri.scheme.downcase
|
||||||
|
when /ftp/
|
||||||
|
ftp(uri, options)
|
||||||
|
when /http|https/
|
||||||
|
http(uri, options, 10)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def self.http(uri, options, count)
|
||||||
|
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
|
||||||
|
if uri.scheme =~ /https/i
|
||||||
|
http.use_ssl = true
|
||||||
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
|
end
|
||||||
|
|
||||||
|
if !options[:method] || options[:method] =~ /^get$/i
|
||||||
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
|
|
||||||
|
# http basic auth (if needed)
|
||||||
|
if options[:user] && options[:user] != '' && options[:password] && options[:password] != ''
|
||||||
|
request.basic_auth user, password
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
response = http.request(request)
|
||||||
|
rescue Exception => e
|
||||||
|
return Result.new(
|
||||||
|
:error => e.inspect,
|
||||||
|
:success => false,
|
||||||
|
:code => 0,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
elsif options[:method] =~ /^post$/i
|
||||||
|
request = Net::HTTP::Post.new(uri.request_uri)
|
||||||
|
|
||||||
|
# http basic auth (if needed)
|
||||||
|
if options[:user] && options[:user] != '' && options[:password] && options[:password] != ''
|
||||||
|
request.basic_auth user, password
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
request.set_form_data( options[:data] )
|
||||||
|
response = http.request(request)
|
||||||
|
rescue Exception => e
|
||||||
|
return Result.new(
|
||||||
|
:error => e.inspect,
|
||||||
|
:success => false,
|
||||||
|
:code => 0,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if !response
|
||||||
|
return Result.new(
|
||||||
|
:error => "Can't connect to #{uri.to_s}, got no response!",
|
||||||
|
:success => false,
|
||||||
|
:code => 0,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
case response
|
||||||
|
when Net::HTTPNotFound
|
||||||
|
return Result.new(
|
||||||
|
:error => "No such file #{uri.to_s}, 404!",
|
||||||
|
:success => false,
|
||||||
|
:code => response.code,
|
||||||
|
)
|
||||||
|
|
||||||
|
when Net::HTTPClientError
|
||||||
|
return Result.new(
|
||||||
|
:error => "Client Error: #{response.inspect}!",
|
||||||
|
:success => false,
|
||||||
|
:code => response.code,
|
||||||
|
)
|
||||||
|
|
||||||
|
when Net::HTTPRedirection
|
||||||
|
raise "Too many redirections for the original URL, halting." if count <= 0
|
||||||
|
url = response["location"]
|
||||||
|
uri = URI.parse(url)
|
||||||
|
return http(uri, options, count - 1)
|
||||||
|
|
||||||
|
when Net::HTTPOK
|
||||||
|
return Result.new(
|
||||||
|
:body => response.body,
|
||||||
|
:success => true,
|
||||||
|
:code => response.code,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
raise "Unknown method '#{option[:method]}'"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.ftp(uri,options)
|
||||||
|
host = uri.host
|
||||||
|
filename = File.basename(uri.path)
|
||||||
|
remote_dir = File.dirname(uri.path)
|
||||||
|
|
||||||
|
temp_file = Tempfile.new("download-#{filename}")
|
||||||
|
temp_file.binmode
|
||||||
|
|
||||||
|
begin
|
||||||
|
Net::FTP.open(host) do |ftp|
|
||||||
|
ftp.passive = true
|
||||||
|
if options[:user] && options[:password]
|
||||||
|
ftp.login( options[:user], options[:password] )
|
||||||
|
else
|
||||||
|
ftp.login
|
||||||
|
end
|
||||||
|
ftp.chdir(remote_dir) unless remote_dir == '.'
|
||||||
|
|
||||||
|
begin
|
||||||
|
ftp.getbinaryfile( filename, temp_file )
|
||||||
|
rescue => e
|
||||||
|
return Result.new(
|
||||||
|
:error => e.inspect,
|
||||||
|
:success => false,
|
||||||
|
:code => 550,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
return Result.new(
|
||||||
|
:error => e.inspect,
|
||||||
|
:success => false,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
contents = temp_file.read
|
||||||
|
temp_file.close
|
||||||
|
Result.new(
|
||||||
|
:body => contents,
|
||||||
|
:success => true,
|
||||||
|
:code => 200,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
class Result
|
||||||
|
def initialize(options)
|
||||||
|
@success = options[:success]
|
||||||
|
@body = options[:body]
|
||||||
|
@code = options[:code]
|
||||||
|
@error = options[:error]
|
||||||
|
end
|
||||||
|
def error
|
||||||
|
@error
|
||||||
|
end
|
||||||
|
def success?
|
||||||
|
@success
|
||||||
|
end
|
||||||
|
def body
|
||||||
|
@body
|
||||||
|
end
|
||||||
|
def code
|
||||||
|
@code
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue