faucet.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>{{.Network}}: Authenticated Faucet</title>
  8. <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
  9. <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
  10. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-noty/2.4.1/packaged/jquery.noty.packaged.min.js"></script>
  12. <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
  13. <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.0/moment.min.js"></script>
  14. <style>
  15. .vertical-center {
  16. min-height: 100%;
  17. min-height: 100vh;
  18. display: flex;
  19. align-items: center;
  20. }
  21. .progress {
  22. position: relative;
  23. }
  24. .progress span {
  25. position: absolute;
  26. display: block;
  27. width: 100%;
  28. color: white;
  29. }
  30. pre {
  31. padding: 6px;
  32. margin: 0;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <div class="vertical-center">
  38. <div class="container">
  39. <div class="row" style="margin-bottom: 16px;">
  40. <div class="col-lg-12">
  41. <h1 style="text-align: center;"><i class="fa fa-bath" aria-hidden="true"></i> {{.Network}} Authenticated Faucet</h1>
  42. </div>
  43. </div>
  44. <div class="row">
  45. <div class="col-lg-8 col-lg-offset-2">
  46. <div class="input-group">
  47. <input id="url" name="url" type="text" class="form-control" placeholder="Social network URL containing your Ethereum address..."/>
  48. <span class="input-group-btn">
  49. <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Give me Ether <i class="fa fa-caret-down" aria-hidden="true"></i></button>
  50. <ul class="dropdown-menu dropdown-menu-right">{{range $idx, $amount := .Amounts}}
  51. <li><a style="text-align: center;" onclick="tier={{$idx}}; {{if $.Recaptcha}}grecaptcha.execute(){{else}}submit({{$idx}}){{end}}">{{$amount}} / {{index $.Periods $idx}}</a></li>{{end}}
  52. </ul>
  53. </span>
  54. </div>{{if .Recaptcha}}
  55. <div class="g-recaptcha" data-sitekey="{{.Recaptcha}}" data-callback="submit" data-size="invisible"></div>{{end}}
  56. </div>
  57. </div>
  58. <div class="row" style="margin-top: 32px;">
  59. <div class="col-lg-6 col-lg-offset-3">
  60. <div class="panel panel-small panel-default">
  61. <div class="panel-body" style="padding: 0; overflow: auto; max-height: 300px;">
  62. <table id="requests" class="table table-condensed" style="margin: 0;"></table>
  63. </div>
  64. <div class="panel-footer">
  65. <table style="width: 100%"><tr>
  66. <td style="text-align: center;"><i class="fa fa-rss" aria-hidden="true"></i> <span id="peers"></span> peers</td>
  67. <td style="text-align: center;"><i class="fa fa-database" aria-hidden="true"></i> <span id="block"></span> blocks</td>
  68. <td style="text-align: center;"><i class="fa fa-heartbeat" aria-hidden="true"></i> <span id="funds"></span> Ethers</td>
  69. <td style="text-align: center;"><i class="fa fa-university" aria-hidden="true"></i> <span id="funded"></span> funded</td>
  70. </tr></table>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="row" style="margin-top: 32px;">
  76. <div class="col-lg-12">
  77. <h3>How does this work?</h3>
  78. <p>This Ether faucet is running on the {{.Network}} network. To prevent malicious actors from exhausting all available funds or accumulating enough Ether to mount long running spam attacks, requests are tied to common 3rd party social network accounts. Anyone having a Twitter or Facebook account may request funds within the permitted limits.</p>
  79. <dl class="dl-horizontal">
  80. <dt style="width: auto; margin-left: 40px;"><i class="fa fa-twitter" aria-hidden="true" style="font-size: 36px;"></i></dt>
  81. <dd style="margin-left: 88px; margin-bottom: 10px;"></i> To request funds via Twitter, make a <a href="https://twitter.com/intent/tweet?text=Requesting%20faucet%20funds%20into%200x0000000000000000000000000000000000000000%20on%20the%20%23{{.Network}}%20%23Ethereum%20test%20network." target="_about:blank">tweet</a> with your Ethereum address pasted into the contents (surrounding text doesn't matter).<br/>Copy-paste the <a href="https://support.twitter.com/articles/80586" target="_about:blank">tweets URL</a> into the above input box and fire away!</dd>
  82. <dt style="width: auto; margin-left: 40px;"><i class="fa fa-facebook" aria-hidden="true" style="font-size: 36px;"></i></dt>
  83. <dd style="margin-left: 88px; margin-bottom: 10px;"></i> To request funds via Facebook, publish a new <strong>public</strong> post with your Ethereum address embedded into the content (surrounding text doesn't matter).<br/>Copy-paste the <a href="https://www.facebook.com/help/community/question/?id=282662498552845" target="_about:blank">posts URL</a> into the above input box and fire away!</dd>
  84. {{if .NoAuth}}
  85. <dt class="text-danger" style="width: auto; margin-left: 40px;"><i class="fa fa-unlock-alt" aria-hidden="true" style="font-size: 36px;"></i></dt>
  86. <dd class="text-danger" style="margin-left: 88px; margin-bottom: 10px;"></i> To request funds <strong>without authentication</strong>, simply copy-paste your Ethereum address into the above input box (surrounding text doesn't matter) and fire away.<br/>This mode is susceptible to Byzantine attacks. Only use for debugging or private networks!</dd>
  87. {{end}}
  88. </dl>
  89. <p>You can track the current pending requests below the input field to see how much you have to wait until your turn comes.</p>
  90. {{if .Recaptcha}}<em>The faucet is running invisible reCaptcha protection against bots.</em>{{end}}
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. <script>
  96. // Global variables to hold the current status of the faucet
  97. var attempt = 0;
  98. var server;
  99. var tier = 0;
  100. var requests = [];
  101. // Define a function that creates closures to drop old requests
  102. var dropper = function(hash) {
  103. return function() {
  104. for (var i=0; i<requests.length; i++) {
  105. if (requests[i].tx.hash == hash) {
  106. requests.splice(i, 1);
  107. break;
  108. }
  109. }
  110. }
  111. };
  112. // Define the function that submits a gist url to the server
  113. var submit = function({{if .Recaptcha}}captcha{{end}}) {
  114. server.send(JSON.stringify({url: $("#url")[0].value, tier: tier{{if .Recaptcha}}, captcha: captcha{{end}}}));{{if .Recaptcha}}
  115. grecaptcha.reset();{{end}}
  116. };
  117. // Define a method to reconnect upon server loss
  118. var reconnect = function() {
  119. server = new WebSocket(((window.location.protocol === "https:") ? "wss://" : "ws://") + window.location.host + "/api");
  120. server.onmessage = function(event) {
  121. var msg = JSON.parse(event.data);
  122. if (msg === null) {
  123. return;
  124. }
  125. if (msg.funds !== undefined) {
  126. $("#funds").text(msg.funds);
  127. }
  128. if (msg.funded !== undefined) {
  129. $("#funded").text(msg.funded);
  130. }
  131. if (msg.peers !== undefined) {
  132. $("#peers").text(msg.peers);
  133. }
  134. if (msg.number !== undefined) {
  135. $("#block").text(parseInt(msg.number, 16));
  136. }
  137. if (msg.error !== undefined) {
  138. noty({layout: 'topCenter', text: msg.error, type: 'error', timeout: 5000, progressBar: true});
  139. }
  140. if (msg.success !== undefined) {
  141. noty({layout: 'topCenter', text: msg.success, type: 'success', timeout: 5000, progressBar: true});
  142. }
  143. if (msg.requests !== undefined && msg.requests !== null) {
  144. // Mark all previous requests missing as done
  145. for (var i=0; i<requests.length; i++) {
  146. if (msg.requests.length > 0 && msg.requests[0].tx.hash == requests[i].tx.hash) {
  147. break;
  148. }
  149. if (requests[i].time != "") {
  150. requests[i].time = "";
  151. setTimeout(dropper(requests[i].tx.hash), 3000);
  152. }
  153. }
  154. // Append any new requests into our local collection
  155. var common = -1;
  156. if (requests.length > 0) {
  157. for (var i=0; i<msg.requests.length; i++) {
  158. if (requests[requests.length-1].tx.hash == msg.requests[i].tx.hash) {
  159. common = i;
  160. break;
  161. }
  162. }
  163. }
  164. for (var i=common+1; i<msg.requests.length; i++) {
  165. requests.push(msg.requests[i]);
  166. }
  167. // Iterate over our entire local collection and re-render the funding table
  168. var content = "";
  169. for (var i=requests.length-1; i >= 0; i--) {
  170. var done = requests[i].time == "";
  171. var elapsed = moment().unix()-moment(requests[i].time).unix();
  172. content += "<tr id='" + requests[i].tx.hash + "'>";
  173. content += " <td><div style=\"background: url('" + requests[i].avatar + "'); background-size: cover; width:32px; height: 32px; border-radius: 4px;\"></div></td>";
  174. content += " <td><pre>" + requests[i].account + "</pre></td>";
  175. content += " <td style=\"width: 100%; text-align: center; vertical-align: middle;\">";
  176. if (done) {
  177. content += " funded";
  178. } else {
  179. content += " <span id='time-" + i + "' class='timer'>" + moment.duration(-elapsed, 'seconds').humanize(true) + "</span>";
  180. }
  181. content += " <div class='progress' style='height: 4px; margin: 0;'>";
  182. if (done) {
  183. content += " <div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='30' style='width:100%;'></div>";
  184. } else if (elapsed > 30) {
  185. content += " <div class='progress-bar progress-bar-danger progress-bar-striped active' role='progressbar' aria-valuenow='30' style='width:100%;'></div>";
  186. } else {
  187. content += " <div class='progress-bar progress-bar-striped active' role='progressbar' aria-valuenow='" + elapsed + "' style='width:" + (elapsed * 100 / 30) + "%;'></div>";
  188. }
  189. content += " </div>";
  190. content += " </td>";
  191. content += "</tr>";
  192. }
  193. $("#requests").html("<tbody>" + content + "</tbody>");
  194. }
  195. }
  196. server.onclose = function() { setTimeout(reconnect, 3000); };
  197. }
  198. // Start a UI updater to push the progress bars forward until they are done
  199. setInterval(function() {
  200. $('.progress-bar').each(function() {
  201. var progress = Number($(this).attr('aria-valuenow')) + 1;
  202. if (progress < 30) {
  203. $(this).attr('aria-valuenow', progress);
  204. $(this).css('width', (progress * 100 / 30) + '%');
  205. } else if (progress == 30) {
  206. $(this).css('width', '100%');
  207. $(this).addClass("progress-bar-danger");
  208. }
  209. })
  210. $('.timer').each(function() {
  211. var index = Number($(this).attr('id').substring(5));
  212. $(this).html(moment.duration(moment(requests[index].time).unix()-moment().unix(), 'seconds').humanize(true));
  213. })
  214. }, 1000);
  215. // Establish a websocket connection to the API server
  216. reconnect();
  217. </script>{{if .Recaptcha}}
  218. <script src="https://www.google.com/recaptcha/api.js" async defer></script>{{end}}
  219. </body>
  220. </html>