No Description
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.

main.go 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "net/http"
  6. "os"
  7. "regexp"
  8. "strconv"
  9. "strings"
  10. "other/license-server/jetbrain"
  11. "other/license-server/mybatis"
  12. "other/license-server/jrebel"
  13. "other/license-server/ldap"
  14. "other/license-server/mybatis/codehelp"
  15. "other/license-server/help"
  16. )
  17. var userName string
  18. var prolongationPeriod int64
  19. var validationPeriod int64
  20. var validationDeadlinePeriod int64
  21. var isUserNameEnv bool
  22. func main() {
  23. userName = os.Getenv("LICENSE-SERVER_USERNAME")
  24. log.SetOutput(os.Stdout)
  25. versionMode := flag.Bool("v", false, "show version")
  26. host := flag.String("host", "0.0.0.0", "bind on host")
  27. flag.Int64Var(&prolongationPeriod, "prolongationPeriod", 607875500, "prolong ation period(延长期)")
  28. flag.Int64Var(&validationPeriod, "validationPeriod", 607875500, "validation period(验证周期)")
  29. flag.Int64Var(&validationDeadlinePeriod, "validationDeadlinePeriod", 607875500, "validation deadline period(验证截止期限)")
  30. port := flag.Int("port", 22508, "port number")
  31. if userName == "" {
  32. flag.StringVar(&userName, "u", "luamas", "If you want to use a local user name, fill in empty such, -u empty")
  33. } else {
  34. isUserNameEnv = true
  35. }
  36. flag.Parse()
  37. if *versionMode {
  38. help.Version()
  39. return
  40. }
  41. addressAndPort := *host + ":" + strconv.Itoa(*port)
  42. log.Println("*************************************************************")
  43. log.Println("** Jrebel And Jetbrains License Server **")
  44. log.Println("** Jetbrains MyBatis Plugin active host **")
  45. log.Println("** Ldap Admin KeyGen http://xxx/ladp **")
  46. log.Println("** host:x.x.x.x www.codesmagic.com nginx reverse proxy" + strconv.Itoa(*port) + "**")
  47. log.Println("** by: luamas **")
  48. log.Println("** http://www.luamas.com **")
  49. log.Println("** Alipay donation: myluamas@gmail.com **")
  50. log.Println("** Please support genuine!!! **")
  51. log.Println("** You can use --help get the list of arguments **")
  52. log.Println("** listen on " + addressAndPort + " **")
  53. if *host == "0.0.0.0" {
  54. log.Println("** You can use http://127.0.0.1:" + strconv.Itoa(*port) + " as license server **")
  55. } else {
  56. log.Println("** You can use http://" + addressAndPort + " as license server **")
  57. }
  58. if isUserNameEnv {
  59. log.Println("** Use environment variables LICENSE-SERVER_USERNAME **")
  60. }
  61. if userName == "empty" {
  62. userName = ""
  63. log.Println("** You use the local username **")
  64. } else {
  65. log.Println("** The username you are using is " + userName + " **")
  66. }
  67. log.Println("*************************************************************")
  68. if strings.Contains(addressAndPort, "0.0.0.0") {
  69. addressAndPort = strings.Replace(addressAndPort, "0.0.0.0", "", 1)
  70. }
  71. routerBinding()
  72. err := http.ListenAndServe(addressAndPort, http.DefaultServeMux)
  73. if err != nil {
  74. log.Fatalln(err)
  75. }
  76. }
  77. func routerBinding() {
  78. mux := http.NewServeMux()
  79. http.Handle("/", urlMatcher(mux))
  80. }
  81. func urlMatcher(_ http.Handler) http.Handler {
  82. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  83. r.URL.Path = strings.ToLower(r.URL.Path)
  84. if r.URL.Path == "/" {
  85. index(w, r)
  86. return
  87. }
  88. isJrebel1, err1 := regexp.MatchString("/agent/.*", r.URL.Path)
  89. if err1 == nil && isJrebel1 {
  90. jrebel.Jrebel(w, r, userName)
  91. return
  92. }
  93. isJrebel2, err11 := regexp.MatchString("/jrebel/.*", r.URL.Path)
  94. if err11 == nil && isJrebel2 {
  95. jrebel.Jrebel(w, r, userName)
  96. return
  97. }
  98. isJetbrains, err2 := regexp.MatchString("/rpc/.*\\.action", r.URL.Path)
  99. if err2 == nil && isJetbrains {
  100. jetbrain.Jetbrains(w, r, userName, prolongationPeriod,validationPeriod,validationDeadlinePeriod)
  101. return
  102. }
  103. isJetbrainsMybatis, err2 := regexp.MatchString("/activate", r.URL.Path)
  104. if err2 == nil && isJetbrainsMybatis {
  105. mybatis.JetbrainsMybatis(w, r)
  106. return
  107. }
  108. isJetbrainsMybatisCodeHelp, err2 := regexp.MatchString("/codehelp", r.URL.Path)
  109. if err2 == nil && isJetbrainsMybatisCodeHelp {
  110. codehelp.Codehelp(w,r)
  111. return
  112. }
  113. isLdap, err2 := regexp.MatchString("/ldap", r.URL.Path)
  114. if err2 == nil && isLdap {
  115. ldap.Ldap(w, r)
  116. return
  117. }
  118. http.Error(w, "页面未找到", 404)
  119. })
  120. }
  121. func index(w http.ResponseWriter, _ *http.Request) {
  122. w.Write([]byte("License Server"))
  123. }