#use warnings;
use Cwd;
+# Subs imported from serverhelp module
+use serverhelp qw(
+ servername_str
+ );
+
# Variables and subs imported from sshhelp module
use sshhelp qw(
$sshdexe
my $pidfile = $HTTPPIDFILE;
my $port = $HTTPPORT;
my $ip = $HOSTIP;
- my $nameext;
+ my $proto = 'http';
+ my $ipvnum = 4;
+ my $idnum = 1;
+ my $srvrname;
my $fork = $forkserver?"--fork":"";
if($ipv6) {
# if IPv6, use a different setup
+ $ipvnum = 6;
$pidfile = $HTTP6PIDFILE;
$port = $HTTP6PORT;
$ip = $HOST6IP;
- $nameext="-ipv6";
}
# don't retry if the server doesn't work
return (0,0);
}
+ $srvrname = servername_str($proto, $ipvnum, $idnum);
+
my $pid = processexists($pidfile);
if($pid > 0) {
stopserver($pid);
if($httppid <= 0 || !kill(0, $httppid)) {
# it is NOT alive
- logmsg "RUN: failed to start the HTTP$nameext server\n";
+ logmsg "RUN: failed to start the $srvrname server\n";
stopserver("$pid2");
displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1;
# Server is up. Verify that we can speak to it.
my $pid3 = verifyserver("http", $ip, $port);
if(!$pid3) {
- logmsg "RUN: HTTP$nameext server failed verification\n";
+ logmsg "RUN: $srvrname server failed verification\n";
# failed to talk to it properly. Kill the server and return failure
stopserver("$httppid $pid2");
displaylogs($testnumcheck);
$pid2 = $pid3;
if($verbose) {
- logmsg "RUN: HTTP$nameext server is now running PID $httppid\n";
+ logmsg "RUN: $srvrname server is now running PID $httppid\n";
}
sleep(1);
my $RUNNING;
my $ip = $HOSTIP;
my $pidfile = $HTTPSPIDFILE;
+ my $proto = 'https';
+ my $ipvnum = 4;
+ my $idnum = 1;
+ my $srvrname;
if(!$stunnel) {
return 0;
if($ipv6) {
# not complete yet
+ $ipvnum = 6;
$ip = $HOST6IP;
}
return (0,0);
}
+ $srvrname = servername_str($proto, $ipvnum, $idnum);
+
my $pid = processexists($pidfile);
if($pid > 0) {
# kill previous stunnel!
if($httpspid <= 0 || !kill(0, $httpspid)) {
# it is NOT alive
- logmsg "RUN: failed to start the HTTPS server\n";
+ logmsg "RUN: failed to start the $srvrname server\n";
stopservers($verbose);
displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1;
# Server is up. Verify that we can speak to it.
my $pid3 = verifyserver("https", $ip, $HTTPSPORT);
if(!$pid3) {
- logmsg "RUN: HTTPS server failed verification\n";
+ logmsg "RUN: $srvrname server failed verification\n";
# failed to talk to it properly. Kill the server and return failure
stopserver("$httpspid $pid2");
displaylogs($testnumcheck);
# Here pid3 is actually the pid returned by the unsecure-http server.
if($verbose) {
- logmsg "RUN: HTTPS server is now running PID $httpspid\n";
+ logmsg "RUN: $srvrname server is now running PID $httpspid\n";
}
sleep(1);
my $port;
my $pidfile;
my $ip=$HOSTIP;
- my $nameext;
my $cmd;
my $flag;
+ my $ipvnum = 4;
+ my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
+ my $srvrname;
if($proto eq "ftp") {
- $port = $id?$FTP2PORT:$FTPPORT;
- $pidfile = $id?$FTP2PIDFILE:$FTPPIDFILE;
+ $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
+ $pidfile = ($idnum>1)?$FTP2PIDFILE:$FTPPIDFILE;
if($ipv6) {
# if IPv6, use a different setup
+ $ipvnum = 6;
$pidfile = $FTP6PIDFILE;
$port = $FTP6PORT;
$ip = $HOST6IP;
- $nameext="-ipv6";
}
}
elsif($proto eq "pop3") {
return (0,0);
}
+ $srvrname = servername_str($proto, $ipvnum, $idnum);
+
my $pid = processexists($pidfile);
if($pid > 0) {
stopserver($pid);
$flag .= $debugprotocol?"-v ":"";
$flag .= "-s \"$srcdir\" ";
my $addr;
- if($id) {
- $flag .="--id $id ";
+ if($idnum > 1) {
+ $flag .="--id $idnum ";
}
if($ipv6) {
$flag .="--ipv6 ";
if($ftppid <= 0 || !kill(0, $ftppid)) {
# it is NOT alive
- logmsg "RUN: failed to start the ". uc($proto) ."$id$nameext server\n";
+ logmsg "RUN: failed to start the $srvrname server\n";
stopserver("$pid2");
displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1;
# Server is up. Verify that we can speak to it.
my $pid3 = verifyserver($proto, $ip, $port);
if(!$pid3) {
- logmsg "RUN: ". uc($proto) ."$id$nameext server failed verification\n";
+ logmsg "RUN: $srvrname server failed verification\n";
# failed to talk to it properly. Kill the server and return failure
stopserver("$ftppid $pid2");
displaylogs($testnumcheck);
$pid2 = $pid3;
if($verbose) {
- logmsg "RUN: ". uc($proto) ."$id$nameext server is now running".
- " PID $ftppid\n";
+ logmsg "RUN: $srvrname server is now running PID $ftppid\n";
}
sleep(1);
my $RUNNING;
my $ip = $HOSTIP;
my $pidfile = $FTPSPIDFILE;
+ my $proto = 'ftps';
+ my $ipvnum = 4;
+ my $idnum = 1;
+ my $srvrname;
if(!$stunnel) {
return 0;
if($ipv6) {
# not complete yet
+ $ipvnum = 6;
$ip = $HOST6IP;
}
return (0,0);
}
+ $srvrname = servername_str($proto, $ipvnum, $idnum);
+
my $pid = processexists($pidfile);
if($pid > 0) {
# kill previous stunnel!
if($ftpspid <= 0 || !kill(0, $ftpspid)) {
# it is NOT alive
- logmsg "RUN: failed to start the FTPS server\n";
+ logmsg "RUN: failed to start the $srvrname server\n";
stopservers($verbose);
displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1;
# Server is up. Verify that we can speak to it.
my $pid3 = verifyserver("ftps", $ip, $FTPSPORT);
if(!$pid3) {
- logmsg "RUN: FTPS server failed verification\n";
+ logmsg "RUN: $srvrname server failed verification\n";
# failed to talk to it properly. Kill the server and return failure
stopserver("$ftpspid $pid2");
displaylogs($testnumcheck);
# Here pid3 is actually the pid returned by the unsecure-ftp server.
if($verbose) {
- logmsg "RUN: FTPS server is now running PID $ftpspid\n";
+ logmsg "RUN: $srvrname server is now running PID $ftpspid\n";
}
sleep(1);
# check for pidfile
my $pidfile = $TFTPPIDFILE;
my $ip=$HOSTIP;
- my $nameext;
my $cmd;
+ my $proto = 'tftp';
+ my $ipvnum = 4;
+ my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
+ my $srvrname;
if($ipv6) {
# if IPv6, use a different setup
+ $ipvnum = 6;
$pidfile = $TFTP6PIDFILE;
$port = $TFTP6PORT;
$ip = $HOST6IP;
- $nameext="-ipv6";
}
# don't retry if the server doesn't work
return (0,0);
}
+ $srvrname = servername_str($proto, $ipvnum, $idnum);
+
my $pid = processexists($pidfile);
if($pid > 0) {
stopserver($pid);
# start our server:
my $flag=$debugprotocol?"-v ":"";
$flag .= "-s \"$srcdir\" ";
- if($id) {
- $flag .="--id $id ";
+ if($idnum > 1) {
+ $flag .="--id $idnum ";
}
if($ipv6) {
$flag .="--ipv6 ";
if($tftppid <= 0 || !kill(0, $tftppid)) {
# it is NOT alive
- logmsg "RUN: failed to start the TFTP$id$nameext server\n";
+ logmsg "RUN: failed to start the $srvrname server\n";
stopserver("$pid2");
displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1;
# Server is up. Verify that we can speak to it.
my $pid3 = verifyserver("tftp", $ip, $port);
if(!$pid3) {
- logmsg "RUN: TFTP$id$nameext server failed verification\n";
+ logmsg "RUN: $srvrname server failed verification\n";
# failed to talk to it properly. Kill the server and return failure
stopserver("$tftppid $pid2");
displaylogs($testnumcheck);
$pid2 = $pid3;
if($verbose) {
- logmsg "RUN: TFTP$id$nameext server is now running PID $tftppid\n";
+ logmsg "RUN: $srvrname server is now running PID $tftppid\n";
}
sleep(1);
my $port = $SSHPORT;
my $socksport = $SOCKSPORT;
my $pidfile = $SSHPIDFILE;
+ my $proto = 'ssh';
+ my $ipvnum = 4;
+ my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
+ my $srvrname;
# don't retry if the server doesn't work
if ($doesntrun{$pidfile}) {
return (0,0);
}
+ $srvrname = servername_str($proto, $ipvnum, $idnum);
+
my $pid = processexists($pidfile);
if($pid > 0) {
stopserver($pid);
if($sshpid <= 0 || !kill(0, $sshpid)) {
# it is NOT alive
- logmsg "RUN: failed to start the SSH server\n";
+ logmsg "RUN: failed to start the $srvrname server\n";
stopserver("$pid2");
$doesntrun{$pidfile} = 1;
return (0,0);
my $pid3 = verifyserver("ssh",$ip,$port);
if(!$pid3) {
- logmsg "RUN: SSH server failed verification\n";
+ logmsg "RUN: $srvrname server failed verification\n";
# failed to fetch server pid. Kill the server and return failure
stopserver("$sshpid $pid2");
$doesntrun{$pidfile} = 1;
}
if($verbose) {
- logmsg "RUN: SSH server is now running PID $pid2\n";
+ logmsg "RUN: $srvrname server is now running PID $pid2\n";
}
return ($pid2, $sshpid);
my $ip=$HOSTIP;
my $port = $SOCKSPORT;
my $pidfile = $SOCKSPIDFILE;
+ my $proto = 'socks';
+ my $ipvnum = 4;
+ my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
+ my $srvrname;
# don't retry if the server doesn't work
if ($doesntrun{$pidfile}) {
return (0,0);
}
+ $srvrname = servername_str($proto, $ipvnum, $idnum);
+
my $pid = processexists($pidfile);
if($pid > 0) {
stopserver($pid);
--- /dev/null
+#***************************************************************************
+# _ _ ____ _
+# Project ___| | | | _ \| |
+# / __| | | | |_) | |
+# | (__| |_| | _ <| |___
+# \___|\___/|_| \_\_____|
+#
+# Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://curl.haxx.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# $Id$
+#***************************************************************************
+
+package serverhelp;
+
+use strict;
+use warnings;
+use Exporter;
+
+
+#***************************************************************************
+# Global symbols allowed without explicit package name
+#
+use vars qw(
+ @ISA
+ @EXPORT_OK
+ );
+
+
+#***************************************************************************
+# Inherit Exporter's capabilities
+#
+@ISA = qw(Exporter);
+
+
+#***************************************************************************
+# Global symbols this module will export upon request
+#
+@EXPORT_OK = qw(
+ servername_id
+ servername_str
+ servername_canon
+ );
+
+
+#***************************************************************************
+# Return server name string formatted for presentation purposes
+#
+sub servername_str {
+ my ($proto, $ipver, $idnum) = @_;
+
+ $proto = uc($proto) if($proto);
+ die "unsupported protocol: $proto" unless($proto &&
+ ($proto =~ /^(((FTP|HTTP|IMAP|POP3|SMTP|TFTP)S?)|(SOCKS|SSH))$/));
+
+ $ipver = (not $ipver) ? 'ipv4' : lc($ipver);
+ die "unsupported IP version: $ipver" unless($ipver &&
+ ($ipver =~ /^(4|6|ipv4|ipv6|-ipv4|-ipv6)$/));
+ $ipver = ($ipver =~ /6$/) ? '-IPv6' : '';
+
+ $idnum = 1 if(not $idnum);
+ die "unsupported ID number: $idnum" unless($idnum &&
+ ($idnum =~ /^(\d+)$/));
+ $idnum = '' unless($idnum > 1);
+
+ return "${proto}${idnum}${ipver}";
+}
+
+
+#***************************************************************************
+# Return server name string formatted for identification purposes
+#
+sub servername_id {
+ my ($proto, $ipver, $idnum) = @_;
+ return lc(servername_str($proto, $ipver, $idnum));
+}
+
+
+#***************************************************************************
+# Return server name string formatted for file name purposes
+#
+sub servername_canon {
+ my ($proto, $ipver, $idnum) = @_;
+ my $string = lc(servername_str($proto, $ipver, $idnum));
+ $string =~ tr/-/_/;
+ return $string;
+}
+
+
+#***************************************************************************
+# End of library
+1;
+