Hi,
First a quick explanation of my problem, then an explanation of what the script is actually doing.

When I point my browser (NN 6 mac) at the script, without sending input, it displays what it's supposed to (incuding the closing HTML tags), but never finishes loading.
The status says "Document: Done", but the progress bar is only half-way across, and the animated "N" continues to animate (forever).

So, to put it simply, is there something wrong with my script, or is it just a silly browser bug?

I've tested the script with my usual array of browsers, namely
mac - IE 4.0, 4.5, 5.0, 5.02, 5.1 - NN 4.75, 4.76, 6 - Opera 5.0
p.c. - IE 5.0, 6.0 - Opera 6.01
And the only one that doesn't seem to finish loading properly is NN 6 on mac.

Reason: my host is making changes to all accounts, including changing email username changes and directory structure changes amongst others.
This script ftp's into every site I manage to see if the directory structure has changed, so that when it does, I can upload revised versions of all scripts and then phone my customers to help them change their outlook express settings.
I have this script displayed in a browser in the background continually, and frequently hit 'refresh' and see if anything's different.

The script checks that it's running under a secure server, if not it prints an error.
When the script is called without input, it prints a table of all the websites defined in @sites and an adjascent password box so that I can enter the passwords for the sites I want to check. When the passwords are submitted to the script, it ftp's into each server and prints me a page showing, for each site, particular files in particular folders.

The script works in all respects other than the initial page doesn't seem to finish loading properly. I'm currently using the script with no 'apparant' problems, but I'd just like to know whether I'm exiting the script properly (Would it be possible for me to exit improperly? :)).
Is the 'finish' sub I'm using bad practise?

And of course, I welcome and comments/criticisms about the security and implementation of my coding.

Thanks a lot,
fireartist
#!/usr/bin/perl -wT use strict; use CGI; use Net::FTP; my $q = new CGI; print $q->header, $q->start_html; # Disable uploads $CGI::DISABLE_UPLOADS = 1; # Maximum number of bytes per post $CGI::POST_MAX = 1; #comment out the next line when live #use CGI::Carp qw(fatalsToBrowser); # ###Fill usernames and passwords my @sites = ("site1.com", "site2.com", "site3.com"); my %username = ( "site1com" => "usernam1", "site2com" => "usernam2", "site3com" => "usernam3"); # ###Start program my ($ftp, $error, $site, %password); &Hashes; #check this is running on a secure server unless ( $q->https() ) { print $q->center('NOT secure'); &finish; } #have the passwords been sent? if ( $q->param('pass') ) { &sortPasswords; &mainStuff; } else { &askForPasswords; } &finish; exit 0; # ### sub mainStuff { foreach $site (@sites) { #format site name for use with hashes $_ = $site; $_ =~ s/-//g; $_ =~ s/\.//g; my $username = $username{$_}; if ( $q->param("$username") ) { my $password = $password{$username}; print "<br><b>$site</b><br> \n"; #create new ftp object $ftp = Net::FTP->new("$site", Debug => 0); #login to ftp $ftp->login("$username", "$password") or &pushError("ftp login error with $site"); #get dir listing my @dir1 = $ftp->dir() or &pushError("ftp error with dir on $site"); #print out the dir listing print "/home/"."$username"."/<br>"; my $line1; foreach $line1 (@dir1) { if ($line1 =~ /www|htdocs|cgi-bin/) { print "$line1<br>"; } } print "/home/"."$username"."/www/<br>"; #get dir listing my @dir2 = $ftp->dir('www') or &pushError("ftp error with dir on $site"); #print out the dir listing my $line2; foreach $line2 (@dir2) { if ($line2 =~ /htdocs|cgi-bin/) { print "$line2<br>"; } } #disconnect from ftp $ftp->quit or &pushError("error disconnecting from $site"); } } } sub sortPasswords { foreach $site (@sites) { my $password; #format site name for use with hashes $_ = $site; $_ =~ s/-//g; $_ =~ s/\.//g; my $username = $username{$_}; #check if password was sent if ( $q->param("$username") ) { $password = $q->param("$username"); unless ( $password =~ /^[\w]*$/ ) { print "<b>Illegal password entered for $site</b>"; &finish; } $password{$username} = $password; } } } sub askForPasswords { #get this scripts url my $url = $q->url(-absolute=>1); #start form print "<table align=\"center\">"; print $q->start_form(-method=>"POST", -action=>"$url"); print $q->hidden(-name=>'pass', -default=>1); #print password boxes foreach $site (@sites) { #format site name for use with hashes $_ = $site; $_ =~ s/-//g; $_ =~ s/\.//g; my $username = $username{$_}; print "<tr><td>"."$site"."</td><td>"; print $q->password_field(-name=>"$username", -value=>'', -size=>8); print "</td><tr>"; } #print submit and reset buttons print "<tr><td>"; print $q->submit; print "</td><td>"; print $q->reset; print "</td></tr>"; #end form print $q->endform; print "</table>"; } sub checkHashes { foreach $site ( @sites ) { $_ = $site; $_ =~ s/-//g; $_ =~ s/\.//g; unless ( defined ($username{$_}) ) { print "error with username hash at $site <br> \n"; $error = 1; } } if ( defined ($error) ) { &finish } } sub pushError { print "<br><b>$_[0]</b><br> \n"; } sub finish { print $q->end_html; exit 0; }

2002-03-06 - Edited by dvergin to fix ampersands per user request


In reply to Exiting improperly, or NN6 error? by fireartist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.