line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OzDB;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25658
|
use 5.008006;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
1345
|
use Benchmark;
|
|
1
|
|
|
|
|
9041
|
|
|
1
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Start the benchmark timer
|
9
|
|
|
|
|
|
|
my $t0 = new Benchmark;
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export
|
16
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead.
|
17
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants.
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# This allows declaration use OzDB ':all';
|
20
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
21
|
|
|
|
|
|
|
# will save memory.
|
22
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
) ] );
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT = qw(
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
);
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '0.02';
|
33
|
|
|
|
|
|
|
# 5/20/2005, NeXeN: Yet another versioning scheme. Altho PAUSE/CPAN
|
34
|
|
|
|
|
|
|
# allows for x.y.z versioning schema, we'll move to x.yz so it'll show
|
35
|
|
|
|
|
|
|
# the minor version number correctly, with the revision point as the
|
36
|
|
|
|
|
|
|
# last digit.
|
37
|
|
|
|
|
|
|
#
|
38
|
|
|
|
|
|
|
#
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# 5/19/2005, NeXeN: The new versioning scheme has been reset back to
|
41
|
|
|
|
|
|
|
# 0.0.1 for distribution with cpan. Please see the
|
42
|
|
|
|
|
|
|
# Changes file for more information.
|
43
|
|
|
|
|
|
|
#
|
44
|
|
|
|
|
|
|
# our $VERSION = '0.1.3';
|
45
|
|
|
|
|
|
|
#
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# methods.
|
49
|
|
|
|
|
|
|
sub new {
|
50
|
|
|
|
|
|
|
# my $t0 = new Benchmark;
|
51
|
0
|
|
|
0
|
0
|
|
my $package = shift;
|
52
|
0
|
|
|
|
|
|
return bless( {}, $package );
|
53
|
|
|
|
|
|
|
# my $t1 = new Benchmark;
|
54
|
|
|
|
|
|
|
# my $td = timediff($t1, $t0);
|
55
|
|
|
|
|
|
|
# print "Your OzDB Request took aproximately ", timestr($td),"\n\nThe results of your request are as follows:\n\n\n";
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub verbose {
|
60
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
61
|
0
|
0
|
|
|
|
|
if (@_) {
|
62
|
0
|
|
|
|
|
|
$self->{'verbose'} = shift;
|
63
|
|
|
|
|
|
|
}
|
64
|
0
|
|
|
|
|
|
return $self->{'verbose'};
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub add_user {
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# add_user method allows for 4 arguments exactly like authenticate. The only
|
70
|
|
|
|
|
|
|
# difference is the second argument is ignored, and the third and forth must
|
71
|
|
|
|
|
|
|
# be string and integer respectively. First argument is the name of the db file
|
72
|
|
|
|
|
|
|
#
|
73
|
|
|
|
|
|
|
# This is a cumulative database. No remove functionality is implemented.
|
74
|
|
|
|
|
|
|
#
|
75
|
|
|
|
|
|
|
# format, add_user("userfile", "ignored", "user", "authlevel")
|
76
|
|
|
|
|
|
|
# authlevel being numeric value, ignored meaning the arg is not used
|
77
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
78
|
0
|
0
|
|
|
|
|
open( USRDB, "<$_[0]" ) or die "error opening user file: $_[0]\n";
|
79
|
0
|
|
|
|
|
|
my @lines = ; # Read it into an array
|
80
|
0
|
|
|
|
|
|
close(USRDB);
|
81
|
|
|
|
|
|
|
# check for correct syntax
|
82
|
|
|
|
|
|
|
# if ($_[3] !~ /^\d+$/ or $_[2] !~ /^[A-Za-z]+$/)
|
83
|
0
|
0
|
0
|
|
|
|
if (not defined $_[3] or not defined $_[2] or $_[3] !~ /^\d+$/)
|
84
|
|
|
|
|
|
|
{
|
85
|
0
|
|
|
|
|
|
print "The must be letters only and the must be a number between 1 and 500\n";
|
86
|
0
|
|
|
|
|
|
return "0 $_[2] $_[3]";
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
else
|
90
|
|
|
|
|
|
|
{
|
91
|
0
|
|
|
|
|
|
my $test;
|
92
|
0
|
|
|
|
|
|
for $test (@lines)
|
93
|
|
|
|
|
|
|
{
|
94
|
|
|
|
|
|
|
# skip lines that are comments or blank lines
|
95
|
0
|
0
|
|
|
|
|
if ($test =~ /^s*#/)
|
96
|
|
|
|
|
|
|
{
|
97
|
0
|
|
|
|
|
|
next;
|
98
|
|
|
|
|
|
|
}
|
99
|
0
|
0
|
|
|
|
|
if ($test =~ /^$/)
|
100
|
|
|
|
|
|
|
{
|
101
|
0
|
|
|
|
|
|
next;
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
# still in the for loop
|
104
|
|
|
|
|
|
|
# split the line up into into it's seporate values, delimited by space
|
105
|
0
|
|
|
|
|
|
my (@words) = split(/ /, $test);
|
106
|
|
|
|
|
|
|
# evaluate if the entry exists, if it does, exit the loop and give 'already exists' message
|
107
|
0
|
0
|
|
|
|
|
if ($words[0] eq $_[2])
|
108
|
|
|
|
|
|
|
{
|
109
|
0
|
|
|
|
|
|
print "The user, $words[0], already exists.\n";
|
110
|
0
|
|
|
|
|
|
return "1 $_[2] $_[3]";
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
# ok, the user didn't match, so what do we do now?
|
114
|
0
|
|
|
|
|
|
next;
|
115
|
|
|
|
|
|
|
# go to the next one, duh
|
116
|
|
|
|
|
|
|
# still looping
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
# no longer in loop, but still else
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# the entry doesnt exist, lets make one
|
121
|
0
|
|
|
|
|
|
print "Adding user $_[2] at authlevel $_[3].\n";
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# re-opening of the file, this time in append mode
|
124
|
|
|
|
|
|
|
# doesn't seem to be too much of an IO drain, I get 0 ms execution
|
125
|
|
|
|
|
|
|
# times tested up to 25mb file. Until sockets are implemented,
|
126
|
|
|
|
|
|
|
# this should be fine.
|
127
|
0
|
0
|
|
|
|
|
open(USRDB, ">>$_[0]") or die "could not open $_[0] for append!\n";
|
128
|
|
|
|
|
|
|
# print our data to the file
|
129
|
0
|
|
|
|
|
|
print USRDB "$_[2] $_[3]\n";
|
130
|
|
|
|
|
|
|
# close the file
|
131
|
0
|
|
|
|
|
|
close(USRDB);
|
132
|
0
|
|
|
|
|
|
return "2 $_[2] $_[3]";
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# still in the else meaning valid syntax with data left to handle
|
135
|
|
|
|
|
|
|
# open(USRDB, ">>authuser.db");
|
136
|
|
|
|
|
|
|
}
|
137
|
|
|
|
|
|
|
# still in the sub, outside the else
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
}
|
140
|
|
|
|
|
|
|
sub add_command {
|
141
|
0
|
|
|
0
|
0
|
|
return 0;
|
142
|
|
|
|
|
|
|
}
|
143
|
|
|
|
|
|
|
sub authenticate {
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# format, authenticate("userfile", "commandfile", "user", "command")
|
146
|
|
|
|
|
|
|
# authlevel being numeric value
|
147
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
148
|
0
|
0
|
|
|
|
|
open( USRDB, "<$_[0]" ) or die "error opening user file: $_[0]\n";
|
149
|
0
|
|
|
|
|
|
my @users = ; # Read it into an array
|
150
|
0
|
0
|
|
|
|
|
open( CMDDB, "<$_[1]" ) or die "error opening command file: $_[1]\n";
|
151
|
0
|
|
|
|
|
|
my @commands = ;
|
152
|
0
|
|
|
|
|
|
close(USRDB);
|
153
|
0
|
|
|
|
|
|
close(CMDDB);
|
154
|
0
|
|
|
|
|
|
my $userset;
|
155
|
0
|
0
|
0
|
|
|
|
if (not defined $ARGV[0] or not defined $ARGV[1])
|
156
|
|
|
|
|
|
|
{
|
157
|
0
|
|
|
|
|
|
print "Wrong Syntax\n";
|
158
|
0
|
|
|
|
|
|
return "0 $_[2] $_[3]";
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
}
|
161
|
0
|
|
|
|
|
|
for $userset (@users)
|
162
|
|
|
|
|
|
|
{
|
163
|
0
|
0
|
|
|
|
|
if ( $userset =~ /^s*#/ )
|
164
|
|
|
|
|
|
|
{
|
165
|
0
|
|
|
|
|
|
next;
|
166
|
|
|
|
|
|
|
}
|
167
|
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
if ( $userset =~ /^$/ )
|
169
|
|
|
|
|
|
|
{
|
170
|
0
|
|
|
|
|
|
next;
|
171
|
|
|
|
|
|
|
}
|
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
my (@userlist) = split( / /, $userset );
|
174
|
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
|
if ( $userlist[0] eq $_[2] )
|
176
|
|
|
|
|
|
|
{
|
177
|
0
|
|
|
|
|
|
my $command;
|
178
|
0
|
|
|
|
|
|
for $command (@commands)
|
179
|
|
|
|
|
|
|
{
|
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
chomp($command);
|
182
|
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
if ( $command =~ /^s*#/ )
|
184
|
|
|
|
|
|
|
{
|
185
|
0
|
|
|
|
|
|
next;
|
186
|
|
|
|
|
|
|
}
|
187
|
0
|
0
|
|
|
|
|
if ( $command =~ /^$/ )
|
188
|
|
|
|
|
|
|
{
|
189
|
0
|
|
|
|
|
|
next;
|
190
|
|
|
|
|
|
|
}
|
191
|
0
|
|
|
|
|
|
my (@cmmd) = split( / /, $command );
|
192
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
if ( $cmmd[0] eq $_[3] )
|
194
|
|
|
|
|
|
|
{
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# command exists
|
197
|
|
|
|
|
|
|
|
198
|
0
|
0
|
|
|
|
|
if ( $userlist[1] >= $cmmd[1] )
|
199
|
|
|
|
|
|
|
{
|
200
|
0
|
0
|
|
|
|
|
if ( defined $cmmd[2] )
|
201
|
|
|
|
|
|
|
{
|
202
|
|
|
|
|
|
|
# authenticated, but what type of command?
|
203
|
0
|
0
|
|
|
|
|
if ( $cmmd[2] eq "." )
|
204
|
|
|
|
|
|
|
{
|
205
|
0
|
|
|
|
|
|
print "$userlist[0] authenticated for $cmmd[0] which does: @cmmd[3..$#cmmd]\n";
|
206
|
0
|
|
|
|
|
|
return "1.0 $_[2] $_[3] @cmmd[3..$#cmmd]";
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
}
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
else
|
211
|
|
|
|
|
|
|
{
|
212
|
0
|
0
|
|
|
|
|
if ( $cmmd[2] eq "]" )
|
213
|
|
|
|
|
|
|
{
|
214
|
0
|
|
|
|
|
|
print "$userlist[0] authenticated for $cmmd[0] which does: @cmmd[3..$#cmmd]\n";
|
215
|
0
|
|
|
|
|
|
for ( @cmmd[ 3 .. $#cmmd ], $_[2] ) { s/[\x0A\x0D]//g; s/[\r\n]//; }
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
return "1.1 $_[2] $_[3] @cmmd[3..$#cmmd]";
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
#print "second time @cmmd[3..$#cmmd] test\n";
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
}
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
}
|
223
|
|
|
|
|
|
|
}
|
224
|
|
|
|
|
|
|
else
|
225
|
|
|
|
|
|
|
{
|
226
|
|
|
|
|
|
|
{
|
227
|
0
|
|
|
|
|
|
print "$userlist[0] authenticated for $cmmd[0]\n";
|
|
0
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
return "1.2 $_[2] $_[3]";
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
}
|
231
|
|
|
|
|
|
|
}
|
232
|
|
|
|
|
|
|
# I'm too lazy to track down the iteration of this loop
|
233
|
|
|
|
|
|
|
# therefore, I will add this print statement...
|
234
|
|
|
|
|
|
|
# If anyone sees the following message, please report
|
235
|
|
|
|
|
|
|
# it to the author's email address.
|
236
|
0
|
|
|
|
|
|
print "why did this happen?\n";
|
237
|
0
|
|
|
|
|
|
return "0 $_[2] $_[3]";
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
}
|
240
|
0
|
|
|
|
|
|
print "User $_[2] Not Authenticated\n";
|
241
|
0
|
|
|
|
|
|
return "2 $_[2] $_[3]";
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
}
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# looping through the commands
|
246
|
|
|
|
|
|
|
#print "why did this happen3?\n";
|
247
|
|
|
|
|
|
|
}
|
248
|
0
|
|
|
|
|
|
print "Command $_[3] doesn't exist\n";
|
249
|
0
|
|
|
|
|
|
return "3 $_[2] $_[3]";
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
}
|
252
|
0
|
|
|
|
|
|
next;
|
253
|
0
|
|
|
|
|
|
return "0 $_[2] $_[3]";
|
254
|
|
|
|
|
|
|
}
|
255
|
0
|
|
|
|
|
|
print "User $_[2] doesn't exist\n";
|
256
|
0
|
|
|
|
|
|
return "4 $_[2] $_[3]";
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
#end of sub
|
260
|
|
|
|
|
|
|
}
|
261
|
|
|
|
|
|
|
# see if we can get a different timer result
|
262
|
|
|
|
|
|
|
print "OzDB Driver version $VERSION\n";
|
263
|
|
|
|
|
|
|
# set a stop timer
|
264
|
|
|
|
|
|
|
my $t1 = new Benchmark;
|
265
|
|
|
|
|
|
|
# calculate time difference
|
266
|
|
|
|
|
|
|
my $td = timediff($t1, $t0);
|
267
|
|
|
|
|
|
|
print "Your OzDB Request took aproximately ", timestr($td),"\nThe results of your request are as follows:\n";
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
1;
|
270
|
|
|
|
|
|
|
__END__
|