2
0

httpserver.pl 4.1 KB

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