github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/cmd/puppeth/wizard_ethstats.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package main 13 14 import ( 15 "fmt" 16 "sort" 17 18 "github.com/Sberex/go-sberex/log" 19 ) 20 21 // deployEthstats queries the user for various input on deploying an ethstats 22 // monitoring server, after which it executes it. 23 func (w *wizard) deployEthstats() { 24 // Select the server to interact with 25 server := w.selectServer() 26 if server == "" { 27 return 28 } 29 client := w.servers[server] 30 31 // Retrieve any active ethstats configurations from the server 32 infos, err := checkEthstats(client, w.network) 33 if err != nil { 34 infos = ðstatsInfos{ 35 port: 80, 36 host: client.server, 37 secret: "", 38 } 39 } 40 existed := err == nil 41 42 // Figure out which port to listen on 43 fmt.Println() 44 fmt.Printf("Which port should ethstats listen on? (default = %d)\n", infos.port) 45 infos.port = w.readDefaultInt(infos.port) 46 47 // Figure which virtual-host to deploy ethstats on 48 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 49 log.Error("Failed to decide on ethstats host", "err", err) 50 return 51 } 52 // Port and proxy settings retrieved, figure out the secret and boot ethstats 53 fmt.Println() 54 if infos.secret == "" { 55 fmt.Printf("What should be the secret password for the API? (must not be empty)\n") 56 infos.secret = w.readString() 57 } else { 58 fmt.Printf("What should be the secret password for the API? (default = %s)\n", infos.secret) 59 infos.secret = w.readDefaultString(infos.secret) 60 } 61 // Gather any blacklists to ban from reporting 62 if existed { 63 fmt.Println() 64 fmt.Printf("Keep existing IP %v blacklist (y/n)? (default = yes)\n", infos.banned) 65 if w.readDefaultString("y") != "y" { 66 // The user might want to clear the entire list, although generally probably not 67 fmt.Println() 68 fmt.Printf("Clear out blacklist and start over (y/n)? (default = no)\n") 69 if w.readDefaultString("n") != "n" { 70 infos.banned = nil 71 } 72 // Offer the user to explicitly add/remove certain IP addresses 73 fmt.Println() 74 fmt.Println("Which additional IP addresses should be blacklisted?") 75 for { 76 if ip := w.readIPAddress(); ip != "" { 77 infos.banned = append(infos.banned, ip) 78 continue 79 } 80 break 81 } 82 fmt.Println() 83 fmt.Println("Which IP addresses should not be blacklisted?") 84 for { 85 if ip := w.readIPAddress(); ip != "" { 86 for i, addr := range infos.banned { 87 if ip == addr { 88 infos.banned = append(infos.banned[:i], infos.banned[i+1:]...) 89 break 90 } 91 } 92 continue 93 } 94 break 95 } 96 sort.Strings(infos.banned) 97 } 98 } 99 // Try to deploy the ethstats server on the host 100 nocache := false 101 if existed { 102 fmt.Println() 103 fmt.Printf("Should the ethstats be built from scratch (y/n)? (default = no)\n") 104 nocache = w.readDefaultString("n") != "n" 105 } 106 trusted := make([]string, 0, len(w.servers)) 107 for _, client := range w.servers { 108 if client != nil { 109 trusted = append(trusted, client.address) 110 } 111 } 112 if out, err := deployEthstats(client, w.network, infos.port, infos.secret, infos.host, trusted, infos.banned, nocache); err != nil { 113 log.Error("Failed to deploy ethstats container", "err", err) 114 if len(out) > 0 { 115 fmt.Printf("%s\n", out) 116 } 117 return 118 } 119 // All ok, run a network scan to pick any changes up 120 w.networkStats() 121 }