Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package config
  2. import (
  3. "encoding/hex"
  4. "net"
  5. "net/url"
  6. "strconv"
  7. )
  8. type URLs struct {
  9. TG string `json:"tg_url"`
  10. TMe string `json:"tme_url"`
  11. TGQRCode string `json:"tg_qrcode"`
  12. TMeQRCode string `json:"tme_qrcode"`
  13. }
  14. type IPURLs struct {
  15. IPv4 URLs `json:"ipv4"`
  16. IPv6 URLs `json:"ipv6"`
  17. BotSecret string `json:"secret_for_mtproxybot"`
  18. }
  19. func GetURLs() (urls IPURLs) {
  20. secret := ""
  21. switch C.SecretMode {
  22. case SecretModeSimple:
  23. secret = hex.EncodeToString(C.Secret)
  24. case SecretModeSecured:
  25. secret = "dd" + hex.EncodeToString(C.Secret)
  26. }
  27. urls.IPv4 = makeURLs(C.PublicIPv4, secret)
  28. urls.IPv6 = makeURLs(C.PublicIPv6, secret)
  29. urls.BotSecret = secret
  30. return urls
  31. }
  32. func makeURLs(addr *net.TCPAddr, secret string) (urls URLs) {
  33. values := url.Values{}
  34. values.Set("server", addr.IP.String())
  35. values.Set("port", strconv.Itoa(addr.Port))
  36. values.Set("secret", secret)
  37. urls.TG = makeTGURL(values)
  38. urls.TMe = makeTMeURL(values)
  39. urls.TGQRCode = makeQRCodeURL(urls.TG)
  40. urls.TMeQRCode = makeQRCodeURL(urls.TG)
  41. return
  42. }
  43. func makeTGURL(values url.Values) string {
  44. tgURL := url.URL{
  45. Scheme: "tg",
  46. Host: "proxy",
  47. RawQuery: values.Encode(),
  48. }
  49. return tgURL.String()
  50. }
  51. func makeTMeURL(values url.Values) string {
  52. tMeURL := url.URL{
  53. Scheme: "https",
  54. Host: "t.me",
  55. Path: "proxy",
  56. RawQuery: values.Encode(),
  57. }
  58. return tMeURL.String()
  59. }
  60. func makeQRCodeURL(data string) string {
  61. qr := url.URL{
  62. Scheme: "https",
  63. Host: "api.qrserver.com",
  64. Path: "v1/create-qr-code",
  65. }
  66. values := url.Values{}
  67. values.Set("qzone", "4")
  68. values.Set("format", "svg")
  69. values.Set("data", data)
  70. qr.RawQuery = values.Encode()
  71. return qr.String()
  72. }