Skip to content

Commit

Permalink
Feat: return proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Dec 11, 2023
1 parent 55506d6 commit 7eab193
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .env.docker.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ TELEGRAM_API_HASH=
# FATAL_ERROR = 0; ERROR = 1; WARNING = 2; const NOTICE = 3; VERBOSE = 4; ULTRA_VERBOSE = 5;
LOGGER_LEVEL=2

# TELEGRAM SOCKS5 PROXY (optional)
TELEGRAM_PROXY_ADDRESS=
TELEGRAM_PROXY_PORT=
TELEGRAM_PROXY_USERNAME=
TELEGRAM_PROXY_PASSWORD=

# DB
# memory
# Keep all data in memory/session file.
Expand Down
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ TELEGRAM_API_HASH=
# FATAL_ERROR = 0; ERROR = 1; WARNING = 2; const NOTICE = 3; VERBOSE = 4; ULTRA_VERBOSE = 5;
LOGGER_LEVEL=2

# TELEGRAM SOCKS5 PROXY (optional)
TELEGRAM_PROXY_ADDRESS=
TELEGRAM_PROXY_PORT=
TELEGRAM_PROXY_USERNAME=
TELEGRAM_PROXY_PASSWORD=

# DB
# memory
# Keep all data in memory/session file.
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,24 @@ Each session stored in `sessions/{$session}.madeline`. Nested folders supported.

```json
{
"connection_settings": {
"all": {
"proxy": "\\SocksProxy",
"proxy_extra": {
"address": "127.0.0.1",
"port": 1234,
"username": "user",
"password": "pass"
}
"connection": {
"proxies": {
"\\danog\\MadelineProto\\Stream\\Proxy\\SocksProxy": [
{
"address": "127.0.0.1",
"port": 1234,
"username": "user",
"password": "pass"
}
],
"\\danog\\MadelineProto\\Stream\\Proxy\\HttpProxy": [
{
"address": "127.0.0.1",
"port": 1234,
"username": "user",
"password": "pass"
}
]
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
'rpc_drop_timeout' => 11,
],
'connection' => [
'max_media_socket_count' => 10
'max_media_socket_count' => 10,
'proxies' => [
'\danog\MadelineProto\Stream\Proxy\SocksProxy' => [
[
"address" => (string)getenv('TELEGRAM_PROXY_ADDRESS'),
"port"=> (int)getenv('TELEGRAM_PROXY_PORT'),
"username"=> (string)getenv('TELEGRAM_PROXY_USERNAME'),
"password"=> (string)getenv('TELEGRAM_PROXY_PASSWORD'),
],
]
]
],
'serialization' => [
'interval' => 600,
Expand Down Expand Up @@ -63,6 +73,10 @@
]
];

if (empty($settings['telegram']['connection']['proxies']['\danog\MadelineProto\Stream\Proxy\SocksProxy'][0]['address'])) {
$settings['telegram']['connection']['proxies'] = [];
}

if (empty($settings['telegram']['app_info']['api_id'])) {
throw new InvalidArgumentException('Need to fill TELEGRAM_API_ID in .env.docker or .env');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static function getWrapper(API $madelineProto): APIWrapper

private static function getSettingsFromArray(string $session, array $settings, SettingsAbstract $settingsObject = new Settings()): SettingsAbstract {
foreach ($settings as $key => $value) {
if (is_array($value)) {
if (is_array($value) && $key !== 'proxies') {
if ($key === 'db' && isset($value['type'])) {
$type = match ($value['type']) {
'memory' => new Settings\Database\Memory(),
Expand Down

0 comments on commit 7eab193

Please sign in to comment.