From 1fa309516fede39b54ce71016016506d2416d279 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Fri, 27 Apr 2018 09:26:56 +0200 Subject: [PATCH] Added all configuration options and a sample configuration file of tentacle server --- pandora_server/bin/tentacle_server | 154 +++++++++++++++++------- pandora_server/bin/tentacle_server.conf | 75 ++++++++++++ 2 files changed, 183 insertions(+), 46 deletions(-) create mode 100644 pandora_server/bin/tentacle_server.conf diff --git a/pandora_server/bin/tentacle_server b/pandora_server/bin/tentacle_server index 6a65b0f32c..3c940c0cac 100755 --- a/pandora_server/bin/tentacle_server +++ b/pandora_server/bin/tentacle_server @@ -102,7 +102,7 @@ my $SERVICE_NAME="Tentacle Server"; my $SERVICE_PARAMS=join(' ', @ARGV); # Program version -our $VERSION = '0.6.1'; +our $VERSION = '0.6.2'; # IPv4 address to listen on my @t_addresses = ('0', '0.0.0.0'); @@ -201,9 +201,6 @@ $t_program_name =~ s/.*\///g; # Log file my $log_file = undef; -# Configuration readed from file; -my $CONF = {}; - ################################################################################ ## SUB print_help ## Print help screen. @@ -282,6 +279,8 @@ sub daemonize { ################################################################################ sub parse_options { my %opts; + my $CONF = {}; + my $token_value; my $tmp; my @t_addresses_tmp; @@ -310,13 +309,14 @@ sub parse_options { # Configuration file if (defined($opts{'F'})) { - parse_config_file($opts{'F'}); + parse_config_file($opts{'F'}, $CONF); } # Address - if (defined ($opts{'a'})) { + $token_value = get_config_value($opts{'a'}, $CONF->{'addresses'}); + if (defined ($token_value)) { @t_addresses = (); - @t_addresses_tmp = split(/,/, $opts{'a'}); + @t_addresses_tmp = split(/,/, $token_value); foreach my $t_address (@t_addresses_tmp) { $t_address =~ s/^ *(.*?) *$/$1/; @@ -332,15 +332,17 @@ sub parse_options { } # Maximum simultaneous connections - if (defined ($opts{'c'})) { - $t_max_conn = $opts{'c'}; + $token_value = get_config_value($opts{'c'}, $CONF->{'max_connections'}); + if (defined ($token_value)) { + $t_max_conn = $token_value; if ($t_max_conn !~ /^\d+$/ || $t_max_conn < 1) { error ("Invalid number of maximum simultaneous connections."); } } # Run as daemon - if (defined ($opts{'d'})) { + $token_value = get_config_value($opts{'d'}, $CONF->{'daemon'}, 1); + if (defined ($token_value)) { if ($^ eq 'MSWin32') { error ("-d flag not available for this OS."); } @@ -349,11 +351,12 @@ sub parse_options { } # Enable SSL - if (defined ($opts{'e'})) { + $token_value = get_config_value($opts{'e'}, $CONF->{'ssl_cert'}); + if (defined ($token_value)) { require IO::Socket::SSL; - $t_ssl_cert = $opts{'e'}; + $t_ssl_cert = $token_value; if (! -f $t_ssl_cert) { error ("File $t_ssl_cert does not exist."); } @@ -362,21 +365,24 @@ sub parse_options { } # Verify peer certificate - if (defined ($opts{'f'})) { - $t_ssl_ca = $opts{'f'}; + $token_value = get_config_value($opts{'f'}, $CONF->{'ssl_ca'}); + if (defined ($token_value)) { + $t_ssl_ca = $token_value; if (! -f $t_ssl_ca) { error ("File $t_ssl_ca does not exist."); } } # Insecure mode - if (defined ($opts{'I'})) { + $token_value = get_config_value($opts{'I'}, $CONF->{'insecure'}, 1); + if (defined ($token_value)) { $t_insecure = 1; } # Filters (regexp:dir;regexp:dir...) - if (defined ($opts{'i'})) { - my @filters = split (';', $opts{'i'}); + $token_value = get_config_value($opts{'i'}, $CONF->{'filters'}); + if (defined ($token_value)) { + my @filters = split (';', $token_value); foreach my $filter (@filters) { my ($regexp, $dir) = split (':', $filter); next unless defined ($regexp) && defined ($dir); @@ -390,51 +396,58 @@ sub parse_options { } # SSL private key file - if (defined ($opts{'k'})) { - $t_ssl_key = $opts{'k'}; + $token_value = get_config_value($opts{'k'}, $CONF->{'ssl_key'}); + if (defined ($token_value)) { + $t_ssl_key = $token_value; if (! -f $t_ssl_key) { error ("File $t_ssl_key does not exist."); } } # Maximum file size - if (defined ($opts{'m'})) { - $t_max_size = $opts{'m'}; + $token_value = get_config_value($opts{'m'}, $CONF->{'max_size'}); + if (defined ($token_value)) { + $t_max_size = $token_value; if ($t_max_size !~ /^\d+$/ || $t_max_size < 1) { error ("Invalid maximum file size."); } } # File overwrite - if (defined ($opts{'o'})) { + $token_value = get_config_value($opts{'o'}, $CONF->{'overwrite'}, 1); + if (defined ($token_value)) { $t_overwrite = 1; } # Port - if (defined ($opts{'p'})) { - $t_port = $opts{'p'}; + $token_value = get_config_value($opts{'p'}, $CONF->{'port'}); + if (defined ($token_value)) { + $t_port = $token_value; if ($t_port !~ /^\d+$/ || $t_port < 1 || $t_port > 65535) { error ("Port $t_port is not valid."); } } # Quiet mode - if (defined ($opts{'q'})) { + $token_value = get_config_value($opts{'q'}, $CONF->{'quiet'}, 1); + if (defined ($token_value)) { $t_quiet = 1; } # Retries - if (defined ($opts{'r'})) { - $t_retries = $opts{'r'}; + $token_value = get_config_value($opts{'r'}, $CONF->{'retries'}); + if (defined ($token_value)) { + $t_retries = $token_value; if ($t_retries !~ /^\d+$/ || $t_retries < 1) { error ("Invalid number of retries for network operations."); } } # 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 if (! -d $t_directory) { @@ -453,25 +466,36 @@ sub parse_options { } } else { - if (! defined($opts{'b'})) { + $token_value = get_config_value($opts{'b'}, $CONF->{'proxy_ip'}); + if (! defined($token_value)) { print_help (); exit 1; } } # Timeout - if (defined ($opts{'t'})) { - $t_timeout = $opts{'t'}; + $token_value = get_config_value($opts{'t'}, $CONF->{'timeout'}); + if (defined ($token_value)) { + $t_timeout = $token_value; if ($t_timeout !~ /^\d+$/ || $t_timeout < 1) { 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 if (defined ($opts{'v'})) { $t_log = 1; + $t_log_hard = 0; } - # Be verbose hard if (defined ($opts{'V'})) { $t_log = 1; @@ -479,18 +503,21 @@ sub parse_options { } # 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: "); } # Server password - if (defined ($opts{'x'})) { - $t_pwd = $opts{'x'}; + $token_value = get_config_value($opts{'x'}, $CONF->{'password'}); + if (defined ($token_value)) { + $t_pwd = $token_value; } #Proxy IP address - if (defined ($opts{'b'})) { - $t_proxy_ip = $opts{'b'}; + $token_value = get_config_value($opts{'b'}, $CONF->{'proxy_ip'}); + if (defined ($token_value)) { + $t_proxy_ip = $token_value; if ($t_proxy_ip !~ /^[a-zA-Z\.]+$/ && ($t_proxy_ip !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ || $1 < 0 || $1 > 255 || $2 < 0 || $2 > 255 || $3 < 0 || $3 > 255 || $4 < 0 || $4 > 255) && @@ -500,15 +527,17 @@ sub parse_options { } # Proxy Port - if (defined ($opts{'g'})) { - $t_proxy_port = $opts{'g'}; + $token_value = get_config_value($opts{'g'}, $CONF->{'proxy_port'}); + if (defined ($token_value)) { + $t_proxy_port = $token_value; if ($t_proxy_port !~ /^\d+$/ || $t_proxy_port < 1 || $t_proxy_port > 65535) { error ("Proxy port $t_port is not valid."); } } # 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) { $t_use_libwrap = 1; } else { @@ -540,8 +569,24 @@ sub parse_options { } # Get the config file - if (defined ($opts{'l'})) { - $log_file = $opts{'l'}; + $token_value = get_config_value($opts{'l'}, $CONF->{'log_file'}); + 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. ################################################################################ sub parse_config_file { - my ($config_file) = @_; + my ($config_file, $CONF) = @_; # File should be writable if (! -r $config_file) { @@ -569,8 +614,8 @@ sub parse_config_file { while (<$FH>) { my $buffer_line = $_; if ($buffer_line =~ /^[a-zA-Z]/){ # begins with letters - if ($buffer_line =~ m/([\w\-\_\.]+)\s([0-9\w\-\_\.\/\?\&\=\)\(\_\-\!\*\@\#\%\$\~\"\']+)/){ - $CONF->{$1} = $2; + if ($buffer_line =~ m/([\w\-\_\.]+)\s+(.*)/){ + $CONF->{$1} = $2 unless $2 eq ""; } } } @@ -579,6 +624,23 @@ sub parse_config_file { 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 ## Open the proxy server socket. diff --git a/pandora_server/bin/tentacle_server.conf b/pandora_server/bin/tentacle_server.conf new file mode 100644 index 0000000000..5260a213aa --- /dev/null +++ b/pandora_server/bin/tentacle_server.conf @@ -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 \ No newline at end of file