Compare commits

...

4 Commits

8 changed files with 26 additions and 26 deletions

View File

@ -6,7 +6,7 @@ SYSDDIR_=${shell pkg-config systemd --variable=systemdsystemunitdir}
SYSDDIR=${SYSDDIR_:/%=%}
DESTDIR=/
LDFLAGS=-ldflags "-s -w -X main.version=2.0.1" -tags osusergo,netgo
LDFLAGS=-ldflags "-s -w -X main.version=2.0.2" -tags osusergo,netgo
all: ${TARGET}

View File

@ -1,4 +1,4 @@
justcaptcha ver. 2.0.1
justcaptcha ver. 2.0.2
======================
A simple CAPTCHA service implementation.

View File

@ -1,6 +1,6 @@
# Maintainer: Alexander "Arav" Andreev <me@arav.su>
pkgname=justcaptcha
pkgver=2.0.1
pkgver=2.0.2
pkgrel=1
pkgdesc="Just a CAPTCHA service"
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
@ -15,7 +15,7 @@ replaces=()
backup=()
options=()
install=
source=('https://git.arav.su/Arav/justcaptcha/archive/2.0.1.tar.gz')
source=('https://git.arav.su/Arav/justcaptcha/archive/2.0.2.tar.gz')
noextract=()
md5sums=('SKIP')

2
go.mod
View File

@ -9,5 +9,5 @@ require (
require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
golang.org/x/image v0.3.0 // indirect
golang.org/x/image v0.5.0 // indirect
)

6
go.sum
View File

@ -7,8 +7,8 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.3.0 h1:HTDXbdK9bjfSWkPzDJIw89W8CAtfFGduujWs33NLLsg=
golang.org/x/image v0.3.0/go.mod h1:fXd9211C/0VTlYuAcOhW8dY/RtEJqODXOWBDpmYBf+A=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@ -25,7 +25,7 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

View File

@ -30,8 +30,8 @@ func NewID(additionalData string, answer Answer) ID {
return ID(base64.RawURLEncoding.EncodeToString(idHash.Sum(nil)))
}
// CaptchaDB interface with all necessary methods.
type CaptchaDB interface {
// DB interface with all necessary methods.
type DB interface {
New(data string, captcha Captcha) (Captcha, ID)
GetExpiry() time.Duration
SetExpiry(expiry time.Duration)

View File

@ -8,8 +8,8 @@ import (
"git.arav.su/Arav/justcaptcha/pkg/captcha"
)
// InMemoryCaptchaDB implementation that lives in a memory (map).
type InMemoryCaptchaDB struct {
// InMemoryDB implementation that lives in a memory (map).
type InMemoryDB struct {
sync.Mutex
db map[captcha.ID]captcha.Captcha
@ -17,11 +17,11 @@ type InMemoryCaptchaDB struct {
expiryScanInterval time.Duration
}
// NewInMemoryCaptchaDB returns an initialised instance of an InMemoryCaptchaDB.
// NewInMemoryDB returns an initialised instance of an InMemoryDB.
// An expiry is a scan interval for expired CAPTCHAs (if passed a longer one,
// resets to a default (captcha.DefaultExpiredScanInterval)).
func NewInMemoryCaptchaDB(expiry time.Duration) *InMemoryCaptchaDB {
db := &InMemoryCaptchaDB{
func NewInMemoryDB(expiry time.Duration) *InMemoryDB {
db := &InMemoryDB{
db: make(map[captcha.ID]captcha.Captcha),
expiry: expiry}
@ -39,7 +39,7 @@ func NewInMemoryCaptchaDB(expiry time.Duration) *InMemoryCaptchaDB {
// New accepts a CAPTCHA instance, generates an ID and store it in a database.
// A data string is an additional random data used to generate an ID,
// e.g. an IP-address.
func (imcdb *InMemoryCaptchaDB) New(data string, cptcha captcha.Captcha) (captcha.Captcha, captcha.ID) {
func (imcdb *InMemoryDB) New(data string, cptcha captcha.Captcha) (captcha.Captcha, captcha.ID) {
id := captcha.NewID(data, cptcha.Answer())
imcdb.Lock()
@ -50,13 +50,13 @@ func (imcdb *InMemoryCaptchaDB) New(data string, cptcha captcha.Captcha) (captch
}
// GetExpiry returns an expiry for a CAPTCHA.
func (imcdb *InMemoryCaptchaDB) GetExpiry() time.Duration {
func (imcdb *InMemoryDB) GetExpiry() time.Duration {
return imcdb.expiry
}
// SetExpiry changes an expiry for a CAPTCHA and a scan interval. Scan interval
// cannot be longer than a default, so if it is, then resets to a default.
func (imcdb *InMemoryCaptchaDB) SetExpiry(expiry time.Duration) {
func (imcdb *InMemoryDB) SetExpiry(expiry time.Duration) {
imcdb.expiry = expiry
if expiry < captcha.DefaultExpiredScanInterval {
imcdb.expiryScanInterval = expiry
@ -67,7 +67,7 @@ func (imcdb *InMemoryCaptchaDB) SetExpiry(expiry time.Duration) {
// Image returns a freshly generated image for a CAPTCHA with style if
// applicable.
func (imcdb *InMemoryCaptchaDB) Image(id captcha.ID, style string) *image.Image {
func (imcdb *InMemoryDB) Image(id captcha.ID, style string) *image.Image {
imcdb.Lock()
defer imcdb.Unlock()
if c, ok := imcdb.db[id]; ok {
@ -78,7 +78,7 @@ func (imcdb *InMemoryCaptchaDB) Image(id captcha.ID, style string) *image.Image
// Solve compares given answer with a stored one and if failed
// deletes a CAPTCHA from database.
func (imcdb *InMemoryCaptchaDB) Solve(id captcha.ID, answer captcha.Answer) bool {
func (imcdb *InMemoryDB) Solve(id captcha.ID, answer captcha.Answer) bool {
imcdb.Lock()
defer imcdb.Unlock()
if c, ok := imcdb.db[id]; ok {
@ -93,7 +93,7 @@ func (imcdb *InMemoryCaptchaDB) Solve(id captcha.ID, answer captcha.Answer) bool
// IsSolved checks if CAPTCHA was solved and removes it
// from a database.
func (imcdb *InMemoryCaptchaDB) IsSolved(id captcha.ID) bool {
func (imcdb *InMemoryDB) IsSolved(id captcha.ID) bool {
imcdb.Lock()
defer imcdb.Unlock()
if c, ok := imcdb.db[id]; ok {
@ -104,14 +104,14 @@ func (imcdb *InMemoryCaptchaDB) IsSolved(id captcha.ID) bool {
}
// Remove a CAPTCHA from a database.
func (imcdb *InMemoryCaptchaDB) Remove(id captcha.ID) {
func (imcdb *InMemoryDB) Remove(id captcha.ID) {
imcdb.Lock()
defer imcdb.Unlock()
delete(imcdb.db, id)
}
// cleanExpired removes expired CAPTCHAs in a loop.
func (imcdb *InMemoryCaptchaDB) cleanExpired() {
func (imcdb *InMemoryDB) cleanExpired() {
for {
sleepFor := imcdb.expiryScanInterval - (time.Duration(time.Now().Second()) % imcdb.expiryScanInterval)
time.Sleep(sleepFor)
@ -126,9 +126,9 @@ func (imcdb *InMemoryCaptchaDB) cleanExpired() {
}
}
// An instance of InMemoryCaptchaDB
// An instance of InMemoryDB
var imcdb = NewInMemoryCaptchaDB(captcha.DefaultExpiredScanInterval)
var imcdb = NewInMemoryDB(captcha.DefaultExpiredScanInterval)
func GetExpiry() time.Duration {
return imcdb.GetExpiry()

View File

@ -40,7 +40,7 @@ func TestInMemDBDefaultInstance(t *testing.T) {
}
func TestInMemDBNewInstance(t *testing.T) {
db := inmemdb.NewInMemoryCaptchaDB(expiry)
db := inmemdb.NewInMemoryDB(expiry)
if db.GetExpiry() != expiry {
t.Errorf("expected expiry %v, but got %v", expiry, db.GetExpiry())