adding license
This commit is contained in:
@@ -23,8 +23,8 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def lookup_domain
|
def lookup_domain
|
||||||
# if request.subdomain.present? && request.subdomain != "www"
|
if request.subdomain.present? && request.subdomain != "www"
|
||||||
@license = current_license(ENV["SX_PROVISION_URL"], "chromisreal-16") # request.subdomain.downcase
|
@license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) # request.subdomain.downcase
|
||||||
if (!@license.nil?)
|
if (!@license.nil?)
|
||||||
# logger.info "Location - " + @license.name
|
# logger.info "Location - " + @license.name
|
||||||
ActiveRecord::Base.establish_connection(website_connection(@license))
|
ActiveRecord::Base.establish_connection(website_connection(@license))
|
||||||
@@ -35,16 +35,17 @@ class ApplicationController < ActionController::Base
|
|||||||
# redirect_to root_url(:host => request.domain) + "store_error"
|
# redirect_to root_url(:host => request.domain) + "store_error"
|
||||||
render :json => [{ status: false, message: 'Invalid Access!'}]
|
render :json => [{ status: false, message: 'Invalid Access!'}]
|
||||||
end
|
end
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_license(url, key)
|
def current_license(url, key)
|
||||||
@license = License.new(url, key)
|
@license = License.new(url, key)
|
||||||
|
|
||||||
##creating md5 hash
|
# Export for Key
|
||||||
md5_hostname = Digest::MD5.new
|
passphrase = key + ENV["secret_key_base"]
|
||||||
md5key = md5_hostname.update(request.host)
|
key, iv = AESEncDec.export_key(passphrase)
|
||||||
if (@license.detail_with_local_cache(key, md5key.to_s) == true)
|
|
||||||
|
if (@license.detail_with_local_file(key, key, iv) == true)
|
||||||
#if (@license.detail == true)
|
#if (@license.detail == true)
|
||||||
|
|
||||||
return @license
|
return @license
|
||||||
|
|||||||
@@ -5,9 +5,14 @@ require 'uri'
|
|||||||
class AESEncDec {
|
class AESEncDec {
|
||||||
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||||
|
|
||||||
def self.export_key
|
def self.export_key(passphrase)
|
||||||
ENV['aes_key'] = cipher.key = cipher.random_key # stores the key in key, and also sets the generated key on the cipher
|
# We want a 256 bit key symetric key based on passphrase
|
||||||
|
digest = Digest::SHA256.new
|
||||||
|
key = digest.update(passphrase)
|
||||||
|
# key = digest.digest
|
||||||
|
ENV['aes_key'] = cipher.key = key # stores the key in key, and also sets the generated key on the cipher
|
||||||
ENV['aes_iv'] = cipher.iv = cipher.random_iv # stores the iv in iv, and also sets the generated iv on the cipher
|
ENV['aes_iv'] = cipher.iv = cipher.random_iv # stores the iv in iv, and also sets the generated iv on the cipher
|
||||||
|
return cipher.key, cipher.iv
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.encrypt(data)
|
def self.encrypt(data)
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ class License
|
|||||||
end
|
end
|
||||||
|
|
||||||
# generate key for license file encrypt
|
# generate key for license file encrypt
|
||||||
AESEncDec.export_key()
|
# AESEncDec.export_key()
|
||||||
|
|
||||||
@secret = ENV["aes_key"]
|
# @secret = ENV["aes_key"]
|
||||||
@params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } }
|
@params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -34,30 +34,30 @@ class License
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_license_file
|
def detail_with_local_file(lookup, key, iv)
|
||||||
return File.exist?("config/license.yml")
|
|
||||||
end
|
|
||||||
|
|
||||||
def detail_with_local_cache(lookup, key)
|
|
||||||
##Check from local redis - if available load local otherwise get from remote
|
##Check from local redis - if available load local otherwise get from remote
|
||||||
cache_key = "store:license:#{key}:hostname"
|
#cache_key = "store:license:#{key}:hostname"
|
||||||
|
|
||||||
# No Needs for current
|
# No Needs for current
|
||||||
# @secret = key
|
# @secret = key
|
||||||
|
|
||||||
cache_license = nil
|
#cache_license = nil
|
||||||
|
|
||||||
##Get redis connection from connection pool
|
##Get redis connection from connection pool
|
||||||
Redis.current do |conn|
|
#
|
||||||
cache_license = conn.get(cache_key)
|
|
||||||
end
|
|
||||||
|
|
||||||
Rails.logger.info "Cache key - " + cache_key.to_s
|
#Rails.logger.info "Cache key - " + cache_key.to_s
|
||||||
|
|
||||||
|
has_license = check_license_file
|
||||||
|
|
||||||
|
if has_license
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
if cache_license.nil?
|
if cache_license.nil?
|
||||||
##change the d/e key
|
##change the d/e key
|
||||||
# @options = { query: {device: "SXlite", lookup: lookup, skey: @secret, token: SECRETS_CONFIG['provision_key']} }
|
# @options = { query: {device: "SXlite", lookup: lookup, skey: @secret, token: SECRETS_CONFIG['provision_key']} }
|
||||||
@params = { query: { lookup_type: "cloud", lookup: "subdomain", token: SECRETS_CONFIG['license_key']} }
|
@params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} }
|
||||||
|
|
||||||
response = self.class.get("/request_license", @params)
|
response = self.class.get("/request_license", @params)
|
||||||
@license = response.parsed_response
|
@license = response.parsed_response
|
||||||
@@ -95,7 +95,6 @@ class License
|
|||||||
end
|
end
|
||||||
|
|
||||||
def detail
|
def detail
|
||||||
|
|
||||||
response = self.class.get("/subdomain", @options)
|
response = self.class.get("/subdomain", @options)
|
||||||
@license = response.parsed_response
|
@license = response.parsed_response
|
||||||
|
|
||||||
@@ -151,6 +150,10 @@ class License
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def check_license_file
|
||||||
|
return File.exist?("config/license.yml")
|
||||||
|
end
|
||||||
|
|
||||||
def assign
|
def assign
|
||||||
# self.name = @license["name"]
|
# self.name = @license["name"]
|
||||||
# self.address_1 = @license["address_1"]
|
# self.address_1 = @license["address_1"]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
development:
|
development:
|
||||||
server_mode: local
|
server_mode: cloud
|
||||||
license_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk
|
license_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user