need to fix license

This commit is contained in:
Yan
2017-12-19 16:54:11 +06:30
parent 4e616ed5eb
commit 3be8a56ac6
2 changed files with 55 additions and 11 deletions

View File

@@ -46,10 +46,12 @@ class ApplicationController < ActionController::Base
def current_license(url)
@license = License.new(url)
if (@license.detail_with_local_file() == true)
puts "RUN SAY BYAR"
if (@license.detail_with_local_file() == 0)
puts "Expired or No License!"
elsif (@license.detail_with_local_file() == 2)
puts "Expiring! pls, license extend..."
else
return nil
puts "RUN SAY BYAR"
end
end

View File

@@ -69,8 +69,17 @@ class License
# For Local System
def detail_with_local_file()
# aes = MyAesCrypt.new
# aes_key, aes_iv = aes.export_key(lookup)
# flag = ENV["AES_KEY"]
# # Check Exists IV
# if flag == "<%= ENV['AES_IV'] %>"
# # Export for Key
# aes = MyAesCrypt.new
# aes_key, aes_iv = aes.export_key(lookup)
# else
# aes_key = ENV["AES_KEY"]
# aes_iv = ENV["AES_IV"]
# end
renewal_date_str = read_license("renewable_date")
# ##Check from local redis - if available load local otherwise get from remote
@@ -84,14 +93,17 @@ class License
# redis.set(renewable_date, Marshal.dump(@license))
# else
# get_renewable_date = Marshal.load(cache_renewable_date)
if check_expiring(renewal_date_str)
return true
if check_expiring(renewal_date_str)
# return for all ok
return 1
else
has_license = verify_license()
if has_license
puts "VERIFIED"
return true
# return for expiring
return 2
else
return 0
end
end
# end
@@ -144,7 +156,13 @@ class License
# Check License expired date from PROVISION SERVER
def check_expired(renewal_date_str)
expired_date_str = read_license("renewable_date")
expired_date = DateTime.parse(expired_date_str)
renewal_date = DateTime.parse(renewal_date_str)
if(renewal_date != expired_date){
update_license("renewable_date", renewal_date_str)
}
if (renewal_date < Date.today)
return true
else
@@ -163,8 +181,7 @@ class License
if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line|
if line.include? (key)
decrypted_line_array = line.split(": ")
byebug
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
@@ -186,7 +203,32 @@ class License
return decrypted_line
end
# Update license file for line
def update_license(content, new_content)
if !new_content.include? "=="
str = encode_str(new_content)
crypted_str = AESCrypt.encrypt_data(str, ENV['AES_KEY'], ENV['AES_IV'], ENV['CIPHER_TYPE'])
end
content_str = read_license_no_decrypt(content)
if File.exist?("config/license.yml")
file_str = File.read("config/license.yml")
new_file_str = file_str.gsub(content, crypted_str)
# To write changes to the file, use:
# File.open("config/license.yml", "w") {|file| file.puts new_file_str }
# File.open("config/license.yml").each do |line|
# new_file_str = line.gsub(content, crypted_str)
# f.put
# end
end
end
private
def encode_str(str)
return Base64.encode64(str)
end
def decode_str(str)
return Base64.decode64(str)