diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 1ff003db..1a08ee41 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,7 +1,6 @@ class InstallController < BaseController - skip_before_action :lookup_domain + skip_before_action :set_current_tenant_by_subdomain_or_first skip_before_action :verify_authenticity_token - # before_action :check_license def index end @@ -9,7 +8,7 @@ class InstallController < BaseController def activate flag = "<%= ENV['AES_IV'] %>" key_base = "<%= ENV['secret_key_base'] %>" - + restaurant = params[:restaurant_name] license_key = params[:license_key] # admin_user = params[:admin_user] @@ -18,20 +17,20 @@ class InstallController < BaseController db_schema = params[:db_schema] db_user = params[:db_user] db_password = params[:db_password] - phrase = license_key - + phrase = license_key + # Check Exists IV # if flag == "<%= ENV['AES_IV'] %>" - # # Export for Key - # aes = MyAesCrypt.new + # # Export for Key + # aes = MyAesCrypt.new # aes_key, aes_iv = aes.export_key(phrase) - # else + # else # aes_key = ENV["AES_KEY"] # aes_iv = ENV["AES_IV"] # end @license = License.new(ENV["SX_PROVISION_URL"]) - response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password) + response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password) if response[:status] redirect_to root_url, notice: response["message"] else @@ -39,28 +38,17 @@ class InstallController < BaseController end end - def check_license - if License.check_license_file - redirect_to root_url + def lookup_domain + if (ENV["SERVER_MODE"] == "application") || + (request.subdomain.present? && request.subdomain != "www" && ENV["SERVER_MODE"] != "cloud") + if check_license(request.host) + redirect_to root_url + end + else + not_found end end - # def lookup_domain - # if request.subdomain.present? && request.subdomain != "www" - # @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) - # if (!@license.nil?) - # # logger.info "Location - " + @license.name - # ActiveRecord::Base.establish_connection(website_connection(@license)) - # # 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 current_license(url, key) # @license = License.new(url, key) diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index d63c9325..25655a91 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -26,11 +26,11 @@ class ActionController::Base redirect_to activate_path end else - render_not_found + not_found end end - def render_not_found + 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 }