#!/usr/bin/perl use strict; $| = 1; my $THREADS_SUPPORTED; #required for polling support on STDIN in windows... my $IS_WINDOWS; BEGIN { $IS_WINDOWS = $^O =~ /mswin/i; if ($IS_WINDOWS){ $THREADS_SUPPORTED = eval 'use threads; 1'; if ($THREADS_SUPPORTED){ require threads; import threads; } } } require IO::Socket::INET; require IO::Socket::SSL; use IO::Socket; use Time::HiRes qw( sleep ); use POSIX ":sys_wait_h"; my ($pid,$output_buffer,$in_cleanup,$proc_stdin); my @AUTOS = qw/-pb -do -st internal -l 7/; push @AUTOS, "-ia" if (! $IS_WINDOWS || $THREADS_SUPPORTED); my ($DISPLAY_OUTPUT,$ACCEPT_INPUT,$PASTEBIN_USER,$FILE,$OB_AUTO,$OB_FILE,@SIP_TRACE_ON,$SOFIA_LOG_LEVEL,$CLEANUP_COMMANDS,$DEBUG_MODE,$JUST_READ_FILE,$PASTEBIN_TIME,$PASTEBIN_TITLE,$PASTEBIN_PRIVATE); $SIG{INT} = \&cleanup; $0=~/^(.+[\\\/])[^\\\/]+[\\\/]*$/; my $base_folder = $1 || "./"; $base_folder =~ s/\\/\//g; my $FS_CLI = $IS_WINDOWS ? $base_folder . "fs_cli.exe" : $base_folder . "fs_cli"; if (! -e $FS_CLI){ $FS_CLI = $IS_WINDOWS ? "fs_cli.exe" : "./fs_cli"; if (! -e $FS_CLI){ $FS_CLI = $IS_WINDOWS ? $base_folder . "bin//fs_cli.exe" : $base_folder . "bin/fs_cli"; if (! -e $FS_CLI){ $FS_CLI = $IS_WINDOWS ? "c:/program files/Freeswitch/fs_cli.exe" : "/usr/local/freeswitch/bin/fs_cli"; } } } die "Unable to find fs_cli in the fs_logger.pl directory($base_folder), the current directory or in default location of: $FS_CLI" if (! -e $FS_CLI); my @CMD = qw/-b/; my (@EXEC_ON_CONNECT,@EXEC_ON_QUIT); sub usage(){ my $auto_str = join " ", @AUTOS; my $usage = qq~ Usage: fs_logger.pl options -A, --auto Auto mode, equiv of $auto_str -h, --help Usage Information -H, --host=hostname Host to connect -P, --port=port Port to connect (1 - 65535) -u, --user=user\@domain user\@domain -p, --password=password Password -x, --execute=command Execute Command on connect -X, --quit-execute=command Execute Command when quitting -l, --loglevel=command Log Level -d, --debug=level fs_cli Debug Level (0 - 7) -t, --timeout Timeout for API commands (in milliseconds) -q, --quiet Disable logging -r, --retry Retry connection on failure -R, --reconnect Reconnect if disconnected -f, --file= Output file -pb --paste-bin[=] Post to FS Pastebin (optional post as) -st --sip-trace[=] Sip trace (optional profile to trace on) -sd --sip-debug= Set SIP debug level -oa --obfuscate-auto Auto obfuscate sensitive information -of --obfuscate-file= File containing strings to obfuscate -do --display-output Display output on stdout -ia --input-accept Pass input to the freeswitch console -D, --fslogger-debug FSLogger debug mode -jrf --just-read-file= Read file instead of collecting log from fs_cli -pbt --pastebin-time=