From 9a30e78a82e6c6f1768406f5e8a03e2a9f706a92 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Thu, 28 Jan 2021 15:02:16 +0100 Subject: [PATCH] Added add-firewall-rules.ps1 --- Data/scripts.csv | 1 + README.md | 1 + Scripts/add-firewall-rules.ps1 | 77 ++++++++++++++++++++++++++++++++++ Scripts/set-wallpaper.ps1 | 0 4 files changed, 79 insertions(+) create mode 100755 Scripts/add-firewall-rules.ps1 mode change 100644 => 100755 Scripts/set-wallpaper.ps1 diff --git a/Data/scripts.csv b/Data/scripts.csv index 86977c31..7dbc93a9 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -1,4 +1,5 @@ Filename,Description +add-firewall-rules.ps1, adds firewall rules to the given executables, requires admin rights check-ipv4-address.ps1, checks the given IPv4 address for validity check-mac-address.ps1, checks the given MAC address for validity check-xml-file.ps1, checks the given XML file for validity diff --git a/README.md b/README.md index 91bf9753..c7198523 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ List of Scripts --------------- The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfolder: +* [add-firewall-rules.ps1](Scripts/add-firewall-rules.ps1) - adds firewall rules for the given executables * [check-ipv4-address.ps1](Scripts/check-ipv4-address.ps1) - checks the given IPv4 address for validity * [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity * [check-xml-file.ps1](Scripts/check-xml-file.ps1) - checks the given XML file for validity diff --git a/Scripts/add-firewall-rules.ps1 b/Scripts/add-firewall-rules.ps1 new file mode 100755 index 00000000..2adb284c --- /dev/null +++ b/Scripts/add-firewall-rules.ps1 @@ -0,0 +1,77 @@ +#!/snap/bin/powershell +<# +.SYNTAX ./add-firewall-rules.ps1 [] +.DESCRIPTION adds firewall rules for the given executables, administrator rights are required +.LINK https://github.com/fleschutz/PowerShell +.NOTES Author: Markus Fleschutz / License: CC0 +#> + +#Requires -RunAsAdministrator + +param([string]$PathToExecutables) + +$command = ' +$output = ''Firewall rules for path '' + $args[0] +write-output $output +for($i = 1; $i -lt $args.count; $i++){ + $path = $args[0] + $path += ''\'' + $path += $args[$i] + + $null = $args[$i] -match ''[^\\]*\.exe$'' + $name = $matches[0] + $output = ''Adding firewall rule for '' + $name + write-output $output + $null = New-NetFirewallRule -DisplayName $name -Direction Inbound -Program $path -Profile Domain, Private -Action Allow +} +Write-Host -NoNewLine ''Done - press any key to continue...''; +$null = $Host.UI.RawUI.ReadKey(''NoEcho,IncludeKeyDown''); +' +#get current path +$path = get-location +$path = Convert-Path -Path $path +if(test-path "$path\executables"){ + #get all executables + $Apps = @() + $Apps += Get-ChildItem "$path\executables\*.exe" -Name + + for($i = 0; $i -lt $Apps.length; $i++){ + $Apps[$i] = "executables\" + $Apps[$i] + } + #Add 64bit Apps (if applicable) + $Apps64 = @() + if(test-path "$path\executables64"){ + #only try if 64bit executables are present + $Apps64 += Get-ChildItem "$path\executables64\*.exe" -Name + for($i = 0; $i -lt $Apps64.length; $i++){ + $Apps64[$i] = "executables64\" + $Apps64[$i] + } + $Apps += $Apps64 + } + #Add all Java runtimes delivered + $subdirs = get-childitem $path\jre + foreach($item in $subdirs){ + if($item.PSIsContainer){ + $itempath = $item.BaseName + $itempath += "\bin\javaw.exe" + $itempath = "jre\$itempath" + if(test-path("$path\$itempath")){ + $Apps += $itempath + } + } + } + + if($Apps.count -eq 0){ + Write-Warning "No executables found. No Firewall rules have been created." + Write-Host -NoNewhLine 'Press any key to continue...'; + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); + }else{ + $arg = "$path $Apps" + Start-Process powershell -Verb runAs -ArgumentList "-command & {$command} $arg" + } +}else{ + write-warning "Cannot find executables path. The script must be executed in ATTower root directory" + Write-Host -NoNewLine 'Press any key to continue...'; + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); +} +exit 0 diff --git a/Scripts/set-wallpaper.ps1 b/Scripts/set-wallpaper.ps1 old mode 100644 new mode 100755