line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::WWD::Functions; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
####################################### |
4
|
|
|
|
|
|
|
# WorldWide Database Client Package # |
5
|
|
|
|
|
|
|
# Copyright 2000-2005 John Baleshiski # |
6
|
|
|
|
|
|
|
# All rights reserved. # |
7
|
|
|
|
|
|
|
####################################### |
8
|
|
|
|
|
|
|
# Version 0.50 - Initial release |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(stripPerl) ] ); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
13
|
|
|
|
|
|
|
our @EXPORT = qw(stripPerl); |
14
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
2285
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use HTTP::Headers; |
18
|
|
|
|
|
|
|
use HTTP::Request; |
19
|
|
|
|
|
|
|
use LWP::UserAgent; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $XMLparser = XML::LibXML->new(); |
22
|
|
|
|
|
|
|
my $header = HTTP::Headers->new('content-type' => 'text/html'); |
23
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub localhost { return $ENV{'SERVER_NAME'}; } |
26
|
|
|
|
|
|
|
sub localdomain { return splitdomain($ENV{'SERVER_NAME'}); } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub splitdomain { |
29
|
|
|
|
|
|
|
my $domain = shift; |
30
|
|
|
|
|
|
|
my $suffix = ""; |
31
|
|
|
|
|
|
|
$domain = reverse $domain; |
32
|
|
|
|
|
|
|
if($domain =~ /\./) { |
33
|
|
|
|
|
|
|
$suffix = $` . "."; |
34
|
|
|
|
|
|
|
$domain = $'; |
35
|
|
|
|
|
|
|
} else { return ""; } |
36
|
|
|
|
|
|
|
if($domain =~ /^..\./) { |
37
|
|
|
|
|
|
|
$suffix .= $&; |
38
|
|
|
|
|
|
|
$domain = $'; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
if($domain =~ /\./) { $domain = $`; } |
41
|
|
|
|
|
|
|
return (reverse $domain) . (reverse $suffix); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub stripPerl { |
45
|
|
|
|
|
|
|
my $code = shift; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$code =~ s/localhost\(/Net\:\:WWD\:\:Functions\:\:localhost\(/g; |
48
|
|
|
|
|
|
|
$code =~ s/localdomain\(/Net\:\:WWD\:\:Functions\:\:localdomain\(/g; |
49
|
|
|
|
|
|
|
$code =~ s/getTag\(/Net\:\:WWD\:\:Functions\:\:getTag\(/g; |
50
|
|
|
|
|
|
|
$code =~ s/webget\(/Net\:\:WWD\:\:Functions\:\:webget\(/g; |
51
|
|
|
|
|
|
|
$code =~ s/currentURL\(/Net\:\:WWD\:\:Functions\:\:currentURL\(/g; |
52
|
|
|
|
|
|
|
$code =~ s/getData\(/Net\:\:WWD\:\:Functions\:\:getData\(/g; |
53
|
|
|
|
|
|
|
$code =~ s/storeData\(/Net\:\:WWD\:\:Functions\:\:storeData\(/g; |
54
|
|
|
|
|
|
|
$code =~ s/parseXML\(/Net\:\:WWD\:\:Functions\:\:parseXML\(/g; |
55
|
|
|
|
|
|
|
$code =~ s/\$param/DPERLPARAM/g; |
56
|
|
|
|
|
|
|
$code =~ s/\$ENV/DPERLENV/g; |
57
|
|
|
|
|
|
|
$code =~ s/\$\`/DPERLMPRE/g; |
58
|
|
|
|
|
|
|
$code =~ s/\$\'/DPERLMPOST/g; |
59
|
|
|
|
|
|
|
$code =~ s/\s+\(/\(/g; |
60
|
|
|
|
|
|
|
$code =~ s/\`//g; |
61
|
|
|
|
|
|
|
$code =~ s/\@/\@WWD/g; |
62
|
|
|
|
|
|
|
$code =~ s/\$/\$WWD/g; |
63
|
|
|
|
|
|
|
# $code =~ s/\&//g; |
64
|
|
|
|
|
|
|
$code =~ s/\%//g; |
65
|
|
|
|
|
|
|
$code =~ s/accept\(//g; |
66
|
|
|
|
|
|
|
$code =~ s/bind\(//g; |
67
|
|
|
|
|
|
|
$code =~ s/binmode\(//g; |
68
|
|
|
|
|
|
|
$code =~ s/chdir\(//g; |
69
|
|
|
|
|
|
|
$code =~ s/chmod\(//g; |
70
|
|
|
|
|
|
|
$code =~ s/chown\(//g; |
71
|
|
|
|
|
|
|
$code =~ s/chroot\(//g; |
72
|
|
|
|
|
|
|
$code =~ s/close\(//g; |
73
|
|
|
|
|
|
|
$code =~ s/closedir\(//g; |
74
|
|
|
|
|
|
|
$code =~ s/connect\(//g; |
75
|
|
|
|
|
|
|
$code =~ s/dbmclose\(//g; |
76
|
|
|
|
|
|
|
$code =~ s/dbmopen\(//g; |
77
|
|
|
|
|
|
|
$code =~ s/die\(//g; |
78
|
|
|
|
|
|
|
$code =~ s/dump\(//g; |
79
|
|
|
|
|
|
|
$code =~ s/endgrent\(//g; |
80
|
|
|
|
|
|
|
$code =~ s/endhostent\(//g; |
81
|
|
|
|
|
|
|
$code =~ s/endnetent\(//g; |
82
|
|
|
|
|
|
|
$code =~ s/endprotoent\(//g; |
83
|
|
|
|
|
|
|
$code =~ s/endpwent\(//g; |
84
|
|
|
|
|
|
|
$code =~ s/endservent\(//g; |
85
|
|
|
|
|
|
|
$code =~ s/eof\(//g; |
86
|
|
|
|
|
|
|
$code =~ s/eval\(//g; |
87
|
|
|
|
|
|
|
$code =~ s/exit\(//g; |
88
|
|
|
|
|
|
|
$code =~ s/fcntl\(//g; |
89
|
|
|
|
|
|
|
$code =~ s/fileno\(//g; |
90
|
|
|
|
|
|
|
$code =~ s/flock\(//g; |
91
|
|
|
|
|
|
|
$code =~ s/fork\(//g; |
92
|
|
|
|
|
|
|
$code =~ s/format\(//g; |
93
|
|
|
|
|
|
|
$code =~ s/getc\(//g; |
94
|
|
|
|
|
|
|
$code =~ s/getgrent\(//g; |
95
|
|
|
|
|
|
|
$code =~ s/getgrgid\(//g; |
96
|
|
|
|
|
|
|
$code =~ s/getgrnam\(//g; |
97
|
|
|
|
|
|
|
$code =~ s/gethostbyaddr\(//g; |
98
|
|
|
|
|
|
|
$code =~ s/gethostbyname\(//g; |
99
|
|
|
|
|
|
|
$code =~ s/gethostent\(//g; |
100
|
|
|
|
|
|
|
$code =~ s/getlogin\(//g; |
101
|
|
|
|
|
|
|
$code =~ s/getnetbyaddr\(//g; |
102
|
|
|
|
|
|
|
$code =~ s/getnetent\(//g; |
103
|
|
|
|
|
|
|
$code =~ s/getnetbyname\(//g; |
104
|
|
|
|
|
|
|
$code =~ s/getprotobyname\(//g; |
105
|
|
|
|
|
|
|
$code =~ s/getprotobynumber\(//g; |
106
|
|
|
|
|
|
|
$code =~ s/getprotoent\(//g; |
107
|
|
|
|
|
|
|
$code =~ s/getpwent\(//g; |
108
|
|
|
|
|
|
|
$code =~ s/getpwnam\(//g; |
109
|
|
|
|
|
|
|
$code =~ s/getpwuid\(//g; |
110
|
|
|
|
|
|
|
$code =~ s/getservbyname\(//g; |
111
|
|
|
|
|
|
|
$code =~ s/getservbyport\(//g; |
112
|
|
|
|
|
|
|
$code =~ s/getservent\(//g; |
113
|
|
|
|
|
|
|
$code =~ s/glob\(//g; |
114
|
|
|
|
|
|
|
$code =~ s/import\(//g; |
115
|
|
|
|
|
|
|
$code =~ s/ioctl\(//g; |
116
|
|
|
|
|
|
|
$code =~ s/kill\(//g; |
117
|
|
|
|
|
|
|
$code =~ s/link\(//g; |
118
|
|
|
|
|
|
|
$code =~ s/listen\(//g; |
119
|
|
|
|
|
|
|
$code =~ s/lstat\(//g; |
120
|
|
|
|
|
|
|
$code =~ s/mkdir\(//g; |
121
|
|
|
|
|
|
|
$code =~ s/open\(//g; |
122
|
|
|
|
|
|
|
$code =~ s/opendir\(//g; |
123
|
|
|
|
|
|
|
$code =~ s/printf\(//g; |
124
|
|
|
|
|
|
|
$code =~ s/read\(//g; |
125
|
|
|
|
|
|
|
$code =~ s/readdir\(//g; |
126
|
|
|
|
|
|
|
$code =~ s/readlink\(//g; |
127
|
|
|
|
|
|
|
$code =~ s/recv\(//g; |
128
|
|
|
|
|
|
|
$code =~ s/rename\(//g; |
129
|
|
|
|
|
|
|
$code =~ s/require\(//g; |
130
|
|
|
|
|
|
|
$code =~ s/reset\(//g; |
131
|
|
|
|
|
|
|
$code =~ s/rewinddir\(//g; |
132
|
|
|
|
|
|
|
$code =~ s/rmdir\(//g; |
133
|
|
|
|
|
|
|
$code =~ s/seek\(//g; |
134
|
|
|
|
|
|
|
$code =~ s/seekdir\(//g; |
135
|
|
|
|
|
|
|
$code =~ s/select\(//g; |
136
|
|
|
|
|
|
|
$code =~ s/send\(//g; |
137
|
|
|
|
|
|
|
$code =~ s/setgrent\(//g; |
138
|
|
|
|
|
|
|
$code =~ s/sethostent\(//g; |
139
|
|
|
|
|
|
|
$code =~ s/setnetent\(//g; |
140
|
|
|
|
|
|
|
$code =~ s/setprotoent\(//g; |
141
|
|
|
|
|
|
|
$code =~ s/setpwent\(//g; |
142
|
|
|
|
|
|
|
$code =~ s/setservent\(//g; |
143
|
|
|
|
|
|
|
$code =~ s/shutdown\(//g; |
144
|
|
|
|
|
|
|
$code =~ s/socket\(//g; |
145
|
|
|
|
|
|
|
$code =~ s/socketpair\(//g; |
146
|
|
|
|
|
|
|
$code =~ s/stat\(//g; |
147
|
|
|
|
|
|
|
$code =~ s/symlink\(//g; |
148
|
|
|
|
|
|
|
$code =~ s/syscall\(//g; |
149
|
|
|
|
|
|
|
$code =~ s/sysopen\(//g; |
150
|
|
|
|
|
|
|
$code =~ s/sysread\(//g; |
151
|
|
|
|
|
|
|
$code =~ s/sysseek\(//g; |
152
|
|
|
|
|
|
|
$code =~ s/system\(//g; |
153
|
|
|
|
|
|
|
$code =~ s/syswrite\(//g; |
154
|
|
|
|
|
|
|
$code =~ s/tell\(//g; |
155
|
|
|
|
|
|
|
$code =~ s/telldir\(//g; |
156
|
|
|
|
|
|
|
$code =~ s/truncate\(//g; |
157
|
|
|
|
|
|
|
$code =~ s/umask\(//g; |
158
|
|
|
|
|
|
|
$code =~ s/unlink\(//g; |
159
|
|
|
|
|
|
|
$code =~ s/use\(//g; |
160
|
|
|
|
|
|
|
$code =~ s/utime\(//g; |
161
|
|
|
|
|
|
|
$code =~ s/warn\(//g; |
162
|
|
|
|
|
|
|
$code =~ s/write\(//g; |
163
|
|
|
|
|
|
|
$code =~ s/\$wwd//g; |
164
|
|
|
|
|
|
|
$code =~ s/DPERLPARAM/\$param/g; |
165
|
|
|
|
|
|
|
$code =~ s/DPERLENV/\$ENV/g; |
166
|
|
|
|
|
|
|
$code =~ s/DPERLMPRE/\$\`/g; |
167
|
|
|
|
|
|
|
$code =~ s/DPERLMPOST/\$\'/g; |
168
|
|
|
|
|
|
|
$code =~ s/DPERLDOLLAR/\$/g; |
169
|
|
|
|
|
|
|
return $code; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub currentURL { |
173
|
|
|
|
|
|
|
return "http://" . $ENV{'SERVER_NAME'}.$ENV{'SCRIPT_NAME'}; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub getData { |
177
|
|
|
|
|
|
|
my($name) = @_; |
178
|
|
|
|
|
|
|
$name =~ s/[^A-Za-z0-9]//g; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
open(FH,"/usr/share/wwd/data-store/${name}"); |
181
|
|
|
|
|
|
|
flock(FH,LOCK_EX); |
182
|
|
|
|
|
|
|
my $strS = ; |
183
|
|
|
|
|
|
|
close(FH); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
my @fInfo = stat "/usr/share/wwd/data-store/${name}"; |
186
|
|
|
|
|
|
|
return ($strS,$fInfo[9]); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub storeData { |
190
|
|
|
|
|
|
|
my($name,$value) = @_; |
191
|
|
|
|
|
|
|
$name =~ s/[^A-Za-z0-9]//g; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
open(FH,">/usr/share/wwd/data-store/${name}"); |
194
|
|
|
|
|
|
|
flock(FH,LOCK_EX); |
195
|
|
|
|
|
|
|
print FH $value; |
196
|
|
|
|
|
|
|
close(FH); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub parseXML { |
200
|
|
|
|
|
|
|
my($xml,$node) = @_; |
201
|
|
|
|
|
|
|
my $graph = $XMLparser->parse_string($xml); |
202
|
|
|
|
|
|
|
return $graph->findvalue($node); |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub webget { |
206
|
|
|
|
|
|
|
my($url) = @_; |
207
|
|
|
|
|
|
|
my $req = HTTP::Request->new(GET,$url,$header,""); |
208
|
|
|
|
|
|
|
my $resp = $ua->request($req); |
209
|
|
|
|
|
|
|
my $lines = $resp->as_string(); |
210
|
|
|
|
|
|
|
if($lines =~ /\n\n/) { $lines = $'; } |
211
|
|
|
|
|
|
|
return $lines; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub getTag { |
215
|
|
|
|
|
|
|
my ($host, $tag, $o, $rp) = @_; |
216
|
|
|
|
|
|
|
if(!defined $o) { $o = ""; } |
217
|
|
|
|
|
|
|
if(!defined $rp) { $rp = ""; } |
218
|
|
|
|
|
|
|
my $s = viewTag($host, $tag, $o, $rp); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
if($s =~ /\:/) { $s = $'; } |
221
|
|
|
|
|
|
|
if($s =~ /\:/) { $s = $'; } |
222
|
|
|
|
|
|
|
return $s; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub invalidPassword { |
226
|
|
|
|
|
|
|
my ($user, $pw, $readpw, $tmppw, $fname) = @_; |
227
|
|
|
|
|
|
|
my $ttl = ""; |
228
|
|
|
|
|
|
|
chomp($user); |
229
|
|
|
|
|
|
|
chomp($pw); |
230
|
|
|
|
|
|
|
chomp($readpw); |
231
|
|
|
|
|
|
|
chomp($tmppw); |
232
|
|
|
|
|
|
|
($ttl,$tmppw) = split(/;/, $tmppw); |
233
|
|
|
|
|
|
|
if(($ttl < time)&&($ttl ne "")) { |
234
|
|
|
|
|
|
|
open(FH,"+<${fname}"); |
235
|
|
|
|
|
|
|
flock(FH,LOCK_EX); |
236
|
|
|
|
|
|
|
my @lines = ; |
237
|
|
|
|
|
|
|
seek(FH, 0, 0); |
238
|
|
|
|
|
|
|
truncate(FH, 0); |
239
|
|
|
|
|
|
|
$lines[3] = "\n"; |
240
|
|
|
|
|
|
|
for(my $i=0; $i<@lines; $i++) { print FH $lines[$i]; } |
241
|
|
|
|
|
|
|
close(FH); |
242
|
|
|
|
|
|
|
$tmppw = ""; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
if($pw eq "") { |
245
|
|
|
|
|
|
|
if(($tmppw ne "")||($readpw ne "")) { return 1; } |
246
|
|
|
|
|
|
|
return 0; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
if(($pw eq $tmppw)||($pw eq $readpw)) { return 0; } |
249
|
|
|
|
|
|
|
return 1; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
sub canAccess { |
253
|
|
|
|
|
|
|
my($accesslist,$host,$fname) = @_; |
254
|
|
|
|
|
|
|
chomp($accesslist); |
255
|
|
|
|
|
|
|
if($accesslist eq "") { return 1; } |
256
|
|
|
|
|
|
|
my @allowed = split(/,/, $accesslist); |
257
|
|
|
|
|
|
|
for(my $i=0; $i<@allowed; $i++) { |
258
|
|
|
|
|
|
|
if($allowed[$i] =~ /;/) { |
259
|
|
|
|
|
|
|
my $s = $`; |
260
|
|
|
|
|
|
|
my $times = $'; |
261
|
|
|
|
|
|
|
if(($s eq $host)||($s eq currentUser())) { |
262
|
|
|
|
|
|
|
setAccess($s, $times, $fname); |
263
|
|
|
|
|
|
|
return 1; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
} else { if(($allowed[$i] eq $host)||($allowed[$i] eq currentUser())) { return 1; } } |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
return 0; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub setAccess { |
271
|
|
|
|
|
|
|
my($host,$times, $fname) = @_; |
272
|
|
|
|
|
|
|
open(FH,"+<${fname}"); |
273
|
|
|
|
|
|
|
flock(FH,LOCK_EX); |
274
|
|
|
|
|
|
|
my @lines = ; |
275
|
|
|
|
|
|
|
seek(FH, 0, 0); |
276
|
|
|
|
|
|
|
truncate(FH, 0); |
277
|
|
|
|
|
|
|
chomp($lines[6]); |
278
|
|
|
|
|
|
|
my @list = split(/,/, $lines[6]); |
279
|
|
|
|
|
|
|
$lines[6] = ""; |
280
|
|
|
|
|
|
|
for(my $i=0; $i<@list; $i++) { |
281
|
|
|
|
|
|
|
if($list[$i] =~ /$host;$times/) { |
282
|
|
|
|
|
|
|
$times--; |
283
|
|
|
|
|
|
|
if($times == 0) { $list[$i] = ""; } |
284
|
|
|
|
|
|
|
else { $list[$i] = "${host};${times}"; } |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
if($list[$i] ne "") { $lines[6] .= $list[$i] . ","; } |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
$lines[6] =~ s/,$//; |
289
|
|
|
|
|
|
|
$lines[6] .= "\n"; |
290
|
|
|
|
|
|
|
for(my $i=0; $i<@lines; $i++) { print FH $lines[$i]; } |
291
|
|
|
|
|
|
|
close(FH); |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
1; |