Merge pull request #314 from Icinga:feature/listen_localhost_default_socket

Feature: Adds support to set listen ip, defaults to localhost

We should ensure the local socket creation always defaults to the loopback interface, while making it configurable on which IP it listens.
This commit is contained in:
Lord Hepipud 2021-08-04 10:08:57 +02:00 committed by GitHub
commit 4bb17aadae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#301](https://github.com/Icinga/icinga-powershell-framework/pull/301) Improves error handling to no longer print passwords in case `String` is used for `SecureString` arguments
* [#305](https://github.com/Icinga/icinga-powershell-framework/pull/305) Adds a new Cmdlet to test if functions with `Add-Type` are already present inside the current scope of the shell
* [#306](https://github.com/Icinga/icinga-powershell-framework/pull/306) Adds new Cmdlet `Exit-IcingaThrowCritical` to throw critical exit with a custom message, either by force or by using string filtering and adds storing of plugin exit codes internally
* [#314](https://github.com/Icinga/icinga-powershell-framework/pull/314) Adds support to configure on which address TCP sockets are created on, defaults to `loopback` interface
## 1.5.2 (2021-07-09)

View file

@ -1,6 +1,7 @@
function New-IcingaTCPSocket()
{
param (
[string]$Address = '',
[int]$Port = 0,
[switch]$Start = $FALSE
);
@ -9,7 +10,14 @@ function New-IcingaTCPSocket()
throw 'Please specify a valid port to open a TCP socket for';
}
$TCPSocket = [System.Net.Sockets.TcpListener]$Port;
# Listen on localhost by default
$ListenAddress = New-Object System.Net.IPEndPoint([IPAddress]::Loopback, $Port);
if ([string]::IsNullOrEmpty($Address) -eq $FALSE) {
$ListenAddress = New-Object System.Net.IPEndPoint([IPAddress]::Parse($Address), $Port);
}
$TCPSocket = New-Object 'System.Net.Sockets.TcpListener' $ListenAddress;
Write-IcingaDebugMessage -Message (
[string]::Format(