license
This commit is contained in:
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
|
|||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
# lookup domain for db from provision
|
# lookup domain for db from provision
|
||||||
before_action :lookup_domain, :set_locale
|
before_action :check_license, :lookup_domain, :set_locale
|
||||||
|
|
||||||
helper_method :current_company,:current_login_employee,:current_user
|
helper_method :current_company,:current_login_employee,:current_user
|
||||||
# alias_method :current_user, :current_login_employee,:current_user
|
# alias_method :current_user, :current_login_employee,:current_user
|
||||||
@@ -94,10 +94,9 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
def check_license
|
def check_license
|
||||||
# if current_company.nil?
|
if License.check_license_file
|
||||||
# redirect_to install_path
|
|
||||||
# end
|
else
|
||||||
if !File.directory?("/config/license.yml")
|
|
||||||
redirect_to install_path
|
redirect_to install_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ require 'uri'
|
|||||||
class AESEncDec {
|
class AESEncDec {
|
||||||
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||||
|
|
||||||
def export_key
|
def self.export_key
|
||||||
ENV['aes_key'] = cipher.key = cipher.random_key # stores the key in key, and also sets the generated key on the cipher
|
ENV['aes_key'] = cipher.key = cipher.random_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
|
||||||
end
|
end
|
||||||
|
|
||||||
def encrypt(data)
|
def self.encrypt(data)
|
||||||
cipher.encrypt
|
cipher.encrypt
|
||||||
cipher.key = ENV["aes_key"]
|
cipher.key = ENV["aes_key"]
|
||||||
cipher.iv = ENV["aes_iv"]
|
cipher.iv = ENV["aes_iv"]
|
||||||
@@ -19,13 +19,13 @@ class AESEncDec {
|
|||||||
return encrypted
|
return encrypted
|
||||||
end
|
end
|
||||||
|
|
||||||
def decrypt
|
def self.decrypt(data)
|
||||||
cipher.decrypt
|
cipher.decrypt
|
||||||
cipher.key = ENV["aes_key"]
|
cipher.key = ENV["aes_key"]
|
||||||
cipher.iv = ENV["aes_iv"]
|
cipher.iv = ENV["aes_iv"]
|
||||||
|
|
||||||
# Start the decryption
|
# Start the decryption
|
||||||
decoded = Base64.urlsafe_decode64(encrypted)
|
decoded = Base64.urlsafe_decode64(data)
|
||||||
decrypted = cipher.update(decoded) + cipher.final
|
decrypted = cipher.update(decoded) + cipher.final
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,10 @@ class License
|
|||||||
self.class.base_uri server
|
self.class.base_uri server
|
||||||
end
|
end
|
||||||
|
|
||||||
@secret = SecureRandom.hex(10)
|
# generate key for license file encrypt
|
||||||
|
AESCrypt.export_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
|
||||||
|
|
||||||
@@ -31,6 +34,10 @@ class License
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.check_license_file
|
||||||
|
return File.exist?("config/license.yml")
|
||||||
|
end
|
||||||
|
|
||||||
def detail_with_local_cache(lookup, key)
|
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"
|
||||||
@@ -50,7 +57,7 @@ class License
|
|||||||
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: { device: "SXlite", token: SECRETS_CONFIG['license_key']} }
|
@params = { query: { lookup_type: "cloud", lookup: "subdomain", token: SECRETS_CONFIG['license_key']} }
|
||||||
|
|
||||||
response = self.class.get("/request_license", @params)
|
response = self.class.get("/request_license", @params)
|
||||||
@license = response.parsed_response
|
@license = response.parsed_response
|
||||||
@@ -106,7 +113,7 @@ class License
|
|||||||
|
|
||||||
def check_remote_license(license_key)
|
def check_remote_license(license_key)
|
||||||
# @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} }
|
# @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} }
|
||||||
@options = { query: {device: "SX", key: license_key, skey: @secret, token: SECRETS_CONFIG['provision_key']} }
|
@options = { query: {lookup_type: "application", encrypted_key: @secret, token: SECRETS_CONFIG['provision_key']} }
|
||||||
response = self.class.get("/license", @options)
|
response = self.class.get("/license", @options)
|
||||||
|
|
||||||
@license = response.parsed_response
|
@license = response.parsed_response
|
||||||
|
|||||||
0
config/initializers/license.rb
Executable file → Normal file
0
config/initializers/license.rb
Executable file → Normal file
0
config/license.yml
Executable file → Normal file
0
config/license.yml
Executable file → Normal file
Reference in New Issue
Block a user