Websites/config/default_config.rb
Donovan Daniels 90c05547f6
Move dev host rewriting into middleware
This makes matching against routes later much more reliable and less complicated
2024-05-03 17:53:47 -05:00

245 lines
6.7 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_base_url
"https://thumbs.yiff.media"
end
def e621_thumbnails_base_path
"/data/e621-thumbnails"
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
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