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