-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathlinklint
More file actions
executable file
·3647 lines (2900 loc) · 108 KB
/
linklint
File metadata and controls
executable file
·3647 lines (2900 loc) · 108 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/local/bin/perl
#==========================================================================
# linklint - a fast link checker and web site maintenance tool.
# Copyright (C) 1997 James B. Bowlin. All rights reserved.
#
# Linklint is SHAREWARE
#
# Introductory Price: $20 Individual, $100 Commercial
# Send check, money-order, or purchase order to:
#
# Bowlin Software and Consulting
# 484 Lake Park Ave. #317
# Oakland, CA 94610 USA
# Fax: 510-832-0847
#
# Try linklint for free. If you want to use it regularly then please
# send the appropriate fee to the address above. This one-time fee
# will entitle you to technical support and unlimited upgrades.
#
# This is a total rewrite of Rick Jansen's 4/15/96 version of webxref.
# Thanks to Celeste Stokely, Scott Perry, Patrick Meyer, Brian Kaminer
# David Hull, Stephan Petersen, Todd O'Boyle and Vittal Aithal
# for many excellent suggestions.
#
# Bugs, comments, suggestions welcome: bowlin@sirius.com
# Updates available at http://www.goldwarp.com/bowlin/linklint/
#========================================================================
$version = "2.1";
$date = "July 24, 1997";
$prog = "linklint";
$Usage0 = 'Usage: linklint @file @@file -flag [option] linkset linkset ...';
$Usage = $Usage0 . q~
-root dir Set server root to "dir" (default ".").
-host name[:port] Use "name" as domain name of site.
-http Check site remotely via http (requires -host).
-net Check status of remote http links found in site.
-help Show help. (Use "-help -out file" for complete usage).
Multi File Output:
-doc dir Write many (.txt) output files in "dir" directory.
Single File Output:
-error print errors -out file direct output to "file"
-warn print warnings -xref cross reference
-list print files found -forward sort by referring file
linkset:
home page only: / (default) root dir only: /#
entire site: /@ and all subdirs: /#/#
specific links: /link1 /link2 ... "sub" dir and below: /sub/@
~;
$Help2 = q~
Site Checking:
-case Check filename case (Windows/Dos only, local only).
-orphan List all unused (orphan) files (local only).
-index file Use "file" as default index file (local only).
-skip linkset Don't check html files that match linkset.
-ignore linkset Ignore all files matching linkset.
-limit n Only check up to n html files (default 500).
-map /a[=/b] Subsitute leading /a with /b (for serverside image maps).
-local linkset Always get files that match linkset locally.
Network:
-timeout t Timeout remote links after t seconds (default 15).
-delay d Delay d seconds between requests to same host (default 0).
-redirect Follow <meta> redirects in remote urls.
-proxy host[:port] Send remote http requests through a proxy server.
-password realm user:password
Authorize access to "realm".
Remote Status Cache:
-netmod Put urls in cache and report modified status.
-netset ... and update last modified status in the cache.
-retry Only check urls that had host failures.
-flush Remove urls from cache that aren't currently being checked.
-checksum Exaustive check of modified status.
-cache dir Read/save "linklint.url" cache file in this directory.
Output:
-quiet Don't print progress on screen.
-silent Don't print summary on screen.
-docbase exp Overrides defaults for linking html output back to site.
-textonly Only write .txt files in -doc directory.
-htmlonly Erase .txt files after .html output files are written.
Debug Flags:
-db1 Debug input, linkset expressions.
-db2 Show every file that gets checked (not just html).
-db3 Debug parser. Print tags and links found.
-db4 not used
-db5 not used
-db6 Detail last-modified status for remote urls.
-db7 Print brief debug information checking remote urls.
-db8 Print headers while checking remote urls.
-db9 Generate random http errors.
@cmndfile Read command line options from "cmndfile".
@@file Check status of remote http links in "file".
Linklint is SHAREWARE
Introductory Price: $20 Individual, $100 Commercial
Send check, money-order, or purchase order to:
Bowlin Software and Consulting
484 Lake Park Ave. #317
Oakland, CA 94610 USA
Fax: 510-832-0847
Try linklint for free. If you want to use it regularly then please
send the appropriate fee to the address above. This one-time fee
will entitle you to technical support and unlimited upgrades.
~;
$Usage1 =
qq~$prog $version $date. SHAREWARE by Jim Bowlin (bowlin\@sirius.com)\n~;
$Usage2 =
qq~Updates available at http://www.goldwarp.com/bowlin/linklint/\n\n~;
$Usage3 = qq~
Use $prog with no arguments for standard usage.
Use "$prog -help -out file" to save ALL options in a file.
~;
$Help = q~
Examples:
1) linklint -doc linkdoc -root dir
Checks home page. Output files go in "linkdoc" directory.
2) linklint -doc linkdoc -root dir /@
Checks all files under "dir". Output files go in "linkdoc" directory.
3) linklint -doc linkdoc -root dir /@ -net
Checks site as (2). Then checks all http links found in site.
4) linklint -doc linkdoc -root dir /#
Like (2) but only checks files in the root directory.
5) linklint -doc linkdoc -host host /@ -http
Same as (2) but checks site using http instead of file system.
6) linklint -doc linkdoc @@linkdoc/remote.txt
Check remote link status without rechecking entire site.
~;
$ErrUsage = qq~
Use $prog with no arguments for simple usage.
Use "$prog -help -out file" to save a list of ALL options in a file.
~;
#------------------ Start up values ----------------------------------
#----- Files to try in case of a directory reference like "/"
@DefIndex = (
'home.html', 'index.html', 'index.shtml', 'index.htm', 'index.cgi',
'wwwhome.html', 'welcome.html',
);
$DefCaseSens = '';
#----- File extensions and floormats
$HtmlExts = 'html|shtml|htm';
$AnyCgi = '\?|^/cgi-bin/|(\.(cgi|pl)(/|$))';
$StandardMaps = '(/imagemap|/cgi-(b|w)in/(imagemap.exe|htimage))';
@fileformat = (
"cgi::$AnyCgi",
'default index::\(default\)',
"html::\.($HtmlExts)\$",
'map::\.map$',
'image::\.(gif|jpg|jpeg|tif|tiff|pic|pict|hdf|ras|xbm)$',
'text::\.txt$',
'audio::\.(au|snd|wav|aif|aiff|midi|mid)$',
'video::\.(mpg|mpeg|avi|qt|mov)$',
'shockwave::\.dcr$',
'applet::\.class$',
'other::unknown',
);
@filesplit = (
'found %3d file%s::.',
'found %3d default index%es::\/$',
);
@lostsplit = (
'ERROR %3d missing file%s::.',
'ERROR %3d missing director%y::\/$',
);
foreach (@fileformat) {
($name,$data) = split(/::/);
push(@filesplit,"found %3d $name file%s::$data");
push(@lostsplit,"ERROR %3d missing $name file%s::$data");
}
@schema = ("http", "https", 'ftp', 'javascript', 'mailto', 'gopher',
'file','news', 'view-source', 'about', 'unknown');
@schemesplit = ( "found %3d other link%s::.");
foreach (@schema) {
push(@schemesplit, "found %3d $_ link%s::^$_:");
}
#--------------- Output Floormats ----------------------------------
@UrlHtml = (
'urlsum',
'urlindex',
'urllog',
"Index of Linklint results for remote urls",
);
@SiteHtml = (
'summary',
'linklint',
'log',
"Index of Linklint results ",
);
#---- flags used in the printout lists below
$LIST = 001; $NOXR = 010; $URLDOC = 0100;
$WARN = 002; $XREF = 020; # $URLDOC = 0200;
$ERR = 004; $FWD = 040;
$PrnFlag = 0;
$SumFlag = $LIST | $ERR | $WARN | $NOXR;
$DocFlag = $LIST | $ERR | $WARN | $NOXR | $XREF | $FWD | $URLDOC;
@SumPrint = (0, 0, 1, $SumFlag);
@SiteForm = (
# file; %Data; $mask; program; @parameters
"dir; DirList; 001; 1; found %3d director%y with files; 0",
"file; FileList; 011; 2; filesplit; 0",
"fileX; FileList; 021; 2; filesplit; 2",
"fileF; Forward; 041; 1; found %3d file%s with forward links; 1; contains %d link%s:",
"remote; ExtLink; 011; 2; schemesplit; 0",
"remoteX; ExtLink; 021; 2; schemesplit; 2",
"anchor; Anchor; 011; 1; found %3d named anchor%s; 0",
"anchorX; Anchor; 021; 1; found %3d named anchor%s; 2",
"imgmap; ImgMap; 011; 1; found %3d named image map%s; 0",
"imgmapX; ImgMap; 021; 1; found %3d named image map%s; 2",
"ignore; Ignored; 011; 1; ----- %3d ignored file%s; 0",
"ignoreX; Ignored; 021; 1; ----- %3d ignored file%s; 2",
"action; Action; 011; 1; ----- %3d action%s skipped; 0",
"actionX; Action; 021; 1; ----- %3d action%s skipped; 2",
"skipped; Skipped; 012; 1; ----- %3d file%s skipped; 0",
"skipX; Skipped; 022; 1; ----- %3d file%s skipped; 2",
"orphan; OrphList; 001; 1; ----- %3d orphan%s; 0",
"warn; WarnList; 012; 1; warn %3d warning%s; 0",
"warnX; WarnList; 022; 1; warn %3d warning%s; 2; occurred in",
"warnF; WarnF; 042; 1; warn %3d file%s with warnings; 1; had %d warning%s",
"case; BadCase; 014; 1; ERROR %3d file%s mismatched case; 0",
"caseX; BadCase; 024; 1; ERROR %3d file%s mismatched case; 2",
"caseF; CaseF; 044; 1; ERROR %3d file%s with mismatched link(s); 1; had %d mismatched link%s",
"error; LostFile; 014; 2; lostsplit; 0",
"errorX; LostFile; 024; 2; lostsplit; 2",
"errorF; ErrF; 044; 1; ERROR %3d file%s had broken links; 1; had %d broken link%s",
"errorA; LostAnch; 014; 1; ERROR %3d missing named anchor%s; 0",
"errorAX; LostAnch; 024; 1; ERROR %3d missing named anchor%s; 2",
"errorM; LostMap; 014; 1; ERROR %3d missing named image map%s; 0",
"errorMX; LostMap; 024; 1; ERROR %3d missing named image maps%s; 2",
"httpfail; HttpFail; 022; 3; ----- %3d link%s; 0; failed via http",
"httpok; HttpOk; 022; 3; ----- %3d link%s; 0; ok via http",
"mapped; Mapped; 022; 1; ----- %3d link%s %w mapped; 1; mapped to",
);
@UrlForm = (
"urlok; UrlOk; 0001; 3; found %3d url%s; 0; %w ok",
"urlmoved; UrlMoved; 0002; 3; ----- %3d url%s; 0; moved",
"urlhost; HostFail; 0104; 3; ERROR %3d host%s; 0; failed; %d host%s:",
"urlfail; UrlFail; 0014; 3; ERROR %3d url%s; 0; failed",
"urlfailX; UrlFailX; 0024; 3; ERROR %3d url%s; 2; failed",
"urlfailF; UrlFailF; 0044; 1; ERROR %3d file%s with failed urls; 1; had %d failed url%s",
"urlskip; UrlWarn; 0012; 3; warn %3d url%s; 0; not checked",
"urlmod; UrlMod; 0000; 3; found %3d url%s; 0; %w modified",
"urlwarn; WarnList; 0012; 1; warn %3d warning%s; 0",
"urlwarnX; WarnList; 0022; 1; warn %3d warning%s; 2; in %d url%s",
"urlwarnF; WarnF; 042; 1; warn %3d url%s with warnings; 1; had %d warning%s",
);
#----- Command Line Input
$MiscFlags = 'http|netmod|netset|flush|retry|redirect|textonly|htmlonly' .
'|case|error|forward|help|list|net|quiet|silent|orphan|warn|xref';
$HashOpts = 'local|index|ignore|map|skip|javascript';
$FullOpts = 'delay|doc|host|limit|out|root|timeout|proxy|docbase|cache';
%CheckedIn = ();
#---------------------------------------------------------------------------
# Misc. startup values
#---------------------------------------------------------------------------
$Arg{'timeout'} = 15; # how long to wait for a response
$Arg{'delay'} = 0; # how long to delay between requests
$Arg{'VERSION'} = $version;
$Headline = "#" . "-" x 60 . "\n"; # used to print lists
$ATTRIB = q~\s*=\s*("([^"]*)"|'([^']*)'|([^\s"']+))~;
#----- prevent warnings
%HttpOk = %HttpFail = %CaseF = %WarnF = ();
%UrlWarn = %Ignored = %UrlFailX = %UrlFailF = %LostMap = ();
$UrlOk = $Abort = 0;
###########################################################################
#
# Main code starts here
#
###########################################################################
@ARGV || do { print $Usage1, $Usage2, $Usage; exit; };
$Arg{'DOS'} = $Dos = $^O ?
($^O =~ /win32/i ? 1 : '') :
($ENV{'windir'} ? 1 : '') ;
$pwdprog = $Dos ? 'cd' : 'pwd'; # program to pwd
$HOME = &GetCwd; # this is done twice.
#---------------- Command Line Arguments -------------------------
@infiles = &ReadArgs(@ARGV);
foreach(@HttpFiles) {
push(@infiles, &ReadHttp($_));
}
$Arg{'doc'} && ! $DB{1} && do {
($DocDir = $Arg{'doc'} ) =~ s#\\#\/#g;
$DocDir =~ m#^/# || ($DocDir = "$HOME/$DocDir" );
-d $DocDir || mkdir($DocDir, 0777) ||
&Error(qq~invalid output directory: "$DocDir"~, 'sys');
$SiteLog = "$DocDir/log.txt";
$UrlLog = "$DocDir/urllog.txt";
$LogProgress++;
};
$Arg{'out'} && !$DB{1} && do {
$OutLog = $Arg{'out'};
$OutLog =~ m#^/# || ($OutLog = "$HOME/$OutLog" );
};
$Arg{'help'} && do {
$Arg{'out'} && do {
&LogFile($Arg{'out'});
print $Usage1, $Usage2, $Usage, $Help2, $Help;
exit;
};
print $Help, $Usage3;
exit;
};
($LogDir = $Arg{'cache'} || $ENV{'LINKLINT'} || $ENV{'HOME'} || $HOME) =~ s#/$##;
$StatFile = $LogDir . "/linklint.url";
#----- Link Spec's
$Arg{'case'} && do {
$Dos || &Error("can only check case under Windows/Dos");
$CheckCase++;
};
$IgnoreCase = ($Dos && ! $CheckCase && ! $Arg{'http'} ) ? 1 : 0;
foreach(@infiles) {
s#^http:#http:#i && (push(@CheckUrls, $_), next);
$_ = "/$_" unless m#^/#;
$IgnoreCase && tr/A-Z/a-z/;
$LinkSet{$_}++;
};
%LinkSet || do {
%LinkSet = ( '/', '1');
$Hints{ 'Use a linkset of /@ to check entire site.'}++;
};
foreach(keys %LinkSet) {
m%[\@\#]% || ($Seeds{$_}++, next); # literals
m%^([^\@\#]*/)% && $Seeds{$1}++; # directories
}
%LinkSet && ! %Seeds && do {
print STDERR "\nError: Could not form any seeds from the linksets.\n";
exit;
};
$LinkSet = &LinkSet("linkset", *LinkSet);
#----- Flags and Options
&WantNumber($Arg{'limit'}, "-limit");
&WantNumber($Arg{'timeout'}, "-timeout");
&WantNumber($Arg{'delay'}, "-delay");
$Arg{'error'} && ($PrnFlag |= ($NOXR | $ERR));
$Arg{'warn'} && ($PrnFlag |= ($NOXR | $WARN));
$Arg{'list'} && ($PrnFlag |= ($NOXR | $LIST));
$Arg{'xref'} && ($PrnFlag |= $XREF, $PrnFlag &= ~ $NOXR);
$Arg{'forward'} && ($PrnFlag |= $FWD, $PrnFlag &= ~ ($NOXR | $XREF));
$Arg{'quiet'} && $Quiet++;
$Arg{'silent'} && $Silent++;
$DB{2} && $DbLink++;
$DB{3} && $DbP++;
$CacheNet = $Arg{'retry'} || $Arg{'flush'} || $Arg{'netmod'}
|| $Arg{'netset'};
$CheckNet = $Arg{'netmod'} || $Arg{'netset'} || $Arg{'net'};
$CacheNet && !$CheckNet && !@CheckUrls && do {
$Arg{'flush'} &&
print STDERR "ERROR: -flush requires -net or -netmod or -netset\n";
$Arg{'retry'} &&
print STDERR "ERROR: -retry requires -net or -netmod or -netset\n";
print STDERR $ErrUsage;
exit;
};
$Limit = $Arg{'limit'} = $Arg{'limit'} || 500; # check at most 500 files
$Arg{'root'} && do {
$DB{1} || chdir($Arg{'root'}) ||
&Error(qq~invalid root directory: "$Arg{'root'}"~, 'sys');
&GetCwd;
$HeaderRoot = $CWD;
};
$ServerRoot = $CWD;
$IgnoreCase && $ServerRoot =~ tr/A-Z/a-z/;
$ServerHost = $Arg{'host'} || '';
#---- get base for links in html files in -doc directory
$DocDir && do {
$DocBase = defined $Arg{'docbase'} ? $Arg{'docbase'} :
$Arg{'http'} ? "http://$ServerHost" :
$Dos ? "file:///$DosDrive|$ServerRoot" : "file://$ServerRoot";
};
$Arg{'tilde'} && do {
($ServerTilde = $Arg{'tilde'} ) =~ s/#/\$1/g;
$ServerTilde = '"' . $ServerTilde . '"';
};
%IGNORE && do {
$Ignore = &LinkSet('ignore', *IGNORE);
};
%INDEX && do {
grep(m/[A-Z]/, @DefIndex = keys %INDEX) && $DefCaseSens++;
$Arg{'index'} = join(" ", @DefIndex);
};
%JAVASCRIPT && do {
foreach( keys %JAVASCRIPT) {
&SetProtoJS($_);
}
};
%MAP && do {
local(@maps);
foreach ( keys %MAP ) {
$NewMap{$_} = s/=([^=]*)$// ? $1 : '';
push(@maps, &Regular($_) );
}
$Arg{'map'} = $ServerMap = join( '|', @maps);
};
!%LOCAL && $LOCAL{'@.map'}++; # default to *.map
%LOCAL && ($Local = &LinkSet("local", *LOCAL));
%SKIP && ($Skip = &LinkSet("skip", *SKIP));
$Arg{'http'} && do {
$ServerHost || &Error("must set -host when using -http");
&HttpInit(*Arg, *DB, *PASSWORD, 'spider');
$Http++;
($Arg{'case'} || $Arg{'orphan'} ) &&
$Hints{"-case and -orphan don't work in -http mode."}++;
};
$DB{1} && do {
foreach ( sort keys %Arg) {
printf "%10s %s\n", $_, &Abbrev(60, $Arg{$_});
}
%PASSWORD || exit;
print "Passwords:\n";
foreach (sort keys %PASSWORD) {
print qq~"$_" $PASSWORD{$_}\n~;
}
exit;
};
#--------------- Local/Remote Site Checking ---------------------
! @CheckUrls && do {
&LogFile( $OutLog || $SiteLog);
&Progress( $Http ? "\nChecking links via http://$ServerHost"
: "\nChecking links locally in $ServerRoot");
&Progress("that match: " . join(" ", keys %LinkSet));
&Progress(&Plural(scalar keys %Seeds, "%d seed%s: ") .
join(" ", sort keys %Seeds));
$Time = -time;
&SetBase("/");
foreach (sort keys %Seeds) {
$_ = &UniqueUrl($_);
&Progress("\nSeed: $_");
&WasCached($_, "\n") || &LinkLint(0, $_, "\n");
}
$Time += time;
$DirList = keys %DirList;
&CheckOrphan(*DirList,*OrphList,*BadCase, $Arg{'orphan'}, $CheckCase);
&ProcessLocal;
&PrintOutput(*SiteForm, *SiteSummary, $DocDir, @SiteHtml);
};
$CheckNet && push(@CheckUrls, grep( m#^http://#i, keys %ExtLink));
@CheckUrls || exit;
#--------------- Remote Url Checking ---------------------
%WarnList = ();
&LogFile( $OutLog || $UrlLog);
&HttpInit(*Arg, *DB, *PASSWORD, 'checkonly');
$CacheNet && &Http'OpenCache($StatFile);
$Arg{'flush'} && &Http'FlushCache(@CheckUrls);
$Arg{'retry'} &&
! (@CheckUrls = &Http'Recheck(@CheckUrls)) &&
((print STDERR "No urls need to be retried.\n"), exit);
%UrlStatus = &Http'CheckURLS(@CheckUrls);
&Http'WriteCaches;
($CheckedUrls = keys %UrlStatus) || exit;
&Http'StatusMsg(*UrlStatus, *UrlOk, *UrlFail, *UrlWarn);
$UrlRetry = &Http'RetryCount(*UrlStatus);
foreach( keys %ExtLink) {
$UrlFail{$_} || next;
$UrlFailX{$_} = $UrlFail{$_};
$UrlFailXX{"$_&cr; $UrlFailX{$_}"} = $ExtLink{$_};
}
&HashUnique(*WarnList);
&InvertKeys(*WarnList, *WarnF);
$UrlFailedF = &InvertKeys(*UrlFailXX, *UrlFailF);
&Http'OtherStatus(*UrlMod, *HostFail, *UrlMoved, *UrlRedirect);
&PrintOutput(*UrlForm, *UrlSummary, $DocDir, @UrlHtml);
exit;
###########################################################################
#
# Site Checking Routines
#
###########################################################################
#--------------------------------------------------------------------------
# UniqueUrl($url)
#
# Make a URL Unique. Decode "/../" and "." in the path of full URL's
# Do same for relative URL's But also completes the path
# if it does not start with a "/".
#--------------------------------------------------------------------------
sub UniqueUrl
{
local($_) = @_;
local($scheme, $host, $local);
$DbP && $ErrTag && print $ErrTag;
s#^([\w\.\-\+]+):## && do { # specified scheme
($scheme = $1) =~ tr/A-Z/a-z/; # lower case scheme
$scheme =~ /^https?$|^ftp$/ || do {
$DbP && print "==> LINK $scheme:$_\n\n";
return "$scheme:$_";
};
};
s#^//([^/]*)## && ($host = $1); # specified host
($scheme && $host) || ($scheme = $BaseScheme) && do {
$host || $BasePath || m#^/# || ($host = $_, $_ = '');
$host || ($host = $BaseHost) && m#^/# || ($_ = $BasePath . $_);
};
(($host && $host ne $ServerHost) || ($scheme && $scheme !~ /http/i )) ||
do {
m#^/# || ($_ = $CurPath . $_);
s/\#.*$//; # strip local anchor
$local++;
};
m/&/ && do {
s/&/&/g; # expand & etc
s/</</g;
s/>/>/g;
s/"/"/g;
s/ / /g;
s/&#(\d\d?\d?);/pack("c",$1)/ge;
};
s#\\#/#g && &Warn("\\ converted to / in $_[0]", $link);
#----- make path unique by expanding /.. and /.
m#/\.# && do {
while (s#/\./#/#) {;} # /./ -> /
while (s#/[^/]*/\.\./#/#) {;} # /dir/../ -> /
s#/.$##; # trailing /.
s#/[^/]*/\.\.$#/#; # trailing /dir/../ -> /
};
$local || do {
$scheme = $scheme || 'http';
$host = $host ? "//$host" : '';
$DbP && print "==> LINK $scheme:$host$_\n\n";
return "$scheme:$host$_";
};
$IgnoreCase && tr/A-Z/a-z/;
$DbP && $ErrTag && print "==> LOCAL LINK $_\n\n";
$_ || '/';
}
#--------------------------------------------------------------------------
# WasCached($link, $referer)
#
# Does some quick checks on $link. Return 1 if we are done with it.
# Return 0 if it should be checked further. Also bails out early
# If we know we will not have to process any further.
#--------------------------------------------------------------------------
sub WasCached
{
local($link, $referer) = @_;
$referer ne "\n" && &AppendList(*Forward, $referer, $link);
$LostFile{$link} &&
(($LostFile{$link} .= "\n$referer"), return '1');
$FileList{$link} && do {
$Skipped{$link} && ($Skipped{$link} .= "\n$referer");
$FileList{$link} .= "\n$referer";
return '1';
};
$Action{$link} && return '1';
$link =~ m#^(\w+):# && do {
&AppendList(*ExtLink, $link, $referer);
return '1';
};
$Ignore && $link =~ m/$Ignore/o && do {
&AppendList(*Ignored, $link, $referer);
return '1';
};
'';
}
#--------------------------------------------------------------------------
# LinkLint($level, $link, $referer)
#
# $level keeps track of depth of recursion.
# $link is the URL or file to check
# $referer is the file that referenced $link.
# Recursively get all referenced files from a file.
# NOTE: $link is assumed to be anchored at the server root.
#--------------------------------------------------------------------------
sub LinkLint
{
local($level, $link, $referer) = @_;
local(%newlinks);
$DbLink && &Progress("getting $link");
($ServerMap || $ServerTilde) && do {
($link = &MapLink($link, $referer)) || return '';
};
$link = $Http && $link !~ m/$Local/o ?
&LinkRemote($link, $referer) :
&LinkLocal($link, $referer);
$link || return;
$Forward{$link} = "\n"; # this primes forward
#----- recurse into all links found in this file
foreach $new (keys %newlinks) {
&WasCached($new, $link) || &LinkLint($level+1, $new, $link);
}
}
#--------------------------------------------------------------------------
# LinkLocal($link, $referer)
#
# Does the local equivalent of what the server does.
#--------------------------------------------------------------------------
sub LinkLocal
{
local($link, $referer) = @_;
$link =~ s/\?.*$//; # strip local queries
local($lastdir); # for directory listings
-d "$ServerRoot$link" && $link !~ m#/$# && ( $link .= '/' );
local($path) = $link; # for index files
if ( $link =~ m#/$#) {
if (&LookupDir($link) ) {
$path = &LookupDir($link);
$PrintAddenda{$link} = "[file: $path]";
}
else {
$LASTDIR || do {
&AppendList(*LostFile, $link, $referer);
return '';
};
$lastdir = '1';
&Warn("index file not found", $link);
$PrintAddenda{$link} = "[directory listing]";
}
}
elsif ( -f _ ) {
((stat(_))[2] & 4 == 0) && &Warn("not world readable", $link);
}
else {
&AppendList(*LostFile, $link, $referer);
$ServerTilde || $link =~ m#(^/~[^/]*)# &&
$Hints{qq~use -http to resolve "$1" links.~}++;
$ServerMap || $link =~ /^($StandardMaps)/o &&
$Hints{qq~use "-map $1" to resolve imagemaps.~}++;
return '';
}
&AppendList(*FileList, $link, $referer);
&CacheDir($link);
$lastdir && do {
&StopRecursion($link, $referer) && return '';
&Progress("checking $link");
%newlinks = %LASTDIR;
return $link;
};
$path =~ /\.($HtmlExts|map)$/io || return ''; # only parse html & .map
&StopRecursion($link, $referer) && return '';
&Progress("checking $link");
open($path, "$ServerRoot$path") || do {
&Warn(qq~could not open file: "$ServerRoot$path"\n~, 'sys');
return '';
};
$path =~ /\.map$/i ?
&ParseMap($path, *newlinks) :
&ParseHtml($path, $link, *newlinks);
close($path);
$link;
}
#--------------------------------------------------------------------------
# MapLink($link, $referer)
#
# Resolves my server maps for $link. Returns new $link or '' if
# the new link was already cached.
#--------------------------------------------------------------------------
sub MapLink
{
local($link, $referer) = @_;
local(%checked, $old);
$old = $link;
while ( ($ServerMap && $link =~ s#^($ServerMap)#$NewMap{$1}#o) ||
($ServerTilde && $link =~ s#^/~([^/]*)#$ServerTilde#oee) ) {
$checked{$link}++ || next;
&Warn("infinite mapping loop", $link);
return $link;
}
($old eq $link || "$old/" eq $link) && return $link;
$PrintAddenda{$link} = "($old)";
$Mapped{$old} = $link;
$DbLink && &Progress("mapped $old\n => $link");
&WasCached($link, $referer) && return '';
$link;
}
#--------------------------------------------------------------------------
# StopRecursion($link, $referer)
#
# Stops recursion as needed. Also records skipped files.
#--------------------------------------------------------------------------
sub StopRecursion
{
local($link, $referer) = @_;
$Parsed{$link} && return '1';
$Abort || $link !~ /$LinkSet/o || ($Skip && $link =~ /$Skip/o) ||
++$Parsed > $Limit || do {
$Parsed{$link}++;
return '';
};
&AppendList(*Skipped, $link, $referer);
push(@Skipped, $link);
&Progress("----- $link");
return '1';
}
#--------------------------------------------------------------------------
# LinkRemote($link, $referer)
#
# Checks $link via http. If it is an html file it is parsed and
# the results go into local lists maintained by LinkLink().
#--------------------------------------------------------------------------
sub LinkRemote
{
local($oldlink, $referer) = @_;
#---- check url and parse into local arrays in LinkLint().
$Fetched{$oldlink}++ && return '';
($flag, $link) = &Http'Parse($ServerHost, $oldlink, $referer, *newlinks);
$flag == -5000 && return ''; # user interrupt
$flag == -4000 && do { # moved to different host
&AppendList(*ExtLink, $link, $referer);
return '';
};
$link ne $oldlink && $link ne "$oldlink/" && do {
$PrintAddenda{$link} = "($oldlink)";
$Mapped{$oldlink} = $link;
};
$flag || return ''; # new url was already cached
local($msg) = &Http'ErrorMsg($flag);
&Http'FlagWarn($flag) && do {
&AppendList(*Ignored, $link, $referer);
&AppendList(*HttpFail, $link, $msg);
&Warn($msg, $link);
return '';
};
&Http'FlagOk($flag) || do {
&AppendList(*LostFile, $link, $referer);
&AppendList(*HttpFail, $link, $msg);
return '';
};
&AppendList(*HttpOk, $link, $msg);
$flag == -2000 || return '';
$link;
}
#--------------------------------------------------------------------------
# CacheDir($link)
#
# Save a list of directories for orphan and case checking.
#--------------------------------------------------------------------------
sub CacheDir
{
local($dir) = @_;
$dir =~ s#/[^/]*$##;
local($absdir) = $ServerRoot . $dir;
$dir = $dir || '(root)';
($DirList{$dir} || $LostDir{$dir}) && return;
&AppendList( -d $absdir ? *DirList : *LostDir, $dir, "\n");
}
#--------------------------------------------------------------------------
# ParseHtml(*HANDLE, $link, *list)
#
# Extracts all (?) links from the file by setting %list{link} = "1".
# Links are expanded to full unique URL's or paths.
# %Anchor named anchors found
# %ImgMap named image maps found
# %WantAnch named anchors to find
# %WantMap named image maps to find
#--------------------------------------------------------------------------
sub ParseHtml
{
local(*HANDLE, $link, *list) = @_;
local($tag, $code, $temp, $url, $att, $term, $anch);
&SetBase($link);
$DbP && print "\n" , '=' x 60, "\nFILE $link\n\n";
$/ = "<"; # use "<" as newline separator
TAG:
while (<HANDLE>) {
/^\!\-\-/ && do {
while ($_ !~ /\-\-\!?>/ ) { # ignore tags inside comments
($_ = <HANDLE>) && next;
&Warn(q~missing end comment "-->"~, $link);
last TAG;
}
next TAG;
};
m/^(\w+)(\s*("[^"]*"|'[^']*'|[^>"'])*)(>?)/ || next;
$tag = $1;
$att = $2;
$term = $4;