rucaptcha_number 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/README.md +1 -0
- data/app/controllers/ru_captcha_number/captcha_controller.rb +12 -0
- data/config/locales/rucaptcha_number.en.yml +3 -0
- data/config/locales/rucaptcha_number.pt-BR.yml +3 -0
- data/config/locales/rucaptcha_number.zh-CN.yml +3 -0
- data/config/locales/rucaptcha_number.zh-TW.yml +3 -0
- data/config/routes.rb +3 -0
- data/ext/rucaptcha_number/colors.h +118 -0
- data/ext/rucaptcha_number/extconf.rb +2 -0
- data/ext/rucaptcha_number/font.h +11 -0
- data/ext/rucaptcha_number/rucaptcha_number.c +240 -0
- data/lib/rucaptcha_number/cache.rb +11 -0
- data/lib/rucaptcha_number/configuration.rb +17 -0
- data/lib/rucaptcha_number/controller_helpers.rb +91 -0
- data/lib/rucaptcha_number/engine.rb +15 -0
- data/lib/rucaptcha_number/errors/configuration.rb +5 -0
- data/lib/rucaptcha_number/version.rb +3 -0
- data/lib/rucaptcha_number/view_helpers.rb +19 -0
- data/lib/rucaptcha_number.rb +79 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 93292a4eac153a644e6791c826ffa83e43abb14cbe20e43398c47376ac879f7a
|
4
|
+
data.tar.gz: 307db233b9be982d4e8e299ef3fc4e5a974fe811efb98317f72c4a8fa7135a4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b33a9ad3b68f399b21604fc8bc157234363ae0ac8581772d8f75f37aff4bea052ab7d5d98f6ed34ee4c1c952a37de497139746fece34d250b5bdfedd864e973
|
7
|
+
data.tar.gz: abd98f35984405caa879bd2a2d940509fed8a25afde6a1c683659de2726ff79124ee9e1f0684092b77ac0097d9b32f85398221ddfc7f7b302e254f910c892df6
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Copy of Rucaptcha,For my website
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RuCaptchaNumber
|
2
|
+
class CaptchaController < ActionController::Base
|
3
|
+
def index
|
4
|
+
return head :ok if request.head?
|
5
|
+
headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
|
6
|
+
headers['Pragma'] = 'no-cache'
|
7
|
+
data = generate_rucaptcha
|
8
|
+
opts = { disposition: 'inline', type: 'image/gif',filename: data[:filename] }
|
9
|
+
send_data data[:image], opts
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
// Colors from
|
2
|
+
// https://material.io/guidelines/style/color.html#color-ui-color-palette
|
3
|
+
// Color covert HEX RGB to \x??\x??\x??
|
4
|
+
static char *colors[] = {
|
5
|
+
// Black 500 #000000
|
6
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
7
|
+
"\x00\x00\x00"
|
8
|
+
"\x00\x00\x00"
|
9
|
+
"\x00\x00\x00"
|
10
|
+
"\x00\x00\x00"
|
11
|
+
"\x00\x00\x00"
|
12
|
+
"\x00\x00\x00"
|
13
|
+
"\x00\x00\x00"
|
14
|
+
"\x00\x00\x00"
|
15
|
+
"\x00\x00\x00"
|
16
|
+
"\x00\x00\x00"
|
17
|
+
"\x00\x00\x00"
|
18
|
+
"\x00\x00\x00"
|
19
|
+
"\x00\x00\x00"
|
20
|
+
"\x00\x00\x00"
|
21
|
+
"\x00\x00\x00"
|
22
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
23
|
+
|
24
|
+
// Red A700 #D50000
|
25
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
26
|
+
"\xD5\x00\x00"
|
27
|
+
"\xD5\x00\x00"
|
28
|
+
"\xD5\x00\x00"
|
29
|
+
"\xD5\x00\x00"
|
30
|
+
"\xD5\x00\x00"
|
31
|
+
"\xD5\x00\x00"
|
32
|
+
"\xD5\x00\x00"
|
33
|
+
"\xD5\x00\x00"
|
34
|
+
"\xD5\x00\x00"
|
35
|
+
"\xD5\x00\x00"
|
36
|
+
"\xD5\x00\x00"
|
37
|
+
"\xD5\x00\x00"
|
38
|
+
"\xD5\x00\x00"
|
39
|
+
"\xD5\x00\x00"
|
40
|
+
"\xD5\x00\x00"
|
41
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
42
|
+
|
43
|
+
// Deep Orange A700 #DD2C00
|
44
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
45
|
+
"\xDD\x2C\x00"
|
46
|
+
"\xDD\x2C\x00"
|
47
|
+
"\xDD\x2C\x00"
|
48
|
+
"\xDD\x2C\x00"
|
49
|
+
"\xDD\x2C\x00"
|
50
|
+
"\xDD\x2C\x00"
|
51
|
+
"\xDD\x2C\x00"
|
52
|
+
"\xDD\x2C\x00"
|
53
|
+
"\xDD\x2C\x00"
|
54
|
+
"\xDD\x2C\x00"
|
55
|
+
"\xDD\x2C\x00"
|
56
|
+
"\xDD\x2C\x00"
|
57
|
+
"\xDD\x2C\x00"
|
58
|
+
"\xDD\x2C\x00"
|
59
|
+
"\xDD\x2C\x00"
|
60
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
61
|
+
|
62
|
+
// Blue A700 #2962FF
|
63
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
64
|
+
"\x29\x62\xFF"
|
65
|
+
"\x29\x62\xFF"
|
66
|
+
"\x29\x62\xFF"
|
67
|
+
"\x29\x62\xFF"
|
68
|
+
"\x29\x62\xFF"
|
69
|
+
"\x29\x62\xFF"
|
70
|
+
"\x29\x62\xFF"
|
71
|
+
"\x29\x62\xFF"
|
72
|
+
"\x29\x62\xFF"
|
73
|
+
"\x29\x62\xFF"
|
74
|
+
"\x29\x62\xFF"
|
75
|
+
"\x29\x62\xFF"
|
76
|
+
"\x29\x62\xFF"
|
77
|
+
"\x29\x62\xFF"
|
78
|
+
"\x29\x62\xFF"
|
79
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
80
|
+
|
81
|
+
// Green A700 #00C853
|
82
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
83
|
+
"\x00\xC8\x53"
|
84
|
+
"\x00\xC8\x53"
|
85
|
+
"\x00\xC8\x53"
|
86
|
+
"\x00\xC8\x53"
|
87
|
+
"\x00\xC8\x53"
|
88
|
+
"\x00\xC8\x53"
|
89
|
+
"\x00\xC8\x53"
|
90
|
+
"\x00\xC8\x53"
|
91
|
+
"\x00\xC8\x53"
|
92
|
+
"\x00\xC8\x53"
|
93
|
+
"\x00\xC8\x53"
|
94
|
+
"\x00\xC8\x53"
|
95
|
+
"\x00\xC8\x53"
|
96
|
+
"\x00\xC8\x53"
|
97
|
+
"\x00\xC8\x53"
|
98
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
|
99
|
+
|
100
|
+
// Yellow A700 #FFD600
|
101
|
+
"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
|
102
|
+
"\xFF\xD6\x00"
|
103
|
+
"\xFF\xD6\x00"
|
104
|
+
"\xFF\xD6\x00"
|
105
|
+
"\xFF\xD6\x00"
|
106
|
+
"\xFF\xD6\x00"
|
107
|
+
"\xFF\xD6\x00"
|
108
|
+
"\xFF\xD6\x00"
|
109
|
+
"\xFF\xD6\x00"
|
110
|
+
"\xFF\xD6\x00"
|
111
|
+
"\xFF\xD6\x00"
|
112
|
+
"\xFF\xD6\x00"
|
113
|
+
"\xFF\xD6\x00"
|
114
|
+
"\xFF\xD6\x00"
|
115
|
+
"\xFF\xD6\x00"
|
116
|
+
"\xFF\xD6\x00"
|
117
|
+
"\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04"
|
118
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
static int8_t lt1[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-4,14,7,0,0,0,0,-100,-2,14,7,0,0,0,0,0,0,-100,-1,9,1,0,0,0,0,0,0,0,-100,3,0,0,0,0,0,0,0,0,0,-100,6,0,0,0,5,9,0,0,0,0,-100,10,0,3,13,-1,11,0,0,0,0,-100,-1,11,-3,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-5,11,0,0,0,0,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
2
|
+
static int8_t lt2[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-4,12,6,3,0,0,0,2,5,11,-100,-2,11,3,0,0,0,0,0,0,0,0,0,3,14,-100,-1,8,0,0,0,0,0,0,0,0,0,0,0,0,1,14,-100,-1,9,0,0,0,0,4,7,7,4,0,0,0,0,0,3,-100,-2,0,0,7,14,-4,13,2,0,0,0,0,11,-100,-2,9,13,-7,13,0,0,0,0,6,-100,-12,5,0,0,0,3,-100,-12,9,0,0,0,0,-100,-12,11,0,0,0,0,-100,-12,11,0,0,0,0,-100,-12,7,0,0,0,3,-100,-12,4,0,0,0,7,-100,-11,13,0,0,0,0,12,-100,-11,5,0,0,0,2,-100,-10,12,0,0,0,0,10,-100,-10,3,0,0,0,3,-100,-9,7,0,0,0,0,12,-100,-8,10,0,0,0,0,8,-100,-7,12,0,0,0,0,4,-100,-6,14,2,0,0,0,2,14,-100,-5,14,2,0,0,0,0,14,-100,-5,3,0,0,0,0,12,-100,-4,5,0,0,0,0,12,-100,-3,5,0,0,0,0,12,-100,-2,5,0,0,0,0,9,-100,-1,8,0,0,0,0,2,7,7,7,7,7,7,7,7,7,7,11,-100,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
3
|
+
static int8_t lt3[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-3,13,8,5,3,0,0,1,3,8,14,-100,-1,11,4,0,0,0,0,0,0,0,0,0,0,8,-100,-1,8,0,0,0,0,0,0,0,0,0,0,0,0,8,-100,-1,13,0,0,0,5,10,11,9,3,0,0,0,0,0,13,-100,-2,3,7,14,-5,8,0,0,0,0,6,-100,-2,14,-8,3,0,0,0,3,-100,-11,8,0,0,0,0,-100,-11,11,0,0,0,0,-100,-11,10,0,0,0,2,-100,-11,6,0,0,0,5,-100,-10,14,0,0,0,0,11,-100,-9,14,2,0,0,0,3,-100,-7,13,8,0,0,0,0,2,14,-100,-4,7,0,0,0,0,0,0,0,3,14,-100,-4,7,0,0,0,0,0,0,3,12,-100,-4,7,0,0,0,0,0,0,0,0,3,12,-100,-7,14,11,5,0,0,0,0,0,12,-100,-10,13,2,0,0,0,1,14,-100,-11,14,0,0,0,0,8,-100,-12,6,0,0,0,3,-100,-12,11,0,0,0,0,-100,-12,11,0,0,0,0,-100,-12,6,0,0,0,2,-100,-11,14,0,0,0,0,5,-100,-1,10,10,-7,13,2,0,0,0,0,13,-100,-1,2,0,1,5,8,11,11,9,5,0,0,0,0,0,6,-100,13,0,0,0,0,0,0,0,0,0,0,0,0,0,5,-100,11,1,0,0,0,0,0,0,0,0,0,0,1,10,-100,-2,12,7,4,3,0,0,0,3,6,10,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
4
|
+
static int8_t lt4[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-10,14,0,0,0,0,0,-100,-10,5,0,0,0,0,0,-100,-9,11,0,0,0,0,0,0,-100,-9,2,0,0,0,0,0,0,-100,-8,8,0,0,1,3,0,0,0,-100,-7,14,0,0,0,9,1,0,0,0,-100,-7,5,0,0,1,-1,0,0,0,0,-100,-6,11,0,0,0,9,-1,0,0,0,0,-100,-6,2,0,0,1,-2,0,0,0,0,-100,-5,8,0,0,0,10,-2,0,0,0,0,-100,-4,14,0,0,0,3,-3,0,0,0,0,-100,-4,5,0,0,0,13,-3,0,0,0,0,-100,-3,11,0,0,0,7,-4,0,0,0,0,-100,-3,2,0,0,1,14,-4,0,0,0,0,-100,-2,8,0,0,0,10,-5,0,0,0,0,-100,-1,14,0,0,0,4,-6,0,0,0,0,-100,-1,5,0,0,0,13,-6,0,0,0,0,-100,11,0,0,0,4,11,11,11,11,11,11,11,0,0,0,0,11,11,11,13,-100,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,-12,0,0,0,0,-100,-12,0,0,0,0,-100,-12,0,0,0,0,-100,-12,0,0,0,0,-100,-12,0,0,0,0,-100,-12,0,0,0,0,-100,-12,0,0,0,0,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
5
|
+
static int8_t lt5[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-3,10,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,-3,7,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,-3,6,0,0,0,0,0,0,0,0,0,0,0,0,7,-100,-3,3,0,0,1,7,7,7,7,7,7,7,7,7,11,-100,-3,1,0,0,5,-100,-3,0,0,0,7,-100,-2,13,0,0,0,10,-100,-2,11,0,0,0,11,-100,-2,9,0,0,0,-100,-2,7,0,0,0,-100,-2,4,0,0,0,0,0,0,2,5,9,-100,-2,3,0,0,0,0,0,0,0,0,0,1,10,-100,-2,0,0,0,0,0,0,0,0,0,0,0,0,6,-100,-2,10,11,11,11,11,9,6,0,0,0,0,0,0,9,-100,-10,7,0,0,0,0,0,14,-100,-11,8,0,0,0,0,8,-100,-12,2,0,0,0,3,-100,-12,8,0,0,0,0,-100,-12,11,0,0,0,0,-100,-12,11,0,0,0,0,-100,-12,8,0,0,0,3,-100,-12,2,0,0,0,6,-100,-11,8,0,0,0,0,13,-100,-1,8,13,-7,8,0,0,0,0,4,-100,-1,0,0,2,7,10,11,11,7,1,0,0,0,0,2,14,-100,10,0,0,0,0,0,0,0,0,0,0,0,0,2,13,-100,10,0,0,0,0,0,0,0,0,0,0,0,6,14,-100,-1,14,9,6,3,1,0,0,1,4,8,14,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
6
|
+
static int8_t lt6[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-10,11,7,3,2,0,7,-100,-7,14,6,0,0,0,0,0,0,7,-100,-6,8,0,0,0,0,0,0,0,0,7,-100,-4,14,4,0,0,0,0,0,1,6,8,11,13,-100,-4,3,0,0,0,0,3,11,-100,-3,6,0,0,0,0,9,-100,-2,11,0,0,0,0,11,-100,-2,3,0,0,0,8,-100,-1,10,0,0,0,3,-100,-1,4,0,0,0,10,-100,14,0,0,0,0,-1,14,9,4,0,0,1,5,11,-100,10,0,0,0,5,11,1,0,0,0,0,0,0,0,3,14,-100,6,0,0,0,3,0,0,0,0,0,0,0,0,0,0,2,14,-100,3,0,0,0,0,0,2,10,14,-1,10,3,0,0,0,0,5,-100,2,0,0,0,0,5,-6,5,0,0,0,0,13,-100,0,0,0,0,1,-7,14,0,0,0,0,7,-100,0,0,0,0,8,-8,6,0,0,0,3,-100,0,0,0,0,11,-8,10,0,0,0,0,-100,2,0,0,0,11,-8,11,0,0,0,0,-100,3,0,0,0,8,-8,11,0,0,0,0,-100,7,0,0,0,5,-8,8,0,0,0,3,-100,12,0,0,0,0,14,-7,4,0,0,0,7,-100,-1,2,0,0,0,7,-6,13,0,0,0,0,13,-100,-1,9,0,0,0,0,9,-4,14,2,0,0,0,3,-100,-2,4,0,0,0,0,5,10,11,8,1,0,0,0,0,13,-100,-2,14,2,0,0,0,0,0,0,0,0,0,0,0,12,-100,-3,14,6,0,0,0,0,0,0,0,0,1,12,-100,-5,13,6,3,0,0,1,4,9,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
7
|
+
static int8_t lt7[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,-100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,-100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,-100,7,7,7,7,7,7,7,7,7,7,7,7,2,0,0,0,9,-100,-11,14,0,0,0,0,14,-100,-11,7,0,0,0,6,-100,-11,1,0,0,0,13,-100,-10,9,0,0,0,4,-100,-10,2,0,0,0,11,-100,-9,11,0,0,0,2,-100,-9,3,0,0,0,9,-100,-8,13,0,0,0,0,-100,-8,5,0,0,0,7,-100,-7,14,0,0,0,0,13,-100,-7,7,0,0,0,5,-100,-6,14,0,0,0,0,12,-100,-6,9,0,0,0,3,-100,-6,1,0,0,0,9,-100,-5,10,0,0,0,1,-100,-5,3,0,0,0,7,-100,-4,11,0,0,0,0,14,-100,-4,5,0,0,0,5,-100,-3,13,0,0,0,0,13,-100,-3,6,0,0,0,3,-100,-2,14,0,0,0,0,10,-100,-2,7,0,0,0,1,-100,-2,1,0,0,0,8,-100,-1,9,0,0,0,0,14,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
8
|
+
static int8_t lt8[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-4,11,6,2,0,0,0,4,8,14,-100,-2,13,3,0,0,0,0,0,0,0,0,0,10,-100,-1,12,0,0,0,0,0,0,0,0,0,0,0,0,9,-100,-1,1,0,0,0,2,10,-2,12,3,0,0,0,0,13,-100,9,0,0,0,2,14,-5,3,0,0,0,6,-100,3,0,0,0,10,-6,10,0,0,0,2,-100,0,0,0,0,-8,0,0,0,0,-100,0,0,0,0,-8,0,0,0,0,-100,1,0,0,0,12,-6,13,0,0,0,3,-100,5,0,0,0,5,-6,7,0,0,0,8,-100,11,0,0,0,0,9,-4,12,0,0,0,0,14,-100,-1,6,0,0,0,0,4,13,-1,10,0,0,0,0,10,-100,-2,5,0,0,0,0,0,1,0,0,0,0,9,-100,-3,8,0,0,0,0,0,0,0,0,11,-100,-3,5,0,0,0,0,0,0,0,0,0,7,-100,-2,5,0,0,0,0,5,7,0,0,0,0,0,5,-100,-1,8,0,0,0,0,11,-2,14,5,0,0,0,0,6,-100,14,0,0,0,0,10,-5,5,0,0,0,0,12,-100,8,0,0,0,3,-7,1,0,0,0,5,-100,3,0,0,0,8,-7,7,0,0,0,2,-100,0,0,0,0,11,-7,11,0,0,0,0,-100,0,0,0,0,11,-7,11,0,0,0,0,-100,1,0,0,0,8,-7,9,0,0,0,3,-100,5,0,0,0,2,-7,3,0,0,0,6,-100,10,0,0,0,0,8,-5,9,0,0,0,0,13,-100,-1,3,0,0,0,0,7,13,-1,13,7,0,0,0,0,6,-100,-1,14,2,0,0,0,0,0,0,0,0,0,0,0,5,-100,-2,14,4,0,0,0,0,0,0,0,0,0,7,-100,-4,12,6,3,0,0,1,3,8,14,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
9
|
+
static int8_t lt9[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-5,9,4,0,0,0,3,9,14,-100,-3,12,2,0,0,0,0,0,0,0,1,12,-100,-2,12,0,0,0,0,0,0,0,0,0,0,0,12,-100,-1,14,1,0,0,0,2,10,11,9,1,0,0,0,2,-100,-1,7,0,0,0,2,14,-3,14,0,0,0,0,9,-100,14,0,0,0,0,11,-5,9,0,0,0,1,-100,9,0,0,0,2,-7,0,0,0,0,12,-100,4,0,0,0,7,-7,4,0,0,0,8,-100,2,0,0,0,10,-7,7,0,0,0,5,-100,0,0,0,0,11,-7,10,0,0,0,3,-100,0,0,0,0,11,-7,11,0,0,0,2,-100,1,0,0,0,9,-7,11,0,0,0,0,-100,3,0,0,0,6,-7,10,0,0,0,0,-100,7,0,0,0,1,-7,4,0,0,0,0,-100,13,0,0,0,0,7,-5,9,0,0,0,0,2,-100,-1,5,0,0,0,0,6,14,-1,13,6,0,0,0,0,0,3,-100,-1,14,2,0,0,0,0,0,0,0,0,0,2,0,0,0,6,-100,-2,14,2,0,0,0,0,0,0,0,6,8,0,0,0,8,-100,-4,9,3,0,0,0,4,11,-1,4,0,0,0,12,-100,-11,14,0,0,0,1,-100,-11,7,0,0,0,7,-100,-10,14,0,0,0,0,14,-100,-10,3,0,0,0,7,-100,-8,14,4,0,0,0,1,14,-100,-7,10,1,0,0,0,0,12,-100,-2,11,9,7,4,0,0,0,0,0,0,12,-100,-2,3,0,0,0,0,0,0,0,2,12,-100,-2,3,0,0,0,0,0,1,7,-100,-2,3,0,3,3,7,11,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
10
|
+
static int8_t lt0[] = {-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-5,11,5,1,0,0,4,9,-100,-4,6,0,0,0,0,0,0,0,3,14,-100,-3,5,0,0,0,0,0,0,0,0,0,2,14,-100,-2,8,0,0,0,0,7,11,7,0,0,0,0,6,-100,-1,14,0,0,0,0,9,-3,12,0,0,0,0,13,-100,-1,8,0,0,0,3,-5,5,0,0,0,5,-100,-1,1,0,0,0,10,-5,12,0,0,0,0,-100,13,0,0,0,0,-7,0,0,0,0,12,-100,9,0,0,0,3,-7,3,0,0,0,8,-100,6,0,0,0,6,-7,7,0,0,0,5,-100,3,0,0,0,7,-7,7,0,0,0,3,-100,3,0,0,0,9,-7,10,0,0,0,3,-100,0,0,0,0,11,-7,11,0,0,0,0,-100,0,0,0,0,11,-7,11,0,0,0,0,-100,0,0,0,0,11,-7,11,0,0,0,0,-100,0,0,0,0,11,-7,11,0,0,0,0,-100,0,0,0,0,11,-7,11,0,0,0,0,-100,3,0,0,0,9,-7,9,0,0,0,3,-100,3,0,0,0,7,-7,7,0,0,0,3,-100,6,0,0,0,6,-7,6,0,0,0,6,-100,8,0,0,0,3,-7,3,0,0,0,9,-100,12,0,0,0,0,-7,0,0,0,0,13,-100,-1,1,0,0,0,10,-5,12,0,0,0,1,-100,-1,7,0,0,0,5,-5,5,0,0,0,7,-100,-1,13,0,0,0,0,11,-3,11,0,0,0,0,13,-100,-2,7,0,0,0,0,7,11,7,0,0,0,0,7,-100,-3,2,0,0,0,0,0,0,0,0,0,3,-100,-3,14,4,0,0,0,0,0,0,0,5,14,-100,-5,10,4,0,0,1,5,11,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-101};
|
11
|
+
static int8_t *lt[]={lt1,lt2,lt3,lt4,lt5,lt6,lt7,lt8,lt9,lt0,lt1,lt2,lt3,lt4,lt5,lt6,lt7,lt8,lt9,lt0,lt1,lt2,lt3,lt4,lt5,lt6,lt7,lt8,lt9,lt0};
|
@@ -0,0 +1,240 @@
|
|
1
|
+
// http://github.com/ITikhonov/captcha
|
2
|
+
const int gifsize;
|
3
|
+
void captcha(unsigned char im[70*200], unsigned char l[8], int length, int i_line, int i_filter);
|
4
|
+
void makegif(unsigned char im[70*200], unsigned char gif[gifsize], int style);
|
5
|
+
|
6
|
+
#include <unistd.h>
|
7
|
+
#include <stdint.h>
|
8
|
+
#include <stdlib.h>
|
9
|
+
#include <fcntl.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <time.h>
|
12
|
+
#include <ruby.h>
|
13
|
+
#include "font.h"
|
14
|
+
#include "colors.h"
|
15
|
+
|
16
|
+
static int8_t *lt[];
|
17
|
+
const int gifsize=17646;
|
18
|
+
|
19
|
+
void makegif(unsigned char im[70*200], unsigned char gif[gifsize], int style) {
|
20
|
+
// tag ; widthxheight ; GCT:0:0:7 ; bgcolor + aspect // GCT
|
21
|
+
// Image Separator // left x top // widthxheight // Flags
|
22
|
+
// LZW code size
|
23
|
+
srand(time(NULL));
|
24
|
+
int color_len = (int) sizeof(colors) / sizeof(colors[0]);
|
25
|
+
int color_idx = rand() % color_len;
|
26
|
+
if (style == 0) {
|
27
|
+
color_idx = 0;
|
28
|
+
}
|
29
|
+
memcpy(gif,colors[color_idx],13+48+10+1);
|
30
|
+
|
31
|
+
int x,y;
|
32
|
+
unsigned char *i=im;
|
33
|
+
unsigned char *p=gif+13+48+10+1;
|
34
|
+
for(y=0;y<70;y++) {
|
35
|
+
*p++=250; // Data length 5*50=250
|
36
|
+
for(x=0;x<50;x++)
|
37
|
+
{
|
38
|
+
unsigned char a=i[0]>>4,b=i[1]>>4,c=i[2]>>4,d=i[3]>>4;
|
39
|
+
|
40
|
+
p[0]=16|(a<<5); // bbb10000
|
41
|
+
p[1]=(a>>3)|64|(b<<7); // b10000xb
|
42
|
+
p[2]=b>>1; // 0000xbbb
|
43
|
+
p[3]=1|(c<<1); // 00xbbbb1
|
44
|
+
p[4]=4|(d<<3); // xbbbb100
|
45
|
+
i+=4;
|
46
|
+
p+=5;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
// Data length // End of LZW (b10001) // Terminator // GIF End
|
51
|
+
memcpy(gif+gifsize-4,"\x01" "\x11" "\x00" ";",4);
|
52
|
+
}
|
53
|
+
|
54
|
+
static const int8_t sw[200]={0, 4, 8, 12, 16, 20, 23, 27, 31, 35, 39, 43, 47, 50, 54, 58, 61, 65, 68, 71, 75, 78, 81, 84, 87, 90, 93, 96, 98, 101, 103, 105, 108, 110, 112, 114, 115, 117, 119, 120, 121, 122, 123, 124, 125, 126, 126, 127, 127, 127, 127, 127, 127, 127, 126, 126, 125, 124, 123, 122, 121, 120, 119, 117, 115, 114, 112, 110, 108, 105, 103, 101, 98, 96, 93, 90, 87, 84, 81, 78, 75, 71, 68, 65, 61, 58, 54, 50, 47, 43, 39, 35, 31, 27, 23, 20, 16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -23, -27, -31, -35, -39, -43, -47, -50, -54, -58, -61, -65, -68, -71, -75, -78, -81, -84, -87, -90, -93, -96, -98, -101, -103, -105, -108, -110, -112, -114, -115, -117, -119, -120, -121, -122, -123, -124, -125, -126, -126, -127, -127, -127, -127, -127, -127, -127, -126, -126, -125, -124, -123, -122, -121, -120, -119, -117, -115, -114, -112, -110, -108, -105, -103, -101, -98, -96, -93, -90, -87, -84, -81, -78, -75, -71, -68, -65, -61, -58, -54, -50, -47, -43, -39, -35, -31, -27, -23, -20, -16, -12, -8, -4};
|
55
|
+
|
56
|
+
|
57
|
+
#define MAX(x,y) ((x>y)?(x):(y))
|
58
|
+
|
59
|
+
static int letter(int n, int pos, unsigned char im[70*200], unsigned char swr[200], uint8_t s1, uint8_t s2) {
|
60
|
+
int8_t *p=lt[n];
|
61
|
+
unsigned char *r=im+200*16+pos;
|
62
|
+
unsigned char *i=r;
|
63
|
+
int sk1=s1+pos;
|
64
|
+
int sk2=s2+pos;
|
65
|
+
int mpos=pos;
|
66
|
+
int row=0;
|
67
|
+
for(;*p!=-101;p++) {
|
68
|
+
if(*p<0) {
|
69
|
+
if(*p==-100) { r+=200; i=r; sk1=s1+pos; row++; continue; }
|
70
|
+
i+=-*p;
|
71
|
+
continue;
|
72
|
+
}
|
73
|
+
|
74
|
+
if(sk1>=200) sk1=sk1%200;
|
75
|
+
int skew=sw[sk1]/16;
|
76
|
+
sk1+=(swr[pos+i-r]&0x1)+1;
|
77
|
+
|
78
|
+
if(sk2>=200) sk2=sk2%200;
|
79
|
+
int skewh=sw[sk2]/70;
|
80
|
+
sk2+=(swr[row]&0x1);
|
81
|
+
|
82
|
+
unsigned char *x=i+skew*200+skewh;
|
83
|
+
mpos=MAX(mpos,pos+i-r);
|
84
|
+
|
85
|
+
if((x-im)<70*200) *x=(*p)<<4;
|
86
|
+
i++;
|
87
|
+
}
|
88
|
+
return mpos + 3;
|
89
|
+
}
|
90
|
+
|
91
|
+
#define NDOTS 10
|
92
|
+
|
93
|
+
uint32_t dr[NDOTS];
|
94
|
+
|
95
|
+
static void line(unsigned char im[70*200], unsigned char swr[200], uint8_t s1) {
|
96
|
+
int x;
|
97
|
+
int sk1=s1;
|
98
|
+
for(x=0;x<199;x++) {
|
99
|
+
if(sk1>=200) sk1=sk1%200;
|
100
|
+
int skew=sw[sk1]/20;
|
101
|
+
sk1+=swr[x]&0x3+1;
|
102
|
+
unsigned char *i= im+(200*(45+skew)+x);
|
103
|
+
i[0]=0; i[1]=0; i[200]=0; i[201]=0;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
static void dots(unsigned char im[70*200]) {
|
108
|
+
int n;
|
109
|
+
for(n=0;n<NDOTS;n++) {
|
110
|
+
uint32_t v=dr[n];
|
111
|
+
unsigned char *i=im+v%(200*67);
|
112
|
+
|
113
|
+
i[0]=0xff;
|
114
|
+
i[1]=0xff;
|
115
|
+
i[2]=0xff;
|
116
|
+
i[200]=0xff;
|
117
|
+
i[201]=0xff;
|
118
|
+
i[202]=0xff;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
static void blur(unsigned char im[70*200]) {
|
123
|
+
unsigned char *i=im;
|
124
|
+
int x,y;
|
125
|
+
for(y=0;y<68;y++) {
|
126
|
+
for(x=0;x<198;x++) {
|
127
|
+
unsigned int c11=*i,c12=i[1],c21=i[200],c22=i[201];
|
128
|
+
*i++=((c11+c12+c21+c22)/4);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
static void filter(unsigned char im[70*200]) {
|
134
|
+
unsigned char om[70*200];
|
135
|
+
unsigned char *i=im;
|
136
|
+
unsigned char *o=om;
|
137
|
+
|
138
|
+
memset(om,0xff,sizeof(om));
|
139
|
+
|
140
|
+
int x,y;
|
141
|
+
for(y=0;y<70;y++) {
|
142
|
+
for(x=4;x<200-4;x++) {
|
143
|
+
if(i[0]>0xf0 && i[1]<0xf0) { o[0]=0; o[1]=0; }
|
144
|
+
else if(i[0]<0xf0 && i[1]>0xf0) { o[0]=0; o[1]=0; }
|
145
|
+
|
146
|
+
i++;
|
147
|
+
o++;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
memmove(im,om,sizeof(om));
|
152
|
+
}
|
153
|
+
|
154
|
+
static const char *letters="123456789012345678901234567890";
|
155
|
+
|
156
|
+
void captcha(unsigned char im[70*200], unsigned char l[8], int length, int i_line, int i_filter) {
|
157
|
+
unsigned char swr[200];
|
158
|
+
uint8_t s1,s2;
|
159
|
+
|
160
|
+
int f=open("/dev/urandom",O_RDONLY);
|
161
|
+
read(f,l,5); read(f,swr,200); read(f,dr,sizeof(dr)); read(f,&s1,1); read(f,&s2,1);
|
162
|
+
close(f);
|
163
|
+
memset(im,0xff,200*70); s1=s1&0x7f; s2=s2&0x3f;
|
164
|
+
|
165
|
+
int x;
|
166
|
+
for(x=0;x<length;x++){
|
167
|
+
l[x]%=25;
|
168
|
+
}
|
169
|
+
for(x=length;x<8;x++){
|
170
|
+
l[length]=0;
|
171
|
+
}
|
172
|
+
//l[0]%=25; l[1]%=25; l[2]%=25; l[3]%=25; l[4]=0; // l[4]%=25; l[5]=0;
|
173
|
+
int p=30;
|
174
|
+
for(x=0;x<length;x++){
|
175
|
+
p=letter(l[x],p,im,swr,s1,s2);
|
176
|
+
}
|
177
|
+
|
178
|
+
if (i_line == 1) {
|
179
|
+
line(im,swr,s1);
|
180
|
+
}
|
181
|
+
// dots(im);
|
182
|
+
if (i_filter == 1) {
|
183
|
+
blur(im);
|
184
|
+
filter(im);
|
185
|
+
}
|
186
|
+
|
187
|
+
for(x=0;x<length;x++){
|
188
|
+
l[x]=letters[l[x]];
|
189
|
+
}
|
190
|
+
//l[1]=letters[l[1]]; l[2]=letters[l[2]]; l[3]=letters[l[3]]; //l[4]=letters[l[4]];
|
191
|
+
}
|
192
|
+
|
193
|
+
// #ifdef CAPTCHA
|
194
|
+
//
|
195
|
+
// int main() {
|
196
|
+
// char l[6];
|
197
|
+
// unsigned char im[70*200];
|
198
|
+
// unsigned char gif[gifsize];
|
199
|
+
//
|
200
|
+
// captcha(im,l);
|
201
|
+
// makegif(im,gif);
|
202
|
+
//
|
203
|
+
// write(1,gif,gifsize);
|
204
|
+
// write(2,l,5);
|
205
|
+
//
|
206
|
+
// return 0;
|
207
|
+
// }
|
208
|
+
//
|
209
|
+
// #endif
|
210
|
+
|
211
|
+
VALUE RuCaptchaNumber = Qnil;
|
212
|
+
|
213
|
+
void Init_rucaptcha_number();
|
214
|
+
|
215
|
+
VALUE create(VALUE self, VALUE style, VALUE length, VALUE line, VALUE filter);
|
216
|
+
|
217
|
+
void Init_rucaptcha_number() {
|
218
|
+
RuCaptchaNumber = rb_define_module("RuCaptchaNumber");
|
219
|
+
rb_define_singleton_method(RuCaptchaNumber, "create", create, 4);
|
220
|
+
}
|
221
|
+
|
222
|
+
VALUE create(VALUE self, VALUE style, VALUE length, VALUE line, VALUE filter) {
|
223
|
+
char l[8];
|
224
|
+
unsigned char im[80*200];
|
225
|
+
unsigned char gif[gifsize];
|
226
|
+
int i_style = FIX2INT(style);
|
227
|
+
int i_length = FIX2INT(length);
|
228
|
+
int i_line = FIX2INT(line);
|
229
|
+
int i_filter = FIX2INT(filter);
|
230
|
+
|
231
|
+
captcha(im, l, i_length, i_line, i_filter);
|
232
|
+
makegif(im, gif, i_style);
|
233
|
+
|
234
|
+
VALUE result = rb_ary_new2(2);
|
235
|
+
rb_ary_push(result, rb_str_new2(l));
|
236
|
+
rb_ary_push(result, rb_str_new(gif, gifsize));
|
237
|
+
|
238
|
+
return result;
|
239
|
+
}
|
240
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RuCaptchaNumber
|
2
|
+
class Configuration
|
3
|
+
# Store Captcha code where, this config more like Rails config.cache_store
|
4
|
+
# default: Rails application config.cache_store
|
5
|
+
attr_accessor :cache_store
|
6
|
+
# rucaptcha expire time, default 2 minutes
|
7
|
+
attr_accessor :expires_in
|
8
|
+
# Color style, default: :colorful, allows: [:colorful, :black_white]
|
9
|
+
attr_accessor :style
|
10
|
+
# Chars length: default 5, allows: [3..7]
|
11
|
+
attr_accessor :length
|
12
|
+
# strikethrough, default: true
|
13
|
+
attr_accessor :strikethrough
|
14
|
+
# outline style for hard mode, default: false
|
15
|
+
attr_accessor :outline
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module RuCaptchaNumber
|
2
|
+
module ControllerHelpers
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
helper_method :verify_rucaptcha?
|
7
|
+
end
|
8
|
+
|
9
|
+
# filename key of rucaptcha
|
10
|
+
def rucaptcha_filename
|
11
|
+
filename = SecureRandom.hex
|
12
|
+
filename_digest = Digest::SHA256.hexdigest(filename.inspect)
|
13
|
+
['rucaptcha-session', filename_digest].join(':')
|
14
|
+
end
|
15
|
+
|
16
|
+
# Generate a new Captcha
|
17
|
+
def generate_rucaptcha
|
18
|
+
res = RuCaptchaNumber.generate()
|
19
|
+
session_val = {
|
20
|
+
code: res[0],
|
21
|
+
time: Time.now.to_i
|
22
|
+
}
|
23
|
+
filename = rucaptcha_filename
|
24
|
+
RuCaptchaNumber.cache.write(filename, session_val, expires_in: RuCaptchaNumber.config.expires_in)
|
25
|
+
|
26
|
+
{filename: filename,image: res[1]}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Verify captcha code
|
30
|
+
#
|
31
|
+
# params:
|
32
|
+
# resource - [optional] a ActiveModel object, if given will add validation error message to object.
|
33
|
+
# :keep_session - if true, RuCaptchaNumber will not delete the captcha code session.
|
34
|
+
#
|
35
|
+
# exmaples:
|
36
|
+
#
|
37
|
+
# verify_rucaptcha?
|
38
|
+
# verify_rucaptcha?(user, keep_session: true)
|
39
|
+
# verify_rucaptcha?(nil, keep_session: true)
|
40
|
+
#
|
41
|
+
def verify_rucaptcha?(resource = nil, opts = {})
|
42
|
+
opts ||= {}
|
43
|
+
|
44
|
+
if params[:filename].blank?
|
45
|
+
return add_rucaptcha_validation_error
|
46
|
+
end
|
47
|
+
|
48
|
+
store_info = RuCaptchaNumber.cache.read(params[:filename])
|
49
|
+
# make sure move used key
|
50
|
+
RuCaptchaNumber.cache.delete(params[:filename]) unless opts[:keep_session]
|
51
|
+
|
52
|
+
# Make sure session exist
|
53
|
+
if store_info.blank?
|
54
|
+
return add_rucaptcha_validation_error
|
55
|
+
end
|
56
|
+
|
57
|
+
# Make sure not expire
|
58
|
+
if (Time.now.to_i - store_info[:time]) > RuCaptchaNumber.config.expires_in
|
59
|
+
return add_rucaptcha_validation_error
|
60
|
+
end
|
61
|
+
|
62
|
+
# Make sure parama have captcha
|
63
|
+
captcha = (params[:_rucaptcha] || '').downcase.strip
|
64
|
+
if captcha.blank?
|
65
|
+
return add_rucaptcha_validation_error
|
66
|
+
end
|
67
|
+
|
68
|
+
if captcha != store_info[:code]
|
69
|
+
return add_rucaptcha_validation_error
|
70
|
+
end
|
71
|
+
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def add_rucaptcha_validation_error
|
78
|
+
if defined?(resource) && resource && resource.respond_to?(:errors)
|
79
|
+
resource.errors.add(:base, t('rucaptcha.invalid'))
|
80
|
+
end
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
def warning_when_session_invalid
|
85
|
+
Rails.logger.warn "
|
86
|
+
WARNING! The session.id is blank, RuCaptchaNumber can't work properly, please keep session available.
|
87
|
+
More details about this: https://github.com/huacnlee/rucaptcha/pull/66
|
88
|
+
"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RuCaptchaNumber
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace RuCaptchaNumber
|
4
|
+
|
5
|
+
initializer 'rucaptcha.init' do |app|
|
6
|
+
# https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/action_dispatch/routing/route_set.rb#L268
|
7
|
+
# `app.routes.prepend` start from Rails 3.2 - 5.0
|
8
|
+
app.routes.prepend do
|
9
|
+
mount RuCaptchaNumber::Engine => '/rucaptcha'
|
10
|
+
end
|
11
|
+
|
12
|
+
RuCaptchaNumber.check_cache_store!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RuCaptchaNumber
|
2
|
+
module ViewHelpers
|
3
|
+
def rucaptcha_input_tag(opts = {})
|
4
|
+
opts[:name] = '_rucaptcha'
|
5
|
+
opts[:type] = 'text'
|
6
|
+
opts[:autocorrect] = 'off'
|
7
|
+
opts[:autocapitalize] = 'off'
|
8
|
+
opts[:pattern] = '[a-zA-Z]*'
|
9
|
+
opts[:maxlength] = 5
|
10
|
+
opts[:autocomplete] = 'off'
|
11
|
+
tag(:input, opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def rucaptcha_image_tag(opts = {})
|
15
|
+
opts[:class] = opts[:class] || 'rucaptcha-image'
|
16
|
+
image_tag(ru_captcha.root_url, opts)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'rucaptcha_number/rucaptcha_number'
|
5
|
+
require 'rucaptcha_number/version'
|
6
|
+
require 'rucaptcha_number/configuration'
|
7
|
+
require 'rucaptcha_number/controller_helpers'
|
8
|
+
require 'rucaptcha_number/view_helpers'
|
9
|
+
require 'rucaptcha_number/cache'
|
10
|
+
require 'rucaptcha_number/engine'
|
11
|
+
require 'rucaptcha_number/errors/configuration'
|
12
|
+
|
13
|
+
module RuCaptchaNumber
|
14
|
+
class << self
|
15
|
+
def config
|
16
|
+
return @config if defined?(@config)
|
17
|
+
@config = Configuration.new
|
18
|
+
@config.style = :colorful
|
19
|
+
@config.length = 5
|
20
|
+
@config.strikethrough = true
|
21
|
+
@config.outline = false
|
22
|
+
@config.expires_in = 2.minutes
|
23
|
+
|
24
|
+
if Rails.application
|
25
|
+
@config.cache_store = Rails.application.config.cache_store
|
26
|
+
else
|
27
|
+
@config.cache_store = :mem_cache_store
|
28
|
+
end
|
29
|
+
@config.cache_store
|
30
|
+
@config
|
31
|
+
end
|
32
|
+
|
33
|
+
def configure(&block)
|
34
|
+
config.instance_exec(&block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate()
|
38
|
+
style = config.style == :colorful ? 1 : 0
|
39
|
+
length = config.length
|
40
|
+
|
41
|
+
unless length.in?(3..7)
|
42
|
+
raise Rucaptcha::Errors::Configuration, 'length config error, value must in 3..7'
|
43
|
+
end
|
44
|
+
|
45
|
+
strikethrough = config.strikethrough ? 1 : 0
|
46
|
+
outline = config.outline ? 1 : 0
|
47
|
+
self.create(style, length, strikethrough, outline)
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_cache_store!
|
51
|
+
cache_store = RuCaptchaNumber.config.cache_store
|
52
|
+
store_name = cache_store.is_a?(Array) ? cache_store.first : cache_store
|
53
|
+
if [:memory_store, :null_store, :file_store].include?(store_name)
|
54
|
+
RuCaptchaNumber.config.cache_store = [:file_store, Rails.root.join('tmp/cache/rucaptcha_number/session')]
|
55
|
+
|
56
|
+
puts "
|
57
|
+
|
58
|
+
RuCaptchaNumber's cache_store requirements are stored across processes and machines,
|
59
|
+
such as :mem_cache_store, :redis_store, or other distributed storage.
|
60
|
+
But your current set is #{cache_store}, it has changed to :file_store for working.
|
61
|
+
NOTE: :file_store is still not a good way, it only works with single server case.
|
62
|
+
|
63
|
+
Please make config file `config/initializers/rucaptcha_number.rb` to setup `cache_store`.
|
64
|
+
More infomation please read GitHub RuCaptchaNumber README file.
|
65
|
+
https://github.com/huacnlee/rucaptcha_number
|
66
|
+
|
67
|
+
"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
ActiveSupport.on_load(:action_controller) do
|
74
|
+
ActionController::Base.send :include, RuCaptchaNumber::ControllerHelpers
|
75
|
+
end
|
76
|
+
|
77
|
+
ActiveSupport.on_load(:action_view) do
|
78
|
+
include RuCaptchaNumber::ViewHelpers
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rucaptcha_number
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roc Leung
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
description:
|
42
|
+
email: rocleung@live.com
|
43
|
+
executables: []
|
44
|
+
extensions:
|
45
|
+
- ext/rucaptcha_number/extconf.rb
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- CHANGELOG.md
|
49
|
+
- README.md
|
50
|
+
- app/controllers/ru_captcha_number/captcha_controller.rb
|
51
|
+
- config/locales/rucaptcha_number.en.yml
|
52
|
+
- config/locales/rucaptcha_number.pt-BR.yml
|
53
|
+
- config/locales/rucaptcha_number.zh-CN.yml
|
54
|
+
- config/locales/rucaptcha_number.zh-TW.yml
|
55
|
+
- config/routes.rb
|
56
|
+
- ext/rucaptcha_number/colors.h
|
57
|
+
- ext/rucaptcha_number/extconf.rb
|
58
|
+
- ext/rucaptcha_number/font.h
|
59
|
+
- ext/rucaptcha_number/rucaptcha_number.c
|
60
|
+
- lib/rucaptcha_number.rb
|
61
|
+
- lib/rucaptcha_number/cache.rb
|
62
|
+
- lib/rucaptcha_number/configuration.rb
|
63
|
+
- lib/rucaptcha_number/controller_helpers.rb
|
64
|
+
- lib/rucaptcha_number/engine.rb
|
65
|
+
- lib/rucaptcha_number/errors/configuration.rb
|
66
|
+
- lib/rucaptcha_number/version.rb
|
67
|
+
- lib/rucaptcha_number/view_helpers.rb
|
68
|
+
homepage: ''
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.0.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.7.8
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Copy of Rucaptcha,For my website
|
92
|
+
test_files: []
|