diff --git a/Gemfile b/Gemfile
index 90182812..94ed4ef3 100755
--- a/Gemfile
+++ b/Gemfile
@@ -95,6 +95,9 @@ gem 'cancancan', '~> 1.10'
#end
group :development do
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
+ gem 'byebug', platform: :mri
+
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
diff --git a/Gemfile.lock b/Gemfile.lock
index 48c34ea2..1c7e6534 100755
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -53,6 +53,7 @@ GEM
bcrypt (3.1.11)
bindex (0.5.0)
builder (3.2.3)
+ byebug (9.1.0)
cancancan (1.17.0)
capistrano (3.10.1)
airbrussh (>= 1.0.0)
@@ -286,6 +287,7 @@ PLATFORMS
DEPENDENCIES
aescrypt
bcrypt (~> 3.1.7)
+ byebug
cancancan (~> 1.10)
capistrano
capistrano-bundler
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7fafd6bd..3f789fc4 100755
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -38,11 +38,11 @@ class ApplicationController < ActionController::Base
end
else
# check for license file
- # if check_license
- # current_license(ENV["SX_PROVISION_URL"])
- # else
- # redirect_to activate_path
- # end
+ if check_license
+ current_license(ENV["SX_PROVISION_URL"])
+ else
+ redirect_to activate_path
+ end
end
end
diff --git a/app/controllers/sym_control_controller.rb b/app/controllers/sym_control_controller.rb
index 816b8f2c..92d9cedd 100644
--- a/app/controllers/sym_control_controller.rb
+++ b/app/controllers/sym_control_controller.rb
@@ -1,5 +1,6 @@
class SymControlController < BaseController
skip_before_action :verify_authenticity_token
+ http_basic_authenticate_with name: "vip", password: "!abcABC01"
def run
sym_path = "/home/yan/symmetric/"
@@ -32,4 +33,14 @@ class SymControlController < BaseController
end
end
+ def get_key
+ license = License.new(ENV["SX_PROVISION_URL"])
+ status = license.get_key
+ if status
+ render :text => "
Success!
"
+ else
+ render :text => "Not Get!
"
+ end
+ end
+
end
\ No newline at end of file
diff --git a/app/models/license.rb b/app/models/license.rb
index 36ce9b29..4af6059a 100755
--- a/app/models/license.rb
+++ b/app/models/license.rb
@@ -45,7 +45,7 @@ class License
if (@license["status"] == true)
assign(aes_key, aes_iv)
- Rails.logger.info "License - " + response.parsed_response.to_s
+ # Rails.logger.info "License - " + response.parsed_response.to_s
redis = Redis.new
redis.set(cache_key, Marshal.dump(@license))
@@ -106,7 +106,7 @@ class License
redis = Redis.new
cache_license = redis.get(cache_key)
- Rails.logger.info "Cache key - " + cache_key.to_s
+ # Rails.logger.info "Cache key - " + cache_key.to_s
if cache_license.nil?
cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] }
@@ -114,7 +114,7 @@ class License
redis.set(cache_key, Marshal.dump(cache))
end
- Rails.logger.info "License - " + response.parsed_response.to_s
+ # Rails.logger.info "License - " + response.parsed_response.to_s
response = create_license_file(@activate)
if(response[:status])
@@ -136,7 +136,7 @@ class License
response = self.class.get("/verify", @params)
@varified = response.parsed_response
- Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
+ # Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
if (@varified["status"])
if (!check_expired(@varified["plan_next_renewal_date"]))
return true
@@ -227,6 +227,36 @@ class License
# f.put
# end
end
+ end
+
+ # Re-get keys
+ def get_key
+ api_token = read_license_no_decrypt("api_token")
+ shop_name = read_license_no_decrypt("shop_name")
+ @params = { query: {lookup_type: "application", api_token: api_token} }
+ response = self.class.get("/get_key", @params)
+ @data = response.parsed_response
+
+ if (@data["status"])
+ ##Check from local redis - if available load local otherwise get from remote
+ cache_key = "shop:#{shop_name}"
+
+ cache_license = nil
+
+ ##Get redis connection from connection pool
+ redis = Redis.new
+ cache_license = redis.get(cache_key)
+
+ # Rails.logger.info "Cache key - " + cache_key.to_s
+
+ if cache_license.nil?
+ cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["plan_next_renewable_date"] }
+ redis = Redis.new
+ redis.set(cache_key, Marshal.dump(cache))
+ end
+ return true
+ end
+ return false
end
private
diff --git a/config/routes.rb b/config/routes.rb
index 5f57f339..10df301d 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -13,6 +13,7 @@ scope "(:locale)", locale: /en|mm/ do
get 'activate' => 'install#index'
post 'activate' => 'install#activate'
get 'run_sym' => 'sym_control#run'
+ get 'get_key' => 'sym_control#get_key'
#--------- Login/Authentication ------------#
get 'auth/:emp_id' => 'home#show', as: :emp_login
diff --git a/config/secrets.yml b/config/secrets.yml
index 37b1f0b0..04a808fc 100755
--- a/config/secrets.yml
+++ b/config/secrets.yml
@@ -12,7 +12,7 @@
development:
secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61
- sx_provision_url: 192.168.1.49:3002/api #connect.smartsales.asia/api #provision.zsai.ws/api
+ sx_provision_url: connect.smartsales.dev//api #connect.smartsales.asia/api #provision.zsai.ws/api
server_mode: application
cipher_type: AES-256-CBC
sx_key: Wh@t1$C2L