wizard_faucet.go 6.7 KB

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