Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

oragono.go 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/mkcerts"
  17. stackimpact "github.com/stackimpact/stackimpact-go"
  18. "golang.org/x/crypto/ssh/terminal"
  19. )
  20. func main() {
  21. version := irc.SemVer
  22. usage := `oragono.
  23. Usage:
  24. oragono initdb [--conf <filename>] [--quiet]
  25. oragono upgradedb [--conf <filename>] [--quiet]
  26. oragono genpasswd [--conf <filename>] [--quiet]
  27. oragono mkcerts [--conf <filename>] [--quiet]
  28. oragono run [--conf <filename>] [--quiet]
  29. oragono -h | --help
  30. oragono --version
  31. Options:
  32. --conf <filename> Configuration file to use [default: ircd.yaml].
  33. --quiet Don't show startup/shutdown lines.
  34. -h --help Show this screen.
  35. --version Show version.`
  36. arguments, _ := docopt.Parse(usage, nil, true, version, false)
  37. configfile := arguments["--conf"].(string)
  38. config, err := irc.LoadConfig(configfile)
  39. if err != nil {
  40. log.Fatal("Config file did not load successfully:", err.Error())
  41. }
  42. // assemble separate log configs
  43. var logConfigs []logger.Config
  44. for _, lConfig := range config.Logging {
  45. logConfigs = append(logConfigs, logger.Config{
  46. MethodStdout: lConfig.MethodStdout,
  47. MethodStderr: lConfig.MethodStderr,
  48. MethodFile: lConfig.MethodFile,
  49. Filename: lConfig.Filename,
  50. Level: lConfig.Level,
  51. Types: lConfig.Types,
  52. ExcludedTypes: lConfig.ExcludedTypes,
  53. })
  54. }
  55. logger, err := logger.NewManager(logConfigs...)
  56. if err != nil {
  57. log.Fatal("Logger did not load successfully:", err.Error())
  58. }
  59. if arguments["genpasswd"].(bool) {
  60. fmt.Print("Enter Password: ")
  61. bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
  62. if err != nil {
  63. log.Fatal("Error reading password:", err.Error())
  64. }
  65. password := string(bytePassword)
  66. encoded, err := irc.GenerateEncodedPassword(password)
  67. if err != nil {
  68. log.Fatal("encoding error:", err.Error())
  69. }
  70. fmt.Print("\n")
  71. fmt.Println(encoded)
  72. } else if arguments["initdb"].(bool) {
  73. irc.InitDB(config.Datastore.Path)
  74. if !arguments["--quiet"].(bool) {
  75. log.Println("database initialized: ", config.Datastore.Path)
  76. }
  77. } else if arguments["upgradedb"].(bool) {
  78. irc.UpgradeDB(config.Datastore.Path)
  79. if !arguments["--quiet"].(bool) {
  80. log.Println("database upgraded: ", config.Datastore.Path)
  81. }
  82. } else if arguments["mkcerts"].(bool) {
  83. if !arguments["--quiet"].(bool) {
  84. log.Println("making self-signed certificates")
  85. }
  86. for name, conf := range config.Server.TLSListeners {
  87. log.Printf(" making cert for %s listener\n", name)
  88. host := config.Server.Name
  89. err := mkcerts.CreateCert("Oragono", host, conf.Cert, conf.Key)
  90. if err == nil {
  91. if !arguments["--quiet"].(bool) {
  92. log.Printf(" Certificate created at %s : %s\n", conf.Cert, conf.Key)
  93. }
  94. } else {
  95. log.Fatal(" Could not create certificate:", err.Error())
  96. }
  97. }
  98. } else if arguments["run"].(bool) {
  99. rand.Seed(time.Now().UTC().UnixNano())
  100. if !arguments["--quiet"].(bool) {
  101. logger.Info("startup", fmt.Sprintf("Oragono v%s starting", irc.SemVer))
  102. }
  103. // profiling
  104. if config.Debug.StackImpact.Enabled {
  105. if config.Debug.StackImpact.AgentKey == "" || config.Debug.StackImpact.AppName == "" {
  106. logger.Error("startup", "Could not start StackImpact - agent-key or app-name are undefined")
  107. return
  108. }
  109. agent := stackimpact.NewAgent()
  110. agent.Start(stackimpact.Options{AgentKey: config.Debug.StackImpact.AgentKey, AppName: config.Debug.StackImpact.AppName})
  111. defer agent.RecordPanic()
  112. logger.Info("startup", fmt.Sprintf("StackImpact profiling started as %s", config.Debug.StackImpact.AppName))
  113. }
  114. // warning if running a non-final version
  115. if strings.Contains(irc.SemVer, "unreleased") {
  116. logger.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.")
  117. }
  118. server, err := irc.NewServer(configfile, config, logger)
  119. if err != nil {
  120. logger.Error("startup", fmt.Sprintf("Could not load server: %s", err.Error()))
  121. return
  122. }
  123. if !arguments["--quiet"].(bool) {
  124. logger.Info("startup", "Server running")
  125. defer logger.Info("shutdown", fmt.Sprintf("Oragono v%s exiting", irc.SemVer))
  126. }
  127. server.Run()
  128. }
  129. }