Skip to content

Commit

Permalink
Fix CodeQL Alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelinux committed Jan 25, 2024
1 parent 26c3e28 commit 82e75b9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 21 deletions.
7 changes: 6 additions & 1 deletion Src/Private/Get-VbrServerConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ function Get-VbrServerConnection {
#>
[CmdletBinding()]
param (

[Parameter(
Position = 0,
Mandatory = $true,
HelpMessage = 'TCP Port of target Veeam Backup Server'
)]
[string]$Port
)

begin {
Expand Down
63 changes: 48 additions & 15 deletions Src/Private/Out-VbrDiagram.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,39 @@ function Out-VbrDiagram {
[OutputType([String])]
Param
(

[Parameter(
Position = 0,
Mandatory = $true,
HelpMessage = 'Please provide the graphviz dot object'
)]
$GraphObj,
[Parameter(
Position = 1,
Mandatory = $false,
HelpMessage = 'Allow to enable error debugging'
)]
[bool]$ErrorDebug,
[Parameter(
Position = 2,
Mandatory = $false,
HelpMessage = 'Allow to rotate the diagram output image. valid rotation degree (90, 180)'
)]
[int]$Rotate
)
process {
if ($EnableErrorDebug) {
$Graph
if ($ErrorDebug) {
$GraphObj
} else {
# If Filename parameter is not specified, set filename to the Output.$OutputFormat
foreach ($OutputFormat in $Format) {
if ($Filename) {
Try {
if ($OutputFormat -ne "base64") {
if($OutputFormat -ne "svg") {
$Document = Export-PSGraph -Source $Graph -DestinationPath "$($OutputFolderPath)$($FileName)" -OutputFormat $OutputFormat -GraphVizPath $GraphvizPath
$Document = Export-PSGraph -Source $GraphObj -DestinationPath "$($OutputFolderPath)$($FileName)" -OutputFormat $OutputFormat -GraphVizPath $GraphvizPath
Write-ColorOutput -Color green "Diagram '$FileName' has been saved to '$OutputFolderPath'."
} else {
$Document = Export-PSGraph -Source $Graph -DestinationPath "$($OutputFolderPath)$($FileName)" -OutputFormat $OutputFormat -GraphVizPath $GraphvizPath
$Document = Export-PSGraph -Source $GraphObj -DestinationPath "$($OutputFolderPath)$($FileName)" -OutputFormat $OutputFormat -GraphVizPath $GraphvizPath
#Fix icon path issue with svg output
$images = Select-String -Path $($Document.fullname) -Pattern '<image xlink:href=".*png".*>' -AllMatches
foreach($match in $images) {
Expand All @@ -51,13 +68,13 @@ function Out-VbrDiagram {

}
} else {
$Document = Export-PSGraph -Source $Graph -DestinationPath "$($OutputFolderPath)$($FileName)" -OutputFormat 'png' -GraphVizPath $GraphvizPath
$Document = Export-PSGraph -Source $GraphObj -DestinationPath "$($OutputFolderPath)$($FileName)" -OutputFormat 'png' -GraphVizPath $GraphvizPath
if ($Document) {
# Code used to allow rotating image!
if ($Rotate) {
Add-Type -AssemblyName System.Windows.Forms
$RotatedIMG = new-object System.Drawing.Bitmap $Document.FullName
$RotatedIMG.RotateFlip("Rotate90FlipNone")
$RotatedIMG.RotateFlip("Rotate$($Rotate)FlipNone")
$RotatedIMG.Save($Document.FullName,"png")
if ($RotatedIMG) {
$Base64 = [convert]::ToBase64String((get-content $Document -encoding byte))
Expand Down Expand Up @@ -89,10 +106,10 @@ function Out-VbrDiagram {
Try {
if ($OutputFormat -ne "base64") {
if($OutputFormat -ne "svg") {
$Document = Export-PSGraph -Source $Graph -DestinationPath "$($OutputFolderPath)$($File)" -OutputFormat $OutputFormat -GraphVizPath $GraphvizPath
$Document = Export-PSGraph -Source $GraphObj -DestinationPath "$($OutputFolderPath)$($File)" -OutputFormat $OutputFormat -GraphVizPath $GraphvizPath
Write-ColorOutput -Color green "Diagram '$File' has been saved to '$OutputFolderPath'."
} else {
$Document = Export-PSGraph -Source $Graph -DestinationPath "$($OutputFolderPath)$($File)" -OutputFormat $OutputFormat -GraphVizPath $GraphvizPath
$Document = Export-PSGraph -Source $GraphObj -DestinationPath "$($OutputFolderPath)$($File)" -OutputFormat $OutputFormat -GraphVizPath $GraphvizPath
$images = Select-String -Path $($Document.fullname) -Pattern '<image xlink:href=".*png".*>' -AllMatches
foreach($match in $images) {
$matchFound = $match -Match '"(.*png)"'
Expand All @@ -110,13 +127,29 @@ function Out-VbrDiagram {
}
}
} else {
$Document = Export-PSGraph -Source $Graph -DestinationPath "$($OutputFolderPath)$($File)" -OutputFormat 'png' -GraphVizPath $GraphvizPath
$Document = Export-PSGraph -Source $GraphObj -DestinationPath "$($OutputFolderPath)$($File)" -OutputFormat 'png' -GraphVizPath $GraphvizPath
if ($Document) {
$Base64 = [convert]::ToBase64String((get-content $Document -encoding byte))
if ($Base64) {
Remove-Item -Path $Document.FullName
$Base64
} else {Remove-Item -Path $Document.FullName}
# Code used to allow rotating image!
if ($Rotate) {
Add-Type -AssemblyName System.Windows.Forms
$RotatedIMG = new-object System.Drawing.Bitmap $Document.FullName
$RotatedIMG.RotateFlip("Rotate$($Rotate)FlipNone")
$RotatedIMG.Save($Document.FullName,"png")
if ($RotatedIMG) {
$Base64 = [convert]::ToBase64String((get-content $Document -encoding byte))
if ($Base64) {
Remove-Item -Path $Document.FullName
$Base64
} else {Remove-Item -Path $Document.FullName}
}
} else {
# Code used to output image to base64 format
$Base64 = [convert]::ToBase64String((get-content $Document -encoding byte))
if ($Base64) {
Remove-Item -Path $Document.FullName
$Base64
} else {Remove-Item -Path $Document.FullName}
}
}
}
} catch {
Expand Down
10 changes: 5 additions & 5 deletions Src/Public/New-VeeamDiagram.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ function New-VeeamDiagram {

if ($EnableEdgeDebug) {
$EdgeDebug = @{style='filled'; color='red'}
$URLIcon = $true
$script:URLIcon = $true
} else {$EdgeDebug = @{style='invis'; color='red'}}

if ($EnableSubGraphDebug) {
$SubGraphDebug = @{style='dashed'; color='red'}
$URLIcon = $true
$script:URLIcon = $true
} else {$SubGraphDebug = @{style='invis'; color='gray'}}

$RootPath = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
Expand Down Expand Up @@ -348,13 +348,13 @@ function New-VeeamDiagram {

try {

$VBRServer = Get-VBRServer -Type Local
$script:VBRServer = Get-VBRServer -Type Local

} Catch {throw "Unable to get Veeam B&R Server"}

Get-VbrBackupServerInfo

$Graph = Graph -Name VeeamVBR -Attributes $MainGraphAttributes {
$script:Graph = Graph -Name VeeamVBR -Attributes $MainGraphAttributes {
# Node default theme
node @{
label = ''
Expand Down Expand Up @@ -546,6 +546,6 @@ function New-VeeamDiagram {
}
end {
#Export Diagram
Out-VbrDiagram
Out-ADDiagram -GraphObj $Graph -ErrorDebug $EnableErrorDebug -Rotate $Rotate
}
}

0 comments on commit 82e75b9

Please sign in to comment.