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

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