Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
awit-ssh-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
allworldit
awit-ssh-client
Commits
949d2644
Commit
949d2644
authored
8 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
Added username specification support
parent
0ec0b2e7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
awit-ssh
+24
-14
24 additions, 14 deletions
awit-ssh
with
24 additions
and
14 deletions
awit-ssh
+
24
−
14
View file @
949d2644
...
...
@@ -45,7 +45,7 @@ if (!eval {require Term::ReadKey; 1;}) {
use
User::
pwent
;
my
$VERSION
=
"
0.1.
1
";
my
$VERSION
=
"
0.1.
3
";
print
(
STDERR
"
AWIT-SSH-Client v
$VERSION
- Copyright (c) 2016, AllWorldIT
\n\n
");
...
...
@@ -76,15 +76,27 @@ if (defined($optctl{'version'})) {
}
# Variables we may set below
my
$loginUsername
;
# Pull in hostname
my
$hostSpec
=
shift
(
@ARGV
)
//
"";
my
(
$host
,
$port
)
=
split
('
:
',
$hostSpec
);
if
(
!
defined
(
$host
))
{
my
(
$loginHost
,
$loginPort
)
=
split
('
:
',
$hostSpec
);
if
(
defined
(
$loginHost
))
{
# Suck in username if specified
my
(
$userBit
,
$hostBit
)
=
split
('
:
',
$loginHost
);
if
(
defined
(
$hostBit
))
{
$loginUsername
=
$userBit
;
$loginHost
=
$hostBit
;
}
}
else
{
logger
('
ERROR
',
color
('
magenta
')
.
"
No hostname provided
"
.
color
('
reset
'));
exit
1
;
}
# Check for config and read
my
$configFile
=
$ENV
{"
HOME
"}
.
'
/.awit-ssh.conf
';
if
(
!
-
f
$configFile
)
{
...
...
@@ -107,7 +119,6 @@ if (!defined($ldapBase) || $ldapBase eq "") {
# Check if we should be doing port knocking
if
(
defined
(
my
$knock
=
$optctl
{'
knock
'}))
{
# If so, split off the host and the port
...
...
@@ -171,7 +182,7 @@ my $mesg = $ldap->bind("cn=$username,ou=Users,$ldapBase",password => $password);
# Search
$mesg
=
$ldap
->
search
(
base
=>
"
ou=Servers,
$ldapBase
",
filter
=>
"
(|(cn=
$
h
ost
)(awitLoginHost=
$
h
ost
)(awitLoginHostAlias=
$
h
ost
))
",
filter
=>
"
(|(cn=
$
loginH
ost
)(awitLoginHost=
$
loginH
ost
)(awitLoginHostAlias=
$
loginH
ost
))
",
);
# Check for error
if
(
my
$mesgCode
=
$mesg
->
code
())
{
...
...
@@ -186,7 +197,6 @@ if (my $mesgCode = $mesg->code()) {
# Some flags we may need
my
$needDSS
;
my
$loginUsername
;
# If no matches
...
...
@@ -226,19 +236,19 @@ if ($ldapEntry) {
# Check if we need to set the host
if
(
my
$ldapLoginHost
=
$ldapEntry
->
get_value
('
awitLoginHost
'))
{
logger
('
INFO
',"
- Host
"
.
color
('
green
')
.
"
%s
"
.
color
('
reset
')
.
"
(awitLoginHost)
",
$ldapLoginHost
);
$
h
ost
=
$ldapLoginHost
;
$
loginH
ost
=
$ldapLoginHost
;
}
# Check if we need to set the port
if
(
my
$ldapLoginPort
=
$ldapEntry
->
get_value
('
awitLoginPort
'))
{
logger
('
INFO
',"
- Port
"
.
color
('
green
')
.
"
%s
"
.
color
('
reset
')
.
"
(awitLoginPort)
",
$ldapLoginPort
);
$
p
ort
=
$ldapLoginPort
;
$
loginP
ort
=
$ldapLoginPort
if
(
!
defined
(
$loginPort
))
;
}
# Check if we need to set the username
if
(
my
$ldapLoginUsername
=
$ldapEntry
->
get_value
('
awitLoginUsername
'))
{
logger
('
INFO
',"
- Username
"
.
color
('
green
')
.
"
%s
"
.
color
('
reset
')
.
"
(awitLoginUsername)
",
$ldapLoginUsername
);
$loginUsername
=
$ldapLoginUsername
;
$loginUsername
=
$ldapLoginUsername
if
(
!
defined
(
$loginUsername
))
;
}
# Check if we have a description
...
...
@@ -273,8 +283,8 @@ if ($ldapEntry) {
my
@sshArgs
=
();
# Check if we have a port defined, if so specify it
if
(
defined
(
$
p
ort
))
{
push
(
@sshArgs
,'
-p
',
$
p
ort
);
if
(
defined
(
$
loginP
ort
))
{
push
(
@sshArgs
,'
-p
',
$
loginP
ort
);
}
# Check if we have a different username defined to login as
...
...
@@ -290,8 +300,8 @@ if (defined($needDSS)) {
push
(
@sshArgs
,'
-o
','
HostKeyAlgorithms=+ssh-dss
');
}
logger
('
NOTICE
',"
Connecting to host '
"
.
color
('
green
')
.
"
$
h
ost
"
.
color
('
reset
')
.
"
'
"
.
(
defined
(
$
p
ort
)
?
"
on port '
"
.
color
('
green
')
.
"
$
p
ort
"
.
color
('
reset
')
.
"
'
"
:
"")
.
"
...
\n\n\n
");
logger
('
NOTICE
',"
Connecting to host '
"
.
color
('
green
')
.
"
$
loginH
ost
"
.
color
('
reset
')
.
"
'
"
.
(
defined
(
$
loginP
ort
)
?
"
on port '
"
.
color
('
green
')
.
"
$
loginP
ort
"
.
color
('
reset
')
.
"
'
"
:
"")
.
"
...
\n\n\n
");
exec
('
/usr/bin/ssh
',
'
-F
',
$ENV
{"
HOME
"}
.
'
/.ssh/config
',
...
...
@@ -312,7 +322,7 @@ exec('/usr/bin/ssh',
'
-o
','
ControlMaster=autoask
',
'
-o
','
ControlPath=~/.ssh/awit-ssh-master-%C
',
@sshArgs
,
$
h
ost
$
loginH
ost
);
exit
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment