Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

oragono.go 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright (c) 2012-2014 Jeremy Latt
  2. // Copyright (c) 2014-2015 Edmund Huber
  3. // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
  4. // released under the MIT license
  5. package main
  6. import (
  7. "fmt"
  8. "log"
  9. "math/rand"
  10. "strings"
  11. "syscall"
  12. "time"
  13. "github.com/docopt/docopt-go"
  14. "github.com/oragono/oragono/irc"
  15. "github.com/oragono/oragono/irc/logger"
  16. "github.com/oragono/oragono/irc/mkcerts"
  17. "github.com/oragono/oragono/irc/passwd"
  18. stackimpact "github.com/stackimpact/stackimpact-go"
  19. "golang.org/x/crypto/ssh/terminal"
  20. )
  21. var commit = ""
  22. func main() {
  23. version := irc.SemVer
  24. usage := `oragono.
  25. Usage:
  26. oragono initdb [--conf <filename>] [--quiet]
  27. oragono upgradedb [--conf <filename>] [--quiet]
  28. oragono genpasswd [--conf <filename>] [--quiet]
  29. oragono mkcerts [--conf <filename>] [--quiet]
  30. oragono run [--conf <filename>] [--quiet]
  31. oragono -h | --help
  32. oragono --version
  33. Options:
  34. --conf <filename> Configuration file to use [default: ircd.yaml].
  35. --quiet Don't show startup/shutdown lines.
  36. -h --help Show this screen.
  37. --version Show version.`
  38. arguments, _ := docopt.Parse(usage, nil, true, version, false)
  39. configfile := arguments["--conf"].(string)
  40. config, err := irc.LoadConfig(configfile)
  41. if err != nil {
  42. log.Fatal("Config file did not load successfully: ", err.Error())
  43. }
  44. logman, err := logger.NewManager(config.Logging)
  45. if err != nil {
  46. log.Fatal("Logger did not load successfully:", err.Error())
  47. }
  48. if arguments["genpasswd"].(bool) {
  49. fmt.Print("Enter Password: ")
  50. bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
  51. if err != nil {
  52. log.Fatal("Error reading password:", err.Error())
  53. }
  54. password := string(bytePassword)
  55. encoded, err := passwd.GenerateEncodedPassword(password)
  56. if err != nil {
  57. log.Fatal("encoding error:", err.Error())
  58. }
  59. fmt.Print("\n")
  60. fmt.Println(encoded)
  61. } else if arguments["initdb"].(bool) {
  62. irc.InitDB(config.Datastore.Path)
  63. if !arguments["--quiet"].(bool) {
  64. log.Println("database initialized: ", config.Datastore.Path)
  65. }
  66. } else if arguments["upgradedb"].(bool) {
  67. irc.UpgradeDB(config.Datastore.Path)
  68. if !arguments["--quiet"].(bool) {
  69. log.Println("database upgraded: ", config.Datastore.Path)
  70. }
  71. } else if arguments["mkcerts"].(bool) {
  72. if !arguments["--quiet"].(bool) {
  73. log.Println("making self-signed certificates")
  74. }
  75. for name, conf := range config.Server.TLSListeners {
  76. if !arguments["--quiet"].(bool) {
  77. log.Printf(" making cert for %s listener\n", name)
  78. }
  79. host := config.Server.Name
  80. err := mkcerts.CreateCert("Oragono", host, conf.Cert, conf.Key)
  81. if err == nil {
  82. if !arguments["--quiet"].(bool) {
  83. log.Printf(" Certificate created at %s : %s\n", conf.Cert, conf.Key)
  84. }
  85. } else {
  86. log.Fatal(" Could not create certificate:", err.Error())
  87. }
  88. }
  89. } else if arguments["run"].(bool) {
  90. rand.Seed(time.Now().UTC().UnixNano())
  91. if !arguments["--quiet"].(bool) {
  92. logman.Info("startup", fmt.Sprintf("Oragono v%s starting", irc.SemVer))
  93. if commit == "" {
  94. logman.Debug("startup", fmt.Sprintf("Could not get current commit"))
  95. } else {
  96. logman.Info("startup", fmt.Sprintf("Running commit %s", commit))
  97. }
  98. }
  99. // set current git commit
  100. irc.Commit = commit
  101. if commit != "" {
  102. irc.Ver = fmt.Sprintf("%s-%s", irc.Ver, commit)
  103. }
  104. // profiling
  105. if config.Debug.StackImpact.Enabled {
  106. if config.Debug.StackImpact.AgentKey == "" || config.Debug.StackImpact.AppName == "" {
  107. logman.Error("startup", "Could not start StackImpact - agent-key or app-name are undefined")
  108. return
  109. }
  110. agent := stackimpact.NewAgent()
  111. agent.Start(stackimpact.Options{AgentKey: config.Debug.StackImpact.AgentKey, AppName: config.Debug.StackImpact.AppName})
  112. defer agent.RecordPanic()
  113. logman.Info("startup", fmt.Sprintf("StackImpact profiling started as %s", config.Debug.StackImpact.AppName))
  114. }
  115. // warning if running a non-final version
  116. if strings.Contains(irc.SemVer, "unreleased") {
  117. logman.Warning("startup", "You are currently running an unreleased beta version of Oragono that may be unstable and could corrupt your database.\nIf you are running a production network, please download the latest build from https://oragono.io/downloads.html and run that instead.")
  118. }
  119. server, err := irc.NewServer(config, logman)
  120. if err != nil {
  121. logman.Error("startup", fmt.Sprintf("Could not load server: %s", err.Error()))
  122. return
  123. }
  124. if !arguments["--quiet"].(bool) {
  125. logman.Info("startup", "Server running")
  126. defer logman.Info("shutdown", fmt.Sprintf("Oragono v%s exiting", irc.SemVer))
  127. }
  128. server.Run()
  129. }
  130. }