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
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

doctor.go 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package cli
  2. import (
  3. "fmt"
  4. "os"
  5. "strings"
  6. "text/template"
  7. "github.com/9seconds/mtg/v2/internal/config"
  8. "github.com/9seconds/mtg/v2/internal/utils"
  9. )
  10. var (
  11. tplWDeprecatedConfig = template.Must(
  12. template.New("deprecated-config").
  13. Parse(` ⚠️ Option {{ .old | printf "%q" }}{{ if .old_section }} from section [{{ .old_section }}]{{ end }} is deprecated and will be removed in v{{ .when }}. Please use {{ .new | printf "%q" }}{{ if .new_section }} in [{{ .new_section }}] section{{ end }} instead.`),
  14. )
  15. )
  16. type Doctor struct {
  17. conf *config.Config
  18. ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` //nolint: lll
  19. }
  20. func (d *Doctor) Run(cli *CLI, version string) error {
  21. conf, err := utils.ReadConfig(d.ConfigPath)
  22. if err != nil {
  23. return fmt.Errorf("cannot init config: %w", err)
  24. }
  25. d.conf = conf
  26. everythingOK := true
  27. fmt.Println("Deprecated options")
  28. if errs := d.checkDeprecatedConfig(); len(errs) > 0 {
  29. for _, err := range errs {
  30. fmt.Println(err)
  31. everythingOK = false
  32. }
  33. } else {
  34. fmt.Println(" ✅ All good")
  35. }
  36. if !everythingOK {
  37. os.Exit(1)
  38. }
  39. return nil
  40. }
  41. func (d *Doctor) checkDeprecatedConfig() []string {
  42. errors := []string{}
  43. if d.conf.DomainFrontingIP.Value != nil {
  44. errors = d.addError(errors, tplWDeprecatedConfig, map[string]string{
  45. "when": "2.3.0",
  46. "old": "domain-fronting-ip",
  47. "old_section": "",
  48. "new": "ip",
  49. "new_section": "domain-fronting",
  50. })
  51. }
  52. if d.conf.DomainFrontingPort.Value != 0 {
  53. errors = d.addError(errors, tplWDeprecatedConfig, map[string]string{
  54. "when": "2.3.0",
  55. "old": "domain-fronting-port",
  56. "old_section": "",
  57. "new": "port",
  58. "new_section": "domain-fronting",
  59. })
  60. }
  61. if d.conf.DomainFrontingProxyProtocol.Value {
  62. errors = d.addError(errors, tplWDeprecatedConfig, map[string]string{
  63. "when": "2.3.0",
  64. "old": "domain-fronting-proxy-protocol",
  65. "old_section": "",
  66. "new": "proxy-protocol",
  67. "new_section": "domain-fronting",
  68. })
  69. }
  70. if d.conf.Network.DOHIP.Value != nil {
  71. errors = d.addError(errors, tplWDeprecatedConfig, map[string]string{
  72. "when": "2.3.0",
  73. "old": "doh-ip",
  74. "old_section": "network",
  75. "new": "dns",
  76. "new_section": "network",
  77. })
  78. }
  79. return errors
  80. }
  81. func (d *Doctor) addError(messages []string, tpl *template.Template, context map[string]string) []string {
  82. value := &strings.Builder{}
  83. if err := tpl.Execute(value, context); err != nil {
  84. panic(err)
  85. }
  86. return append(messages, value.String())
  87. }