line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GD::SecurityImage::Utils; |
2
|
1
|
|
|
1
|
|
18983
|
use GD::SecurityImage; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use strict; |
4
|
|
|
|
|
|
|
use vars qw(@EXPORT @ISA $VERSION); |
5
|
|
|
|
|
|
|
use Exporter; |
6
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
7
|
|
|
|
|
|
|
@EXPORT = ('write_captcha'); |
8
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)/g; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$GD::SecurityImage::Utils::DEBUG=0; |
11
|
|
|
|
|
|
|
sub DEBUG : lvalue { $GD::SecurityImage::Utils::DEBUG } |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub find_a_ttf_file { |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my @arg = ('find','/usr/share/fonts/','-type','f', '-image', '"*ttf"'); |
17
|
|
|
|
|
|
|
my @files = split (/\n/, `@arg`); |
18
|
|
|
|
|
|
|
scalar @files or warn("no ttf fount with [@arg]") and return; |
19
|
|
|
|
|
|
|
return $files[0]; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub write_captcha { |
28
|
|
|
|
|
|
|
my ($abs_out,$opt)=@_; |
29
|
|
|
|
|
|
|
if (defined $opt){ |
30
|
|
|
|
|
|
|
ref $opt eq 'HASH' or croak('must be hash ref'); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
$opt||={}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# captcha |
38
|
|
|
|
|
|
|
$opt->{width} ||= 140; |
39
|
|
|
|
|
|
|
$opt->{height} ||= 50; |
40
|
|
|
|
|
|
|
$opt->{ptsize} ||= 32; |
41
|
|
|
|
|
|
|
$opt->{lines} ||= 14; |
42
|
|
|
|
|
|
|
$opt->{rndmax} ||= 4; |
43
|
|
|
|
|
|
|
$opt->{font} ||= undef; #'/var/www/public_html/.icons/luxisr.ttf'; |
44
|
|
|
|
|
|
|
$opt->{bgcolor} ||= '#dddddd'; |
45
|
|
|
|
|
|
|
# Create a normal image |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$abs_out=~/[^\/]\.(\w{1,5})$/ or die("abs out $abs_out cant match extension type"); |
48
|
|
|
|
|
|
|
my $ext = lc($1); |
49
|
|
|
|
|
|
|
$ext eq 'png' |
50
|
|
|
|
|
|
|
or $ext eq 'gif' |
51
|
|
|
|
|
|
|
or $ext eq 'jpg' |
52
|
|
|
|
|
|
|
or $ext eq 'jpeg' |
53
|
|
|
|
|
|
|
or die("extension $ext for $abs_out is not an acceptable image format"); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $image = new GD::SecurityImage ( |
59
|
|
|
|
|
|
|
width => $opt->{width}, |
60
|
|
|
|
|
|
|
height => $opt->{height}, |
61
|
|
|
|
|
|
|
lines => $opt->{lines}, |
62
|
|
|
|
|
|
|
bgcolor => $opt->{bgcolor}, |
63
|
|
|
|
|
|
|
ptsize => $opt->{ptsize}, |
64
|
|
|
|
|
|
|
rndmax => $opt->{rndmax}, # TODO change to at least 4 for release |
65
|
|
|
|
|
|
|
send_ctobg => 0, |
66
|
|
|
|
|
|
|
font => $opt->{font}, |
67
|
|
|
|
|
|
|
# if the font is not present, or illegible by the uid, the words do not show in the image. |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$image->random(); |
71
|
|
|
|
|
|
|
$image->create('ttf','circle','#113377', '#225599'); |
72
|
|
|
|
|
|
|
$image->particle(700,6); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my($image_data, $mime_type, $correct_code) = $image->out(); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
print STDERR "login captcha mime: $mime_type, random number: $correct_code\n" if DEBUG; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
open(OUT,'>',$abs_out) or die; |
81
|
|
|
|
|
|
|
binmode OUT; |
82
|
|
|
|
|
|
|
print OUT $image_data; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return $correct_code; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |