update multi_tenancy/license
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Api::ShopsController < Api::ApiController
|
class Api::ShopsController < Api::ApiController
|
||||||
skip_before_action :set_current_tenant_by_subdomain_or_first, only: [:index, :show]
|
skip_before_action :set_current_tenant_by_subdomain_or_name, only: [:index, :show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@shops = Shop.select('id,logo,name,shop_code,address,phone_no').all
|
@shops = Shop.select('id,logo,name,shop_code,address,phone_no').all
|
||||||
|
|||||||
@@ -2,32 +2,32 @@ module LicenseVerification
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
before_action :lookup_domain
|
before_action :lookup_domain
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def lookup_domain
|
def lookup_domain
|
||||||
if request.subdomain.present? && request.subdomain != "www"
|
if request.subdomain.present? && request.subdomain != "www"
|
||||||
from = request.subdomain.downcase + "." + request.domain.downcase
|
from = request.subdomain.downcase + "." + request.domain.downcase
|
||||||
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
|
@license = cache_license(ENV["SX_PROVISION_URL"], from) # 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))
|
||||||
# authenticate_session_token
|
# authenticate_session_token
|
||||||
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
||||||
else
|
else
|
||||||
# reconnect_default_db
|
# reconnect_default_db
|
||||||
logger.info 'License is nil'
|
logger.info 'License is nil'
|
||||||
# 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
|
||||||
else
|
else
|
||||||
# check for license file
|
# check for license file
|
||||||
# if check_license
|
# if check_license
|
||||||
# current_license(ENV["SX_PROVISION_URL"])
|
# current_license(ENV["SX_PROVISION_URL"])
|
||||||
# else
|
# else
|
||||||
# redirect_to activate_path
|
# redirect_to activate_path
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -41,27 +41,27 @@ module LicenseVerification
|
|||||||
if @user
|
if @user
|
||||||
return true
|
return true
|
||||||
#Maybe log - login?
|
#Maybe log - login?
|
||||||
else
|
else
|
||||||
flash[:notice] = 'Invalid Access!'
|
flash[:notice] = 'Invalid Access!'
|
||||||
# return false
|
# return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_license(url)
|
def current_license(url)
|
||||||
@license = License.new(url)
|
@license = License.new(url)
|
||||||
flag = @license.detail_with_local_file()
|
flag = @license.detail_with_local_file()
|
||||||
if (flag == 0)
|
if (flag == 0)
|
||||||
flash[:notice] = 'Expired or No License!'
|
flash[:notice] = 'Expired or No License!'
|
||||||
elsif (flag == 2)
|
elsif (flag == 2)
|
||||||
flash[:notice] = 'Expiring! Please, License extend...'
|
flash[:notice] = 'Expiring! Please, License extend...'
|
||||||
else
|
else
|
||||||
Rails.logger.info "License successed"
|
Rails.logger.info "License successed"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_license(url, lookup)
|
def cache_license(url, lookup)
|
||||||
@license = License.new(url, lookup)
|
@license = License.new(url, lookup)
|
||||||
|
|
||||||
if (@license.detail_with_local_cache(lookup) == true)
|
if (@license.detail_with_local_cache(lookup) == true)
|
||||||
return @license
|
return @license
|
||||||
@@ -84,4 +84,4 @@ module LicenseVerification
|
|||||||
def default_connection
|
def default_connection
|
||||||
@default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup
|
@default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,20 +3,26 @@ module MultiTenancy
|
|||||||
|
|
||||||
included do
|
included do
|
||||||
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
|
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
|
||||||
before_action :set_current_tenant_by_subdomain_or_first if respond_to? :before_action
|
before_action :set_current_tenant_by_subdomain_or_name if respond_to? :before_action
|
||||||
helper_method :current_shop if respond_to? :helper_method
|
helper_method :current_shop if respond_to? :helper_method
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def set_current_tenant_by_subdomain_or_first
|
def set_current_tenant_by_subdomain_or_name
|
||||||
find_tenant_by_subdomain_or_frist || not_found
|
find_tenant_by_subdomain_or_name || not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_tenant_by_subdomain_or_frist
|
def find_tenant_by_subdomain_or_name
|
||||||
if request.subdomains.last && request.subdomains.last != "www"
|
if request.subdomains.last && request.subdomains.last != "www"
|
||||||
set_current_tenant(Shop.find_by(subdomain: request.subdomains.last))
|
set_current_tenant(Shop.find_by(subdomain: request.subdomains.last))
|
||||||
elsif ENV["SERVER_MODE"] == "application"
|
elsif ENV["SERVER_MODE"] == "application"
|
||||||
set_current_tenant(Shop.first)
|
license = License.new(ENV["SX_PROVISION_URL"], request.host)
|
||||||
|
shop_name = license.read_license_no_decrypt("shop_name")
|
||||||
|
if Rails.env.production? || shop_name
|
||||||
|
set_current_tenant(Shop.find_by(name: shop_name))
|
||||||
|
else
|
||||||
|
set_current_tenant(Shop.first)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class InstallController < BaseController
|
class InstallController < BaseController
|
||||||
skip_before_action :set_current_tenant_by_subdomain_or_first
|
skip_before_action :set_current_tenant_by_subdomain_or_name
|
||||||
skip_before_action :verify_authenticity_token
|
skip_before_action :verify_authenticity_token
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -219,26 +219,22 @@ class License
|
|||||||
|
|
||||||
# read line by key for license file
|
# read line by key for license file
|
||||||
def read_license(key_name)
|
def read_license(key_name)
|
||||||
decrypted_line = ""
|
|
||||||
key, iv = get_redis_key()
|
key, iv = get_redis_key()
|
||||||
|
|
||||||
if File.exist?("config/license.yml")
|
if File.exist?("config/license.yml")
|
||||||
if license = YAML.load(File.read("config/license.yml"))
|
if license = YAML.load(File.read("config/license.yml"))
|
||||||
decrypted_line = AESCrypt.decrypt_data(decode_str(license[lookup][key_name]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
AESCrypt.decrypt_data(decode_str(license[lookup][key_name]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return decrypted_line
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# read line by key for license file without decrypt
|
# read line by key for license file without decrypt
|
||||||
def read_license_no_decrypt(key)
|
def read_license_no_decrypt(key)
|
||||||
decrypted_line = ""
|
|
||||||
if File.exist?("config/license.yml")
|
if File.exist?("config/license.yml")
|
||||||
if license = YAML.load_file("config/license.yml")
|
if license = YAML.load_file("config/license.yml")
|
||||||
decrypted_line = license[lookup][key]
|
decrypted_line = license[lookup][key]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return decrypted_line
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update license file for line
|
# Update license file for line
|
||||||
@@ -255,11 +251,6 @@ class License
|
|||||||
|
|
||||||
# To write changes to the file, use:
|
# To write changes to the file, use:
|
||||||
File.open("config/license.yml", "w") {|file| file.write(license.to_yaml) }
|
File.open("config/license.yml", "w") {|file| file.write(license.to_yaml) }
|
||||||
|
|
||||||
# File.open("config/license.yml").each do |line|
|
|
||||||
# new_file_str = line.gsub(content, crypted_str)
|
|
||||||
# f.put
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -306,6 +297,7 @@ class License
|
|||||||
redis = Redis.new
|
redis = Redis.new
|
||||||
cache_shop = redis.get(cache_key)
|
cache_shop = redis.get(cache_key)
|
||||||
|
|
||||||
|
puts Marshal.load(cache_shop)
|
||||||
if !cache_shop.nil?
|
if !cache_shop.nil?
|
||||||
@shop = Marshal.load(cache_shop)
|
@shop = Marshal.load(cache_shop)
|
||||||
key = @shop["key"]
|
key = @shop["key"]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class ActionController::Base
|
class ActionController::Base
|
||||||
before_action :lookup_domain, :set_locale
|
before_action :lookup_domain if Rails.env.production?
|
||||||
|
before_action :set_locale
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@ class ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
class ActionController::API
|
class ActionController::API
|
||||||
before_action :lookup_domain
|
before_action :lookup_domain if Rails.env.production?
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ namespace :shop do
|
|||||||
|
|
||||||
|
|
||||||
#Create Adminstrator employee
|
#Create Adminstrator employee
|
||||||
ActiveRecord::Base.connection.execute("INSERT INTO employees(name,role,password_digest,emp_id,created_by,shop_code,created_at,updated_at,app_id,app_token) VALUES ('Administrator','administrator','$2a$10$OKFA4b4yh0xCJNmzjMMijusnO712LUSEL4/y56p2XmdKBRPWgXwDa','999','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Cashier','cashier','$2a$10$rXWBQro.YqUu5klH9oxqA.vcdq7webHm75FeXylY4uoJlek82luOq','333','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Manager','manager','$2a$10$JmzePPoejam8alpR6hrjr.8jIe/pm36IhErtoP4WwK788x2JfHUL2','777','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Application','application','$2a$12$Kzr5OIFb7B7KU52iKNoeSu5LnXtfJx0YX3s3d.HHJzxeodCv31Ehm','444','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(), '#{SecureRandom.urlsafe_base64(nil, false)}', '#{SecureRandom.hex(10)}');")
|
ActiveRecord::Base.connection.execute("INSERT INTO employees(name,role,password_digest,emp_id,created_by,shop_code,created_at,updated_at,app_id,app_token) VALUES ('Administrator','administrator','$2a$10$OKFA4b4yh0xCJNmzjMMijusnO712LUSEL4/y56p2XmdKBRPWgXwDa','999','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Cashier','cashier','$2a$10$rXWBQro.YqUu5klH9oxqA.vcdq7webHm75FeXylY4uoJlek82luOq','333','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Manager','manager','$2a$10$JmzePPoejam8alpR6hrjr.8jIe/pm36IhErtoP4WwK788x2JfHUL2','777','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL);")
|
||||||
Rails.logger.info " Finished Create Adminstrator employee Set Up Data"
|
Rails.logger.info " Finished Create Adminstrator employee Set Up Data"
|
||||||
|
|
||||||
#PrintSetting
|
#PrintSetting
|
||||||
|
|||||||
Reference in New Issue
Block a user