httpserver.pl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 https://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. push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
  25. push(@INC, ".");
  26. }
  27. use strict;
  28. use warnings;
  29. use serverhelp qw(
  30. server_pidfilename
  31. server_logfilename
  32. );
  33. my $verbose = 0; # set to 1 for debugging
  34. my $port = 8990; # just a default
  35. my $unix_socket; # location to place a listening Unix socket
  36. my $ipvnum = 4; # default IP version of http server
  37. my $idnum = 1; # default http server instance number
  38. my $proto = 'http'; # protocol the http server speaks
  39. my $pidfile; # http server pid file
  40. my $logfile; # http server log file
  41. my $connect; # IP to connect to on CONNECT
  42. my $srcdir;
  43. my $gopher = 0;
  44. my $flags = "";
  45. my $path = '.';
  46. my $logdir = $path .'/log';
  47. while(@ARGV) {
  48. if($ARGV[0] eq '--pidfile') {
  49. if($ARGV[1]) {
  50. $pidfile = $ARGV[1];
  51. shift @ARGV;
  52. }
  53. }
  54. elsif($ARGV[0] eq '--logfile') {
  55. if($ARGV[1]) {
  56. $logfile = $ARGV[1];
  57. shift @ARGV;
  58. }
  59. }
  60. elsif($ARGV[0] eq '--srcdir') {
  61. if($ARGV[1]) {
  62. $srcdir = $ARGV[1];
  63. shift @ARGV;
  64. }
  65. }
  66. elsif($ARGV[0] eq '--ipv4') {
  67. $ipvnum = 4;
  68. }
  69. elsif($ARGV[0] eq '--ipv6') {
  70. $ipvnum = 6;
  71. }
  72. elsif($ARGV[0] eq '--unix-socket') {
  73. $ipvnum = 'unix';
  74. if($ARGV[1]) {
  75. $unix_socket = $ARGV[1];
  76. shift @ARGV;
  77. }
  78. }
  79. elsif($ARGV[0] eq '--gopher') {
  80. $gopher = 1;
  81. }
  82. elsif($ARGV[0] eq '--port') {
  83. if($ARGV[1] =~ /^(\d+)$/) {
  84. $port = $1;
  85. shift @ARGV;
  86. }
  87. }
  88. elsif($ARGV[0] eq '--connect') {
  89. if($ARGV[1]) {
  90. $connect = $ARGV[1];
  91. shift @ARGV;
  92. }
  93. }
  94. elsif($ARGV[0] eq '--id') {
  95. if($ARGV[1] =~ /^(\d+)$/) {
  96. $idnum = $1 if($1 > 0);
  97. shift @ARGV;
  98. }
  99. }
  100. elsif($ARGV[0] eq '--verbose') {
  101. $verbose = 1;
  102. }
  103. else {
  104. print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n";
  105. }
  106. shift @ARGV;
  107. }
  108. if(!$srcdir) {
  109. $srcdir = $ENV{'srcdir'} || '.';
  110. }
  111. if(!$pidfile) {
  112. $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
  113. }
  114. if(!$logfile) {
  115. $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
  116. }
  117. $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
  118. $flags .= "--gopher " if($gopher);
  119. $flags .= "--connect $connect " if($connect);
  120. if($ipvnum eq 'unix') {
  121. $flags .= "--unix-socket '$unix_socket' ";
  122. } else {
  123. $flags .= "--ipv$ipvnum --port $port ";
  124. }
  125. $flags .= "--srcdir \"$srcdir\"";
  126. if($verbose) {
  127. print STDERR "RUN: server/sws $flags\n";
  128. }
  129. exec("server/sws $flags");