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.

urls.go 1.6KB

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