github.com/JFJun/bsc@v1.0.0/cmd/puppeth/wizard_ethstats.go (about) 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 17 package main 18 19 import ( 20 "fmt" 21 "sort" 22 23 "github.com/JFJun/bsc/log" 24 ) 25 26 // deployEthstats queries the user for various input on deploying an ethstats 27 // monitoring server, after which it executes it. 28 func (w *wizard) deployEthstats() { 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 ethstats configurations from the server 37 infos, err := checkEthstats(client, w.network) 38 if err != nil { 39 infos = ðstatsInfos{ 40 port: 80, 41 host: client.server, 42 secret: "", 43 } 44 } 45 existed := err == nil 46 47 // Figure out which port to listen on 48 fmt.Println() 49 fmt.Printf("Which port should ethstats listen on? (default = %d)\n", infos.port) 50 infos.port = w.readDefaultInt(infos.port) 51 52 // Figure which virtual-host to deploy ethstats on 53 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 54 log.Error("Failed to decide on ethstats host", "err", err) 55 return 56 } 57 // Port and proxy settings retrieved, figure out the secret and boot ethstats 58 fmt.Println() 59 if infos.secret == "" { 60 fmt.Printf("What should be the secret password for the API? (must not be empty)\n") 61 infos.secret = w.readString() 62 } else { 63 fmt.Printf("What should be the secret password for the API? (default = %s)\n", infos.secret) 64 infos.secret = w.readDefaultString(infos.secret) 65 } 66 // Gather any blacklists to ban from reporting 67 if existed { 68 fmt.Println() 69 fmt.Printf("Keep existing IP %v blacklist (y/n)? (default = yes)\n", infos.banned) 70 if !w.readDefaultYesNo(true) { 71 // The user might want to clear the entire list, although generally probably not 72 fmt.Println() 73 fmt.Printf("Clear out blacklist and start over (y/n)? (default = no)\n") 74 if w.readDefaultYesNo(false) { 75 infos.banned = nil 76 } 77 // Offer the user to explicitly add/remove certain IP addresses 78 fmt.Println() 79 fmt.Println("Which additional IP addresses should be blacklisted?") 80 for { 81 if ip := w.readIPAddress(); ip != "" { 82 infos.banned = append(infos.banned, ip) 83 continue 84 } 85 break 86 } 87 fmt.Println() 88 fmt.Println("Which IP addresses should not be blacklisted?") 89 for { 90 if ip := w.readIPAddress(); ip != "" { 91 for i, addr := range infos.banned { 92 if ip == addr { 93 infos.banned = append(infos.banned[:i], infos.banned[i+1:]...) 94 break 95 } 96 } 97 continue 98 } 99 break 100 } 101 sort.Strings(infos.banned) 102 } 103 } 104 // Try to deploy the ethstats server on the host 105 nocache := false 106 if existed { 107 fmt.Println() 108 fmt.Printf("Should the ethstats be built from scratch (y/n)? (default = no)\n") 109 nocache = w.readDefaultYesNo(false) 110 } 111 trusted := make([]string, 0, len(w.servers)) 112 for _, client := range w.servers { 113 if client != nil { 114 trusted = append(trusted, client.address) 115 } 116 } 117 if out, err := deployEthstats(client, w.network, infos.port, infos.secret, infos.host, trusted, infos.banned, nocache); err != nil { 118 log.Error("Failed to deploy ethstats container", "err", err) 119 if len(out) > 0 { 120 fmt.Printf("%s\n", out) 121 } 122 return 123 } 124 // All ok, run a network scan to pick any changes up 125 w.networkStats() 126 }