103 lines
3.0 KiB
Ruby
103 lines
3.0 KiB
Ruby
require 'openssl'
|
|
require 'base64'
|
|
class ClientSitesController < ApplicationController
|
|
|
|
def check_module_permissions
|
|
apps = params[:apps]
|
|
store_key = params[:store_token]
|
|
site = RegisteredSite.find_by(:uid => store_key) rescue nil
|
|
render :json => {"success" => false}.to_json and return if site.nil?
|
|
installed_modules = site.installed_modules
|
|
permissions = []
|
|
apps.each do |app|
|
|
# rm = RegisteredModule.find_by(:module_key => app) rescue nil
|
|
# if !rm.nil?
|
|
# im = installed_modules.where(:r_module => rm.id)
|
|
# if im.count > 0
|
|
# permissions << {"app" => app, "granted" => im.first.permission_granted}
|
|
# else
|
|
# permissions << {"app" => app, "granted" => false}
|
|
# end
|
|
# else
|
|
# permissions << {"app" => app, "granted" => false}
|
|
# end
|
|
permissions << {"app" => app, "granted" => true}
|
|
|
|
end
|
|
render :json => {"success" => true,"permissions" => permissions}.to_json
|
|
end
|
|
|
|
def get_csrf_token
|
|
render :json => {"token" => form_authenticity_token}.to_json
|
|
end
|
|
|
|
def widget_download_url
|
|
rdw = RegisteredDesktopWidget.find_by(:widget_key => params[:widget_uid]) rescue nil
|
|
if !rdw.nil?
|
|
if !rdw.widget.nil?
|
|
render :json => {"success" => true,"url" => rdw.widget.url}
|
|
else
|
|
render :json => {"success" => false}
|
|
end
|
|
else
|
|
render :json => {"success" => false}
|
|
end
|
|
end
|
|
|
|
def get_desktop_widget_list
|
|
widget_list = []
|
|
rdws = RegisteredDesktopWidget.all.approve
|
|
rdws.each do |rdw|
|
|
t = {
|
|
"description" => "This is description",
|
|
"author" => (User.find(rdw.create_user_id).name rescue User.find(rdw.create_user_id).user_name),
|
|
"widgetName" => rdw.name,
|
|
"icon" => "http://" + request.host_with_port + "#{rdw.icon.thumb.url}",
|
|
"_id" => rdw.widget_key
|
|
}
|
|
widget_list << t
|
|
end
|
|
render :json => {"widgetList" => widget_list}.to_json
|
|
end
|
|
|
|
def register_old_sites_modules
|
|
apps = params[:apps]
|
|
store_key = params[:store_token]
|
|
site = RegisteredSite.find_by(:uid => store_key)
|
|
response = {}
|
|
if site.nil?
|
|
response["success"] = false
|
|
response["message"] = "Cannot verify site credentials. Make sure the site is registered."
|
|
else
|
|
apps.each do |app|
|
|
rm = RegisteredModule.find_by(:module_key => app) rescue nil
|
|
if !rm.nil?
|
|
im = InstalledModule.where(:r_module => rm.id, :registered_site_id => site.id)
|
|
if im.count == 0
|
|
im = InstalledModule.new
|
|
im.r_module = rm.id
|
|
im.permission_granted = true
|
|
im.registered_site = site
|
|
im.save
|
|
end
|
|
end
|
|
end
|
|
response["success"] = true
|
|
end
|
|
render :json => response.to_json
|
|
end
|
|
|
|
def check_for_rulingcom
|
|
private_key_file = File.join(Rails.root, "store.pem")
|
|
password = 'Rulingcom.com_Bjo4xjp6'
|
|
private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file),password)
|
|
string = private_key.private_decrypt(Base64.decode64(params[:encpas]))
|
|
mp = MasterPassword.first rescue nil
|
|
if !mp.nil? && mp.authenticate(string)
|
|
render :json => {"success" => true}.to_json
|
|
else
|
|
render :json => {"success" => false}.to_json
|
|
end
|
|
end
|
|
|
|
end |