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
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
client = make_client(URI.parse(host), region)
client.get(url, headers) do |response|
@ -4694,6 +4700,13 @@ get "/videoplayback" do |env|
rescue ex
end
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
first_chunk = true
range_start, range_end = parse_range(env.request.headers["Range"]?)

View file

@ -96,6 +96,19 @@ struct Config
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({
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
@ -123,6 +136,7 @@ struct Config
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.
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

View file

@ -1292,6 +1292,14 @@ def process_video_params(query, preferences)
related_videos = related_videos == 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"]?
video_start = decode_time(query["t"])
end

View file

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

View file

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

View file

@ -98,7 +98,7 @@ var video_data = {
<% end %>
</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>
<% else %>
<form class="pure-form pure-form-stacked" action="/latest_version" method="get" rel="noopener" target="_blank">