2002-02-19 09:03:45 +08:00
|
|
|
#!/usr/bin/env perl
|
2010-01-08 23:54:07 +08:00
|
|
|
#***************************************************************************
|
|
|
|
# _ _ ____ _
|
|
|
|
# Project ___| | | | _ \| |
|
|
|
|
# / __| | | | |_) | |
|
|
|
|
# | (__| |_| | _ <| |___
|
|
|
|
# \___|\___/|_| \_\_____|
|
|
|
|
#
|
2021-09-08 15:36:49 +08:00
|
|
|
# Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2010-01-08 23:54:07 +08:00
|
|
|
#
|
|
|
|
# This software is licensed as described in the file COPYING, which
|
|
|
|
# you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
# are also available at https://curl.se/docs/copyright.html.
|
2010-01-08 23:54:07 +08:00
|
|
|
#
|
|
|
|
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
# copies of the Software, and permit persons to whom the Software is
|
|
|
|
# furnished to do so, under the terms of the COPYING file.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
#
|
2010-01-08 23:54:07 +08:00
|
|
|
#***************************************************************************
|
|
|
|
|
|
|
|
BEGIN {
|
2012-11-14 18:40:31 +08:00
|
|
|
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
|
|
|
|
push(@INC, ".");
|
2010-01-08 23:54:07 +08:00
|
|
|
}
|
2000-11-13 16:02:02 +08:00
|
|
|
|
2002-02-19 09:03:45 +08:00
|
|
|
use strict;
|
2010-01-08 23:54:07 +08:00
|
|
|
use warnings;
|
2000-11-13 16:02:02 +08:00
|
|
|
|
2010-01-08 23:54:07 +08:00
|
|
|
use serverhelp qw(
|
|
|
|
server_pidfilename
|
|
|
|
server_logfilename
|
|
|
|
);
|
2000-11-13 16:02:02 +08:00
|
|
|
|
2019-05-19 05:32:04 +08:00
|
|
|
use sshhelp qw(
|
|
|
|
exe_ext
|
|
|
|
);
|
|
|
|
|
2010-01-08 23:54:07 +08:00
|
|
|
my $verbose = 0; # set to 1 for debugging
|
|
|
|
my $port = 8990; # just a default
|
2014-12-27 04:45:21 +08:00
|
|
|
my $unix_socket; # location to place a listening Unix socket
|
2010-01-08 23:54:07 +08:00
|
|
|
my $ipvnum = 4; # default IP version of http server
|
2017-03-26 23:02:22 +08:00
|
|
|
my $idnum = 1; # default http server instance number
|
2010-01-08 23:54:07 +08:00
|
|
|
my $proto = 'http'; # protocol the http server speaks
|
2020-04-16 23:52:24 +08:00
|
|
|
my $pidfile; # pid file
|
|
|
|
my $portfile; # port number file
|
|
|
|
my $logfile; # log file
|
2011-12-18 06:47:22 +08:00
|
|
|
my $connect; # IP to connect to on CONNECT
|
2010-01-08 23:54:07 +08:00
|
|
|
my $srcdir;
|
2010-08-25 06:47:45 +08:00
|
|
|
my $gopher = 0;
|
2010-01-08 09:48:54 +08:00
|
|
|
|
|
|
|
my $flags = "";
|
2010-01-08 23:54:07 +08:00
|
|
|
my $path = '.';
|
|
|
|
my $logdir = $path .'/log';
|
2010-01-08 09:48:54 +08:00
|
|
|
|
2010-01-08 23:54:07 +08:00
|
|
|
while(@ARGV) {
|
|
|
|
if($ARGV[0] eq '--pidfile') {
|
|
|
|
if($ARGV[1]) {
|
|
|
|
$pidfile = $ARGV[1];
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
2000-11-16 17:06:18 +08:00
|
|
|
}
|
2020-04-16 23:52:24 +08:00
|
|
|
elsif($ARGV[0] eq '--portfile') {
|
|
|
|
if($ARGV[1]) {
|
|
|
|
$portfile = $ARGV[1];
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
|
|
|
}
|
2010-01-08 23:54:07 +08:00
|
|
|
elsif($ARGV[0] eq '--logfile') {
|
|
|
|
if($ARGV[1]) {
|
|
|
|
$logfile = $ARGV[1];
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
2004-02-12 22:40:08 +08:00
|
|
|
}
|
2010-01-08 23:54:07 +08:00
|
|
|
elsif($ARGV[0] eq '--srcdir') {
|
|
|
|
if($ARGV[1]) {
|
|
|
|
$srcdir = $ARGV[1];
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
2004-12-15 05:52:16 +08:00
|
|
|
}
|
2010-01-08 23:54:07 +08:00
|
|
|
elsif($ARGV[0] eq '--ipv4') {
|
|
|
|
$ipvnum = 4;
|
|
|
|
}
|
|
|
|
elsif($ARGV[0] eq '--ipv6') {
|
|
|
|
$ipvnum = 6;
|
|
|
|
}
|
2014-11-28 06:59:23 +08:00
|
|
|
elsif($ARGV[0] eq '--unix-socket') {
|
|
|
|
$ipvnum = 'unix';
|
|
|
|
if($ARGV[1]) {
|
|
|
|
$unix_socket = $ARGV[1];
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
|
|
|
}
|
2010-08-25 06:47:45 +08:00
|
|
|
elsif($ARGV[0] eq '--gopher') {
|
|
|
|
$gopher = 1;
|
|
|
|
}
|
2010-01-08 23:54:07 +08:00
|
|
|
elsif($ARGV[0] eq '--port') {
|
|
|
|
if($ARGV[1] =~ /^(\d+)$/) {
|
|
|
|
$port = $1;
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
2006-04-10 21:09:56 +08:00
|
|
|
}
|
2011-12-18 06:47:22 +08:00
|
|
|
elsif($ARGV[0] eq '--connect') {
|
|
|
|
if($ARGV[1]) {
|
|
|
|
$connect = $ARGV[1];
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
|
|
|
}
|
2010-01-08 23:54:07 +08:00
|
|
|
elsif($ARGV[0] eq '--id') {
|
|
|
|
if($ARGV[1] =~ /^(\d+)$/) {
|
|
|
|
$idnum = $1 if($1 > 0);
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
2000-11-16 17:06:18 +08:00
|
|
|
}
|
2010-01-08 23:54:07 +08:00
|
|
|
elsif($ARGV[0] eq '--verbose') {
|
|
|
|
$verbose = 1;
|
2004-12-12 05:41:00 +08:00
|
|
|
}
|
2010-01-08 23:54:07 +08:00
|
|
|
else {
|
|
|
|
print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n";
|
|
|
|
}
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$srcdir) {
|
|
|
|
$srcdir = $ENV{'srcdir'} || '.';
|
|
|
|
}
|
|
|
|
if(!$pidfile) {
|
|
|
|
$pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
|
|
|
|
}
|
2020-04-16 23:52:24 +08:00
|
|
|
if(!$portfile) {
|
|
|
|
$portfile = "$path/". server_portfilename($proto, $ipvnum, $idnum);
|
|
|
|
}
|
2010-01-08 23:54:07 +08:00
|
|
|
if(!$logfile) {
|
|
|
|
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
|
|
|
|
}
|
2000-11-14 00:06:16 +08:00
|
|
|
|
2020-04-16 23:52:24 +08:00
|
|
|
$flags .= "--pidfile \"$pidfile\" ".
|
|
|
|
"--logfile \"$logfile\" ".
|
|
|
|
"--portfile \"$portfile\" ";
|
2010-08-25 06:47:45 +08:00
|
|
|
$flags .= "--gopher " if($gopher);
|
2011-12-18 06:47:22 +08:00
|
|
|
$flags .= "--connect $connect " if($connect);
|
2014-11-28 06:59:23 +08:00
|
|
|
if($ipvnum eq 'unix') {
|
|
|
|
$flags .= "--unix-socket '$unix_socket' ";
|
|
|
|
} else {
|
|
|
|
$flags .= "--ipv$ipvnum --port $port ";
|
|
|
|
}
|
|
|
|
$flags .= "--srcdir \"$srcdir\"";
|
2010-01-08 09:48:54 +08:00
|
|
|
|
2011-12-18 06:47:22 +08:00
|
|
|
if($verbose) {
|
2019-05-19 05:32:04 +08:00
|
|
|
print STDERR "RUN: server/sws".exe_ext('SRV')." $flags\n";
|
2011-12-18 06:47:22 +08:00
|
|
|
}
|
|
|
|
|
2021-08-18 03:16:41 +08:00
|
|
|
$| = 1;
|
|
|
|
exec("exec server/sws".exe_ext('SRV')." $flags");
|