Merge branch 'r-1902001-01' into foodcourt
This commit is contained in:
@@ -27,7 +27,7 @@ class License
|
||||
end
|
||||
|
||||
# For Cloud
|
||||
def detail_with_local_cache(lookup)
|
||||
def detail_with_local_cache
|
||||
aes = MyAesCrypt.new
|
||||
aes_key, aes_iv = aes.export_to_file(lookup)
|
||||
|
||||
@@ -75,21 +75,14 @@ class License
|
||||
end
|
||||
|
||||
# For Local System
|
||||
def detail_with_local_file()
|
||||
renewal_date_str = read_license("renewable_date")
|
||||
if check_expiring(renewal_date_str)
|
||||
# return for all ok
|
||||
return 1
|
||||
def detail_with_local_file
|
||||
if expired?
|
||||
return 0
|
||||
elsif expire_in?(10)
|
||||
return 2
|
||||
else
|
||||
has_license = verify_license()
|
||||
if has_license
|
||||
# return for expiring
|
||||
return 2
|
||||
else
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
||||
# License Activation
|
||||
@@ -99,42 +92,58 @@ class License
|
||||
aes_key, aes_iv = aes.export_key(license_key)
|
||||
|
||||
@params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } }
|
||||
response = self.class.get("/activate", @params)
|
||||
@activate = response.parsed_response
|
||||
|
||||
if (@activate["status"])
|
||||
begin
|
||||
response = self.class.get("/activate", @params)
|
||||
@activate = response.parsed_response
|
||||
|
||||
##Check from local redis - if available load local otherwise get from remote
|
||||
cache_key = "shop:#{@activate["shop_name"]}"
|
||||
if (@activate["status"])
|
||||
|
||||
##Get redis connection from connection pool
|
||||
# redis = Redis.new
|
||||
# cache_license = redis.get(cache_key)
|
||||
##Check from local redis - if available load local otherwise get from remote
|
||||
cache_key = "shop:#{@activate["shop_name"]}"
|
||||
|
||||
Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
##Get redis connection from connection pool
|
||||
# redis = Redis.new
|
||||
# cache_license = redis.get(cache_key)
|
||||
|
||||
# if cache_license.nil?
|
||||
cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] }
|
||||
redis = Redis.new
|
||||
redis.set(cache_key, Marshal.dump(cache))
|
||||
# end
|
||||
Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
|
||||
Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
# if cache_license.nil?
|
||||
cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] }
|
||||
redis = Redis.new
|
||||
redis.set(cache_key, Marshal.dump(cache))
|
||||
# end
|
||||
|
||||
response = create_license_file(@activate)
|
||||
Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
|
||||
if(response[:status])
|
||||
#sym_path = "/home/user/symmetric/"
|
||||
sym_path = File.expand_path("~/symmetric/")
|
||||
|
||||
response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password)
|
||||
response = create_license_file(@activate)
|
||||
|
||||
if(response[:status])
|
||||
response = run_symmetric(sym_path)
|
||||
#sym_path = "/home/user/symmetric/"
|
||||
sym_path = File.expand_path("~/symmetric/")
|
||||
|
||||
response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password)
|
||||
|
||||
if(response[:status])
|
||||
response = run_symmetric(sym_path)
|
||||
end
|
||||
end
|
||||
else
|
||||
response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"}
|
||||
end
|
||||
else
|
||||
response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"}
|
||||
|
||||
rescue SocketError => e
|
||||
Rails.logger.debug "In SocketError No Internet connection !"
|
||||
response = { "status": false, "message": "In SocketError No Internet connection !"}
|
||||
rescue HTTParty::Error
|
||||
Rails.logger.debug "Server Error HTTParty"
|
||||
response = { "status": false, "message": "Server Error HTTParty"}
|
||||
rescue Net::OpenTimeout
|
||||
Rails.logger.debug "connection Timeout"
|
||||
response = { "status": false, "message": "Connection Timeout"}
|
||||
rescue OpenURI::HTTPError
|
||||
Rails.logger.debug "Can't connect server"
|
||||
response = { "status": false, "message": "Can't connect server"}
|
||||
end
|
||||
return response
|
||||
end
|
||||
@@ -144,39 +153,50 @@ class License
|
||||
@params = { query: {lookup_type: "application", api_token: api_token} }
|
||||
|
||||
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 (!check_expired(@varified["renewable_date"]))
|
||||
return true
|
||||
end
|
||||
else
|
||||
delete_license_file
|
||||
response = self.class.get("/verify", @params)
|
||||
@varified = response.parsed_response
|
||||
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
|
||||
if (@varified["status"])
|
||||
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'])
|
||||
return true
|
||||
end
|
||||
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
|
||||
|
||||
# Check Expired before 30 days
|
||||
def check_expiring(renewal_date_str)
|
||||
if !renewal_date_str.empty?
|
||||
def expired?
|
||||
if renewal_date_str = read_license("renewable_date")
|
||||
renewal_date = DateTime.parse(renewal_date_str)
|
||||
renewal_date > Date.today.advance(:days => 30)
|
||||
renewal_date < Date.today
|
||||
end
|
||||
end
|
||||
|
||||
def expire_in?(days)
|
||||
if renewal_date_str = read_license("renewable_date")
|
||||
renewal_date = DateTime.parse(renewal_date_str)
|
||||
renewal_date < days.days.from_now
|
||||
end
|
||||
end
|
||||
|
||||
def days_to_expire
|
||||
if renewal_date_str = read_license("renewable_date")
|
||||
Date.today - DateTime.parse(renewal_date_str).to_date
|
||||
end
|
||||
end
|
||||
|
||||
@@ -195,13 +215,14 @@ class License
|
||||
end
|
||||
end
|
||||
|
||||
def check_license_subdomain(lookup)
|
||||
def check_license_subdomain
|
||||
aes = MyAesCrypt.new
|
||||
aes_key, aes_iv = aes.export_key(lookup)
|
||||
|
||||
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
|
||||
@@ -209,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
|
||||
@@ -228,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'])
|
||||
@@ -252,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