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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. case SecretModeTLS:
  27. secret = "ee" + hex.EncodeToString(C.Secret) + hex.EncodeToString([]byte(C.CloakHost))
  28. }
  29. urls.IPv4 = makeURLs(C.PublicIPv4, secret)
  30. urls.IPv6 = makeURLs(C.PublicIPv6, secret)
  31. urls.BotSecret = hex.EncodeToString(C.Secret)
  32. return urls
  33. }
  34. func makeURLs(addr *net.TCPAddr, secret string) (urls URLs) {
  35. values := url.Values{}
  36. values.Set("server", addr.IP.String())
  37. values.Set("port", strconv.Itoa(addr.Port))
  38. values.Set("secret", secret)
  39. urls.TG = makeTGURL(values)
  40. urls.TMe = makeTMeURL(values)
  41. urls.TGQRCode = makeQRCodeURL(urls.TG)
  42. urls.TMeQRCode = makeQRCodeURL(urls.TG)
  43. return
  44. }
  45. func makeTGURL(values url.Values) string {
  46. tgURL := url.URL{
  47. Scheme: "tg",
  48. Host: "proxy",
  49. RawQuery: values.Encode(),
  50. }
  51. return tgURL.String()
  52. }
  53. func makeTMeURL(values url.Values) string {
  54. tMeURL := url.URL{
  55. Scheme: "https",
  56. Host: "t.me",
  57. Path: "proxy",
  58. RawQuery: values.Encode(),
  59. }
  60. return tMeURL.String()
  61. }
  62. func makeQRCodeURL(data string) string {
  63. qr := url.URL{
  64. Scheme: "https",
  65. Host: "api.qrserver.com",
  66. Path: "v1/create-qr-code",
  67. }
  68. values := url.Values{}
  69. values.Set("qzone", "4")
  70. values.Set("format", "svg")
  71. values.Set("data", data)
  72. qr.RawQuery = values.Encode()
  73. return qr.String()
  74. }