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
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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"` //nolint: tagliatelle
  10. TMe string `json:"tme_url"` //nolint: tagliatelle
  11. TGQRCode string `json:"tg_qrcode"` //nolint: tagliatelle
  12. TMeQRCode string `json:"tme_qrcode"` //nolint: tagliatelle
  13. }
  14. type IPURLs struct {
  15. IPv4 *URLs `json:"ipv4,omitempty"`
  16. IPv6 *URLs `json:"ipv6,omitempty"`
  17. BotSecret string `json:"secret_for_mtproxybot"` //nolint: tagliatelle
  18. }
  19. func GetURLs() IPURLs {
  20. secret := ""
  21. urls := IPURLs{}
  22. switch C.SecretMode {
  23. case SecretModeSimple:
  24. secret = hex.EncodeToString(C.Secret)
  25. case SecretModeSecured:
  26. secret = "dd" + hex.EncodeToString(C.Secret)
  27. case SecretModeTLS:
  28. secret = "ee" + hex.EncodeToString(C.Secret) + hex.EncodeToString([]byte(C.CloakHost))
  29. }
  30. if C.PublicIPv4.IP != nil {
  31. urls.IPv4 = makeURLs(C.PublicIPv4, secret)
  32. }
  33. if C.PublicIPv6.IP != nil {
  34. urls.IPv6 = makeURLs(C.PublicIPv6, secret)
  35. }
  36. urls.BotSecret = hex.EncodeToString(C.Secret)
  37. return urls
  38. }
  39. func makeURLs(addr *net.TCPAddr, secret string) *URLs {
  40. urls := &URLs{}
  41. values := url.Values{}
  42. values.Set("server", addr.IP.String())
  43. values.Set("port", strconv.Itoa(addr.Port))
  44. values.Set("secret", secret)
  45. return &URLs{
  46. TG: makeTGURL(values),
  47. TMe: makeTMeURL(values),
  48. TGQRCode: makeQRCodeURL(urls.TG),
  49. TMeQRCode: makeQRCodeURL(urls.TMe),
  50. }
  51. }
  52. func makeTGURL(values url.Values) string {
  53. tgURL := url.URL{
  54. Scheme: "tg",
  55. Host: "proxy",
  56. RawQuery: values.Encode(),
  57. }
  58. return tgURL.String()
  59. }
  60. func makeTMeURL(values url.Values) string {
  61. tMeURL := url.URL{
  62. Scheme: "https",
  63. Host: "t.me",
  64. Path: "proxy",
  65. RawQuery: values.Encode(),
  66. }
  67. return tMeURL.String()
  68. }
  69. func makeQRCodeURL(data string) string {
  70. qr := url.URL{
  71. Scheme: "https",
  72. Host: "api.qrserver.com",
  73. Path: "v1/create-qr-code",
  74. }
  75. values := url.Values{}
  76. values.Set("qzone", "4")
  77. values.Set("format", "svg")
  78. values.Set("data", data)
  79. qr.RawQuery = values.Encode()
  80. return qr.String()
  81. }