update conflix after pull

This commit is contained in:
Aung Myo
2017-12-01 09:23:07 +06:30
9 changed files with 90 additions and 80 deletions

View File

@@ -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"])

View File

@@ -13,10 +13,13 @@ class MyAesCrypt
# for cloud is lookup
# for local is license_key
# iv_salt = passphrase+"c2l"
passphrase = passphrase + ENV['SX_KEY']
passphrase = passphrase.gsub(".","_")
digest = Digest::SHA256.new
key_digest = digest.update(passphrase)
# iv_digest = digest.update(iv_salt)
key = key_digest.digest
key = key_digest.digest
# iv = iv_digest.digest
ENV['AES_KEY'] = cipher_key = Base64.encode64(key) # stores the key in key, and also sets the generated key on the @cipher
ENV['AES_IV'] = cipher_iv = Base64.encode64(@cipher.random_iv) # stores the iv in iv, and also sets the generated iv on the @cipher

View File

@@ -27,28 +27,28 @@ class SaleItem < ApplicationRecord
end
def self.update_existing_item(qty, item, sale_id, type, item_price, price)
sale_item = SaleItem.new
sale_item.product_code = item.product_code
sale_item.item_instance_code = item.item_instance_code
sale_item.product_name = item.product_name + "(#{type})"
sale_item.product_alt_name = item.product_alt_name
sale_item.account_id = item.account_id
sale_item.remark = type
if type == "foc" || type == "promotion" || type == "void"
sale_item.qty = qty * (-1)
else
sale_item.qty = qty
end
sale_item = SaleItem.new
sale_item.product_code = item.product_code
sale_item.item_instance_code = item.item_instance_code
sale_item.product_name = item.product_name + "(#{type})"
sale_item.product_alt_name = item.product_alt_name
sale_item.account_id = item.account_id
sale_item.remark = type
if type == "foc" || type == "promotion" || type == "void"
sale_item.qty = qty * (-1)
else
sale_item.qty = qty
end
sale_item.unit_price = item_price # * (-1)
sale_item.taxable_price = (price) * (-1)
sale_item.price = (price) * (-1)
sale_item.unit_price = item_price # * (-1)
sale_item.taxable_price = (price) * (-1)
sale_item.price = (price) * (-1)
sale_item.is_taxable = 1
sale_item.sale_id = sale_id
sale_item.save
sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount)
sale_item.is_taxable = 1
sale_item.sale_id = sale_id
sale_item.save
sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount)
end
def self.get_order_items_details(sale_id)
@@ -95,7 +95,7 @@ class SaleItem < ApplicationRecord
discount_account = {:name => a.title, :price => 0}
# Check for actual sale items
sale_items.where("is_taxable = false AND remark = 'Discount'").find_each do |si|
sale_items.where("remark = 'Discount'").find_each do |si|
if si.account_id == a.id
discount_account[:price] = (discount_account[:price].abs + si.price.abs) * (-1)
end