Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

REFACTOR (notifiers): Support HTTP and SOCKS proxies for Telegram notifier

Rostislav Dugin1f4cf296c0f1
diff --git a/backend/internal/features/notifiers/controller_test.go b/backend/internal/features/notifiers/controller_test.go
index d9089609..b4fa26b4 100644
--- a/backend/internal/features/notifiers/controller_test.go
+++ b/backend/internal/features/notifiers/controller_test.go
@@ -472,10 +472,10 @@ func Test_NotifierSensitiveDataLifecycle_AllTypes(t *testing.T) {
Name: "Test Telegram Notifier",
NotifierType: NotifierTypeTelegram,
TelegramNotifier: &telegram_notifier.TelegramNotifier{
- BotToken: "original-bot-token-12345",
- TargetChatID: "123456789",
- IsHTTPProxyEnabled: true,
- HTTPProxyURL: "http://user:[email protected]:3128",
+ BotToken: "original-bot-token-12345",
+ TargetChatID: "123456789",
+ IsProxyEnabled: true,
+ ProxyURL: "socks5://user:[email protected]:1080",
},
}
},
@@ -486,10 +486,10 @@ func Test_NotifierSensitiveDataLifecycle_AllTypes(t *testing.T) {
Name: "Updated Telegram Notifier",
NotifierType: NotifierTypeTelegram,
TelegramNotifier: &telegram_notifier.TelegramNotifier{
- BotToken: "",
- TargetChatID: "987654321",
- IsHTTPProxyEnabled: true,
- HTTPProxyURL: "",
+ BotToken: "",
+ TargetChatID: "987654321",
+ IsProxyEnabled: true,
+ ProxyURL: "",
},
}
},
@@ -504,18 +504,17 @@ func Test_NotifierSensitiveDataLifecycle_AllTypes(t *testing.T) {
assert.True(
t,
- isEncrypted(notifier.TelegramNotifier.HTTPProxyURL),
- "HTTPProxyURL should be encrypted in DB",
+ isEncrypted(notifier.TelegramNotifier.ProxyURL),
+ "ProxyURL should be encrypted in DB",
)
- decryptedProxyURL := decryptField(t, notifier.TelegramNotifier.HTTPProxyURL)
- assert.Equal(t, "http://user:[email protected]:3128", decryptedProxyURL)
- assert.True(t, notifier.TelegramNotifier.IsHTTPProxyEnabled)
+ decryptedProxyURL := decryptField(t, notifier.TelegramNotifier.ProxyURL)
+ assert.Equal(t, "socks5://user:[email protected]:1080", decryptedProxyURL)
+ assert.True(t, notifier.TelegramNotifier.IsProxyEnabled)
},
verifyHiddenData: func(t *testing.T, notifier *Notifier) {
assert.Equal(t, "", notifier.TelegramNotifier.BotToken)
- assert.Equal(t, "", notifier.TelegramNotifier.HTTPProxyURL)
- assert.True(t, notifier.TelegramNotifier.IsHTTPProxyEnabled)
- assert.True(t, notifier.TelegramNotifier.HasHTTPProxyURL)
+ assert.Equal(t, "", notifier.TelegramNotifier.ProxyURL)
+ assert.True(t, notifier.TelegramNotifier.IsProxyEnabled)
},
},
{
@@ -839,10 +838,10 @@ func Test_CreateNotifier_AllSensitiveFieldsEncryptedInDB(t *testing.T) {
Name: "Test Telegram",
NotifierType: NotifierTypeTelegram,
TelegramNotifier: &telegram_notifier.TelegramNotifier{
- BotToken: "plain-telegram-token-123",
- TargetChatID: "123456789",
- IsHTTPProxyEnabled: true,
- HTTPProxyURL: "http://proxy.example.com:8080",
+ BotToken: "plain-telegram-token-123",
+ TargetChatID: "123456789",
+ IsProxyEnabled: true,
+ ProxyURL: "http://proxy.example.com:8080",
},
}
},
@@ -857,10 +856,10 @@ func Test_CreateNotifier_AllSensitiveFieldsEncryptedInDB(t *testing.T) {
assert.True(
t,
- isEncrypted(notifier.TelegramNotifier.HTTPProxyURL),
- "HTTPProxyURL should be encrypted",
+ isEncrypted(notifier.TelegramNotifier.ProxyURL),
+ "ProxyURL should be encrypted",
)
- decryptedProxyURL := decryptField(t, notifier.TelegramNotifier.HTTPProxyURL)
+ decryptedProxyURL := decryptField(t, notifier.TelegramNotifier.ProxyURL)
assert.Equal(t, "http://proxy.example.com:8080", decryptedProxyURL)
},
},
diff --git a/backend/internal/features/notifiers/models/telegram/enums.go b/backend/internal/features/notifiers/models/telegram/enums.go
new file mode 100644
index 00000000..bb2da159
--- /dev/null
+++ b/backend/internal/features/notifiers/models/telegram/enums.go
@@ -0,0 +1,21 @@
+package telegram_notifier
+
+type ProxyScheme string
+
+const (
+ ProxySchemeHTTP ProxyScheme = "http"
+ ProxySchemeHTTPS ProxyScheme = "https"
+ ProxySchemeSOCKS5 ProxyScheme = "socks5"
+ ProxySchemeSOCKS5H ProxyScheme = "socks5h"
+)
+
+func (s ProxyScheme) IsAllowed() bool {
+ return allowedProxySchemes[s]
+}
+
+var allowedProxySchemes = map[ProxyScheme]bool{
+ ProxySchemeHTTP: true,
+ ProxySchemeHTTPS: true,
+ ProxySchemeSOCKS5: true,
+ ProxySchemeSOCKS5H: true,
+}
diff --git a/backend/internal/features/notifiers/models/telegram/model.go b/backend/internal/features/notifiers/models/telegram/model.go
index 973e1a52..08432cee 100644
--- a/backend/internal/features/notifiers/models/telegram/model.go
+++ b/backend/internal/features/notifiers/models/telegram/model.go
@@ -10,7 +10,6 @@ import (
"net/url"
"strconv"
"strings"
- "time"
"github.com/google/uuid"
@@ -18,13 +17,12 @@ import (
)
type TelegramNotifier struct {
- NotifierID uuid.UUID `json:"notifierId" gorm:"primaryKey;column:notifier_id"`
- BotToken string `json:"botToken" gorm:"not null;column:bot_token"`
- TargetChatID string `json:"targetChatId" gorm:"not null;column:target_chat_id"`
- ThreadID *int64 `json:"threadId" gorm:"column:thread_id"`
- IsHTTPProxyEnabled bool `json:"isHttpProxyEnabled" gorm:"column:is_http_proxy_enabled;type:boolean;not null;default:false"`
- HTTPProxyURL string `json:"httpProxyUrl" gorm:"column:http_proxy_url;type:text"`
- HasHTTPProxyURL bool `json:"hasHttpProxyUrl" gorm:"-"`
+ NotifierID uuid.UUID `json:"notifierId" gorm:"primaryKey;column:notifier_id"`
+ BotToken string `json:"botToken" gorm:"not null;column:bot_token"`
+ TargetChatID string `json:"targetChatId" gorm:"not null;column:target_chat_id"`
+ ThreadID *int64 `json:"threadId" gorm:"column:thread_id"`
+ IsProxyEnabled bool `json:"isProxyEnabled" gorm:"column:is_proxy_enabled;type:boolean;not null;default:false"`
+ ProxyURL string `json:"proxyUrl" gorm:"column:proxy_url;type:text"`
}
func (t *TelegramNotifier) TableName() string {
@@ -40,19 +38,18 @@ func (t *TelegramNotifier) Validate(encryptor encryption.FieldEncryptor) error {
return errors.New("target chat ID is required")
}
- if t.IsHTTPProxyEnabled {
- if t.HTTPProxyURL == "" {
- return errors.New("HTTP proxy URL is required")
+ if t.IsProxyEnabled {
+ if t.ProxyURL == "" {
+ return errors.New("proxy URL is required")
}
- proxyURL, err := encryptor.Decrypt(t.HTTPProxyURL)
+ proxyURL, err := encryptor.Decrypt(t.ProxyURL)
if err != nil {
- return fmt.Errorf("failed to decrypt HTTP proxy URL: %w", err)
+ return fmt.Errorf("failed to decrypt proxy URL: %w", err)
}
- parsedProxyURL, err := url.Parse(proxyURL)
- if err != nil || parsedProxyURL.Scheme != "http" || parsedProxyURL.Host == "" {
- return errors.New("HTTP proxy URL must be a valid http:// URL")
+ if _, err := parseProxyURL(proxyURL); err != nil {
+ return err
}
}
@@ -118,49 +115,20 @@ func (t *TelegramNotifier) Send(
return nil
}
-func (t *TelegramNotifier) buildHTTPClient(
- encryptor encryption.FieldEncryptor,
-) (*http.Client, error) {
- client := &http.Client{
- Timeout: 30 * time.Second,
- }
-
- if !t.IsHTTPProxyEnabled {
- return client, nil
- }
-
- proxyURL, err := encryptor.Decrypt(t.HTTPProxyURL)
- if err != nil {
- return nil, fmt.Errorf("failed to decrypt HTTP proxy URL: %w", err)
- }
-
- parsedProxyURL, err := url.Parse(proxyURL)
- if err != nil || parsedProxyURL.Scheme != "http" || parsedProxyURL.Host == "" {
- return nil, errors.New("HTTP proxy URL must be a valid http:// URL")
- }
-
- transport := http.DefaultTransport.(*http.Transport).Clone()
- transport.Proxy = http.ProxyURL(parsedProxyURL)
- client.Transport = transport
-
- return client, nil
-}
-
func (t *TelegramNotifier) HideSensitiveData() {
t.BotToken = ""
- t.HasHTTPProxyURL = t.IsHTTPProxyEnabled && t.HTTPProxyURL != ""
- t.HTTPProxyURL = ""
+ t.ProxyURL = ""
}
func (t *TelegramNotifier) Update(incoming *TelegramNotifier) {
t.TargetChatID = incoming.TargetChatID
t.ThreadID = incoming.ThreadID
- t.IsHTTPProxyEnabled = incoming.IsHTTPProxyEnabled
+ t.IsProxyEnabled = incoming.IsProxyEnabled
- if !incoming.IsHTTPProxyEnabled {
- t.HTTPProxyURL = ""
- } else if incoming.HTTPProxyURL != "" {
- t.HTTPProxyURL = incoming.HTTPProxyURL
+ if !incoming.IsProxyEnabled {
+ t.ProxyURL = ""
+ } else if incoming.ProxyURL != "" {
+ t.ProxyURL = incoming.ProxyURL
}
if incoming.BotToken != "" {
@@ -177,14 +145,14 @@ func (t *TelegramNotifier) EncryptSensitiveData(encryptor encryption.FieldEncryp
t.BotToken = encrypted
}
- if !t.IsHTTPProxyEnabled {
- t.HTTPProxyURL = ""
- } else if t.HTTPProxyURL != "" {
- encrypted, err := encryptor.Encrypt(t.HTTPProxyURL)
+ if !t.IsProxyEnabled {
+ t.ProxyURL = ""
+ } else if t.ProxyURL != "" {
+ encrypted, err := encryptor.Encrypt(t.ProxyURL)
if err != nil {
- return fmt.Errorf("failed to encrypt HTTP proxy URL: %w", err)
+ return fmt.Errorf("failed to encrypt proxy URL: %w", err)
}
- t.HTTPProxyURL = encrypted
+ t.ProxyURL = encrypted
}
return nil
diff --git a/backend/internal/features/notifiers/models/telegram/model_test.go b/backend/internal/features/notifiers/models/telegram/model_test.go
index c93ddcbf..b136904d 100644
--- a/backend/internal/features/notifiers/models/telegram/model_test.go
+++ b/backend/internal/features/notifiers/models/telegram/model_test.go
@@ -1,7 +1,6 @@
package telegram_notifier
import (
- "net/http"
"testing"
"github.com/stretchr/testify/assert"
@@ -18,60 +17,42 @@ func (p passthroughEncryptor) Decrypt(ciphertext string) (string, error) {
return ciphertext, nil
}
-func Test_Validate_WhenHTTPProxyEnabledWithoutURL_ReturnsError(t *testing.T) {
+func Test_Validate_WhenProxyEnabledWithoutURL_ReturnsError(t *testing.T) {
notifier := &TelegramNotifier{
- BotToken: "token",
- TargetChatID: "123456",
- IsHTTPProxyEnabled: true,
+ BotToken: "token",
+ TargetChatID: "123456",
+ IsProxyEnabled: true,
}
err := notifier.Validate(passthroughEncryptor{})
require.Error(t, err)
- assert.Contains(t, err.Error(), "HTTP proxy URL is required")
+ assert.Contains(t, err.Error(), "proxy URL is required")
}
-func Test_Validate_WhenHTTPProxyURLIsNotHTTP_ReturnsError(t *testing.T) {
+func Test_Validate_WhenProxyURLSchemeUnsupported_ReturnsError(t *testing.T) {
notifier := &TelegramNotifier{
- BotToken: "token",
- TargetChatID: "123456",
- IsHTTPProxyEnabled: true,
- HTTPProxyURL: "https://proxy.example.com:3128",
+ BotToken: "token",
+ TargetChatID: "123456",
+ IsProxyEnabled: true,
+ ProxyURL: "ftp://proxy.example.com:3128",
}
err := notifier.Validate(passthroughEncryptor{})
require.Error(t, err)
- assert.Contains(t, err.Error(), "valid http:// URL")
+ assert.Contains(t, err.Error(), "http/https/socks5/socks5h")
}
-func Test_BuildHTTPClient_WhenHTTPProxyEnabled_UsesConfiguredProxy(t *testing.T) {
+func Test_Validate_WhenProxyURLIsSocks5_ReturnsNoError(t *testing.T) {
notifier := &TelegramNotifier{
- IsHTTPProxyEnabled: true,
- HTTPProxyURL: "http://user:[email protected]:3128",
+ BotToken: "token",
+ TargetChatID: "123456",
+ IsProxyEnabled: true,
+ ProxyURL: "socks5://user:[email protected]:1080",
}
- client, err := notifier.buildHTTPClient(passthroughEncryptor{})
- require.NoError(t, err)
-
- transport, ok := client.Transport.(*http.Transport)
- require.True(t, ok)
- require.NotNil(t, transport.Proxy)
-
- req, err := http.NewRequest(http.MethodGet, "https://api.telegram.org", nil)
- require.NoError(t, err)
-
- proxyURL, err := transport.Proxy(req)
- require.NoError(t, err)
- require.NotNil(t, proxyURL)
- assert.Equal(t, "http://user:[email protected]:3128", proxyURL.String())
-}
-
-func Test_BuildHTTPClient_WhenHTTPProxyDisabled_UsesDefaultTransport(t *testing.T) {
- notifier := &TelegramNotifier{}
-
- client, err := notifier.buildHTTPClient(passthroughEncryptor{})
+ err := notifier.Validate(passthroughEncryptor{})
require.NoError(t, err)
- assert.Nil(t, client.Transport)
}
diff --git a/backend/internal/features/notifiers/models/telegram/proxies.go b/backend/internal/features/notifiers/models/telegram/proxies.go
new file mode 100644
index 00000000..19a26269
--- /dev/null
+++ b/backend/internal/features/notifiers/models/telegram/proxies.go
@@ -0,0 +1,53 @@
+package telegram_notifier
+
+import (
+ "errors"
+ "fmt"
+ "net/http"
+ "net/url"
+ "time"
+
+ "databasus-backend/internal/util/encryption"
+)
+
+func parseProxyURL(rawProxyURL string) (*url.URL, error) {
+ parsedProxyURL, err := url.Parse(rawProxyURL)
+ if err != nil || !ProxyScheme(parsedProxyURL.Scheme).IsAllowed() || parsedProxyURL.Host == "" {
+ return nil, errors.New("proxy URL must be a valid http/https/socks5/socks5h URL")
+ }
+
+ return parsedProxyURL, nil
+}
+
+func (t *TelegramNotifier) buildHTTPClient(
+ encryptor encryption.FieldEncryptor,
+) (*http.Client, error) {
+ client := &http.Client{
+ Timeout: 30 * time.Second,
+ }
+
+ if !t.IsProxyEnabled {
+ return client, nil
+ }
+
+ proxyURL, err := encryptor.Decrypt(t.ProxyURL)
+ if err != nil {
+ return nil, fmt.Errorf("failed to decrypt proxy URL: %w", err)
+ }
+
+ parsedProxyURL, err := parseProxyURL(proxyURL)
+ if err != nil {
+ return nil, err
+ }
+
+ defaultTransport, isTransport := http.DefaultTransport.(*http.Transport)
+ if !isTransport {
+ return nil, errors.New("unexpected default HTTP transport type")
+ }
+
+ transport := defaultTransport.Clone()
+ transport.Proxy = http.ProxyURL(parsedProxyURL)
+ client.Transport = transport
+
+ return client, nil
+}
diff --git a/backend/internal/features/notifiers/models/telegram/proxies_test.go b/backend/internal/features/notifiers/models/telegram/proxies_test.go
new file mode 100644
index 00000000..4ece9b85
--- /dev/null
+++ b/backend/internal/features/notifiers/models/telegram/proxies_test.go
@@ -0,0 +1,47 @@
+package telegram_notifier
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func Test_BuildHTTPClient_WhenProxyEnabled_UsesConfiguredProxy(t *testing.T) {
+ for _, proxyURL := range []string{
+ "http://user:[email protected]:3128",
+ "https://proxy.example.com:8443",
+ "socks5://user:[email protected]:1080",
+ "socks5h://proxy.example.com:1080",
+ } {
+ notifier := &TelegramNotifier{
+ IsProxyEnabled: true,
+ ProxyURL: proxyURL,
+ }
+
+ client, err := notifier.buildHTTPClient(passthroughEncryptor{})
+ require.NoError(t, err)
+
+ transport, ok := client.Transport.(*http.Transport)
+ require.True(t, ok)
+ require.NotNil(t, transport.Proxy)
+
+ req, err := http.NewRequest(http.MethodGet, "https://api.telegram.org", nil)
+ require.NoError(t, err)
+
+ resolvedProxyURL, err := transport.Proxy(req)
+ require.NoError(t, err)
+ require.NotNil(t, resolvedProxyURL)
+ assert.Equal(t, proxyURL, resolvedProxyURL.String())
+ }
+}
+
+func Test_BuildHTTPClient_WhenProxyDisabled_UsesDefaultTransport(t *testing.T) {
+ notifier := &TelegramNotifier{}
+
+ client, err := notifier.buildHTTPClient(passthroughEncryptor{})
+
+ require.NoError(t, err)
+ assert.Nil(t, client.Transport)
+}
diff --git a/backend/migrations/20260526120000_add_telegram_http_proxy.sql b/backend/migrations/20260526120000_add_telegram_http_proxy.sql
deleted file mode 100644
index 51432d55..00000000
--- a/backend/migrations/20260526120000_add_telegram_http_proxy.sql
+++ /dev/null
@@ -1,17 +0,0 @@
--- +goose Up
--- +goose StatementBegin
-
-ALTER TABLE telegram_notifiers
- ADD COLUMN is_http_proxy_enabled BOOLEAN NOT NULL DEFAULT FALSE,
- ADD COLUMN http_proxy_url TEXT;
-
--- +goose StatementEnd
-
--- +goose Down
--- +goose StatementBegin
-
-ALTER TABLE telegram_notifiers
- DROP COLUMN IF EXISTS http_proxy_url,
- DROP COLUMN IF EXISTS is_http_proxy_enabled;
-
--- +goose StatementEnd
diff --git a/backend/migrations/20260622120000_add_telegram_proxy.sql b/backend/migrations/20260622120000_add_telegram_proxy.sql
new file mode 100644
index 00000000..c50cdedb
--- /dev/null
+++ b/backend/migrations/20260622120000_add_telegram_proxy.sql
@@ -0,0 +1,17 @@
+-- +goose Up
+-- +goose StatementBegin
+
+ALTER TABLE telegram_notifiers
+ ADD COLUMN is_proxy_enabled BOOLEAN NOT NULL DEFAULT FALSE,
+ ADD COLUMN proxy_url TEXT;
+
+-- +goose StatementEnd
+
+-- +goose Down
+-- +goose StatementBegin
+
+ALTER TABLE telegram_notifiers
+ DROP COLUMN IF EXISTS proxy_url,
+ DROP COLUMN IF EXISTS is_proxy_enabled;
+
+-- +goose StatementEnd
diff --git a/frontend/src/entity/notifiers/models/telegram/TelegramNotifier.ts b/frontend/src/entity/notifiers/models/telegram/TelegramNotifier.ts
index b40d8ec8..35bd0631 100644
--- a/frontend/src/entity/notifiers/models/telegram/TelegramNotifier.ts
+++ b/frontend/src/entity/notifiers/models/telegram/TelegramNotifier.ts
@@ -2,9 +2,8 @@ export interface TelegramNotifier {
botToken: string;
targetChatId: string;
threadId?: number;
- isHttpProxyEnabled?: boolean;
- httpProxyUrl?: string;
- hasHttpProxyUrl?: boolean;
+ isProxyEnabled?: boolean;
+ proxyUrl?: string;
// temp field
isSendToThreadEnabled?: boolean;
diff --git a/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.test.ts b/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.test.ts
index 3d90fb26..d5c79c7b 100644
--- a/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.test.ts
+++ b/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.test.ts
@@ -3,46 +3,52 @@ import { describe, expect, it } from 'vitest';
import { validateTelegramNotifier } from './validateTelegramNotifier';
describe('validateTelegramNotifier', () => {
- it('requires proxy URL when HTTP proxy is enabled for a new notifier', () => {
+ it('requires proxy URL when proxy is enabled for a new notifier', () => {
expect(
validateTelegramNotifier(true, {
botToken: 'token',
targetChatId: '123456',
- isHttpProxyEnabled: true,
+ isProxyEnabled: true,
}),
).toBe(false);
});
- it('allows an existing hidden proxy URL', () => {
+ it('allows an empty proxy URL on update (keeps the existing one)', () => {
expect(
validateTelegramNotifier(false, {
botToken: '',
targetChatId: '123456',
- isHttpProxyEnabled: true,
- hasHttpProxyUrl: true,
+ isProxyEnabled: true,
}),
).toBe(true);
});
- it('rejects non-http proxy URLs', () => {
+ it('rejects proxy URLs with an unsupported scheme', () => {
expect(
validateTelegramNotifier(true, {
botToken: 'token',
targetChatId: '123456',
- isHttpProxyEnabled: true,
- httpProxyUrl: 'https://proxy.example.com:3128',
+ isProxyEnabled: true,
+ proxyUrl: 'ftp://proxy.example.com:3128',
}),
).toBe(false);
});
- it('allows valid http proxy URLs', () => {
- expect(
- validateTelegramNotifier(true, {
- botToken: 'token',
- targetChatId: '123456',
- isHttpProxyEnabled: true,
- httpProxyUrl: 'http://user:[email protected]:3128',
- }),
- ).toBe(true);
+ it('accepts http, https, socks5 and socks5h proxy URLs', () => {
+ for (const proxyUrl of [
+ 'http://user:[email protected]:3128',
+ 'https://proxy.example.com:8443',
+ 'socks5://user:[email protected]:1080',
+ 'socks5h://proxy.example.com:1080',
+ ]) {
+ expect(
+ validateTelegramNotifier(true, {
+ botToken: 'token',
+ targetChatId: '123456',
+ isProxyEnabled: true,
+ proxyUrl,
+ }),
+ ).toBe(true);
+ }
});
});
diff --git a/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.ts b/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.ts
index ce44999e..304c198f 100644
--- a/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.ts
+++ b/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.ts
@@ -1,5 +1,16 @@
import type { TelegramNotifier } from './TelegramNotifier';
+const allowedProxyProtocols = ['http:', 'https:', 'socks5:', 'socks5h:'];
+
+const isValidProxyUrl = (rawProxyUrl: string): boolean => {
+ try {
+ const proxyUrl = new URL(rawProxyUrl);
+ return allowedProxyProtocols.includes(proxyUrl.protocol) && !!proxyUrl.host;
+ } catch {
+ return false;
+ }
+};
+
export const validateTelegramNotifier = (
isCreate: boolean,
notifier: TelegramNotifier,
@@ -17,20 +28,13 @@ export const validateTelegramNotifier = (
return false;
}
- if (notifier.isHttpProxyEnabled) {
- if (!notifier.httpProxyUrl && !notifier.hasHttpProxyUrl) {
+ if (notifier.isProxyEnabled) {
+ if (isCreate && !notifier.proxyUrl) {
return false;
}
- if (notifier.httpProxyUrl) {
- try {
- const proxyUrl = new URL(notifier.httpProxyUrl);
- if (proxyUrl.protocol !== 'http:' || !proxyUrl.host) {
- return false;
- }
- } catch {
- return false;
- }
+ if (notifier.proxyUrl && !isValidProxyUrl(notifier.proxyUrl)) {
+ return false;
}
}
diff --git a/frontend/src/features/notifiers/ui/edit/notifiers/EditTelegramNotifierComponent.tsx b/frontend/src/features/notifiers/ui/edit/notifiers/EditTelegramNotifierComponent.tsx
index 6764224a..ad07a6ad 100644
--- a/frontend/src/features/notifiers/ui/edit/notifiers/EditTelegramNotifierComponent.tsx
+++ b/frontend/src/features/notifiers/ui/edit/notifiers/EditTelegramNotifierComponent.tsx
@@ -117,10 +117,10 @@ export function EditTelegramNotifierComponent({ notifier, setNotifier, setUnsave
</div>
<div className="mt-4 mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
- <div className="mb-1 min-w-[150px] sm:mb-0">Use HTTP proxy</div>
+ <div className="mb-1 min-w-[150px] sm:mb-0">Use proxy</div>
<div className="flex items-center">
<Switch
- checked={notifier?.telegramNotifier?.isHttpProxyEnabled || false}
+ checked={notifier?.telegramNotifier?.isProxyEnabled || false}
onChange={(checked) => {
if (!notifier?.telegramNotifier) return;
@@ -128,9 +128,8 @@ export function EditTelegramNotifierComponent({ notifier, setNotifier, setUnsave
...notifier,
telegramNotifier: {
...notifier.telegramNotifier,
- isHttpProxyEnabled: checked,
- httpProxyUrl: checked ? notifier.telegramNotifier.httpProxyUrl : undefined,
- hasHttpProxyUrl: checked ? notifier.telegramNotifier.hasHttpProxyUrl : false,
+ isProxyEnabled: checked,
+ proxyUrl: checked ? notifier.telegramNotifier.proxyUrl : undefined,
},
});
setUnsaved();
@@ -138,18 +137,18 @@ export function EditTelegramNotifierComponent({ notifier, setNotifier, setUnsave
size="small"
/>
- <Tooltip className="cursor-pointer" title="Use HTTP proxy for Telegram API requests">
+ <Tooltip className="cursor-pointer" title="Use a proxy for Telegram API requests">
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
</Tooltip>
</div>
</div>
- {notifier?.telegramNotifier?.isHttpProxyEnabled && (
+ {notifier?.telegramNotifier?.isProxyEnabled && (
<div className="mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
- <div className="mb-1 min-w-[150px] sm:mb-0">HTTP proxy URL</div>
+ <div className="mb-1 min-w-[150px] sm:mb-0">Proxy URL</div>
<div className="flex items-center">
- <Input.Password
- value={notifier?.telegramNotifier?.httpProxyUrl || ''}
+ <Input
+ value={notifier?.telegramNotifier?.proxyUrl || ''}
onChange={(e) => {
if (!notifier?.telegramNotifier) return;
@@ -157,23 +156,19 @@ export function EditTelegramNotifierComponent({ notifier, setNotifier, setUnsave
...notifier,
telegramNotifier: {
...notifier.telegramNotifier,
- httpProxyUrl: e.target.value.trim(),
+ proxyUrl: e.target.value.trim(),
},
});
setUnsaved();
}}
size="small"
className="w-full max-w-[250px]"
- placeholder={
- notifier.telegramNotifier.hasHttpProxyUrl
- ? 'Configured'
- : 'http://proxy.example.com:3128'
- }
+ placeholder="socks5://user:pass@host:1080"
/>
<Tooltip
className="cursor-pointer"
- title="Proxy URL must start with http:// and may include username and password"
+ title="Supports http, https, socks5, socks5h. May include username and password"
>
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
</Tooltip>
diff --git a/frontend/src/features/notifiers/ui/show/notifier/ShowTelegramNotifierComponent.tsx b/frontend/src/features/notifiers/ui/show/notifier/ShowTelegramNotifierComponent.tsx
index 3f1784db..c4b0dba3 100644
--- a/frontend/src/features/notifiers/ui/show/notifier/ShowTelegramNotifierComponent.tsx
+++ b/frontend/src/features/notifiers/ui/show/notifier/ShowTelegramNotifierComponent.tsx
@@ -25,9 +25,9 @@ export function ShowTelegramNotifierComponent({ notifier }: Props) {
</div>
)}
- {notifier?.telegramNotifier?.isHttpProxyEnabled && (
+ {notifier?.telegramNotifier?.isProxyEnabled && (
<div className="mb-1 flex items-center">
- <div className="min-w-[110px]">HTTP proxy</div>
+ <div className="min-w-[110px]">Proxy</div>
Enabled
</div>
)}