#!/usr/bin/perl -I/opt/SUNWstade/lib
#<copyright>
# ----------------------------------------------------------
# Sun Proprietary/Confidential Code
# Copyright 2001, Sun Microsystems, Inc. All rights reserved.
# ----------------------------------------------------------
#</copyright>

use Util;
use LWP::UserAgent;

if ($ARGV[0] && defined($ARGV[1]) ) {
  my $URLS;
  print "Testing tokens on $ARGV[0]...\n";
  $ip = $ARGV[0];
  $parm = $ARGV[1];
  if($ARGV[2] ne "all"){
    $FILE = $ARGV[2] ? "$ARGV[2].htm" : "elemprop.htm";
    push(@URLS, "http://guest\@$ip/$FILE?unitIndex=$parm");
  }else{
    @URLS = getAllURLS($ip);
  }
    
} else {
  print "\n  Usage: testt3 <ip> <0/1> [page_name|all]   # enter 0 or 1 for unit1 or unit2 \n";
  print "  Example: testt3 diag210 0 elemprop \n\n";
  exit;
}


if (!Util->testIp($ip,3)) {
  print "ERROR: Cannot ping $ip\n";
  exit;
}


foreach $url (@URLS) {
print "URL=$url \n";
$time = time;

$ua = new LWP::UserAgent;

#  $ua->agent("AgentName/0.1 " . $ua->agent);
#  $ua->proxy('http' => "http://cache-brm.Central.Sun.COM:8080");
#  $ua->credentials("http://diag210.central", "NobleGUI", "guest", "");

my $req = new HTTP::Request(GET => $url);

my $res = $ua->request($req);

if ($res->is_success) {
  $s = length($res->content);
#  print "GOT " . length($res->content);
  print $res->content;
} else {
  print "$FILE FAILED!";
}

print "bytes in " . (time - $time) . "secs\n";
}

sub getAllURLS{
  my ($name, $other)=@_;
  my @URLS;
  my @FILES =
    ("enclmap.htm",
    "frudata.htm",
    "fruprop.htm",
    "linkstat.htm",
    "log.htm",
    "logprop.htm",
    "loopinf.htm",
    "lun.htm",
    "monitor.htm",
    "ntp.htm",
    "portperf.htm",
    "portprop.htm",
    "schedule.htm",
    "slice.htm",
    "sysdata.htm",
    "sysdate.htm",
    "sysoper.htm",
    "sysperf.htm",
    "sysprop.htm",
    "system.htm",
    "timeprop.htm",
    "vol.htm",
    "voloper.htm",
    "volperf.htm",
    "volprop.htm",
    "htmltoc"
  );
  foreach $file (@FILES){
    push(@URLS, "http://guest\@$name/$file");
  }
    push(@URLS, "http://guest\@$name/elemprop.htm?unitIndex=0");
    push(@URLS, "http://guest\@$name/elemprop.htm?unitIndex=1");
    push(@URLS, "http://guest\@$name/elemprop.htm?unitIndex=2");
    push(@URLS, "http://guest\@$name/elemprop.htm?unitIndex=3");
    push(@URLS, "http://guest\@$name/elemprop.htm?unitIndex=4");
    push(@URLS, "http://guest\@$name/elemprop.htm?unitIndex=5");
  return @URLS;
}

