blib/script/verify-link-control

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/script/build-schedule ↑ Summary blib/script/fix-link.cgi »
1 #!/usr/local/bin/perl -w
2  
3 =head1 NAME
4  
5 verify-link-control - check that linkcontroller setup is correct
6  
7 =head1 DESCRIPTION
8  
9 This program simply loads the configuration for LinkController and
10 then carries out some simple tests to see if all is as it should be.
11  
12 If any problems are detected then it suggests corrective action,
13 either a variable which should be added to the configuration file
14 (.link-control in the users home directory) or a program which should
15 be run.
16  
17 =head1 BUGS
18  
19 This program needs to have lots of things added
20  
21 =over 4
22  
23 =item *
24  
25 Check that the filenames make sense.
26  
27 =item *
28  
29 Check that the files are the correct type.
30  
31 =item *
32  
33 Check that the files interact correctly
34  
35 =item *
36  
37 Check permissions
38  
39 =back
40  
41 =head1 SEE ALSO
42  
43 L<verify-link-control(1)>; L<extract-links(1)>; L<build-schedule>
44 L<link-report(1)>; L<fix-link(1)>; L<link-report.cgi(1)>; L<fix-link.cgi>
45 L<suggest(1)>; L<link-report.cgi(1)>; L<configure-link-control>
46  
47 The LinkController manual in the distribution in HTML, info, or
48 postscript formats, included in the distribution.
49  
50 http://scotclimb.org.uk/software/linkcont/ - the
51 LinkController homepage.
52  
53 =cut
54  
55 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 2 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 0 ▶use DB_File;
Subroutine BEGIN: called CC=1 SCAR=2.6
60 use MLDBM qw(DB_File);
61  
62 use WWW::Link_Controller::ReadConf;
63 use WWW::Link_Controller::Version;
64 use Data::Dumper;
65 use WWW::Link;
66 use Schedule::SoftTime;
67  
68 use Getopt::Function; #don't need yet qw(maketrue makevalue);
69  
70 $::opthandler = new Getopt::Function
71 [ "version V>version",
72 "usage h>usage help>usage",
73 "help-opt=s",
74 "verbose:i v>verbose",
75 ], {};
76  
77 $::opthandler->std_opts;
78  
79 $::opthandler->check_opts;
80  
81 die "can't accept any arguments" if @ARGV;
82  
83 sub usage() {
84 print <<EOF;
85 verify-link-control [options] page-url...
86  
87 EOF
88 $::opthandler->list_opts;
89 print <<EOF;
90  
91 Check that link controller is set up correctly and suggest corrective
92 action for any problems
93 EOF
94 }
95  
96 sub version() {
97 print <<'EOF';
98 verify-link-control version
99 $Id: verify-link-control.pl,v 1.9 2002/01/18 20:32:35 mikedlr Exp $
100 EOF
101 }
102  
103 $::now=time;
104  
105 my $revision='$Revision: 1.9 $';
106 use WWW::Link_Controller::Version;
107 my $version = $WWW::Link_Controller::Version::VERSION;
108  
109  
110 print STDOUT <<EOF;
111 verify-link-control: $revision LinkController version $version
112  
113 checking through your configuration.
114  
115 EOF
116  
117 unless ($::user_address) {
118 print STDOUT <<EOF;
119  
120 User Email address needs to be defined (\$::user_address) if you want
121 to test links. You will be able to make reports from other people's
122 data though
123 EOF
124 }
125  
126 unless ($::page_index) {
127 print STDOUT <<EOF;
128  
129 Page index variable needs to be defined (\$::page_index) to allow
130 rebuilding of link index.
131 EOF
132 } elsif (! -e $::page_index) {
133 print STDOUT <<EOF;
134  
135 The file $::page_index should exist but
136 doesn't you may want to build it with extract-links The \$::page_index
137 variable controls its location.
138 EOF
139 }
140  
141 unless ($::link_index) {
142 print STDOUT <<EOF;
143  
144 Page index variable needs to be defined (\$::link_index) to allow
145 rebuilding of link index. It's a filename.
146 EOF
147 } elsif (! -e $::link_index) {
148 print STDOUT <<EOF;
149  
150 The file $::link_index should exist but
151 doesn't. You need this to generate reports identifying which resource
152 has a broken link. You can build it with extract-links The
153 \$::link_index variable controls its location.
154 EOF
155 }
156  
157 unless ($::links) {
158 print STDOUT <<EOF;
159  
160 Links database variable needs to be defined (\$::links)
161 to allow reports on the status of links and link checking.
162 EOF
163 } elsif (! -e $::links) {
164 print STDOUT <<EOF
165  
166 The file $::links should exist but
167 doesn't. You will have to rebuild it using extract-links. The
168 \$::links variable controls its location
169 EOF
170 }
171  
172 unless ($::infostrucs) {
173 print STDOUT <<EOF;
174  
175 The \$::infostrucs variable should be defined. This variable gives
176 the name of a configuration file which allows extract links to know
177 where you keep your infostructure(s) (web pages).
178 EOF
179 } elsif (! -e $::infostrucs) {
180 print STDOUT <<EOF;
181  
182 The file $::infostrucs should exist but
183 doesn't you should put configuration of your web pages in it, like so
184  
185 directory http://my.webserver.somewhere/ /var/www/html
186 www http://dynamic.my.webserver.somewhere
187 EOF
188 }
189  
190 unless ($::base_dir) {
191 print STDOUT <<EOF;
192  
193 Base directory variable should be defined (\$::base_dir) this will
194 give default definitions for many other variables. It should be a
195 directory where LinkController can keep various data files.
196 EOF
197 }
198  
199 #verify index
200 #is it in order
201 #do keys match in reverse
202 #verify database
203 #are all indexed forms included
204  
205 defined $::links or do {
206 print STDOUT <<EOF;
207  
208 Can't check databases due to previous configuration errors. Giving up.
209 EOF
210 exit 1;
211 };
212  
213  
214 print STDOUT <<EOF;
215  
216 Checking through entire schedule and link database; this may take time
217 EOF
218  
219 #$::linkdbm =
220 tie %::links, "MLDBM", $::links, O_RDONLY, 0666, $::DB_HASH
221 or die $!;
222  
223 SCHED: {
224  
225 $::check_inverted=0;
226  
227 $::schedule or do {
228 print STDOUT <<EOF;
229  
230 Schedule file variable needs to be defined (\$::schedule) to allow the
231 link testing software to know what to do. This won't affect your
232 ability to make reports from other people's data
233 EOF
234 last SCHED;
235 };
236 -e $::schedule or do {
237 print STDOUT <<EOF;
238  
239 The file $::schedule should exist but
240 doesn't. You may want to consider using the program
241 build-schedule to create it. The \$::schedule variable controls its
242 location.
243 EOF
244 last SCHED;
245 };
246 my $sched;
247  
248 eval { $sched=new Schedule::SoftTime $::schedule; };
249  
250 $@ && do {
251 if ( $@ =~ m/Permission denied/ ) {
252 print STDOUT <<EOF;
253  
254 You don't seem to have access to the schedule file
255 $::schedule
256 If you want to test links yourself, you need to get access to it.
257 EOF
258 last SCHED;
259 } else {
260 print STDOUT <<EOF;
261  
262 If you want to test links, you need to get access to it.
263 Unknown error trying to access schedule file $::schedule
264 $@
265 EOF
266 }
267 last SCHED;
268 };
269  
270 my ($count, $past, $future);
271  
272 my ($time,$url) = $sched->first_item();
273  
274 defined $time or do {
275 print STDOUT <<EOF;
276  
277 The schedule is empty. Please try rebuilding it with Build Schedule;
278 EOF
279 last SCHED;
280 };
281  
282 $::check_inverted=1;
283 %::inverted=();
284  
285 ENTRY: while ( defined $time ) {
286 $time =~ m/^(?:\d+(?:\.\d*)?|\.\d+)$/ or $time < 1 or do {
287 print STDOUT <<EOF;
288  
289 Internal application error; illegal time value $time in schedule. Try
290 deleting the schedule and rebuilding with build-schedule.
291 EOF
292 last SCHED;
293 };
294  
295 exists $::links{$url} or do {
296 print STDOUT <<EOF;
297  
298 Minor application error; non existent link $url
299 scheduled for testing. If this recurs over a long period, please
300 investigate.
301 EOF
302 next ENTRY;
303 };
304  
305 $::inverted{$url}=$time;
306  
307 $time > ( $::now + 3 * 30 * 24 * 60 * 60 ) and do {
308 print STDOUT <<EOF;
309  
310 Link $url scheduled to be tested
311 more than three months into the future (now $::now sched $time)
312 which seems to be unreasonable. If you didn't do this using
313 build-schedule, then please investigate
314 EOF
315 };
316  
317 $count++;
318 $time > $::now ? $future++ : $past++;
319  
320 } continue {
321 ($time,$url) = $sched->next_item();
322 }
323  
324 $count < 10 and $past > $future * 0.3 and do {
325 print STDOUT <<EOF;
326  
327 A large proportion of the links in the database are scheduled in the
328 past. This may mean that you aren't running test-links often enough. You
329 may want to rebuild the schedule with build-schedule. If you have
330 very many links to check then you may need to adjust some
331 parameters... FIXME: which??
332  
333 Before running test-link again, you probably want to try running
334 build-schedule in order to avoid getting a pulst of activity.
335  
336 If you find test-link is running and testing continuously, and still
337 isn't testing all of your links often enough, then you have reached
338 the limit of the current design. You will have to look for ways to
339 improve it. Consider contributing (or paying a programmer to
340 contribute) a parallelised link checking routine.
341 EOF
342 };
343  
344 }
345  
346  
347  
348 while ( my ($url,$link) = each %::links ) {
349 $url =~ m/\%\+\+refresh_time/ and do {
350 $link =~ m/^(?:\d+(?:\.\d*)?|\.\d+)$/ or do {
351 print STDOUT <<EOF;
352  
353 Refresh time on database is invalid. Try running extract-links and if
354 it doesn't fix the problem then follow the bug reporting procedure
355 EOF
356 }
357 };
358 $url =~ m/\%\+\+/ && next; #unknown option maybe we should warn?
359  
360 ref $link or do {
361 print STDOUT <<EOF;
362 Database record for $url is $link,
363 not the reference expected.
364 EOF
365 next;
366 };
367  
368 my $ref=ref $link;
369 #accept subclasses too..
370 $ref =~ m/WWW::Link/ or do {
371 print STDOUT <<EOF;
372 Unexpected package $ref for link $url in database.
373 Expected WWW::Link.
374 EOF
375 next;
376 };
377  
378 my $lurl;
379 eval {
380 $lurl = $link->url();
381 };
382  
383 $@ && do {
384 print STDOUT <<EOF;
385 Something's wrong with the link for $url. \$link->url() doesn't work
386 EOF
387 next;
388 };
389  
390 $lurl eq $url or do {
391 print STDOUT <<EOF;
392 Link url $lurl does not match database key $url
393 EOF
394 };
395  
396 next unless $::check_inverted;
397  
398 exists $::inverted{$url} or do {
399 print STDOUT <<EOF;
400 Link url $url is not scheduled for testing. Use build-schedule to
401 rebuild the schedule. If the link should be scheduled, then please
402 investigate how it stopped being scheduled
403 EOF
404 };
405 }
406  
407  
« blib/script/build-schedule ↑ Summary blib/script/fix-link.cgi »