wizard_dashboard.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. "github.com/ethereum/go-ethereum/log"
  20. )
  21. // deployDashboard queries the user for various input on deploying a web-service
  22. // dashboard, after which is pushes the container.
  23. func (w *wizard) deployDashboard() {
  24. // Select the server to interact with
  25. server := w.selectServer()
  26. if server == "" {
  27. return
  28. }
  29. client := w.servers[server]
  30. // Retrieve any active dashboard configurations from the server
  31. infos, err := checkDashboard(client, w.network)
  32. if err != nil {
  33. infos = &dashboardInfos{
  34. port: 80,
  35. host: client.server,
  36. }
  37. }
  38. existed := err == nil
  39. // Figure out which port to listen on
  40. fmt.Println()
  41. fmt.Printf("Which port should the dashboard listen on? (default = %d)\n", infos.port)
  42. infos.port = w.readDefaultInt(infos.port)
  43. // Figure which virtual-host to deploy the dashboard on
  44. infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host)
  45. if err != nil {
  46. log.Error("Failed to decide on dashboard host", "err", err)
  47. return
  48. }
  49. // Port and proxy settings retrieved, figure out which services are available
  50. available := make(map[string][]string)
  51. for server, services := range w.services {
  52. for _, service := range services {
  53. available[service] = append(available[service], server)
  54. }
  55. }
  56. for _, service := range []string{"ethstats", "explorer", "wallet", "faucet"} {
  57. // Gather all the locally hosted pages of this type
  58. var pages []string
  59. for _, server := range available[service] {
  60. client := w.servers[server]
  61. if client == nil {
  62. continue
  63. }
  64. // If there's a service running on the machine, retrieve it's port number
  65. var port int
  66. switch service {
  67. case "ethstats":
  68. if infos, err := checkEthstats(client, w.network); err == nil {
  69. port = infos.port
  70. }
  71. case "explorer":
  72. if infos, err := checkExplorer(client, w.network); err == nil {
  73. port = infos.webPort
  74. }
  75. case "wallet":
  76. if infos, err := checkWallet(client, w.network); err == nil {
  77. port = infos.webPort
  78. }
  79. case "faucet":
  80. if infos, err := checkFaucet(client, w.network); err == nil {
  81. port = infos.port
  82. }
  83. }
  84. if page, err := resolve(client, w.network, service, port); err == nil && page != "" {
  85. pages = append(pages, page)
  86. }
  87. }
  88. // Promt the user to chose one, enter manually or simply not list this service
  89. defLabel, defChoice := "don't list", len(pages)+2
  90. if len(pages) > 0 {
  91. defLabel, defChoice = pages[0], 1
  92. }
  93. fmt.Println()
  94. fmt.Printf("Which %s service to list? (default = %s)\n", service, defLabel)
  95. for i, page := range pages {
  96. fmt.Printf(" %d. %s\n", i+1, page)
  97. }
  98. fmt.Printf(" %d. List external %s service\n", len(pages)+1, service)
  99. fmt.Printf(" %d. Don't list any %s service\n", len(pages)+2, service)
  100. choice := w.readDefaultInt(defChoice)
  101. if choice < 0 || choice > len(pages)+2 {
  102. log.Error("Invalid listing choice, aborting")
  103. return
  104. }
  105. var page string
  106. switch {
  107. case choice <= len(pages):
  108. page = pages[choice-1]
  109. case choice == len(pages)+1:
  110. fmt.Println()
  111. fmt.Printf("Which address is the external %s service at?\n", service)
  112. page = w.readString()
  113. default:
  114. // No service hosting for this
  115. }
  116. // Save the users choice
  117. switch service {
  118. case "ethstats":
  119. infos.ethstats = page
  120. case "explorer":
  121. infos.explorer = page
  122. case "wallet":
  123. infos.wallet = page
  124. case "faucet":
  125. infos.faucet = page
  126. }
  127. }
  128. // If we have ethstats running, ask whether to make the secret public or not
  129. if w.conf.ethstats != "" {
  130. fmt.Println()
  131. fmt.Println("Include ethstats secret on dashboard (y/n)? (default = yes)")
  132. infos.trusted = w.readDefaultString("y") == "y"
  133. }
  134. // Try to deploy the dashboard container on the host
  135. nocache := false
  136. if existed {
  137. fmt.Println()
  138. fmt.Printf("Should the dashboard be built from scratch (y/n)? (default = no)\n")
  139. nocache = w.readDefaultString("n") != "n"
  140. }
  141. if out, err := deployDashboard(client, w.network, &w.conf, infos, nocache); err != nil {
  142. log.Error("Failed to deploy dashboard container", "err", err)
  143. if len(out) > 0 {
  144. fmt.Printf("%s\n", out)
  145. }
  146. return
  147. }
  148. // All ok, run a network scan to pick any changes up
  149. w.networkStats()
  150. }