|
|
|
|
@@ -43,7 +43,7 @@ class License
|
|
|
|
|
if cache_license.nil?
|
|
|
|
|
##change the d/e key
|
|
|
|
|
# @options = { query: {device: "SXlite", lookup: lookup, skey: @secret, token: SECRETS_CONFIG['provision_key']} }
|
|
|
|
|
@params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} }
|
|
|
|
|
@params = { query: { lookup_type: self.server_mode, lookup: lookup, iv_key: iv} }
|
|
|
|
|
response = self.class.get("/subdomain", @params)
|
|
|
|
|
@license = response.parsed_response
|
|
|
|
|
|
|
|
|
|
@@ -83,18 +83,17 @@ class License
|
|
|
|
|
|
|
|
|
|
# License Activation
|
|
|
|
|
def license_activate (key, iv, license_key, db_host, db_schema, db_user, db_password)
|
|
|
|
|
@params = { query: { lookup_type: self.server_mode, encrypted_key: key, iv_key: iv, license_key: license_key } }
|
|
|
|
|
@params = { query: { lookup_type: self.server_mode, iv_key: iv, license_key: license_key } }
|
|
|
|
|
response = self.class.get("/activate", @params)
|
|
|
|
|
@activate = response.parsed_response
|
|
|
|
|
|
|
|
|
|
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
|
|
|
|
|
|
|
|
|
|
if (@activate["status"])
|
|
|
|
|
response = create_license_file(@activate)
|
|
|
|
|
if(response["status"])
|
|
|
|
|
if(response[:status])
|
|
|
|
|
sym_path = "/home/yan/symmetric/"
|
|
|
|
|
response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password)
|
|
|
|
|
if(response["status"])
|
|
|
|
|
if(response[:status])
|
|
|
|
|
response = run_symmetric(sym_path)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -136,12 +135,12 @@ class License
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# read line by key for license file
|
|
|
|
|
def read_license(key)
|
|
|
|
|
def read_license(key)
|
|
|
|
|
decrypted_line = ""
|
|
|
|
|
if File.exist?("config/license.yml")
|
|
|
|
|
File.open("config/license.yml").each do |line|
|
|
|
|
|
if line.include? (key)
|
|
|
|
|
decrypted_line_array = line.split(":")
|
|
|
|
|
decrypted_line_array = line.split(": ")
|
|
|
|
|
decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE'])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -162,20 +161,20 @@ class License
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
# Licese File Creation
|
|
|
|
|
f = File.open("config/license.yml", "w")
|
|
|
|
|
f.write("iv_key: #{response_data['iv_key']}\n")
|
|
|
|
|
f.write("shop_name: #{response_data['shop_name']}\n")
|
|
|
|
|
f.write("email: #{response_data['email']}\n")
|
|
|
|
|
f.write("telephone: #{response_data['telephone']}\n")
|
|
|
|
|
f.write("fax: #{response_data['fax']}\n")
|
|
|
|
|
f.write("address: #{response_data['address']}\n")
|
|
|
|
|
f.write("dbhost: #{response_data['dbhost']}\n")
|
|
|
|
|
f.write("dbschema: #{response_data['dbschema']}\n")
|
|
|
|
|
f.write("dbusername: #{response_data['dbusername']}\n")
|
|
|
|
|
f.write("dbpassword: #{response_data['dbpassword']}\n")
|
|
|
|
|
f.write("api_token: #{response_data['api_token']}\n")
|
|
|
|
|
f.write("app_token: #{response_data['app_token']}\n")
|
|
|
|
|
f.close
|
|
|
|
|
File.open("config/license.yml", "w") do |f|
|
|
|
|
|
f.puts("iv_key: #{response_data['iv_key']}")
|
|
|
|
|
f.puts("shop_name: #{response_data['shop_name']}")
|
|
|
|
|
f.puts("email: #{response_data['email']}")
|
|
|
|
|
f.puts("telephone: #{response_data['telephone']}")
|
|
|
|
|
f.puts("fax: #{response_data['fax']}")
|
|
|
|
|
f.puts("address: #{response_data['address']}")
|
|
|
|
|
f.puts("dbhost: #{response_data['dbhost']}")
|
|
|
|
|
f.puts("dbschema: #{response_data['dbschema']}")
|
|
|
|
|
f.puts("dbusername: #{response_data['dbusername']}")
|
|
|
|
|
f.puts("dbpassword: #{response_data['dbpassword']}")
|
|
|
|
|
f.puts("api_token: #{response_data['api_token']}")
|
|
|
|
|
f.puts("app_token: #{response_data['app_token']}")
|
|
|
|
|
end
|
|
|
|
|
rescue IOError
|
|
|
|
|
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
|
|
|
|
|
end
|
|
|
|
|
@@ -237,18 +236,19 @@ class License
|
|
|
|
|
|
|
|
|
|
# Run Symmetric
|
|
|
|
|
def run_symmetric(sym_path)
|
|
|
|
|
check_sym_proc_str = `#{sym_path + "bin/sym_service status"}`
|
|
|
|
|
check_sym_proc_str = check_sym_proc_str.split("\n")
|
|
|
|
|
sym_install_status = check_sym_proc_str[0].split(": ")
|
|
|
|
|
# sym_run_status = check_sym_proc_str[1].split(": ")
|
|
|
|
|
# check_sym_proc_str = `#{sym_path + "bin/sym_service status"}`
|
|
|
|
|
# check_sym_proc_str = check_sym_proc_str.split("\n")
|
|
|
|
|
# sym_install_status = check_sym_proc_str[0].split(": ")
|
|
|
|
|
|
|
|
|
|
check_sym_proc_str = `#{"service SymmetricDS status"}`
|
|
|
|
|
|
|
|
|
|
# Check Sym Installed
|
|
|
|
|
if sym_install_status[1] == "false"
|
|
|
|
|
response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"}
|
|
|
|
|
end
|
|
|
|
|
# if sym_install_status[1] == "false"
|
|
|
|
|
# response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"}
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# Run Sym Service
|
|
|
|
|
sym_run_status = check_sym_running(check_sym_proc_str[1], sym_path)
|
|
|
|
|
sym_run_status = check_sym_running(check_sym_proc_str, sym_path)
|
|
|
|
|
if sym_run_status
|
|
|
|
|
# Create Sym Table
|
|
|
|
|
check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables")
|
|
|
|
|
@@ -272,18 +272,23 @@ class License
|
|
|
|
|
# Check Symmetric Running
|
|
|
|
|
def check_sym_running(status, sym_path)
|
|
|
|
|
# Run Sym Service
|
|
|
|
|
if status.include? "Server is already running"
|
|
|
|
|
# if status.include? "Server is already running"
|
|
|
|
|
# return true
|
|
|
|
|
# elsif status.include? "false"
|
|
|
|
|
# sym_start_str = `#{sym_path + "bin/sym_service start"}`
|
|
|
|
|
# if sym_start_str.include? "Started"
|
|
|
|
|
# return true
|
|
|
|
|
# else
|
|
|
|
|
# check_sym_running(sym_start_status[0])
|
|
|
|
|
# end
|
|
|
|
|
# else
|
|
|
|
|
# return true
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
if status.include? "Active: active (running)" #"Server is already running"
|
|
|
|
|
return true
|
|
|
|
|
elsif status.include? "false"
|
|
|
|
|
sym_start_str = `#{sym_path + "bin/sym_service start"}`
|
|
|
|
|
if sym_start_str.include? "Started"
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
check_sym_running(sym_start_status[0])
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Delete License File
|
|
|
|
|
@@ -318,7 +323,7 @@ class License
|
|
|
|
|
|
|
|
|
|
key = Base64.decode64(ENV['AES_KEY'])
|
|
|
|
|
iv = Base64.decode64(ENV['AES_IV'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] )
|
|
|
|
|
host = Base64.decode64(@license["dbhost"])
|
|
|
|
|
dbschema = Base64.decode64(@license["dbschema"])
|
|
|
|
|
|