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:
halali 2018-09-16 14:38:00 +02:00 committed by morpheus65535
parent 26ac122548
commit 4416799122
5 changed files with 2062 additions and 1816 deletions

View File

@ -18,7 +18,7 @@ from init import *
from update_db import * from update_db import *
from get_settings import get_general_settings from get_settings import get_general_settings, get_proxy_settings
import logging import logging
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler
@ -57,6 +57,16 @@ def configure_logging():
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 from bottle import route, run, template, static_file, request, redirect, response, HTTPError, app
import bottle import bottle
bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__), 'views/')) 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 from json import dumps
import itertools import itertools
import operator import operator
import requests
import pretty import pretty
from datetime import datetime, timedelta from datetime import datetime, timedelta
from io import BytesIO from io import BytesIO
@ -768,13 +777,14 @@ def settings():
settings_notifier = c.fetchall() settings_notifier = c.fetchall()
c.close() 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_general = get_general_settings()
settings_proxy = get_proxy_settings()
settings_auth = get_auth_settings() settings_auth = get_auth_settings()
settings_sonarr = get_sonarr_settings() settings_sonarr = get_sonarr_settings()
settings_radarr = get_radarr_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') @route(base_url + 'save_settings', method='POST')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -883,6 +893,35 @@ def save_settings():
if after != before: if after != before:
configured() configured()
get_general_settings() 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 = get_auth_settings()

View File

@ -209,6 +209,55 @@ def get_auth_settings():
return [type, username, password] 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(): def get_sonarr_settings():
cfg = ConfigParser() cfg = ConfigParser()
try: try:

12
init.py
View File

@ -156,6 +156,18 @@ except sqlite3.OperationalError:
cfg.set(section, 'use_embedded_subs', "False") cfg.set(section, 'use_embedded_subs', "False")
cfg.set(section, 'only_monitored', "False") cfg.set(section, 'only_monitored', "False")
cfg.set(section, 'adaptive_searching', "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' section = 'auth'

View File

@ -8,17 +8,17 @@ dogpile.cache>=0.6.5
#enzyme>=0.4.1 <-- included in /libs #enzyme>=0.4.1 <-- included in /libs
gitpython>=2.1.9 gitpython>=2.1.9
langdetect>=1.0.7 langdetect>=1.0.7
Pillow>=5.1.0
py-pretty>=1 py-pretty>=1
pycountry>=18.2.23 pycountry>=18.2.23
pytz>=2018.4 pytz>=2018.4
requests>=2.18.4 requests>=2.18.4
#subliminal>=2.0.5 <-- included in /libs #subliminal>=2.0.5 <-- included in /libs
tzlocal>=1.5.1 tzlocal>=1.5.1
urllib3<1.23,>=1.21.1 #urllib3<1.23,>=1.21.1
waitress>=1.1.0 waitress>=1.1.0
configparser>=3.5.0 configparser>=3.5.0
backports.functools-lru-cache>=1.5 backports.functools-lru-cache>=1.5
pysocks>=1.6.8
beaker>=1.10.0 beaker>=1.10.0
#Subliminal requirements #Subliminal requirements

File diff suppressed because it is too large Load Diff