class ActionController::Base before_action :lookup_domain, :set_locale private def lookup_domain 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)) # authenticate_session_token # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema 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!'}] end elsif request.subdomains.last && request.subdomains.last != "www" || ENV["SERVER_MODE"] == "application" # check for license file 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 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 Rails.logger.info "Run License" end end def cache_license(url, lookup) @license = License.new(url, lookup) if (@license.detail_with_local_cache(lookup) == true) return @license else return nil end end def check_license(lookup) License.check_license_file(lookup) end def check_installation if current_company.nil? redirect_to install_path 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 ActiveRecord::Base.establish_connection(Rails.env) end # Regular database.yml configuration hash def default_connection @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup end #change locallization def set_locale I18n.locale = params[:locale] || I18n.default_locale end # RESTful url for localize def default_url_options { locale: I18n.locale } end end class ActionController::API before_action :lookup_domain private def lookup_domain 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)) # authenticate_session_token # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema 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!'}] end end end def cache_license(url, lookup) @license = License.new(url, lookup) if (@license.detail_with_local_cache(lookup) == true) return @license else return nil 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 ActiveRecord::Base.establish_connection(Rails.env) end # Regular database.yml configuration hash def default_connection @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup end #change locallization def set_locale I18n.locale = params[:locale] || I18n.default_locale end # RESTful url for localize def default_url_options { locale: I18n.locale } end end