update license control

This commit is contained in:
Thein Lin Kyaw
2020-06-02 14:23:08 +06:30
parent 51932b8a86
commit da75403437
3 changed files with 244 additions and 153 deletions

View File

@@ -1,58 +1,65 @@
class ActionController::Base
before_action :lookup_domain, :set_locale
before_action :lookup_domain if Rails.env.production?
before_action :set_locale
helper_method :current_license,
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
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 (!@license.nil?)
logger.info "Location - " + @license.dbschema
ActiveRecord::Base.establish_connection(website_connection(@license))
# authenticate_session_token
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
if license = cache_license # request.subdomain.downcase
logger.info "Location - " + license.dbschema
ActiveRecord::Base.establish_connection(website_connection(license))
else
# reconnect_default_db
logger.info 'License is nil'
# redirect_to root_url(:host => request.domain) + "store_error"
render :json => [{ status: false, message: 'Invalid Access!'}]
not_found
end
elsif ENV["SERVER_MODE"] == "application" || request.subdomains.last && request.subdomains.last != "www"
# check for license file
if !check_license
if ENV["SERVER_MODE"] == "application" || check_subdomain
redirect_to activate_path
else
not_found
end
end
else
# check for license file
# if check_license
# current_license(ENV["SX_PROVISION_URL"])
# else
# redirect_to activate_path
# end
end
end
def current_license(url)
@license = License.new(url)
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"
not_found
end
end
def cache_license(url, lookup)
@license = License.new(url, lookup)
def current_license
@license ||= License.new(ENV["SX_PROVISION_URL"], request.host)
end
if (@license.detail_with_local_cache(lookup) == true)
return @license
def cache_license
if (current_license.detail_with_local_cache == true)
return current_license
else
return nil
end
end
def check_subdomain
current_license.check_license_subdomain
end
def check_license
License.check_license_file
if License.check_license_file(request.host)
if current_license.expired?
return false
end
return true
end
end
def check_installation
@@ -64,7 +71,6 @@ class ActionController::Base
def website_connection(license)
default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase,
:username => license.dbusername, :password => license.dbpassword)
end
def reconnect_default_db
@@ -89,42 +95,58 @@ class ActionController::Base
end
class ActionController::API
before_action :lookup_domain
before_action :lookup_domain if Rails.env.production?
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
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 (!@license.nil?)
logger.info "Location - " + @license.dbschema
ActiveRecord::Base.establish_connection(website_connection(@license))
# authenticate_session_token
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
if ENV["SERVER_CODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
if license = cache_license # request.subdomain.downcase
logger.info "Location - " + license.dbschema
ActiveRecord::Base.establish_connection(website_connection(license))
else
# reconnect_default_db
logger.info 'License is nil'
# redirect_to root_url(:host => request.domain) + "store_error"
render :json => [{ status: false, message: 'Invalid Access!'}]
not_found
end
elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www")
not_found unless check_license
else
not_found
end
end
def cache_license(url, lookup)
@license = License.new(url, lookup)
def current_license
@license ||= License.new(ENV["SX_PROVISION_URL"], request.host)
end
if (@license.detail_with_local_cache(lookup) == true)
return @license
def cache_license
if (current_license.detail_with_local_cache == true)
return current_license
else
return nil
end
end
def check_license
if License.check_license_file(request.host)
if current_license.expired?
return false
end
return true
end
end
def website_connection(license)
default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase,
:username => license.dbusername, :password => license.dbpassword)
end
def reconnect_default_db

19
config/license.yml Normal file
View File

@@ -0,0 +1,19 @@
---
'': &1
iv_key: cHmsbixLckobLPvChZxYog==
shop_name: inyahappy
email: support@code2lab.com
telephone: ''
fax: ''
address: ''
dbhost: T78U5MC1QxdtmrveA3dT5znI93KRZgEDv1YEAJLOBuYhF9Okg6IFGds7o0P2Jw0qRCVBAo2mL9zvqCmZ9sIYCQ==
dbschema: QwNWv33nV+/PI7mQ5vUwYpu7oLDVwCFv6E3xLchwDLM=
dbusername: xObcAQiPi19xCQbc0z5buQ==
dbpassword: UIscqcoVMXn4A/OfHnSU6A==
api_token: oHYLdtqtAAacxqAhTMfdVxCRyEkyxLzKcYY
app_token: qVYAxcvsklHlTMEBzgznEqdBZBPI
plan_sku: j3tTAFpFkYP3DNCHSinzqA==
renewable_date: fjyqVnVXXEoyvOVf1Ksa1Q==
plan_name: a3TIsOfLtnkDpqP/FCTjyk/viicooUnN4DJasj4jSF4=
192.168.1.125: *1
192.168.43.132: *1