Skip to content

Commit bf31c37

Browse files
committed
Expose recaptcha url via config
1 parent 29955e4 commit bf31c37

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

config.conf.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ secret = ""
1515
send_quit_on_client_close = "Client closed"
1616

1717
[verify]
18+
recaptcha_url = "https://www.google.com/recaptcha/api/siteverify"
1819
recaptcha_secret = ""
1920
recaptcha_key = ""
2021

pkg/recaptcha/recaptcha.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
// R type represents an object of Recaptcha and has public property Secret,
1414
// which is secret obtained from google recaptcha tool admin interface
1515
type R struct {
16+
URL string
1617
Secret string
1718
lastError []string
1819
}
@@ -23,15 +24,12 @@ type googleResponse struct {
2324
ErrorCodes []string `json:"error-codes"`
2425
}
2526

26-
// url to post submitted re-captcha response to
27-
var postURL = "https://www.google.com/recaptcha/api/siteverify"
28-
2927
// VerifyResponse is a method similar to `Verify`; but doesn't parse the form for you. Useful if
3028
// you're receiving the data as a JSON object from a javascript app or similar.
3129
func (r *R) VerifyResponse(response string) bool {
3230
r.lastError = make([]string, 1)
3331
client := &http.Client{Timeout: 20 * time.Second}
34-
resp, err := client.PostForm(postURL,
32+
resp, err := client.PostForm(r.URL,
3533
url.Values{"secret": {r.Secret}, "response": {response}})
3634
if err != nil {
3735
r.lastError = append(r.lastError, err.Error())

pkg/webircgateway/client_command_handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func (c *Client) ProcessLineFromClient(line string) (string, error) {
189189
verified := false
190190
if len(message.Params) >= 1 {
191191
captcha := recaptcha.R{
192+
URL: c.Gateway.Config.ReCaptchaURL,
192193
Secret: c.Gateway.Config.ReCaptchaSecret,
193194
}
194195

pkg/webircgateway/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type Config struct {
7373
Identd bool
7474
RequiresVerification bool
7575
SendQuitOnClientClose string
76+
ReCaptchaURL string
7677
ReCaptchaSecret string
7778
ReCaptchaKey string
7879
Secret string
@@ -142,6 +143,7 @@ func (c *Config) Load() error {
142143
c.GatewayWhitelist = []glob.Glob{}
143144
c.ReverseProxies = []net.IPNet{}
144145
c.Webroot = ""
146+
c.ReCaptchaURL = ""
145147
c.ReCaptchaSecret = ""
146148
c.ReCaptchaKey = ""
147149
c.RequiresVerification = false
@@ -180,6 +182,7 @@ func (c *Config) Load() error {
180182
c.RequiresVerification = section.Key("required").MustBool(false)
181183
c.ReCaptchaSecret = captchaSecret
182184
}
185+
c.ReCaptchaURL = section.Key("recaptcha_url").MustString("https://www.google.com/recaptcha/api/siteverify")
183186
}
184187

185188
if section.Name() == "dnsbl" {

0 commit comments

Comments
 (0)