Compare commits
19 Commits
ec9b44d8d5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| cccd7ca3d6 | |||
| 140edc1cb1 | |||
| 56a910d714 | |||
| fc3a39b0b9 | |||
| 47c313a26a | |||
| 5332818990 | |||
| 0119923ed7 | |||
| 4a8fff4384 | |||
| 0ce3ebdb35 | |||
| 130e346319 | |||
| 5003661a63 | |||
| 043bca95a2 | |||
| 6bd82a2a91 | |||
| 2a21a23462 | |||
| e5bc1f76df | |||
| cda29f2ef1 | |||
| 56bc398bf0 | |||
| 939ff159f5 | |||
| f0ddf5ab5a |
+100
@@ -0,0 +1,100 @@
|
||||
# Common settings that generally should always be used with your language specific settings
|
||||
|
||||
# Auto detect text files and perform LF normalization
|
||||
# https://www.davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
|
||||
* text=auto
|
||||
|
||||
#
|
||||
# The above will handle all files NOT found below
|
||||
#
|
||||
|
||||
# Documents
|
||||
*.bibtex text diff=bibtex
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
||||
*.md text diff=markdown
|
||||
*.tex text diff=tex
|
||||
*.adoc text
|
||||
*.textile text
|
||||
*.mustache text
|
||||
*.csv text
|
||||
*.tab text
|
||||
*.tsv text
|
||||
*.txt text
|
||||
*.sql text
|
||||
*.ps1 text eol=crlf
|
||||
|
||||
# Graphics
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.jpeg binary
|
||||
*.gif binary
|
||||
*.tif binary
|
||||
*.tiff binary
|
||||
*.ico binary
|
||||
# SVG treated as an asset (binary) by default.
|
||||
*.svg text
|
||||
# If you want to treat it as binary,
|
||||
# use the following line instead.
|
||||
# *.svg binary
|
||||
*.eps binary
|
||||
|
||||
# Scripts
|
||||
*.bash text eol=lf
|
||||
*.fish text eol=lf
|
||||
*.sh text eol=lf
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
*.cmd text eol=crlf
|
||||
|
||||
# web frontend stack -- force LF so SRI hashes are always correct
|
||||
*.html text eol=lf
|
||||
*.htm text eol=lf
|
||||
*.css text eol=lf
|
||||
*.min.css text eol=lf
|
||||
*.js text eol=lf
|
||||
*.min.js text eol=lf
|
||||
*.php text eol=lf
|
||||
|
||||
# Visual Studio projects (Rider also)
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Serialisation
|
||||
*.json text
|
||||
*.toml text
|
||||
*.xml text
|
||||
*.yaml text
|
||||
*.yml text
|
||||
|
||||
# Archives
|
||||
*.7z binary
|
||||
*.gz binary
|
||||
*.tar binary
|
||||
*.tgz binary
|
||||
*.zip binary
|
||||
|
||||
# Text files where line endings should be preserved
|
||||
*.patch -text
|
||||
|
||||
#
|
||||
# Exclude files from exporting
|
||||
#
|
||||
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.gitkeep export-ignore
|
||||
.idea export-ignore
|
||||
.vscode export-ignore
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# ignore text XML WOL database files
|
||||
*.test.xml
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/contentModel.xml
|
||||
/.idea.ps-vpn-wol.iml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="asif" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CommitMessageInspectionProfile">
|
||||
<profile version="1.0">
|
||||
<inspection_tool class="BodyLimit" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
<inspection_tool class="SubjectBodySeparation" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
<inspection_tool class="SubjectLimit" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<WOLDatabase>
|
||||
<Configuration>
|
||||
<BroadcastAddress>127.0.0.1</BroadcastAddress>
|
||||
<Port>7</Port>
|
||||
<DnsSuffix>.internal.mydomain.tld</DnsSuffix>
|
||||
</Configuration>
|
||||
<Computers>
|
||||
<Computer name="reception01" friendlyName="Front-desk computer" mac="aa:00:00:00:00:01"/>
|
||||
<Computer name="accounting01" friendlyName="accounting workstation 1" mac="bb:00:00:00:00:01"/>
|
||||
<Computer name="accounting02" friendlyName="" mac="bb:00:00:00:00:02"/>
|
||||
<Computer name="manager01" friendlyName="management workstation 1" mac="cc:00:00:00:00:01"/>
|
||||
<Computer name="tech" friendlyName="I.T. technician workstation" mac="ff:ff:ff:ff:ff:01"/>
|
||||
</Computers>
|
||||
</WOLDatabase>
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
<#
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
# Array of strings listing computer name(s) to wake up. Names will be matched using RegEx
|
||||
[Alias("Computer")]
|
||||
[String[]]
|
||||
$TargetComputer = "",
|
||||
# XML database file containing computer details (Default: WOLDatabase.xml)
|
||||
[Alias("List", "Database")]
|
||||
[String]
|
||||
$WolDatabase = "WOLDatabase.xml",
|
||||
# Skip connectivity check
|
||||
[Alias("NoCheck", "NoReadiness")]
|
||||
[Switch]
|
||||
$NoConnectivityCheck,
|
||||
# Delay before running first connectivity check (Default: 10)
|
||||
[Alias("Delay")]
|
||||
[Int]
|
||||
$ConnectivityCheckDelay = 10,
|
||||
# Seconds before aborting connectivity check (Default: 300)
|
||||
[Alias("Timeout")]
|
||||
[Int]
|
||||
$ConnectivityCheckTimeout = 300,
|
||||
# Seconds between connectivity checks (Default: 30)
|
||||
[Alias("Interval")]
|
||||
[Int]
|
||||
$ConnectivityCheckInterval = 30,
|
||||
# Port to use for connectivity check (Default: 3389-RDP)
|
||||
[Alias("CheckPort")]
|
||||
[Int]
|
||||
$ConnectivityCheckPort = 3389
|
||||
)
|
||||
|
||||
function exitError($errMessage, $PSItem, $exitCode = 1)
|
||||
{
|
||||
if ( [String]::IsNullOrEmpty($errMessage))
|
||||
{
|
||||
Write-Host -ForegroundColor Red "`n`rABNORMAL EXIT: exitError function called without exit message!`n`r"
|
||||
exit 99
|
||||
}
|
||||
Write-Host -ForegroundColor Red "`r`nERROR: ${errMessage}."
|
||||
if ($PSItem)
|
||||
{
|
||||
Write-Host -ForegroundColor Red "`r`nAdditional information:`r`n$PSItem"
|
||||
}
|
||||
Write-Host
|
||||
Exit $exitCode
|
||||
}
|
||||
|
||||
function exitGracefully()
|
||||
{
|
||||
Write-Host -ForegroundColor Green "`r`nFinished.`r`n"
|
||||
Exit 0
|
||||
}
|
||||
|
||||
# constants
|
||||
Set-Variable -Name wolModuleName -Value "wol-magicPacket" -Option Constant
|
||||
|
||||
# exit on error if Send-MagicPacket module is not loaded
|
||||
if (!(Get-Module -Name $wolModuleName))
|
||||
{
|
||||
try
|
||||
{
|
||||
Import-Module -Name $wolModuleName -ErrorAction Stop
|
||||
}
|
||||
catch
|
||||
{
|
||||
$errMessage = "Unable to load '$wolModuleName'"
|
||||
exitError $errMessage $PSItem
|
||||
}
|
||||
}
|
||||
|
||||
# exit if database cannot be found/read
|
||||
if (!(Test-Path -Path $WolDatabase -PathType Leaf))
|
||||
{
|
||||
$errMessage = "Unable to find or read Wake-On-LAN database file ($WolDatabase)"
|
||||
exitError $errMessage
|
||||
}
|
||||
|
||||
# get target computer name if not already specified
|
||||
if ( [String]::IsNullOrWhiteSpace($TargetComputer))
|
||||
{
|
||||
do
|
||||
{
|
||||
$TargetComputer = Read-Host -Prompt 'Computer to wake-up'
|
||||
} while ( [String]::IsNullOrWhiteSpace($TargetComputer))
|
||||
}
|
||||
Write-Host
|
||||
|
||||
# read database and assemble list of target computers
|
||||
[xml]$wolDb = Get-Content -Path $WolDatabase
|
||||
$broadcastIP = $wolDb.WOLDatabase.Configuration.BroadcastAddress
|
||||
$port = $wolDb.WOLDatabase.Configuration.Port
|
||||
$dnsSuffix = $wolDb.WOLDatabase.Configuration.DnsSuffix
|
||||
$targetComputers = [System.Collections.Generic.List[PSObject]]::new()
|
||||
$TargetComputer | ForEach-Object {
|
||||
$tgt = $_
|
||||
$wolDb.WOLDatabase.Computers.Computer | Where-Object { $_.name -match $tgt } | ForEach-Object { $targetComputers.Add($_) }
|
||||
}
|
||||
$removeFromTargetComputers = [System.Collections.Generic.List[String]]::new()
|
||||
|
||||
# exit if nothing to do (i.e. empty targetComputers list)
|
||||
if ($targetComputers.Count -eq 0)
|
||||
{
|
||||
Write-Host -ForegroundColor Yellow "No computers found matching '$TargetComputer'. Nothing to do.`r`n"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# send WOL magic packets
|
||||
$targetComputers | ForEach-Object {
|
||||
$wolError = @()
|
||||
$name = $_.name
|
||||
$friendlyName = $_.friendlyName
|
||||
if ( [String]::IsNullOrWhiteSpace($friendlyName))
|
||||
{
|
||||
Write-Host "Processing request to wake-up '$name'... " -NoNewline
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Processing request to wake-up '$friendlyName'... " -NoNewline
|
||||
}
|
||||
|
||||
# send magic packet
|
||||
$_.mac | Send-MagicPacket -BroadcastIP $broadcastIP -Port $port -ErrorAction SilentlyContinue -ErrorVariable +wolError
|
||||
if ($wolError.Count -eq 0)
|
||||
{
|
||||
Write-Host -ForegroundColor Green "[OK]"
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host -ForegroundColor Red "[ERROR]"
|
||||
# queue for removal from computers on which to run a connectivity check
|
||||
$removeFromTargetComputers.Add($name)
|
||||
}
|
||||
}
|
||||
|
||||
# remove computers from targetComputers if WOL packet was not successfully sent
|
||||
$removeFromTargetComputers | ForEach-Object {
|
||||
$removeName = $_
|
||||
$targetComputers.Remove(($targetComputers | Where-Object { $_.name -eq $removeName })) | Out-Null
|
||||
}
|
||||
|
||||
# exit if connectivity check skipped or if no computers to test
|
||||
if ($NoConnectivityCheck)
|
||||
{
|
||||
Write-Host "`r`nSkipping connectivity checks."
|
||||
exitGracefully
|
||||
}
|
||||
elseif ($targetComputers.Count -eq 0)
|
||||
{
|
||||
exitError "No wake-up packets sent successfully" -exitCode 5
|
||||
}
|
||||
|
||||
# wait for initial delay seconds to let computer(s) wake up
|
||||
for ($i = $ConnectivityCheckDelay; $i -gt 0; $i--) {
|
||||
Write-Progress -Activity "Waiting for computer(s) to wake-up..." -SecondsRemaining $i
|
||||
Start-Sleep 1
|
||||
}
|
||||
Write-Progress -Activity "Waiting for computer(s) to wake-up..." -Completed
|
||||
|
||||
# iterate computers and test connectivity
|
||||
# TODO: run connectivity test as background job
|
||||
$connCheckTotalTime = 0
|
||||
$removeFromTargetComputers.Clear()
|
||||
do
|
||||
{
|
||||
$targetComputers | ForEach-Object {
|
||||
$name = $_.name
|
||||
$friendlyName = $_.friendlyName
|
||||
$fqdn = -join ($name, $dnsSuffix)
|
||||
$connectionError = @()
|
||||
|
||||
if ( [String]::IsNullOrWhiteSpace($friendlyName))
|
||||
{
|
||||
Write-Host "Testing connection readiness of '$name'... " -NoNewline
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Testing connection readiness of '$friendlyName'... " -NoNewline
|
||||
}
|
||||
if (!(Test-NetConnection -ComputerName $fqdn -Port $ConnectivityCheckPort -InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -ErrorVariable +connectionError))
|
||||
{
|
||||
if (($connCheckTotalTime + $ConnectivityCheckInterval) -gt $ConnectivityCheckTimeout)
|
||||
{
|
||||
# last iteration, display 'error'
|
||||
Write-Host -ForegroundColor Red "[ERROR]"
|
||||
$connectionError | ForEach-Object {
|
||||
$errMsg = $_.ToString()
|
||||
Write-Verbose "`t(Additional information: $errMsg)"
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# more iterations pending, display 'retrying'
|
||||
Write-Host -ForegroundColor Yellow "[RETRYING]"
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host -ForegroundColor Green "[OK]"
|
||||
# queue for removal from computers to check next round
|
||||
$removeFromTargetComputers.Add($name)
|
||||
}
|
||||
}
|
||||
|
||||
# remove computers from targetComputers if connectivity check already successful
|
||||
$removeFromTargetComputers | ForEach-Object {
|
||||
$removeName = $_
|
||||
$targetComputers.Remove(($targetComputers | Where-Object { $_.name -eq $removeName })) | Out-Null
|
||||
}
|
||||
|
||||
# sleep until next test interval and increase time counter
|
||||
$connCheckTotalTime += $ConnectivityCheckInterval
|
||||
if ($connCheckTotalTime -le $ConnectivityCheckTimeout -and $targetComputers.Count -gt 0)
|
||||
{
|
||||
for ($i = $ConnectivityCheckInterval; $i -gt 0; $i--) {
|
||||
Write-Progress -Activity "Waiting for next connectivity check..." -SecondsRemaining $i
|
||||
Start-Sleep 1
|
||||
}
|
||||
Write-Progress -Activity "Waiting for next connectivity check..." -Completed
|
||||
}
|
||||
} while ($connCheckTotalTime -le $ConnectivityCheckTimeout -and $targetComputers.Count -gt 0)
|
||||
|
||||
# exit gracefully
|
||||
exitGracefully
|
||||
Reference in New Issue
Block a user