Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
03dffe3e
Unverified
Commit
03dffe3e
authored
Apr 16, 2017
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/faucet: add optional recaptcha validation support
parent
cb3f5f8b
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
13 deletions
+49
-13
faucet.go
cmd/faucet/faucet.go
+40
-7
faucet.html
cmd/faucet/faucet.html
+8
-5
website.go
cmd/faucet/website.go
+1
-1
No files found.
cmd/faucet/faucet.go
View file @
03dffe3e
...
...
@@ -29,6 +29,7 @@ import (
"io/ioutil"
"math/big"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
...
...
@@ -73,6 +74,9 @@ var (
githubUser
=
flag
.
String
(
"github.user"
,
""
,
"GitHub user to authenticate with for Gist access"
)
githubToken
=
flag
.
String
(
"github.token"
,
""
,
"GitHub personal token to access Gists with"
)
captchaToken
=
flag
.
String
(
"captcha.token"
,
""
,
"Recaptcha site key to authenticate client side"
)
captchaSecret
=
flag
.
String
(
"captcha.secret"
,
""
,
"Recaptcha secret key to authenticate server side"
)
logFlag
=
flag
.
Int
(
"loglevel"
,
3
,
"Log level to use for Ethereum and the faucet"
)
)
...
...
@@ -99,6 +103,7 @@ func main() {
"Network"
:
*
netnameFlag
,
"Amount"
:
*
payoutFlag
,
"Period"
:
period
,
"Recaptcha"
:
*
captchaToken
,
})
// Load and parse the genesis block requested by the user
blob
,
err
:=
ioutil
.
ReadFile
(
*
genesisFlag
)
...
...
@@ -298,6 +303,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
// Fetch the next funding request and validate against github
var
msg
struct
{
URL
string
`json:"url"`
Captcha
string
`json:"captcha"`
}
if
err
:=
websocket
.
JSON
.
Receive
(
conn
,
&
msg
);
err
!=
nil
{
return
...
...
@@ -306,8 +312,35 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
websocket
.
JSON
.
Send
(
conn
,
map
[
string
]
string
{
"error"
:
"URL doesn't link to GitHub Gists"
})
continue
}
log
.
Info
(
"Faucet funds requested"
,
"addr"
,
conn
.
RemoteAddr
(),
"gist"
,
msg
.
URL
)
log
.
Info
(
"Faucet funds requested"
,
"gist"
,
msg
.
URL
)
// If captcha verifications are enabled, make sure we're not dealing with a robot
if
*
captchaToken
!=
""
{
form
:=
url
.
Values
{}
form
.
Add
(
"secret"
,
*
captchaSecret
)
form
.
Add
(
"response"
,
msg
.
Captcha
)
res
,
err
:=
http
.
PostForm
(
"https://www.google.com/recaptcha/api/siteverify"
,
form
)
if
err
!=
nil
{
websocket
.
JSON
.
Send
(
conn
,
map
[
string
]
string
{
"error"
:
err
.
Error
()})
continue
}
var
result
struct
{
Success
bool
`json:"success"`
Errors
json
.
RawMessage
`json:"error-codes"`
}
err
=
json
.
NewDecoder
(
res
.
Body
)
.
Decode
(
&
result
)
res
.
Body
.
Close
()
if
err
!=
nil
{
websocket
.
JSON
.
Send
(
conn
,
map
[
string
]
string
{
"error"
:
err
.
Error
()})
continue
}
if
!
result
.
Success
{
log
.
Warn
(
"Captcha verification failed"
,
"err"
,
string
(
result
.
Errors
))
websocket
.
JSON
.
Send
(
conn
,
map
[
string
]
string
{
"error"
:
"Beep-boop, you're a robot!"
})
continue
}
}
// Retrieve the gist from the GitHub Gist APIs
parts
:=
strings
.
Split
(
msg
.
URL
,
"/"
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
"https://api.github.com/gists/"
+
parts
[
len
(
parts
)
-
1
],
nil
)
...
...
@@ -334,7 +367,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
continue
}
if
gist
.
Owner
.
Login
==
""
{
websocket
.
JSON
.
Send
(
conn
,
map
[
string
]
string
{
"error"
:
"
Nice try ;)
"
})
websocket
.
JSON
.
Send
(
conn
,
map
[
string
]
string
{
"error"
:
"
Anonymous Gists not allowed
"
})
continue
}
// Iterate over all the files and look for Ethereum addresses
...
...
@@ -349,7 +382,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
continue
}
// Validate the user's existence since the API is unhelpful here
if
res
,
err
=
http
.
Head
(
"https://github.com/
%s"
,
gist
.
Owner
.
Login
);
err
!=
nil
{
if
res
,
err
=
http
.
Head
(
"https://github.com/
"
+
gist
.
Owner
.
Login
);
err
!=
nil
{
websocket
.
JSON
.
Send
(
conn
,
map
[
string
]
string
{
"error"
:
err
.
Error
()})
continue
}
...
...
cmd/faucet/faucet.html
View file @
03dffe3e
...
...
@@ -51,9 +51,10 @@
<div
class=
"input-group"
>
<input
id=
"gist"
type=
"text"
class=
"form-control"
placeholder=
"GitHub Gist URL containing your Ethereum address..."
>
<span
class=
"input-group-btn"
>
<button
class=
"btn btn-default"
type=
"button"
onclick=
"
submit()
"
>
Give me Ether!
</button>
<button
class=
"btn btn-default"
type=
"button"
onclick=
"
{{if .Recaptcha}}grecaptcha.execute(){{else}}submit(){{end}}
"
>
Give me Ether!
</button>
</span>
</div>
</div>
{{if .Recaptcha}}
<div
class=
"g-recaptcha"
data-sitekey=
"{{.Recaptcha}}"
data-callback=
"submit"
data-size=
"invisible"
></div>
{{end}}
</div>
</div>
<div
class=
"row"
style=
"margin-top: 32px;"
>
...
...
@@ -89,8 +90,9 @@
var
server
;
// Define the function that submits a gist url to the server
var
submit
=
function
()
{
server
.
send
(
JSON
.
stringify
({
url
:
$
(
"#gist"
)[
0
].
value
}));
var
submit
=
function
({{
if
.
Recaptcha
}}
captcha
{{
end
}})
{
server
.
send
(
JSON
.
stringify
({
url
:
$
(
"#gist"
)[
0
].
value
{{
if
.
Recaptcha
}},
captcha
:
captcha
{{
end
}}}));{{
if
.
Recaptcha
}}
grecaptcha
.
reset
();{{
end
}}
};
// Define a method to reconnect upon server loss
var
reconnect
=
function
()
{
...
...
@@ -138,6 +140,7 @@
}
// Establish a websocket connection to the API server
reconnect
();
</script>
</script>
{{if .Recaptcha}}
<script
src=
"https://www.google.com/recaptcha/api.js"
async
defer
></script>
{{end}}
</body>
</html>
cmd/faucet/website.go
View file @
03dffe3e
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment