Added all configuration options and a sample configuration file of tentacle server
This commit is contained in:
parent
979e7fa8b5
commit
1fa309516f
|
@ -102,7 +102,7 @@ my $SERVICE_NAME="Tentacle Server";
|
||||||
my $SERVICE_PARAMS=join(' ', @ARGV);
|
my $SERVICE_PARAMS=join(' ', @ARGV);
|
||||||
|
|
||||||
# Program version
|
# Program version
|
||||||
our $VERSION = '0.6.1';
|
our $VERSION = '0.6.2';
|
||||||
|
|
||||||
# IPv4 address to listen on
|
# IPv4 address to listen on
|
||||||
my @t_addresses = ('0', '0.0.0.0');
|
my @t_addresses = ('0', '0.0.0.0');
|
||||||
|
@ -201,9 +201,6 @@ $t_program_name =~ s/.*\///g;
|
||||||
# Log file
|
# Log file
|
||||||
my $log_file = undef;
|
my $log_file = undef;
|
||||||
|
|
||||||
# Configuration readed from file;
|
|
||||||
my $CONF = {};
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
## SUB print_help
|
## SUB print_help
|
||||||
## Print help screen.
|
## Print help screen.
|
||||||
|
@ -282,6 +279,8 @@ sub daemonize {
|
||||||
################################################################################
|
################################################################################
|
||||||
sub parse_options {
|
sub parse_options {
|
||||||
my %opts;
|
my %opts;
|
||||||
|
my $CONF = {};
|
||||||
|
my $token_value;
|
||||||
my $tmp;
|
my $tmp;
|
||||||
my @t_addresses_tmp;
|
my @t_addresses_tmp;
|
||||||
|
|
||||||
|
@ -310,13 +309,14 @@ sub parse_options {
|
||||||
|
|
||||||
# Configuration file
|
# Configuration file
|
||||||
if (defined($opts{'F'})) {
|
if (defined($opts{'F'})) {
|
||||||
parse_config_file($opts{'F'});
|
parse_config_file($opts{'F'}, $CONF);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Address
|
# Address
|
||||||
if (defined ($opts{'a'})) {
|
$token_value = get_config_value($opts{'a'}, $CONF->{'addresses'});
|
||||||
|
if (defined ($token_value)) {
|
||||||
@t_addresses = ();
|
@t_addresses = ();
|
||||||
@t_addresses_tmp = split(/,/, $opts{'a'});
|
@t_addresses_tmp = split(/,/, $token_value);
|
||||||
|
|
||||||
foreach my $t_address (@t_addresses_tmp) {
|
foreach my $t_address (@t_addresses_tmp) {
|
||||||
$t_address =~ s/^ *(.*?) *$/$1/;
|
$t_address =~ s/^ *(.*?) *$/$1/;
|
||||||
|
@ -332,15 +332,17 @@ sub parse_options {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Maximum simultaneous connections
|
# Maximum simultaneous connections
|
||||||
if (defined ($opts{'c'})) {
|
$token_value = get_config_value($opts{'c'}, $CONF->{'max_connections'});
|
||||||
$t_max_conn = $opts{'c'};
|
if (defined ($token_value)) {
|
||||||
|
$t_max_conn = $token_value;
|
||||||
if ($t_max_conn !~ /^\d+$/ || $t_max_conn < 1) {
|
if ($t_max_conn !~ /^\d+$/ || $t_max_conn < 1) {
|
||||||
error ("Invalid number of maximum simultaneous connections.");
|
error ("Invalid number of maximum simultaneous connections.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run as daemon
|
# Run as daemon
|
||||||
if (defined ($opts{'d'})) {
|
$token_value = get_config_value($opts{'d'}, $CONF->{'daemon'}, 1);
|
||||||
|
if (defined ($token_value)) {
|
||||||
if ($^ eq 'MSWin32') {
|
if ($^ eq 'MSWin32') {
|
||||||
error ("-d flag not available for this OS.");
|
error ("-d flag not available for this OS.");
|
||||||
}
|
}
|
||||||
|
@ -349,11 +351,12 @@ sub parse_options {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Enable SSL
|
# Enable SSL
|
||||||
if (defined ($opts{'e'})) {
|
$token_value = get_config_value($opts{'e'}, $CONF->{'ssl_cert'});
|
||||||
|
if (defined ($token_value)) {
|
||||||
|
|
||||||
require IO::Socket::SSL;
|
require IO::Socket::SSL;
|
||||||
|
|
||||||
$t_ssl_cert = $opts{'e'};
|
$t_ssl_cert = $token_value;
|
||||||
if (! -f $t_ssl_cert) {
|
if (! -f $t_ssl_cert) {
|
||||||
error ("File $t_ssl_cert does not exist.");
|
error ("File $t_ssl_cert does not exist.");
|
||||||
}
|
}
|
||||||
|
@ -362,21 +365,24 @@ sub parse_options {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verify peer certificate
|
# Verify peer certificate
|
||||||
if (defined ($opts{'f'})) {
|
$token_value = get_config_value($opts{'f'}, $CONF->{'ssl_ca'});
|
||||||
$t_ssl_ca = $opts{'f'};
|
if (defined ($token_value)) {
|
||||||
|
$t_ssl_ca = $token_value;
|
||||||
if (! -f $t_ssl_ca) {
|
if (! -f $t_ssl_ca) {
|
||||||
error ("File $t_ssl_ca does not exist.");
|
error ("File $t_ssl_ca does not exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Insecure mode
|
# Insecure mode
|
||||||
if (defined ($opts{'I'})) {
|
$token_value = get_config_value($opts{'I'}, $CONF->{'insecure'}, 1);
|
||||||
|
if (defined ($token_value)) {
|
||||||
$t_insecure = 1;
|
$t_insecure = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Filters (regexp:dir;regexp:dir...)
|
# Filters (regexp:dir;regexp:dir...)
|
||||||
if (defined ($opts{'i'})) {
|
$token_value = get_config_value($opts{'i'}, $CONF->{'filters'});
|
||||||
my @filters = split (';', $opts{'i'});
|
if (defined ($token_value)) {
|
||||||
|
my @filters = split (';', $token_value);
|
||||||
foreach my $filter (@filters) {
|
foreach my $filter (@filters) {
|
||||||
my ($regexp, $dir) = split (':', $filter);
|
my ($regexp, $dir) = split (':', $filter);
|
||||||
next unless defined ($regexp) && defined ($dir);
|
next unless defined ($regexp) && defined ($dir);
|
||||||
|
@ -390,51 +396,58 @@ sub parse_options {
|
||||||
}
|
}
|
||||||
|
|
||||||
# SSL private key file
|
# SSL private key file
|
||||||
if (defined ($opts{'k'})) {
|
$token_value = get_config_value($opts{'k'}, $CONF->{'ssl_key'});
|
||||||
$t_ssl_key = $opts{'k'};
|
if (defined ($token_value)) {
|
||||||
|
$t_ssl_key = $token_value;
|
||||||
if (! -f $t_ssl_key) {
|
if (! -f $t_ssl_key) {
|
||||||
error ("File $t_ssl_key does not exist.");
|
error ("File $t_ssl_key does not exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Maximum file size
|
# Maximum file size
|
||||||
if (defined ($opts{'m'})) {
|
$token_value = get_config_value($opts{'m'}, $CONF->{'max_size'});
|
||||||
$t_max_size = $opts{'m'};
|
if (defined ($token_value)) {
|
||||||
|
$t_max_size = $token_value;
|
||||||
if ($t_max_size !~ /^\d+$/ || $t_max_size < 1) {
|
if ($t_max_size !~ /^\d+$/ || $t_max_size < 1) {
|
||||||
error ("Invalid maximum file size.");
|
error ("Invalid maximum file size.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# File overwrite
|
# File overwrite
|
||||||
if (defined ($opts{'o'})) {
|
$token_value = get_config_value($opts{'o'}, $CONF->{'overwrite'}, 1);
|
||||||
|
if (defined ($token_value)) {
|
||||||
$t_overwrite = 1;
|
$t_overwrite = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Port
|
# Port
|
||||||
if (defined ($opts{'p'})) {
|
$token_value = get_config_value($opts{'p'}, $CONF->{'port'});
|
||||||
$t_port = $opts{'p'};
|
if (defined ($token_value)) {
|
||||||
|
$t_port = $token_value;
|
||||||
if ($t_port !~ /^\d+$/ || $t_port < 1 || $t_port > 65535) {
|
if ($t_port !~ /^\d+$/ || $t_port < 1 || $t_port > 65535) {
|
||||||
error ("Port $t_port is not valid.");
|
error ("Port $t_port is not valid.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Quiet mode
|
# Quiet mode
|
||||||
if (defined ($opts{'q'})) {
|
$token_value = get_config_value($opts{'q'}, $CONF->{'quiet'}, 1);
|
||||||
|
if (defined ($token_value)) {
|
||||||
$t_quiet = 1;
|
$t_quiet = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Retries
|
# Retries
|
||||||
if (defined ($opts{'r'})) {
|
$token_value = get_config_value($opts{'r'}, $CONF->{'retries'});
|
||||||
$t_retries = $opts{'r'};
|
if (defined ($token_value)) {
|
||||||
|
$t_retries = $token_value;
|
||||||
if ($t_retries !~ /^\d+$/ || $t_retries < 1) {
|
if ($t_retries !~ /^\d+$/ || $t_retries < 1) {
|
||||||
error ("Invalid number of retries for network operations.");
|
error ("Invalid number of retries for network operations.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Storage directory
|
# Storage directory
|
||||||
if (defined ($opts{'s'})) {
|
$token_value = get_config_value($opts{'s'}, $CONF->{'directory'});
|
||||||
|
if (defined ($token_value)) {
|
||||||
|
|
||||||
$t_directory = $opts{'s'};
|
$t_directory = $token_value;
|
||||||
|
|
||||||
# Check that directory exists
|
# Check that directory exists
|
||||||
if (! -d $t_directory) {
|
if (! -d $t_directory) {
|
||||||
|
@ -453,25 +466,36 @@ sub parse_options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (! defined($opts{'b'})) {
|
$token_value = get_config_value($opts{'b'}, $CONF->{'proxy_ip'});
|
||||||
|
if (! defined($token_value)) {
|
||||||
print_help ();
|
print_help ();
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Timeout
|
# Timeout
|
||||||
if (defined ($opts{'t'})) {
|
$token_value = get_config_value($opts{'t'}, $CONF->{'timeout'});
|
||||||
$t_timeout = $opts{'t'};
|
if (defined ($token_value)) {
|
||||||
|
$t_timeout = $token_value;
|
||||||
if ($t_timeout !~ /^\d+$/ || $t_timeout < 1) {
|
if ($t_timeout !~ /^\d+$/ || $t_timeout < 1) {
|
||||||
error ("Invalid timeout for network operations.");
|
error ("Invalid timeout for network operations.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Read verbose from config file
|
||||||
|
if (defined($CONF->{'verbose'})) {
|
||||||
|
if ($CONF->{'verbose'} eq "1") {
|
||||||
|
$t_log = 1;
|
||||||
|
} elsif ($CONF->{'verbose'} eq "2") {
|
||||||
|
$t_log = 1;
|
||||||
|
$t_log_hard = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
# Be verbose
|
# Be verbose
|
||||||
if (defined ($opts{'v'})) {
|
if (defined ($opts{'v'})) {
|
||||||
$t_log = 1;
|
$t_log = 1;
|
||||||
|
$t_log_hard = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Be verbose hard
|
# Be verbose hard
|
||||||
if (defined ($opts{'V'})) {
|
if (defined ($opts{'V'})) {
|
||||||
$t_log = 1;
|
$t_log = 1;
|
||||||
|
@ -479,18 +503,21 @@ sub parse_options {
|
||||||
}
|
}
|
||||||
|
|
||||||
# SSL private key password
|
# SSL private key password
|
||||||
if (defined ($opts{'w'})) {
|
$token_value = get_config_value($opts{'w'}, $CONF->{'ssl_password'}, 1);
|
||||||
|
if (defined ($token_value)) {
|
||||||
$t_ssl_pwd = ask_passwd ("Enter private key file password: ", "Enter private key file password again for confirmation: ");
|
$t_ssl_pwd = ask_passwd ("Enter private key file password: ", "Enter private key file password again for confirmation: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
# Server password
|
# Server password
|
||||||
if (defined ($opts{'x'})) {
|
$token_value = get_config_value($opts{'x'}, $CONF->{'password'});
|
||||||
$t_pwd = $opts{'x'};
|
if (defined ($token_value)) {
|
||||||
|
$t_pwd = $token_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#Proxy IP address
|
#Proxy IP address
|
||||||
if (defined ($opts{'b'})) {
|
$token_value = get_config_value($opts{'b'}, $CONF->{'proxy_ip'});
|
||||||
$t_proxy_ip = $opts{'b'};
|
if (defined ($token_value)) {
|
||||||
|
$t_proxy_ip = $token_value;
|
||||||
if ($t_proxy_ip !~ /^[a-zA-Z\.]+$/ && ($t_proxy_ip !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
|
if ($t_proxy_ip !~ /^[a-zA-Z\.]+$/ && ($t_proxy_ip !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
|
||||||
|| $1 < 0 || $1 > 255 || $2 < 0 || $2 > 255
|
|| $1 < 0 || $1 > 255 || $2 < 0 || $2 > 255
|
||||||
|| $3 < 0 || $3 > 255 || $4 < 0 || $4 > 255) &&
|
|| $3 < 0 || $3 > 255 || $4 < 0 || $4 > 255) &&
|
||||||
|
@ -500,15 +527,17 @@ sub parse_options {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Proxy Port
|
# Proxy Port
|
||||||
if (defined ($opts{'g'})) {
|
$token_value = get_config_value($opts{'g'}, $CONF->{'proxy_port'});
|
||||||
$t_proxy_port = $opts{'g'};
|
if (defined ($token_value)) {
|
||||||
|
$t_proxy_port = $token_value;
|
||||||
if ($t_proxy_port !~ /^\d+$/ || $t_proxy_port < 1 || $t_proxy_port > 65535) {
|
if ($t_proxy_port !~ /^\d+$/ || $t_proxy_port < 1 || $t_proxy_port > 65535) {
|
||||||
error ("Proxy port $t_port is not valid.");
|
error ("Proxy port $t_port is not valid.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# TCP wrappers support
|
# TCP wrappers support
|
||||||
if (defined ($opts{'T'})) {
|
$token_value = get_config_value($opts{'T'}, $CONF->{'use_libwrap'}, 1);
|
||||||
|
if (defined ($token_value)) {
|
||||||
if ($t_libwrap_installed) {
|
if ($t_libwrap_installed) {
|
||||||
$t_use_libwrap = 1;
|
$t_use_libwrap = 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -540,8 +569,24 @@ sub parse_options {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the config file
|
# Get the config file
|
||||||
if (defined ($opts{'l'})) {
|
$token_value = get_config_value($opts{'l'}, $CONF->{'log_file'});
|
||||||
$log_file = $opts{'l'};
|
if (defined ($token_value)) {
|
||||||
|
$log_file = $token_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
# No command lines config values
|
||||||
|
|
||||||
|
# Get the block size
|
||||||
|
if (defined ($CONF->{'block_size'})) {
|
||||||
|
if ($t_port !~ /^\d+$/ || $t_port < 1) {
|
||||||
|
error ("Invalid block size: " . $CONF->{'block_size'} . ".");
|
||||||
|
}
|
||||||
|
$t_block_size = $CONF->{'block_size'};
|
||||||
|
}
|
||||||
|
|
||||||
|
# Configuration file invalid chars
|
||||||
|
if (defined ($CONF->{'invalid_chars'})) {
|
||||||
|
$t_invalid_chars = $CONF->{'invalid_chars'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,7 +595,7 @@ sub parse_options {
|
||||||
## Get all options from a config file.
|
## Get all options from a config file.
|
||||||
################################################################################
|
################################################################################
|
||||||
sub parse_config_file {
|
sub parse_config_file {
|
||||||
my ($config_file) = @_;
|
my ($config_file, $CONF) = @_;
|
||||||
|
|
||||||
# File should be writable
|
# File should be writable
|
||||||
if (! -r $config_file) {
|
if (! -r $config_file) {
|
||||||
|
@ -569,8 +614,8 @@ sub parse_config_file {
|
||||||
while (<$FH>) {
|
while (<$FH>) {
|
||||||
my $buffer_line = $_;
|
my $buffer_line = $_;
|
||||||
if ($buffer_line =~ /^[a-zA-Z]/){ # begins with letters
|
if ($buffer_line =~ /^[a-zA-Z]/){ # begins with letters
|
||||||
if ($buffer_line =~ m/([\w\-\_\.]+)\s([0-9\w\-\_\.\/\?\&\=\)\(\_\-\!\*\@\#\%\$\~\"\']+)/){
|
if ($buffer_line =~ m/([\w\-\_\.]+)\s+(.*)/){
|
||||||
$CONF->{$1} = $2;
|
$CONF->{$1} = $2 unless $2 eq "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -579,6 +624,23 @@ sub parse_config_file {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## SUB parse_config_file
|
||||||
|
## Search in command line options and config hash from configuration file
|
||||||
|
## to get a value (command line is a priority)
|
||||||
|
################################################################################
|
||||||
|
sub get_config_value {
|
||||||
|
my ($cmd_value, $conf_value, $bool) = @_;
|
||||||
|
$bool = 0 unless defined($bool);
|
||||||
|
|
||||||
|
return $cmd_value if defined($cmd_value);
|
||||||
|
# The boolean type value is 1 or undef (0 should be translated like undefP)
|
||||||
|
if ($bool && defined($conf_value)) {
|
||||||
|
return undef if ($conf_value ne "1");
|
||||||
|
}
|
||||||
|
return $conf_value;
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
## SUB start_proxy
|
## SUB start_proxy
|
||||||
## Open the proxy server socket.
|
## Open the proxy server socket.
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
##########################################################################
|
||||||
|
# Tentacle Server Parameters
|
||||||
|
# See https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_en:Tentacle
|
||||||
|
# for protocol description.
|
||||||
|
# Tentacle have IANA assigned port tpc/41121 as official port.
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
# [-a] IPv4 address to listen on. Several IPs cam be selected separating if by comma.
|
||||||
|
addresses 0.0.0.0
|
||||||
|
|
||||||
|
# [-p] Port to listen on
|
||||||
|
# port 41121
|
||||||
|
|
||||||
|
# [-c] Maximum number of simultaneous connections
|
||||||
|
# max_connections 10
|
||||||
|
|
||||||
|
# [-d] Run as daemon. 1 true, 0 false
|
||||||
|
daemon 1
|
||||||
|
|
||||||
|
# [-i] Enable insecure mode
|
||||||
|
# insecure 0
|
||||||
|
|
||||||
|
# Filters (regexp:dir;regexp:dir...)
|
||||||
|
filters .*\.conf:conf;.*\.md5:md5;.*\.zip:collections;.*\.lock:trans
|
||||||
|
|
||||||
|
# [-m] Maximum file size allowed by the server in bytes
|
||||||
|
#max_size 2000000
|
||||||
|
|
||||||
|
# [-o] Accept files with a repeated name
|
||||||
|
# overwrite 0
|
||||||
|
|
||||||
|
# [-q] Do not output error messages.
|
||||||
|
# quiet 0
|
||||||
|
|
||||||
|
# [-r] Number of retries for socket read/write operations
|
||||||
|
# retries 3
|
||||||
|
|
||||||
|
# [-s] Storage directory
|
||||||
|
directory /var/spool/pandora/data_in
|
||||||
|
|
||||||
|
# [-b] Address to proxy client requests to
|
||||||
|
# proxy_ip 127.0.0.1
|
||||||
|
|
||||||
|
# [-g] Port to proxy client requests to
|
||||||
|
# proxy_port 41121
|
||||||
|
|
||||||
|
# [-t] Timeout for socket read/write operations in seconds
|
||||||
|
# timeout 1
|
||||||
|
|
||||||
|
# [-v and -V] Verbose level
|
||||||
|
# 0: Do not display any informative messages
|
||||||
|
# 1: Display only important messages [-v]
|
||||||
|
# 2: Display all messages [-V]
|
||||||
|
# verbose 0
|
||||||
|
|
||||||
|
# [-l] Log file
|
||||||
|
# log_file /path/to/log/file
|
||||||
|
|
||||||
|
# [-x] Server password
|
||||||
|
# password PASSWORD
|
||||||
|
|
||||||
|
# [-e] SSL certificate file full path
|
||||||
|
# ssl_cert /path/to/ssl/cert
|
||||||
|
|
||||||
|
# [-f] SSL CA file full path
|
||||||
|
# ssl_ca /path/to/ssl/ca
|
||||||
|
|
||||||
|
# [-k] SSL private key file
|
||||||
|
# ssl_key /path/to/private/key/file
|
||||||
|
|
||||||
|
# [-w] SSL password. Set to 1 to ask for password by command line
|
||||||
|
# ssl_password 0
|
||||||
|
|
||||||
|
# [-T] Use libwrap library (Authen::Libwrap perl module)
|
||||||
|
# use_libwrap 0
|
Loading…
Reference in New Issue