line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BBS::UserInfo::Ptt; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1562
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
15
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
80
|
|
7
|
1
|
|
|
1
|
|
881
|
use Expect; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BBS::UserInfo::Ptt - Get user information of PTT-style BBS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use BBS::UserInfo::Ptt; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# create object |
22
|
|
|
|
|
|
|
my $bot = BBS::UserInfo::Ptt->new( |
23
|
|
|
|
|
|
|
'debug' => 1, |
24
|
|
|
|
|
|
|
'port' => 23, |
25
|
|
|
|
|
|
|
'server' => 'ptt.cc', |
26
|
|
|
|
|
|
|
'telnet' => '/usr/bin/telnet', |
27
|
|
|
|
|
|
|
'timeout' => 10 |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# connect to the server |
31
|
|
|
|
|
|
|
$bot->connect() or die('Unable to connect BBS'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $userdata = $bot->query('username'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# print some data |
36
|
|
|
|
|
|
|
print($userdata->{'logintimes'}); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 FUNCTIONS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new() |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Create a BBS::UserInfo::Ptt object, there are some parameters that you |
43
|
|
|
|
|
|
|
can define: |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
server => 'ptt.cc' # Necessary, server name |
46
|
|
|
|
|
|
|
port => 23 # Optional, server port |
47
|
|
|
|
|
|
|
telnet => 'telnet' # Optional, telnet program |
48
|
|
|
|
|
|
|
timeout => 10 # Optional, Expect timeout |
49
|
|
|
|
|
|
|
debug => 1 # Optional, print debug information |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
|
|
|
|
|
|
my ($class, %params) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my %self = ( |
57
|
|
|
|
|
|
|
'debug' => 0, |
58
|
|
|
|
|
|
|
'password' => '', # incomplete function |
59
|
|
|
|
|
|
|
'port' => 23, |
60
|
|
|
|
|
|
|
'server' => undef, |
61
|
|
|
|
|
|
|
'telnet' => 'telnet', |
62
|
|
|
|
|
|
|
'timeout' => 10, |
63
|
|
|
|
|
|
|
'username' => 'guest' # incomplete function |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
while (my ($k, $v) = each(%params)) { |
67
|
|
|
|
|
|
|
$self{$k} = $v if (exists $self{$k}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return bless(\%self, $class); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 connect() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Connect to the BBS server. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub connect { |
80
|
|
|
|
|
|
|
my $self = shift(); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->{'expect'} = Expect->spawn($self->{'telnet'}, $self->{'server'}, |
83
|
|
|
|
|
|
|
$self->{'port'}); |
84
|
|
|
|
|
|
|
$self->{'expect'}->log_stdout(0); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return undef unless (defined($self->_login($self))); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return $self->{'expect'}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _login { |
92
|
|
|
|
|
|
|
my $self = shift(); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $bot = $self->{'expect'}; |
95
|
|
|
|
|
|
|
my $debug = $self->{'debug'}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
print("Waiting for login\n") if ($debug); |
98
|
|
|
|
|
|
|
$bot->expect($self->{'timeout'}, '-re', '請輸入代號'); |
99
|
|
|
|
|
|
|
return undef if ($bot->error()); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$bot->send($self->{'username'}, "\r\n[D[D"); |
102
|
|
|
|
|
|
|
return 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 query() |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Query user information and return a hash reference with: |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=over 4 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * nickname |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * logintimes |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * posttimes |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * lastlogintime |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item * lastloginip |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub query { |
126
|
|
|
|
|
|
|
my ($self, $user) = @_; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $bot = $self->{'expect'}; |
129
|
|
|
|
|
|
|
my $debug = $self->{'debug'}; |
130
|
|
|
|
|
|
|
my $timeout = $self->{'timeout'}; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$bot->send("[D[Dt\r\nq\r\n", $user, "\r\n"); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my %h; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
print("Waiting for nickname\n") if ($debug); |
137
|
|
|
|
|
|
|
$bot->expect($timeout, '-re', '《ID暱稱》\S+\((.*)\)\s*《'); |
138
|
|
|
|
|
|
|
$h{'nickname'} = ($bot->matchlist)[0]; |
139
|
|
|
|
|
|
|
printf("nickname = %s\n", $h{'nickname'}) if ($debug); |
140
|
|
|
|
|
|
|
return undef if ($bot->error()); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
print("Waiting for logintimes\n") if ($debug); |
143
|
|
|
|
|
|
|
$bot->expect($timeout, '-re', '《上站次數》(\d+)次'); |
144
|
|
|
|
|
|
|
$h{'logintimes'} = ($bot->matchlist)[0]; |
145
|
|
|
|
|
|
|
printf("logintimes = %s\n", $h{'logintimes'}) if ($debug); |
146
|
|
|
|
|
|
|
return undef if ($bot->error()); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
print("Waiting for posttimes\n") if ($debug); |
149
|
|
|
|
|
|
|
$bot->expect($timeout, '-re', '《文章篇數》(\d+)篇'); |
150
|
|
|
|
|
|
|
$h{'posttimes'} = ($bot->matchlist)[0]; |
151
|
|
|
|
|
|
|
printf("posttimes = %s\n", $h{'posttimes'}) if ($debug); |
152
|
|
|
|
|
|
|
return undef if ($bot->error()); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
print("Waiting for lastelogintime\n") if ($debug); |
155
|
|
|
|
|
|
|
$bot->expect($timeout, '-re', '《上次上站》(\S+\s\S+\s\S+)\s'); |
156
|
|
|
|
|
|
|
$h{'lastlogintime'} = ($bot->matchlist)[0]; |
157
|
|
|
|
|
|
|
printf("lastlogintime = %s\n", $h{'lastlogintime'}) if ($debug); |
158
|
|
|
|
|
|
|
return undef if ($bot->error()); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
print("Waiting for lasteloginip\n") if ($debug); |
161
|
|
|
|
|
|
|
$bot->expect($timeout, '-re', '《上次故鄉》(\S+)'); |
162
|
|
|
|
|
|
|
$h{'lastloginip'} = ($bot->matchlist)[0]; |
163
|
|
|
|
|
|
|
printf("lastloginip = %s\n", $h{'lastloginip'}) if ($debug); |
164
|
|
|
|
|
|
|
return undef if ($bot->error()); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
return \%h; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 AUTHOR |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Gea-Suan Lin, C<< >> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Copyright 2006 Gea-Suan Lin, all rights reserved. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
178
|
|
|
|
|
|
|
under the same terms as Perl itself. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; # End of BBS::UserInfo::Ptt |