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

View File

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