-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add http and socks proxy support --------- Co-authored-by: Dmitry Misharov <[email protected]>
- Loading branch information
1 parent
69a70ed
commit d451b52
Showing
16 changed files
with
1,713 additions
and
194 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import json | ||
from typing import TYPE_CHECKING | ||
|
||
import xbmc | ||
|
||
if TYPE_CHECKING: | ||
from resources.lib.plugin import Plugin | ||
|
||
|
||
class XbmcSettings: | ||
def __init__(self, plugin: "Plugin") -> None: | ||
self.plugin = plugin | ||
|
||
def get_setting(self, setting_id: str): | ||
# https://kodi.wiki/view/JSON-RPC_API/v13#Settings.GetSettingValue | ||
try: | ||
self.plugin.logger.debug(f"Try to get system setting: {setting_id}") | ||
response = xbmc.executeJSONRPC( | ||
"{" | ||
'"jsonrpc": "2.0",' | ||
'"method": "Settings.GetSettingValue",' | ||
'"params": ' | ||
f'{{ "setting": "{setting_id}" }},' | ||
'"id": 1' | ||
"}" | ||
) | ||
# Response example: | ||
# { "id": 1, "jsonrpc": "2.0", "result": { "value": "some data" } } | ||
self.plugin.logger.debug(f"JSON RPC Response: {response}") | ||
setting = json.loads(str(response)) | ||
return setting["result"]["value"] | ||
except Exception as exception: | ||
self.plugin.logger.error(f"JSON RPC Exception: {exception}") | ||
return None | ||
|
||
|
||
class XbmcProxySettings(XbmcSettings): | ||
def proxy_type(self, type: int) -> str: | ||
proxy_types = { | ||
0: "http", | ||
1: "socks4", | ||
2: "socks4a", | ||
3: "socks5", | ||
4: "socks5h", # SOCKS5 with remote DNS resolving | ||
5: "https", | ||
} | ||
try: | ||
self.plugin.logger.debug(f"Parsing system proxy type: {type} -> {proxy_types[type]}") | ||
return proxy_types[type] | ||
except KeyError: | ||
self.plugin.logger.warning(f"Proxy type '{type}' is unknown") | ||
return "" | ||
|
||
@property | ||
def is_enabled(self) -> bool: | ||
return self.get_setting("network.usehttpproxy") or False | ||
|
||
@property | ||
def type(self) -> str: | ||
return self.proxy_type(int(self.get_setting("network.httpproxytype"))) or "" | ||
|
||
@property | ||
def host(self) -> str: | ||
return self.get_setting("network.httpproxyserver") or "" | ||
|
||
@property | ||
def port(self) -> int: | ||
return int(self.get_setting("network.httpproxyport")) or 0 | ||
|
||
@property | ||
def username(self) -> str | None: | ||
return self.get_setting("network.httpproxyusername") or None | ||
|
||
@property | ||
def password(self) -> str | None: | ||
return self.get_setting("network.httpproxypassword") or None | ||
|
||
@property | ||
def is_correct(self): | ||
return len(self.host) > 3 and self.port > 0 | ||
|
||
@property | ||
def is_http(self) -> bool: | ||
return self.type in ["http", "https"] | ||
|
||
@property | ||
def is_socks(self) -> bool: | ||
return self.type in ["socks4", "socks4a", "socks5", "socks5r"] | ||
|
||
@property | ||
def is_socks4(self) -> bool: | ||
return self.type in ["socks4", "socks4a"] | ||
|
||
@property | ||
def is_socks5(self) -> bool: | ||
return self.type in ["socks5", "socks5r"] | ||
|
||
@property | ||
def with_auth(self) -> bool: | ||
return bool(self.username and self.password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Change Log | ||
|
||
Brief descriptions of changes will be logged here. Note that unless otherwise specified, all future versions should be backwards compatible with older versions. | ||
|
||
## [1.6.8] - 2017-12-21 | ||
- Remove support for EOL Python 3.3 | ||
|
||
## [1.6.7] - 2017-03-22 | ||
- Make SocksiPy legacy functions kwarg-compatible. See issue [#71](https://github.com/Anorov/PySocks/pull/71). | ||
- Use setuptools in setup.py to support wheel. See issue [#73](https://github.com/Anorov/PySocks/pull/73). | ||
- Test and logging enhancements | ||
|
||
## [1.6.6] - 2017-01-29 | ||
- Full test suite finally added | ||
- Travis CI enabled for project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright 2006 Dan-Haim. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. Neither the name of Dan Haim nor the names of his contributors may be used | ||
to endorse or promote products derived from this software without specific | ||
prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY DAN HAIM "AS IS" AND ANY EXPRESS OR IMPLIED | ||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | ||
EVENT SHALL DAN HAIM OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA | ||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMANGE. |
Oops, something went wrong.