mirror of https://github.com/morpheus65535/bazarr
Proxy support #113
* Initial commit
* More development
* Update requirements
* Update init filr
* fix
* Added exclude settings
* Change wording
* Fix bad merge
* Hide setting if not selected proxy type
* revert disabled update check
* Fix for APScheduler import
* Revert "Fix for APScheduler import"
This reverts commit 0f4744d2c8
.
* Fix som Bugs
* Fix som Bugs
* Dynamicaly add or remove form validation rules for proxy
This commit is contained in:
parent
26ac122548
commit
4416799122
47
bazarr.py
47
bazarr.py
|
@ -18,7 +18,7 @@ from init import *
|
|||
from update_db import *
|
||||
|
||||
|
||||
from get_settings import get_general_settings
|
||||
from get_settings import get_general_settings, get_proxy_settings
|
||||
import logging
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
|
||||
|
@ -57,6 +57,16 @@ def configure_logging():
|
|||
|
||||
configure_logging()
|
||||
|
||||
import requests
|
||||
if get_proxy_settings()[0] != 'None':
|
||||
if get_proxy_settings()[3] != '' and get_proxy_settings()[4] != '':
|
||||
proxy = get_proxy_settings()[0] + '://' + get_proxy_settings()[3] + ':' + get_proxy_settings()[4] + '@' + get_proxy_settings()[1] + ':' + get_proxy_settings()[2]
|
||||
else:
|
||||
proxy = get_proxy_settings()[0] + '://' + get_proxy_settings()[1] + ':' + get_proxy_settings()[2]
|
||||
os.environ['HTTP_PROXY'] = str(proxy)
|
||||
os.environ['HTTPS_PROXY'] = str(proxy)
|
||||
os.environ['NO_PROXY'] = str(get_proxy_settings()[5])
|
||||
|
||||
from bottle import route, run, template, static_file, request, redirect, response, HTTPError, app
|
||||
import bottle
|
||||
bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__), 'views/'))
|
||||
|
@ -68,7 +78,6 @@ from cork import Cork
|
|||
from json import dumps
|
||||
import itertools
|
||||
import operator
|
||||
import requests
|
||||
import pretty
|
||||
from datetime import datetime, timedelta
|
||||
from io import BytesIO
|
||||
|
@ -768,13 +777,14 @@ def settings():
|
|||
settings_notifier = c.fetchall()
|
||||
c.close()
|
||||
|
||||
from get_settings import get_general_settings, get_auth_settings, get_radarr_settings, get_sonarr_settings
|
||||
from get_settings import get_general_settings, get_proxy_settings, get_auth_settings, get_radarr_settings, get_sonarr_settings
|
||||
settings_general = get_general_settings()
|
||||
settings_proxy = get_proxy_settings()
|
||||
settings_auth = get_auth_settings()
|
||||
settings_sonarr = get_sonarr_settings()
|
||||
settings_radarr = get_radarr_settings()
|
||||
|
||||
return template('settings', __file__=__file__, bazarr_version=bazarr_version, settings_general=settings_general, settings_auth=settings_auth, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr, settings_radarr=settings_radarr, settings_notifier=settings_notifier, base_url=base_url)
|
||||
return template('settings', __file__=__file__, bazarr_version=bazarr_version, settings_general=settings_general, settings_proxy=settings_proxy, settings_auth=settings_auth, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr, settings_radarr=settings_radarr, settings_notifier=settings_notifier, base_url=base_url)
|
||||
|
||||
@route(base_url + 'save_settings', method='POST')
|
||||
@custom_auth_basic(check_credentials)
|
||||
|
@ -884,6 +894,35 @@ def save_settings():
|
|||
configured()
|
||||
get_general_settings()
|
||||
|
||||
settings_proxy = get_proxy_settings()
|
||||
|
||||
if not cfg.has_section('proxy'):
|
||||
cfg.add_section('proxy')
|
||||
|
||||
settings_proxy_type = request.forms.get('settings_proxy_type')
|
||||
settings_proxy_url = request.forms.get('settings_proxy_url')
|
||||
settings_proxy_port = request.forms.get('settings_proxy_port')
|
||||
settings_proxy_username = request.forms.get('settings_proxy_username')
|
||||
settings_proxy_password = request.forms.get('settings_proxy_password')
|
||||
settings_proxy_exclude = request.forms.get('settings_proxy_exclude')
|
||||
|
||||
before_proxy_password = (unicode(settings_proxy[0]), unicode(settings_proxy[5]))
|
||||
if before_proxy_password[0] != settings_proxy_type:
|
||||
configured()
|
||||
if before_proxy_password[1] == settings_proxy_password:
|
||||
cfg.set('proxy', 'type', text_type(settings_proxy_type))
|
||||
cfg.set('proxy', 'url', text_type(settings_proxy_url))
|
||||
cfg.set('proxy', 'port', text_type(settings_proxy_port))
|
||||
cfg.set('proxy', 'username', text_type(settings_proxy_username))
|
||||
cfg.set('proxy', 'exclude', text_type(settings_proxy_exclude))
|
||||
else:
|
||||
cfg.set('proxy', 'type', text_type(settings_proxy_type))
|
||||
cfg.set('proxy', 'url', text_type(settings_proxy_url))
|
||||
cfg.set('proxy', 'port', text_type(settings_proxy_port))
|
||||
cfg.set('proxy', 'username', text_type(settings_proxy_username))
|
||||
cfg.set('proxy', 'password', text_type(settings_proxy_password))
|
||||
cfg.set('proxy', 'exclude', text_type(settings_proxy_exclude))
|
||||
|
||||
settings_auth = get_auth_settings()
|
||||
|
||||
settings_auth_type = request.forms.get('settings_auth_type')
|
||||
|
|
|
@ -209,6 +209,55 @@ def get_auth_settings():
|
|||
return [type, username, password]
|
||||
|
||||
|
||||
def get_proxy_settings():
|
||||
cfg = ConfigParser()
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
cfg.read_file(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if cfg.has_section('proxy'):
|
||||
if cfg.has_option('proxy', 'type'):
|
||||
proxy_type = cfg.get('proxy', 'type')
|
||||
else:
|
||||
proxy_type = 'None'
|
||||
|
||||
if cfg.has_option('proxy', 'url'):
|
||||
url = cfg.get('proxy', 'url')
|
||||
else:
|
||||
url = ''
|
||||
|
||||
if cfg.has_option('proxy', 'port'):
|
||||
port = cfg.get('proxy', 'port')
|
||||
else:
|
||||
port = ''
|
||||
|
||||
if cfg.has_option('proxy', 'username'):
|
||||
username = cfg.get('proxy', 'username')
|
||||
else:
|
||||
username = ''
|
||||
|
||||
if cfg.has_option('proxy', 'password'):
|
||||
password = cfg.get('proxy', 'password')
|
||||
else:
|
||||
password = ''
|
||||
|
||||
if cfg.has_option('proxy', 'exclude'):
|
||||
exclude = cfg.get('proxy', 'exclude')
|
||||
else:
|
||||
exclude = 'localhost,127.0.0.1'
|
||||
else:
|
||||
proxy_type = ''
|
||||
url = ''
|
||||
port = ''
|
||||
username = ''
|
||||
password = ''
|
||||
exclude = 'localhost,127.0.0.1'
|
||||
|
||||
return [proxy_type, url, port, username, password, exclude]
|
||||
|
||||
|
||||
def get_sonarr_settings():
|
||||
cfg = ConfigParser()
|
||||
try:
|
||||
|
|
12
init.py
12
init.py
|
@ -157,6 +157,18 @@ except sqlite3.OperationalError:
|
|||
cfg.set(section, 'only_monitored', "False")
|
||||
cfg.set(section, 'adaptive_searching', "False")
|
||||
|
||||
section = 'proxy'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'type', "None")
|
||||
cfg.set(section, 'url', "")
|
||||
cfg.set(section, 'port', "")
|
||||
cfg.set(section, 'username', "")
|
||||
cfg.set(section, 'password', "")
|
||||
cfg.set(section, 'exclude', "localhost,127.0.0.1")
|
||||
|
||||
section = 'auth'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
|
|
|
@ -8,17 +8,17 @@ dogpile.cache>=0.6.5
|
|||
#enzyme>=0.4.1 <-- included in /libs
|
||||
gitpython>=2.1.9
|
||||
langdetect>=1.0.7
|
||||
Pillow>=5.1.0
|
||||
py-pretty>=1
|
||||
pycountry>=18.2.23
|
||||
pytz>=2018.4
|
||||
requests>=2.18.4
|
||||
#subliminal>=2.0.5 <-- included in /libs
|
||||
tzlocal>=1.5.1
|
||||
urllib3<1.23,>=1.21.1
|
||||
#urllib3<1.23,>=1.21.1
|
||||
waitress>=1.1.0
|
||||
configparser>=3.5.0
|
||||
backports.functools-lru-cache>=1.5
|
||||
pysocks>=1.6.8
|
||||
beaker>=1.10.0
|
||||
|
||||
#Subliminal requirements
|
||||
|
|
|
@ -186,6 +186,123 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui dividing header">Proxy settings</div>
|
||||
<div class="twelve wide column">
|
||||
<div class="ui grid">
|
||||
|
||||
<div class="middle aligned row">
|
||||
<div class="right aligned four wide column">
|
||||
<label>Proxy type</label>
|
||||
</div>
|
||||
<div class="five wide column">
|
||||
<select name="settings_proxy_type" id="settings_proxy_type" class="ui fluid selection dropdown">
|
||||
<option value="None">None</option>
|
||||
<option value="http">HTTP(S)</option>
|
||||
<option value="socks4">Socks4</option>
|
||||
<option value="socks5">Socks5</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="collapsed center aligned column">
|
||||
<div class="ui basic icon" data-tooltip="Requires restart to take effect" data-inverted="">
|
||||
<i class="yellow warning sign icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapsed center aligned column">
|
||||
<div class="ui basic icon" data-tooltip="Type of your proxy." data-inverted="">
|
||||
<i class="help circle large icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="proxy_option middle aligned row">
|
||||
<div class="right aligned four wide column">
|
||||
<label>Hostname</label>
|
||||
</div>
|
||||
<div class="five wide column">
|
||||
<div class='field'>
|
||||
<div class="ui fluid input">
|
||||
<input id="settings_proxy_url" name="settings_proxy_url" type="text" value="{{settings_proxy[1]}}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="proxy_option middle aligned row">
|
||||
<div class="right aligned four wide column">
|
||||
<label>Port</label>
|
||||
</div>
|
||||
<div class="five wide column">
|
||||
<div class='field'>
|
||||
<div class="ui fluid input">
|
||||
<input id="settings_proxy_port" name="settings_proxy_port" type="text" value="{{settings_proxy[2]}}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="proxy_option middle aligned row">
|
||||
<div class="right aligned four wide column">
|
||||
<label>Username</label>
|
||||
</div>
|
||||
<div class="five wide column">
|
||||
<div class='field'>
|
||||
<div class="ui fluid input">
|
||||
<input id="settings_proxy_username" name="settings_proxy_username" type="text" value="{{settings_proxy[3]}}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapsed center aligned column">
|
||||
<div class="ui basic icon" data-tooltip="UYou only need to enter a username and password if one is required. Leave them blank otherwise" data-inverted="">
|
||||
<i class="help circle large icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="proxy_option middle aligned row">
|
||||
<div class="right aligned four wide column">
|
||||
<label>Password</label>
|
||||
</div>
|
||||
<div class="five wide column">
|
||||
<div class='field'>
|
||||
<div class="ui fluid input">
|
||||
<input id="settings_proxy_password" name="settings_proxy_password" type="password" value="{{settings_proxy[4]}}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapsed center aligned column">
|
||||
<div class="ui basic icon" data-tooltip="You only need to enter a username and password if one is required. Leave them blank otherwise" data-inverted="">
|
||||
<i class="help circle large icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="proxy_option middle aligned row">
|
||||
<div class="right aligned four wide column">
|
||||
<label>Ignored Addresses</label>
|
||||
</div>
|
||||
<div class="five wide column">
|
||||
<div class='field'>
|
||||
<div class="ui fluid input">
|
||||
<input id="settings_proxy_exclude" name="settings_proxy_exclude" type="text" value="{{settings_proxy[5]}}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapsed center aligned column">
|
||||
<div class="ui basic icon" data-tooltip="Use ',' as a separator, and '*.' as a wildcard for subdomains" data-inverted="">
|
||||
<i class="help circle large icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui dividing header">Security settings</div>
|
||||
<div class="twelve wide column">
|
||||
<div class="ui grid">
|
||||
|
@ -1528,6 +1645,8 @@
|
|||
$('#settings_loglevel').dropdown('set selected','{{!settings_general[4]}}');
|
||||
$('#settings_page_size').dropdown('clear');
|
||||
$('#settings_page_size').dropdown('set selected','{{!settings_general[21]}}');
|
||||
$('#settings_proxy_type').dropdown('clear');
|
||||
$('#settings_proxy_type').dropdown('set selected','{{!settings_proxy[0]}}');
|
||||
$('#settings_providers').dropdown('clear');
|
||||
$('#settings_providers').dropdown('set selected',{{!enabled_providers}});
|
||||
$('#settings_languages').dropdown('clear');
|
||||
|
@ -1703,6 +1822,33 @@
|
|||
})
|
||||
;
|
||||
|
||||
if ($('#settings_proxy_type').val() == "None") {
|
||||
$('.proxy_option').hide();
|
||||
$('#settings_form').form('remove rule', 'settings_proxy_url', 'empty')
|
||||
$('#settings_form').form('remove rule', 'settings_proxy_port', 'empty')
|
||||
$('#settings_form').form('remove rule', 'settings_proxy_port', 'integer[1..65535]')
|
||||
}
|
||||
else {
|
||||
$('#settings_form').form('add rule', 'settings_proxy_url', 'empty')
|
||||
$('#settings_form').form('add rule', 'settings_proxy_port', 'empty')
|
||||
$('#settings_form').form('add rule', 'settings_proxy_port', 'integer[1..65535]')
|
||||
};
|
||||
|
||||
$('#settings_proxy_type').dropdown('setting', 'onChange', function(){
|
||||
if ($('#settings_proxy_type').val() == "None") {
|
||||
$('.proxy_option').hide();
|
||||
$('#settings_form').form('remove rule', 'settings_proxy_url', 'empty')
|
||||
$('#settings_form').form('remove rule', 'settings_proxy_port', 'empty')
|
||||
$('#settings_form').form('remove rule', 'settings_proxy_port', 'integer[1..65535]')
|
||||
}
|
||||
else {
|
||||
$('.proxy_option').show();
|
||||
$('#settings_form').form('add rule', 'settings_proxy_url', 'empty')
|
||||
$('#settings_form').form('add rule', 'settings_proxy_port', 'empty')
|
||||
$('#settings_form').form('add rule', 'settings_proxy_port', 'integer[1..65535]')
|
||||
};
|
||||
});
|
||||
|
||||
$('#settings_providers').dropdown('setting', 'onChange', function(){
|
||||
$('.form').form('validate field', 'settings_subliminal_providers');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue