update license
This commit is contained in:
@@ -151,47 +151,35 @@ class License
|
||||
def verify_license
|
||||
api_token = read_license_no_decrypt("api_token")
|
||||
@params = { query: {lookup_type: "application", api_token: api_token} }
|
||||
old_renewable_date = read_license("renewable_date")
|
||||
|
||||
begin
|
||||
response = self.class.get("/verify", @params)
|
||||
@varified = response.parsed_response
|
||||
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
|
||||
if (@varified["status"])
|
||||
if old_renewable_date.to_date == @varified['renewable_date'].to_date
|
||||
message = "*** License can't be verified. ***"
|
||||
status = 2
|
||||
elsif old_renewable_date.to_date < @varified['renewable_date'].to_date
|
||||
old_renewable_date = read_license("renewable_date")
|
||||
if old_renewable_date.to_date < @varified['renewable_date'].to_date
|
||||
update_license("renewable_date", @varified['renewable_date'])
|
||||
status = 1
|
||||
message = "*** License con be verified. ***"
|
||||
return true
|
||||
end
|
||||
return status, message
|
||||
|
||||
else
|
||||
delete_license_file
|
||||
|
||||
stauts = 0
|
||||
message = "*** Your license has been expired. ***"
|
||||
return status, message
|
||||
end
|
||||
|
||||
rescue SocketError => e
|
||||
Rails.logger.debug "In SocketError No Internet connection ! "
|
||||
return true
|
||||
rescue HTTParty::Error
|
||||
Rails.logger.debug "Server Error HTTParty"
|
||||
return true
|
||||
rescue Net::OpenTimeout
|
||||
Rails.logger.debug "connection Timeout"
|
||||
return true
|
||||
rescue OpenURI::HTTPError
|
||||
Rails.logger.debug "Can't connect server"
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def exists?
|
||||
License.check_license_file(lookup)
|
||||
end
|
||||
|
||||
def expired?
|
||||
if renewal_date_str = read_license("renewable_date")
|
||||
renewal_date = DateTime.parse(renewal_date_str)
|
||||
@@ -234,6 +222,7 @@ class License
|
||||
params = { query: { lookup_type: "cloud", lookup: lookup, iv_key: aes_iv} }
|
||||
response = self.class.get("/subdomain", params)
|
||||
response.parsed_response["status"]
|
||||
rescue
|
||||
end
|
||||
|
||||
# Check License File exists
|
||||
@@ -241,15 +230,21 @@ class License
|
||||
return unless File.exist?("config/license.yml")
|
||||
if license = YAML.load_file("config/license.yml")
|
||||
if license[lookup].nil?
|
||||
if ENV["SERVER_MODE"] == "application"
|
||||
license[lookup] = license.values.first
|
||||
|
||||
if license['iv_key']
|
||||
license = { lookup => license }
|
||||
else
|
||||
tld_length = Rails.application.config.action_dispatch.tld_length
|
||||
subdomains = URL.extract_subdomains(lookup, tld_length)
|
||||
if key = license.keys.find { |k| URL.extract_subdomains(k, tld_length).last == subdomains.last}
|
||||
license[lookup] = license[key]
|
||||
if subdomains.last && subdomains.last != 'www'
|
||||
if key = license.keys.find { |k| URL.extract_subdomains(k, tld_length).last == subdomains.last}
|
||||
license[lookup] = license[key]
|
||||
end
|
||||
else
|
||||
license[lookup] = license.values.first
|
||||
end
|
||||
end
|
||||
|
||||
if license[lookup]
|
||||
File.open("config/license.yml", "w") { |file| file.write license.to_yaml }
|
||||
end
|
||||
@@ -260,9 +255,8 @@ class License
|
||||
|
||||
# read line by key for license file
|
||||
def read_license(key_name)
|
||||
key, iv = get_redis_key()
|
||||
|
||||
if File.exist?("config/license.yml")
|
||||
key, iv = get_redis_key()
|
||||
if license = YAML.load(File.read("config/license.yml"))
|
||||
if license[lookup]
|
||||
AESCrypt.decrypt_data(decode_str(license[lookup][key_name]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
||||
@@ -284,13 +278,12 @@ class License
|
||||
|
||||
# Update license file for line
|
||||
def update_license(content, new_content)
|
||||
key, iv = get_redis_key()
|
||||
|
||||
if !new_content.include? "=="
|
||||
crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
||||
end
|
||||
|
||||
if File.exist?("config/license.yml")
|
||||
key, iv = get_redis_key()
|
||||
|
||||
if !new_content.include? "=="
|
||||
crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
||||
end
|
||||
if license = YAML.load_file("config/license.yml")
|
||||
license[lookup][content] = encode_str(crypted_str)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user