license key api for redis

This commit is contained in:
Yan
2018-01-12 15:07:11 +06:30
parent 0eda7543ff
commit 649711f72d
7 changed files with 57 additions and 10 deletions

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -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 => "<h1>Success!</h1>"
else
render :text => "<h1>Not Get!</h1>"
end
end
end

View File

@@ -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

View File

@@ -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

View File

@@ -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