From 15f0090c8be9b9d2142ab6b2951d97eee7d01f0d Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 18 Aug 2021 15:05:53 +0200 Subject: [PATCH] Adds mmc list view, kickstart filter, spelling fix --- doc/31-Changelog.md | 3 +- .../06-Update-Framework-And-Components.md | 6 +-- .../32-Test-Icinga-Agent-Environment.md | 30 +++++++-------- ...-Run-Icinga-Agent-As-Other-Service-User.md | 14 +++---- .../icingaagent/tests/Test-IcingaAcl.psm1 | 4 +- lib/core/installer/Install-Icinga.psm1 | 27 ++++++++----- .../installation/general/InstallWindows.psm1 | 2 +- .../general/InstallationConfigString.psm1 | 4 +- ...Service.psm1 => SelectInstallService.psm1} | 2 +- .../menu/manage/general/ListOverview.psm1 | 19 ++++++++++ .../installer/tools/ShowInstallerMenu.psm1 | 38 ++++++++++++------- .../logging/Write-IcingaConsoleOutput.psm1 | 7 ++-- .../logging/Write-IcingaConsolePlain.psm1 | 6 ++- .../Get-IcingaRepositoryPackage.psm1 | 17 ++++++++- .../repository/Search-IcingaRepository.psm1 | 2 +- lib/core/repository/Show-Icinga.psm1 | 28 ++++++++++++-- .../tools/Add-IcingaWhiteSpaceToString.psm1 | 2 +- lib/core/tools/Write-IcingaConsoleHeader.psm1 | 33 +++++++++++++++- .../Write-IcingaConsoleTextColorSplit.psm1 | 23 +++++++++++ 19 files changed, 200 insertions(+), 67 deletions(-) rename lib/core/installer/menu/installation/ifwservice/{SelectInstallPowerShellService.psm1 => SelectInstallService.psm1} (90%) create mode 100644 lib/core/installer/menu/manage/general/ListOverview.psm1 create mode 100644 lib/core/tools/Write-IcingaConsoleTextColorSplit.psm1 diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 4978a73..bad41ca 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -20,7 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#328](https://github.com/Icinga/icinga-powershell-framework/pull/328) Fixes installer while using installation files or the installation command, which did not overwrite default values with custom values * [#330](https://github.com/Icinga/icinga-powershell-framework/pull/330) Fixes `Remove-ItemSecure` which was not using all args and might fail on empty path entries * [#332](https://github.com/Icinga/icinga-powershell-framework/pull/332) Fixes Icinga Director Self-Service ticket handling, which was not working within the Icinga Management Console -* [#335](https://github.com/Icinga/icinga-powershell-framework/pull/335) Fixex Icinga Director Self-Service Zones and CA config for legacy installation wizard +* [#335](https://github.com/Icinga/icinga-powershell-framework/pull/335) Fixes Icinga Director Self-Service Zones and CA config for legacy installation wizard ### Enhancements @@ -35,6 +35,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#322](https://github.com/Icinga/icinga-powershell-framework/pull/322) Remove legacy import feature from Framework and replace it with a dummy function, as no longer required by Icinga for Windows * [#323](https://github.com/Icinga/icinga-powershell-framework/pull/323) Adds `-RebuildCache` switch to `icinga` command alias and `Invoke-IcingaCommand`, for quicker cache re-creation for developers * [#333](https://github.com/Icinga/icinga-powershell-framework/pull/333) Adds Cmdlet `Test-IcingaForWindowsService` to test the Icinga for Windows service configuration +* [#338](https://github.com/Icinga/icinga-powershell-framework/pull/338) Improves various styles, outputs and view for the Icinga for Windows Management Console and fixes some spelling mistakes ## 1.5.2 (2021-07-09) diff --git a/doc/frameworkusage/06-Update-Framework-And-Components.md b/doc/frameworkusage/06-Update-Framework-And-Components.md index fd002a0..180203a 100644 --- a/doc/frameworkusage/06-Update-Framework-And-Components.md +++ b/doc/frameworkusage/06-Update-Framework-And-Components.md @@ -46,9 +46,9 @@ Which version of the "Icinga Framework" do you want to install? (release/snapsho [Notice]: Framework update has been completed. Please start a new PowerShell instance now to complete the update [Passed]: Icinga Agent service is installed [Passed]: The specified user "NT Authority\NetworkService" is allowed to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "NT Authority\NetworkService" -[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writeable by the Icinga Service User "NT Authority\NetworkService" -[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writeable by the Icinga Service User "NT Authority\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "NT Authority\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writable by the Icinga Service User "NT Authority\NetworkService" +[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writable by the Icinga Service User "NT Authority\NetworkService" [Passed]: Icinga Agent configuration is valid [Passed]: Icinga Agent debug log is disabled [Notice]: Starting Icinga Agent service diff --git a/doc/frameworkusage/32-Test-Icinga-Agent-Environment.md b/doc/frameworkusage/32-Test-Icinga-Agent-Environment.md index 1671433..5bc80f6 100644 --- a/doc/frameworkusage/32-Test-Icinga-Agent-Environment.md +++ b/doc/frameworkusage/32-Test-Icinga-Agent-Environment.md @@ -17,9 +17,9 @@ Once executed you will receive a status of tests which are performed: ```text [Passed]: Icinga Agent service is installed [Passed]: The specified user "NT AUTHORITY\NetworkService" is allowed to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" -[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" -[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" [Passed]: Icinga Agent configuration is valid [Passed]: Icinga Agent debug log is disabled ``` @@ -29,9 +29,9 @@ In order to make the Icinga Agent and the Icinga PowerShell Framework work prope ```text [Passed]: Icinga Agent service is installed [Passed]: The specified user "NT AUTHORITY\NetworkService" is allowed to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" -[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" -[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" [Passed]: Icinga Agent configuration is valid [Warning]: The debug log of the Icinga Agent is enabled. Please keep in mind to disable it once testing is done, as a huge amount of data is generated ``` @@ -43,10 +43,10 @@ In addition for testing, the Icinga PowerShell Framework will suggest methods to ```text [Passed]: Icinga Agent service is installed [Passed]: The specified user "NT AUTHORITY\NetworkService" is allowed to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" [Failed]: Directory "C:\ProgramData\icinga2\var" is not accessible by the Icinga Service User "NT AUTHORITY\NetworkService" \_ Please run the following command to fix this issue: Set-IcingaAcl -Directory 'C:\ProgramData\icinga2\var' -[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" [Passed]: Icinga Agent configuration is valid [Passed]: Icinga Agent debug log is disabled ``` @@ -58,7 +58,7 @@ Set-IcingaAcl -Directory 'C:\ProgramData\icinga2\var'; ``` ```text -[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" ``` Now if we run the test again, the issue is resolved: @@ -66,9 +66,9 @@ Now if we run the test again, the issue is resolved: ```text [Passed]: Icinga Agent service is installed [Passed]: The specified user "NT AUTHORITY\NetworkService" is allowed to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" -[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" -[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" [Passed]: Icinga Agent configuration is valid [Passed]: Icinga Agent debug log is disabled ``` @@ -84,9 +84,9 @@ Test-IcingaAgent;` ```text [Passed]: Icinga Agent service is installed [Passed]: The specified user "NT AUTHORITY\NetworkService" is allowed to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" -[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" -[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writeable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" +[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writable by the Icinga Service User "NT AUTHORITY\NetworkService" [Failed]: Icinga Agent configuration contains errors. Run this command for getting a detailed error report: "Test-IcingaAgentConfig -WriteStackTrace | Out-Null" [Passed]: Icinga Agent debug log is disabled ``` diff --git a/doc/frameworkusage/33-Run-Icinga-Agent-As-Other-Service-User.md b/doc/frameworkusage/33-Run-Icinga-Agent-As-Other-Service-User.md index 84f2b48..f44f9c5 100644 --- a/doc/frameworkusage/33-Run-Icinga-Agent-As-Other-Service-User.md +++ b/doc/frameworkusage/33-Run-Icinga-Agent-As-Other-Service-User.md @@ -33,9 +33,9 @@ Set-IcingaAgentServiceUser -User 'NT AUTHORITY\SYSTEM' -SetPermission; ```text [Notice]: The Icinga Service User already has permission to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "NT AUTHORITY\SYSTEM" -[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writeable by the Icinga Service User "NT AUTHORITY\SYSTEM" -[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writeable by the Icinga Service User "NT AUTHORITY\SYSTEM" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "NT AUTHORITY\SYSTEM" +[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writable by the Icinga Service User "NT AUTHORITY\SYSTEM" +[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writable by the Icinga Service User "NT AUTHORITY\SYSTEM" [Notice]: Service User successfully updated ``` @@ -64,7 +64,7 @@ If we how ever run our Cmdlet `Test-IcingaAgent` (which is described [here](32-T ```text [Failed]: The specified user "icinga" is not allowed to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "icinga" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "icinga" [Failed]: Directory "C:\ProgramData\icinga2\var" is not accessible by the Icinga Service User "icinga" \_ Please run the following command to fix this issue: Set-IcingaAcl -Directory 'C:\ProgramData\icinga2\var' ``` @@ -78,9 +78,9 @@ Set-IcingaAgentServiceUser -User $cred.UserName -Password $cred.Password -SetPer ```text [Passed]: The specified user "icinga" is allowed to run as service -[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writeable by the Icinga Service User "icinga" -[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writeable by the Icinga Service User "icinga" -[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writeable by the Icinga Service User "icinga" +[Passed]: Directory "C:\ProgramData\icinga2\etc" is accessible and writable by the Icinga Service User "icinga" +[Passed]: Directory "C:\ProgramData\icinga2\var" is accessible and writable by the Icinga Service User "icinga" +[Passed]: Directory "C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\cache" is accessible and writable by the Icinga Service User "icinga" [Notice]: Service User successfully updated ``` diff --git a/lib/core/icingaagent/tests/Test-IcingaAcl.psm1 b/lib/core/icingaagent/tests/Test-IcingaAcl.psm1 index dacab73..97f2d85 100644 --- a/lib/core/icingaagent/tests/Test-IcingaAcl.psm1 +++ b/lib/core/icingaagent/tests/Test-IcingaAcl.psm1 @@ -38,9 +38,9 @@ function Test-IcingaAcl() [string]$messageFormat = 'Directory "{0}" {1} by the Icinga Service User "{2}"'; if ($UserFound) { if ($HasAccess) { - Write-IcingaTestOutput -Severity 'Passed' -Message ([string]::Format($messageFormat, $Directory, 'is accessible and writeable', $ServiceUser)); + Write-IcingaTestOutput -Severity 'Passed' -Message ([string]::Format($messageFormat, $Directory, 'is accessible and writable', $ServiceUser)); } else { - Write-IcingaTestOutput -Severity 'Failed' -Message ([string]::Format($messageFormat, $Directory, 'is accessible but NOT writeable', $ServiceUser)); + Write-IcingaTestOutput -Severity 'Failed' -Message ([string]::Format($messageFormat, $Directory, 'is accessible but NOT writable', $ServiceUser)); Write-IcingaConsolePlain "\_ Please run the following command to fix this issue: Set-IcingaAcl -Directory '$Directory'"; } } else { diff --git a/lib/core/installer/Install-Icinga.psm1 b/lib/core/installer/Install-Icinga.psm1 index 00919d4..0e96883 100644 --- a/lib/core/installer/Install-Icinga.psm1 +++ b/lib/core/installer/Install-Icinga.psm1 @@ -103,14 +103,22 @@ function Install-Icinga() 'Help' = 'Allows you to install Icinga for Windows with all required components and options.' }, @{ - 'Caption' = 'Install Components'; - 'Command' = 'Show-IcingaForWindowsMenuInstallComponents'; - 'Help' = 'Allows you to install new components for Icinga for Windows from your repositories.'; + 'Caption' = 'Install components'; + 'Command' = 'Show-IcingaForWindowsMenuInstallComponents'; + 'Help' = 'Allows you to install new components for Icinga for Windows from your repositories.'; + 'Disabled' = (-Not ($global:Icinga.InstallWizard.AdminShell)); }, @{ - 'Caption' = 'Update environment'; - 'Command' = 'Show-IcingaForWindowsMenuUpdateComponents'; - 'Help' = 'Allows you to modify your current Icinga for Windows installation.'; + 'Caption' = 'Update components'; + 'Command' = 'Show-IcingaForWindowsMenuUpdateComponents'; + 'Help' = 'Allows you to modify your current Icinga for Windows installation.'; + 'Disabled' = (-Not ($global:Icinga.InstallWizard.AdminShell)); + }, + @{ + 'Caption' = 'Remove components'; + 'Command' = 'Show-IcingaForWindowsMenuRemoveComponents'; + 'Help' = 'Allows you to modify your current Icinga for Windows installation.'; + 'Disabled' = (-Not ($global:Icinga.InstallWizard.AdminShell)); }, @{ 'Caption' = 'Manage environment'; @@ -118,10 +126,9 @@ function Install-Icinga() 'Help' = 'Allows you to modify your current Icinga for Windows installation.'; }, @{ - 'Caption' = 'Remove components'; - 'Command' = 'Show-IcingaForWindowsMenuRemoveComponents'; - 'Help' = 'Allows you to modify your current Icinga for Windows installation.'; - 'Disabled' = (-Not ($global:Icinga.InstallWizard.AdminShell)); + 'Caption' = 'List environment'; + 'Command' = 'Show-IcingaForWindowsMenuListEnvironment'; + 'Help' = 'Shows you an overview of your current Icinga for Windows installation, including installed components and system informations.'; } ) ` -DefaultIndex 0; diff --git a/lib/core/installer/menu/installation/general/InstallWindows.psm1 b/lib/core/installer/menu/installation/general/InstallWindows.psm1 index 6fdd02e..6bb16d7 100644 --- a/lib/core/installer/menu/installation/general/InstallWindows.psm1 +++ b/lib/core/installer/menu/installation/general/InstallWindows.psm1 @@ -28,7 +28,7 @@ function Show-IcingaForWindowsInstallerMenuInstallWindows() 'Disabled' = ([bool]($null -eq (Get-IcingaPowerShellConfig -Path 'Framework.Config.Swap'))); }, @{ - 'Caption' = 'Reconfigure Environment'; + 'Caption' = 'Reconfigure environment'; 'Command' = 'Invoke-IcingaForWindowsManagementConsoleReconfigureAgent'; 'Help' = 'Load the current configuration of Icinga for Windows to modify it.'; 'Disabled' = ([bool]($null -eq (Get-IcingaPowerShellConfig -Path 'Framework.Config.Live'))); diff --git a/lib/core/installer/menu/installation/general/InstallationConfigString.psm1 b/lib/core/installer/menu/installation/general/InstallationConfigString.psm1 index 271ee91..21ee4d5 100644 --- a/lib/core/installer/menu/installation/general/InstallationConfigString.psm1 +++ b/lib/core/installer/menu/installation/general/InstallationConfigString.psm1 @@ -1,8 +1,7 @@ function Show-IcingaForWindowsManagementConsoleInstallationConfigString() { [string]$ConfigurationString = [string]::Format( - "{0}Install-Icinga -InstallCommand '{1}'{0}", - (New-IcingaNewLine), + "Install-Icinga -InstallCommand '{0}'", (Get-IcingaForWindowsManagementConsoleConfigurationString -Compress) ); @@ -23,5 +22,6 @@ function Show-IcingaForWindowsManagementConsoleInstallationConfigString() -ConfigLimit 1 ` -DefaultIndex 'c' ` -ReadOnly ` + -PlainTextOutput ` -Hidden; } diff --git a/lib/core/installer/menu/installation/ifwservice/SelectInstallPowerShellService.psm1 b/lib/core/installer/menu/installation/ifwservice/SelectInstallService.psm1 similarity index 90% rename from lib/core/installer/menu/installation/ifwservice/SelectInstallPowerShellService.psm1 rename to lib/core/installer/menu/installation/ifwservice/SelectInstallService.psm1 index 6258474..d2f4b69 100644 --- a/lib/core/installer/menu/installation/ifwservice/SelectInstallPowerShellService.psm1 +++ b/lib/core/installer/menu/installation/ifwservice/SelectInstallService.psm1 @@ -29,4 +29,4 @@ function Show-IcingaForWindowsInstallerMenuSelectInstallIcingaForWindowsService( -Advanced:$Advanced; } -Set-Alias -Name 'IfW-InstallPowerShellService' -Value 'Show-IcingaForWindowsInstallerMenuSelectInstallIcingaForWindowsService'; +Set-Alias -Name 'IfW-InstallService' -Value 'Show-IcingaForWindowsInstallerMenuSelectInstallIcingaForWindowsService'; diff --git a/lib/core/installer/menu/manage/general/ListOverview.psm1 b/lib/core/installer/menu/manage/general/ListOverview.psm1 new file mode 100644 index 0000000..361adb9 --- /dev/null +++ b/lib/core/installer/menu/manage/general/ListOverview.psm1 @@ -0,0 +1,19 @@ +function Show-IcingaForWindowsMenuListEnvironment() +{ + Show-IcingaForWindowsInstallerMenu ` + -Header 'Icinga for Windows environment overview:' ` + -Entries @( + @{ + 'Caption' = ''; + 'Command' = 'Install-Icinga'; + 'Help' = 'A summary of your current Icinga for Windows installation'; + } + ) ` + -AddConfig ` + -DefaultValues @(([string]::Join("`n", (Show-Icinga -SkipHeader)))) ` + -ConfigLimit 1 ` + -DefaultIndex 'c' ` + -ReadOnly ` + -PlainTextOutput ` + -Hidden; +} diff --git a/lib/core/installer/tools/ShowInstallerMenu.psm1 b/lib/core/installer/tools/ShowInstallerMenu.psm1 index 972f395..98ddcca 100644 --- a/lib/core/installer/tools/ShowInstallerMenu.psm1 +++ b/lib/core/installer/tools/ShowInstallerMenu.psm1 @@ -15,9 +15,10 @@ function Show-IcingaForWindowsInstallerMenu() [string]$ContinueFunction = $null, [switch]$ConfigElement = $FALSE, [switch]$HiddenConfigElement = $FALSE, - [switch]$ReadOnly = $FALSE, + [switch]$ReadOnly = $FALSE, [switch]$Automated = $FALSE, - [switch]$Advanced = $FALSE + [switch]$Advanced = $FALSE, + [switch]$PlainTextOutput = $FALSE ); if ((Test-IcingaForWindowsInstallationHeaderPrint) -eq $FALSE -And (Get-IcingaFrameworkDebugMode) -eq $FALSE) { @@ -83,19 +84,18 @@ function Show-IcingaForWindowsInstallerMenu() ); if ($global:Icinga.InstallWizard.AdminShell -eq $FALSE) { - $ConsoleHeaderLines += '[Warning]: Run this shell as Administrator to unlock all features' + $ConsoleHeaderLines += '[Warning]: Run this shell with administrative privileges to unlock all features' } - $ConsoleHeaderLines += @( - 'This is an experimental feature and might contain bugs', - 'Please provide us with feedback, issues and input at', - 'https://github.com/Icinga/icinga-powershell-framework/issues' - ) + if ($PSVersionTable.PSVersion -lt '5.0.0.0') { + $ConsoleHeaderLines += ([string]::Format('[Warning]: Update to PowerShell version >=5.0 from currently {0} to unlock all features (like JEA)', $PSVersionTable.PSVersion.ToString(2))); + } Write-IcingaConsoleHeader -HeaderLines $ConsoleHeaderLines; Write-IcingaConsolePlain ''; Write-IcingaConsolePlain $Header; + Write-IcingaConsolePlain ''; } @@ -144,10 +144,14 @@ function Show-IcingaForWindowsInstallerMenu() } if ($StoredValues.Count -ne 0) { - if ($PasswordInput -eq $FALSE) { - Write-IcingaConsolePlain ([string]::Format(' {0}', (ConvertFrom-IcingaArrayToString -Array $StoredValues -AddQuotes))) -ForeColor Cyan; + if ($PlainTextOutput) { + Write-IcingaConsolePlain (ConvertFrom-IcingaArrayToString -Array $StoredValues) -ForeColor Cyan; } else { - Write-IcingaConsolePlain ([string]::Format(' {0}', (ConvertFrom-IcingaArrayToString -Array $StoredValues -AddQuotes -SecureContent))) -ForeColor Cyan; + if ($PasswordInput -eq $FALSE) { + Write-IcingaConsolePlain ([string]::Format(' {0}', (ConvertFrom-IcingaArrayToString -Array $StoredValues -AddQuotes))) -ForeColor Cyan; + } else { + Write-IcingaConsolePlain ([string]::Format(' {0}', (ConvertFrom-IcingaArrayToString -Array $StoredValues -AddQuotes -SecureContent))) -ForeColor Cyan; + } } } @@ -163,7 +167,11 @@ function Show-IcingaForWindowsInstallerMenu() Write-IcingaConsolePlain ''; if ($global:Icinga.InstallWizard.DisplayAdvanced) { - $MenuNavigation = [string]::Format('{0} [a] Advanced', $MenuNavigation) + if ($global:Icinga.InstallWizard.ShowAdvanced -eq $FALSE) { + $MenuNavigation = [string]::Format('{0} [a] Advanced', $MenuNavigation) + } else { + $MenuNavigation = [string]::Format('{0} [a] Hide Advanced', $MenuNavigation) + } } $MenuNavigation = [string]::Format('{0} [c] Continue', $MenuNavigation) @@ -172,7 +180,11 @@ function Show-IcingaForWindowsInstallerMenu() $MenuNavigation = [string]::Format('{0} [d] Delete', $MenuNavigation) } - $MenuNavigation = [string]::Format('{0} [h] Help [m] Main', $MenuNavigation) + if ($global:Icinga.InstallWizard.ShowHelp -eq $FALSE) { + $MenuNavigation = [string]::Format('{0} [h] Help [m] Main', $MenuNavigation) + } else { + $MenuNavigation = [string]::Format('{0} [h] Hide Help [m] Main', $MenuNavigation) + } if ([string]::IsNullOrEmpty($LastParent) -eq $FALSE -Or $global:Icinga.InstallWizard.LastParent.Count -gt 1) { $MenuNavigation = [string]::Format('{0} [p] Previous', $MenuNavigation) diff --git a/lib/core/logging/Write-IcingaConsoleOutput.psm1 b/lib/core/logging/Write-IcingaConsoleOutput.psm1 index 6cb660b..c21430c 100644 --- a/lib/core/logging/Write-IcingaConsoleOutput.psm1 +++ b/lib/core/logging/Write-IcingaConsoleOutput.psm1 @@ -33,7 +33,8 @@ function Write-IcingaConsoleOutput() [array]$Objects, [ValidateSet('Default', 'Black', 'DarkBlue', 'DarkGreen', 'DarkCyan', 'DarkRed', 'DarkMagenta', 'DarkYellow', 'Gray', 'DarkGray', 'Blue', 'Green', 'Cyan', 'Red', 'Magenta', 'Yellow', 'White')] [string]$ForeColor = 'Default', - [string]$Severity = 'Notice' + [string]$Severity = 'Notice', + [switch]$NoNewLine = $FALSE ); if ((Test-IcingaFrameworkConsoleOutput) -eq $FALSE) { @@ -67,8 +68,8 @@ function Write-IcingaConsoleOutput() } if ($ForeColor -eq 'Default') { - Write-Host $OutputMessage; + Write-Host $OutputMessage -NoNewline:$NoNewLine; } else { - Write-Host $OutputMessage -ForegroundColor $ForeColor; + Write-Host $OutputMessage -ForegroundColor $ForeColor -NoNewline:$NoNewLine; } } diff --git a/lib/core/logging/Write-IcingaConsolePlain.psm1 b/lib/core/logging/Write-IcingaConsolePlain.psm1 index 6b21f2b..1cb29b4 100644 --- a/lib/core/logging/Write-IcingaConsolePlain.psm1 +++ b/lib/core/logging/Write-IcingaConsolePlain.psm1 @@ -25,12 +25,14 @@ function Write-IcingaConsolePlain() [string]$Message, [array]$Objects, [ValidateSet('Default', 'Black', 'DarkBlue', 'DarkGreen', 'DarkCyan', 'DarkRed', 'DarkMagenta', 'DarkYellow', 'Gray', 'DarkGray', 'Blue', 'Green', 'Cyan', 'Red', 'Magenta', 'Yellow', 'White')] - [string]$ForeColor = 'Default' + [string]$ForeColor = 'Default', + [switch]$NoNewLine = $FALSE ); Write-IcingaConsoleOutput ` -Message $Message ` -Objects $Objects ` -ForeColor $ForeColor ` - -Severity $null; + -Severity $null ` + -NoNewLine:$NoNewLine; } diff --git a/lib/core/repository/Get-IcingaRepositoryPackage.psm1 b/lib/core/repository/Get-IcingaRepositoryPackage.psm1 index bbb3500..47e718e 100644 --- a/lib/core/repository/Get-IcingaRepositoryPackage.psm1 +++ b/lib/core/repository/Get-IcingaRepositoryPackage.psm1 @@ -9,7 +9,22 @@ function Get-IcingaRepositoryPackage() if ([string]::IsNullOrEmpty($Name)) { Write-IcingaConsoleError 'You have to provide a component name'; - return; + + return @{ + 'HasPackage' = $FALSE; + 'Package' = $null; + 'Source' = $null; + 'Repository' = $null; + }; + } + + if ($Name.ToLower() -eq 'kickstart') { + return @{ + 'HasPackage' = $FALSE; + 'Package' = $null; + 'Source' = $null; + 'Repository' = $null; + }; } $Repositories = Get-IcingaRepositories -ExcludeDisabled; diff --git a/lib/core/repository/Search-IcingaRepository.psm1 b/lib/core/repository/Search-IcingaRepository.psm1 index 4c13c2b..5cd8870 100644 --- a/lib/core/repository/Search-IcingaRepository.psm1 +++ b/lib/core/repository/Search-IcingaRepository.psm1 @@ -43,7 +43,7 @@ function Search-IcingaRepository() foreach ($repoEntry in $RepoContent.Packages.PSObject.Properties.Name) { - if ($repoEntry -NotLike $Name) { + if ($repoEntry -NotLike $Name -Or $Name.ToLower() -eq 'kickstart') { continue; } diff --git a/lib/core/repository/Show-Icinga.psm1 b/lib/core/repository/Show-Icinga.psm1 index cebee98..5c8ec09 100644 --- a/lib/core/repository/Show-Icinga.psm1 +++ b/lib/core/repository/Show-Icinga.psm1 @@ -1,17 +1,39 @@ function Show-Icinga() { + param ( + [switch]$SkipHeader = $FALSE + ); + $IcingaInstallation = Get-IcingaInstallation -Release; [array]$Output = @( 'Icinga for Windows environment' ); + [array]$VersionList = @(); [int]$MaxComponentLength = Get-IcingaMaxTextLength -TextArray $IcingaInstallation.Keys; - [int]$MaxVersionLength = Get-IcingaMaxTextLength -TextArray $IcingaInstallation.Values.CurrentVersion; + + foreach ($entry in $IcingaInstallation.Keys) { + $LockVersion = Get-IcingaComponentLock -Name $entry; + + if ($null -eq $LockVersion) { + $VersionList += [string]$IcingaInstallation[$entry].CurrentVersion; + continue; + } + + $VersionList += ([string]::Format('{0}*', $IcingaInstallation[$entry].CurrentVersion)); + } + + [int]$MaxVersionLength = Get-IcingaMaxTextLength -TextArray $VersionList; [string]$ComponentHeader = Add-IcingaWhiteSpaceToString -Text 'Component' -Length $MaxComponentLength; [string]$ComponentLine = Add-IcingaWhiteSpaceToString -Text '---' -Length $MaxComponentLength; $Output += '-----------'; $Output += ''; + + if ($SkipHeader) { + [array]$Output = @(); + } + $Output += 'Installed components on this system'; $Output += ''; $Output += [string]::Format('{0} {1} Available', $ComponentHeader, ((Add-IcingaWhiteSpaceToString -Text 'Version' -Length $MaxVersionLength))); - $Output += [string]::Format('{0} {1} ---', $ComponentLine, ((Add-IcingaWhiteSpaceToString -Text '---' -Length $MaxVersionLength))); + $Output += [string]::Format('{0} {1} ---', $ComponentLine, ((Add-IcingaWhiteSpaceToString -Text '---' -Length $MaxVersionLength))); foreach ($component in $IcingaInstallation.Keys) { $Data = $IcingaInstallation[$component]; @@ -27,7 +49,7 @@ function Show-Icinga() } [string]$ComponentName = Add-IcingaWhiteSpaceToString -Text $component -Length $MaxComponentLength; - $Output += [string]::Format('{0} {1} {2}', $ComponentName, (Add-IcingaWhiteSpaceToString -Text $CurrentVersion -Length $MaxVersionLength), $LatestVersion); + $Output += [string]::Format('{0} {1} {2}', $ComponentName, (Add-IcingaWhiteSpaceToString -Text $CurrentVersion -Length $MaxVersionLength), $LatestVersion); } $Output += ''; diff --git a/lib/core/tools/Add-IcingaWhiteSpaceToString.psm1 b/lib/core/tools/Add-IcingaWhiteSpaceToString.psm1 index 76d8103..a0598c7 100644 --- a/lib/core/tools/Add-IcingaWhiteSpaceToString.psm1 +++ b/lib/core/tools/Add-IcingaWhiteSpaceToString.psm1 @@ -7,7 +7,7 @@ function Add-IcingaWhiteSpaceToString() [int]$LengthOffset = $Length - $Text.Length; - while ($LengthOffset -gt 0) { + while ($LengthOffset -ge 0) { $Text += ' '; $LengthOffset -= 1; } diff --git a/lib/core/tools/Write-IcingaConsoleHeader.psm1 b/lib/core/tools/Write-IcingaConsoleHeader.psm1 index c91644c..291b3f2 100644 --- a/lib/core/tools/Write-IcingaConsoleHeader.psm1 +++ b/lib/core/tools/Write-IcingaConsoleHeader.psm1 @@ -8,6 +8,7 @@ function Write-IcingaConsoleHeader() [int]$MaxHeaderLength = 0; [int]$TableHeaderCount = 0; [array]$TableHeader = @(); + [array]$SeverityData = @(); Import-LocalizedData ` -BaseDirectory (Get-IcingaFrameworkRootPath) ` @@ -24,6 +25,10 @@ function Write-IcingaConsoleHeader() } foreach ($line in $ParsedHeaders) { + if ($line.Contains('[Notice]') -Or $line.Contains('[Warning]') -Or $line.Contains('Error')) { + continue + } + if ($MaxHeaderLength -lt $line.Length) { $MaxHeaderLength = $line.Length } @@ -61,8 +66,34 @@ function Write-IcingaConsoleHeader() } } } - Write-IcingaConsolePlain -Message '**{1} {0} {2}**' -Objects $line, ([string]::Join('', $LeftSpacing)), ([string]::Join('', $RightSpacing)); + + if ($line.Contains('[Notice]') -Or $line.Contains('[Warning]') -Or $line.Contains('Error')) { + $SeverityData += $line; + continue; + } + + $HeaderMessage = [string]::Format('**{1} {0} {2}**', $line, ([string]::Join('', $LeftSpacing)), ([string]::Join('', $RightSpacing))); + + Write-IcingaConsolePlain -Message $HeaderMessage; } Write-IcingaConsolePlain ([string]::Join('', $TableHeader)); + + if ($SeverityData.Count -ne 0) { + Write-IcingaConsolePlain -Message ''; + + foreach ($entry in $SeverityData) { + if (Write-IcingaConsoleTextColorSplit -Pattern '[Warning]' -Message $entry -ForeColor 'DarkYellow') { + continue; + } + + if (Write-IcingaConsoleTextColorSplit -Pattern '[Error]' -Message $entry -ForeColor 'Red') { + continue; + } + + if (Write-IcingaConsoleTextColorSplit -Pattern '[Notice]' -Message $entry -ForeColor 'Green') { + continue; + } + } + } } diff --git a/lib/core/tools/Write-IcingaConsoleTextColorSplit.psm1 b/lib/core/tools/Write-IcingaConsoleTextColorSplit.psm1 new file mode 100644 index 0000000..9f65860 --- /dev/null +++ b/lib/core/tools/Write-IcingaConsoleTextColorSplit.psm1 @@ -0,0 +1,23 @@ +function Write-IcingaConsoleTextColorSplit() +{ + param ( + [string]$Pattern = '', + [string]$Message = '', + [ValidateSet('Default', 'Black', 'DarkBlue', 'DarkGreen', 'DarkCyan', 'DarkRed', 'DarkMagenta', 'DarkYellow', 'Gray', 'DarkGray', 'Blue', 'Green', 'Cyan', 'Red', 'Magenta', 'Yellow', 'White')] + [string]$ForeColor = 'Default' + ); + + if ($Message.Contains($Pattern)) { + [int]$RemoveLength = $Pattern.Length; + [string]$SeverityMsg = $Pattern; + Write-IcingaConsolePlain -Message ($Message.Substring(0, $Message.IndexOf($Pattern))) -NoNewLine; + + Write-IcingaConsolePlain -Message $SeverityMsg -ForeColor $ForeColor -NoNewLine; + + Write-IcingaConsolePlain -Message ($Message.Substring($Message.IndexOf($Pattern) + $RemoveLength, $Message.Length - $Message.IndexOf($Pattern) - $RemoveLength)); + + return $TRUE; + } + + return $FALSE; +}