wizard_faucet.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.readDefaultString("y") != "y" {
  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.readDefaultString("n") == "n" {
  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. // Figure out where the user wants to store the persistent data
  95. fmt.Println()
  96. if infos.node.datadir == "" {
  97. fmt.Printf("Where should data be stored on the remote machine?\n")
  98. infos.node.datadir = w.readString()
  99. } else {
  100. fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.node.datadir)
  101. infos.node.datadir = w.readDefaultString(infos.node.datadir)
  102. }
  103. // Figure out which port to listen on
  104. fmt.Println()
  105. fmt.Printf("Which TCP/UDP port should the light client listen on? (default = %d)\n", infos.node.port)
  106. infos.node.port = w.readDefaultInt(infos.node.port)
  107. // Set a proper name to report on the stats page
  108. fmt.Println()
  109. if infos.node.ethstats == "" {
  110. fmt.Printf("What should the node be called on the stats page?\n")
  111. infos.node.ethstats = w.readString() + ":" + w.conf.ethstats
  112. } else {
  113. fmt.Printf("What should the node be called on the stats page? (default = %s)\n", infos.node.ethstats)
  114. infos.node.ethstats = w.readDefaultString(infos.node.ethstats) + ":" + w.conf.ethstats
  115. }
  116. // Load up the credential needed to release funds
  117. if infos.node.keyJSON != "" {
  118. if key, err := keystore.DecryptKey([]byte(infos.node.keyJSON), infos.node.keyPass); err != nil {
  119. infos.node.keyJSON, infos.node.keyPass = "", ""
  120. } else {
  121. fmt.Println()
  122. fmt.Printf("Reuse previous (%s) funding account (y/n)? (default = yes)\n", key.Address.Hex())
  123. if w.readDefaultString("y") != "y" {
  124. infos.node.keyJSON, infos.node.keyPass = "", ""
  125. }
  126. }
  127. }
  128. for i := 0; i < 3 && infos.node.keyJSON == ""; i++ {
  129. fmt.Println()
  130. fmt.Println("Please paste the faucet's funding account key JSON:")
  131. infos.node.keyJSON = w.readJSON()
  132. fmt.Println()
  133. fmt.Println("What's the unlock password for the account? (won't be echoed)")
  134. infos.node.keyPass = w.readPassword()
  135. if _, err := keystore.DecryptKey([]byte(infos.node.keyJSON), infos.node.keyPass); err != nil {
  136. log.Error("Failed to decrypt key with given passphrase")
  137. infos.node.keyJSON = ""
  138. infos.node.keyPass = ""
  139. }
  140. }
  141. // Check if the user wants to run the faucet in debug mode (noauth)
  142. noauth := "n"
  143. if infos.noauth {
  144. noauth = "y"
  145. }
  146. fmt.Println()
  147. fmt.Printf("Permit non-authenticated funding requests (y/n)? (default = %v)\n", infos.noauth)
  148. infos.noauth = w.readDefaultString(noauth) != "n"
  149. // Try to deploy the faucet server on the host
  150. nocache := false
  151. if existed {
  152. fmt.Println()
  153. fmt.Printf("Should the faucet be built from scratch (y/n)? (default = no)\n")
  154. nocache = w.readDefaultString("n") != "n"
  155. }
  156. if out, err := deployFaucet(client, w.network, w.conf.bootnodes, infos, nocache); err != nil {
  157. log.Error("Failed to deploy faucet container", "err", err)
  158. if len(out) > 0 {
  159. fmt.Printf("%s\n", out)
  160. }
  161. return
  162. }
  163. // All ok, run a network scan to pick any changes up
  164. w.networkStats()
  165. }