wizard_ethstats.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package main
  17. import (
  18. "fmt"
  19. "sort"
  20. "github.com/ethereum/go-ethereum/log"
  21. )
  22. // deployEthstats queries the user for various input on deploying an ethstats
  23. // monitoring server, after which it executes it.
  24. func (w *wizard) deployEthstats() {
  25. // Select the server to interact with
  26. server := w.selectServer()
  27. if server == "" {
  28. return
  29. }
  30. client := w.servers[server]
  31. // Retrieve any active ethstats configurations from the server
  32. infos, err := checkEthstats(client, w.network)
  33. if err != nil {
  34. infos = &ethstatsInfos{
  35. port: 80,
  36. host: client.server,
  37. secret: "",
  38. }
  39. }
  40. existed := err == nil
  41. // Figure out which port to listen on
  42. fmt.Println()
  43. fmt.Printf("Which port should ethstats listen on? (default = %d)\n", infos.port)
  44. infos.port = w.readDefaultInt(infos.port)
  45. // Figure which virtual-host to deploy ethstats on
  46. if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil {
  47. log.Error("Failed to decide on ethstats host", "err", err)
  48. return
  49. }
  50. // Port and proxy settings retrieved, figure out the secret and boot ethstats
  51. fmt.Println()
  52. if infos.secret == "" {
  53. fmt.Printf("What should be the secret password for the API? (must not be empty)\n")
  54. infos.secret = w.readString()
  55. } else {
  56. fmt.Printf("What should be the secret password for the API? (default = %s)\n", infos.secret)
  57. infos.secret = w.readDefaultString(infos.secret)
  58. }
  59. // Gather any blacklists to ban from reporting
  60. if existed {
  61. fmt.Println()
  62. fmt.Printf("Keep existing IP %v blacklist (y/n)? (default = yes)\n", infos.banned)
  63. if w.readDefaultString("y") != "y" {
  64. // The user might want to clear the entire list, although generally probably not
  65. fmt.Println()
  66. fmt.Printf("Clear out blacklist and start over (y/n)? (default = no)\n")
  67. if w.readDefaultString("n") != "n" {
  68. infos.banned = nil
  69. }
  70. // Offer the user to explicitly add/remove certain IP addresses
  71. fmt.Println()
  72. fmt.Println("Which additional IP addresses should be blacklisted?")
  73. for {
  74. if ip := w.readIPAddress(); ip != "" {
  75. infos.banned = append(infos.banned, ip)
  76. continue
  77. }
  78. break
  79. }
  80. fmt.Println()
  81. fmt.Println("Which IP addresses should not be blacklisted?")
  82. for {
  83. if ip := w.readIPAddress(); ip != "" {
  84. for i, addr := range infos.banned {
  85. if ip == addr {
  86. infos.banned = append(infos.banned[:i], infos.banned[i+1:]...)
  87. break
  88. }
  89. }
  90. continue
  91. }
  92. break
  93. }
  94. sort.Strings(infos.banned)
  95. }
  96. }
  97. // Try to deploy the ethstats server on the host
  98. nocache := false
  99. if existed {
  100. fmt.Println()
  101. fmt.Printf("Should the ethstats be built from scratch (y/n)? (default = no)\n")
  102. nocache = w.readDefaultString("n") != "n"
  103. }
  104. trusted := make([]string, 0, len(w.servers))
  105. for _, client := range w.servers {
  106. if client != nil {
  107. trusted = append(trusted, client.address)
  108. }
  109. }
  110. if out, err := deployEthstats(client, w.network, infos.port, infos.secret, infos.host, trusted, infos.banned, nocache); err != nil {
  111. log.Error("Failed to deploy ethstats container", "err", err)
  112. if len(out) > 0 {
  113. fmt.Printf("%s\n", out)
  114. }
  115. return
  116. }
  117. // All ok, run a network scan to pick any changes up
  118. w.networkStats()
  119. }