wizard_dashboard.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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", "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.port
  74. }
  75. case "faucet":
  76. if infos, err := checkFaucet(client, w.network); err == nil {
  77. port = infos.port
  78. }
  79. }
  80. if page, err := resolve(client, w.network, service, port); err == nil && page != "" {
  81. pages = append(pages, page)
  82. }
  83. }
  84. // Prompt the user to chose one, enter manually or simply not list this service
  85. defLabel, defChoice := "don't list", len(pages)+2
  86. if len(pages) > 0 {
  87. defLabel, defChoice = pages[0], 1
  88. }
  89. fmt.Println()
  90. fmt.Printf("Which %s service to list? (default = %s)\n", service, defLabel)
  91. for i, page := range pages {
  92. fmt.Printf(" %d. %s\n", i+1, page)
  93. }
  94. fmt.Printf(" %d. List external %s service\n", len(pages)+1, service)
  95. fmt.Printf(" %d. Don't list any %s service\n", len(pages)+2, service)
  96. choice := w.readDefaultInt(defChoice)
  97. if choice < 0 || choice > len(pages)+2 {
  98. log.Error("Invalid listing choice, aborting")
  99. return
  100. }
  101. var page string
  102. switch {
  103. case choice <= len(pages):
  104. page = pages[choice-1]
  105. case choice == len(pages)+1:
  106. fmt.Println()
  107. fmt.Printf("Which address is the external %s service at?\n", service)
  108. page = w.readString()
  109. default:
  110. // No service hosting for this
  111. }
  112. // Save the users choice
  113. switch service {
  114. case "ethstats":
  115. infos.ethstats = page
  116. case "explorer":
  117. infos.explorer = page
  118. case "faucet":
  119. infos.faucet = page
  120. }
  121. }
  122. // If we have ethstats running, ask whether to make the secret public or not
  123. if w.conf.ethstats != "" {
  124. fmt.Println()
  125. fmt.Println("Include ethstats secret on dashboard (y/n)? (default = yes)")
  126. infos.trusted = w.readDefaultYesNo(true)
  127. }
  128. // Try to deploy the dashboard container on the host
  129. nocache := false
  130. if existed {
  131. fmt.Println()
  132. fmt.Printf("Should the dashboard be built from scratch (y/n)? (default = no)\n")
  133. nocache = w.readDefaultYesNo(false)
  134. }
  135. if out, err := deployDashboard(client, w.network, &w.conf, infos, nocache); err != nil {
  136. log.Error("Failed to deploy dashboard container", "err", err)
  137. if len(out) > 0 {
  138. fmt.Printf("%s\n", out)
  139. }
  140. return
  141. }
  142. // All ok, run a network scan to pick any changes up
  143. w.networkStats()
  144. }