1
0
mirror of https://github.com/moparisthebest/curl synced 2025-01-09 13:08:00 -05:00

Attempt to enhance stunnel 3.X logging

This commit is contained in:
Yang Tse 2009-11-27 19:52:56 +00:00
parent 6f273b1a5f
commit a240f4d1df

View File

@ -10,13 +10,6 @@ use Cwd;
my $stunnel = "stunnel"; my $stunnel = "stunnel";
#
# -p pemfile
# -P pid dir
# -d listen port
# -r target port
# -s stunnel path
my $verbose=0; # set to 1 for debugging my $verbose=0; # set to 1 for debugging
my $port = 8991; # just our default, weird enough my $port = 8991; # just our default, weird enough
@ -71,7 +64,11 @@ my $pidfile="$path/.$proto.pid"; # stunnel process pid file
my $logfile="$path/log/stunnel.log"; # stunnel log file my $logfile="$path/log/stunnel.log"; # stunnel log file
my $loglevel=5; my $loglevel=5;
# find out version info for the given stunnel binary my $ssltext = uc($proto) ." SSL/TLS:";
#***************************************************************************
# Find out version info for the given stunnel binary
#
my $ver_major; my $ver_major;
my $ver_minor; my $ver_minor;
foreach my $veropt (('-version', '-V')) { foreach my $veropt (('-version', '-V')) {
@ -84,28 +81,41 @@ foreach my $veropt (('-version', '-V')) {
} }
last if($ver_major); last if($ver_major);
} }
my $cmd;
if(!$ver_major) { if(!$ver_major) {
if(-x "$stunnel" && ! -d "$stunnel") { if(-x "$stunnel" && ! -d "$stunnel") {
print "unknown stunnel version\n"; print "$ssltext Unknown stunnel version\n";
} }
else { else {
print "no stunnel\n"; print "$ssltext No stunnel\n";
} }
exit; exit 1;
} }
elsif($ver_major < 4) {
#***************************************************************************
# Build command to execute depending on stunnel version
#
my $cmd;
if($ver_major < 4) {
# stunnel version less than 4.00 # stunnel version less than 4.00
$cmd = "$stunnel -p $certfile -P $pidfile -d $port -r $target_port "; $cmd = "$stunnel -p $certfile -P $pidfile -d $port -r $target_port -f ";
$cmd .= ">$logfile 2>&1"; $cmd .= "-D $loglevel >$logfile 2>&1";
if($verbose) {
print uc($proto) ." server (stunnel $ver_major.$ver_minor)\n";
print "cmd: $cmd\n";
print "pem cert file: $certfile\n";
print "pid file: $pidfile\n";
print "log file: $logfile\n";
print "log level: $loglevel\n";
print "listen on port: $port\n";
print "connect to port: $target_port\n";
}
} }
else { else {
# stunnel version 4.00 or later # stunnel version 4.00 or later
$cmd = "$stunnel $conffile "; $cmd = "$stunnel $conffile ";
$cmd .= ">$logfile 2>&1"; $cmd .= ">$logfile 2>&1";
# stunnel configuration file # stunnel configuration file
open(STUNCONF, ">$conffile") || exit 1; if(open(STUNCONF, ">$conffile")) {
print STUNCONF " print STUNCONF "
CApath = $path CApath = $path
cert = $certfile cert = $certfile
@ -118,30 +128,39 @@ else {
accept = $port accept = $port
connect = $target_port connect = $target_port
"; ";
close STUNCONF; if(!close(STUNCONF)) {
} print "$ssltext Error closing file $conffile\n";
exit 1;
if($verbose) { }
print uc($proto)." server: $cmd\n"; }
else {
print " print "$ssltext Error writing file $conffile\n";
CApath = $path exit 1;
cert = $certfile }
pid = $pidfile if($verbose) {
debug = $loglevel print uc($proto) ." server (stunnel $ver_major.$ver_minor)\n";
output = $logfile print "cmd: $cmd\n";
foreground = yes print "CApath = $path\n";
print "cert = $certfile\n";
[curltest] print "pid = $pidfile\n";
accept = $port print "debug = $loglevel\n";
connect = $target_port print "output = $logfile\n";
"; print "foreground = yes\n";
print "\n";
print "[curltest]\n";
print "accept = $port\n";
print "connect = $target_port\n";
}
} }
#***************************************************************************
# Set file permissions on certificate pem file. # Set file permissions on certificate pem file.
#
chmod(0600, $certfile) if(-f $certfile); chmod(0600, $certfile) if(-f $certfile);
#***************************************************************************
# Run stunnel.
#
my $rc = system($cmd); my $rc = system($cmd);
$rc >>= 8; $rc >>= 8;