httpsserver.pl 2.0 KB

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