httpsserver.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/perl
  2. #
  3. # $Id: httpsserver.pl,v 1.6 2003/10/29 16:27:43 bagder Exp $
  4. # This is the HTTPS server designed for the curl test suite.
  5. #
  6. # It is actually just a layer that runs stunnel properly.
  7. use strict;
  8. my $stunnel = "stunnel";
  9. #
  10. # -p pemfile
  11. # -P pid dir
  12. # -d listen port
  13. # -r target port
  14. # -s stunnel path
  15. my $verbose=0; # set to 1 for debugging
  16. my $port = 8433; # just our default, weird enough
  17. my $target_port = 8999; # test http-server port
  18. my $path = `pwd`;
  19. chomp $path;
  20. my $srcdir=$path;
  21. do {
  22. if($ARGV[0] eq "-v") {
  23. $verbose=1;
  24. }
  25. if($ARGV[0] eq "-w") {
  26. return 0; # return success, means we have stunnel working!
  27. }
  28. elsif($ARGV[0] eq "-r") {
  29. $target_port=$ARGV[1];
  30. shift @ARGV;
  31. }
  32. elsif($ARGV[0] eq "-s") {
  33. $stunnel=$ARGV[1];
  34. shift @ARGV;
  35. }
  36. elsif($ARGV[0] eq "-d") {
  37. $srcdir=$ARGV[1];
  38. shift @ARGV;
  39. }
  40. elsif($ARGV[0] =~ /^(\d+)$/) {
  41. $port = $1;
  42. }
  43. } while(shift @ARGV);
  44. my $conffile="$path/stunnel.conf"; # stunnel configuration data
  45. my $certfile="$srcdir/stunnel.pem"; # stunnel server certificate
  46. my $pidfile="$path/.https.pid"; # stunnel process pid file
  47. open(CONF, ">$conffile") || return 1;
  48. print CONF "
  49. CApath=$path
  50. cert = $certfile
  51. pid = $pidfile
  52. debug = 0
  53. output = /dev/null
  54. foreground = yes
  55. [curltest]
  56. accept = $port
  57. connect = $target_port
  58. ";
  59. close CONF;
  60. #system("chmod go-rwx $conffile $certfile"); # secure permissions
  61. # works only with stunnel versions < 4.00
  62. my $cmd="$stunnel -p $certfile -P $pidfile -d $port -r $target_port 2>/dev/null";
  63. # use some heuristics to determine stunnel version
  64. my $version_ge_4=system("$stunnel -V 2>&1|grep '^stunnel.* on '>/dev/null 2>&1");
  65. # works only with stunnel versions >= 4.00
  66. if ($version_ge_4) { $cmd="$stunnel $conffile"; }
  67. if($verbose) {
  68. print "HTTPS server: $cmd\n";
  69. }
  70. system($cmd);
  71. unlink $conffile;