-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-WebChange.ps1
More file actions
217 lines (191 loc) · 7.16 KB
/
Copy pathTest-WebChange.ps1
File metadata and controls
217 lines (191 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<#
.SYNOPSIS
Ueberwacht Webseiten auf inhaltliche Aenderungen per Hash-Vergleich.
.DESCRIPTION
Laedt die in urls.txt aufgefuehrten Adressen, bildet einen Hash ueber den
Seiteninhalt und vergleicht ihn mit dem letzten Stand aus state.json.
Geaenderte Seiten werden gemeldet, der neue Stand zurueckgeschrieben.
Gedacht fuer einen zeitgesteuerten Lauf, etwa um Herstellerseiten mit
Versionshinweisen oder Sicherheitsmeldungen zu beobachten.
.NOTES
state.json ist die Zustandsdatei des Laufs und per .gitignore
ausgeschlossen. Wird sie geloescht, meldet der naechste Lauf alle Seiten
als geaendert.
#>
function Test-WebChanges {
param (
[string]$EingabeDatei = "urls.txt",
[string]$StateDatei = "state.json",
[int]$TimeoutSec = 30,
[string]$UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
)
if (-not (Test-Path -LiteralPath $EingabeDatei -PathType Leaf)) {
Write-Warning "Datei '$EingabeDatei' nicht gefunden."
return
}
$state = @{}
if (Test-Path -LiteralPath $StateDatei -PathType Leaf) {
try {
$state = Get-Content $StateDatei -Raw -ErrorAction Stop | ConvertFrom-Json -AsHashtable -ErrorAction Stop
}
catch {
Write-Warning "Fehler beim Lesen der State-Datei: $_"
$state = @{}
}
}
$urls = Get-Content $EingabeDatei
foreach ($line in $urls) {
if ($line -match '^(?<url>[^|]+)\s*\|\s*(?<text>.+)$') {
$url = $matches.url.Trim()
$searchText = $matches.text.Trim()
}
else {
Write-Warning "Zeile ungültig: $line"
continue
}
try {
$response = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec $TimeoutSec -UserAgent $UserAgent -ErrorAction Stop
$content = $response.Content
}
catch {
Write-Warning "FEHLER beim Abruf: $url – $_"
continue
}
# Effiziente Hash-Berechnung
$hash = [System.BitConverter]::ToString(
[System.Security.Cryptography.SHA256]::HashData(
[System.Text.Encoding]::UTF8.GetBytes($content)
)
).Replace('-', '')
# Case-insensitive Textsuche mit Regex
$foundText = [bool]($content -imatch [regex]::Escape($searchText))
if (-not $state.ContainsKey($url)) {
$state[$url] = [ordered]@{
Hash = $hash
FoundText = $foundText
NeuHash = $null
NeuFound = $null
}
Write-Host "Erster Check: $url – Hash gespeichert"
continue
}
$oldHash = $state[$url].Hash
$oldFound = $state[$url].FoundText
if ($hash -ne $oldHash -or $foundText -ne $oldFound) {
if ($state[$url].NeuHash -ne $hash -or $state[$url].NeuFound -ne $foundText) {
$state[$url].NeuHash = $hash
$state[$url].NeuFound = $foundText
Write-Warning "ÄNDERUNG: $url (Hash oder Text geändert)"
}
else {
Write-Warning "Noch nicht bestätigt: $url"
}
}
}
try {
$state | ConvertTo-Json -Depth 5 | Set-Content -Encoding UTF8 -Path $StateDatei -Force
}
catch {
Write-Warning "Fehler beim Speichern des States: $_"
}
}
function Confirm-WebChange {
param (
[string]$Url,
[string]$StateDatei = "state.json"
)
if (-not (Test-Path -LiteralPath $StateDatei -PathType Leaf)) {
Write-Warning "State-Datei nicht gefunden."
return
}
try {
$state = Get-Content $StateDatei -Raw -ErrorAction Stop | ConvertFrom-Json -AsHashtable -ErrorAction Stop
}
catch {
Write-Warning "Fehler beim Lesen der State-Datei: $_"
return
}
$urlsToCheck = @()
if ($Url) {
$urlsToCheck += $Url
}
else {
$urlsToCheck += $state.Keys | Where-Object {
$s = $state[$_]
$null -ne $s.NeuHash -or $null -ne $s.NeuFound
}
}
foreach ($u in $urlsToCheck) {
if (-not $state.ContainsKey($u)) {
Write-Warning "URL nicht in Status-Datei: $u"
continue
}
$s = $state[$u]
if ($null -eq $s.NeuHash -and $null -eq $s.NeuFound) {
Write-Host "Keine neuen Änderungen bei: $u"
continue
}
if (-not $Url) {
Write-Host ""
Write-Host "Änderung erkannt für:"
Write-Host " URL: $u"
Write-Host " Alter Hash: $($s.Hash)"
Write-Host " Neuer Hash: $($s.NeuHash)"
Write-Host " Text vorher gefunden: $($s.FoundText)"
Write-Host " Text jetzt gefunden: $($s.NeuFound)"
$skipToNext = $false
while (-not $skipToNext) {
$eingabe = Read-Host "Aktion? (j=ja / n=nein / s=überspringen / o=öffnen / q=abbrechen)"
switch ($eingabe.ToLower()) {
'j' {
$s.Hash = $s.NeuHash
$s.FoundText = $s.NeuFound
$s.NeuHash = $null
$s.NeuFound = $null
Write-Host "Änderung bestätigt: $u"
$skipToNext = $true
}
'n' {
$s.NeuHash = $null
$s.NeuFound = $null
Write-Host "Änderung verworfen: $u"
$skipToNext = $true
}
's' {
Write-Host "Übersprungen: $u"
$skipToNext = $true
}
'o' {
Start-Process $u
}
'q' {
Write-Host "Abbruch durch Benutzer."
return
}
default {
Write-Host "Ungültige Eingabe."
}
}
}
}
else {
$s.Hash = $s.NeuHash
$s.FoundText = $s.NeuFound
$s.NeuHash = $null
$s.NeuFound = $null
Write-Host "Änderung bestätigt: $u"
}
}
try {
$state | ConvertTo-Json -Depth 5 | Set-Content -Encoding UTF8 -Path $StateDatei -Force
}
catch {
Write-Warning "Fehler beim Speichern des bestätigten States: $_"
}
}
# Test-WebChanges -EingabeDatei "urls.txt" -StateDatei "state.json"
# Confirm-WebChange -Url "https://help-viewer.kisters.de/desktop/en/3dvs_versioninfo_intro.php"
# Confirm-WebChange -Url "https://www.teamviewer.com/de/global/support/knowledge-base/teamviewer-remote/download-and-installation/supported-operating-systems-for-teamviewer-remote"
# urls.txt
# https://help-viewer.kisters.de/desktop/en/3dvs_versioninfo_intro.php | 2025.2.312
# https://www.teamviewer.com/de/global/support/knowledge-base/teamviewer-remote/download-and-installation/supported-operating-systems-for-teamviewer-remote | TeamViewer 15.64