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