19bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#!/usr/bin/env perl 29bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#*************************************************************************** 39bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# _ _ ____ _ 49bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# Project ___| | | | _ \| | 59bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# / __| | | | |_) | | 69bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# | (__| |_| | _ <| |___ 79bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# \___|\___/|_| \_\_____| 89bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# 99bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. 109bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# 119bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# This software is licensed as described in the file COPYING, which 129bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# you should have received as part of this distribution. The terms 13d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo# are also available at https://curl.haxx.se/docs/copyright.html. 149bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# 159bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# You may opt to use, copy, modify, merge, publish, distribute and/or sell 169bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# copies of the Software, and permit persons to whom the Software is 179bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# furnished to do so, under the terms of the COPYING file. 189bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# 199bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 209bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# KIND, either express or implied. 219bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# 229bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#*************************************************************************** 239bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 249bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas EckelsBEGIN { 25e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'}); 26e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET push(@INC, "."); 279bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels} 289bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 299bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsuse strict; 309bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsuse warnings; 319bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 329bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsuse serverhelp qw( 339bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels server_pidfilename 349bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels server_logfilename 359bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels ); 369bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 379bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $verbose = 0; # set to 1 for debugging 389bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $port = 8997; # just a default 399bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $ipvnum = 4; # default IP version of tftp server 409bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $idnum = 1; # dafault tftp server instance number 419bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $proto = 'tftp'; # protocol the tftp server speaks 429bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $pidfile; # tftp server pid file 439bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $logfile; # tftp server log file 449bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $srcdir; 459bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $fork; 469bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 479bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $flags = ""; 489bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $path = '.'; 499bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $logdir = $path .'/log'; 509bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 519bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelswhile(@ARGV) { 529bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels if($ARGV[0] eq '--pidfile') { 539bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels if($ARGV[1]) { 549bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $pidfile = $ARGV[1]; 559bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels shift @ARGV; 569bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 579bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 589bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels elsif($ARGV[0] eq '--logfile') { 599bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels if($ARGV[1]) { 609bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $logfile = $ARGV[1]; 619bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels shift @ARGV; 629bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 639bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 649bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels elsif($ARGV[0] eq '--srcdir') { 659bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels if($ARGV[1]) { 669bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $srcdir = $ARGV[1]; 679bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels shift @ARGV; 689bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 699bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 709bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels elsif($ARGV[0] eq '--ipv4') { 719bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $ipvnum = 4; 729bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 739bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels elsif($ARGV[0] eq '--ipv6') { 749bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $ipvnum = 6; 759bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 769bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels elsif($ARGV[0] eq '--port') { 779bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels if($ARGV[1] =~ /^(\d+)$/) { 789bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $port = $1; 799bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels shift @ARGV; 809bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 819bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 829bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels elsif($ARGV[0] eq '--id') { 839bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels if($ARGV[1] =~ /^(\d+)$/) { 849bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $idnum = $1 if($1 > 0); 859bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels shift @ARGV; 869bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 879bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 889bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels elsif($ARGV[0] eq '--verbose') { 899bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $verbose = 1; 909bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 919bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels else { 929bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels print STDERR "\nWarning: tftpserver.pl unknown parameter: $ARGV[0]\n"; 939bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } 949bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels shift @ARGV; 959bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels} 969bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 979bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsif(!$srcdir) { 989bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $srcdir = $ENV{'srcdir'} || '.'; 999bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels} 1009bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsif(!$pidfile) { 1019bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum); 1029bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels} 1039bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsif(!$logfile) { 1049bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum); 1059bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels} 1069bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 1079bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" "; 1089bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels$flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\""; 1099bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 1109bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsexec("server/tftpd $flags"); 111