From 746bbcf7a343f2205710db00b9ac7ce07d4c4a36 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 10 Feb 2020 14:47:19 +0630 Subject: [PATCH] fix licnese --- config/initializers/action_controller.rb | 41 ++++++++++++++---------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index eb7ba401..48184216 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -1,12 +1,12 @@ class ActionController::Base - before_action :lookup_domain, :set_locale + before_action :lookup_domain if Rails.env.production? + before_action :set_locale private def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - from = request.subdomain.downcase + "." + request.domain.downcase - @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase + if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_MODE"] == "cloud" + @license = cache_license(ENV["SX_PROVISION_URL"], request.host) # request.subdomain.downcase if (!@license.nil?) logger.info "Location - " + @license.dbschema ActiveRecord::Base.establish_connection(website_connection(@license)) @@ -18,26 +18,34 @@ class ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end - else + elsif request.subdomains.last && request.subdomains.last != "www" || ENV["SERVER_MODE"] == "application" # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) + if check_license(request.host) + current_license(ENV["SX_PROVISION_URL"], request.host) else redirect_to activate_path end + else + not_found end - end - def current_license(url) - @license = License.new(url) + def not_found + respond_to do |format| + format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found } + format.json { head :not_found } + end + end + + def current_license(url, lookup) + @license = License.new(url, lookup) flag = @license.detail_with_local_file() if (flag == 0) flash[:notice] = 'Expired or No License!' elsif (flag == 2) flash[:notice] = 'Expiring! Please, License extend...' else - puts "RUN SAY BYAR" + Rails.logger.info "Run License" end end @@ -51,8 +59,8 @@ class ActionController::Base end end - def check_license - License.check_license_file + def check_license(lookup) + License.check_license_file(lookup) end def check_installation @@ -89,14 +97,13 @@ class ActionController::Base end class ActionController::API - before_action :lookup_domain + before_action :lookup_domain if Rails.env.production? private def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - from = request.subdomain.downcase + "." + request.domain.downcase - @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase + if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] == "cloud" + @license = cache_license(ENV["SX_PROVISION_URL"], request.host) # request.subdomain.downcase if (!@license.nil?) logger.info "Location - " + @license.dbschema ActiveRecord::Base.establish_connection(website_connection(@license))