| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: Auth.pm,v 1.17 2004/01/28 07:05:46 cmdrwalrus Exp $ |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package CGI::Auth; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
773
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
79
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
15
|
use vars qw/$VERSION/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
60
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '3.00'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# This delimiter cannot be a regex special character, unfortunately, since it |
|
13
|
|
|
|
|
|
|
# is used with split. So, for instance, the pipe (|) is not allowed, as well |
|
14
|
|
|
|
|
|
|
# as the dash (-), caret (^), dot (.), etc... |
|
15
|
1
|
|
|
1
|
|
5
|
use constant DELIMITER => ':'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4870
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=pod |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
CGI::Auth - Simple session-based password authentication for CGI applications |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
require CGI::Auth; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $auth = new CGI::Auth({ |
|
28
|
|
|
|
|
|
|
-authdir => 'auth', |
|
29
|
|
|
|
|
|
|
-formaction => "myscript.pl", |
|
30
|
|
|
|
|
|
|
-authfields => [ |
|
31
|
|
|
|
|
|
|
{id => 'user', display => 'User Name', hidden => 0, required => 1}, |
|
32
|
|
|
|
|
|
|
{id => 'pw', display => 'Password', hidden => 1, required => 1}, |
|
33
|
|
|
|
|
|
|
], |
|
34
|
|
|
|
|
|
|
}); |
|
35
|
|
|
|
|
|
|
$auth->check; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
C provides password authentication for web-based applications. It |
|
40
|
|
|
|
|
|
|
uses server-based session files which are referred to by a parameter in all |
|
41
|
|
|
|
|
|
|
links and forms inside the scripts guarded by C. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
At the beginning of each script, a C object should be created and |
|
44
|
|
|
|
|
|
|
its C method called. When this happens, C checks for a |
|
45
|
|
|
|
|
|
|
'session_file' CGI parameter. If that parameter exists and has a matching |
|
46
|
|
|
|
|
|
|
session file in the session directory, C returns, and the rest of the |
|
47
|
|
|
|
|
|
|
script can execute. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
If the session file parameter or the file itself doesn't exist, C |
|
50
|
|
|
|
|
|
|
presents the user with a login form and exits the script. The login form will |
|
51
|
|
|
|
|
|
|
then be submitted to the same script (specified in C<-formaction>). When |
|
52
|
|
|
|
|
|
|
C is called this time, it verifies the user's login information in the |
|
53
|
|
|
|
|
|
|
userfile, creates a session file and provides the session file parameter to the |
|
54
|
|
|
|
|
|
|
rest of the script. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 CREATING AND CONFIGURING |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Before anything can be done with C, an object must be created: |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $auth = new CGI::Auth( \%options ); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 Parameters to C |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The C method creates and configures a C object using |
|
65
|
|
|
|
|
|
|
parameters that are passed via a hash reference that can/should contain the |
|
66
|
|
|
|
|
|
|
following items (optional ones are indicated): |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=over 4 |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item C<-cgi> |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
I<(optional)> |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This parameter provides C with a CGI object reference so that the |
|
75
|
|
|
|
|
|
|
extra overhead of creating another object can be avoided. If your script is |
|
76
|
|
|
|
|
|
|
going to use CGI.pm, it is most efficient to create the CGI object and pass it |
|
77
|
|
|
|
|
|
|
to C, rather than both your script and Auth having to create |
|
78
|
|
|
|
|
|
|
separate objects. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Note: As of version 2.4.3, C can now be used with C. |
|
81
|
|
|
|
|
|
|
This hasn't been tested thoroughly yet, so use caution if you decide to do so. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item C<-admin> |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
I<(optional if C<-formaction> given)> |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This parameter should be used by command-line utilities that perform |
|
88
|
|
|
|
|
|
|
administration of the user database. If Auth is given this parameter, it will |
|
89
|
|
|
|
|
|
|
only allow command-line execution (execution from CGI will be aborted). |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item C<-authdir> |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
I<(required)> |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Directory where Auth will look for its files. In other words, if C<-sessdir>, |
|
96
|
|
|
|
|
|
|
C<-userfile>, C<-logintmpl>, C<-loginheader> or C<-loginfooter> are scalars |
|
97
|
|
|
|
|
|
|
and do not begin with a slash (i.e., are not absolute paths), this directory |
|
98
|
|
|
|
|
|
|
will be prepended to them. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item C<-sessdir> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
I<(optional, default = 'sess')> |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Directory where Auth will store session files. These files should be pruned |
|
105
|
|
|
|
|
|
|
periodically (i.e., nightly or weekly) since a session file will remain here if |
|
106
|
|
|
|
|
|
|
a user does not log out. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item C<-userfile> |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
I<(optional, default = 'user.dat')> |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
File containing definitions of users, including login information and any extra |
|
113
|
|
|
|
|
|
|
parameters. This file will be created, edited and read by C and its |
|
114
|
|
|
|
|
|
|
command-line administration tool. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item C<-logintmpl> |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
I<(optional, excludes C<-loginheader> and C<-loginfooter> if present)> |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Template for use with C. The template can be given in one of |
|
121
|
|
|
|
|
|
|
three ways: |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=over 4 |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item 1 |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
An C object reference, |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item 2 |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
A hash containing parameters for Cnew>, or |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item 3 |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
A filename (then C<-logintmplpath> can be the path parameter). |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The template must contain a form for the user to fill out, and it is |
|
140
|
|
|
|
|
|
|
recommended that the form not contain any elements with names beginning with |
|
141
|
|
|
|
|
|
|
'auth_', since these are reserved for C fields. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
A sample template file (C) is included in the extra subdirectory of |
|
144
|
|
|
|
|
|
|
this package. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
For a list of what should be included in the template, see |
|
147
|
|
|
|
|
|
|
L and L below. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item C<-logintmplpath> |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
I<(optional, default = [])> |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
List of search path(s) for C files (the 'path' option). This |
|
154
|
|
|
|
|
|
|
is used only if C<-logintmpl> is a filename. Otherwise, the path option must |
|
155
|
|
|
|
|
|
|
be passed to Cnew> directly. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item C<-loginheader> |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
I<(optional, default = 'login.head' or a simple default header)> |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Header for login screen. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
NOTE: C<-loginheader> and C<-loginfooter> are ignored if C<-logintmpl> is |
|
164
|
|
|
|
|
|
|
provided. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item C<-loginfooter> |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
I<(optional, default = 'login.foot' or a simple default footer)> |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Footer for login screen. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
NOTE: C<-loginheader> and C<-loginfooter> are ignored if C<-logintmpl> is |
|
173
|
|
|
|
|
|
|
provided. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item C<-formaction> |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
I<(optional if C<-admin> given)> |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
URL of calling script. This is used by the login screen as the form's "action" |
|
180
|
|
|
|
|
|
|
property. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item C<-authfields> |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
I<(required)> |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Array of hashes defining fields in user database. This requires at least one |
|
187
|
|
|
|
|
|
|
field, which must be 'required' and not 'hidden'. Any other fields can be used |
|
188
|
|
|
|
|
|
|
to authenticate the user or to contain information about the user such as |
|
189
|
|
|
|
|
|
|
groups, access levels, etc. Once a user has logged on, all of his fields are |
|
190
|
|
|
|
|
|
|
available through the C method. However, any fields that are marked |
|
191
|
|
|
|
|
|
|
'hidden' will be crypted and not readable by the script. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Each field in the C<-authfields> anonymous array is a hash containing 4 keys: |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
'id' ID of the field. This must be unique across all fields. |
|
196
|
|
|
|
|
|
|
'display' Display string which is presented to the user. |
|
197
|
|
|
|
|
|
|
'hidden' Flag (0 or 1) that determines whether this field is hidden |
|
198
|
|
|
|
|
|
|
on the login screen and encrypted in the user file. |
|
199
|
|
|
|
|
|
|
'required' Flag (0 or 1) indicating whether this field must be given |
|
200
|
|
|
|
|
|
|
for authentication. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Here is an example of a simple username/password scheme, with one extra data |
|
203
|
|
|
|
|
|
|
parameter: |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
-authfields => [ |
|
206
|
|
|
|
|
|
|
{id => 'user', display => 'User Name', hidden => 0, required => 1}, |
|
207
|
|
|
|
|
|
|
{id => 'pw', display => 'Password', hidden => 1, required => 1}, |
|
208
|
|
|
|
|
|
|
{id => 'group', display => 'Group', hidden => 0, required => 0}, |
|
209
|
|
|
|
|
|
|
], |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item C<-timeout> |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
I<(optional, default = 60 * 15, 15 minutes)> |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
The timeout value in seconds after which an unused session file will expire. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item C<-cgiprune> |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
I<(optional, default = false)> |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Whether to allow calls to prune in CGI mode. If your CGI scripts need (or |
|
222
|
|
|
|
|
|
|
want) to delete old session files, this will have to be set to true. I can't |
|
223
|
|
|
|
|
|
|
think of any particular reason not to allow this, but it isn't allowed by |
|
224
|
|
|
|
|
|
|
default. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item C<-md5pwd> |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
I<(optional, default = false)> |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Whether to use an MD5 hash for hidden fields in the user data file. If false, |
|
231
|
|
|
|
|
|
|
the Perl built-in C is used twice (via the C sub below), so |
|
232
|
|
|
|
|
|
|
hidden fields are restricted to 16 characters. If true, MD5 hashes are used, |
|
233
|
|
|
|
|
|
|
and there is no length restriction for hidden fields. |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
If this option is changed, the user data file will have to be recreated using |
|
236
|
|
|
|
|
|
|
MD5 hashes, so it's best to make this decision at the beginning. |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Using MD5 hashes will result in a slight performance hit when logging in. This |
|
239
|
|
|
|
|
|
|
will probably not be noticeable at all. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=back |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 Template Variables |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
These template variables are required. The names of these are case-insensitive |
|
246
|
|
|
|
|
|
|
by default. See L for more information. |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=over 4 |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item C |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
A message to the user, such as "Login failed", "Session expired", etc... |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
NOTE: This variable might be left blank when the form is created. So don't |
|
255
|
|
|
|
|
|
|
depend on it having a value. |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=item C |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
The 'action' property of the form that submits the authentication information. |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item C |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
The 'name' property of the submit button on the form. The tag for the button |
|
264
|
|
|
|
|
|
|
should look something like this: |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
The 'value' property of the submit button can be anything. |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=back |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head2 Template Loops |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
These loops must exist in the template. The names of these are case-insensitive |
|
275
|
|
|
|
|
|
|
by default. See L for more information. |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=over 4 |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=item C |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Provides variables for each required Auth field. These are the fields which |
|
282
|
|
|
|
|
|
|
will be filled in by the user when logging in. The following variables are |
|
283
|
|
|
|
|
|
|
provided: |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=over 4 |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=item C |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
The display name of the field, e.g., "User Name" or "Password". |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item C |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
The 'name' property of the text input for the field. |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item C |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
The type, 'text' or 'password', of the input, depending on whether this |
|
298
|
|
|
|
|
|
|
field is hidden or not. |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=back |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=back |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=head1 PUBLIC METHODS |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
There are two groups of public methods in CGI::Auth. The CGI-mode methods are |
|
307
|
|
|
|
|
|
|
called from CGI scripts for the purposes of authenticating a user and managing |
|
308
|
|
|
|
|
|
|
sessions. The command-line methods are used only in command-line scripts, |
|
309
|
|
|
|
|
|
|
such as the authman.pl sample userbase manager script. The latter methods |
|
310
|
|
|
|
|
|
|
will abort execution if they are run in a CGI environment. |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head2 Initialization Methods |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
These are used for creating a C object. |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=over 4 |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=item C |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
Constructor. It accepts as a parameter a hash reference holding named |
|
321
|
|
|
|
|
|
|
options. For a list and descriptions of these options, see |
|
322
|
|
|
|
|
|
|
L>. |
|
323
|
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=cut |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
sub new |
|
327
|
|
|
|
|
|
|
{ |
|
328
|
1
|
|
|
1
|
1
|
22
|
my $proto = shift; |
|
329
|
1
|
|
33
|
|
|
9
|
my $class = ref($proto) || $proto; |
|
330
|
1
|
|
|
|
|
3
|
my $self = {}; |
|
331
|
1
|
|
|
|
|
3
|
bless $self, $class; |
|
332
|
|
|
|
|
|
|
|
|
333
|
1
|
50
|
|
|
|
7
|
$self->init(@_) or return undef; |
|
334
|
|
|
|
|
|
|
|
|
335
|
1
|
|
|
|
|
6
|
return $self; |
|
336
|
|
|
|
|
|
|
} |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=pod |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=item C |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
Performs processing of options passed to C. This should not be called |
|
343
|
|
|
|
|
|
|
directly. |
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=cut |
|
346
|
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
# Called by new--all parameters to new are passed off to init for processing. |
|
348
|
|
|
|
|
|
|
sub init |
|
349
|
|
|
|
|
|
|
{ |
|
350
|
1
|
|
|
1
|
1
|
4
|
my ($self, $param) = (shift, shift); |
|
351
|
|
|
|
|
|
|
|
|
352
|
1
|
50
|
|
|
|
7
|
return 0 unless (UNIVERSAL::isa($param, 'HASH')); |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
# Parameters in an anonymous hash. |
|
355
|
|
|
|
|
|
|
# All config options are passed here... no config file! |
|
356
|
1
|
|
|
|
|
8
|
$self->{cgi} = $param->{-cgi}; |
|
357
|
1
|
|
|
|
|
4
|
$self->{sessfile} = $param->{-sessfile}; |
|
358
|
1
|
50
|
|
|
|
6
|
$self->{admin} = $param->{-admin} ? 1 : 0; |
|
359
|
|
|
|
|
|
|
|
|
360
|
1
|
|
|
|
|
3
|
$self->{authdir} = $param->{-authdir}; |
|
361
|
1
|
|
|
|
|
3
|
$self->{sessdir} = $param->{-sessdir}; |
|
362
|
1
|
|
|
|
|
3
|
for ($self->{authdir}, $self->{sessdir}) |
|
363
|
|
|
|
|
|
|
{ |
|
364
|
2
|
100
|
|
|
|
12
|
s|/+$|| if ($_); # Delete trailing slashes. |
|
365
|
|
|
|
|
|
|
} |
|
366
|
|
|
|
|
|
|
|
|
367
|
1
|
|
|
|
|
3
|
$self->{userfile} = $param->{-userfile}; |
|
368
|
1
|
50
|
|
|
|
4
|
if ($self->{logintmpl} = $param->{-logintmpl}) # Either an HTML::Template template, |
|
369
|
|
|
|
|
|
|
{ |
|
370
|
0
|
|
0
|
|
|
0
|
$self->{logintmplpath} = $param->{-logintmplpath} || []; |
|
371
|
|
|
|
|
|
|
} |
|
372
|
|
|
|
|
|
|
else |
|
373
|
|
|
|
|
|
|
{ |
|
374
|
1
|
|
|
|
|
4
|
$self->{loginheader} = $param->{-loginheader}; # or a header and footer. |
|
375
|
1
|
|
|
|
|
3
|
$self->{loginfooter} = $param->{-loginfooter}; |
|
376
|
|
|
|
|
|
|
} |
|
377
|
1
|
|
|
|
|
2
|
$self->{formaction} = $param->{-formaction}; |
|
378
|
1
|
|
|
|
|
3
|
$self->{authfields} = $param->{-authfields}; |
|
379
|
1
|
|
|
|
|
2
|
$self->{timeout} = $param->{-timeout}; |
|
380
|
1
|
50
|
|
|
|
5
|
$self->{cgiprune} = $param->{-cgiprune} ? 1 : 0; |
|
381
|
1
|
|
|
|
|
3
|
$self->{validchars} = $param->{-validchars}; |
|
382
|
1
|
50
|
|
|
|
4
|
$self->{md5pwd} = $param->{-md5pwd} ? 1 : 0; |
|
383
|
|
|
|
|
|
|
|
|
384
|
1
|
50
|
|
|
|
7
|
if ($self->{admin}) |
|
385
|
|
|
|
|
|
|
{ |
|
386
|
0
|
|
|
|
|
0
|
&DenyCGI; |
|
387
|
|
|
|
|
|
|
} |
|
388
|
|
|
|
|
|
|
else |
|
389
|
|
|
|
|
|
|
{ |
|
390
|
1
|
50
|
33
|
|
|
10
|
unless ( UNIVERSAL::isa( $self->{cgi}, 'CGI' ) || UNIVERSAL::isa( $self->{cgi}, 'CGI::Simple' ) ) |
|
391
|
|
|
|
|
|
|
{ |
|
392
|
|
|
|
|
|
|
# Default to CGI if none is given. |
|
393
|
1
|
|
|
|
|
3
|
eval { require CGI; }; |
|
|
1
|
|
|
|
|
1155923
|
|
|
394
|
1
|
50
|
|
|
|
31383
|
if ( $@ ) |
|
395
|
|
|
|
|
|
|
{ |
|
396
|
|
|
|
|
|
|
# If CGI is not available, try CGI::Simple. |
|
397
|
0
|
|
|
|
|
0
|
eval { require CGI::Simple; }; |
|
|
0
|
|
|
|
|
0
|
|
|
398
|
0
|
0
|
|
|
|
0
|
if ( $@ ) |
|
399
|
|
|
|
|
|
|
{ |
|
400
|
|
|
|
|
|
|
# If neither is available, there's gonna be trouble! |
|
401
|
0
|
|
|
|
|
0
|
croak "CGI::Auth needs CGI or CGI::Simple, but neither is available"; |
|
402
|
|
|
|
|
|
|
} |
|
403
|
|
|
|
|
|
|
else |
|
404
|
|
|
|
|
|
|
{ |
|
405
|
|
|
|
|
|
|
# Got CGI::Simple, so create an object of it. |
|
406
|
0
|
|
|
|
|
0
|
$self->{cgi} = CGI::Simple->new; |
|
407
|
|
|
|
|
|
|
} |
|
408
|
|
|
|
|
|
|
} |
|
409
|
|
|
|
|
|
|
else |
|
410
|
|
|
|
|
|
|
{ |
|
411
|
|
|
|
|
|
|
# Got CGI, so create an object of it. |
|
412
|
1
|
|
|
|
|
9
|
$self->{cgi} = new CGI; |
|
413
|
|
|
|
|
|
|
} |
|
414
|
|
|
|
|
|
|
} |
|
415
|
|
|
|
|
|
|
} |
|
416
|
|
|
|
|
|
|
|
|
417
|
1
|
50
|
33
|
|
|
7286
|
unless ($self->{authdir} && ($self->{admin} || $self->{formaction}) && $self->{authfields}) |
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
418
|
|
|
|
|
|
|
{ |
|
419
|
0
|
|
|
|
|
0
|
&carp("Auth::init - Missing required configuration data"); |
|
420
|
0
|
|
|
|
|
0
|
return 0; |
|
421
|
|
|
|
|
|
|
} |
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
# Set defaults for optional config entries if not given: |
|
424
|
1
|
50
|
|
|
|
6
|
unless ($self->{logintmpl}) |
|
425
|
|
|
|
|
|
|
{ |
|
426
|
1
|
50
|
|
|
|
6
|
$self->{loginheader} = 'login.head' unless ($self->{loginheader}); |
|
427
|
1
|
50
|
|
|
|
5
|
$self->{loginfooter} = 'login.foot' unless ($self->{loginfooter}); |
|
428
|
|
|
|
|
|
|
} |
|
429
|
1
|
50
|
|
|
|
5
|
$self->{sessdir} = 'sess' unless ($self->{sessdir}); |
|
430
|
1
|
50
|
|
|
|
174
|
$self->{userfile} = 'user.dat' unless ($self->{userfile}); |
|
431
|
1
|
50
|
|
|
|
5
|
$self->{timeout} = 60 * 15 unless ($self->{timeout}); |
|
432
|
1
|
|
50
|
|
|
8
|
$self->{validchars} ||= '\w\d -_.'; |
|
433
|
1
|
50
|
|
|
|
5
|
if ( -1 != index( $self->{validchars}, DELIMITER ) ) |
|
434
|
|
|
|
|
|
|
{ |
|
435
|
0
|
|
|
|
|
0
|
&carp( "Auth::init - Delimiter character '" . DELIMITER . "' cannot be included in validchars" ); |
|
436
|
0
|
|
|
|
|
0
|
return 0; |
|
437
|
|
|
|
|
|
|
} |
|
438
|
|
|
|
|
|
|
|
|
439
|
1
|
|
|
|
|
3
|
for (@{$self}{qw/sessdir userfile logintmpl loginheader loginfooter/}) |
|
|
1
|
|
|
|
|
4
|
|
|
440
|
|
|
|
|
|
|
{ |
|
441
|
5
|
50
|
66
|
|
|
33
|
if ( $_ and not ref and not m{^/} ) |
|
|
|
|
66
|
|
|
|
|
|
442
|
|
|
|
|
|
|
{ |
|
443
|
4
|
|
|
|
|
11
|
$_ = $self->{authdir} . '/' . $_; |
|
444
|
|
|
|
|
|
|
} |
|
445
|
|
|
|
|
|
|
} |
|
446
|
|
|
|
|
|
|
|
|
447
|
1
|
50
|
|
|
|
38
|
unless (-f $self->{userfile}) |
|
448
|
|
|
|
|
|
|
{ |
|
449
|
0
|
|
|
|
|
0
|
&carp("Auth::init - User data file doesn't exist"); |
|
450
|
0
|
|
|
|
|
0
|
return 0; |
|
451
|
|
|
|
|
|
|
} |
|
452
|
|
|
|
|
|
|
|
|
453
|
1
|
|
|
|
|
2
|
for (@{$self->{authfields}}) |
|
|
1
|
|
|
|
|
4
|
|
|
454
|
|
|
|
|
|
|
{ |
|
455
|
2
|
50
|
|
|
|
11
|
if ($_->{id} eq 'sess_file') |
|
456
|
|
|
|
|
|
|
{ |
|
457
|
0
|
|
|
|
|
0
|
&carp("Auth::init - id 'sess_file' is reserved"); |
|
458
|
0
|
|
|
|
|
0
|
return 0; |
|
459
|
|
|
|
|
|
|
} |
|
460
|
|
|
|
|
|
|
} |
|
461
|
|
|
|
|
|
|
|
|
462
|
1
|
50
|
33
|
|
|
13
|
unless ($self->{authfields}->[0]->{required} and not $self->{authfields}->[0]->{hidden}) |
|
463
|
|
|
|
|
|
|
{ |
|
464
|
0
|
|
|
|
|
0
|
&carp("Auth::init - First auth field must be required and not hidden--rethink your auth configuration"); |
|
465
|
0
|
|
|
|
|
0
|
return 0; |
|
466
|
|
|
|
|
|
|
} |
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
# Create authdata hash. |
|
469
|
1
|
|
|
|
|
5
|
$self->{authdata} = {}; |
|
470
|
|
|
|
|
|
|
|
|
471
|
1
|
|
|
|
|
6
|
return 1; |
|
472
|
|
|
|
|
|
|
} |
|
473
|
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
=pod |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
=back |
|
477
|
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
=head2 CGI-mode Methods |
|
479
|
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
These methods are called from CGI scripts. |
|
481
|
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
=over 4 |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
=item C |
|
485
|
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
Ensures authentication. If the session file is not present or has expired, a |
|
487
|
|
|
|
|
|
|
login form is presented to the user. A call to this method should occur in |
|
488
|
|
|
|
|
|
|
every script that must be secured, before the script prints B to the |
|
489
|
|
|
|
|
|
|
browser. |
|
490
|
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
=cut |
|
492
|
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
sub check |
|
494
|
|
|
|
|
|
|
{ |
|
495
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
496
|
|
|
|
|
|
|
|
|
497
|
0
|
|
0
|
|
|
|
my $session_file = $self->{sessfile} || $self->{cgi}->param('auth_sessfile'); |
|
498
|
|
|
|
|
|
|
|
|
499
|
0
|
0
|
|
|
|
|
if ($session_file) |
|
|
|
0
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
{ |
|
501
|
|
|
|
|
|
|
# Untaint. |
|
502
|
0
|
|
|
|
|
|
$session_file =~ s/[^0-9A-Za-z\._]+//g; |
|
503
|
0
|
|
|
|
|
|
$session_file =~ m/([0-9A-Za-z\._]+)/; |
|
504
|
0
|
|
|
|
|
|
$self->{sess_file} = $session_file = $1; |
|
505
|
|
|
|
|
|
|
|
|
506
|
0
|
|
|
|
|
|
my ($field0) = $self->OpenSessionFile; |
|
507
|
0
|
0
|
|
|
|
|
if ($field0) |
|
|
|
0
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
{ |
|
509
|
0
|
|
|
|
|
|
return $self->setdata($self->GetUserData($field0)); |
|
510
|
|
|
|
|
|
|
} |
|
511
|
|
|
|
|
|
|
elsif (defined $field0) |
|
512
|
|
|
|
|
|
|
{ |
|
513
|
0
|
|
|
|
|
|
$self->PrintLoginForm("Your session has expired. Please log in again."); |
|
514
|
0
|
|
|
|
|
|
exit(0); |
|
515
|
|
|
|
|
|
|
} |
|
516
|
|
|
|
|
|
|
else |
|
517
|
|
|
|
|
|
|
{ |
|
518
|
0
|
|
|
|
|
|
$self->PrintLoginForm("Could not open session file. Please log in again."); |
|
519
|
0
|
|
|
|
|
|
&carp("Auth::check - Could not open session file"); |
|
520
|
0
|
|
|
|
|
|
exit(0); |
|
521
|
|
|
|
|
|
|
} |
|
522
|
|
|
|
|
|
|
} |
|
523
|
|
|
|
|
|
|
elsif (defined $self->{cgi}->param('auth_submit')) |
|
524
|
|
|
|
|
|
|
{ |
|
525
|
0
|
|
|
|
|
|
my $authfield0 = $self->{authfields}->[0]; |
|
526
|
0
|
|
|
|
|
|
my $field0 = $self->{cgi}->param( 'auth_' . $authfield0->{id} ); |
|
527
|
0
|
|
|
|
|
|
my @userdata = $self->GetUserData( $field0 ); |
|
528
|
|
|
|
|
|
|
# Make sure GetUserData found the user. |
|
529
|
0
|
0
|
|
|
|
|
if ( not @userdata ) |
|
530
|
|
|
|
|
|
|
{ |
|
531
|
0
|
|
|
|
|
|
$self->PrintLoginForm( "Authentication failed! Check login information and try again." ); |
|
532
|
0
|
|
|
|
|
|
&carp( "Auth::check - Invalid '" . $authfield0->{display} . "' field" ); |
|
533
|
0
|
|
|
|
|
|
exit( 0 ); |
|
534
|
|
|
|
|
|
|
} |
|
535
|
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
# Verify required fields in form data with those in @userdata. |
|
537
|
0
|
|
|
|
|
|
eval { |
|
538
|
0
|
|
|
|
|
|
for my $idx ( 1 .. @{ $self->{authfields} } - 1 ) |
|
|
0
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
{ |
|
540
|
0
|
|
|
|
|
|
my $authfield = $self->{authfields}->[$idx]; |
|
541
|
0
|
0
|
|
|
|
|
if ( $authfield->{required} ) |
|
542
|
|
|
|
|
|
|
{ |
|
543
|
0
|
|
|
|
|
|
my $formvalue = $self->{cgi}->param( 'auth_' . $authfield->{id} ); |
|
544
|
0
|
0
|
|
|
|
|
if ( $authfield->{hidden} ) |
|
545
|
|
|
|
|
|
|
{ |
|
546
|
|
|
|
|
|
|
# Check against crypted userdata. |
|
547
|
0
|
0
|
|
|
|
|
if ( $self->{md5pwd} ) |
|
548
|
|
|
|
|
|
|
{ |
|
549
|
|
|
|
|
|
|
# MD5 hash. |
|
550
|
0
|
0
|
|
|
|
|
if ( MD5Crypt( $formvalue ) ne $userdata[$idx] ) |
|
551
|
|
|
|
|
|
|
{ |
|
552
|
0
|
|
|
|
|
|
die "MD5 mismatch on '" . $authfield->{display} . "' field"; |
|
553
|
|
|
|
|
|
|
} |
|
554
|
|
|
|
|
|
|
} |
|
555
|
|
|
|
|
|
|
else |
|
556
|
|
|
|
|
|
|
{ |
|
557
|
|
|
|
|
|
|
# Double crypt(). |
|
558
|
0
|
0
|
|
|
|
|
if ( DoubleCrypt( $formvalue, $userdata[$idx] ) ne $userdata[$idx] ) |
|
559
|
|
|
|
|
|
|
{ |
|
560
|
0
|
|
|
|
|
|
die "crypt() mismatch on '" . $authfield->{display} . "' field"; |
|
561
|
|
|
|
|
|
|
} |
|
562
|
|
|
|
|
|
|
} |
|
563
|
|
|
|
|
|
|
} |
|
564
|
|
|
|
|
|
|
else |
|
565
|
|
|
|
|
|
|
{ |
|
566
|
|
|
|
|
|
|
# Check against uncrypted userdata. |
|
567
|
0
|
0
|
|
|
|
|
if ( $userdata[$idx] ne $formvalue ) |
|
568
|
|
|
|
|
|
|
{ |
|
569
|
0
|
|
|
|
|
|
die "Mismatch on '" . $authfield->{display} . "' field"; |
|
570
|
|
|
|
|
|
|
} |
|
571
|
|
|
|
|
|
|
} |
|
572
|
|
|
|
|
|
|
} |
|
573
|
|
|
|
|
|
|
} |
|
574
|
|
|
|
|
|
|
}; |
|
575
|
0
|
0
|
|
|
|
|
if ( $@ ) |
|
576
|
|
|
|
|
|
|
{ |
|
577
|
0
|
|
|
|
|
|
$self->PrintLoginForm( "Authentication failed! Check login information and try again." ); |
|
578
|
0
|
|
|
|
|
|
&carp( "Auth::check - $@" ); |
|
579
|
0
|
|
|
|
|
|
exit( 0 ); |
|
580
|
|
|
|
|
|
|
} |
|
581
|
|
|
|
|
|
|
else |
|
582
|
|
|
|
|
|
|
{ |
|
583
|
0
|
0
|
|
|
|
|
if ( $self->{sess_file} = $self->CreateSessionFile( $field0 ) ) |
|
584
|
|
|
|
|
|
|
{ |
|
585
|
0
|
|
|
|
|
|
return $self->setdata( @userdata ); |
|
586
|
|
|
|
|
|
|
} |
|
587
|
|
|
|
|
|
|
else |
|
588
|
|
|
|
|
|
|
{ |
|
589
|
0
|
|
|
|
|
|
$self->PrintLoginForm( "A session file could not be created. You may not be able to log in at this time." ); |
|
590
|
0
|
|
|
|
|
|
&carp( "Auth::check - Could not create session file" ); |
|
591
|
0
|
|
|
|
|
|
exit( 0 ); |
|
592
|
|
|
|
|
|
|
} |
|
593
|
|
|
|
|
|
|
} |
|
594
|
|
|
|
|
|
|
} |
|
595
|
|
|
|
|
|
|
else |
|
596
|
|
|
|
|
|
|
{ |
|
597
|
0
|
|
|
|
|
|
$self->PrintLoginForm; |
|
598
|
0
|
|
|
|
|
|
exit(0); |
|
599
|
|
|
|
|
|
|
} |
|
600
|
|
|
|
|
|
|
} |
|
601
|
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=pod |
|
603
|
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
=item C |
|
605
|
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
Deletes the session file so that the user must log in again to gain access. |
|
607
|
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
Returns 1 if session file deleted successfully, 0 if an error occurred ($! will |
|
609
|
|
|
|
|
|
|
contain the error), or -1 if the session file did not exist. |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
=cut |
|
612
|
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
sub endsession |
|
614
|
|
|
|
|
|
|
{ |
|
615
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
616
|
|
|
|
|
|
|
|
|
617
|
0
|
0
|
|
|
|
|
if (-f $self->{sessdir} . "/" . $self->{sess_file}) |
|
618
|
|
|
|
|
|
|
{ |
|
619
|
0
|
|
|
|
|
|
return unlink $self->{sessdir} . "/" . $self->{sess_file}; |
|
620
|
|
|
|
|
|
|
} |
|
621
|
|
|
|
|
|
|
else |
|
622
|
|
|
|
|
|
|
{ |
|
623
|
0
|
|
|
|
|
|
return -1; |
|
624
|
|
|
|
|
|
|
} |
|
625
|
|
|
|
|
|
|
} |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
=pod |
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
=item C |
|
630
|
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
Sets auth data fields. |
|
632
|
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
=cut |
|
634
|
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
sub setdata |
|
636
|
|
|
|
|
|
|
{ |
|
637
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
638
|
0
|
|
|
|
|
|
my @data = @_; |
|
639
|
|
|
|
|
|
|
|
|
640
|
0
|
0
|
|
|
|
|
return 0 if (@data != @{$self->{authfields}}); |
|
|
0
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
|
|
642
|
0
|
|
|
|
|
|
for (my $idx = 0; $idx < @data; ++$idx) |
|
643
|
|
|
|
|
|
|
{ |
|
644
|
0
|
0
|
|
|
|
|
next if ($self->{authfields}->[$idx]->{hidden}); |
|
645
|
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
# Store non-hidden data in authdata for program to access. |
|
647
|
0
|
|
|
|
|
|
$self->{authdata}->{$self->{authfields}->[$idx]->{id}} = $data[$idx]; |
|
648
|
|
|
|
|
|
|
} |
|
649
|
|
|
|
|
|
|
|
|
650
|
0
|
|
|
|
|
|
return 1; |
|
651
|
|
|
|
|
|
|
} |
|
652
|
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
=pod |
|
654
|
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
=item C |
|
656
|
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
Returns a given data field. The field's ID is passed as the parameter, and the |
|
658
|
|
|
|
|
|
|
data is returned. The special field 'sess_file' returns the name of the |
|
659
|
|
|
|
|
|
|
current session file in the C<-sessdir> directory. |
|
660
|
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
=cut |
|
662
|
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
sub data |
|
664
|
|
|
|
|
|
|
{ |
|
665
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
666
|
0
|
|
|
|
|
|
my $key = shift; |
|
667
|
|
|
|
|
|
|
|
|
668
|
0
|
0
|
|
|
|
|
if ($key eq 'sess_file') |
|
669
|
|
|
|
|
|
|
{ |
|
670
|
0
|
|
|
|
|
|
return $self->{sess_file}; |
|
671
|
|
|
|
|
|
|
} |
|
672
|
|
|
|
|
|
|
|
|
673
|
0
|
|
|
|
|
|
return $self->{authdata}->{$key}; |
|
674
|
|
|
|
|
|
|
} |
|
675
|
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
=pod |
|
677
|
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
=item C |
|
679
|
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
Returns the name of the session file parameter (i.e., 'auth_sessfile'). |
|
681
|
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
=cut |
|
683
|
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
sub sfparam_name |
|
685
|
|
|
|
|
|
|
{ |
|
686
|
0
|
|
|
0
|
1
|
|
'auth_sessfile'; |
|
687
|
|
|
|
|
|
|
} |
|
688
|
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
=pod |
|
690
|
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
=item C |
|
692
|
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
Returns the value of the session file parameter (i.e., the name of the session file). |
|
694
|
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
=cut |
|
696
|
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
sub sfparam_value |
|
698
|
|
|
|
|
|
|
{ |
|
699
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
700
|
|
|
|
|
|
|
|
|
701
|
0
|
|
|
|
|
|
$self->data('sess_file'); |
|
702
|
|
|
|
|
|
|
} |
|
703
|
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
=pod |
|
705
|
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
=item C B<(deprecated)> |
|
707
|
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
B<(deprecated)> - Use of C and C is discouraged in favour |
|
709
|
|
|
|
|
|
|
of C and C because the latter provide much more |
|
710
|
|
|
|
|
|
|
flexibility. For example, they allow you to create elements that are |
|
711
|
|
|
|
|
|
|
XHTML-compliant, whereas the data returned from C is only valid for |
|
712
|
|
|
|
|
|
|
HTML 4. |
|
713
|
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
Returns the session file parameter as a hidden input field suitable for |
|
715
|
|
|
|
|
|
|
inserting in a EFORME, e.g.: |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
'' |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
=cut |
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
sub formfield |
|
722
|
|
|
|
|
|
|
{ |
|
723
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
724
|
|
|
|
|
|
|
|
|
725
|
0
|
|
|
|
|
|
my $name = $self->sfparam_name; |
|
726
|
0
|
|
|
|
|
|
my $value = $self->sfparam_value; |
|
727
|
|
|
|
|
|
|
|
|
728
|
0
|
|
|
|
|
|
return qq(); |
|
729
|
|
|
|
|
|
|
} |
|
730
|
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
=pod |
|
732
|
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
=item C |
|
734
|
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
B<(deprecated)> - Use of C and C is discouraged in favour |
|
736
|
|
|
|
|
|
|
of C and C because the latter provide much more |
|
737
|
|
|
|
|
|
|
flexibility. For example, they allow you to create elements that are |
|
738
|
|
|
|
|
|
|
XHTML-compliant, whereas the data returned from C is only valid for |
|
739
|
|
|
|
|
|
|
HTML 4. |
|
740
|
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
Returns the session file parameter as a field suitable for tacking onto the end |
|
742
|
|
|
|
|
|
|
of an URL (such as in a link), e.g.: |
|
743
|
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
'auth_sessfile=DBEEL87CXV7H'. |
|
745
|
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
=cut |
|
747
|
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
sub urlfield |
|
749
|
|
|
|
|
|
|
{ |
|
750
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
751
|
|
|
|
|
|
|
|
|
752
|
0
|
|
|
|
|
|
my $name = $self->sfparam_name; |
|
753
|
0
|
|
|
|
|
|
my $value = $self->sfparam_value; |
|
754
|
|
|
|
|
|
|
|
|
755
|
0
|
|
|
|
|
|
return qq($name=$value); |
|
756
|
|
|
|
|
|
|
} |
|
757
|
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
=pod |
|
759
|
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
=back |
|
761
|
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
=head2 Command-line Methods |
|
763
|
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
These methods are used for user maintenance. They cannot be run under a CGI |
|
765
|
|
|
|
|
|
|
environment. Use them only in command-line programs as an administrator (or as |
|
766
|
|
|
|
|
|
|
a user with write access to the user data file). |
|
767
|
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
=over 4 |
|
769
|
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
=item C |
|
771
|
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
The parameters are an ordered list of data values for the @authfields. For |
|
773
|
|
|
|
|
|
|
example: |
|
774
|
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
$auth->adduser('KAM', 'smokey'); # Branchname, Password |
|
776
|
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
=cut |
|
778
|
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
sub adduser |
|
780
|
|
|
|
|
|
|
{ |
|
781
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
782
|
|
|
|
|
|
|
|
|
783
|
0
|
|
|
|
|
|
&DenyCGI; |
|
784
|
|
|
|
|
|
|
|
|
785
|
0
|
|
|
|
|
|
my @userdata = @_; |
|
786
|
0
|
0
|
|
|
|
|
&croak("Bad user data") if (@userdata != @{$self->{authfields}}); |
|
|
0
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
# Append user to user file. |
|
789
|
0
|
0
|
|
|
|
|
open USER, ">> " . $self->{userfile} |
|
790
|
|
|
|
|
|
|
or return 0; |
|
791
|
0
|
|
|
|
|
|
for (my $idx = 0; $idx < @userdata; ++$idx) |
|
792
|
|
|
|
|
|
|
{ |
|
793
|
0
|
|
|
|
|
|
my $authfield = $self->{authfields}->[$idx]; |
|
794
|
0
|
0
|
|
|
|
|
if ( $authfield->{hidden} ) |
|
795
|
|
|
|
|
|
|
{ |
|
796
|
0
|
0
|
|
|
|
|
if ( $self->{md5pwd} ) |
|
797
|
|
|
|
|
|
|
{ |
|
798
|
0
|
|
|
|
|
|
$userdata[$idx] = MD5Crypt( $userdata[$idx] ); |
|
799
|
|
|
|
|
|
|
} |
|
800
|
|
|
|
|
|
|
else |
|
801
|
|
|
|
|
|
|
{ |
|
802
|
0
|
0
|
|
|
|
|
if ( length $userdata[$idx] > 16 ) |
|
803
|
|
|
|
|
|
|
{ |
|
804
|
0
|
|
|
|
|
|
&croak( "Hidden field '" . $authfield->{display} . "' cannot have length greater than 16 characters when using crypt" ); |
|
805
|
|
|
|
|
|
|
} |
|
806
|
|
|
|
|
|
|
# Store encrypted. |
|
807
|
0
|
|
|
|
|
|
$userdata[$idx] = DoubleCrypt( $userdata[$idx], join '', ('.', '_', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64] ); |
|
808
|
|
|
|
|
|
|
} |
|
809
|
|
|
|
|
|
|
} |
|
810
|
|
|
|
|
|
|
} |
|
811
|
0
|
|
|
|
|
|
print USER join( DELIMITER, @userdata ), "\n"; |
|
812
|
0
|
|
|
|
|
|
close USER; |
|
813
|
|
|
|
|
|
|
} |
|
814
|
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
=pod |
|
816
|
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
=item C |
|
818
|
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
Prints a list of users in the user file. |
|
820
|
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
=cut |
|
822
|
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
sub listusers |
|
824
|
|
|
|
|
|
|
{ |
|
825
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
826
|
|
|
|
|
|
|
|
|
827
|
0
|
|
|
|
|
|
&DenyCGI; |
|
828
|
|
|
|
|
|
|
|
|
829
|
0
|
0
|
|
|
|
|
open USER, "< " . $self->{userfile} or return; |
|
830
|
0
|
|
|
|
|
|
while () |
|
831
|
|
|
|
|
|
|
{ |
|
832
|
0
|
|
|
|
|
|
my ($br) = split( DELIMITER, $_, 2 ); |
|
833
|
0
|
|
|
|
|
|
print "$br\n"; |
|
834
|
|
|
|
|
|
|
} |
|
835
|
0
|
|
|
|
|
|
close USER; |
|
836
|
|
|
|
|
|
|
} |
|
837
|
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
=pod |
|
839
|
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
=item C |
|
841
|
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
Prints details for one user. The parameter is the user's 'field 0' value. |
|
843
|
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
=cut |
|
845
|
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
sub viewuser |
|
847
|
|
|
|
|
|
|
{ |
|
848
|
0
|
|
|
0
|
1
|
|
my ($self, $field0) = @_; |
|
849
|
|
|
|
|
|
|
|
|
850
|
0
|
|
|
|
|
|
&DenyCGI; |
|
851
|
|
|
|
|
|
|
|
|
852
|
0
|
|
|
|
|
|
my @userdata = $self->GetUserData($field0); |
|
853
|
|
|
|
|
|
|
|
|
854
|
0
|
0
|
|
|
|
|
if (@userdata == 0) |
|
855
|
|
|
|
|
|
|
{ |
|
856
|
0
|
|
|
|
|
|
print "$field0 does not exist.\n"; |
|
857
|
0
|
|
|
|
|
|
return 0; |
|
858
|
|
|
|
|
|
|
} |
|
859
|
0
|
0
|
|
|
|
|
&croak("Bad user data for $field0") if (@userdata != @{$self->{authfields}}); |
|
|
0
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
|
|
861
|
0
|
|
|
|
|
|
for (my $idx = 0; $idx < @userdata; ++$idx) |
|
862
|
|
|
|
|
|
|
{ |
|
863
|
0
|
|
|
|
|
|
my $msg = $self->{authfields}->[$idx]->{display}; |
|
864
|
0
|
0
|
|
|
|
|
$msg .= " (required)" if ($self->{authfields}->[$idx]->{required}); |
|
865
|
0
|
0
|
|
|
|
|
$msg .= " (hidden)" if ($self->{authfields}->[$idx]->{hidden}); |
|
866
|
0
|
|
|
|
|
|
$msg .= ": " . $userdata[$idx] . "\n"; |
|
867
|
|
|
|
|
|
|
|
|
868
|
0
|
|
|
|
|
|
print $msg; |
|
869
|
|
|
|
|
|
|
} |
|
870
|
|
|
|
|
|
|
} |
|
871
|
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
=pod |
|
873
|
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
=item C |
|
875
|
|
|
|
|
|
|
|
|
876
|
|
|
|
|
|
|
Deletes a user. The parameter is the user's 'field 0' value. |
|
877
|
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
=cut |
|
879
|
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
sub deluser |
|
881
|
|
|
|
|
|
|
{ |
|
882
|
0
|
|
|
0
|
1
|
|
my ($self, $field0) = @_; |
|
883
|
|
|
|
|
|
|
|
|
884
|
0
|
|
|
|
|
|
&DenyCGI; |
|
885
|
|
|
|
|
|
|
|
|
886
|
0
|
|
|
|
|
|
$self->viewuser($field0); |
|
887
|
|
|
|
|
|
|
|
|
888
|
0
|
|
|
|
|
|
print "\nDelete this user? "; |
|
889
|
0
|
|
|
|
|
|
my $resp = ; |
|
890
|
|
|
|
|
|
|
|
|
891
|
|
|
|
|
|
|
# If the response begins with a 'y' (or 'Y'), ie. 'yes' or 'y' or 'you better not!'... |
|
892
|
0
|
0
|
|
|
|
|
if ( $resp =~ /^[yY]/ ) |
|
893
|
|
|
|
|
|
|
{ |
|
894
|
0
|
0
|
|
|
|
|
open USER, "< " . $self->{userfile} or &croak("Unable to read userfile: $!"); |
|
895
|
0
|
|
|
|
|
|
my @userfile = ; |
|
896
|
0
|
|
|
|
|
|
close USER; |
|
897
|
|
|
|
|
|
|
|
|
898
|
0
|
0
|
|
|
|
|
open USER, "> " . $self->{userfile} or &croak("Unable to write userfile: $!"); |
|
899
|
0
|
|
|
|
|
|
for (@userfile) |
|
900
|
|
|
|
|
|
|
{ |
|
901
|
0
|
0
|
|
|
|
|
if (!/^$field0\b/i) |
|
902
|
|
|
|
|
|
|
{ |
|
903
|
0
|
|
|
|
|
|
print USER $_; |
|
904
|
|
|
|
|
|
|
} |
|
905
|
|
|
|
|
|
|
} |
|
906
|
0
|
|
|
|
|
|
close USER; |
|
907
|
0
|
|
|
|
|
|
print "\nUser deleted.\n"; |
|
908
|
|
|
|
|
|
|
} |
|
909
|
|
|
|
|
|
|
else |
|
910
|
|
|
|
|
|
|
{ |
|
911
|
0
|
|
|
|
|
|
print "\nUser not deleted.\n"; |
|
912
|
|
|
|
|
|
|
} |
|
913
|
|
|
|
|
|
|
} |
|
914
|
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
=pod |
|
916
|
|
|
|
|
|
|
|
|
917
|
|
|
|
|
|
|
=item C |
|
918
|
|
|
|
|
|
|
|
|
919
|
|
|
|
|
|
|
Prunes the session file directory by deleting session files that have expired. |
|
920
|
|
|
|
|
|
|
This can be called in CGI mode if '-cgiprune' is set to true. |
|
921
|
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
=cut |
|
923
|
|
|
|
|
|
|
|
|
924
|
|
|
|
|
|
|
sub prune |
|
925
|
|
|
|
|
|
|
{ |
|
926
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
927
|
|
|
|
|
|
|
|
|
928
|
0
|
0
|
|
|
|
|
&DenyCGI unless ( $self->{cgiprune} ); |
|
929
|
|
|
|
|
|
|
|
|
930
|
0
|
|
|
|
|
|
my $pruned = 0; |
|
931
|
|
|
|
|
|
|
|
|
932
|
0
|
|
|
|
|
|
opendir SESSDIR, $self->{sessdir}; |
|
933
|
0
|
|
|
|
|
|
while (my $file = readdir(SESSDIR)) |
|
934
|
|
|
|
|
|
|
{ |
|
935
|
0
|
|
|
|
|
|
$file = $self->{sessdir} . '/' . $file; |
|
936
|
0
|
0
|
|
|
|
|
next unless (-f $file); |
|
937
|
|
|
|
|
|
|
|
|
938
|
0
|
|
|
|
|
|
my $mtime = (stat _)[9]; |
|
939
|
0
|
|
|
|
|
|
my $now = time; |
|
940
|
0
|
|
|
|
|
|
my $age = $now - $mtime; |
|
941
|
|
|
|
|
|
|
|
|
942
|
0
|
0
|
|
|
|
|
$pruned += unlink $file if ($age > $self->{timeout}); |
|
943
|
|
|
|
|
|
|
} |
|
944
|
0
|
|
|
|
|
|
closedir SESSDIR; |
|
945
|
|
|
|
|
|
|
|
|
946
|
0
|
|
|
|
|
|
return $pruned; |
|
947
|
|
|
|
|
|
|
} |
|
948
|
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
=pod |
|
950
|
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
=back |
|
952
|
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
=head1 PRIVATE METHODS |
|
954
|
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
There are also some private methods. Use of them by unauthorized dirrty |
|
956
|
|
|
|
|
|
|
scripts is a federal offence in some jurisdictions, carrying a maximum sentence |
|
957
|
|
|
|
|
|
|
of yearly noogies by yours-truly. This may or may not be legal in your |
|
958
|
|
|
|
|
|
|
country. |
|
959
|
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
=over 4 |
|
961
|
|
|
|
|
|
|
|
|
962
|
|
|
|
|
|
|
=item C |
|
963
|
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
Fetches a user's auth data from the user file. The data fields are returned as |
|
965
|
|
|
|
|
|
|
a list, in the order in which they appear in the data file. |
|
966
|
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
=cut |
|
968
|
|
|
|
|
|
|
|
|
969
|
|
|
|
|
|
|
sub GetUserData |
|
970
|
|
|
|
|
|
|
{ |
|
971
|
0
|
|
|
0
|
1
|
|
my ($self, $field0) = @_; |
|
972
|
|
|
|
|
|
|
|
|
973
|
0
|
0
|
|
|
|
|
unless ( $field0 ) |
|
974
|
|
|
|
|
|
|
{ |
|
975
|
0
|
|
|
|
|
|
warn "Field0 not given"; |
|
976
|
0
|
|
|
|
|
|
return; |
|
977
|
|
|
|
|
|
|
} |
|
978
|
0
|
0
|
|
|
|
|
unless ( open( USER, "< " . $self->{userfile} ) ) |
|
979
|
|
|
|
|
|
|
{ |
|
980
|
0
|
|
|
|
|
|
warn "Couldn't open userfile"; |
|
981
|
0
|
|
|
|
|
|
return; |
|
982
|
|
|
|
|
|
|
} |
|
983
|
|
|
|
|
|
|
|
|
984
|
0
|
|
|
|
|
|
my @userdata; |
|
985
|
0
|
|
|
|
|
|
my $fzero = $field0 . DELIMITER; |
|
986
|
0
|
|
|
|
|
|
while ( ) |
|
987
|
|
|
|
|
|
|
{ |
|
988
|
0
|
0
|
|
|
|
|
next if ( !/^$fzero/i ); |
|
989
|
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
# Field 0 found--get user data. |
|
991
|
0
|
|
|
|
|
|
chop; |
|
992
|
0
|
|
|
|
|
|
@userdata = split( DELIMITER ); |
|
993
|
0
|
|
|
|
|
|
last; |
|
994
|
|
|
|
|
|
|
} |
|
995
|
0
|
|
|
|
|
|
close USER; |
|
996
|
0
|
0
|
|
|
|
|
if ( lc $userdata[0] ne lc $field0 ) |
|
997
|
|
|
|
|
|
|
{ |
|
998
|
0
|
|
|
|
|
|
warn "Field 0 ($field0) doesn't match (" . join( ', ', @userdata ) . ")"; |
|
999
|
0
|
|
|
|
|
|
return; |
|
1000
|
|
|
|
|
|
|
} |
|
1001
|
|
|
|
|
|
|
|
|
1002
|
0
|
|
|
|
|
|
return @userdata; |
|
1003
|
|
|
|
|
|
|
} |
|
1004
|
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
=pod |
|
1006
|
|
|
|
|
|
|
|
|
1007
|
|
|
|
|
|
|
=item C |
|
1008
|
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
Prints the login form using either an C or a header and footer. |
|
1010
|
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
This is called by C when the user is not authenticated. |
|
1012
|
|
|
|
|
|
|
|
|
1013
|
|
|
|
|
|
|
This method hands off either to C or to C. |
|
1014
|
|
|
|
|
|
|
|
|
1015
|
|
|
|
|
|
|
=cut |
|
1016
|
|
|
|
|
|
|
|
|
1017
|
|
|
|
|
|
|
sub PrintLoginForm |
|
1018
|
|
|
|
|
|
|
{ |
|
1019
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
|
1020
|
|
|
|
|
|
|
|
|
1021
|
0
|
|
|
|
|
|
print $self->{cgi}->header; |
|
1022
|
|
|
|
|
|
|
|
|
1023
|
0
|
0
|
|
|
|
|
if ($self->{logintmpl}) |
|
1024
|
|
|
|
|
|
|
{ |
|
1025
|
0
|
|
|
|
|
|
$self->PLF_template($msg); |
|
1026
|
|
|
|
|
|
|
} |
|
1027
|
|
|
|
|
|
|
else |
|
1028
|
|
|
|
|
|
|
{ |
|
1029
|
0
|
|
|
|
|
|
$self->PLF_headerfooter($msg); |
|
1030
|
|
|
|
|
|
|
} |
|
1031
|
|
|
|
|
|
|
} |
|
1032
|
|
|
|
|
|
|
|
|
1033
|
|
|
|
|
|
|
=pod |
|
1034
|
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
=item C |
|
1036
|
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
Prints the login form using an HTML::Template. It uses the value of the |
|
1038
|
|
|
|
|
|
|
logintmpl property to get the template. |
|
1039
|
|
|
|
|
|
|
|
|
1040
|
|
|
|
|
|
|
=cut |
|
1041
|
|
|
|
|
|
|
|
|
1042
|
|
|
|
|
|
|
sub PLF_template |
|
1043
|
|
|
|
|
|
|
{ |
|
1044
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
|
1045
|
|
|
|
|
|
|
|
|
1046
|
0
|
|
|
|
|
|
require HTML::Template; |
|
1047
|
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
# logintmpl can be one of three things (which are all true values): |
|
1049
|
|
|
|
|
|
|
# 1. An HTML::Template object reference, |
|
1050
|
|
|
|
|
|
|
# 2. A hash containing parameters for HTML::Template->new, or |
|
1051
|
|
|
|
|
|
|
# 3. A filename (then logintmplpath can be the path parameter). |
|
1052
|
0
|
|
|
|
|
|
my $template = $self->{logintmpl}; |
|
1053
|
0
|
0
|
|
|
|
|
unless ( UNIVERSAL::isa( $template, 'HTML::Template' ) ) |
|
1054
|
|
|
|
|
|
|
{ |
|
1055
|
0
|
|
|
|
|
|
$template = new HTML::Template( |
|
1056
|
|
|
|
|
|
|
UNIVERSAL::isa( $template, 'HASH' ) |
|
1057
|
0
|
0
|
|
|
|
|
? %{ $self->{logintmpl} } |
|
1058
|
|
|
|
|
|
|
: ( |
|
1059
|
|
|
|
|
|
|
filename => $template, |
|
1060
|
|
|
|
|
|
|
path => $self->{logintmplpath}, |
|
1061
|
|
|
|
|
|
|
) |
|
1062
|
|
|
|
|
|
|
); |
|
1063
|
|
|
|
|
|
|
} |
|
1064
|
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
# Create parameters for Auth_Fields . |
|
1066
|
0
|
|
|
|
|
|
my @fields = (); |
|
1067
|
0
|
|
|
|
|
|
foreach my $authfield (@{$self->{authfields}}) |
|
|
0
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
{ |
|
1069
|
0
|
0
|
|
|
|
|
if ($authfield->{required}) |
|
1070
|
|
|
|
|
|
|
{ |
|
1071
|
0
|
0
|
|
|
|
|
push @fields, { |
|
1072
|
|
|
|
|
|
|
Display_Name => $authfield->{display}, |
|
1073
|
|
|
|
|
|
|
Input_Name => 'auth_' . $authfield->{id}, |
|
1074
|
|
|
|
|
|
|
Input_Type => $authfield->{hidden} ? 'password' : 'text', |
|
1075
|
|
|
|
|
|
|
}; |
|
1076
|
|
|
|
|
|
|
} |
|
1077
|
|
|
|
|
|
|
} |
|
1078
|
|
|
|
|
|
|
|
|
1079
|
|
|
|
|
|
|
$template->param( |
|
1080
|
0
|
|
|
|
|
|
Message => $msg, |
|
1081
|
|
|
|
|
|
|
Auth_Fields => \@fields, |
|
1082
|
|
|
|
|
|
|
Button_Name => 'auth_submit', |
|
1083
|
|
|
|
|
|
|
Form_Action => $self->{formaction}, |
|
1084
|
|
|
|
|
|
|
Form_Fields => $self->FormFields, |
|
1085
|
|
|
|
|
|
|
); |
|
1086
|
0
|
|
|
|
|
|
print $template->output(); |
|
1087
|
|
|
|
|
|
|
} |
|
1088
|
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
=pod |
|
1090
|
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
=item C |
|
1092
|
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
Prints the login form using a header and footer. It uses the values of the |
|
1094
|
|
|
|
|
|
|
loginheader and loginfooter properties. |
|
1095
|
|
|
|
|
|
|
|
|
1096
|
|
|
|
|
|
|
=cut |
|
1097
|
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
sub PLF_headerfooter |
|
1099
|
|
|
|
|
|
|
{ |
|
1100
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
|
1101
|
|
|
|
|
|
|
|
|
1102
|
0
|
0
|
|
|
|
|
if (open HEADER, "< " . $self->{loginheader}) |
|
1103
|
|
|
|
|
|
|
{ |
|
1104
|
0
|
|
|
|
|
|
my @header = |
|
1105
|
0
|
|
|
|
|
|
close HEADER; |
|
1106
|
0
|
|
|
|
|
|
print @header; |
|
1107
|
|
|
|
|
|
|
} |
|
1108
|
|
|
|
|
|
|
else |
|
1109
|
|
|
|
|
|
|
{ |
|
1110
|
0
|
|
|
|
|
|
print <
|
|
1111
|
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
Login |
|
1114
|
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
|
|
1116
|
|
|
|
|
|
|
Please enter your login information: |
|
1117
|
|
|
|
|
|
|
DEFAULT |
|
1118
|
|
|
|
|
|
|
} |
|
1119
|
|
|
|
|
|
|
|
|
1120
|
0
|
0
|
|
|
|
|
if ($msg) |
|
1121
|
|
|
|
|
|
|
{ |
|
1122
|
0
|
|
|
|
|
|
print qq( $msg \n); |
|
1123
|
|
|
|
|
|
|
} |
|
1124
|
|
|
|
|
|
|
|
|
1125
|
0
|
|
|
|
|
|
my $formaction = $self->{formaction}; |
|
1126
|
0
|
|
|
|
|
|
print <
|
|
1127
|
|
|
|
|
|
|
|
|
1128
|
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
|
|
1154
|
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
END |
|
1156
|
|
|
|
|
|
|
|
|
1157
|
0
|
0
|
|
|
|
|
if (open FOOTER, "< " . $self->{loginfooter}) |
|
1158
|
|
|
|
|
|
|
{ |
|
1159
|
0
|
|
|
|
|
|
my @footer = |
|
1160
|
0
|
|
|
|
|
|
close FOOTER; |
|
1161
|
0
|
|
|
|
|
|
print @footer; |
|
1162
|
|
|
|
|
|
|
} |
|
1163
|
|
|
|
|
|
|
else |
|
1164
|
|
|
|
|
|
|
{ |
|
1165
|
0
|
|
|
|
|
|
print "\n"; |
|
1166
|
|
|
|
|
|
|
} |
|
1167
|
|
|
|
|
|
|
} |
|
1168
|
|
|
|
|
|
|
|
|
1169
|
|
|
|
|
|
|
=pod |
|
1170
|
|
|
|
|
|
|
|
|
1171
|
|
|
|
|
|
|
=item C |
|
1172
|
|
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
|
Returns HTML code for placing existing CGI parameters on a form so that the |
|
1174
|
|
|
|
|
|
|
login process is transparent to the calling script. |
|
1175
|
|
|
|
|
|
|
|
|
1176
|
|
|
|
|
|
|
For any single-valued parameters, it creates a hidden C<< >> control, |
|
1177
|
|
|
|
|
|
|
and for any multi-valued parameters, it creates a hidden (i.e., |
|
1178
|
|
|
|
|
|
|
C |