github.com/waltonchain/waltonchain_gwtc_src@v1.1.4-0.20201225072101-8a298c95a819/cmd/puppeth/wizard_ethstats.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 // deployEthstats queries the user for various input on deploying an ethstats 26 // monitoring server, after which it executes it. 27 func (w *wizard) deployEthstats() { 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 ethstats configurations from the server 36 infos, err := checkEthstats(client, w.network) 37 if err != nil { 38 infos = ðstatsInfos{ 39 port: 80, 40 host: client.server, 41 secret: "", 42 } 43 } 44 // Figure out which port to listen on 45 fmt.Println() 46 fmt.Printf("Which port should ethstats listen on? (default = %d)\n", infos.port) 47 infos.port = w.readDefaultInt(infos.port) 48 49 // Figure which virtual-host to deploy ethstats on 50 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 51 log.Error("Failed to decide on ethstats host", "err", err) 52 return 53 } 54 // Port and proxy settings retrieved, figure out the secret and boot ethstats 55 fmt.Println() 56 if infos.secret == "" { 57 fmt.Printf("What should be the secret password for the API? (must not be empty)\n") 58 infos.secret = w.readString() 59 } else { 60 fmt.Printf("What should be the secret password for the API? (default = %s)\n", infos.secret) 61 infos.secret = w.readDefaultString(infos.secret) 62 } 63 // Gather any blacklists to ban from reporting 64 fmt.Println() 65 fmt.Printf("Keep existing IP %v blacklist (y/n)? (default = yes)\n", infos.banned) 66 if w.readDefaultString("y") != "y" { 67 infos.banned = nil 68 69 fmt.Println() 70 fmt.Println("Which IP addresses should be blacklisted?") 71 for { 72 if ip := w.readIPAddress(); ip != nil { 73 infos.banned = append(infos.banned, ip.String()) 74 continue 75 } 76 break 77 } 78 } 79 // Try to deploy the ethstats server on the host 80 trusted := make([]string, 0, len(w.servers)) 81 for _, client := range w.servers { 82 if client != nil { 83 trusted = append(trusted, client.address) 84 } 85 } 86 if out, err := deployEthstats(client, w.network, infos.port, infos.secret, infos.host, trusted, infos.banned); err != nil { 87 log.Error("Failed to deploy ethstats container", "err", err) 88 if len(out) > 0 { 89 fmt.Printf("%s\n", out) 90 } 91 return 92 } 93 // All ok, run a network scan to pick any changes up 94 w.networkStats(false) 95 }