Skip to content

Instantly share code, notes, and snippets.

@nullcookies
Forked from avsej/fetch_rubymine_license.rb
Created January 8, 2020 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nullcookies/b008e5755613d1e94c9443cf2bd16537 to your computer and use it in GitHub Desktop.
Save nullcookies/b008e5755613d1e94c9443cf2bd16537 to your computer and use it in GitHub Desktop.
Automate rubymine license fetching
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'digest/md5'
require 'pp'
begin
require 'faker'
rescue LoadError
puts "You should install faker gem. (gem install faker)"
exit
end
jetbrains_uri = URI.parse("http://www.jetbrains.com/eforms/rmEvaluation.action")
login = "e#{Digest::MD5.hexdigest(Time.now.to_s)[0...8]}"
params = {
"licenseRequest.firstName" => Faker::Name.first_name,
"licenseRequest.lastName" => Faker::Name.last_name,
"licenseRequest.registrationName" => Faker::Name.name,
"licenseRequest.email" => "#{login}@asdasd.ru",
"licenseRequest.company" => Faker::Company.name,
"licenseRequest.country" => "UNITED STATES",
"submitButton" => "Submit"
}
puts "post to #{jetbrains_uri}"
pp params
response = Net::HTTP.post_form(jetbrains_uri, params)
asdasd_inbox_uri = URI.parse("http://asdasd.ru/?to=#{login}&dfrom=jetbrains.com")
msgid = nil
while msgid.nil?
sleep_time = 60
puts "sleep for #{sleep_time} seconds"
(sleep_time/10).times { sleep(10); print "." }
puts "\ncheck inbox #{asdasd_inbox_uri}"
inbox = Net::HTTP.get(asdasd_inbox_uri)
inbox =~ /location\.href='\/read\?msgid=(\d+)'/
msgid = $1
end
puts "message found msgid=#{msgid}"
asdasd_message_uri = URI.parse("http://asdasd.ru/read?msgid=#{msgid}")
puts "fetch message #{asdasd_message_uri}"
mail = Net::HTTP.get(asdasd_message_uri)
mail =~ /=+ LICENSE BEGIN =+(.*?)=+ LICENSE END =+/m
key = $1.gsub(/<br \/>/, "\n")
puts "Here your license key:"
puts key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment