mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
2014-04-03 Koichiro KIKUCHI <koichiro@rworks.jp>
* bin/tentacle_server: Updated to the logfile supported version. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9712 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
479a206b5e
commit
e7c86b7d9b
@ -1,3 +1,7 @@
|
|||||||
|
2014-04-03 Koichiro KIKUCHI <koichiro@rworks.jp>
|
||||||
|
|
||||||
|
* bin/tentacle_server: Updated to the logfile supported version.
|
||||||
|
|
||||||
2014-04-03 Ramon Novoa <rnovoa@artica.es>
|
2014-04-03 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* util/recon_scripts/snmp-recon.pl: Added to the repository. Recon SNMP L2
|
* util/recon_scripts/snmp-recon.pl: Added to the repository. Recon SNMP L2
|
||||||
|
@ -61,7 +61,7 @@ use warnings;
|
|||||||
use Getopt::Std;
|
use Getopt::Std;
|
||||||
use IO::Select;
|
use IO::Select;
|
||||||
use Thread::Semaphore;
|
use Thread::Semaphore;
|
||||||
use POSIX ":sys_wait_h";
|
use POSIX qw(:sys_wait_h strftime);
|
||||||
|
|
||||||
my $t_libwrap_installed = eval { require Authen::Libwrap } ? 1 : 0;
|
my $t_libwrap_installed = eval { require Authen::Libwrap } ? 1 : 0;
|
||||||
|
|
||||||
@ -77,10 +77,6 @@ my $SOCKET_MODULE =
|
|||||||
: eval { require IO::Socket::INET } ? 'IO::Socket::INET'
|
: eval { require IO::Socket::INET } ? 'IO::Socket::INET'
|
||||||
: die $@;
|
: die $@;
|
||||||
|
|
||||||
if ($SOCKET_MODULE eq 'IO::Socket::INET') {
|
|
||||||
print_log ("IO::Socket::INET6 is not found. IPv6 is disabled.");
|
|
||||||
}
|
|
||||||
|
|
||||||
# Program version
|
# Program version
|
||||||
our $VERSION = '0.4.0';
|
our $VERSION = '0.4.0';
|
||||||
|
|
||||||
@ -173,6 +169,10 @@ my $t_use_libwrap = 0;
|
|||||||
my $t_program_name = $0;
|
my $t_program_name = $0;
|
||||||
$t_program_name =~ s/.*\///g;
|
$t_program_name =~ s/.*\///g;
|
||||||
|
|
||||||
|
# logfile name and it's file handle
|
||||||
|
my $t_logfile;
|
||||||
|
my $t_logfile_handle;
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
## SUB print_help
|
## SUB print_help
|
||||||
## Print help screen.
|
## Print help screen.
|
||||||
@ -192,6 +192,7 @@ sub print_help {
|
|||||||
print ("\t-h\t\tShow help.\n");
|
print ("\t-h\t\tShow help.\n");
|
||||||
print ("\t-i\t\tFilters.\n");
|
print ("\t-i\t\tFilters.\n");
|
||||||
print ("\t-k key\t\tOpenSSL private key file.\n");
|
print ("\t-k key\t\tOpenSSL private key file.\n");
|
||||||
|
print ("\t-l file\t\tPath to the log file. Only used in daemon mode.\n");
|
||||||
print ("\t-m size\t\tMaximum file size in bytes (default ${t_max_size}b).\n");
|
print ("\t-m size\t\tMaximum file size in bytes (default ${t_max_size}b).\n");
|
||||||
print ("\t-o\t\tEnable file overwrite.\n");
|
print ("\t-o\t\tEnable file overwrite.\n");
|
||||||
print ("\t-p port\t\tPort to listen on (default $t_port).\n");
|
print ("\t-p port\t\tPort to listen on (default $t_port).\n");
|
||||||
@ -221,9 +222,13 @@ sub daemonize {
|
|||||||
|
|
||||||
open (STDIN, '/dev/null') || error ("Cannot read /dev/null: $!.");
|
open (STDIN, '/dev/null') || error ("Cannot read /dev/null: $!.");
|
||||||
|
|
||||||
# Do not be verbose when running as a daemon
|
if ($t_logfile) {
|
||||||
open (STDOUT, '>/dev/null') || error ("Cannot write to /dev/null: $!.");
|
open_logfile();
|
||||||
open (STDERR, '>/dev/null') || error ("Cannot write to /dev/null: $!.");
|
} else {
|
||||||
|
# Do not be verbose when running as a daemon
|
||||||
|
open (STDOUT, '>/dev/null') || error ("Cannot write to /dev/null: $!.");
|
||||||
|
open (STDERR, '>/dev/null') || error ("Cannot write to /dev/null: $!.");
|
||||||
|
}
|
||||||
|
|
||||||
# Fork
|
# Fork
|
||||||
$pid = fork ();
|
$pid = fork ();
|
||||||
@ -235,6 +240,14 @@ sub daemonize {
|
|||||||
if ($pid != 0) {
|
if ($pid != 0) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
$SIG{TERM} = \&stop_server;
|
||||||
|
$SIG{HUP} = sub {
|
||||||
|
print_log ("SIGHUP received.");
|
||||||
|
if ($t_logfile_handle) {
|
||||||
|
close($t_logfile_handle);
|
||||||
|
open_logfile();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
# Child
|
# Child
|
||||||
POSIX::setsid () || error ("Cannot start a new session: $!.");
|
POSIX::setsid () || error ("Cannot start a new session: $!.");
|
||||||
@ -271,7 +284,7 @@ sub parse_options {
|
|||||||
my @t_addresses_tmp;
|
my @t_addresses_tmp;
|
||||||
|
|
||||||
# Get options
|
# Get options
|
||||||
if (getopts ('a:c:de:f:hi:k:m:op:qr:s:t:vwx:b:g:T', \%opts) == 0 || defined ($opts{'h'})) {
|
if (getopts ('a:c:de:f:hi:k:l:m:op:qr:s:t:vwx:b:g:T', \%opts) == 0 || defined ($opts{'h'})) {
|
||||||
print_help ();
|
print_help ();
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
@ -467,6 +480,10 @@ sub parse_options {
|
|||||||
error ("Authen::Libwrap is not installed.");
|
error ("Authen::Libwrap is not installed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (defined ($opts{'l'})) {
|
||||||
|
$t_logfile = $opts{'l'};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -510,6 +527,11 @@ sub open_proxy {
|
|||||||
################################################################################
|
################################################################################
|
||||||
sub start_server {
|
sub start_server {
|
||||||
|
|
||||||
|
# Show IPv6 status
|
||||||
|
if ($SOCKET_MODULE eq 'IO::Socket::INET') {
|
||||||
|
print_log ("IO::Socket::INET6 is not found. IPv6 is disabled.");
|
||||||
|
}
|
||||||
|
|
||||||
my $t_server_socket;
|
my $t_server_socket;
|
||||||
|
|
||||||
foreach my $t_address (@t_addresses) {
|
foreach my $t_address (@t_addresses) {
|
||||||
@ -526,8 +548,9 @@ sub start_server {
|
|||||||
print_log ("Cannot open socket for address $t_address on port $t_port: $!.");
|
print_log ("Cannot open socket for address $t_address on port $t_port: $!.");
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
my $msg = "Server listening on $t_address port $t_port";
|
||||||
print_log ("Server listening on $t_address port $t_port (press <ctr-c> to stop)");
|
$msg .= " (press <ctr-c> to stop)" unless $t_daemon;
|
||||||
|
print_log ($msg);
|
||||||
|
|
||||||
# Say message if tentacle proxy is enable
|
# Say message if tentacle proxy is enable
|
||||||
if (defined ($t_proxy_ip)) {
|
if (defined ($t_proxy_ip)) {
|
||||||
@ -606,6 +629,18 @@ sub close_proxy {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## SUB open_logfile
|
||||||
|
## open logfile and assign log file handle to STDOUT and STDERR
|
||||||
|
################################################################################
|
||||||
|
sub open_logfile {
|
||||||
|
if ($t_logfile) {
|
||||||
|
open ($t_logfile_handle, '>>', $t_logfile) || error ("Cannot open log file: $t_logfile: $!.");
|
||||||
|
open (STDOUT, '>&', $t_logfile_handle) || error ("Cannot dup log file handle: $!.");
|
||||||
|
open (STDERR, '>&', $t_logfile_handle) || error ("Cannot dup log file handle: $!.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
## SUB stop_server
|
## SUB stop_server
|
||||||
## Close the server socket.
|
## Close the server socket.
|
||||||
@ -616,6 +651,9 @@ sub stop_server {
|
|||||||
$t_server_socket->close ();
|
$t_server_socket->close ();
|
||||||
}
|
}
|
||||||
print_log ("Server going down");
|
print_log ("Server going down");
|
||||||
|
if ($t_logfile_handle) {
|
||||||
|
close($t_logfile_handle);
|
||||||
|
}
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
@ -1027,6 +1065,15 @@ sub send_file {
|
|||||||
# Common functions
|
# Common functions
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## SUB format_log
|
||||||
|
## format log message
|
||||||
|
################################################################################
|
||||||
|
sub format_log {
|
||||||
|
return strftime("%Y-%m-%d %H:%M:%S ", localtime())
|
||||||
|
. $t_program_name. ' [' . $$ . ']: ' . $_[0];
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
## SUB print_log
|
## SUB print_log
|
||||||
## Print log messages.
|
## Print log messages.
|
||||||
@ -1034,7 +1081,9 @@ sub send_file {
|
|||||||
sub print_log {
|
sub print_log {
|
||||||
|
|
||||||
if ($t_log == 1) {
|
if ($t_log == 1) {
|
||||||
print (STDOUT "[log] $_[0]\n");
|
my $msg = "[log] $_[0]\n";
|
||||||
|
$msg = format_log($msg) if ($t_logfile_handle);
|
||||||
|
print (STDOUT $msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1045,7 +1094,9 @@ sub print_log {
|
|||||||
sub error {
|
sub error {
|
||||||
|
|
||||||
if ($t_quiet == 0) {
|
if ($t_quiet == 0) {
|
||||||
print (STDERR "[err] $_[0]\n");
|
my $msg = "[err] $_[0]\n";
|
||||||
|
$msg = format_log($msg) if ($t_logfile_handle);
|
||||||
|
print (STDERR $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 1;
|
exit 1;
|
||||||
@ -1432,11 +1483,6 @@ if ($#ARGV != -1) {
|
|||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Show IPv6 status
|
|
||||||
if ($SOCKET_MODULE eq 'IO::Socket::INET') {
|
|
||||||
print_log ("IO::Socket::INET6 is not found. IPv6 is disabled.");
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run as daemon?
|
# Run as daemon?
|
||||||
if ($t_daemon == 1 && $^O ne 'MSWin32') {
|
if ($t_daemon == 1 && $^O ne 'MSWin32') {
|
||||||
daemonize ();
|
daemonize ();
|
||||||
@ -1494,6 +1540,8 @@ __END__
|
|||||||
|
|
||||||
=item I<-k key> B<OpenSSL private key> file.
|
=item I<-k key> B<OpenSSL private key> file.
|
||||||
|
|
||||||
|
=item I<-l file> Path to the B<log file>. Only used in daemon mode.
|
||||||
|
|
||||||
=item I<-m size> B<Maximum file size> in bytes (default I<2000000b>).
|
=item I<-m size> B<Maximum file size> in bytes (default I<2000000b>).
|
||||||
|
|
||||||
=item I<-o> Enable file B<overwrite>.
|
=item I<-o> Enable file B<overwrite>.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user