httpserver.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at http://curl.haxx.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. #***************************************************************************
  23. BEGIN {
  24. @INC=(@INC, $ENV{'srcdir'}, '.');
  25. }
  26. use strict;
  27. use warnings;
  28. use serverhelp qw(
  29. server_pidfilename
  30. server_logfilename
  31. );
  32. my $verbose = 0; # set to 1 for debugging
  33. my $port = 8990; # just a default
  34. my $ipvnum = 4; # default IP version of http server
  35. my $idnum = 1; # dafault http server instance number
  36. my $proto = 'http'; # protocol the http server speaks
  37. my $pidfile; # http server pid file
  38. my $logfile; # http server log file
  39. my $connect; # IP to connect to on CONNECT
  40. my $srcdir;
  41. my $gopher = 0;
  42. my $flags = "";
  43. my $path = '.';
  44. my $logdir = $path .'/log';
  45. while(@ARGV) {
  46. if($ARGV[0] eq '--pidfile') {
  47. if($ARGV[1]) {
  48. $pidfile = $ARGV[1];
  49. shift @ARGV;
  50. }
  51. }
  52. elsif($ARGV[0] eq '--logfile') {
  53. if($ARGV[1]) {
  54. $logfile = $ARGV[1];
  55. shift @ARGV;
  56. }
  57. }
  58. elsif($ARGV[0] eq '--srcdir') {
  59. if($ARGV[1]) {
  60. $srcdir = $ARGV[1];
  61. shift @ARGV;
  62. }
  63. }
  64. elsif($ARGV[0] eq '--ipv4') {
  65. $ipvnum = 4;
  66. }
  67. elsif($ARGV[0] eq '--ipv6') {
  68. $ipvnum = 6;
  69. }
  70. elsif($ARGV[0] eq '--gopher') {
  71. $gopher = 1;
  72. }
  73. elsif($ARGV[0] eq '--port') {
  74. if($ARGV[1] =~ /^(\d+)$/) {
  75. $port = $1;
  76. shift @ARGV;
  77. }
  78. }
  79. elsif($ARGV[0] eq '--connect') {
  80. if($ARGV[1]) {
  81. $connect = $ARGV[1];
  82. shift @ARGV;
  83. }
  84. }
  85. elsif($ARGV[0] eq '--id') {
  86. if($ARGV[1] =~ /^(\d+)$/) {
  87. $idnum = $1 if($1 > 0);
  88. shift @ARGV;
  89. }
  90. }
  91. elsif($ARGV[0] eq '--verbose') {
  92. $verbose = 1;
  93. }
  94. else {
  95. print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n";
  96. }
  97. shift @ARGV;
  98. }
  99. if(!$srcdir) {
  100. $srcdir = $ENV{'srcdir'} || '.';
  101. }
  102. if(!$pidfile) {
  103. $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
  104. }
  105. if(!$logfile) {
  106. $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
  107. }
  108. $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
  109. $flags .= "--gopher " if($gopher);
  110. $flags .= "--connect $connect " if($connect);
  111. $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
  112. if($verbose) {
  113. print STDERR "RUN: server/sws $flags\n";
  114. }
  115. exec("server/sws $flags");