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