diff --git a/PSOPNSenseAPI/PSOPNSenseAPI.psd1 b/PSOPNSenseAPI/PSOPNSenseAPI.psd1 deleted file mode 100644 index 4e30d97..0000000 --- a/PSOPNSenseAPI/PSOPNSenseAPI.psd1 +++ /dev/null @@ -1,208 +0,0 @@ -@{ - # Script module or binary module file associated with this manifest. - RootModule = 'PSOPNSenseAPI.psm1' - - # Version number of this module. - ModuleVersion = '2025.04.14.1839' - - # Supported PSEditions - CompatiblePSEditions = @('Desktop', 'Core') - - # ID used to uniquely identify this module - GUID = '8f7a3d7a-0e5a-4b7c-9b5a-9c5b3a5a8e7a' - - # Author of this module - Author = 'PSOPNSenseAPI Contributors' - - # Company or vendor of this module - CompanyName = 'PSOPNSenseAPI' - - # Copyright statement for this module - Copyright = '(c) 2025 PSOPNSenseAPI Contributors. All rights reserved.' - - # Description of the functionality provided by this module - Description = 'PowerShell module for interacting with the OPNSense API to configure firewalls' - - # Minimum version of the PowerShell engine required by this module - PowerShellVersion = '5.1' - - # Name of the PowerShell host required by this module - # PowerShellHostName = '' - - # Minimum version of the PowerShell host required by this module - # PowerShellHostVersion = '' - - # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. - DotNetFrameworkVersion = '4.7.2' - - # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. - # ClrVersion = '' - - # Processor architecture (None, X86, Amd64) required by this module - # ProcessorArchitecture = '' - - # Modules that must be imported into the global environment prior to importing this module - # RequiredModules = @() - - # Assemblies that must be loaded prior to importing this module - RequiredAssemblies = @('bin\PSOPNSenseAPI.dll') - - # Script files (.ps1) that are run in the caller's environment prior to importing this module. - # ScriptsToProcess = @() - - # Type files (.ps1xml) to be loaded when importing this module - # TypesToProcess = @() - - # Format files (.ps1xml) to be loaded when importing this module - # FormatsToProcess = @() - - # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess - NestedModules = @('bin\PSOPNSenseAPI.dll') - - # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = @() - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = @( - # Connection Management - 'Connect-OPNSense', - 'Disconnect-OPNSense', - 'Get-OPNSenseConnection', - - # Firewall Rule Management - 'Get-OPNSenseFirewallRule', - 'New-OPNSenseFirewallRule', - 'Set-OPNSenseFirewallRule', - 'Remove-OPNSenseFirewallRule', - 'Enable-OPNSenseFirewallRule', - 'Disable-OPNSenseFirewallRule', - 'Apply-OPNSenseFirewallChanges', - - # Alias Management - 'Get-OPNSenseAlias', - 'New-OPNSenseAlias', - 'Set-OPNSenseAlias', - 'Remove-OPNSenseAlias', - - # NAT Rule Management - 'Get-OPNSenseNATRule', - 'New-OPNSenseNATRule', - 'Set-OPNSenseNATRule', - 'Remove-OPNSenseNATRule', - - # Interface Management - 'Get-OPNSenseInterface', - 'Set-OPNSenseInterface', - 'Restart-OPNSenseInterface', - 'Get-OPNSenseInterfaceStatistics', - 'New-OPNSenseSubnetVLANs', - - # VLAN Management - 'Get-OPNSenseVLAN', - 'New-OPNSenseVLAN', - 'Set-OPNSenseVLAN', - 'Remove-OPNSenseVLAN', - - # DNS Configuration - 'Get-OPNSenseDNSServer', - 'Set-OPNSenseDNSServer', - 'Get-OPNSenseDNSDomain', - 'Set-OPNSenseDNSDomain', - 'Get-OPNSenseDNSOverride', - 'New-OPNSenseDNSOverride', - 'Remove-OPNSenseDNSOverride', - - # Configuration Management - 'Backup-OPNSenseConfig', - 'Restore-OPNSenseConfig', - 'Export-OPNSenseConfig', - 'Import-OPNSenseConfig', - 'Get-OPNSenseConfigBackup', - - # Plugin Management - 'Get-OPNSensePlugin', - 'Install-OPNSensePlugin', - 'Uninstall-OPNSensePlugin', - 'Enable-OPNSensePlugin', - 'Disable-OPNSensePlugin', - - # User Management - 'Get-OPNSenseUser', - 'New-OPNSenseUser', - 'Set-OPNSenseUser', - 'Remove-OPNSenseUser', - - # Firmware Management - 'Get-OPNSenseFirmware', - 'Update-OPNSenseFirmware', - 'Upgrade-OPNSenseFirmware', - - # System Management - 'Restart-OPNSenseFirewall' - ) - - # Variables to export from this module - VariablesToExport = '*' - - # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = @() - - # DSC resources to export from this module - # DscResourcesToExport = @() - - # List of all modules packaged with this module - # ModuleList = @() - - # List of all files packaged with this module - # FileList = @() - - # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. - PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - Tags = @('OPNSense', 'Firewall', 'API', 'Network', 'Security') - - # A URL to the license for this module. - LicenseUri = 'https://github.com/freedbygrace/PSOPNSenseAPI/blob/main/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/freedbygrace/PSOPNSenseAPI' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - ReleaseNotes = 'Initial release of the PSOPNSenseAPI module' - - # Prerelease string of this module - # Prerelease = '' - - # Flag to indicate whether the module requires explicit user acceptance for install/update/save - # RequireLicenseAcceptance = $false - - # External dependent modules of this module - # ExternalModuleDependencies = @() - - } # End of PSData hashtable - - } # End of PrivateData hashtable - - # HelpInfoURI = '' - - # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. - # DefaultCommandPrefix = '' -} - - - - - - - - - - - - diff --git a/PSOPNSenseAPI/PSOPNSenseAPI.psm1 b/PSOPNSenseAPI/PSOPNSenseAPI.psm1 deleted file mode 100644 index feac251..0000000 --- a/PSOPNSenseAPI/PSOPNSenseAPI.psm1 +++ /dev/null @@ -1,3 +0,0 @@ -# This file is intentionally left empty. -# The module functionality is provided by the binary module (DLL). -# This file exists to allow for future PowerShell script functions if needed. diff --git a/output/PSOPNSenseAPI/PSOPNSenseAPI.psd1 b/output/PSOPNSenseAPI/PSOPNSenseAPI.psd1 index 0b577d5..c399f50 100644 --- a/output/PSOPNSenseAPI/PSOPNSenseAPI.psd1 +++ b/output/PSOPNSenseAPI/PSOPNSenseAPI.psd1 @@ -8,7 +8,7 @@ Description = 'PowerShell module for interacting with the OPNSense API to configure firewalls' PowerShellVersion = '5.1' CompatiblePSEditions = @('Desktop', 'Core') - DotNetFrameworkVersion = '4.7.2' + #DotNetFrameworkVersion = '4.7.2' CLRVersion = '4.0.0' FunctionsToExport = @() CmdletsToExport = @( diff --git a/output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 b/output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 index adb5478..05f4dcf 100644 --- a/output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 +++ b/output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 @@ -1,25 +1,36 @@ # Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes # This avoids file lock issues when the module is loaded -$libPath = Join-Path $PSScriptRoot "lib" -$dllFiles = Get-ChildItem -Path $libPath -Filter "*.dll" +$libPath = Join-Path $PSScriptRoot -ChildPath "lib" -foreach ($dll in $dllFiles) { - try { - $dllBytes = [System.IO.File]::ReadAllBytes($dll.FullName) - $Null = [System.Reflection.Assembly]::Load($dllBytes) - Write-Verbose "Attempting to load assembly: $($dll.FullName)" - } - catch { - Write-Warning "Failed to load assembly $($dll.Name): $_" - } +$DLLFileList = Get-ChildItem -Path $libPath -Filter "*.dll" + +$DLLFileListCount = ($DLLFileList | Measure-Object).Count + +$DLLFileListCounter = 1 + +For ($DLLFileListIndex = 0; $DLLFileListIndex -lt $DLLFileListCount; $DLLFileListIndex++) + { + Try + { + $DLLFile = $DLLFileList[$DLLFileListIndex] + + Write-Verbose "Attempting to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount). Please Wait..." + + Write-Verbose "Path: $($DLLFile)" + + $DLLFileBytes = [System.IO.File]::ReadAllBytes($DLLFile.FullName) + + $Null = [System.Reflection.Assembly]::Load($DLLFileBytes) + + Write-Verbose "Successfully loaded DLL assembly $($DLLFileListCounter) of $($DLLFileListCount)" + } + Catch + { + Write-Warning "Failed to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount): $($_.Exception.Message)" + } + Finally + { + $DLLFileListCounter++ + } } - -# Export all cmdlets -$cmdlets = [System.AppDomain]::CurrentDomain.GetAssemblies() | - Where-Object { $_.FullName -like "*PSOPNSenseAPI*" } | - ForEach-Object { $_.GetTypes() } | - Where-Object { $_.IsPublic -and $_.IsClass -and $_.Name -like "*Cmdlet" } | - ForEach-Object { $_.Name } - -Export-ModuleMember -Cmdlet $cmdlets diff --git a/output/PSOPNSenseAPI/lib-new/Newtonsoft.Json.dll b/output/PSOPNSenseAPI/lib-new/Newtonsoft.Json.dll new file mode 100644 index 0000000..341d08f Binary files /dev/null and b/output/PSOPNSenseAPI/lib-new/Newtonsoft.Json.dll differ diff --git a/output/PSOPNSenseAPI/lib-new/PSOPNSenseAPI.dll b/output/PSOPNSenseAPI/lib-new/PSOPNSenseAPI.dll new file mode 100644 index 0000000..4d100e1 Binary files /dev/null and b/output/PSOPNSenseAPI/lib-new/PSOPNSenseAPI.dll differ diff --git a/output/PSOPNSenseAPI/lib/System.Buffers.dll b/output/PSOPNSenseAPI/lib-new/System.Buffers.dll similarity index 100% rename from output/PSOPNSenseAPI/lib/System.Buffers.dll rename to output/PSOPNSenseAPI/lib-new/System.Buffers.dll diff --git a/output/PSOPNSenseAPI/lib/System.Management.Automation.dll b/output/PSOPNSenseAPI/lib-new/System.Management.Automation.dll similarity index 100% rename from output/PSOPNSenseAPI/lib/System.Management.Automation.dll rename to output/PSOPNSenseAPI/lib-new/System.Management.Automation.dll diff --git a/output/PSOPNSenseAPI/lib/System.Memory.dll b/output/PSOPNSenseAPI/lib-new/System.Memory.dll similarity index 100% rename from output/PSOPNSenseAPI/lib/System.Memory.dll rename to output/PSOPNSenseAPI/lib-new/System.Memory.dll diff --git a/output/PSOPNSenseAPI/lib/System.Net.IPNetwork.dll b/output/PSOPNSenseAPI/lib-new/System.Net.IPNetwork.dll similarity index 100% rename from output/PSOPNSenseAPI/lib/System.Net.IPNetwork.dll rename to output/PSOPNSenseAPI/lib-new/System.Net.IPNetwork.dll diff --git a/output/PSOPNSenseAPI/lib/System.Numerics.Vectors.dll b/output/PSOPNSenseAPI/lib-new/System.Numerics.Vectors.dll similarity index 100% rename from output/PSOPNSenseAPI/lib/System.Numerics.Vectors.dll rename to output/PSOPNSenseAPI/lib-new/System.Numerics.Vectors.dll diff --git a/output/PSOPNSenseAPI/lib/System.Runtime.CompilerServices.Unsafe.dll b/output/PSOPNSenseAPI/lib-new/System.Runtime.CompilerServices.Unsafe.dll similarity index 100% rename from output/PSOPNSenseAPI/lib/System.Runtime.CompilerServices.Unsafe.dll rename to output/PSOPNSenseAPI/lib-new/System.Runtime.CompilerServices.Unsafe.dll diff --git a/scripts/Create-Release.ps1 b/scripts/Create-Release.ps1 index 8f1271f..95024a5 100644 --- a/scripts/Create-Release.ps1 +++ b/scripts/Create-Release.ps1 @@ -31,13 +31,38 @@ Copy-Item -Path "src\PSOPNSenseAPI\bin\Release\net472\*.dll" -Destination $libPa Remove-Item -Path "output\PSOPNSenseAPI\lib" -Recurse -Force -ErrorAction SilentlyContinue Rename-Item -Path $libPath -NewName "lib" +# Create the PSM1 file +$psm1Path = "output\PSOPNSenseAPI\PSOPNSenseAPI.psm1" +$psm1Content = @" +# Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes +# This avoids file lock issues when the module is loaded + +`$libPath = Join-Path `$PSScriptRoot "lib" +`$dllFiles = Get-ChildItem -Path `$libPath -Filter "*.dll" + +foreach (`$dll in `$dllFiles) { + try { + Write-Verbose "Attempting to load assembly: `$(`$dll.FullName)" + `$dllBytes = [System.IO.File]::ReadAllBytes(`$dll.FullName) + `$Null = [System.Reflection.Assembly]::Load(`$dllBytes) + Write-Verbose "Successfully loaded assembly: `$(`$dll.FullName)" + } + catch { + Write-Warning "Failed to load assembly `$(`$dll.Name): `$_" + } +} + +# Export all cmdlets from the PSD1 file +"@ +Set-Content -Path $psm1Path -Value $psm1Content + # Create a release archive $zipFile = "output\PSOPNSenseAPI-$version.zip" Compress-Archive -Path "output\PSOPNSenseAPI\*" -DestinationPath $zipFile -Force # Clean up old zip files -Get-ChildItem -Path "output" -Filter "*.zip" | - Where-Object { $_.Name -ne "PSOPNSenseAPI-$version.zip" } | +Get-ChildItem -Path "output" -Filter "*.zip" | + Where-Object { $_.Name -ne "PSOPNSenseAPI-$version.zip" } | Remove-Item -Force # Commit the changes diff --git a/src/PSOPNSenseAPI/PSOPNSenseAPI.psm1 b/src/PSOPNSenseAPI/PSOPNSenseAPI.psm1 new file mode 100644 index 0000000..05f4dcf --- /dev/null +++ b/src/PSOPNSenseAPI/PSOPNSenseAPI.psm1 @@ -0,0 +1,36 @@ +# Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes +# This avoids file lock issues when the module is loaded + +$libPath = Join-Path $PSScriptRoot -ChildPath "lib" + +$DLLFileList = Get-ChildItem -Path $libPath -Filter "*.dll" + +$DLLFileListCount = ($DLLFileList | Measure-Object).Count + +$DLLFileListCounter = 1 + +For ($DLLFileListIndex = 0; $DLLFileListIndex -lt $DLLFileListCount; $DLLFileListIndex++) + { + Try + { + $DLLFile = $DLLFileList[$DLLFileListIndex] + + Write-Verbose "Attempting to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount). Please Wait..." + + Write-Verbose "Path: $($DLLFile)" + + $DLLFileBytes = [System.IO.File]::ReadAllBytes($DLLFile.FullName) + + $Null = [System.Reflection.Assembly]::Load($DLLFileBytes) + + Write-Verbose "Successfully loaded DLL assembly $($DLLFileListCounter) of $($DLLFileListCount)" + } + Catch + { + Write-Warning "Failed to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount): $($_.Exception.Message)" + } + Finally + { + $DLLFileListCounter++ + } +}