github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/cmd/puppeth/wizard_faucet.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 "encoding/json" 16 "fmt" 17 18 "github.com/Sberex/go-sberex/accounts/keystore" 19 "github.com/Sberex/go-sberex/log" 20 ) 21 22 // deployFaucet queries the user for various input on deploying a faucet, after 23 // which it executes it. 24 func (w *wizard) deployFaucet() { 25 // Select the server to interact with 26 server := w.selectServer() 27 if server == "" { 28 return 29 } 30 client := w.servers[server] 31 32 // Retrieve any active faucet configurations from the server 33 infos, err := checkFaucet(client, w.network) 34 if err != nil { 35 infos = &faucetInfos{ 36 node: &nodeInfos{port: 30303, peersTotal: 25}, 37 port: 80, 38 host: client.server, 39 amount: 1, 40 minutes: 1440, 41 tiers: 3, 42 } 43 } 44 existed := err == nil 45 46 infos.node.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") 47 infos.node.network = w.conf.Genesis.Config.ChainId.Int64() 48 49 // Figure out which port to listen on 50 fmt.Println() 51 fmt.Printf("Which port should the faucet listen on? (default = %d)\n", infos.port) 52 infos.port = w.readDefaultInt(infos.port) 53 54 // Figure which virtual-host to deploy ethstats on 55 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 56 log.Error("Failed to decide on faucet host", "err", err) 57 return 58 } 59 // Port and proxy settings retrieved, figure out the funding amount per period configurations 60 fmt.Println() 61 fmt.Printf("How many Ethers to release per request? (default = %d)\n", infos.amount) 62 infos.amount = w.readDefaultInt(infos.amount) 63 64 fmt.Println() 65 fmt.Printf("How many minutes to enforce between requests? (default = %d)\n", infos.minutes) 66 infos.minutes = w.readDefaultInt(infos.minutes) 67 68 fmt.Println() 69 fmt.Printf("How many funding tiers to feature (x2.5 amounts, x3 timeout)? (default = %d)\n", infos.tiers) 70 infos.tiers = w.readDefaultInt(infos.tiers) 71 if infos.tiers == 0 { 72 log.Error("At least one funding tier must be set") 73 return 74 } 75 // Accessing the reCaptcha service requires API authorizations, request it 76 if infos.captchaToken != "" { 77 fmt.Println() 78 fmt.Println("Reuse previous reCaptcha API authorization (y/n)? (default = yes)") 79 if w.readDefaultString("y") != "y" { 80 infos.captchaToken, infos.captchaSecret = "", "" 81 } 82 } 83 if infos.captchaToken == "" { 84 // No previous authorization (or old one discarded) 85 fmt.Println() 86 fmt.Println("Enable reCaptcha protection against robots (y/n)? (default = no)") 87 if w.readDefaultString("n") == "n" { 88 log.Warn("Users will be able to requests funds via automated scripts") 89 } else { 90 // Captcha protection explicitly requested, read the site and secret keys 91 fmt.Println() 92 fmt.Printf("What is the reCaptcha site key to authenticate human users?\n") 93 infos.captchaToken = w.readString() 94 95 fmt.Println() 96 fmt.Printf("What is the reCaptcha secret key to verify authentications? (won't be echoed)\n") 97 infos.captchaSecret = w.readPassword() 98 } 99 } 100 // Figure out where the user wants to store the persistent data 101 fmt.Println() 102 if infos.node.datadir == "" { 103 fmt.Printf("Where should data be stored on the remote machine?\n") 104 infos.node.datadir = w.readString() 105 } else { 106 fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.node.datadir) 107 infos.node.datadir = w.readDefaultString(infos.node.datadir) 108 } 109 // Figure out which port to listen on 110 fmt.Println() 111 fmt.Printf("Which TCP/UDP port should the light client listen on? (default = %d)\n", infos.node.port) 112 infos.node.port = w.readDefaultInt(infos.node.port) 113 114 // Set a proper name to report on the stats page 115 fmt.Println() 116 if infos.node.ethstats == "" { 117 fmt.Printf("What should the node be called on the stats page?\n") 118 infos.node.ethstats = w.readString() + ":" + w.conf.ethstats 119 } else { 120 fmt.Printf("What should the node be called on the stats page? (default = %s)\n", infos.node.ethstats) 121 infos.node.ethstats = w.readDefaultString(infos.node.ethstats) + ":" + w.conf.ethstats 122 } 123 // Load up the credential needed to release funds 124 if infos.node.keyJSON != "" { 125 if key, err := keystore.DecryptKey([]byte(infos.node.keyJSON), infos.node.keyPass); err != nil { 126 infos.node.keyJSON, infos.node.keyPass = "", "" 127 } else { 128 fmt.Println() 129 fmt.Printf("Reuse previous (%s) funding account (y/n)? (default = yes)\n", key.Address.Hex()) 130 if w.readDefaultString("y") != "y" { 131 infos.node.keyJSON, infos.node.keyPass = "", "" 132 } 133 } 134 } 135 for i := 0; i < 3 && infos.node.keyJSON == ""; i++ { 136 fmt.Println() 137 fmt.Println("Please paste the faucet's funding account key JSON:") 138 infos.node.keyJSON = w.readJSON() 139 140 fmt.Println() 141 fmt.Println("What's the unlock password for the account? (won't be echoed)") 142 infos.node.keyPass = w.readPassword() 143 144 if _, err := keystore.DecryptKey([]byte(infos.node.keyJSON), infos.node.keyPass); err != nil { 145 log.Error("Failed to decrypt key with given passphrase") 146 infos.node.keyJSON = "" 147 infos.node.keyPass = "" 148 } 149 } 150 // Check if the user wants to run the faucet in debug mode (noauth) 151 noauth := "n" 152 if infos.noauth { 153 noauth = "y" 154 } 155 fmt.Println() 156 fmt.Printf("Permit non-authenticated funding requests (y/n)? (default = %v)\n", infos.noauth) 157 infos.noauth = w.readDefaultString(noauth) != "n" 158 159 // Try to deploy the faucet server on the host 160 nocache := false 161 if existed { 162 fmt.Println() 163 fmt.Printf("Should the faucet be built from scratch (y/n)? (default = no)\n") 164 nocache = w.readDefaultString("n") != "n" 165 } 166 if out, err := deployFaucet(client, w.network, w.conf.bootnodes, infos, nocache); err != nil { 167 log.Error("Failed to deploy faucet container", "err", err) 168 if len(out) > 0 { 169 fmt.Printf("%s\n", out) 170 } 171 return 172 } 173 // All ok, run a network scan to pick any changes up 174 w.networkStats() 175 }