license cloud finished

This commit is contained in:
Yan
2017-12-08 16:26:41 +06:30
parent 33326931e2
commit dd5936b991
2 changed files with 19 additions and 26 deletions

View File

@@ -61,7 +61,7 @@ class License
@license = response.parsed_response
if (@license["status"] == true)
assign()
assign(aes_key, aes_iv)
Rails.logger.info "License - " + response.parsed_response.to_s
@@ -79,7 +79,7 @@ class License
end
else
@license = Marshal.load(cache_license)
assign()
assign(aes_key, aes_iv)
Rails.logger.info 'API License'
return true
end
@@ -330,7 +330,7 @@ class License
end
# Assign db info for Cloud
def assign
def assign(aes_key, aes_iv)
# self.name = @license["name"]
# self.address_1 = @license["address_1"]
# self.address_2 = @license["address_2"]
@@ -354,10 +354,10 @@ class License
# self.plan_active_connections = @license["plan_active_connections"].to_i
# salt = @license["secret_key"]
key = Base64.decode64(ENV['AES_KEY'])
iv = Base64.decode64(ENV['AES_IV'])
key = Base64.decode64(aes_key)
iv = Base64.decode64(aes_iv)
if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] )
if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] )
host = Base64.decode64(@license["dbhost"])
dbschema = Base64.decode64(@license["dbschema"])
dbusername = Base64.decode64(@license["dbusername"])

View File

@@ -30,7 +30,7 @@ class MyAesCrypt
def export_to_file(passphrase)
file_path = "config/shops.json"
aes_key, aes_iv = export_key(passphrase)
tmpHash = {
tmpHash = {
"lookup" => passphrase,
"value" =>
{
@@ -40,27 +40,20 @@ class MyAesCrypt
}
shop_data = File.read(file_path)
if shop_data != ""
shop_json = JSON.parse(shop_data)
shop_json.each do |j|
byebug
if j == passphrase
j.each do |k|
return k["key"], k["iv"]
end
end
shop_json = JSON.parse(shop_data)
shop_json["data"].each do |j|
if j["lookup"] == passphrase
return j["value"]["key"], j["value"]["iv"]
end
shop_json << tmpHash
File.open(file_path, "w") { |io|
io.puts JSON.pretty_generate(shop_json)
}
else
File.open(file_path, "w") { |io|
io.write(tmpHash.to_json)
}
end
shop_json["data"] << tmpHash
File.open(file_path, "w") { |io|
io.puts JSON.pretty_generate(shop_json)
}
return aes_key, aes_iv
end