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