This repository has been archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify.go
313 lines (280 loc) · 9.92 KB
/
verify.go
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// Update Checker
// Copyright (C) 2020 Florian Probst
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"strconv"
"strings"
)
func compareVersionStrings(version1, version2 string) int {
// replace "-" with "." to remediate version strings like 2.4.6-602
version1 = strings.Replace(version1, "-", ".", -1)
version2 = strings.Replace(version2, "-", ".", -1)
v1Split := strings.Split(version1, ".")
v2Split := strings.Split(version2, ".")
lenV1 := len(v1Split)
lenV2 := len(v2Split)
for i, v1 := range v1Split {
if i >= lenV2 {
return -1
}
v1Int, err1 := strconv.ParseUint(v1, 10, 64)
v2Int, err2 := strconv.ParseUint(v2Split[i], 10, 64)
if err1 != nil || err2 != nil {
// compare as string
return strings.Compare(v1, v2Split[i])
}
if v1Int > v2Int {
return 1
} else if v2Int == v1Int {
if i == lenV1-1 {
if lenV1 == lenV2 {
return 0
}
return -1
}
// else: go on
} else {
return -1
}
}
// TODO: we should return an error here instead
return -1
}
// verifies installed software versions
func verifyInstalledSoftwareVersions(installedSoftware map[string]installedSoftwareComponent, softwareReleaseStatii map[string]softwareReleaseStatus) []installedSoftwareMapping {
var returnMapping []installedSoftwareMapping
for regKey, installedComponent := range installedSoftware {
var upToDate = false
var found = false
var mappedStatValue softwareReleaseStatus
// ignore list
if strings.HasPrefix(installedComponent.DisplayName, "Java Auto Updater") {
continue
}
// Firefox (special due to long term support releases)
if strings.HasPrefix(installedComponent.DisplayName, "Mozilla Firefox") {
version := installedComponent.DisplayVersion
versionSplit := strings.Split(version, ".")
minorVersion := versionSplit[0] + "." + versionSplit[1]
currentRelease, inStatii := softwareReleaseStatii["Mozilla Firefox "+minorVersion]
if inStatii {
mappedStatValue = currentRelease
found = true
if compareVersionStrings(currentRelease.Version, version) == 0 {
upToDate = true
}
} else {
// go through all version and select newest
for statName, statValue := range softwareReleaseStatii {
if strings.HasPrefix(statName, "Mozilla Firefox") {
if mappedStatValue.Version != "" {
if compareVersionStrings(mappedStatValue.Version, statValue.Version) > 0 {
// ignore, we already found a newer release
} else {
found = true
mappedStatValue = statValue
}
} else {
found = true
mappedStatValue = statValue
}
}
}
}
}
// LibreOffice (special due to fresh and still releases)
if strings.HasPrefix(installedComponent.DisplayName, "LibreOffice") {
version := installedComponent.DisplayVersion
versionSplit := strings.Split(version, ".")
minorVersion := versionSplit[0] + "." + versionSplit[1]
subMinorVersion := versionSplit[0] + "." + versionSplit[1] + "." + versionSplit[2]
currentRelease, inStatii := softwareReleaseStatii["LibreOffice "+minorVersion]
if inStatii {
mappedStatValue = currentRelease
found = true
if compareVersionStrings(currentRelease.Version, subMinorVersion) == 0 {
upToDate = true
}
} else {
// go through all versions and select newest
for statName, statValue := range softwareReleaseStatii {
if strings.HasPrefix(statName, "LibreOffice") {
if mappedStatValue.Version != "" {
if compareVersionStrings(mappedStatValue.Version, statValue.Version) > 0 {
// ignore, we already found a newer release
} else {
found = true
mappedStatValue = statValue
}
} else {
found = true
mappedStatValue = statValue
}
}
}
}
}
// "Adobe Flash Player"
if strings.HasPrefix(installedComponent.DisplayName, "Adobe Flash Player") {
upToDate = false
found = true
mappedStatValue = softwareReleaseStatus{
Name: "Adobe Flash Player",
Version: "out of service - please uninstall",
Released: "2020-12-31",
Ends: "2020-12-31",
}
}
// "Adobe Acrobat Reader"
if strings.HasPrefix(installedComponent.DisplayName, "Adobe Acrobat Reader") {
version := installedComponent.DisplayVersion
adobeName := "Adobe Acrobat Reader"
if strings.HasPrefix(installedComponent.DisplayName, "Adobe Acrobat Reader DC") {
// DC version
adobeName += " DC"
} else {
adobeName = installedComponent.DisplayName[0:25]
}
Trace.Printf("Adobe name: " + adobeName)
for statName, statValue := range softwareReleaseStatii {
if strings.HasPrefix(statName, adobeName) {
Trace.Printf("Adobe Reader version mapping found for %s", statName)
mappedStatValue = statValue
found = true
if strings.HasPrefix(version, statValue.Version) {
upToDate = true
}
}
}
}
// other software
softwares := []string{"Google Chrome", "OpenVPN",
"7-Zip", "TeamViewer",
"Mozilla Thunderbird", "VeraCrypt", "Java"}
for _, name := range softwares {
if strings.HasPrefix(installedComponent.DisplayName, name) {
version := installedComponent.DisplayVersion
versionSplit := strings.Split(version, ".")
minorVersion := versionSplit[0] + "." + versionSplit[1]
majorVersion := versionSplit[0]
for statName, statValue := range softwareReleaseStatii {
if strings.HasPrefix(statName, name+" "+minorVersion) {
Trace.Printf("Minor version mapping found for %s", statName)
mappedStatValue = statValue
found = true
if strings.HasPrefix(version, statValue.Version) { //compareVersionStrings(, ) == 0 {
upToDate = true
}
} else if strings.HasPrefix(statName, name+" "+majorVersion) {
Trace.Printf("Major version mapping found for %s", statName)
mappedStatValue = statValue
found = true
if strings.HasPrefix(version, statValue.Version) {
upToDate = true
}
} else if strings.HasPrefix(statName, name) {
if mappedStatValue.Version != "" {
// ignore, we already found a correct release
} else {
Trace.Printf("Name only mapping found for %s", statName)
compareResult := compareVersionStrings(statValue.Version, version)
if compareResult == 0 {
found = true
mappedStatValue = statValue
upToDate = true
} else if compareResult < 0 {
// perhaps newer version as we know of (e.g. for Java) -> leave on unknown
} else {
found = true
mappedStatValue = statValue
}
}
}
}
}
}
// build mapping object
if upToDate {
returnMapping = append(returnMapping, installedSoftwareMapping{
Name: installedComponent.DisplayName,
Status: StatusUpToDate,
InstalledSoftware: installedComponent,
MappedStatus: mappedStatValue,
})
Info.Printf("%s seems up to date (%s)", installedComponent.DisplayName, installedComponent.DisplayVersion)
} else if found {
returnMapping = append(returnMapping, installedSoftwareMapping{
Name: installedComponent.DisplayName,
Status: StatusOutdated,
InstalledSoftware: installedComponent,
MappedStatus: mappedStatValue,
})
Info.Printf("%s seems outdated!! (%s)", installedComponent.DisplayName, installedComponent.DisplayVersion)
} else {
returnMapping = append(returnMapping, installedSoftwareMapping{
Name: installedComponent.DisplayName,
Status: StatusUnknown,
InstalledSoftware: installedComponent,
MappedStatus: mappedStatValue,
})
Trace.Printf("No Information for %s (%s)", installedComponent.DisplayName, regKey)
}
}
return returnMapping
}
// verify OS patchlevel
func verifyOSPatchlevel(windowsVersion WindowsVersion, softwareReleaseStatii map[string]softwareReleaseStatus) installedSoftwareMapping {
var status int
if windowsVersion.CurrentMajorVersionNumber == 10 {
// Windows 10
windowsReleaseName := "Microsoft Windows 10 " + string(windowsVersion.ReleaseID)
Trace.Println("windowsReleaseName: ", windowsReleaseName)
Trace.Println("windowsVersion.UBR: ", windowsVersion.UBR)
Trace.Println("string(windowsVersion.UBR): ", strconv.FormatUint(windowsVersion.UBR, 10))
windowsVersionString := windowsVersion.CurrentBuild + "." + strconv.FormatUint(windowsVersion.UBR, 10)
Trace.Println("windowsVersionString: ", windowsVersionString)
uptodateRelease := softwareReleaseStatii[windowsReleaseName]
Trace.Println("uptodateRelease: ", uptodateRelease)
if uptodateRelease.Version == windowsVersionString {
Info.Printf("Windows seems up to date")
status = StatusUpToDate
} else {
Info.Printf("Windows seems outdated!!")
status = StatusOutdated
}
return installedSoftwareMapping{
Name: "Microsoft Windows 10",
Status: status,
InstalledSoftware: installedSoftwareComponent{
DisplayName: windowsReleaseName,
DisplayVersion: windowsVersionString,
Publisher: "Microsoft",
},
MappedStatus: uptodateRelease,
}
}
Info.Printf("Windows Version <= Windows 8: Not supported by Update Checker")
return installedSoftwareMapping{
Name: windowsVersion.ProductName,
Status: StatusUnknown,
InstalledSoftware: installedSoftwareComponent{
DisplayName: windowsVersion.ProductName,
DisplayVersion: windowsVersion.CurrentBuild,
Publisher: "Microsoft",
},
MappedStatus: softwareReleaseStatus{},
}
}