Skip to content
Snippets Groups Projects
Commit 732f2def authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Added --rsync support

parent fe3b0e2f
No related branches found
No related tags found
1 merge request!15Added rsync support
......@@ -67,6 +67,8 @@ GetOptions(\%optctl,
"debug",
"knock=s",
"rsync",
) or exit 1;
# Check for help
......@@ -81,6 +83,13 @@ if (defined($optctl{'version'})) {
exit 0;
}
# Check if we using rsync instead of SSH
my $useRsync = 0;
my @rsyncParams;
if (defined(my $rsyncHost = $optctl{'rsync'})) {
$useRsync = $rsyncHost;
}
# Check if we should be doing port knocking
my ($knockHost,$knockPort);
if (defined(my $knock = $optctl{'knock'})) {
......@@ -97,7 +106,33 @@ if (defined(my $knock = $optctl{'knock'})) {
my $loginUsername;
# Pull in hostname
my $hostSpec = shift(@ARGV) // "";
my $hostSpec;
if ($useRsync) {
foreach my $param (@ARGV) {
# Look for the remote:// param
if ($param =~ /remote:\/\//) {
# Remove it and set the hostSpec
my $removedTag = substr($param,9);
# Assing hostSpec to the first part of the tag
($hostSpec) = split(/[\/:]/,$removedTag);
# Change first / to a :/
$removedTag =~ s,/,:/,;
push(@rsyncParams,$removedTag);
# Else just add it
} else {
push(@rsyncParams,$param);
}
}
# Make sure we got a hostSpec
if (!defined($hostSpec)) {
logger('ERROR',color('magenta')."awit-ssh --rsync needs a remote://SERVER.... to be specified on the command line".
color('reset'));
exit 1;
}
} else {
$hostSpec = shift(@ARGV) // "";
}
my ($loginHost,$loginPort) = split(':',$hostSpec);
if (defined($loginHost)) {
# Suck in username if specified
......@@ -524,16 +559,34 @@ if (defined($forwardSocket)) {
logger('NOTICE',"Connecting to host '".color('green')."$forwardHost".color('reset')."'" .
(defined($forwardPort) ? " on port '".color('green')."$forwardPort".color('reset')."'" : "") . "...\n\n\n");
# Fire up ssh
system('/usr/bin/ssh',
@sshArgs,
# Override where we connecting to
'-o',"ProxyCommand=nc -U $forwardSocket",
# Explicitly disable control master
'-o','ControlMaster=no',
$realLoginHost
);
# Check what operation we're doing
if ($useRsync) {
# Build SSH command
my $sshCmd = join(' ','/usr/bin/ssh',
@sshArgs,
# Override where we connecting to
'-o',"ProxyCommand=\"nc -U $forwardSocket\"",
# Explicitly disable control master
'-o','ControlMaster=no',
);
# Run rsync
system('/usr/bin/rsync',
'-e',$sshCmd,
@rsyncParams
);
# Normal SSH
} else {
# Fire up SSH
system('/usr/bin/ssh',
@sshArgs,
# Override where we connecting to
'-o',"ProxyCommand=nc -U $forwardSocket",
# Explicitly disable control master
'-o','ControlMaster=no',
$realLoginHost
);
}
# Unlink socket and unset it to designate we exited normally
unlink($forwardSocket);
......@@ -564,13 +617,31 @@ if (defined($forwardSocket)) {
push(@sshArgs,'-p',$loginPort);
}
system('/usr/bin/ssh',
@sshArgs,
# Use basic compression
'-o','Compression=yes',
'-o','CompressionLevel=1',
$loginHost
);
# Check what operation we're doing
if ($useRsync) {
# Build SSH command
my $sshCmd = join(' ','/usr/bin/ssh',
@sshArgs,
# Use basic compression
'-o','Compression=yes',
'-o','CompressionLevel=1'
);
# Run rsync
system('/usr/bin/rsync',
'-e',$sshCmd,
@rsyncParams
);
# Normal SSH
} else {
system('/usr/bin/ssh',
@sshArgs,
# Use basic compression
'-o','Compression=yes',
'-o','CompressionLevel=1',
$loginHost
);
}
}
......@@ -636,11 +707,17 @@ sub displayHelp
{
print(STDERR<<EOF);
Usage: $0 <options> [USER@]HOST
$0 <options> --rsync -- <rsync options> remote://[USER@]HOST/file.name /tmp
General Options:
--help What you're seeing now.
--version Display version.
--debug Enable debugging.
Secure Copy: (using rsync)
--rsync Run rsync instead of ssh, passing all
command line parameters after the host
to it. HOST is used for searching
LDAP.
Port Knocking:
--knock HOST:PORT Port knock a host to get access.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment