link-checker commit: Make Net::IP and other modules required for restricting access to

changeset:   105:af56785d43b6
user:        ville
date:        Sat Nov 06 11:39:28 2004 +0000
files:       Makefile.PL bin/checklink docs/checklink.html etc/checklink.conf
description:
Make Net::IP and other modules required for restricting access to
private IP addresses optional.


diff -r 1c80a38b1f3c -r af56785d43b6 Makefile.PL
--- a/Makefile.PL	Sat Nov 06 11:24:13 2004 +0000
+++ b/Makefile.PL	Sat Nov 06 11:39:28 2004 +0000
@@ -25,7 +25,7 @@
                      Config::General => 2.06,
                      HTML::Parser    => 3.00,
                      LWP             => 5.66,
-                     Net::IP         => 0,
+                     Net::IP         => 0, # Optional, see the docs.
                      Term::ReadKey   => 2.00,
                      Time::HiRes     => 0,
                      URI             => 0,
diff -r 1c80a38b1f3c -r af56785d43b6 bin/checklink
--- a/bin/checklink	Sat Nov 06 11:24:13 2004 +0000
+++ b/bin/checklink	Sat Nov 06 11:39:28 2004 +0000
@@ -5,7 +5,7 @@
 # (c) 1999-2004 World Wide Web Consortium
 # based on Renaud Bruyeron's checklink.pl
 #
-# $Id: checklink,v 4.8 2004-10-12 21:54:11 ville Exp $
+# $Id: checklink,v 4.9 2004-11-06 11:39:28 ville Exp $
 #
 # This program is licensed under the W3C(r) Software License:
 #       http://www.w3.org/Consortium/Legal/copyright-software
@@ -92,9 +92,6 @@
 use HTML::Parser    3.00 qw();
 use HTTP::Request        qw();
 use HTTP::Response       qw();
-use Net::hostent         qw(gethostbyname);
-use Net::IP              qw();
-use Socket               qw(inet_ntoa);
 use Time::HiRes          qw();
 use URI                  qw();
 use URI::Escape          qw();
@@ -112,7 +109,7 @@
   $PACKAGE       = 'W3C Link Checker';
   $PROGRAM       = 'W3C-checklink';
   $VERSION       = '4.0';
-  my ($cvsver)   = q$Revision: 4.8 $ =~ /(\d+[\d\.]*\.\d+)/;
+  my ($cvsver)   = q$Revision: 4.9 $ =~ /(\d+[\d\.]*\.\d+)/;
   $REVISION      = sprintf('version %s [%s] (c) 1999-2004 W3C',
                            $VERSION, $cvsver);
   $AGENT         = sprintf('%s/%s [%s] %s',
@@ -213,6 +210,22 @@
                          $Cfg{Allow_Private_IPs} : $cmdline,
   );
 undef $cmdline;
+
+unless ($Opts{Allow_Private_IPs}) {
+  eval {
+    require Net::IP;
+    require Socket;
+    Socket->import('inet_ntoa');
+    require Net::hostent;
+  };
+  if ($@) {
+    die <<".EOF.";
+Allow_Private_IPs is false; this feature requires the Net::IP, Socket, and
+Net::hostent modules:
+$@
+.EOF.
+  }
+}
 
 # Global variables
 # What is our query?
@@ -1778,19 +1791,19 @@
 sub ip_allowed ($)
 {
   my ($uri) = @_;
+  return undef if $Opts{Allow_Private_IPs}; # Short-circuit
+
   my $hostname = undef;
   eval { $hostname = $uri->host() }; # Not all URIs implement host()...
   return undef unless $hostname;
 
   my $addr = my $iptype = my $resp = undef;
-  if (my $host = gethostbyname($hostname)) {
+  if (my $host = Net::hostent::gethostbyname($hostname)) {
     $addr = inet_ntoa($host->addr()) if $host->addr();
     if ($addr && (my $ip = Net::IP->new($addr))) {
       $iptype = $ip->iptype();
     }
   }
-  $iptype = 'PUBLIC'
-    if ($iptype && $iptype eq 'PRIVATE' && $Opts{Allow_Private_IPs});
   if ($iptype && $iptype ne 'PUBLIC') {
     $resp = HTTP::Response->new(403,
     'Checking non-public IP address disallowed by link checker configuration');
diff -r 1c80a38b1f3c -r af56785d43b6 docs/checklink.html
--- a/docs/checklink.html	Sat Nov 06 11:24:13 2004 +0000
+++ b/docs/checklink.html	Sat Nov 06 11:39:28 2004 +0000
@@ -6,7 +6,7 @@
     <title>W3C Link Checker Documentation</title>
     <link rev="made" href="mailto:www-validator@w3.org" />
     <style type="text/css" media="all">@import "linkchecker.css";</style>
-    <meta name="revision" content="$Id: checklink.html,v 1.23 2004-11-06 11:24:13 ville Exp $" />
+    <meta name="revision" content="$Id: checklink.html,v 1.24 2004-11-06 11:39:28 ville Exp $" />
   </head>
 
   <body>
@@ -138,7 +138,7 @@
           <li><a href="http://search.cpan.org/dist/Config-General/">Config-General</a> (optional, version 2.06 or newer; required only for reading the (optional) configuration file)</li>
 	  <li><a href="http://search.cpan.org/dist/HTML-Parser/">HTML-Parser</a> (version 3.00 or newer)</li>
 	  <li><a href="http://search.cpan.org/dist/libwww-perl/">libwww-perl</a> (version 5.66 or newer; version 5.70 or newer recommended, except for 5.76 which has a bug that may cause the link checker follow redirects to <code>file:</code> URLs)</li>
-          <li><a href="http://search.cpan.org/dist/Net-IP/">Net-IP</a></li>
+          <li><a href="http://search.cpan.org/dist/Net-IP/">Net-IP</a> (optional but recommended; required for restricting access to <a href="http://www.ietf.org/rfc/rfc1918.txt">private IP addresses</a>)</li>
           <li><a href="http://search.cpan.org/dist/TermReadKey/">TermReadKey</a> (optional but recommended; required only in command line mode for password input)</li>
 	  <li><a href="http://search.cpan.org/dist/Time-HiRes/">Time-HiRes</a></li>
 	  <li><a href="http://search.cpan.org/dist/URI/">URI</a></li>
@@ -253,7 +253,7 @@
         alt="Valid XHTML 1.0!" /></a>
       <a title="Send Feedback for the W3C Link Checker"
         href="http://validator.w3.org/feedback.html">The W3C Validator Team</a><br />
-      $Date: 2004-11-06 11:24:13 $
+      $Date: 2004-11-06 11:39:28 $
     </address>
     <p class="copyright">
       <a rel="Copyright" href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> &copy; 1994-2004
diff -r 1c80a38b1f3c -r af56785d43b6 etc/checklink.conf
--- a/etc/checklink.conf	Sat Nov 06 11:24:13 2004 +0000
+++ b/etc/checklink.conf	Sat Nov 06 11:39:28 2004 +0000
@@ -1,6 +1,6 @@
 #
 # Configuration file for the W3C Link Checker
-# $Id: checklink.conf,v 1.5 2004-06-01 21:55:54 ville Exp $
+# $Id: checklink.conf,v 1.6 2004-11-06 11:39:28 ville Exp $
 #
 # See Config::General(3) for the syntax; 'SplitPolicy' is 'equalsign' here.
 #
@@ -20,7 +20,7 @@
 
 #
 # Allow_Private_IPs is a boolean flag (1/0) for specifying whether checking of
-# links on non-public IP addresses is allowed.
+# links to non-public RFC 1918 IP addresses is allowed.
 #
 # The default, ie. not specifying the value here means that checking links
 # on non-public IP addresses is disabled when checklink runs as a CGI script,

Received on Thursday, 5 August 2010 14:47:13 UTC