Initial commit

This commit is contained in:
Yaser
2026-08-13 19:56:46 +03:30
commit de1d57a67b
474 changed files with 43185 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
ApiPagination.configure do |config|
# If you have more than one gem included, you can choose a paginator.
config.paginator = :kaminari # or :will_paginate
# By default, this is set to 'Total'
# config.total_header = 'X-Total'
# By default, this is set to 'Per-Page'
# config.per_page_header = 'X-Per-Page'
# Optional: set this to add a header with the current page number.
config.page_header = 'Page'
# Optional: set this to add other response format. Useful with tools that define :jsonapi format
# config.response_formats = [:json, :xml, :jsonapi]
# Optional: what parameter should be used to set the page option
config.page_param = :page
# Optional: what parameter should be used to set the per page option
config.per_page_param = :limit
# Optional: Include the total and last_page link header
# By default, this is set to true
# Note: When using kaminari, this prevents the count call to the database
# config.include_total = false
end

View File

@@ -0,0 +1,8 @@
# Be sure to restart your server when you modify this file.
# ActiveSupport::Reloader.to_prepare do
# ApplicationController.renderer.defaults.merge!(
# http_host: 'example.org',
# https: false
# )
# end

View File

@@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

View File

@@ -0,0 +1,7 @@
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!

View File

@@ -0,0 +1,157 @@
# frozen_string_literal: true
# 1/ check if ENV key exist then validate and set
# 2/ if no check in credentials then validate and set
# 3/ if no generate display warning, raise error in production, and set
require 'barong/app'
require 'barong/keystore'
require 'barong/string'
private_key_path = ENV['JWT_PRIVATE_KEY_PATH']
if !private_key_path.nil?
pkey = Barong::KeyStore.open!(private_key_path)
Rails.logger.error('Loading private key from: ' + private_key_path)
elsif Rails.application.credentials.has?(:private_key)
pkey = Barong::KeyStore.read!(Rails.application.credentials.private_key)
Rails.logger.info('Loading private key from credentials.yml.enc')
elsif !Rails.env.production?
# Generates private key
key = Barong::KeyStore.generate
pkey = key.to_pem
pub_key = key.public_key.to_pem
# Save private/public keys
Barong::KeyStore.save!(pkey, 'config/rsa-key')
Barong::KeyStore.save!(pub_key, 'config/rsa-key.pub')
Rails.logger.warn('Warning !! Generating private key')
else
raise 'Private key not found or invalid'
end
kstore = Barong::KeyStore.new(pkey)
# Define default value for secret_key_base in test and development mode
ENV['SECRET_KEY_BASE'] = '' unless Rails.env.production?
Barong::App.define do |config|
# General configuration ---------------------------------------------
# https://www.openware.com/sdk/docs/barong/configuration.html#general-configuration
config.set(:app_name, 'Fibitex')
config.set(:domain, 'fibitex.com')
config.set(:uid_prefix, 'ID', regex: /^[A-z]{2,6}$/)
config.set(:session_name, '_dalan_session')
config.set(:session_expire_time, '1800', type: :integer)
config.set(:kyc_provider, 'kycaid', values: %w[kycaid local])
config.set(:required_docs_expire, 'false', type: :bool)
config.set(:doc_num_limit, '10', type: :integer)
config.set(:geoip_lang, 'en', values: %w[en de es fr ja ru])
config.set(:csrf_protection, 'true', type: :bool)
config.set(:apikey_nonce_lifetime, '50000', type: :integer)
config.set(:gateway, 'cloudflare', values: %w[akamai cloudflare])
config.set(:jwt_expire_time, '3600', type: :integer)
config.set(:profile_double_verification, 'false', type: :bool)
config.set(:crc32_salt, '')
config.set(:api_data_masking_enabled, 'true', type: :bool)
config.set(:first_registration_superadmin, 'true', type: :bool)
config.set(:mgn_api_keys_user, 'false', type: :bool)
config.set(:mgn_api_keys_sa, 'false', type: :bool)
# Password configuration -----------------------------------------------
# https://www.openware.com/sdk/docs/barong/configuration.html#password-configuration
config.set(:password_regexp, '^(?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:digit:]])(?=.*[[:graph:]]).{8,80}$', type: :regexp)
config.set(:password_min_entropy, '14', type: :integer)
config.set(:password_use_dictionary, 'true', type: :bool)
# CAPTCHA configuration ---------------------------------------------
# https://www.openware.com/sdk/docs/barong/configuration.html#captcha-configuration
config.set(:captcha, 'none', values: %w[none recaptcha geetest])
config.set(:geetest_id, '')
config.set(:geetest_key, '')
config.set(:recaptcha_site_key, '')
config.set(:recaptcha_secret_key, '')
# Dependencies configuration (vault, redis, rabbitmq) ---------------
# https://www.openware.com/sdk/docs/barong/configuration.html#dependencies-configuration-vault-redis-rabbitmq
config.set(:event_api_rabbitmq_host, 'localhost')
config.set(:event_api_rabbitmq_port, '5672')
config.set(:event_api_rabbitmq_username, 'guest')
config.set(:event_api_rabbitmq_password, 'guest')
config.set(:vault_address, 'http://localhost:8200')
config.set(:vault_token, '')
config.set(:redis_cluster, 'false', type: :bool)
config.set(:redis_url, 'redis://localhost:6379/1')
config.set(:redis_password, '')
config.set(:vault_app_name, 'barong')
# CORS configuration -----------------------------------------------
# https://www.openware.com/sdk/docs/barong/configuration.html#api-cors-configuration
config.set(:api_cors_origins, '*')
config.set(:api_cors_max_age, '3600')
config.set(:api_cors_allow_credentials, 'false', type: :bool)
# Config files configuration ----------------------------------------
# https://www.openware.com/sdk/docs/barong/configuration.html#config-files-configuration
config.set(:config, 'config/barong.yml', type: :path)
config.set(:maxminddb_path, 'geolite/GeoLite2-Country.mmdb', type: :path)
config.set(:seeds_file, Rails.root.join('config', 'seeds.yml'), type: :path)
config.set(:authz_rules_file, Rails.root.join('config', 'authz_rules.yml'), type: :path)
# SMTP configuration ------------------------------------------------
# https://github.com/openware/barong/blob/master/docs/general/env_configuration.md#smtp-configuration
config.set(:sender_email, 'noreply@barong.io')
config.set(:sender_name, 'Barong')
config.set(:smtp_password, '')
config.set(:smtp_port, 1025)
config.set(:smtp_host, 'localhost')
config.set(:smtp_user, '')
config.set(:smtp_logo_link, 'https://storage.cloud.google.com/public_peatio/logo.png')
config.set(:default_language, 'en')
config.set(:smtp_domain, 'test.com')
config.set(:smtp_enable_starttls_auto, 'true', type: :bool)
config.set(:smtp_openssl_verify_mode, 'peer')
config.set(:smtp_auth, 'plain')
# KYCAID ------------------------------------------------------------
config.set(:kycaid_authorization_token, '')
config.set(:kycaid_sandbox_mode, 'true', type: :bool)
config.set(:kycaid_api_endpoint, 'https://api.kycaid.com/')
# Auth0 configuration -----------------------------------------------
config.set(:auth0_domain, '')
config.set(:auth0_client_id, '')
# jibit configuration ----------------------------------------
config.set(:jibit_api_url, '')
config.set(:jibit_api_key, '')
config.set(:jibit_api_secret, '')
end
# KYCAID configuring
KYCAID.configure do |config|
config.authorization_token = Barong::App.config.kycaid_authorization_token
config.sandbox_mode = Barong::App.config.kycaid_sandbox_mode
config.api_endpoint = Barong::App.config.kycaid_api_endpoint
end
ActionMailer::Base.smtp_settings = {
address: Barong::App.config.smtp_host,
port: Barong::App.config.smtp_port,
user_name: Barong::App.config.smtp_user,
authentication: Barong::App.config.smtp_auth,
domain: Barong::App.config.smtp_domain,
enable_starttls_auto: Barong::App.config.smtp_enable_starttls_auto,
openssl_verify_mode: Barong::App.config.smtp_openssl_verify_mode,
password: Barong::App.config.smtp_password
}
Barong::GeoIP.lang = Barong::App.config.geoip_lang
Rails.application.config.x.keystore = kstore
Barong::App.config.keystore = kstore

View File

@@ -0,0 +1,17 @@
# FIXME BarongConfig should be a feature of Barong::App
class BarongConfig
class << self
def list
@hash ||= read_from_yaml
end
private
def read_from_yaml
conf = YAML.load_file(Barong::App.config.config)
conf['activation_requirements'] = {'email' => 'verified'} unless conf['activation_requirements']
conf
end
end
end

View File

@@ -0,0 +1,60 @@
# frozen_string_literal: true
require 'carrierwave/storage/abstract'
require 'carrierwave/storage/file'
require 'carrierwave/storage/fog'
Barong::App.define do |config|
# Storage configuration
# https://www.openware.com/sdk/docs/barong/configuration.html#storage-configuration
config.set(:storage_provider, 'local')
config.set(:storage_bucket_name, 'local')
config.set(:storage_access_key, '')
config.set(:storage_secret_key, '')
config.set(:storage_endpoint, '') # optional (AWS, AliCloud)
config.set(:storage_signature_version, '4') # optional (AWS)
config.set(:storage_region, '') # optional (AWS, AliCloud)
config.set(:storage_pathstyle, 'false', type: :bool) # optional (AWS, AliCloud)
# Carrierwave defaults configuration
config.write(:uploader, UploadUploader)
config.set(:upload_size_min_range, '1', type: :integer) # in megabytes
config.set(:upload_size_max_range, '10', type: :integer) # in megabytes
config.set(:upload_auth_url_expiration, '1', type: :integer) # in minutes
config.set(:upload_extension_whitelist, 'jpg, jpeg, png, pdf', type: :array)
end
CarrierWave.configure do |config|
if 'Google'.casecmp?(Barong::App.config.storage_provider)
config.fog_credentials = {
provider: 'Google',
google_storage_access_key_id: Barong::App.config.storage_access_key,
google_storage_secret_access_key: Barong::App.config.storage_secret_key
}
config.fog_directory = Barong::App.config.storage_bucket_name
elsif 'AWS'.casecmp?(Barong::App.config.storage_provider)
config.fog_credentials = {
provider: 'AWS',
aws_signature_version: Barong::App.config.storage_signature_version,
aws_access_key_id: Barong::App.config.storage_access_key,
aws_secret_access_key: Barong::App.config.storage_secret_key,
region: Barong::App.config.storage_region,
endpoint: Barong::App.config.storage_endpoint,
path_style: Barong::App.config.storage_pathstyle
}
config.fog_directory = Barong::App.config.storage_bucket_name
elsif 'AliCloud'.casecmp?(Barong::App.config.storage_provider)
Barong::App.write(:uploader, AliUploader)
config.fog_credentials = {
provider: 'aliyun',
aliyun_accesskey_id: Barong::App.config.storage_access_key,
aliyun_accesskey_secret: Barong::App.config.storage_secret_key,
aliyun_oss_bucket: Barong::App.config.storage_bucket_name,
aliyun_region_id: Barong::App.config.storage_region,
aliyun_oss_endpoint: "oss-#{Barong::App.config.storage_region}.aliyuncs.com"
}
config.fog_directory = Barong::App.config.storage_bucket_name
else
config.storage :file
end
end

View File

@@ -0,0 +1,25 @@
# Be sure to restart your server when you modify this file.
# Define an application-wide content security policy
# For further information see the following documentation
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
# Rails.application.config.content_security_policy do |policy|
# policy.default_src :self, :https
# policy.font_src :self, :https, :data
# policy.img_src :self, :https, :data
# policy.object_src :none
# policy.script_src :self, :https
# policy.style_src :self, :https
# # Specify URI for violation reports
# # policy.report_uri "/csp-violation-report-endpoint"
# end
# If you are using UJS then enable automatic nonce generation
# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
# Report CSP violations to a specified URI
# For further information see the following documentation:
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
# Rails.application.config.content_security_policy_report_only = true

View File

@@ -0,0 +1,7 @@
# Be sure to restart your server when you modify this file.
Rails.application.config.action_dispatch.signed_cookie_digest = 'SHA256'
# Specify a serializer for the signed and encrypted cookie jars.
# Valid options are :json, :marshal, and :hybrid.
Rails.application.config.action_dispatch.cookies_serializer = :json

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
# document types definitions
class DocumentTypes
class << self
def list
@list ||= YAML.load_file(Barong::App.config.config)['document_types']
end
def category_list
@category_list ||= YAML.load_file(Barong::App.config.config)['document_categories']
end
end
end

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
require_dependency 'barong/event_api'
ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.include ::EventAPI::ActiveRecord::Extension
end

View File

@@ -0,0 +1,25 @@
def catch_and_report_exception(options = {})
begin
yield
nil
rescue options.fetch(:class) { StandardError } => e
report_exception(e)
e
end
end
def report_exception(exception, report_to_ets = true)
report_exception_to_screen(exception)
report_exception_to_ets(exception) if report_to_ets
end
def report_exception_to_screen(exception)
Rails.logger.unknown exception.inspect
Rails.logger.unknown exception.backtrace.join("\n") if exception.respond_to?(:backtrace)
end
def report_exception_to_ets(exception)
Raven.capture_exception(exception) if defined?(Raven)
rescue => ets_exception
report_exception(ets_exception, false)
end

View File

@@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += %i[password upload]

View File

@@ -0,0 +1,16 @@
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end

View File

@@ -0,0 +1,26 @@
require 'yaml'
require 'openssl'
(YAML.load_file('config/management_api.yml') || {}).deep_symbolize_keys!.tap do |x|
x.fetch(:keychain).each do |id, key|
key = OpenSSL::PKey.read(Base64.urlsafe_decode64(key.fetch(:value)))
if key.private?
raise ArgumentError, 'keychain.' + id.to_s + ' was set to private key, ' \
'however it should be public (in config/management_api.yml).'
end
x[:keychain][id][:value] = key
end
x.fetch(:scopes).values.each do |scope|
%i[permitted_signers mandatory_signers].each do |list|
scope[list] = scope.fetch(list, []).map(&:to_sym)
scope[list] = scope.fetch(list, []).map(&:to_sym)
if list == :mandatory_signers && scope[list].empty?
raise ArgumentError, 'scopes.' + scope.to_s + '.' + list.to_s + ' is empty, ' \
'however it should contain at least one value (in config/management_api.yml).'
end
end
end
API::V2::Management::JWTAuthenticationMiddleware.security_configuration = x
end

View File

@@ -0,0 +1,18 @@
KaveRestApi.configure do |config|
# To completely ignore debug mode events(No Errors) uncomment this line *optional
# config.debugmode = false #by default it's true
# It is recommended that you pull your API keys from environment settings. *required
config.api_key = ENV.fetch("KAVENEGAR_API_KEY", 'changeme')
# Default response format is json (you can use xml too). *optional
config.format = 'json'
#If you don't set your sender number in your request, this is the default number used instead *required
config.default_sender = ENV.fetch("KAVENEGAR_SENDER", 'changeme')
# You can remove problematic emojis (like android emojis) and replace with standard emojis listed here:(https://www.webpagefx.com/tools/emoji-cheat-sheet/)
# config.strip_emoji = 'false' # can include false , true and matcher
end

View File

@@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf

View File

@@ -0,0 +1,4 @@
# Don't allow downloaded files to be created as StringIO. Create a tempfile instead
OpenURI::Buffer.send :remove_const, 'StringMax' if OpenURI::Buffer.const_defined?('StringMax')
OpenURI::Buffer.const_set 'StringMax', 0

View File

@@ -0,0 +1,50 @@
# frozen_string_literal: true
require_dependency 'barong/mock_sms'
Barong::App.define do |config|
# Twilio configuration ----------------------
# https://www.openware.com/sdk/docs/barong/configuration.html#twilio-configuration
# config.write(:twilio_provider, TwilioSmsSendService)
# config.set(:phone_verification, 'mock')
# config.set(:twilio_phone_number, '+15005550000')
# config.set(:twilio_account_sid, '')
# config.set(:twilio_auth_token, '')
# config.set(:twilio_service_sid, '')
# config.set(:sms_content_template, 'Your verification code for Barong: {{code}}')
end
# sid = Barong::App.config.twilio_account_sid
# token = Barong::App.config.twilio_auth_token
# service_sid = Barong::App.config.twilio_service_sid
# case Barong::App.config.phone_verification
# when 'twilio_sms'
# raise 'Invalid twilio config' if sid.to_s.empty? || token.to_s.empty?
# client = Twilio::REST::Client.new(sid, token)
# Barong::App.write(:twilio_provider, TwilioSmsSendService)
# when 'twilio_verify'
# raise 'Invalid twilio config' if sid.to_s.empty? || token.to_s.empty?
# client = Twilio::REST::Client.new(sid, token)
# service = client.verify.services.create(friendly_name: Barong::App.config.app_name) unless service_sid.present?
# Barong::App.write(:twilio_provider, TwilioVerifyService)
# when 'mock'
# if Rails.env.production?
# Rails.logger.info("WARNING! Don't use mock phone verification service in production")
# end
# Barong::App.write(:twilio_provider, MockPhoneVerifyService)
# else
# raise "Unknown phone verification service #{Barong::App.config.phone_verification}"
# end
# Barong::App.set(:twilio_client, client) if client
# Barong::App.set(:twilio_service_sid, service.sid) if service
# Phonelib.strict_check = true

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
begin
if Rails.env.production?
redis_url = ENV.fetch('BARONG_REDIS_URL', 'redis://localhost:6379/1')
r = Redis.new(url: redis_url)
r.ping
end
rescue Redis::CannotConnectError
Rails.logger.fatal("Error connecting to Redis on #{redis_url} (Errno::ECONNREFUSED)")
raise 'FATAL: connection to Redis refused'
end

View File

@@ -0,0 +1,27 @@
# frozen_string_literal: true
module Rack
module Session
# redis store configuration class to act as session_store (cache_store)
class Redis
def set_session(env, session_id, new_session, options)
with_lock env, false do
with do |c|
new_options = if env['api_v2.session_lifetime']
x = ActionDispatch::Request::Session::Options.new \
options.instance_variable_get(:@by),
options.instance_variable_get(:@env),
options.instance_variable_get(:@delegate)
x[:expire_after] = env['api_v2.session_lifetime']
x
else
options
end
c.set(session_id, new_session, new_options)
end
session_id
end
end
end
end
end

View File

@@ -0,0 +1,4 @@
# frozen_string_literal: true
# Use cache_store as session_store for Rails sessions. Key default is '_barong_session'
Rails.application.config.session_store :cache_store, key: Barong::App.config.session_name, expire_after: 24.hours.seconds

View File

@@ -0,0 +1,9 @@
# frozen_string_literal: true
Sidekiq.configure_server do |config|
config.redis = { url: ENV.fetch('BARONG_REDIS_URL', 'redis://localhost:6379/1') }
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV.fetch('BARONG_REDIS_URL', 'redis://localhost:6379/1') }
end

View File

@@ -0,0 +1,8 @@
# Extend default list of trusted proxies with generic private and cloudflare proxy list
# Cloudflare proxies list
# config/cloudflare_ips.yml fetches every time you build an image. Check Dockerfile l54, l55
cloudflare_ips = File.read('config/cloudflare_ips.yml').split(/\R+/)
extend_proxies = cloudflare_ips.map { |proxy| IPAddr.new(proxy) }
Rails.application.config.action_dispatch.trusted_proxies = ActionDispatch::RemoteIp::TRUSTED_PROXIES + extend_proxies

View File

@@ -0,0 +1,10 @@
# frozen_string_literal: true
# whitelisted data storage titles definitions
class UserStorageTitles
class << self
def list
@list ||= YAML.load_file(Barong::App.config.config)['user_storage_titles'] || []
end
end
end

View File

@@ -0,0 +1,42 @@
# frozen_string_literal: true
require 'vault/rails'
Vault::Rails.configure do |config|
config.enabled = Rails.env.production?
config.address = Barong::App.config.vault_address
config.token = Barong::App.config.vault_token
config.ssl_verify = false
config.timeout = 60
config.application = Barong::App.config.vault_app_name
end
if Barong::App.config.vault_token.to_s != ''
def renew_process
token = Vault.auth_token.lookup(Vault.token)
time = token.data[:ttl] * (1 + rand) * 0.1
Rails.logger.debug '[VAULT] Token will renew in %.0f sec' % time
sleep(time)
Vault.auth_token.renew(token.data[:id])
Rails.logger.info '[VAULT] Token renewed'
end
# where connect to vault
token = Vault.auth_token.lookup(Vault.token)
if token.data[:renewable]
Rails.logger.info '[VAULT] Starting token renew thread'
Thread.new do
loop do
renew_process
rescue StandardError => e
report_exception(e)
sleep 60
end
end
else
Rails.logger.info '[VAULT] Token is not renewable'
end
else
Rails.logger.warn 'Environment variable BARONG_VAULT_TOKEN is missing'
end

View File

@@ -0,0 +1,12 @@
# encoding: UTF-8
# frozen_string_literal: true
# This file is auto-generated from the current state of VCS.
# Instead of editing this file, please use bin/gendocs.
module Barong
class Application
GIT_TAG = '2.7.0'
GIT_SHA = '3d7fe81'
BUILD_DATE = '2020-12-08 15:09:53+02:00'
VERSION = GIT_TAG
end
end

View File

@@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
# self.include_root_in_json = true
# end