Skip to content

Commit

Permalink
Release v0.0.10-alpha
Browse files Browse the repository at this point in the history
Summary:
  * Bugfix fatal error preventing Socks connection from being
    established
  * Adding new configuration option `jump_port` to specify a port
    should an ssh connection be a different port than `22`.
  * Allow the `jump_host` to be `localhost , `127.0.0.1` or '::1`
    when a connection is forwarded to an other incoming ssh tunnel.
    requires the `jump_port` to be set.
  • Loading branch information
uroesch committed May 17, 2020
1 parent 6994f0d commit e3f38f5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ name = dmz
enabled = yes
setup = no
jump_host = dmz-jumphost.acme.org
jump_port = 2222
```

* `Socks:8881` instructs to create a local Socks proxy on port `8881`.
Equivalent to `-D 8881` on the command line.
* `enabled` should the socks proxy be started or not. Accepts `yes` or `no`.
* `setup` set to `yes` if the jumphost is used for the first time. Accepts `yes` or `no`
* `jump_host` defines the termination point of the Socks proxy.
* `jump_port` defines the port of `jump_host'`s connection, if ommited defaults to 22.


### Example LocalTunnel
Expand Down
66 changes: 48 additions & 18 deletions src/PlinkProxy.au3
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ Opt("MustDeclareVars", 1)
; Functions
; --------------------------------------------------------------------------------------------------------------

; Return a default value for a field default is 'n/a'
Func DefaultValues($Field)
Select
Case $Field = 'jump_port'
Return 22
Case Else
Return 'n/a'
EndSelect
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func _AssocArray()
Local $AssocArray = ObjCreate("Scripting.Dictionary")
If @error Then
Expand Down Expand Up @@ -114,7 +126,7 @@ Func FetchEntry($Section, $Field, $Prefix = "")
If $Prefix <> "" Then
$Section = $Prefix & ":" & $Section
EndIf
Return IniRead($ConfigFile, $Section, $Field, "n/a")
Return IniRead($ConfigFile, $Section, $Field, DefaultValues($Field))
EndFunc

; --------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -152,47 +164,67 @@ EndFunc

; --------------------------------------------------------------------------------------------------------------

Func AssembleProxyCommand($Host)
Func AssembleHost($Host)
If StringInStr($Host, ':') Then
Return $Host
EndIf
Return $Host & ':22'
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func AssembleProxyCommand($JumpHost, $JumpPort = 22)
; Only return proxy command if jump host is not the first hop
; to prevent loops
Local $ProxyCommand = ""
If $Host <> $Globals('first_hop') Then
If $JumpHost <> $Globals('first_hop') Then
$ProxyCommand = _
' -proxycmd "plink -nc ' & $Host & ':22 ' & $Globals('login') & '@' & $Globals('first_hop') & '" '
' -proxycmd "plink -nc ' _
& $JumpHost & ':' & $JumpPort & ' ' _
& $Globals('login') & '@' & $Globals('first_hop') & '" '
EndIf
Return $ProxyCommand
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func AssemblePlinkOptions($Host, $Options)
Func AssemblePlinkOptions($JumpHost, $JumpPort, $Options)
; If the connectin is to forwarded port from another incoming ssh connection on the first hop
; then we need to set to connect host to the same value as the first_hop. Otherwise the connection
; is attempted locally.
Local $ConnectHost = $JumpHost
If StringRegExp($Jumphost, "^(localhost\.?|127\.0\.0\.1|::1)$") Then
$ConnectHost = $Globals('first_hop')
EndIf
Local $PlinkOptions = _
$Options & " " _
& AssembleProxyCommand($Host) _
& $Globals('login') & '@' & $Host
& AssembleProxyCommand($JumpHost, $JumpPort) _
& $Globals('login') & '@' & $ConnectHost
Return $PlinkOptions
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func DigTunnel($TunnelId, $Host, $Options)
Local $Enabled = FetchEntry($TunnelId, 'enabled')
Func DigTunnel($TunnelId, $Options)
Local $PlinkCommand
Local $JumpHost = FetchEntry($TunnelId, 'jump_host')
Local $JumpPort = FetchEntry($TunnelId, 'jump_port')
Local $Enabled = FetchEntry($TunnelId, 'enabled')
Local $HideWindow = @SW_HIDE
Local $AllOptions = $Globals('plink_options') & ' ' & $Options
Local $AllOptions = $Globals('plink_options') & ' -P ' & $JumpPort & ' ' & $Options
Local $SetupMode = StringLower(FetchEntry($TunnelId, 'setup'))
; skip non enabled tunnels
If StringLower($Enabled) == 'no' Then
Return
EndIf
If Not CheckTunnel($TunnelId) Then
If $Setup And $SetupMode == 'yes' Then
$AllOptions = "-A -v " & $Options
$AllOptions = '-A -v -P ' & $JumpPort & ' ' & $Options
$HideWindow = 1
$PlinkCommand = 'plink ' & AssemblePlinkOptions($Host, $AllOptions)
$PlinkCommand = 'plink ' & AssemblePlinkOptions($JumpHost, $JumpPort, $AllOptions)
RunWait($PlinkCommand, "", $HideWindow)
ElseIf $SetupMode <> 'yes' Then
$PlinkCommand = 'plink ' & AssemblePlinkOptions($Host, $AllOptions)
$PlinkCommand = 'plink ' & AssemblePlinkOptions($JumpHost, $JumpPort, $AllOptions)
$TunnelPids($TunnelId) = Run($PlinkCommand, "", $HideWindow)
EndIf
Logger('Info', "Opening tunnel '" & $TunnelId & "' with command '" & $PlinkCommand & "'")
Expand All @@ -202,29 +234,27 @@ EndFunc

Func DigSocksTunnel($TunnelId)
Local $Options = "-D " & StringRegExpReplace($TunnelId, ".*:", "")
DigTunnel($TunnelId, $Host, $Options)
DigTunnel($TunnelId, $Options)
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func DigLocalTunnel($TunnelId)
Local $Host = FetchEntry($TunnelId, 'jump_host')
Local $Options = _
"-L " & StringRegExpReplace($TunnelId, ".*:", "") _
& ':' & FetchEntry($TunnelId, 'target_host') _
& ':' & FetchEntry($TunnelId, 'target_port')
DigTunnel($TunnelId, $Host, $Options)
DigTunnel($TunnelId, $Options)
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func DigRemoteTunnel($TunnelId)
Local $Host = FetchEntry($TunnelId, 'jump_host')
Local $Options = _
"-R " & StringRegExpReplace($TunnelId, ".*:", "") _
& ':' & FetchEntry($TunnelId, 'target_host') _
& ':' & FetchEntry($TunnelId, 'target_port')
DigTunnel($TunnelId, $Host, $Options)
DigTunnel($TunnelId, $Options)
EndFunc

; --------------------------------------------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/PlinkProxy.ini-sample
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ target_port = 636
; the only one being executed when the [Setup Proxies] button is pressed.
; After setup has been conducted change the value to `no`. The simplified
; plink command finally executed looks like the one below.
; `plink -proxycmd "plink -nc admin.dmz.sample.net:22 [email protected]" ^
; -L 12443:ldap.dmz.sample.net:443 [email protected]`
; `plink -proxycmd "plink -nc admin.dmz.sample.net:2222 [email protected]" ^
; -L 12443:ldap.dmz.sample.net:443 -P 2222 [email protected]`
; In the local webbrowser use 'https://localhost:12443/' to connect to the
; web server
name = dmz-http
enabled = yes
setup = yes
jump_host = admin.dmz.sample.net
jump_port = 2222
target_host = www.dmz.sample.net
target_port = 443

Expand Down
2 changes: 1 addition & 1 deletion src/Version.au3
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; ---------------------------------------------------------------------------------
; Version file used by the make, packaging and compile tools
; ---------------------------------------------------------------------------------
Global Const $VERSION = "0.0.9-alpha"
Global Const $VERSION = "0.0.10-alpha"
Global Const $VERSION_MAJOR = (StringSplit($VERSION, '.-'))[1]
Global Const $VERSION_MINOR = (StringSplit($VERSION, '.-'))[2]
Global Const $VERSION_PATCH = (StringSplit($VERSION, '.-'))[3]
Expand Down

0 comments on commit e3f38f5

Please sign in to comment.