diff --git a/bazarr.py b/bazarr.py index 6fc73ba46..074882325 100644 --- a/bazarr.py +++ b/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) @@ -883,6 +893,35 @@ def save_settings(): if after != before: 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() diff --git a/get_settings.py b/get_settings.py index 36c5d303d..219936351 100644 --- a/get_settings.py +++ b/get_settings.py @@ -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: diff --git a/init.py b/init.py index 254a6087b..e0fa46d66 100644 --- a/init.py +++ b/init.py @@ -156,6 +156,18 @@ except sqlite3.OperationalError: cfg.set(section, 'use_embedded_subs', "False") 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' diff --git a/requirements.txt b/requirements.txt index 8bd5f6f6e..888a3a3d0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/views/settings.tpl b/views/settings.tpl index 00b4be5b2..164c55f9d 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -1,1810 +1,1956 @@ - -
- - - - - - - - - - - - - - - -