Add dynamic anonymous redirect service setting

This commit is contained in:
JonnyWong16 2021-10-24 21:27:27 -07:00
parent c13b1a67f2
commit ecb66f39c9
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
4 changed files with 48 additions and 9 deletions

View file

@ -640,14 +640,25 @@
</div>
</div>
<div class="form-group advanced-setting">
<label for="anon_redirect">Anonymous Redirect</label>
<div class="row">
<div class="col-md-4">
<input type="text" class="form-control" id="anon_redirect" name="anon_redirect" value="${config['anon_redirect']}" size="30">
<div class="checkbox advanced-setting">
<label>
<input type="checkbox" name="anon_redirect_dynamic" id="anon_redirect_dynamic" value="1" ${config['anon_redirect_dynamic']} /> Use Dynamic Anonymous Redirect Service
</label>
<p class="help-block">
Allow Tautulli to use the dynamic anonymous redirect service listed <a href="${anon_url('https://tautulli.com/anonymizer.txt')}" target="_blank" rel="noreferrer">here</a>.
Disable to specify your own service.
</p>
</div>
<div id="anon_redirect_options">
<div class="form-group advanced-setting">
<label for="anon_redirect">Anonymous Redirect Service</label>
<div class="row">
<div class="col-md-4">
<input type="text" class="form-control" id="anon_redirect" name="anon_redirect" value="${config['anon_redirect']}" size="30">
</div>
</div>
<p class="help-block">Backlink protection via anonymizer service, must end in "?". Leave blank to disable.</p>
</div>
<p class="help-block">Backlink protection via anonymizer service, must end in "?".</p>
</div>
<div class="padded-header">
@ -2363,6 +2374,7 @@ $(document).ready(function() {
initConfigCheckbox('#api_enabled');
initConfigCheckbox('#enable_https');
initConfigCheckbox('#anon_redirect_dynamic', null, true);
initConfigCheckbox('#https_create_cert');
initConfigCheckbox('#check_github');
initConfigCheckbox('#monitor_pms_updates');

View file

@ -76,7 +76,8 @@ _CONFIG_DEFINITIONS = {
'PMS_UPDATE_CHECK_INTERVAL': (int, 'Advanced', 24),
'PMS_WEB_URL': (str, 'PMS', 'https://app.plex.tv/desktop'),
'TIME_FORMAT': (str, 'General', 'HH:mm'),
'ANON_REDIRECT': (str, 'General', 'https://www.nullrefer.com/?'),
'ANON_REDIRECT': (str, 'General', ''),
'ANON_REDIRECT_DYNAMIC': (int, 'General', 1),
'API_ENABLED': (int, 'General', 1),
'API_KEY': (str, 'General', ''),
'API_SQL': (int, 'General', 0),

View file

@ -775,7 +775,31 @@ def anon_url(*url):
"""
Return a URL string consisting of the Anonymous redirect URL and an arbitrary number of values appended.
"""
return '' if None in url else '%s%s' % (plexpy.CONFIG.ANON_REDIRECT, ''.join(str(s) for s in url))
if plexpy.CONFIG.ANON_REDIRECT_DYNAMIC:
cache_time = timestamp()
cache_filepath = os.path.join(plexpy.CONFIG.CACHE_DIR, 'anonymizer.json')
try:
with open(cache_filepath, 'r', encoding='utf-8') as cache_file:
cache_data = json.load(cache_file)
if cache_time - cache_data['_cache_time'] < 86400: # 24 hours
anon_redirect = cache_data['anon_redirect']
else:
raise
except:
try:
anon_redirect = request.request_content('https://tautulli.com/anonymizer.txt').decode('utf-8')
cache_data = {
'anon_redirect': anon_redirect,
'_cache_time': cache_time
}
with open(cache_filepath, 'w', encoding='utf-8') as cache_file:
json.dump(cache_data, cache_file)
except:
anon_redirect = plexpy.CONFIG.ANON_REDIRECT
else:
anon_redirect = plexpy.CONFIG.ANON_REDIRECT
return '' if None in url else '%s%s' % (anon_redirect, ''.join(str(s) for s in url))
def get_img_service(include_self=False):

View file

@ -3143,6 +3143,7 @@ class WebInterface(object):
"https_ip": plexpy.CONFIG.HTTPS_IP,
"http_base_url": plexpy.CONFIG.HTTP_BASE_URL,
"anon_redirect": plexpy.CONFIG.ANON_REDIRECT,
"anon_redirect_dynamic": checked(plexpy.CONFIG.ANON_REDIRECT_DYNAMIC),
"api_enabled": checked(plexpy.CONFIG.API_ENABLED),
"api_key": plexpy.CONFIG.API_KEY,
"update_db_interval": plexpy.CONFIG.UPDATE_DB_INTERVAL,
@ -3265,7 +3266,8 @@ class WebInterface(object):
"allow_guest_access", "cache_images", "http_proxy", "notify_concurrent_by_ip",
"history_table_activity", "plexpy_auto_update",
"themoviedb_lookup", "tvmaze_lookup", "musicbrainz_lookup", "http_plex_admin",
"newsletter_self_hosted", "newsletter_inline_styles", "sys_tray_icon"
"newsletter_self_hosted", "newsletter_inline_styles", "sys_tray_icon",
"anon_redirect_dynamic"
]
for checked_config in checked_configs:
if checked_config not in kwargs: