Skip to content

Commit

Permalink
Proxy settings fixes
Browse files Browse the repository at this point in the history
- Fixes `Proxy from Elementum settings` setting

Log reported setting applied without really doing anything.

- Adds `Proxy from Elementum (resolve hosts by proxy)` setting option

Option enables default behaviour of `Elementum` in `Burst`. Option is set as new default,
existing users should not be affected by change.

- Adds choice of additional proxy protocols in settings

`SOCKS4a` (`SOCKS4` latest version with hostname resolve by proxy)
`SOCKS5h` (`SOCKS5` latest version with hostname resolve by proxy)

- Adds help label for `use_elementum_proxy` setting
  • Loading branch information
galeksandrp committed May 16, 2021
1 parent 4fc8cc4 commit c236c63
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
19 changes: 18 additions & 1 deletion burst/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
_orig_create_connection = connection.create_connection

# Proxy types
proxy_types = ["socks4", "socks5", "http", "https"]
proxy_types = ["socks4", # socks4 (hostname resolve on client)
"socks5", # socks5 (hostname resolve on client)
"http",
"https",
"socks4a", # socks4 latest version with hostname resolve by proxy
"socks5h"] # socks5 latest version with hostname resolve by proxy
elementum_proxy_types_overrides = {'socks4': 'socks4a',
'socks5': 'socks5h'}

# Disable warning from urllib
urllib3.disable_warnings()
Expand Down Expand Up @@ -182,13 +189,23 @@ def __init__(self, info=None, request_charset='utf-8', response_charset=None, is
elif proxy['enabled']:
if proxy['use_type'] == 0 and info and "proxy_url" in info:
log.debug("Setting proxy from Elementum: %s" % (info["proxy_url"]))

self.proxy_url = info["proxy_url"]
elif proxy['use_type'] == 1:
log.debug("Setting proxy with custom settings: %s" % (repr(proxy)))

if proxy['login'] or proxy['password']:
self.proxy_url = "{0}://{1}:{2}@{3}:{4}".format(proxy['type'], proxy['login'], proxy['password'], proxy['host'], proxy['port'])
else:
self.proxy_url = "{0}://{1}:{2}".format(proxy['type'], proxy['host'], proxy['port'])
if proxy['use_type'] == 2 and info and "proxy_url" in info:
log.debug("Setting proxy with hosts resolve from Elementum: %s" % (info["proxy_url"]))

proxy_url_scheme_separator = '://'
elementum_proxy_url_parts = info["proxy_url"].split(proxy_url_scheme_separator)
elementum_proxy_url_prefix = elementum_proxy_url_parts[0].lower()
if elementum_proxy_url_prefix in elementum_proxy_types_overrides:
self.proxy_url = proxy_url_scheme_separator.join([elementum_proxy_types_overrides[elementum_proxy_url_prefix]] + elementum_proxy_url_parts[1:])

if self.proxy_url:
self.session.proxies = {
Expand Down
18 changes: 17 additions & 1 deletion resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ msgid "Use proxy settings"
msgstr ""

msgctxt "#32107"
msgid "Proxy from Elementum settings"
msgid "From Elementum settings"
msgstr ""

msgctxt "#32108"
Expand Down Expand Up @@ -354,3 +354,19 @@ msgstr ""
msgctxt "#32135"
msgid "Belarusian"
msgstr ""

msgctxt "#32136"
msgid "SOCKS4a"
msgstr ""

msgctxt "#32137"
msgid "SOCKS5h"
msgstr ""

msgctxt "#32138"
msgid "From Elementum settings (resolve hosts by proxy)"
msgstr ""

msgctxt "#32139"
msgid "First enable built-in HTTP proxy in Elementum"
msgstr ""
12 changes: 10 additions & 2 deletions resources/language/Russian/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ msgid "Use proxy settings"
msgstr "Вид настроек прокси"

msgctxt "#32107"
msgid "Proxy from Elementum settings"
msgstr "Прокси из настроек Elementum"
msgid "From Elementum settings"
msgstr "Из настроек Elementum"

msgctxt "#32108"
msgid "Custom settings"
Expand Down Expand Up @@ -354,3 +354,11 @@ msgstr "Качество видео"
msgctxt "#32135"
msgid "Belarusian"
msgstr "Белорусский"

msgctxt "#32138"
msgid "From Elementum settings (resolve hosts by proxy)"
msgstr "Из настроек Elementum (разрешать имена на прокси)"

msgctxt "#32139"
msgid "First enable built-in HTTP proxy in Elementum"
msgstr "Сперва включите встроенный HTTP прокси в Elementum"
18 changes: 17 additions & 1 deletion resources/language/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ msgid "Use proxy settings"
msgstr ""

msgctxt "#32107"
msgid "Proxy from Elementum settings"
msgid "From Elementum settings"
msgstr ""

msgctxt "#32108"
Expand Down Expand Up @@ -354,3 +354,19 @@ msgstr ""
msgctxt "#32135"
msgid "Belarusian"
msgstr ""

msgctxt "#32136"
msgid "SOCKS4a"
msgstr ""

msgctxt "#32137"
msgid "SOCKS5h"
msgstr ""

msgctxt "#32138"
msgid "From Elementum settings (resolve hosts by proxy)"
msgstr ""

msgctxt "#32139"
msgid "First enable built-in HTTP proxy in Elementum"
msgstr ""
5 changes: 3 additions & 2 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- General -->
<category label="32000">
<setting label="32125" id="use_elementum_proxy" type="bool" default="true" />
<setting id="elementum_proxy_help" label="32139" type="text" enable="false" subsetting="true" />

<setting label="32084" id="use_public_dns" type="bool" default="false" enable="eq(-1,false)" />
<setting id="public_dns_list" label="32093" type="text" default="8.8.8.8, 8.8.4.4, 9.9.9.9" enable="eq(-1,true) + eq(-2,false)" />
Expand Down Expand Up @@ -389,8 +390,8 @@
<category label="32095">
<setting label="32095" type="lsep" />
<setting id="proxy_enabled" label="32096" type="bool" default="false" />
<setting id="proxy_use_type" label="32106" type="enum" default="0" subsetting="true" lvalues="32107|32108" enable="eq(-1,true)" />
<setting id="proxy_type" label="32101" type="enum" default="1" subsetting="true" lvalues="32102|32103|32104|32105" enable="eq(-1,1)" />
<setting id="proxy_use_type" label="32106" type="enum" default="2" subsetting="true" lvalues="32107|32108|32138" enable="eq(-1,true)" />
<setting id="proxy_type" label="32101" type="enum" default="1" subsetting="true" lvalues="32102|32103|32104|32105|32136|32137" enable="eq(-1,1)" />
<setting id="proxy_host" label="32097" type="text" default="" subsetting="true" enable="eq(-2,1)" />
<setting id="proxy_port" label="32098" type="number" default="1080" subsetting="true" enable="eq(-3,1)" />
<setting id="proxy_login" label="32099" type="text" default="" subsetting="true" enable="eq(-4,1)" />
Expand Down

0 comments on commit c236c63

Please sign in to comment.