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
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

urls.go 1.9KB

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