0.8.6: Alternative domains and less useless variables
This commit is contained in:
parent
6f17589536
commit
4ed07ccecb
7 changed files with 58 additions and 31 deletions
|
@ -34,3 +34,7 @@ opengraphUseragents:
|
||||||
- "chatterino-api-cache/"
|
- "chatterino-api-cache/"
|
||||||
- "FFZBot/"
|
- "FFZBot/"
|
||||||
- "Twitterbot/"
|
- "Twitterbot/"
|
||||||
|
|
||||||
|
alternativeDomains:
|
||||||
|
- "ayaya.beauty"
|
||||||
|
- "lamartina.gay"
|
||||||
|
|
|
@ -10,7 +10,8 @@ class Config
|
||||||
property dbTableName : String = "files"
|
property dbTableName : String = "files"
|
||||||
property adminEnabled : Bool = false
|
property adminEnabled : Bool = false
|
||||||
property adminApiKey : String? = ""
|
property adminApiKey : String? = ""
|
||||||
property incremental_fileameLength : Bool = true
|
# Not implemented
|
||||||
|
property incrementalFileameLength : Bool = true
|
||||||
property fileameLength : Int32 = 3
|
property fileameLength : Int32 = 3
|
||||||
# In MiB
|
# In MiB
|
||||||
property size_limit : Int16 = 512
|
property size_limit : Int16 = 512
|
||||||
|
@ -27,11 +28,15 @@ class Config
|
||||||
property deleteFilesCheck : Int32 = 1800
|
property deleteFilesCheck : Int32 = 1800
|
||||||
property deleteKeyLength : Int32 = 4
|
property deleteKeyLength : Int32 = 4
|
||||||
# Blocked extensions that are not allowed to be uploaded to the server
|
# Blocked extensions that are not allowed to be uploaded to the server
|
||||||
property blockedExtensions : Array(String) = [] of String
|
|
||||||
property opengraphUseragents : Array(String) = [] of String
|
|
||||||
property siteInfo : String = "xd"
|
property siteInfo : String = "xd"
|
||||||
property siteWarning : String? = ""
|
property siteWarning : String? = ""
|
||||||
property log_level : LogLevel = LogLevel::Info
|
property log_level : LogLevel = LogLevel::Info
|
||||||
|
property blockedExtensions : Array(String) = [] of String
|
||||||
|
property opengraphUseragents : Array(String) = [] of String
|
||||||
|
# Since this program detects the Host header of the client it can be used
|
||||||
|
# with multiple domains. You can display the domains in the frontend
|
||||||
|
# and in `/api/stats`
|
||||||
|
property alternativeDomains : Array(String) = [] of String
|
||||||
|
|
||||||
def self.load
|
def self.load
|
||||||
config_file = "config/config.yml"
|
config_file = "config/config.yml"
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Handling::Admin
|
||||||
|
|
||||||
def delete_file(env)
|
def delete_file(env)
|
||||||
if env.request.headers.try &.["X-Api-Key"]? != CONFIG.adminApiKey || nil
|
if env.request.headers.try &.["X-Api-Key"]? != CONFIG.adminApiKey || nil
|
||||||
error401 "Wrong API Key"
|
error401 "Wrong API Key"
|
||||||
end
|
end
|
||||||
files = env.params.json["files"].as((Array(JSON::Any)))
|
files = env.params.json["files"].as((Array(JSON::Any)))
|
||||||
successfull_files = [] of String
|
successfull_files = [] of String
|
||||||
|
|
|
@ -21,9 +21,6 @@ module Handling
|
||||||
checksum = ""
|
checksum = ""
|
||||||
ip_address = ""
|
ip_address = ""
|
||||||
delete_key = nil
|
delete_key = nil
|
||||||
ip_address = env.request.headers.try &.["X-Forwarded-For"]? ? env.request.headers.["X-Forwarded-For"] : env.request.remote_address.to_s.split(":").first
|
|
||||||
protocol = env.request.headers.try &.["X-Forwarded-Proto"]? ? env.request.headers["X-Forwarded-Proto"] : "http"
|
|
||||||
host = env.request.headers.try &.["X-Forwarded-Host"]? ? env.request.headers["X-Forwarded-Host"] : env.request.headers["Host"]
|
|
||||||
# TODO: Return the file that matches a checksum inside the database
|
# TODO: Return the file that matches a checksum inside the database
|
||||||
HTTP::FormData.parse(env.request) do |upload|
|
HTTP::FormData.parse(env.request) do |upload|
|
||||||
if upload.filename.nil? || upload.filename.to_s.empty?
|
if upload.filename.nil? || upload.filename.to_s.empty?
|
||||||
|
@ -85,9 +82,6 @@ module Handling
|
||||||
files = env.params.json["files"].as((Array(JSON::Any)))
|
files = env.params.json["files"].as((Array(JSON::Any)))
|
||||||
successfull_files = [] of NamedTuple(filename: String, extension: String, original_filename: String, checksum: String, delete_key: String | Nil)
|
successfull_files = [] of NamedTuple(filename: String, extension: String, original_filename: String, checksum: String, delete_key: String | Nil)
|
||||||
failed_files = [] of String
|
failed_files = [] of String
|
||||||
ip_address = env.request.headers.try &.["X-Forwarded-For"]? ? env.request.headers.["X-Forwarded-For"] : env.request.remote_address.to_s.split(":").first
|
|
||||||
protocol = env.request.headers.try &.["X-Forwarded-Proto"]? ? env.request.headers["X-Forwarded-Proto"] : "http"
|
|
||||||
host = env.request.headers.try &.["X-Forwarded-Host"]? ? env.request.headers["X-Forwarded-Host"] : env.request.headers["Host"]
|
|
||||||
# X-Forwarded-For if behind a reverse proxy and the header is set in the reverse
|
# X-Forwarded-For if behind a reverse proxy and the header is set in the reverse
|
||||||
# proxy configuration.
|
# proxy configuration.
|
||||||
if files.empty?
|
if files.empty?
|
||||||
|
@ -166,8 +160,6 @@ module Handling
|
||||||
end
|
end
|
||||||
|
|
||||||
def retrieve_file(env)
|
def retrieve_file(env)
|
||||||
protocol = env.request.headers.try &.["X-Forwarded-Proto"]? ? env.request.headers["X-Forwarded-Proto"] : "http"
|
|
||||||
host = env.request.headers.try &.["X-Forwarded-Host"]? ? env.request.headers["X-Forwarded-Host"] : env.request.headers["Host"]
|
|
||||||
begin
|
begin
|
||||||
fileinfo = SQL.query_all("SELECT filename, original_filename, uploaded_at, extension, checksum, thumbnail
|
fileinfo = SQL.query_all("SELECT filename, original_filename, uploaded_at, extension, checksum, thumbnail
|
||||||
FROM #{CONFIG.dbTableName}
|
FROM #{CONFIG.dbTableName}
|
||||||
|
@ -224,6 +216,7 @@ module Handling
|
||||||
json.field "maxUploadSize", CONFIG.size_limit
|
json.field "maxUploadSize", CONFIG.size_limit
|
||||||
json.field "thumbnailGeneration", CONFIG.generateThumbnails
|
json.field "thumbnailGeneration", CONFIG.generateThumbnails
|
||||||
json.field "filenameLength", CONFIG.fileameLength
|
json.field "filenameLength", CONFIG.fileameLength
|
||||||
|
json.field "alternativeDomains", CONFIG.alternativeDomains
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -265,9 +258,8 @@ module Handling
|
||||||
end
|
end
|
||||||
|
|
||||||
def sharex_config(env)
|
def sharex_config(env)
|
||||||
protocol = env.request.headers.try &.["X-Forwarded-Proto"]? ? env.request.headers["X-Forwarded-Proto"] : "http"
|
|
||||||
host = env.request.headers.try &.["X-Forwarded-Host"]? ? env.request.headers["X-Forwarded-Host"] : env.request.headers["Host"]
|
|
||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
|
# So it's able to download the file instead of displaying it
|
||||||
env.response.headers["Content-Disposition"] = "attachment; filename=\"#{host}.sxcu\""
|
env.response.headers["Content-Disposition"] = "attachment; filename=\"#{host}.sxcu\""
|
||||||
return %({
|
return %({
|
||||||
"Version": "14.0.1",
|
"Version": "14.0.1",
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
require "./http-errors"
|
require "./http-errors"
|
||||||
|
|
||||||
|
macro ip_address
|
||||||
|
env.request.headers.try &.["X-Forwarded-For"]? || env.request.remote_address.to_s.split(":").first
|
||||||
|
end
|
||||||
|
|
||||||
|
macro protocol
|
||||||
|
env.request.headers.try &.["X-Forwarded-Proto"]? || "http"
|
||||||
|
end
|
||||||
|
|
||||||
|
macro host
|
||||||
|
env.request.headers.try &.["X-Forwarded-Host"]? || env.request.headers["Host"]
|
||||||
|
end
|
||||||
|
|
||||||
module Routing
|
module Routing
|
||||||
|
extend self
|
||||||
@@exit_nodes = Array(String).new
|
@@exit_nodes = Array(String).new
|
||||||
if CONFIG.blockTorAddresses
|
if CONFIG.blockTorAddresses
|
||||||
spawn do
|
spawn do
|
||||||
|
@ -16,17 +29,15 @@ module Routing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
before_post do |env|
|
before_post do |env|
|
||||||
ip_address = env.request.headers.try &.["X-Forwarded-For"]? ? env.request.headers.["X-Forwarded-For"] : env.request.remote_address.to_s.split(":").first
|
|
||||||
if @@exit_nodes.includes?(ip_address)
|
if @@exit_nodes.includes?(ip_address)
|
||||||
halt env, status_code: 401, response: error401(CONFIG.torMessage)
|
halt env, status_code: 401, response: error401(CONFIG.torMessage)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.register_all
|
def register_all
|
||||||
get "/" do |env|
|
get "/" do |env|
|
||||||
files_hosted = SQL.query_one "SELECT COUNT (filename) FROM files", as: Int32
|
files_hosted = SQL.query_one "SELECT COUNT (filename) FROM files", as: Int32
|
||||||
host = env.request.headers["Host"]
|
|
||||||
render "src/views/index.ecr"
|
render "src/views/index.ecr"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,12 +49,6 @@ module Routing
|
||||||
Handling.upload_url(env)
|
Handling.upload_url(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
if CONFIG.adminEnabled
|
|
||||||
post "/api/admin/delete" do |env|
|
|
||||||
Handling::Admin.delete_file(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
get "/:filename" do |env|
|
get "/:filename" do |env|
|
||||||
Handling.retrieve_file(env)
|
Handling.retrieve_file(env)
|
||||||
end
|
end
|
||||||
|
@ -63,5 +68,15 @@ module Routing
|
||||||
get "/sharex.sxcu" do |env|
|
get "/sharex.sxcu" do |env|
|
||||||
Handling.sharex_config(env)
|
Handling.sharex_config(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.register_admin
|
||||||
|
end
|
||||||
|
|
||||||
|
def register_admin
|
||||||
|
if CONFIG.adminEnabled
|
||||||
|
post "/api/admin/delete" do |env|
|
||||||
|
Handling::Admin.delete_file(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
14
src/utils.cr
14
src/utils.cr
|
@ -87,11 +87,11 @@ module Utils
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
def hash_file(file_path : String)
|
def hash_file(file_path : String) : String
|
||||||
Digest::SHA1.hexdigest &.file(file_path)
|
Digest::SHA1.hexdigest &.file(file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hash_io(file_path : IO)
|
def hash_io(file_path : IO) : String
|
||||||
Digest::SHA1.hexdigest &.update(file_path)
|
Digest::SHA1.hexdigest &.update(file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -191,12 +191,12 @@ module Utils
|
||||||
resp = HTTP::Client.get(CONFIG.torExitNodesUrl) do |res|
|
resp = HTTP::Client.get(CONFIG.torExitNodesUrl) do |res|
|
||||||
if res.success? && res.status_code == 200
|
if res.success? && res.status_code == 200
|
||||||
begin
|
begin
|
||||||
File.open(CONFIG.torExitNodesFile, "w") do |output|
|
File.open(CONFIG.torExitNodesFile, "w") do |output|
|
||||||
IO.copy(res.body_io, output)
|
IO.copy(res.body_io, output)
|
||||||
|
end
|
||||||
|
rescue ex
|
||||||
|
LOGGER.error "Failed to write to file: #{ex.message}"
|
||||||
end
|
end
|
||||||
rescue ex
|
|
||||||
LOGGER.error "Failed to write to file: #{ex.message}"
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
LOGGER.error "Failed to retrieve exit nodes list. Status Code: #{res.status_code}"
|
LOGGER.error "Failed to retrieve exit nodes list. Status Code: #{res.status_code}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,11 +22,22 @@
|
||||||
<div>
|
<div>
|
||||||
<div style="text-align:center;">
|
<div style="text-align:center;">
|
||||||
<p>
|
<p>
|
||||||
<a href='./chatterino.png'>Chatterino Config</a> | <a href='./sharex.sxcu'>ShareX Config</a> | <a href='https://codeberg.org/Fijxu/file-uploader-crystal'>file-uploader-crystal (BETA <%= CURRENT_TAG %> - <%= CURRENT_VERSION %> @ <%= CURRENT_BRANCH %>)</a>
|
<a href='./chatterino.png'>Chatterino Config</a> |
|
||||||
|
<a href='./sharex.sxcu'>ShareX Config</a> |
|
||||||
|
<a href='https://codeberg.org/Fijxu/file-uploader-crystal'>
|
||||||
|
file-uploader-crystal (BETA <%= CURRENT_TAG %> - <%= CURRENT_VERSION %> @ <%= CURRENT_BRANCH %>)
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
<p>Archivos alojados: <%= files_hosted %></p>
|
<p>Archivos alojados: <%= files_hosted %></p>
|
||||||
<% if CONFIG.blockTorAddresses %>
|
<% if CONFIG.blockTorAddresses %>
|
||||||
<p style="color: red"><%= CONFIG.torMessage %></p>
|
<p style="color: red"><%= CONFIG.torMessage %></p>
|
||||||
|
<% end %>
|
||||||
|
<% if !CONFIG.alternativeDomains.empty? %>
|
||||||
|
<p>
|
||||||
|
<% CONFIG.alternativeDomains.each do | domain | %>
|
||||||
|
<a href="https://<%= domain %>"><%= domain %></a>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue