Donovan Daniels
b1c702e3cd
poorly tested but it worked well enough, I'm sure I'll be patching bugs over the next few weeks Also remove turbo because it sucks Also changed the way we handle hosts in dev
284 lines
7.9 KiB
Ruby
284 lines
7.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Websites
|
|
class Configuration
|
|
def version
|
|
GitHelper.short_hash
|
|
end
|
|
|
|
def version_link
|
|
GitHelper.commit_url(GitHelper.short_hash)
|
|
end
|
|
|
|
def readonly?
|
|
false
|
|
end
|
|
|
|
def source_code_url
|
|
"https://github.com/DonovanDMC/Websites"
|
|
end
|
|
|
|
def e621_status_check_discord_id
|
|
end
|
|
|
|
def e621_status_check_discord_secret
|
|
end
|
|
|
|
def e621_status_check_discord_redirect
|
|
return "http://websites4.containers.local:3000/webhook/discord/cb?domain=status.e621.ws" if Rails.env.development?
|
|
"https://status.e621.ws/webhook/discord/cb"
|
|
end
|
|
|
|
def e621_status_check_discord_scopes
|
|
{
|
|
min: %w[webhook.incoming],
|
|
all: %w[identify webhook.incoming],
|
|
}
|
|
end
|
|
|
|
def e621_status_check_discord_icon
|
|
Base64.encode64(Rails.root.join("app/assets/images/e621.ws/icon.png").read)
|
|
end
|
|
|
|
def e621_status_check_logs_webhook
|
|
# Requests::DiscordWebhook.new(id: "", token: "")
|
|
end
|
|
|
|
def redis_url
|
|
"redis://redis.websites4.containers.local/0"
|
|
end
|
|
|
|
def github_webhook_secret
|
|
end
|
|
|
|
def blocked_ip_addresses
|
|
[]
|
|
end
|
|
|
|
def yiffyapi_usage_webhook
|
|
# Requests::DiscordWebhook.new(id: "", token: "")
|
|
end
|
|
|
|
def yiffyapi_ratelimit_webhook
|
|
# Requests::DiscordWebhook.new(id: "", token: "")
|
|
end
|
|
|
|
def yiffyapi_discord_redirect(type)
|
|
return "http://websites4.containers.local:3000/#{type}?domain=discord.yiff.rest" if Rails.env.development?
|
|
"https://discord.yiff.rest/#{type}"
|
|
end
|
|
|
|
def yiffyapi_discord_scopes(type)
|
|
case type
|
|
when "count_servers"
|
|
%w[identify guilds]
|
|
else
|
|
%w[identify]
|
|
end
|
|
end
|
|
|
|
def yiffyapi_apikey_logs_webhook
|
|
# Requests::DiscordWebhook.new(id: "", token: "")
|
|
end
|
|
|
|
def yiffyapi_apikey_shortener_webhook
|
|
# Requests::DiscordWebhook.new(id: "", token: "")
|
|
end
|
|
|
|
def yiffyapi_administrators
|
|
%w[242843345402069002]
|
|
end
|
|
|
|
def yiffyapi_public_key
|
|
end
|
|
|
|
def yiffyapi_discord_id
|
|
end
|
|
|
|
def yiffyapi_discord_secret
|
|
end
|
|
|
|
def yiffyapi_discord_guild
|
|
end
|
|
|
|
def e621_thumbnails_access_key
|
|
end
|
|
|
|
def e621_thumbnails_storage_zone_name
|
|
end
|
|
|
|
def e621_thumbnails_webhook
|
|
# Requests::DiscordWebhook.new(id: "", token: "")
|
|
end
|
|
|
|
# gifs are unpredictable, prone to timing out and HUGE file sizes -for instance, https://e621.net/posts/4693107 took ~300 seconds
|
|
# to fully generate and be optimized, and produced a 270MB file which is completely unusable
|
|
def e621_thumbnails_disable_gif
|
|
true
|
|
end
|
|
|
|
def pastebin_dev_key
|
|
end
|
|
|
|
def pastebin_user_key
|
|
end
|
|
|
|
def pastebin_folder
|
|
end
|
|
|
|
def common_headers(domain)
|
|
# We don't want to set headers like HSTS in development
|
|
return {} if Rails.env.development?
|
|
{
|
|
"Report-To": {
|
|
group: "default",
|
|
max_age: 31_536_000,
|
|
endpoints: [
|
|
{ url: "https://yiff.report-uri.com/a/d/g" },
|
|
],
|
|
include_subdomains: true,
|
|
}.to_json,
|
|
"NEL": {
|
|
report_to: "default",
|
|
max_age: 31_536_000,
|
|
include_subdomains: true,
|
|
}.to_json,
|
|
"Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload",
|
|
"Expect-CT": "max-age=63072000, enforce, report-uri=\"https://yiff.report-uri.com/r/d/ct/enforce\"",
|
|
"Upgrade-Insecure-Requests": "1",
|
|
"Referrer-Policy": "strict-origin-when-cross-origin",
|
|
"X-XSS-Protection": "0",
|
|
"X-Permitted-Cross-Domain-Policies": "none",
|
|
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
"Access-Control-Allow-Origin": "*",
|
|
"Access-Control-Allow-Methods": "GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS",
|
|
"X-Frame-Options": "DENY",
|
|
"X-Content-Type-Options": "nosniff",
|
|
"X-Feature-Policy": [
|
|
"accelerometer 'none'",
|
|
"ambient-light-sensor 'none'",
|
|
"autoplay 'none'",
|
|
"battery 'none'",
|
|
"camera 'none'",
|
|
"display-capture 'none'",
|
|
"document-domain 'none'",
|
|
"encrypted-media 'none'",
|
|
"execution-while-not-rendered 'none'",
|
|
"execution-while-out-of-viewport 'none'",
|
|
"fullscreen 'none'",
|
|
"gamepad 'none'",
|
|
"geolocation 'none'",
|
|
"gyroscope 'none'",
|
|
"layout-animations 'none'",
|
|
"legacy-image-formats 'none'",
|
|
"magnetometer 'none'",
|
|
"microphone 'none'",
|
|
"midi 'none'",
|
|
"navigation-override 'none'",
|
|
"oversied-images 'none'",
|
|
"payment 'none'",
|
|
"picture-in-picture 'none'",
|
|
"publickey-credentials-get 'none'",
|
|
"speaker-selection 'none'",
|
|
"sync-xhr 'none'",
|
|
"unoptimized-images 'none'",
|
|
"unsized-media 'none'",
|
|
"usb 'none'",
|
|
"vr 'none'",
|
|
"vibrate 'none'",
|
|
"screen-wake-lock 'none'",
|
|
"xr-spatial-tracking 'none'",
|
|
].join("; "),
|
|
"Content-Security-Policy": [
|
|
"default-src 'self' #{domain} *.#{domain}",
|
|
"script-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://static.cloudflareinsights.com",
|
|
"style-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://fonts.googleapis.com",
|
|
"img-src 'self' https: data:",
|
|
"font-src 'self' https: data:",
|
|
"report-uri https://yiff.report-uri.com/r/d/csp/enforce",
|
|
"report-to default",
|
|
"upgrade-insecure-requests",
|
|
"block-all-mixed-content",
|
|
"require-sri-for script style",
|
|
].join("; "),
|
|
}
|
|
end
|
|
|
|
def http_headers
|
|
{
|
|
"User-Agent" => "Websites/4.0.0 (https://github.com/DonovanDMC/Websites; \"donovan_dmc\")",
|
|
}
|
|
end
|
|
|
|
def httparty_options
|
|
{
|
|
timeout: 10,
|
|
open_timout: 5,
|
|
headers: http_headers,
|
|
}
|
|
end
|
|
|
|
def yiffy2_cdn_url
|
|
# return "http://yiffy2.local" if Rails.env.development?
|
|
"https://v2.yiff.media"
|
|
end
|
|
|
|
def yiffy2_bucket_name
|
|
end
|
|
|
|
def yiffy2_access_key_id
|
|
end
|
|
|
|
def yiffy2_secret_access_key
|
|
end
|
|
|
|
def yiffy2_s3_endpoint
|
|
end
|
|
|
|
def e621_thumbnails_storage
|
|
# Bunny.new(base_url: Websites.config.e621_thumbnails_base_url, access_key: Websites.config.e621_thumbnails_access_key, storage_zone_name: Websites.config.e621_thumbnails_storage_zone_name)
|
|
StorageManager::Local.new(base_url: "https://thumbs.yiff.media", base_path: "/data/e621-thumbnails")
|
|
end
|
|
|
|
def yiffy2_storage
|
|
return StorageManager::Local.new(base_url: yiffy2_cdn_url, base_path: "/data/yiffy2") if Rails.env.development?
|
|
StorageManager::S3.new(
|
|
endpoint: yiffy2_s3_endpoint,
|
|
access_key_id: yiffy2_access_key_id,
|
|
secret_access_key: yiffy2_secret_access_key,
|
|
bucket: yiffy2_bucket_name,
|
|
base_url: yiffy2_cdn_url,
|
|
)
|
|
end
|
|
end
|
|
|
|
class EnvironmentConfiguration
|
|
def custom_configuration
|
|
@custom_configuration ||= CustomConfiguration.new
|
|
end
|
|
|
|
def env_to_boolean(method, var)
|
|
is_boolean = method.to_s.end_with?("?")
|
|
return true if is_boolean && var.truthy?
|
|
return false if is_boolean && var.falsy?
|
|
var
|
|
end
|
|
|
|
def method_missing(method, *)
|
|
var = ENV.fetch("WEBSITES_#{method.to_s.upcase.chomp('?')}", nil)
|
|
|
|
if var.present?
|
|
env_to_boolean(method, var)
|
|
else
|
|
custom_configuration.send(method, *)
|
|
end
|
|
end
|
|
end
|
|
|
|
def config
|
|
@config ||= EnvironmentConfiguration.new
|
|
end
|
|
|
|
module_function :config
|
|
end
|