v2.0.4: HTTP proxy support for browsers (Issue #2)
This commit is contained in:
parent
c84193f6f9
commit
f638d6e494
|
|
@ -147,21 +147,26 @@ tg://socks?server=127.0.0.1&port=1080
|
||||||
```bash
|
```bash
|
||||||
TgWsProxy.exe
|
TgWsProxy.exe
|
||||||
```
|
```
|
||||||
|
Просто запусти! Telegram автоматически откроет настройки SOCKS5 прокси.
|
||||||
|
|
||||||
**С аутентификацией:**
|
**С аутентификацией:**
|
||||||
```bash
|
```bash
|
||||||
TgWsProxy.exe --auth "myuser:mypassword"
|
TgWsProxy.exe --auth "myuser:mypassword"
|
||||||
```
|
```
|
||||||
|
Защита прокси паролем.
|
||||||
|
|
||||||
**С HTTP прокси (для опытных):**
|
**С HTTP прокси (для опытных):**
|
||||||
```bash
|
```bash
|
||||||
TgWsProxy.exe --http-port 8080
|
TgWsProxy.exe --http-port 8080
|
||||||
```
|
```
|
||||||
|
Дополнительно включает HTTP прокси для браузеров и других приложений.
|
||||||
|
Telegram использует SOCKS5 (порт 1080), браузеры могут использовать HTTP (порт 8080).
|
||||||
|
|
||||||
**С восходящим прокси (для опытных):**
|
**С восходящим прокси (для опытных):**
|
||||||
```bash
|
```bash
|
||||||
TgWsProxy.exe --upstream-proxy "socks5://user:pass@proxy-server:1080"
|
TgWsProxy.exe --upstream-proxy "socks5://user:pass@proxy-server:1080"
|
||||||
```
|
```
|
||||||
|
Подключение к Telegram через другой SOCKS5 прокси.
|
||||||
|
|
||||||
## Структура проекта
|
## Структура проекта
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,8 @@ func main() {
|
||||||
// Advanced features (for experienced users)
|
// Advanced features (for experienced users)
|
||||||
httpPort := flag.Int("http-port", 0, "Enable HTTP proxy on port (0 = disabled)")
|
httpPort := flag.Int("http-port", 0, "Enable HTTP proxy on port (0 = disabled)")
|
||||||
upstreamProxy := flag.String("upstream-proxy", "", "Upstream SOCKS5/HTTP proxy (format: socks5://user:pass@host:port or http://user:pass@host:port)")
|
upstreamProxy := flag.String("upstream-proxy", "", "Upstream SOCKS5/HTTP proxy (format: socks5://user:pass@host:port or http://user:pass@host:port)")
|
||||||
|
mtprotoSecret := flag.String("mtproto-secret", "", "MTProto proxy secret (enables MTProto mode)")
|
||||||
|
mtprotoPort := flag.Int("mtproto-port", 0, "MTProto proxy port (requires --mtproto-secret)")
|
||||||
|
|
||||||
showVersion := flag.Bool("version", false, "Show version")
|
showVersion := flag.Bool("version", false, "Show version")
|
||||||
|
|
||||||
|
|
@ -149,8 +151,28 @@ func main() {
|
||||||
log.Fatalf("Failed to create server: %v", err)
|
log.Fatalf("Failed to create server: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-configure Telegram Desktop (always attempt on first run)
|
// Auto-configure Telegram Desktop with correct proxy type
|
||||||
log.Println("Attempting to configure Telegram Desktop...")
|
log.Println("Attempting to configure Telegram Desktop...")
|
||||||
|
|
||||||
|
// Determine proxy type and configure Telegram accordingly
|
||||||
|
// Note: Our local proxy only supports SOCKS5
|
||||||
|
// HTTP port is for other applications (browsers, etc.)
|
||||||
|
// MTProto requires external MTProxy server
|
||||||
|
proxyType := "socks5" // Always SOCKS5 for our local proxy
|
||||||
|
proxyPort := cfg.Port
|
||||||
|
proxySecret := ""
|
||||||
|
|
||||||
|
// Log HTTP mode if enabled (for other apps, not Telegram)
|
||||||
|
if *httpPort != 0 {
|
||||||
|
log.Printf("⚙ HTTP proxy enabled on port %d (for browsers/other apps)", *httpPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log MTProto mode info
|
||||||
|
if *mtprotoPort != 0 && *mtprotoSecret != "" {
|
||||||
|
log.Printf("⚙ MTProto mode: Use external MTProxy or configure manually")
|
||||||
|
log.Printf(" tg://proxy?server=%s&port=%d&secret=%s", cfg.Host, *mtprotoPort, *mtprotoSecret)
|
||||||
|
}
|
||||||
|
|
||||||
username, password := "", ""
|
username, password := "", ""
|
||||||
if cfg.Auth != "" {
|
if cfg.Auth != "" {
|
||||||
parts := strings.SplitN(cfg.Auth, ":", 2)
|
parts := strings.SplitN(cfg.Auth, ":", 2)
|
||||||
|
|
@ -158,12 +180,13 @@ func main() {
|
||||||
username, password = parts[0], parts[1]
|
username, password = parts[0], parts[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if telegram.ConfigureProxy(cfg.Host, cfg.Port, username, password) {
|
|
||||||
log.Println("✓ Telegram Desktop proxy configuration opened")
|
if telegram.ConfigureProxyWithType(cfg.Host, proxyPort, username, password, proxySecret, proxyType) {
|
||||||
|
log.Printf("✓ Telegram Desktop %s proxy configuration opened", strings.ToUpper(proxyType))
|
||||||
} else {
|
} else {
|
||||||
log.Println("✗ Failed to auto-configure Telegram.")
|
log.Println("✗ Failed to auto-configure Telegram.")
|
||||||
log.Println(" Manual setup: Settings → Advanced → Connection Type → Proxy")
|
log.Println(" Manual setup: Settings → Advanced → Connection Type → Proxy")
|
||||||
log.Println(" Or open: tg://socks?server=127.0.0.1&port=1080")
|
log.Printf(" Or open: tg://socks?server=%s&port=%d", cfg.Host, proxyPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for updates and auto-download (non-blocking)
|
// Check for updates and auto-download (non-blocking)
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,32 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConfigureProxy opens Telegram's proxy configuration URL.
|
// ConfigureProxy opens Telegram's SOCKS5 proxy configuration URL.
|
||||||
// Returns true if successful, false otherwise.
|
// Returns true if successful, false otherwise.
|
||||||
func ConfigureProxy(host string, port int, username, password string) bool {
|
func ConfigureProxy(host string, port int, username, password string) bool {
|
||||||
// Use tg://socks format (same as original Python version)
|
return ConfigureProxyWithType(host, port, username, password, "", "socks5")
|
||||||
// Format: tg://socks?server=host&port=port
|
}
|
||||||
proxyURL := fmt.Sprintf("tg://socks?server=%s&port=%d", host, port)
|
|
||||||
|
// ConfigureProxyWithType opens Telegram's proxy configuration URL with specified type.
|
||||||
|
// proxyType: "socks5" or "mtproto"
|
||||||
|
// For MTProto, provide secret parameter
|
||||||
|
// Note: HTTP proxy is NOT supported by Telegram Desktop via tg:// URLs
|
||||||
|
// Returns true if successful, false otherwise.
|
||||||
|
func ConfigureProxyWithType(host string, port int, username, password, secret, proxyType string) bool {
|
||||||
|
var proxyURL string
|
||||||
|
|
||||||
|
switch proxyType {
|
||||||
|
case "mtproto":
|
||||||
|
// MTProto proxy format: tg://proxy?server=host&port=port&secret=secret
|
||||||
|
if secret == "" {
|
||||||
|
secret = "ee000000000000000000000000000000" // default dummy secret
|
||||||
|
}
|
||||||
|
proxyURL = fmt.Sprintf("tg://proxy?server=%s&port=%d&secret=%s", host, port, secret)
|
||||||
|
default:
|
||||||
|
// SOCKS5 proxy format: tg://socks?server=host&port=port
|
||||||
|
// This is the only type our local proxy supports
|
||||||
|
proxyURL = fmt.Sprintf("tg://socks?server=%s&port=%d", host, port)
|
||||||
|
}
|
||||||
|
|
||||||
// Open URL using system default handler
|
// Open URL using system default handler
|
||||||
return openURL(proxyURL)
|
return openURL(proxyURL)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue