raptcha 0.0.1 → 2.0.0
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.
- data/README +0 -88
- data/Rakefile +364 -0
- data/image.sh +24 -0
- data/images/raptcha.png +0 -0
- data/lib/raptcha.rb +377 -2063
- metadata +56 -128
- data/bin/raptcha +0 -2225
- data/gemspec.rb +0 -28
- data/install.rb +0 -210
- data/out +0 -0
- data/rails/README +0 -182
- data/rails/Rakefile +0 -10
- data/rails/app/controllers/application.rb +0 -7
- data/rails/app/controllers/raptcha_controller.rb +0 -43
- data/rails/app/helpers/application_helper.rb +0 -3
- data/rails/config/boot.rb +0 -45
- data/rails/config/database.yml +0 -36
- data/rails/config/environment.rb +0 -62
- data/rails/config/environments/development.rb +0 -21
- data/rails/config/environments/production.rb +0 -18
- data/rails/config/environments/test.rb +0 -19
- data/rails/config/lighttpd.conf +0 -54
- data/rails/config/routes.rb +0 -23
- data/rails/doc/README_FOR_APP +0 -2
- data/rails/lib/raptcha.rb +0 -2225
- data/rails/log/development.log +0 -16
- data/rails/log/fastcgi.crash.log +0 -4
- data/rails/log/lighttpd.access.log +0 -2
- data/rails/log/lighttpd.error.log +0 -3
- data/rails/log/production.log +0 -0
- data/rails/log/server.log +0 -0
- data/rails/log/test.log +0 -0
- data/rails/public/404.html +0 -30
- data/rails/public/500.html +0 -30
- data/rails/public/dispatch.cgi +0 -10
- data/rails/public/dispatch.fcgi +0 -24
- data/rails/public/dispatch.rb +0 -10
- data/rails/public/favicon.ico +0 -0
- data/rails/public/images/rails.png +0 -0
- data/rails/public/index.html +0 -277
- data/rails/public/javascripts/application.js +0 -2
- data/rails/public/javascripts/controls.js +0 -833
- data/rails/public/javascripts/dragdrop.js +0 -942
- data/rails/public/javascripts/effects.js +0 -1088
- data/rails/public/javascripts/prototype.js +0 -2515
- data/rails/public/robots.txt +0 -1
- data/rails/script/about +0 -3
- data/rails/script/breakpointer +0 -3
- data/rails/script/console +0 -3
- data/rails/script/destroy +0 -3
- data/rails/script/generate +0 -3
- data/rails/script/performance/benchmarker +0 -3
- data/rails/script/performance/profiler +0 -3
- data/rails/script/plugin +0 -3
- data/rails/script/process/inspector +0 -3
- data/rails/script/process/reaper +0 -3
- data/rails/script/process/spawner +0 -3
- data/rails/script/runner +0 -3
- data/rails/script/server +0 -3
- data/rails/test/test_helper.rb +0 -28
- data/rails/tmp/sessions/ruby_sess.04085f44b9141c9d +0 -0
- data/raptcha-0.0.1.gem +0 -0
- data/samples.rb +0 -19
data/README
CHANGED
@@ -1,88 +0,0 @@
|
|
1
|
-
NAME
|
2
|
-
|
3
|
-
raptcha
|
4
|
-
|
5
|
-
SYNOPSIS
|
6
|
-
|
7
|
-
low drain bamage, storage-less, session-less, plugin-less, zero admin,
|
8
|
-
single-source-file secure captcha system for ruby and/or rails
|
9
|
-
|
10
|
-
DESCRIPTION
|
11
|
-
|
12
|
-
raptcha manages image generation via a streaming controller. the result is
|
13
|
-
that no disk storage is ever needed for captcha images. it also manages
|
14
|
-
authentication via blowfish encoded hidden fields, obviating the need for
|
15
|
-
session/database interaction for captcha validation. the library is useful
|
16
|
-
outside of rails, even from the command line.
|
17
|
-
|
18
|
-
INSTALL
|
19
|
-
|
20
|
-
DEPENDS
|
21
|
-
|
22
|
-
### sudo port install ImageMagick rb-rmagick
|
23
|
-
|
24
|
-
GEM
|
25
|
-
|
26
|
-
gem install raptcha --no-wrappers
|
27
|
-
|
28
|
-
SINGLE FILE INTO RAILS APP
|
29
|
-
|
30
|
-
cp raptcha.rb ./app/lib/
|
31
|
-
|
32
|
-
URIS
|
33
|
-
|
34
|
-
http://codeforpeople.com/
|
35
|
-
http://rubyforge.org/projects/codeforpeople
|
36
|
-
|
37
|
-
EXAMPLES
|
38
|
-
|
39
|
-
GENERATE A SET OF TAGS TO FOR CAPTCHA PLUS FORM INPUT FIELDS
|
40
|
-
|
41
|
-
Raptcha.input
|
42
|
-
:foreground => 'pink', :background => 'mauve', :distort => 'low'
|
43
|
-
|
44
|
-
GENERATE AN INLINE (Base64 encoded png) INPUT TAG SET
|
45
|
-
|
46
|
-
Raptcha.input((
|
47
|
-
:inline => true, :foreground => 'pink', :distort => 'low',
|
48
|
-
:width => 142, :height => 42, :type => 'jpg'
|
49
|
-
))
|
50
|
-
|
51
|
-
USING IN RAILS
|
52
|
-
|
53
|
-
1) setup the raptcha controller
|
54
|
-
prompt:~/rails_root/ > raptcha generate controller
|
55
|
-
|
56
|
-
2) use in your controllers
|
57
|
-
class WickedEasyController < ApplicationController
|
58
|
-
def form
|
59
|
-
@valid = Raptcha.valid? params
|
60
|
-
|
61
|
-
render :inline => <<-rhtml
|
62
|
-
<html> <body>
|
63
|
-
valid :<%= valid %>
|
64
|
-
|
65
|
-
<form method=post>
|
66
|
-
<%= Raptcha.input %>
|
67
|
-
|
68
|
-
<input type=submit name=submit value=submit />
|
69
|
-
</form>
|
70
|
-
</body> </html>
|
71
|
-
rhtml
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
COMMAND LINE USAGE
|
76
|
-
|
77
|
-
ruby raptcha.rb foreground:pink > pink.png && display ping.png
|
78
|
-
|
79
|
-
|
80
|
-
ruby raptcha.rb generate lib
|
81
|
-
|
82
|
-
SAMPLES
|
83
|
-
|
84
|
-
see http://drawohara.tumblr.com/post/5125054
|
85
|
-
|
86
|
-
DOC
|
87
|
-
|
88
|
-
vim raptcha.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,364 @@
|
|
1
|
+
This.rubyforge_project = 'codeforpeople'
|
2
|
+
This.author = "Ara T. Howard"
|
3
|
+
This.email = "ara.t.howard@gmail.com"
|
4
|
+
This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
|
5
|
+
|
6
|
+
|
7
|
+
task :default do
|
8
|
+
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test do
|
12
|
+
run_tests!
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :test do
|
16
|
+
task(:unit){ run_tests!(:unit) }
|
17
|
+
task(:functional){ run_tests!(:functional) }
|
18
|
+
task(:integration){ run_tests!(:integration) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_tests!(which = nil)
|
22
|
+
which ||= '**'
|
23
|
+
test_dir = File.join(This.dir, "test")
|
24
|
+
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
|
25
|
+
test_rbs = Dir.glob(test_glob).sort
|
26
|
+
|
27
|
+
div = ('=' * 119)
|
28
|
+
line = ('-' * 119)
|
29
|
+
helper = "-r ./test/helper.rb" if test(?e, "./test/helper.rb")
|
30
|
+
|
31
|
+
test_rbs.each_with_index do |test_rb, index|
|
32
|
+
testno = index + 1
|
33
|
+
command = "#{ This.ruby } -I ./lib -I ./test/lib #{ helper } #{ test_rb }"
|
34
|
+
|
35
|
+
puts
|
36
|
+
say(div, :color => :cyan, :bold => true)
|
37
|
+
say("@#{ testno } => ", :bold => true, :method => :print)
|
38
|
+
say(command, :color => :cyan, :bold => true)
|
39
|
+
say(line, :color => :cyan, :bold => true)
|
40
|
+
|
41
|
+
system(command)
|
42
|
+
|
43
|
+
say(line, :color => :cyan, :bold => true)
|
44
|
+
|
45
|
+
status = $?.exitstatus
|
46
|
+
|
47
|
+
if status.zero?
|
48
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
49
|
+
say("SUCCESS", :color => :green, :bold => true)
|
50
|
+
else
|
51
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
52
|
+
say("FAILURE", :color => :red, :bold => true)
|
53
|
+
end
|
54
|
+
say(line, :color => :cyan, :bold => true)
|
55
|
+
|
56
|
+
exit(status) unless status.zero?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
task :gemspec do
|
62
|
+
ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
|
63
|
+
ignore_directories = %w[ pkg ]
|
64
|
+
ignore_files = %w[ test/log ]
|
65
|
+
|
66
|
+
shiteless =
|
67
|
+
lambda do |list|
|
68
|
+
list.delete_if do |entry|
|
69
|
+
next unless test(?e, entry)
|
70
|
+
extension = File.basename(entry).split(%r/[.]/).last
|
71
|
+
ignore_extensions.any?{|ext| ext === extension}
|
72
|
+
end
|
73
|
+
list.delete_if do |entry|
|
74
|
+
next unless test(?d, entry)
|
75
|
+
dirname = File.expand_path(entry)
|
76
|
+
ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
|
77
|
+
end
|
78
|
+
list.delete_if do |entry|
|
79
|
+
next unless test(?f, entry)
|
80
|
+
filename = File.expand_path(entry)
|
81
|
+
ignore_files.any?{|file| File.expand_path(file) == filename}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
lib = This.lib
|
86
|
+
object = This.object
|
87
|
+
version = This.version
|
88
|
+
files = shiteless[Dir::glob("**/**")]
|
89
|
+
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
90
|
+
has_rdoc = true #File.exist?('doc')
|
91
|
+
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
|
92
|
+
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
93
|
+
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
94
|
+
|
95
|
+
if This.extensions.nil?
|
96
|
+
This.extensions = []
|
97
|
+
extensions = This.extensions
|
98
|
+
%w( Makefile configure extconf.rb ).each do |ext|
|
99
|
+
extensions << ext if File.exists?(ext)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
extensions = [extensions].flatten.compact
|
103
|
+
|
104
|
+
template =
|
105
|
+
if test(?e, 'gemspec.erb')
|
106
|
+
Template{ IO.read('gemspec.erb') }
|
107
|
+
else
|
108
|
+
Template {
|
109
|
+
<<-__
|
110
|
+
## #{ lib }.gemspec
|
111
|
+
#
|
112
|
+
|
113
|
+
Gem::Specification::new do |spec|
|
114
|
+
spec.name = #{ lib.inspect }
|
115
|
+
spec.version = #{ version.inspect }
|
116
|
+
spec.platform = Gem::Platform::RUBY
|
117
|
+
spec.summary = #{ lib.inspect }
|
118
|
+
spec.description = #{ description.inspect }
|
119
|
+
|
120
|
+
spec.files = #{ files.inspect }
|
121
|
+
spec.executables = #{ executables.inspect }
|
122
|
+
|
123
|
+
spec.require_path = "lib"
|
124
|
+
|
125
|
+
spec.has_rdoc = #{ has_rdoc.inspect }
|
126
|
+
spec.test_files = #{ test_files.inspect }
|
127
|
+
|
128
|
+
# spec.add_dependency 'lib', '>= version'
|
129
|
+
|
130
|
+
spec.extensions.push(*#{ extensions.inspect })
|
131
|
+
|
132
|
+
spec.rubyforge_project = #{ This.rubyforge_project.inspect }
|
133
|
+
spec.author = #{ This.author.inspect }
|
134
|
+
spec.email = #{ This.email.inspect }
|
135
|
+
spec.homepage = #{ This.homepage.inspect }
|
136
|
+
end
|
137
|
+
__
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
Fu.mkdir_p(This.pkgdir)
|
142
|
+
This.gemspec = File.join(This.pkgdir, "gemspec.rb")
|
143
|
+
open("#{ This.gemspec }", "w"){|fd| fd.puts(template)}
|
144
|
+
end
|
145
|
+
|
146
|
+
task :gem => [:clean, :gemspec] do
|
147
|
+
Fu.mkdir_p(This.pkgdir)
|
148
|
+
before = Dir['*.gem']
|
149
|
+
cmd = "gem build #{ This.gemspec }"
|
150
|
+
`#{ cmd }`
|
151
|
+
after = Dir['*.gem']
|
152
|
+
gem = ((after - before).first || after.first) or abort('no gem!')
|
153
|
+
Fu.mv gem, This.pkgdir
|
154
|
+
This.gem = File.basename(gem)
|
155
|
+
end
|
156
|
+
|
157
|
+
task :readme do
|
158
|
+
samples = ''
|
159
|
+
prompt = '~ > '
|
160
|
+
lib = This.lib
|
161
|
+
version = This.version
|
162
|
+
|
163
|
+
Dir['sample*/*'].sort.each do |sample|
|
164
|
+
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
165
|
+
|
166
|
+
cmd = "cat #{ sample }"
|
167
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
168
|
+
samples << Util.indent(`#{ cmd }`, 4) << "\n"
|
169
|
+
|
170
|
+
cmd = "ruby #{ sample }"
|
171
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
172
|
+
|
173
|
+
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
|
174
|
+
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
175
|
+
end
|
176
|
+
|
177
|
+
template =
|
178
|
+
if test(?e, 'readme.erb')
|
179
|
+
Template{ IO.read('readme.erb') }
|
180
|
+
else
|
181
|
+
Template {
|
182
|
+
<<-__
|
183
|
+
NAME
|
184
|
+
#{ lib }
|
185
|
+
|
186
|
+
DESCRIPTION
|
187
|
+
|
188
|
+
INSTALL
|
189
|
+
gem install #{ lib }
|
190
|
+
|
191
|
+
SAMPLES
|
192
|
+
#{ samples }
|
193
|
+
__
|
194
|
+
}
|
195
|
+
end
|
196
|
+
|
197
|
+
open("README", "w"){|fd| fd.puts template}
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
task :clean do
|
202
|
+
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
task :release => [:clean, :gemspec, :gem] do
|
207
|
+
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
|
208
|
+
raise "which one? : #{ gems.inspect }" if gems.size > 1
|
209
|
+
raise "no gems?" if gems.size < 1
|
210
|
+
cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
|
211
|
+
puts cmd
|
212
|
+
system cmd
|
213
|
+
cmd = "gem push #{ This.pkgdir }/#{ This.gem }"
|
214
|
+
puts cmd
|
215
|
+
system cmd
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
BEGIN {
|
223
|
+
# support for this rakefile
|
224
|
+
#
|
225
|
+
$VERBOSE = nil
|
226
|
+
|
227
|
+
require 'ostruct'
|
228
|
+
require 'erb'
|
229
|
+
require 'fileutils'
|
230
|
+
require 'rbconfig'
|
231
|
+
|
232
|
+
# fu shortcut
|
233
|
+
#
|
234
|
+
Fu = FileUtils
|
235
|
+
|
236
|
+
# cache a bunch of stuff about this rakefile/environment
|
237
|
+
#
|
238
|
+
This = OpenStruct.new
|
239
|
+
|
240
|
+
This.file = File.expand_path(__FILE__)
|
241
|
+
This.dir = File.dirname(This.file)
|
242
|
+
This.pkgdir = File.join(This.dir, 'pkg')
|
243
|
+
|
244
|
+
# grok lib
|
245
|
+
#
|
246
|
+
lib = ENV['LIB']
|
247
|
+
unless lib
|
248
|
+
lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
|
249
|
+
end
|
250
|
+
This.lib = lib
|
251
|
+
|
252
|
+
# grok version
|
253
|
+
#
|
254
|
+
version = ENV['VERSION']
|
255
|
+
unless version
|
256
|
+
require "./lib/#{ This.lib }"
|
257
|
+
This.name = lib.capitalize
|
258
|
+
This.object = eval(This.name)
|
259
|
+
version = This.object.send(:version)
|
260
|
+
end
|
261
|
+
This.version = version
|
262
|
+
|
263
|
+
# we need to know the name of the lib an it's version
|
264
|
+
#
|
265
|
+
abort('no lib') unless This.lib
|
266
|
+
abort('no version') unless This.version
|
267
|
+
|
268
|
+
# discover full path to this ruby executable
|
269
|
+
#
|
270
|
+
c = Config::CONFIG
|
271
|
+
bindir = c["bindir"] || c['BINDIR']
|
272
|
+
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
|
273
|
+
ruby_ext = c['EXEEXT'] || ''
|
274
|
+
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
|
275
|
+
This.ruby = ruby
|
276
|
+
|
277
|
+
# some utils
|
278
|
+
#
|
279
|
+
module Util
|
280
|
+
def indent(s, n = 2)
|
281
|
+
s = unindent(s)
|
282
|
+
ws = ' ' * n
|
283
|
+
s.gsub(%r/^/, ws)
|
284
|
+
end
|
285
|
+
|
286
|
+
def unindent(s)
|
287
|
+
indent = nil
|
288
|
+
s.each_line do |line|
|
289
|
+
next if line =~ %r/^\s*$/
|
290
|
+
indent = line[%r/^\s*/] and break
|
291
|
+
end
|
292
|
+
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
293
|
+
end
|
294
|
+
extend self
|
295
|
+
end
|
296
|
+
|
297
|
+
# template support
|
298
|
+
#
|
299
|
+
class Template
|
300
|
+
def initialize(&block)
|
301
|
+
@block = block.binding
|
302
|
+
@template = block.call.to_s
|
303
|
+
end
|
304
|
+
def expand(b=nil)
|
305
|
+
ERB.new(Util.unindent(@template)).result(b||@block)
|
306
|
+
end
|
307
|
+
alias_method 'to_s', 'expand'
|
308
|
+
end
|
309
|
+
def Template(*args, &block) Template.new(*args, &block) end
|
310
|
+
|
311
|
+
# colored console output support
|
312
|
+
#
|
313
|
+
This.ansi = {
|
314
|
+
:clear => "\e[0m",
|
315
|
+
:reset => "\e[0m",
|
316
|
+
:erase_line => "\e[K",
|
317
|
+
:erase_char => "\e[P",
|
318
|
+
:bold => "\e[1m",
|
319
|
+
:dark => "\e[2m",
|
320
|
+
:underline => "\e[4m",
|
321
|
+
:underscore => "\e[4m",
|
322
|
+
:blink => "\e[5m",
|
323
|
+
:reverse => "\e[7m",
|
324
|
+
:concealed => "\e[8m",
|
325
|
+
:black => "\e[30m",
|
326
|
+
:red => "\e[31m",
|
327
|
+
:green => "\e[32m",
|
328
|
+
:yellow => "\e[33m",
|
329
|
+
:blue => "\e[34m",
|
330
|
+
:magenta => "\e[35m",
|
331
|
+
:cyan => "\e[36m",
|
332
|
+
:white => "\e[37m",
|
333
|
+
:on_black => "\e[40m",
|
334
|
+
:on_red => "\e[41m",
|
335
|
+
:on_green => "\e[42m",
|
336
|
+
:on_yellow => "\e[43m",
|
337
|
+
:on_blue => "\e[44m",
|
338
|
+
:on_magenta => "\e[45m",
|
339
|
+
:on_cyan => "\e[46m",
|
340
|
+
:on_white => "\e[47m"
|
341
|
+
}
|
342
|
+
def say(phrase, *args)
|
343
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
344
|
+
options[:color] = args.shift.to_s.to_sym unless args.empty?
|
345
|
+
keys = options.keys
|
346
|
+
keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
|
347
|
+
|
348
|
+
color = options[:color]
|
349
|
+
bold = options.has_key?(:bold)
|
350
|
+
|
351
|
+
parts = [phrase]
|
352
|
+
parts.unshift(This.ansi[color]) if color
|
353
|
+
parts.unshift(This.ansi[:bold]) if bold
|
354
|
+
parts.push(This.ansi[:clear]) if parts.size > 1
|
355
|
+
|
356
|
+
method = options[:method] || :puts
|
357
|
+
|
358
|
+
Kernel.send(method, parts.join)
|
359
|
+
end
|
360
|
+
|
361
|
+
# always run out of the project dir
|
362
|
+
#
|
363
|
+
Dir.chdir(This.dir)
|
364
|
+
}
|