turing 0.0.10 → 0.0.11
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/CHANGES +8 -0
- data/Rakefile +2 -2
- data/lib/turing.rb +1 -1
- data/samples/cgi_handler.rb +49 -0
- data/samples/challenge.rb +31 -0
- data/samples/image.rb +48 -0
- metadata +4 -1
data/CHANGES
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
------------------------------------------------------------------------
|
2
|
+
r312 | wejn | 2007-06-08 15:08:06 +0200 (Fri, 08 Jun 2007) | 1 line
|
3
|
+
|
4
|
+
Added samples dir to gems
|
5
|
+
------------------------------------------------------------------------
|
6
|
+
r311 | wejn | 2007-06-08 13:02:25 +0200 (Fri, 08 Jun 2007) | 1 line
|
7
|
+
|
8
|
+
Fixed repo path in Rakefile
|
9
|
+
------------------------------------------------------------------------
|
2
10
|
r309 | wejn | 2007-06-08 12:36:33 +0200 (Fri, 08 Jun 2007) | 4 lines
|
3
11
|
|
4
12
|
Made compatible with gems 0.9.4.
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ spec = Gem::Specification.new do |s|
|
|
16
16
|
s.summary = "Another implementation of captcha (http://captcha.net/)"
|
17
17
|
s.description = 'Implementation of captcha (Completely Automated Public Turing-Test to Tell Computers and Humans Apart) that is both easy to use and easy to customize/extend.'
|
18
18
|
|
19
|
-
candidates = Dir.glob("{bin,lib,shared,tests}/**/*")
|
19
|
+
candidates = Dir.glob("{bin,lib,shared,tests,samples}/**/*")
|
20
20
|
candidates = candidates.delete_if do |item|
|
21
21
|
item.include?(".svn") || item.include?("rdoc")
|
22
22
|
end
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
require 'fileutils'
|
77
77
|
|
78
78
|
task :release do
|
79
|
-
rel = "file:///home/wejn/
|
79
|
+
rel = "file:///home/wejn/.repos/default/turing/tags/REL-#{Turing::VERSION}"
|
80
80
|
target = "turing-#{Turing::VERSION}"
|
81
81
|
system "svn co #{rel} #{target}"
|
82
82
|
system "svn log #{rel} > #{target}/CHANGES"
|
data/lib/turing.rb
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
# * Turing::Challenge: Captcha challenge generator and verifier.
|
29
29
|
# * Turing::CGIHandler: Simple Turing::Challenge wrapper designed to run as CGI.
|
30
30
|
module Turing # {{{
|
31
|
-
VERSION = "0.0.
|
31
|
+
VERSION = "0.0.11".freeze
|
32
32
|
end # }}}
|
33
33
|
|
34
34
|
require 'turing/image'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Turing -- Ruby implementation of Captcha
|
4
|
+
#
|
5
|
+
# Copyright © 2005 Michal Šafránek <wejn@box.cz>
|
6
|
+
#
|
7
|
+
# This file is part of http://turing.rubyforge.org/
|
8
|
+
#
|
9
|
+
# See turing.rb in lib/ directory for license terms.
|
10
|
+
#
|
11
|
+
|
12
|
+
# This file demonstrates simple CGI challenge/response
|
13
|
+
# authenticator built using CGIHandler.
|
14
|
+
#
|
15
|
+
# It handles autonomously all requests thrown at it
|
16
|
+
# and when user successfully passes turing challenge,
|
17
|
+
# he's given cookie and redirected to some location.
|
18
|
+
#
|
19
|
+
# BTW, it would be fairly easy to convert this to FCGI.
|
20
|
+
#
|
21
|
+
# Warning: For real world please create more intelligent
|
22
|
+
# on_success handler since this one is VERY easy to bypass.
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
gem 'turing'
|
26
|
+
require 'turing'
|
27
|
+
|
28
|
+
tcgi_config = {
|
29
|
+
:imagepath => "/imgs",
|
30
|
+
:outdir => '/home/wejn/ap/htdocs/imgs',
|
31
|
+
:store => '/home/wejn/ap/data/turing.pstore',
|
32
|
+
:redirect_to => 'http://localhost:8000/secured/',
|
33
|
+
}
|
34
|
+
|
35
|
+
tcgi_config[:on_success] = proc do
|
36
|
+
out = {}
|
37
|
+
out[:headers] = {
|
38
|
+
"cookie" => CGI::Cookie.new({
|
39
|
+
'name' => 'turing_passed',
|
40
|
+
'value' => 'true',
|
41
|
+
'path' => '/',
|
42
|
+
'expires' => Time.now + 3600*24,
|
43
|
+
}),
|
44
|
+
"dude" => "you_rock!",
|
45
|
+
}
|
46
|
+
out
|
47
|
+
end
|
48
|
+
|
49
|
+
Turing::CGIHandler.new(tcgi_config).handle
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Turing -- Ruby implementation of Captcha
|
4
|
+
#
|
5
|
+
# Copyright © 2005 Michal Šafránek <wejn@box.cz>
|
6
|
+
#
|
7
|
+
# This file is part of http://turing.rubyforge.org/
|
8
|
+
#
|
9
|
+
# See turing.rb in lib/ directory for license terms.
|
10
|
+
#
|
11
|
+
|
12
|
+
# This file demonstrates how to use Turing::Challenge
|
13
|
+
# to create challenge/response interface with Captcha.
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
gem 'turing'
|
17
|
+
require 'turing'
|
18
|
+
|
19
|
+
tc = Turing::Challenge.new(:store => 'store', :outdir => '.')
|
20
|
+
c = tc.generate_challenge
|
21
|
+
|
22
|
+
system("xv", c.file)
|
23
|
+
|
24
|
+
puts "Enter solution:"
|
25
|
+
r = $stdin.gets.chomp
|
26
|
+
|
27
|
+
if tc.valid_answer?(c.id, r)
|
28
|
+
puts "That's right."
|
29
|
+
else
|
30
|
+
puts "I don't think so."
|
31
|
+
end
|
data/samples/image.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Turing -- Ruby implementation of Captcha
|
4
|
+
#
|
5
|
+
# Copyright © 2005 Michal Šafránek <wejn@box.cz>
|
6
|
+
#
|
7
|
+
# This file is part of http://turing.rubyforge.org/
|
8
|
+
#
|
9
|
+
# See turing.rb in lib/ directory for license terms.
|
10
|
+
#
|
11
|
+
|
12
|
+
# This file demonstrates how to use Turing::Image
|
13
|
+
# to generate image using various methods.
|
14
|
+
#
|
15
|
+
# And how to create and use your own plugin
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
gem 'turing'
|
19
|
+
require 'turing'
|
20
|
+
|
21
|
+
# Default options
|
22
|
+
ti = Turing::Image.new
|
23
|
+
|
24
|
+
# Create some images
|
25
|
+
3.times do |i|
|
26
|
+
ti.generate(File.join(Dir.getwd, i.to_s + '.jpg'), "randomword")
|
27
|
+
end
|
28
|
+
|
29
|
+
# Now create small images using Spiral plugin
|
30
|
+
ti_small = Turing::Image.new(:width => 100, :height => 50, :outdir => '.')
|
31
|
+
ti_small.generate('small.jpg', 'small', Turing::Image::Spiral)
|
32
|
+
|
33
|
+
# Create plugin
|
34
|
+
class BlankMethod < Class.new(Turing::Image)
|
35
|
+
def initialize(opts = {})
|
36
|
+
super(opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate(img, word)
|
40
|
+
write_string(img, 'cour.ttf', GD2::Color[0, 0, 0], "someword", 48)
|
41
|
+
write_string(img, 'cour.ttf', GD2::Color[255, 0, 0, 50.percent], "blankmethod", 14)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Use it exclusively
|
46
|
+
ti.generate(File.join(Dir.getwd, 'blank.jpg'), 'blank', BlankMethod)
|
47
|
+
|
48
|
+
# vim: set ts=4 sw=4 :
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: turing
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
6
|
+
version: 0.0.11
|
7
7
|
date: 2007-06-08 00:00:00 +02:00
|
8
8
|
summary: Another implementation of captcha (http://captcha.net/)
|
9
9
|
require_paths:
|
@@ -63,6 +63,9 @@ files:
|
|
63
63
|
- shared/templates/challenge.rhtml
|
64
64
|
- shared/templates/success.rhtml
|
65
65
|
- shared/templates/error.rhtml
|
66
|
+
- samples/cgi_handler.rb
|
67
|
+
- samples/challenge.rb
|
68
|
+
- samples/image.rb
|
66
69
|
- README
|
67
70
|
- CHANGES
|
68
71
|
- TODO
|