faucet.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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, Google+ 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-google-plus-official" aria-hidden="true" style="font-size: 36px;"></i></dt>
  83. <dd style="margin-left: 88px; margin-bottom: 10px;"></i> To request funds via Google Plus, publish a new <strong>public</strong> post with your Ethereum address embedded into the content (surrounding text doesn't matter).<br/>Copy-paste the posts URL into the above input box and fire away!</dd>
  84. <dt style="width: auto; margin-left: 40px;"><i class="fa fa-facebook" aria-hidden="true" style="font-size: 36px;"></i></dt>
  85. <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>
  86. {{if .NoAuth}}
  87. <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>
  88. <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>
  89. {{end}}
  90. </dl>
  91. <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>
  92. {{if .Recaptcha}}<em>The faucet is running invisible reCaptcha protection against bots.</em>{{end}}
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. <script>
  98. // Global variables to hold the current status of the faucet
  99. var attempt = 0;
  100. var server;
  101. var tier = 0;
  102. var requests = [];
  103. // Define a function that creates closures to drop old requests
  104. var dropper = function(hash) {
  105. return function() {
  106. for (var i=0; i<requests.length; i++) {
  107. if (requests[i].tx.hash == hash) {
  108. requests.splice(i, 1);
  109. break;
  110. }
  111. }
  112. }
  113. };
  114. // Define the function that submits a gist url to the server
  115. var submit = function({{if .Recaptcha}}captcha{{end}}) {
  116. server.send(JSON.stringify({url: $("#url")[0].value, tier: tier{{if .Recaptcha}}, captcha: captcha{{end}}}));{{if .Recaptcha}}
  117. grecaptcha.reset();{{end}}
  118. };
  119. // Define a method to reconnect upon server loss
  120. var reconnect = function() {
  121. server = new WebSocket(((window.location.protocol === "https:") ? "wss://" : "ws://") + window.location.host + "/api");
  122. server.onmessage = function(event) {
  123. var msg = JSON.parse(event.data);
  124. if (msg === null) {
  125. return;
  126. }
  127. if (msg.funds !== undefined) {
  128. $("#funds").text(msg.funds);
  129. }
  130. if (msg.funded !== undefined) {
  131. $("#funded").text(msg.funded);
  132. }
  133. if (msg.peers !== undefined) {
  134. $("#peers").text(msg.peers);
  135. }
  136. if (msg.number !== undefined) {
  137. $("#block").text(parseInt(msg.number, 16));
  138. }
  139. if (msg.error !== undefined) {
  140. noty({layout: 'topCenter', text: msg.error, type: 'error', timeout: 5000, progressBar: true});
  141. }
  142. if (msg.success !== undefined) {
  143. noty({layout: 'topCenter', text: msg.success, type: 'success', timeout: 5000, progressBar: true});
  144. }
  145. if (msg.requests !== undefined && msg.requests !== null) {
  146. // Mark all previous requests missing as done
  147. for (var i=0; i<requests.length; i++) {
  148. if (msg.requests.length > 0 && msg.requests[0].tx.hash == requests[i].tx.hash) {
  149. break;
  150. }
  151. if (requests[i].time != "") {
  152. requests[i].time = "";
  153. setTimeout(dropper(requests[i].tx.hash), 3000);
  154. }
  155. }
  156. // Append any new requests into our local collection
  157. var common = -1;
  158. if (requests.length > 0) {
  159. for (var i=0; i<msg.requests.length; i++) {
  160. if (requests[requests.length-1].tx.hash == msg.requests[i].tx.hash) {
  161. common = i;
  162. break;
  163. }
  164. }
  165. }
  166. for (var i=common+1; i<msg.requests.length; i++) {
  167. requests.push(msg.requests[i]);
  168. }
  169. // Iterate over our entire local collection and re-render the funding table
  170. var content = "";
  171. for (var i=0; i<requests.length; i++) {
  172. var done = requests[i].time == "";
  173. var elapsed = moment().unix()-moment(requests[i].time).unix();
  174. content += "<tr id='" + requests[i].tx.hash + "'>";
  175. content += " <td><div style=\"background: url('" + requests[i].avatar + "'); background-size: cover; width:32px; height: 32px; border-radius: 4px;\"></div></td>";
  176. content += " <td><pre>" + requests[i].account + "</pre></td>";
  177. content += " <td style=\"width: 100%; text-align: center; vertical-align: middle;\">";
  178. if (done) {
  179. content += " funded";
  180. } else {
  181. content += " <span id='time-" + i + "' class='timer'>" + moment.duration(-elapsed, 'seconds').humanize(true) + "</span>";
  182. }
  183. content += " <div class='progress' style='height: 4px; margin: 0;'>";
  184. if (done) {
  185. content += " <div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='30' style='width:100%;'></div>";
  186. } else if (elapsed > 30) {
  187. content += " <div class='progress-bar progress-bar-danger progress-bar-striped active' role='progressbar' aria-valuenow='30' style='width:100%;'></div>";
  188. } else {
  189. content += " <div class='progress-bar progress-bar-striped active' role='progressbar' aria-valuenow='" + elapsed + "' style='width:" + (elapsed * 100 / 30) + "%;'></div>";
  190. }
  191. content += " </div>";
  192. content += " </td>";
  193. content += "</tr>";
  194. }
  195. $("#requests").html("<tbody>" + content + "</tbody>");
  196. }
  197. }
  198. server.onclose = function() { setTimeout(reconnect, 3000); };
  199. }
  200. // Start a UI updater to push the progress bars forward until they are done
  201. setInterval(function() {
  202. $('.progress-bar').each(function() {
  203. var progress = Number($(this).attr('aria-valuenow')) + 1;
  204. if (progress < 30) {
  205. $(this).attr('aria-valuenow', progress);
  206. $(this).css('width', (progress * 100 / 30) + '%');
  207. } else if (progress == 30) {
  208. $(this).css('width', '100%');
  209. $(this).addClass("progress-bar-danger");
  210. }
  211. })
  212. $('.timer').each(function() {
  213. var index = Number($(this).attr('id').substring(5));
  214. $(this).html(moment.duration(moment(requests[index].time).unix()-moment().unix(), 'seconds').humanize(true));
  215. })
  216. }, 1000);
  217. // Establish a websocket connection to the API server
  218. reconnect();
  219. </script>{{if .Recaptcha}}
  220. <script src="https://www.google.com/recaptcha/api.js" async defer></script>{{end}}
  221. </body>
  222. </html>