added license
This commit is contained in:
@@ -110,7 +110,7 @@ class ApplicationController < ActionController::Base
|
||||
if License.check_license_file
|
||||
return true
|
||||
else
|
||||
redirect_to install_path
|
||||
redirect_to activate_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
class InstallController < BaseController
|
||||
before_action :check_license
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def activate
|
||||
restaurant = params[:restaurant_name]
|
||||
license_key = params[:license_key]
|
||||
admin_user = params[:admin_user]
|
||||
admin_password = params[:admin_password]
|
||||
# admin_user = params[:admin_user]
|
||||
# admin_password = params[:admin_password]
|
||||
db_host = params[:db_host]
|
||||
db_schema = params[:db_schema]
|
||||
db_user = params[:db_user]
|
||||
db_password = params[:db_password]
|
||||
|
||||
@@ -15,37 +19,48 @@ class InstallController < BaseController
|
||||
aes_key, aes_iv = aes.export_key(lookup)
|
||||
|
||||
@license = License.new(ENV["SX_PROVISION_URL"])
|
||||
@license.license_activate(aes_key, aes_iv, license_key)
|
||||
response = @license.license_activate(aes_key, aes_iv, license_key, db_host, db_schema, db_user, db_password)
|
||||
if response["status"]
|
||||
redirect_to root_url, notice: response["message"]
|
||||
else
|
||||
redirect_to activate_path, notice: response["message"]
|
||||
end
|
||||
end
|
||||
|
||||
def lookup_domain
|
||||
if request.subdomain.present? && request.subdomain != "www"
|
||||
@license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase)
|
||||
if (!@license.nil?)
|
||||
# logger.info "Location - " + @license.name
|
||||
ActiveRecord::Base.establish_connection(website_connection(@license))
|
||||
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
||||
else
|
||||
# reconnect_default_db
|
||||
logger.info 'License is nil'
|
||||
# redirect_to root_url(:host => request.domain) + "store_error"
|
||||
render :json => [{ status: false, message: 'Invalid Access!'}]
|
||||
end
|
||||
def check_license
|
||||
if License.check_license_file
|
||||
redirect_to root_url
|
||||
end
|
||||
end
|
||||
|
||||
def current_license(url, key)
|
||||
@license = License.new(url, key)
|
||||
# def lookup_domain
|
||||
# if request.subdomain.present? && request.subdomain != "www"
|
||||
# @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase)
|
||||
# if (!@license.nil?)
|
||||
# # logger.info "Location - " + @license.name
|
||||
# ActiveRecord::Base.establish_connection(website_connection(@license))
|
||||
# # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
||||
# else
|
||||
# # reconnect_default_db
|
||||
# logger.info 'License is nil'
|
||||
# # redirect_to root_url(:host => request.domain) + "store_error"
|
||||
# render :json => [{ status: false, message: 'Invalid Access!'}]
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
##creating md5 hash
|
||||
md5_hostname = Digest::MD5.new
|
||||
md5key = md5_hostname.update(request.host)
|
||||
if (@license.detail_with_local_cache(key, md5key.to_s) == true)
|
||||
#if (@license.detail == true)
|
||||
# def current_license(url, key)
|
||||
# @license = License.new(url, key)
|
||||
|
||||
return @license
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
# ##creating md5 hash
|
||||
# md5_hostname = Digest::MD5.new
|
||||
# md5key = md5_hostname.update(request.host)
|
||||
# if (@license.detail_with_local_cache(key, md5key.to_s) == true)
|
||||
# #if (@license.detail == true)
|
||||
|
||||
# return @license
|
||||
# else
|
||||
# return nil
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<input type="text" class="form-control" name="license_key" aria-describedby="license_key" placeholder="Add License Key">
|
||||
<small class="form-text text-muted">Add License Key from Email</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<!-- <div class="form-group">
|
||||
<label for="lblAdministrator">Administrator Username</label>
|
||||
<input type="text" class="form-control" name="admin_user" aria-describedby="admin_user" placeholder="Administrator Username">
|
||||
<small id="admin_user" class="form-text text-muted">First Employee who will be assign as administrator</small>
|
||||
@@ -18,9 +18,17 @@
|
||||
<div class="form-group">
|
||||
<label for="admin_password">Password</label>
|
||||
<input type="password" class="form-control" name="admin_password" placeholder="Password">
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="lblDBHost">Database Host</label>
|
||||
<input type="text" class="form-control" name="db_host" aria-describedby="db_host" placeholder="Database Host" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lblDBName">Database Schema</label>
|
||||
<input type="text" class="form-control" name="db_schema" aria-describedby="db_schema" placeholder="Database Schema">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lblAdministrator">Database Username</label>
|
||||
<input type="text" class="form-control" name="db_user" aria-describedby="db_user" placeholder="Database Username">
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 p-t-20 p-l-10 p-r-10 p-b-50 bg-white">
|
||||
<div class="row justify-content-center form-group">
|
||||
<!-- <span class="col-md-4"></span> -->
|
||||
<input type="text" class="form-control col-4" id="emp_id" onkeypress="empID()" placeholder="Access PIN">
|
||||
<input type="text" class="form-control col-4" id="emp_id" onkeypress="empID()" placeholder="Employee ID">
|
||||
<!-- <span class="col-md-4"></span> -->
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user