added license

This commit is contained in:
Yan
2017-11-16 16:13:26 +06:30
parent b1f98df4e0
commit 178b3484be
10 changed files with 264 additions and 184 deletions

View File

@@ -75,7 +75,7 @@ class License
def detail_with_local_file()
has_license = true #verify_license()
has_license = verify_license()
if has_license
puts "VERIFIED"
@@ -118,7 +118,7 @@ class License
# end
# end
# return false
end
#end
# def detail
# response = self.class.get("/subdomain", @options)
@@ -137,7 +137,7 @@ class License
# end
# License Activation
def license_activate (key, iv, license_key)
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 } }
response = self.class.get("/activate", @params)
@activate = response.parsed_response
@@ -145,10 +145,15 @@ class License
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
if (@activate["status"])
return create_license_file(@activate)
response = create_license_file(@activate)
if(response["status"])
sym_path = "/home/yan/symmetric/engines"
response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password)
end
else
response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"}
end
return response
end
def verify_license
@@ -218,7 +223,7 @@ class License
File.open("config/license.yml").each do |line|
if line.include? (key)
decrypted_line_array = line.split(":")
decrypted_line = AESCrypt.decrypt(decrypted_line_array[1])
decrypted_line = AESCrypt.decrypt_data(decrypted_line_array[1], ENV['AES_KEY'], ENV['AES_IV'], ENV['CIPHER_TYPE'])
end
end
end
@@ -236,7 +241,12 @@ class License
# Licese File Creation
f = File.open("config/license.yml", "w")
f.write("name: #{response_data['name']}\n")
f.write("shopname: #{response_data['shopname']}\n")
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")
@@ -245,9 +255,62 @@ class License
f.write("app_token: #{response_data['app_token']}\n")
f.close
rescue IOError
response = { "status": false, "message": "Can't create license file. Please contact code2lab call center!"}
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
end
response = { "status": true, "message": "Success Activation. License also created."}
end
# Symmetric Configuration
def create_symmetric_config(sym_location, db_host, db_schema, db_user, db_password)
if File.directory? (sym_location)
begin
# sx properties create
f = File.open(sym_location + "/sx.properties", "w")
f.write("engine.name=sx\n")
f.write("db.driver=com.mysql.jdbc.Driver\n")
f.write("db.url=jdbc:mysql://#{db_host}/#{db_schema}?tinyInt1isBit=false\n")
f.write("db.user=#{db_user}\n")
f.write("db.password=#{db_password}\n")
f.write("registration.url=\n")
f.write("sync.url=http://#{db_host}:31415/sync/sx\n")
f.write("group.id=sx\n")
f.write("external.id=000\n")
f.write("job.purge.period.time.ms=7200000\n")
f.write("job.routing.period.time.ms=5000\n")
f.write("job.push.period.time.ms=10000\n")
f.write("job.pull.period.time.ms=10000\n")
f.write("initial.load.create.first=true\n")
f.write("initial.load.use.extract.job.enabled=true\n")
f.close
# read from license file
shop_name = read_license("shop_name")
dbhost = read_license("dbhost")
dbschema = read_license("dbschema")
dbusername = read_license("dbusername")
dbpassword = read_license("dbpassword")
# shop properties create
f = File.open(sym_location + "/#{shop_name}.properties", "w")
f.write("engine.name=#{shop_name}\n")
f.write("db.driver=com.mysql.jdbc.Driver\n")
f.write("db.url=jdbc:mysql://#{dbhost}/#{dbschema}?tinyInt1isBit=false\n")
f.write("db.user=#{dbusername}\n")
f.write("db.password=#{dbpassword}\n")
f.write("registration.url=http://#{db_host}:31415/sync/sx\n")
f.write("group.id=store\n")
f.write("external.id=001\n")
f.write("job.routing.period.time.ms=5000\n")
f.write("job.push.period.time.ms=10000\n")
f.write("job.pull.period.time.ms=10000\n")
# f.write("initial.load.create.first=true\n")
# f.write("initial.load.use.extract.job.enabled=true\n")
f.close
rescue IOError
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
end
response = { "status": true, "message": "Success Activation. License also created."}
end
response = { "status": true, "message": "License created"}
end
# Delete License File