diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-06-20 19:06:19 +0200 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-06-20 19:06:19 +0200 |
commit | eb0e1cc5c26275ff3e5c341404e8bc558f8312b8 (patch) | |
tree | 71f449ccd6f15422717de3ac24f87d5e888ddd79 /lib | |
parent | df6e17e48995f25e72509986f30700d778b179b6 (diff) | |
parent | 3b27a5d45b12f6bac65da2a8e17387bfda42a2f1 (diff) |
Merge branch 'develop'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/freeswitch_event.rb | 2 | ||||
-rw-r--r-- | lib/tasks/backup.rake | 16 | ||||
-rw-r--r-- | lib/tasks/csv_user_import.rake | 14 | ||||
-rw-r--r-- | lib/tasks/update_area_codes.rake | 52 | ||||
-rw-r--r-- | lib/tasks/update_geo_ip_countries.rake | 44 |
5 files changed, 119 insertions, 9 deletions
diff --git a/lib/freeswitch_event.rb b/lib/freeswitch_event.rb index 89d8ea0..f17cd78 100644 --- a/lib/freeswitch_event.rb +++ b/lib/freeswitch_event.rb @@ -60,7 +60,7 @@ class FreeswitchEventSocket if ! body.blank? message['_BODY'] = body end - header.split("\n").each do |line| + header.to_s.split("\n").each do |line| key, value = line.split(/\: */, 2) message[key] = value end diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake index 83bcfd3..0dbadad 100644 --- a/lib/tasks/backup.rake +++ b/lib/tasks/backup.rake @@ -25,32 +25,32 @@ namespace :backup do tmp_dir = "/tmp/gs5_restore_directory" FileUtils.rm_rf tmp_dir FileUtils.mkdir_p tmp_dir - system "cd #{tmp_dir} && nice -n 19 sudo /bin/tar xzf #{restore_job.backup_file.path}" + system "cd #{tmp_dir} && nice -n 19 ionice -c2 -n7 sudo /bin/tar xzf #{restore_job.backup_file.path}" restore_directory = Dir.glob("/tmp/gs5_restore_directory/*").first - system "cd #{restore_directory} && nice -n 19 sudo /bin/tar xf GS5.tar && rm GS5.tar" + system "cd #{restore_directory} && nice -n 19 ionice -c2 -n7 sudo /bin/tar xf GS5.tar && rm GS5.tar" # Restore faxes # if File.exists?("#{restore_directory}/GS5/archives/faxes.tar.gz") - system "cd / && nice -n 19 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/faxes.tar.gz" + system "cd / && nice -n 19 ionice -c2 -n7 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/faxes.tar.gz" end # Restore voicemails # if File.exists?("#{restore_directory}/GS5/archives/voicemails.tar.gz") - system "cd / && nice -n 19 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/voicemails.tar.gz" + system "cd / && nice -n 19 ionice -c2 -n7 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/voicemails.tar.gz" end # Restore recordings # if File.exists?("#{restore_directory}/GS5/archives/recordings.tar.gz") - system "cd / && nice -n 19 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/recordings.tar.gz" + system "cd / && nice -n 19 ionice -c2 -n7 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/recordings.tar.gz" end # Restore avatars # if File.exists?("#{restore_directory}/GS5/archives/avatars.tar.gz") - system "cd / && nice -n 19 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/avatars.tar.gz" + system "cd / && nice -n 19 ionice -c2 -n7 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/avatars.tar.gz" end # Delete the archive tar.gz to get more air to breathe @@ -65,11 +65,11 @@ namespace :backup do db_user = system_odbc_configuration['gemeinschaft']['USER'] db_password = system_odbc_configuration['gemeinschaft']['PASSWORD'] - system "nice -n 19 gunzip < #{restore_directory}/GS5/databases/MySQL/gemeinschaft.sql.gz | nice -n 19 mysql -u #{db_user} -p#{db_password} #{database}" + system "nice -n 19 ionice -c2 -n7 gunzip < #{restore_directory}/GS5/databases/MySQL/gemeinschaft.sql.gz | nice -n 19 ionice -c2 -n7 mysql -u #{db_user} -p#{db_password} #{database}" FileUtils.rm_rf tmp_dir - system "cd /opt/gemeinschaft && nice -n 19 rake db:migrate" + system "cd /opt/gemeinschaft && nice -n 19 ionice -c2 -n7 rake db:migrate" # Rebuild the thumbnails # diff --git a/lib/tasks/csv_user_import.rake b/lib/tasks/csv_user_import.rake index 81959d5..e65bc1f 100644 --- a/lib/tasks/csv_user_import.rake +++ b/lib/tasks/csv_user_import.rake @@ -129,6 +129,16 @@ namespace :user_import do end if user + # Create voicemail account + voicemail_account = user.voicemail_accounts.first + if !voicemail_account + if VoicemailAccount.where(:name => "user_#{user.user_name}").count == 0 + voicemail_account = user.voicemail_accounts.create(:name => "user_#{user.user_name}", :active => true ) + else + voicemail_account = user.voicemail_accounts.create(:active => true) + end + end + # Find or create a sip_accounts ['VoipNr1', 'VoipNr2', 'VoipNr3'].each_with_index do |phone_number_type, index| @@ -141,6 +151,9 @@ namespace :user_import do if !phone_number_type.blank? && !csv_user[phone_number_type].blank? sip_account = user.sip_accounts.where(:auth_name => auth_name).first if sip_account + if sip_account.voicemail_account != voicemail_account + sip_account.update_attributes(:voicemail_account_id => voicemail_account.id) + end if sip_account.caller_name.to_s != user.to_s sip_account.update_attributes(:caller_name => user.to_s) end @@ -154,6 +167,7 @@ namespace :user_import do :hotdeskable => true, :callforward_rules_act_per_sip_account => true, :gs_node_id => gs_node_id, + :voicemail_account_id => voicemail_account.id, ) end diff --git a/lib/tasks/update_area_codes.rake b/lib/tasks/update_area_codes.rake new file mode 100644 index 0000000..0d6eadd --- /dev/null +++ b/lib/tasks/update_area_codes.rake @@ -0,0 +1,52 @@ +namespace :area_codes_update do + desc "Update Area Codes and Central Office Codes." + task :nanp => :environment do + ARCHIVE_URL = 'http://www.nanpa.com/nanp1/allutlzd.zip' + ARCHIVE_PATH = '/tmp/nanp_area_codes.zip' + SOURCE_FILE = '/tmp/allutlzd.txt' + + country = Country.where(:name => "United States of America" ).first + + require 'open-uri' + open(ARCHIVE_PATH, 'wb') do |file| + puts 'Downloading area codes list...' + file << open(ARCHIVE_URL).read + end + + system("cd /tmp/ && unzip #{ARCHIVE_PATH}") + all_lines_count = 0 + File.open(SOURCE_FILE, 'r') {|file| all_lines_count = file.read.count("\n")} + + lines = 0 + File.open(SOURCE_FILE, 'r').each_line do |line| + lines += 1 + + if lines == 1 + next + end + + line_array = line.split("\t") + + state = line_array[0].strip + npa, ncc = line_array[1].split("-") + rate_center = line_array[4].strip.titleize + + if rate_center.blank? || line_array[6].strip != 'AS' || rate_center == 'Xxxxxxxxxx' + next + end + + name = "#{rate_center}, #{state}" + percent = lines.to_f / all_lines_count.to_f * 100.0 + puts "#{all_lines_count} / #{lines} / #{percent.to_i}% / Processing #{name} / +1-#{npa}-#{ncc} " + + area_code = AreaCode.where(:country_id => country.id, :area_code => npa, :central_office_code => ncc).first + if !area_code + area_code = AreaCode.create(:country_id => country.id, :area_code => npa, :central_office_code => ncc, :name => name) + else + if area_code.name != name + area_code.update_attributes({ :name => name }) + end + end + end + end +end
\ No newline at end of file diff --git a/lib/tasks/update_geo_ip_countries.rake b/lib/tasks/update_geo_ip_countries.rake new file mode 100644 index 0000000..86b98fe --- /dev/null +++ b/lib/tasks/update_geo_ip_countries.rake @@ -0,0 +1,44 @@ +namespace :geo_ip_update do + desc "Update Area Codes and Central Office Codes." + task :country => :environment do + ARCHIVE_URL = 'http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip' + ARCHIVE_PATH = '/tmp/geo_ip_countries.zip' + SOURCE_FILE = '/tmp/GeoIPCountryWhois.csv' + + require 'open-uri' + open(ARCHIVE_PATH, 'wb') do |file| + puts 'Downloading GEO-IP database...' + file << open(ARCHIVE_URL).read + end + + system("cd /tmp/ && unzip #{ARCHIVE_PATH}") + all_lines_count = 0 + File.open(SOURCE_FILE, 'r') {|file| all_lines_count = file.read.count("\n")} + + if all_lines_count < 100000 + puts "Too few lines: #{all_lines_count}" + return 0 + end + + GeoIpCountry.destroy_all + + lines = 0 + File.open(SOURCE_FILE, 'r').each_line do |line| + lines += 1 + + line_array = line.split(',') + parameters = { + :from => line_array[0].gsub('"','').strip, + :to => line_array[1].gsub('"','').strip, + :n_from => line_array[2].gsub('"','').to_i, + :n_to => line_array[3].gsub('"','').to_i, + :country_code => line_array[4].gsub('"','').strip, + :country_name => line_array[5].gsub('"','').strip + } + + percent = lines.to_f / all_lines_count.to_f * 100.0 + puts "#{all_lines_count} / #{lines} / #{percent.to_i}% / Processing #{parameters[:from]}-#{parameters[:to]} / #{parameters[:country_name]} " + area_code = GeoIpCountry.create(parameters) + end + end +end
\ No newline at end of file |