diff --git a/app/models/license.rb b/app/models/license.rb index 961d4e5a..37ed5149 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -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"]) diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index 9cbd77bd..569a401d 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -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