github.com/waltonchain/waltonchain_gwtc_src@v1.1.4-0.20201225072101-8a298c95a819/cmd/puppeth/wizard_dashboard.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of go-wtc. 3 // 4 // go-wtc 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-wtc 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-wtc. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "fmt" 21 22 "github.com/wtc/go-wtc/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 // Figure out which port to listen on 44 fmt.Println() 45 fmt.Printf("Which port should the dashboard listen on? (default = %d)\n", infos.port) 46 infos.port = w.readDefaultInt(infos.port) 47 48 // Figure which virtual-host to deploy the dashboard on 49 infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host) 50 if err != nil { 51 log.Error("Failed to decide on dashboard host", "err", err) 52 return 53 } 54 // Port and proxy settings retrieved, figure out which services are available 55 available := make(map[string][]string) 56 for server, services := range w.services { 57 for _, service := range services { 58 available[service] = append(available[service], server) 59 } 60 } 61 listing := make(map[string]string) 62 for _, service := range []string{"ethstats", "explorer", "wallet", "faucet"} { 63 // Gather all the locally hosted pages of this type 64 var pages []string 65 for _, server := range available[service] { 66 client := w.servers[server] 67 if client == nil { 68 continue 69 } 70 // If there's a service running on the machine, retrieve it's port number 71 var port int 72 switch service { 73 case "ethstats": 74 if infos, err := checkEthstats(client, w.network); err == nil { 75 port = infos.port 76 } 77 case "faucet": 78 if infos, err := checkFaucet(client, w.network); err == nil { 79 port = infos.port 80 } 81 } 82 if page, err := resolve(client, w.network, service, port); err == nil && page != "" { 83 pages = append(pages, page) 84 } 85 } 86 // Promt the user to chose one, enter manually or simply not list this service 87 defLabel, defChoice := "don't list", len(pages)+2 88 if len(pages) > 0 { 89 defLabel, defChoice = pages[0], 1 90 } 91 fmt.Println() 92 fmt.Printf("Which %s service to list? (default = %s)\n", service, defLabel) 93 for i, page := range pages { 94 fmt.Printf(" %d. %s\n", i+1, page) 95 } 96 fmt.Printf(" %d. List external %s service\n", len(pages)+1, service) 97 fmt.Printf(" %d. Don't list any %s service\n", len(pages)+2, service) 98 99 choice := w.readDefaultInt(defChoice) 100 if choice < 0 || choice > len(pages)+2 { 101 log.Error("Invalid listing choice, aborting") 102 return 103 } 104 switch { 105 case choice <= len(pages): 106 listing[service] = pages[choice-1] 107 case choice == len(pages)+1: 108 fmt.Println() 109 fmt.Printf("Which address is the external %s service at?\n", service) 110 listing[service] = w.readString() 111 default: 112 // No service hosting for this 113 } 114 } 115 // If we have ethstats running, ask whether to make the secret public or not 116 var ethstats bool 117 if w.conf.ethstats != "" { 118 fmt.Println() 119 fmt.Println("Include ethstats secret on dashboard (y/n)? (default = yes)") 120 ethstats = w.readDefaultString("y") == "y" 121 } 122 // Try to deploy the dashboard container on the host 123 if out, err := deployDashboard(client, w.network, infos.port, infos.host, listing, &w.conf, ethstats); err != nil { 124 log.Error("Failed to deploy dashboard container", "err", err) 125 if len(out) > 0 { 126 fmt.Printf("%s\n", out) 127 } 128 return 129 } 130 // All ok, run a network scan to pick any changes up 131 w.networkStats(false) 132 }