#!/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 "
$site
\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"."/
";
my $line1;
foreach $line1 (@dir1) {
if ($line1 =~ /www|htdocs|cgi-bin/) {
print "$line1
";
}
}
print "/home/"."$username"."/www/
";
#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
";
}
}
#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 "Illegal password entered for $site";
&finish;
}
$password{$username} = $password;
}
}
}
sub askForPasswords {
#get this scripts url
my $url = $q->url(-absolute=>1);
#start form
print "
| "."$site"." | "; print $q->password_field(-name=>"$username", -value=>'', -size=>8); print " |
| "; print $q->submit; print " | "; print $q->reset; print " |