Add administrator option to disable proxying

This commit is contained in:
Omar Roth 2019-07-07 09:07:53 -05:00
parent 5fd3ed782f
commit 2cc25b1e6e
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2
6 changed files with 46 additions and 9 deletions

View file

@ -4667,6 +4667,12 @@ get "/videoplayback" do |env|
end end
if url.includes? "&file=seg.ts" if url.includes? "&file=seg.ts"
if CONFIG.disabled?("livestreams")
env.response.status_code = 403
error_message = "Administrator has disabled this endpoint."
next templated "error"
end
begin begin
client = make_client(URI.parse(host), region) client = make_client(URI.parse(host), region)
client.get(url, headers) do |response| client.get(url, headers) do |response|
@ -4694,6 +4700,13 @@ get "/videoplayback" do |env|
rescue ex rescue ex
end end
else else
if query_params["title"]? && CONFIG.disabled?("downloads") ||
CONFIG.disabled?("dash")
env.response.status_code = 403
error_message = "Administrator has disabled this endpoint."
next templated "error"
end
content_length = nil content_length = nil
first_chunk = true first_chunk = true
range_start, range_end = parse_range(env.request.headers["Range"]?) range_start, range_end = parse_range(env.request.headers["Range"]?)

View file

@ -96,6 +96,19 @@ struct Config
end end
end end
def disabled?(option)
case disabled = CONFIG.disable_proxy
when Bool
return disabled
when Array
if disabled.includes? option
return true
else
return false
end
end
end
YAML.mapping({ YAML.mapping({
channel_threads: Int32, # Number of threads to use for crawling videos from channels (for updating subscriptions) channel_threads: Int32, # Number of threads to use for crawling videos from channels (for updating subscriptions)
feed_threads: Int32, # Number of threads to use for updating feeds feed_threads: Int32, # Number of threads to use for updating feeds
@ -118,11 +131,12 @@ struct Config
default: Preferences.new(*ConfigPreferences.from_yaml("").to_tuple), default: Preferences.new(*ConfigPreferences.from_yaml("").to_tuple),
converter: ConfigPreferencesConverter, converter: ConfigPreferencesConverter,
}, },
dmca_content: {type: Array(String), default: [] of String}, # For compliance with DMCA, disables download widget using list of video IDs dmca_content: {type: Array(String), default: [] of String}, # For compliance with DMCA, disables download widget using list of video IDs
check_tables: {type: Bool, default: false}, # Check table integrity, automatically try to add any missing columns, create tables, etc. check_tables: {type: Bool, default: false}, # Check table integrity, automatically try to add any missing columns, create tables, etc.
cache_annotations: {type: Bool, default: false}, # Cache annotations requested from IA, will not cache empty annotations or annotations that only contain cards cache_annotations: {type: Bool, default: false}, # Cache annotations requested from IA, will not cache empty annotations or annotations that only contain cards
banner: {type: String?, default: nil}, # Optional banner to be displayed along top of page for announcements, etc. banner: {type: String?, default: nil}, # Optional banner to be displayed along top of page for announcements, etc.
hsts: {type: Bool?, default: true}, # Enables 'Strict-Transport-Security'. Ensure that `domain` and all subdomains are served securely hsts: {type: Bool?, default: true}, # Enables 'Strict-Transport-Security'. Ensure that `domain` and all subdomains are served securely
disable_proxy: {type: Bool? | Array(String)?, default: false}, # Disable proxying server-wide: options: 'dash', 'livestreams', 'downloads', 'local'
}) })
end end

View file

@ -1292,6 +1292,14 @@ def process_video_params(query, preferences)
related_videos = related_videos == 1 related_videos = related_videos == 1
video_loop = video_loop == 1 video_loop = video_loop == 1
if CONFIG.disabled?("dash") && quality == "dash"
quality = "high"
end
if CONFIG.disabled?("local") && local
local = false
end
if query["t"]? if query["t"]?
video_start = decode_time(query["t"]) video_start = decode_time(query["t"])
end end

View file

@ -6,7 +6,7 @@
<% if params.autoplay %>autoplay<% end %> <% if params.autoplay %>autoplay<% end %>
<% if params.video_loop %>loop<% end %> <% if params.video_loop %>loop<% end %>
<% if params.controls %>controls<% end %>> <% if params.controls %>controls<% end %>>
<% if hlsvp %> <% if hlsvp && !CONFIG.disabled?("livestreams") %>
<source src="<%= hlsvp %>?local=true" type="application/x-mpegURL" label="livestream"> <source src="<%= hlsvp %>?local=true" type="application/x-mpegURL" label="livestream">
<% else %> <% else %>
<% if params.listen %> <% if params.listen %>

View file

@ -35,7 +35,7 @@ function update_value(element) {
<div class="pure-control-group"> <div class="pure-control-group">
<label for="local"><%= translate(locale, "Proxy videos? ") %></label> <label for="local"><%= translate(locale, "Proxy videos? ") %></label>
<input name="local" id="local" type="checkbox" <% if preferences.local %>checked<% end %>> <input name="local" id="local" type="checkbox" <% if preferences.local && !CONFIG.disabled?("local") %>checked<% end %> <% if CONFIG.disabled?("local") %>disabled<% end %>>
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">
@ -56,7 +56,9 @@ function update_value(element) {
<label for="quality"><%= translate(locale, "Preferred video quality: ") %></label> <label for="quality"><%= translate(locale, "Preferred video quality: ") %></label>
<select name="quality" id="quality"> <select name="quality" id="quality">
<% {"dash", "hd720", "medium", "small"}.each do |option| %> <% {"dash", "hd720", "medium", "small"}.each do |option| %>
<option value="<%= option %>" <% if preferences.quality == option %> selected <% end %>><%= translate(locale, option) %></option> <% if !(option == "dash" && CONFIG.disabled?("dash")) %>
<option value="<%= option %>" <% if preferences.quality == option %> selected <% end %>><%= translate(locale, option) %></option>
<% end %>
<% end %> <% end %>
</select> </select>
</div> </div>

View file

@ -98,7 +98,7 @@ var video_data = {
<% end %> <% end %>
</p> </p>
<% if CONFIG.dmca_content.includes? video.id %> <% if CONFIG.dmca_content.includes?(video.id) || CONFIG.disabled?("downloads") %>
<p><%= translate(locale, "Download is disabled.") %></p> <p><%= translate(locale, "Download is disabled.") %></p>
<% else %> <% else %>
<form class="pure-form pure-form-stacked" action="/latest_version" method="get" rel="noopener" target="_blank"> <form class="pure-form pure-form-stacked" action="/latest_version" method="get" rel="noopener" target="_blank">