license
This commit is contained in:
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
# 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
|
||||
# alias_method :current_user, :current_login_employee,:current_user
|
||||
@@ -94,10 +94,9 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
private
|
||||
def check_license
|
||||
# if current_company.nil?
|
||||
# redirect_to install_path
|
||||
# end
|
||||
if !File.directory?("/config/license.yml")
|
||||
if License.check_license_file
|
||||
|
||||
else
|
||||
redirect_to install_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,12 +5,12 @@ require 'uri'
|
||||
class AESEncDec {
|
||||
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_iv'] = cipher.iv = cipher.random_iv # stores the iv in iv, and also sets the generated iv on the cipher
|
||||
end
|
||||
|
||||
def encrypt(data)
|
||||
def self.encrypt(data)
|
||||
cipher.encrypt
|
||||
cipher.key = ENV["aes_key"]
|
||||
cipher.iv = ENV["aes_iv"]
|
||||
@@ -19,13 +19,13 @@ class AESEncDec {
|
||||
return encrypted
|
||||
end
|
||||
|
||||
def decrypt
|
||||
def self.decrypt(data)
|
||||
cipher.decrypt
|
||||
cipher.key = ENV["aes_key"]
|
||||
cipher.iv = ENV["aes_iv"]
|
||||
|
||||
# Start the decryption
|
||||
decoded = Base64.urlsafe_decode64(encrypted)
|
||||
decoded = Base64.urlsafe_decode64(data)
|
||||
decrypted = cipher.update(decoded) + cipher.final
|
||||
end
|
||||
}
|
||||
@@ -19,7 +19,10 @@ class License
|
||||
self.class.base_uri server
|
||||
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'] } }
|
||||
end
|
||||
|
||||
@@ -31,6 +34,10 @@ class License
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_license_file
|
||||
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
|
||||
cache_key = "store:license:#{key}:hostname"
|
||||
@@ -50,7 +57,7 @@ class License
|
||||
if cache_license.nil?
|
||||
##change the d/e 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)
|
||||
@license = response.parsed_response
|
||||
@@ -106,7 +113,7 @@ class License
|
||||
|
||||
def check_remote_license(license_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)
|
||||
|
||||
@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