Skip to content

Commit

Permalink
Merge branch 'release/0.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed Jan 27, 2024
2 parents f2ce34f + 5e6b3d0 commit d459ec8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
24 changes: 19 additions & 5 deletions Connect-VPN.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function Connect-AnyConnect() # {{{
[Parameter(Position=3, ParameterSetName='Plain', Mandatory=$true)]
[string] $Password,
[Parameter(Position=4, Mandatory=$false)]
[switch] $AcceptNotice
[switch] $AcceptNotice,
[Parameter(Position=5, Mandatory=$false)]
[int] $Timeout = 60
)
if ($PSCmdlet.ParameterSetName -eq 'Credential')
{
Expand Down Expand Up @@ -42,7 +44,7 @@ function Connect-AnyConnect() # {{{

# First Stop any VPN cli and ui
# There must be only one "client" running when connecting
Get-Process | Where ProcessName -match 'vpn(ui|cli)' | ForEach {
Get-Process | Where-Object ProcessName -match 'vpn(ui|cli)' | ForEach-Object {
if (! $_.HasExited)
{
Write-Verbose "Stopping process $($_.Name) (pid: $($_.Id))"
Expand Down Expand Up @@ -88,9 +90,9 @@ function Connect-AnyConnect() # {{{
$vpncli.StandardInput.WriteLine("y")
}

$timer = [Diagnostics.Stopwatch]::StartNew()
Write-Verbose "Reading its output stream"
$found = $false
for ($output = $vpncli.StandardOutput.ReadLine(); $output -ne $null; $output = $vpncli.StandardOutput.ReadLine())
for ($output = $vpncli.StandardOutput.ReadLine(); $null -ne $output -and $timer.Elapsed.TotalSeconds -lt $Timeout; $output = $vpncli.StandardOutput.ReadLine())
{
Write-Debug $output
if ($output -eq ' >> Login failed.')
Expand All @@ -111,6 +113,12 @@ function Connect-AnyConnect() # {{{
}
}
}
$timer.Stop()
if ($timer.Elapsed.TotalSeconds -ge $Timeout)
{
Write-Error "Timeout ($Timeout seconds) while connecting to $ComputerName"
return [PSCustomObject] @{}
}
Start-Process -FilePath (Get-Anyconnect -gui)

return [PSCustomObject] @{
Expand Down Expand Up @@ -150,6 +158,10 @@ function Connect-AnyConnect() # {{{
.PARAMETER AcceptNotice
Accept notice from the server, like a banner message.
.PARAMETER Timeout
Maximum time in seconds to wait for the connection to be established.
Default is 60 seconds.
.INPUTS
The ComputerName can be piped in.
Expand Down Expand Up @@ -193,7 +205,9 @@ function Connect-VPN # {{{
[Parameter(Position=4, ParameterSetName='Plain', Mandatory=$true)]
[string] $Password,
[Parameter(Position=5, Mandatory=$false)]
[switch] $AcceptNotice
[switch] $AcceptNotice,
[Parameter(Position=6, Mandatory=$false)]
[int] $Timeout = 60
)
DynamicParam
{
Expand Down
2 changes: 1 addition & 1 deletion Install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Param(
)

$ModuleName = 'Posh-VPN'
$ModuleVersion = '0.1.5'
$ModuleVersion = '0.1.6'
$GithubRoot = "https://raw.githubusercontent.com/gildas/posh-vpn/$ModuleVersion"

if ([string]::IsNullOrEmpty($Path))
Expand Down
2 changes: 1 addition & 1 deletion Posh-VPN.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Posh-VPN.psm1'

# Version number of this module.
ModuleVersion = '0.1.5'
ModuleVersion = '0.1.6'

# ID used to uniquely identify this module
GUID = 'c762b59e-61f1-4411-9c5b-3709a00199c1'
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Install-Module Posh-VPN
Copy the following line and paste it in a Powershell:

```posh
Start-BitsTransfer http://tinyurl.com/posh-vpn-0-1-5 $env:TEMP ; & $env:TEMP\Install.ps1
Start-BitsTransfer https://raw.githubusercontent.com/gildas/posh-vpn/0.1.6/Install.ps1 $env:TEMP ; & $env:TEMP\Install.ps1
```

To install the latest development version, use one of the followings:
Expand Down Expand Up @@ -65,6 +65,11 @@ PS> $creds = Get-Credential ACME\gildas
PS> $vpn = Connect-VPN -Provider AnyConnect -ComputerName vpn.acme.com -Credential $creds
```

You can also specify a custom timeout. Upon reaching the timeout the `Connect-VPN` Cmdlet will display an error:
```posh
PS> $vpn = Connect-VPN -Provider AnyConnect -ComputerName vpn.acme.com -Credential $creds -Timeout 60
```

In both cases, you can use the TAB completion for the ComputerName. The values come from the available profiles/servers/connections for the given provider.

To get the status of a VPN session:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.5
0.1.6

0 comments on commit d459ec8

Please sign in to comment.