fireartist has asked for the wisdom of the Perl Monks concerning the following question:
#!/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
|
|---|