Created
July 19, 2012 10:29
-
-
Save jerius/3142914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| require 'net/https' | |
| require 'open-uri' | |
| require 'optparse' | |
| require 'readline' | |
| require 'openssl' | |
| ['TERM', 'INT'].each do |signal| | |
| trap(signal){exit} | |
| end | |
| file = false | |
| @rhost ||= Readline::readline("Remote IP: ") | |
| @rlogin ||= Readline::readline("Remote login: ") | |
| @rpassword ||= Readline::readline("Remote password: ") | |
| @lwhost ||= Readline::readline("LW IP: ") | |
| @lwpass ||= Readline::readline("LW Root Pass: ") | |
| @lwemail ||= Readline::readline("Your Email: ") | |
| @skin = Array.new | |
| @accounts = Array.new | |
| unless file | |
| if ARGV.empty? | |
| http = Net::HTTP.new(@rhost, 2087) | |
| http.use_ssl = true | |
| OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE | |
| open("https://#{@rhost}:2087/scripts/fetchcsv", :http_basic_authentication => [@rlogin,@rpassword]) do |csv| | |
| csv.each do |x| | |
| @accounts << x.split(',')[2] | |
| @skin << x.split(',')[9] | |
| end | |
| end | |
| else | |
| @accounts = ARGV | |
| @accounts.uniq! | |
| end | |
| else | |
| @accounts.open(file).readlines | |
| @accounts.uniq! | |
| end | |
| puts "Number of accounts to transfer: #{@accounts.nitems}" | |
| l = 0 | |
| @accounts.each do |x| | |
| if x == 'User Name' | |
| l += 1 | |
| next | |
| end | |
| puts "Processing #{x}" | |
| skin = @skin[l] | |
| puts "Skin:\t#{skin}" | |
| url = "/frontend/#{skin}/backup/dofullbackup.html" | |
| postvars = {'dest' => 'scp', 'email' => @lwemail, 'server' => @lwhost, 'user' => 'root', 'pass' => @lwpass, 'port' => '22', 'rdir' => '/home/'} | |
| req = Net::HTTP::Post.new(url) | |
| req.basic_auth x, @rpassword | |
| req.set_form_data(postvars) | |
| Net::HTTP.new(@rhost, 2083).start { |http| http.request(req) } | |
| l += 1 | |
| puts "Sleeping for 60 seconds to prevent server load" | |
| sleep 60 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment