httpserver.pl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 1998 - 2020, 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.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. use sshhelp qw(
  34. exe_ext
  35. );
  36. my $verbose = 0; # set to 1 for debugging
  37. my $port = 8990; # just a default
  38. my $unix_socket; # location to place a listening Unix socket
  39. my $ipvnum = 4; # default IP version of http server
  40. my $idnum = 1; # default http server instance number
  41. my $proto = 'http'; # protocol the http server speaks
  42. my $pidfile; # pid file
  43. my $portfile; # port number file
  44. my $logfile; # log file
  45. my $connect; # IP to connect to on CONNECT
  46. my $srcdir;
  47. my $gopher = 0;
  48. my $flags = "";
  49. my $path = '.';
  50. my $logdir = $path .'/log';
  51. while(@ARGV) {
  52. if($ARGV[0] eq '--pidfile') {
  53. if($ARGV[1]) {
  54. $pidfile = $ARGV[1];
  55. shift @ARGV;
  56. }
  57. }
  58. elsif($ARGV[0] eq '--portfile') {
  59. if($ARGV[1]) {
  60. $portfile = $ARGV[1];
  61. shift @ARGV;
  62. }
  63. }
  64. elsif($ARGV[0] eq '--logfile') {
  65. if($ARGV[1]) {
  66. $logfile = $ARGV[1];
  67. shift @ARGV;
  68. }
  69. }
  70. elsif($ARGV[0] eq '--srcdir') {
  71. if($ARGV[1]) {
  72. $srcdir = $ARGV[1];
  73. shift @ARGV;
  74. }
  75. }
  76. elsif($ARGV[0] eq '--ipv4') {
  77. $ipvnum = 4;
  78. }
  79. elsif($ARGV[0] eq '--ipv6') {
  80. $ipvnum = 6;
  81. }
  82. elsif($ARGV[0] eq '--unix-socket') {
  83. $ipvnum = 'unix';
  84. if($ARGV[1]) {
  85. $unix_socket = $ARGV[1];
  86. shift @ARGV;
  87. }
  88. }
  89. elsif($ARGV[0] eq '--gopher') {
  90. $gopher = 1;
  91. }
  92. elsif($ARGV[0] eq '--port') {
  93. if($ARGV[1] =~ /^(\d+)$/) {
  94. $port = $1;
  95. shift @ARGV;
  96. }
  97. }
  98. elsif($ARGV[0] eq '--connect') {
  99. if($ARGV[1]) {
  100. $connect = $ARGV[1];
  101. shift @ARGV;
  102. }
  103. }
  104. elsif($ARGV[0] eq '--id') {
  105. if($ARGV[1] =~ /^(\d+)$/) {
  106. $idnum = $1 if($1 > 0);
  107. shift @ARGV;
  108. }
  109. }
  110. elsif($ARGV[0] eq '--verbose') {
  111. $verbose = 1;
  112. }
  113. else {
  114. print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n";
  115. }
  116. shift @ARGV;
  117. }
  118. if(!$srcdir) {
  119. $srcdir = $ENV{'srcdir'} || '.';
  120. }
  121. if(!$pidfile) {
  122. $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
  123. }
  124. if(!$portfile) {
  125. $portfile = "$path/". server_portfilename($proto, $ipvnum, $idnum);
  126. }
  127. if(!$logfile) {
  128. $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
  129. }
  130. $flags .= "--pidfile \"$pidfile\" ".
  131. "--logfile \"$logfile\" ".
  132. "--portfile \"$portfile\" ";
  133. $flags .= "--gopher " if($gopher);
  134. $flags .= "--connect $connect " if($connect);
  135. if($ipvnum eq 'unix') {
  136. $flags .= "--unix-socket '$unix_socket' ";
  137. } else {
  138. $flags .= "--ipv$ipvnum --port $port ";
  139. }
  140. $flags .= "--srcdir \"$srcdir\"";
  141. if($verbose) {
  142. print STDERR "RUN: server/sws".exe_ext('SRV')." $flags\n";
  143. }
  144. exec("server/sws".exe_ext('SRV')." $flags");