Application Source Code

Analyse Page /cgi-bin/analpage.pl

Return to the notes... - Run the program - View dwd.pm module code - View dwd.conf external config file

#!/usr/local/bin/perl -w
#
#  analpage.pl    (c) Andy Belcher DandyWebDesign 2006
#
#  Building on another application; getpage.pl, this will return the
#  source code of the requested URL and parse the HTML into an
#  accessible data-structure.
#
######################################################################
use strict;
use CGI qw(:all);
use LWP::UserAgent;
use dwd;

#  INITIALISE PROGRAM ENVIRONMENT
my %G;      #  Stores global values within the program.
my %arg;    #  Stores the CGI form/URL parameters
my @parameters  = qw(requrl);
initprogenv(\%G,\%arg,\@parameters);

#  DEFINE PROGRAM SPECIFIC VALUES
$G{'pagetitle'}    = "Analyse Page";
$G{'title'}        = "$G{'title'} $G{'pagetitle'}";
$G{'returnurl'}    = "/tech/web/webanalpage.shtml";
$G{'sourceurl'}    = "/tech/web/analpage_source.html";
$G{'pmsourceurl'}  = "/tech/web/dwdpm_source.html";
$G{'requrl'}       = "";
my $error          = "";
my @html           = qw();
#  GET PAGE
if($arg{'requrl'})
  {$G{'requrl'} = $arg{'requrl'};
  if(useragent_fetchpage(\%G)) {parsehtml(\@html,$G{'uacontent'});}
  else {$error = "<p class=\"loud\"><strong>ERROR!</strong> $G{'uaerror'}</p>";}
  }
else {$arg{'requrl'} = "http://dwd/tech/web/web_index.shtml";}

  OUTPUT PAGE
&do_topsection;
print<<HERE;
<div class="main">
<p>Enter a valid URL below...</p>
<p><form method="post" action="$G{'progname'}">
<input type="text" name="requrl" size="50" value="$arg{'requrl'}" />
<br /><input type="submit" value="Get the page..." class="button"
  /></form></p>
</div><!--main-->
$error
HERE
  my $ctr = 0;
  if(@html)
    {print "<table style=\"font-size:8pt;font-family:courier,lucida console,verdana,georgia,arial,Comic Sans MS,courier,lucida console,sans serif;\">";
    foreach my $el (@html)
      {print "<tr><td>$ctr</td>";
      if(($ctr/2 == int($ctr/2)) || ($el =~ /^\s*<\s*!DOCTYPE/gsix))
        {$el = dehtml_string($el);
        $el =~ s/\n/<strong>\\n<\/strong>\n/gsix;
        print "<td>&nbsp;</td><td><code>".$el."</code></td></tr>\n";
        }
      else
        {if($el =~ m/^<\s*\//)
          {print "<td><strong>".dehtml_string($el)."</strong></td><td>&nbsp;</td></tr>\n";}
        elsif($el =~ m/^<!--/)
          {print "<td>&nbsp;</td><td>".dehtml_string($el)."</td></tr>\n";}
        else
          {my %attrib;parseattrib(\%attrib,$el);
          print "<td><strong>$attrib{'element'}</strong></td><td>&nbsp;</td></tr>\n";
          foreach my $at (sort keys %attrib)
            {if($at eq "element") {next;}
            print "<tr><td>&nbsp;</td><td>$at</td><td>$attrib{$at}</td></tr>\n";
            }
          }
        }
      $ctr++;
      }
    print "</table>\n";
    }
  &do_bottom;
#  END PROGRAM
#
#  SUB-ROUTINES
######################################################################
sub do_top {do_std_head(\%G);print "</head>\n<body>\n";do_std_header(\%G);}

######################################################################
sub do_bottom {do_std_bottom($G{'footerssi'});exit;}

######################################################################
sub do_topsection
  {&do_top;print<<HERE;
<div id="pathbar"><script type="text/javascript">drawPathBar(
  'tech','/tech/tech.shtml','To the Technical pages index...',
  'web applications','/tech/web/web_index.shtml','To the web applications index...',
  'program notes','$G{'returnurl'}','The accompanying notes for this program...',
  'analpage.pl');//</script></div><!--pathbar-->
<div id="content">
<div id="rightbar"><dl class="nbar">
<dt>Application Links</dt>
  <dd><a href="$G{'returnurl'}"
    title="Return to the documentation for this application..."
    >Program Notes</a></dd>
  <dd><a href="$G{'sourceurl'}"
    title="View the source code for this application..."
    >source code</a></dd>
  <dd><a href="$G{'pmsourceurl'}"
    title="View the perl module source code..."
    >dwd.pm source</a></dd>
</dl></div><!--rightbar-->
<h2>$G{'pagetitle'}</h2>
HERE
  }

######################################################################
#  EOF