This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglobals.go
139 lines (115 loc) · 3.88 KB
/
globals.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"html/template"
"log"
"net/http"
"regexp"
"sync"
"time"
)
const (
// defines case-insensitive list of captcha characters.
defaultCharsList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
// authentication cookie name
authenticationName = "t6f6e7r83mv6g8mzr4m739k6p"
// number of seconds for authentication cookie expiration
authenticationExpirationSeconds = 86400
// captcha form input names
challengeKey = "captcha_challenge"
responseKey = "captcha_response"
imageID = "captcha_image"
// number of seconds for challenge hash expiration
challengeExpirationSeconds = 60
// number of nanoseconds in second
nanoSecondsInSecond = 1000000000
// HTTP code for non-authorized request, used in nginx redirects
unAuthorizedAccess = http.StatusUnauthorized
// regex for UUIDv4 validation
regExpUUIDv4 = `^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[8,9,a,b][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$`
)
const (
messageOnlyGetMethod = "only GET method"
messageOnlyGetOrPostMethod = "only GET or POST method"
messageOnlyPostMethod = "only POST method"
messageFailedEntropy = "entropy failure"
messageFailedHTMLRender = "HTML render failure"
messageFailedHTTPResponse = "HTTP response failure"
messageExpiredChallenge = "expired challenge"
messageInvalidChallenge = "invalid challenge"
messageInvalidResponse = "invalid response"
messageExpiredRecord = "expired record"
messageUnknownChallenge = "unknown challenge"
messageEmptyAuthentication = "empty authentication"
messageExpiredAuthentication = "authentication expired"
messageInvalidAuthenticationDomain = "invalid authentication domain"
messageInvalidUserAgent = "invalid authentication user-agent"
messageUnknownAuthentication = "unknown authentication"
messageValidAuthentication = "valid authentication"
messageAllowOptionsRequest = "allow OPTIONS method"
messageAllowWebFont = "allow web font"
)
type captchaDBRecord struct {
// Domain defines valid captcha domain
Domain string
// UserAgent stores UA that originated from HTTP request
UserAgent string
// Expires defines captcha TTL
Expires time.Time
// Address stores address that originated from HTTP request
Address string
}
var (
// captcha HTML template
captchaHTMLTemplate *template.Template
// captcha Lite HTML template
captchaLiteTemplate *template.Template
// in memory key:value database
db sync.Map
// in memory captcha database
captchaDB Data
// compiled RegExp for UUIDv4
reUUID *regexp.Regexp
// IP:PORT or unix socket path
cmdAddress string
// log date/time
cmdLogDateTime bool
// enable debug logging
cmdDebug bool
// generates CAPTCHA to a file DB
cmdGenerate uint
// path to CAPTCHA DB file
cmdDBPath string
// empty favicon.ico
favicon = []byte{
000, 000, 001, 000, 001, 000, 016, 016,
002, 000, 001, 000, 001, 000, 176, 000,
000, 000, 022, 000, 000, 000, 040, 000,
000, 000, 016, 000, 000, 000, 032, 000,
000, 000, 001, 000, 001, 000, 000, 000,
000, 000, 128, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 255, 255, 255, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 255, 255,
000, 000, 255, 255, 000, 000, 255, 255,
000, 000, 255, 255, 000, 000, 255, 255,
000, 000, 255, 255, 000, 000, 255, 255,
000, 000, 255, 255, 000, 000, 255, 255,
000, 000, 255, 255, 000, 000, 255, 255,
000, 000, 255, 255, 000, 000, 255, 255,
000, 000, 255, 255, 000, 000, 255, 255,
000, 000, 255, 255, 000, 000,
}
// Logging levels
Info *log.Logger
Error *log.Logger
Debug *log.Logger
Bot *log.Logger
)