-
Notifications
You must be signed in to change notification settings - Fork 1
/
FastvueReporterInstall.ps1
1187 lines (984 loc) · 47.6 KB
/
FastvueReporterInstall.ps1
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ------------------------------------------------------------------------------
# Fastvue Reporter Installation Script
# Copyright © 2023 Fastvue Pty Ltd
# http://go.fastvue.co/?id=170
# ------------------------------------------------------------------------------
<#
.SYNOPSIS
Installs and configures instances of Fastvue Reporter.
.DESCRIPTION
This script is used to install, configure, and uninstall an instance of Fastvue Reporter either on the local machine or on a specified remote machine.
All configuration options can be specified either as parameters to the script, or via a prewritten configuration file using the same parameter names in 'Key=Value' format with one parameter per line, with the path to the configuration file specified using the -ConfigFile parameter. Any parameters specified directly to the script will override settings read from the configuration file if one is specified.
Fastvue Reporter is available for a number of different Firewall vendors, with a separate product per Firewall vendor. The required Fastvue Reporter product must be specified when running the script using the -Product parameter. For a list of available products, run the script with the -ListProducts switch.
.PARAMETER ConfigFile
Path to a configuration file that specifies settings for the installation and configuration of Fastvue Reporter.
.PARAMETER Mode
Mode to run the installation script in. Valid values are 'InstallAndConfigure', 'Install', 'Configure', and 'Uninstall'.
.PARAMETER ConfigTarget
Optional parameter to specify which parts of Fastvue Reporter will be configured, ignoring parts not specified here even if their configurations have been provided.
Specified as either an array or a comma-separated string, can be a combination of any of the following values;
- Auth
- DataRetention
- LDAP
- Mail
- Source
- Productivity
- License
- PublicUrl
- Proxy
- YouTube
.PARAMETER Product
Required. Name of the Fastvue Reporter product you want to install.
.PARAMETER ReleaseChannel
Release Channel to download Fastvue Reporter for. Valid values are 'Stable' and 'Latest'.
.PARAMETER ProductVersion
Version number of Fastvue Reporter product to install.
.PARAMETER InstallerBaseUrl
Alternate base URL to download installers from.
.PARAMETER ShowVars
Debug option to show all variables before proceeding with installation.
.PARAMETER ShowSystemInfo
Show the system information and exit the script without installing.
.PARAMETER Version
Show the script version number and exit the script without installing.
.PARAMETER ListProducts
List available Fastvue Reporter products that can be installed and exits the script without installing.
.PARAMETER ListProductVersions
List available versions of the selected Fastvue Reporter product and exits the script without installing.
.PARAMETER InvokedFromRemote
Flag provided to script automatically when executed on a remote system. Do not specify this parameter manually.
.PARAMETER Server
Remote system to run the installation script on. Requires WinRM enabled on the remote system.
.PARAMETER ServerPort
Remote port to connect to a WinRM session on.
.PARAMETER ServerCredential
Credential for authenticating to the remote system.
.PARAMETER ServerUsername
Username for authenticating to the remote system. Ignored if -ServerCredential is specified.
.PARAMETER ServerPassword
Password for authenticating to the remote system. Can be a plain-text string or a SecureString. Ignored if -ServerCredential is specified.
.PARAMETER TempPath
Temporary path to copy required files to when running the installation script on a remote system.
.PARAMETER InstallerExecutablePath
Path to installer executable. Specifying this will prevent automatic download of the required version.
.PARAMETER ApiCredential
Credential for authenticating to the Fastvue Reporter API.
.PARAMETER ApiUsername
Username for authenticating to the Fastvue Reporter API. Ignored if -ApiCredential is specified.
.PARAMETER ApiPassword
Password for authenticating to the Fastvue Reporter API. Can be a plain-text string or a SecureString. Ignored if -ApiCredential is specified.
.PARAMETER DataPath
Path to where Fastvue Reporter should store its data once installed.
.PARAMETER IISSite
Name of the IIS website to install Fastvue Reporter's web frontend to.
.PARAMETER IISVDir
IIS virtual directory or subpath to install Fastvue Reporter's web frontend to.
.PARAMETER FastvueReporterUrl
Optional. The full URL to the Fastvue Reporter interface. Used to target a specific existing instance or provide the expected URL to access Reporter in case the script cannot automatically determine the correct URL.
.PARAMETER IISAuth
Specifies that IIS Authentication should be configured by the script.
.PARAMETER IISAuthAllowUsers
Comma-separated list of usernames that have permission to access the Fastvue Reporter interface.
.PARAMETER IISAuthAllowRoles
Comma-separated list of roles or security groups that have permission to access the Fastvue Reporter interface.
.PARAMETER IISAuthSharedAllowUsers
Comma-separated list of usernames that have permission to access private shared reports.
.PARAMETER IISAuthSharedAllowRoles
Comma-separated list of roles or security groups that have permission to access private shared reports.
.PARAMETER SyslogSourceHost
Hostname or IP to receive Syslog messages from.
.PARAMETER SyslogSourcePort
Port to receive Syslog messages on.
.PARAMETER MailHost
Hostname or IP of SMTP server to use when sending mail.
.PARAMETER MailPort
Port of the SMTP server.
.PARAMETER MailSSL
Use secure communication with SMTP server.
.PARAMETER MailFrom
Email address to send mail from.
.PARAMETER MailCredential
Credential for authenticating to the SMTP server.
.PARAMETER MailUsername
Username for authenticating to the SMTP server. Ignored if -MailCredential is specified.
.PARAMETER MailPassword
Password for authenticating to the SMTP server. Can be a plain-text string or a SecureString. Ignored if -MailCredential is specified.
.PARAMETER LdapHost
Hostname or IP of LDAP server to import Organizational information from.
.PARAMETER LdapPort
Port of the LDAP server.
.PARAMETER LdapSSL
Use secure communication with LDAP server.
.PARAMETER LdapSearchDN
FQDN to search on the LDAP server.
.PARAMETER LdapCredential
Credential for authenticating to the LDAP server.
.PARAMETER LdapUsername
Username for authenticating to the LDAP server. Ignored if -LdapCredential is specified.
.PARAMETER LdapPassword
Password for authenticating to the LDAP server. Can be a plain-text string or a SecureString. Ignored if -LdapCredential is specified.
.PARAMETER RetentionEnabled
Specifies that the Data Retention policy should be enabled.
.PARAMETER RetentionDays
Number of days to retain imported data for.
.PARAMETER RetentionSize
Maximum size of imported data to retain.
.PARAMETER ProductivityUnacceptable
Array or comma-separated string of category names to mark as Unacceptable in Productivity ratings.
.PARAMETER ProductivityUnproductive
Array or comma-separated string of category names to mark as Unproductive in Productivity ratings.
.PARAMETER ProductivityAcceptable
Array or comma-separated string of category names to mark as Acceptable in Productivity ratings.
.PARAMETER ProductivityProductive
Array or comma-separated string of category names to mark as Productive in Productivity ratings.
.PARAMETER LicenseKey
Array or comma-separated string of License Keys to apply to the installed instance of Fastvue Reporter.
.PARAMETER LicenseKeyMode
How the specified license keys should be applied. Valid values are 'Replace' and 'Add';
'Replace' - Replaces all keys in Fastvue Reporter with the keys specified, removing existing keys if they were not specified.
'Add' - Adds the specified keys to Fastvue Reporter, leaving already existing keys in place.
.PARAMETER PublicUrl
Public URL that this Fastvue Reporter instance will be accessible via. Used when emailing reports and alerts to provide the recipient with a link back to the Fastvue Reporter interface.
.PARAMETER YouTubeApiKey
API key to use when performing lookups on YouTube videos.
.PARAMETER ProxyServer
Proxy server that Fastvue Reporter should use when connecting to external sites.
.PARAMETER ProxyPort
Port of the Proxy server.
.PARAMETER ProxyIgnoreCertErrors
Ignores any certificate errors that occur when connecting via the proxy server.
.PARAMETER ProxyCredential
Credential to authenticate to the Proxy server.
.PARAMETER ProxyUsername
Username to authenticate to the Proxy server. Ignored if -ProxyCredential is specified.
.PARAMETER ProxyPassword
Password to authenticate to the Proxy server. Can be a plain-text string or a SecureString. Ignored if -ProxyCredential is specified.
.PARAMETER ProxyAuthDomain
Authentication domain to be specified to the Proxy server.
.EXAMPLE
.NOTES
#>
param (
[string]$Product = $null,
[string]$ReleaseChannel = "Stable",
[string]$ProductVersion = $null,
[string]$ConfigFile = $null,
[string]$Mode = "InstallAndConfigure",
$ConfigTarget = $null,
[string]$InstallerBaseUrl = $null,
[Switch]$Version = $false,
[Switch]$ShowVars = $false,
[Switch]$ShowSystemInfo = $false,
[Switch]$ListProducts = $false,
[Switch]$ListProductVersions = $false,
[Switch]$InvokedFromRemote = $false,
[string]$Server = $null,
[Int32]$ServerPort = 5985,
[pscredential]$ServerCredential = $null,
[string]$ServerUsername = $null,
$ServerPassword = $null,
[string]$TempPath = "C:\__Fastvue_Install",
[string]$InstallerExecutablePath = $null,
[pscredential]$ApiCredential = $null,
[string]$ApiUsername = $null,
$ApiPassword = $null,
[string]$DataPath = $null,
[string]$IISSite = "Default Web Site",
[string]$IISVDir = $null,
[string]$FastvueReporterUrl = $null,
$IISAuth = $null,
[string]$IISAuthAllowUsers = $null,
[string]$IISAuthAllowRoles = $null,
[string]$IISAuthSharedAllowUsers = $null,
[string]$IISAuthSharedAllowRoles = $null,
[string]$SyslogSourceHost = $null,
[Int32]$SyslogSourcePort = 514,
[string]$MailHost = $null,
[Int32]$MailPort = 587,
[boolean]$MailSSL = $true,
[string]$MailFrom = $null,
[pscredential]$MailCredential = $null,
[string]$MailUsername = $null,
$MailPassword = $null,
[string]$LdapHost = $null,
[Int32]$LdapPort = 389,
[boolean]$LdapSSL = $false,
[string]$LdapSearchDN = $null,
[pscredential]$LdapCredential = $null,
[string]$LdapUsername = $null,
$LdapPassword = $null,
[boolean]$RetentionEnabled = $true,
[Int32]$RetentionDays = 30,
[string]$RetentionSize = $null,
$ProductivityUnacceptable = $null,
$ProductivityUnproductive = $null,
$ProductivityAcceptable = $null,
$ProductivityProductive = $null,
$LicenseKey = $null,
[string]$LicenseKeyMode = "Replace",
[string]$PublicUrl = $null,
[string]$YouTubeApiKey = $null,
[string]$ProxyServer = $null,
[Int32]$ProxyPort = 8080,
[boolean]$ProxyIgnoreCertErrors = $false,
[pscredential]$ProxyCredential = $null,
[string]$ProxyUsername = $null,
$ProxyPassword = $null,
[string]$ProxyAuthDomain = $null
)
Set-Variable -Option Constant FastvueReporterInstallScriptVersion "0.1.2"
if ($Version) {
Write-Output $FastvueReporterInstallScriptVersion
Exit 0
}
# ------------------------------------------------------------------------------
# Helper functions
# ------------------------------------------------------------------------------
function Split-String {
param (
$Value = $null
)
if (!$Value) {
return @()
}
return [regex]::Split($Value, ',(?=(?:[^"]|"[^"]*")*$)') | ForEach-Object { $_.Trim('`"') }
}
function Resolve-Array {
param (
$Value = $null
)
if (!$Value) {
return @()
}
if ($Value.GetType().Name -eq "ArrayList") {
return $Value.ToArray()
}
if (!$Value.GetType().IsArray) {
return Split-String $Value
}
return $Value
}
function Convert-Array-ToJSON {
param (
[Array]$Value = $null
)
if ($Value.Length -eq 0) {
return "[]"
}
return '["{0}"]' -f ($Value -join '","')
}
function Resolve-Credential {
param (
[pscredential]$Provided = $null,
[string]$Username = $null,
$Password = $null,
[boolean]$Ask = $false,
[string]$AskMessage = "Enter credentials"
)
if ($Provided) {
return $Provided
} elseif ($Username -and $Password) {
if ($Password.GetType().Name -eq "string") {
$Password = ConvertTo-SecureString $Password -AsPlainText -Force
}
return New-Object System.Management.Automation.PSCredential($Username, $Password)
} else {
if ($Ask) {
return Get-Credential -Message $AskMessage
} else {
return $null
}
}
}
function Open-Credential {
param (
[pscredential]$Credential = $null
)
if ($Credential) {
return @{Username=$Credential.Username; Password=$Credential.GetNetworkCredential().password}
} else {
return @{Username=$null; Password=$null}
}
}
if (!$Server -and $ShowSystemInfo) {
$osname = (Get-WmiObject -class Win32_OperatingSystem).Caption
Write-Host "Machine Name: $env:computername"
Write-Host "Operating System: $osname"
Exit 0
}
$ThisScriptPath = $MyInvocation.MyCommand.Definition
if ($ConfigFile) {
if (-not(Test-Path $ConfigFile -PathType Leaf)) {
Write-Error "Configuration file '$ConfigFile' could not be found"
Exit 1
}
Get-Content $ConfigFile | Foreach-Object{
if ($_.length -gt 0 -and !$_.StartsWith('#')) {
$var = $_.Split('=', 2)
$varName = $var[0]
$varValue = $var[1]
if (!$PSBoundParameters.ContainsKey($varName)) {
if ($varName.Contains('Password')) {
$secureValue = ConvertTo-SecureString $varValue -AsPlainText -Force
Set-Variable -Name $varName -Value $secureValue
} else {
if ($varValue -eq 'true' -or $varValue -eq 'yes' -or $varValue -eq '1' -or $varValue -eq '$true') {
Set-Variable -Name $varName -Value $true
} elseif ($varValue -eq 'false' -or $varValue -eq 'no' -or $varValue -eq '0' -or $varValue -eq '$false') {
Set-Variable -Name $varName -Value $false
} else {
Set-Variable -Name $varName -Value $varValue
}
}
}
}
}
}
# ------------------------------------------------------------------------------
# Show variables before proceeding if ShowVars specified
# ------------------------------------------------------------------------------
if ($ShowVars) {
Write-Host "--- Showing configured parameters for installation script --------------------"
Get-Variable
Read-Host -Prompt "Confirm vars and press enter to continue"
}
# ------------------------------------------------------------------------------
# Validate parameters for valid values, resolve parameters, and apply defaults where needed
# ------------------------------------------------------------------------------
$ValidModes = @("InstallAndConfigure", "Install", "Configure", "Uninstall")
if (!($ValidModes -contains $Mode)) {
Write-Error "Invalid mode '$Mode' specified. Valid values are $('''{0}''' -f ($ValidModes -join ''','''))"
Exit 1
}
$PerformConfig = $false
$PerformInstall = $false
$PerformUninstall = $false
if ($Mode -eq "InstallAndConfigure" -or $Mode -eq "Install") {
$PerformInstall = $true
}
if ($Mode -eq "InstallAndConfigure" -or $Mode -eq "Configure") {
$PerformConfig = $true
}
if ($Mode -eq "Uninstall") {
$PerformUninstall = $true
}
$ValidConfigTargets = @("Auth", "DataRetention", "LDAP", "Mail", "Source", "Productivity", "License", "PublicUrl", "Proxy", "YouTube")
$ConfigTarget = Resolve-Array $ConfigTarget
if (!$ConfigTarget) {
$ConfigTarget = $ValidConfigTargets.Clone()
}
foreach ($ConfigTargetItem in $ConfigTarget) {
if (!($ValidConfigTargets -contains $ConfigTargetItem)) {
Write-Error "Invalid ConfigTarget '$ConfigTargetItem'. Valid values are $('''{0}''' -f ($ValidConfigTargets -join ''','''))"
Exit 1
}
}
$ValidLicenseKeyModes = @("Replace", "Add")
if (!($ValidLicenseKeyModes -contains $LicenseKeyMode)) {
Write-Error "Invalid license key mode '$LicenseKeyMode' specified. Valid values are $('''{0}''' -f ($ValidLicenseKeyModes -join ''','''))"
Exit 1
}
if (!$Product -and $ListProducts -eq $false) {
Write-Error "Fastvue Reporter product to install was not specified"
Exit 1
}
if (!$InstallerBaseUrl) {
$InstallerBaseUrl = "http://installs.fastvue.co/Fastvue/Reporter"
}
if ($ReleaseChannel -eq "Stable") {
$ReleaseChannelSuffix = "stable"
} elseif ($ReleaseChannel -eq "Latest") {
$ReleaseChannelSuffix = "latest"
} else {
Write-Error "Invalid release channel '$ReleaseChannel' specified"
Exit 1
}
# ------------------------------------------------------------------------------
# Download Fastvue Reporter product manifest and retrieve information for requested product and version.
# ------------------------------------------------------------------------------
$ReleaseManifest = [XML](Invoke-WebRequest -URI "$InstallerBaseUrl/Manifest.xml").Content
if (!$ReleaseManifest) {
Write-Error "Failed to download release manifest. Exiting"
Exit 1
}
$ReleaseManifestProduct = $ReleaseManifest.Manifest.Product | Where-Object { $_.ID -eq "Reporter" }
if ($ListProducts) {
Write-Host "Available Products:"
$ReleaseManifestProduct.Brand | ForEach-Object { Write-Host "- $($_.ID): $($_.Name)" }
Exit 0
}
$ReleaseManifestBrand = $ReleaseManifestProduct.Brand | Where-Object { $_.ID -eq $Product }
if (!$ReleaseManifestBrand) {
Write-Error "Unknown Product '$Product' specified"
Exit 1
}
if ($ListProductVersions) {
Write-Host "Available Versions for $($ReleaseManifestBrand.Name):"
$ReleaseManifestBrand.Release | Sort-Object -Descending -Property "Version" | Select-Object "Version" | ForEach-Object { Write-Host "- $($_.Version)" }
Exit 0
}
if ($ProductVersion) {
$ReleaseManifestVersion = $ReleaseManifestBrand.Release | Where-Object { $_.Version -eq $ProductVersion }
if (!$ReleaseManifestVersion) {
Write-Error "Unable to find release information for software version $ProductVersion for product $Product"
Exit 1
}
} else {
$ReleaseManifestVersion = $ReleaseManifestBrand.Release | Sort-Object -Descending -Property "Version" | Select-Object -First 1
}
if (!$ReleaseManifestVersion) {
Write-Error "Unable to find release information for software for product $Product"
Exit 1
}
$ProductName = $ReleaseManifestBrand.Name
$ProductSourceType = $ReleaseManifestBrand.Configuration.SourceType
$ProductInstallerUrlPath = $ReleaseManifestVersion.Path
$ProductVersion = $ReleaseManifestVersion.Version
$FastvueReporterInstallerDownloadUrl = "${InstallerBaseUrl}/${ProductInstallerUrlPath}_${ReleaseChannelSuffix}.exe".Replace(' ', '%20')
# ------------------------------------------------------------------------------
# Set up variables for configuring IIS
# ------------------------------------------------------------------------------
if (!$IISSite) {
$IISSite = "Default Web Site"
}
if ($IISVDir -ne "") {
$IISConfigLocation = "$IISSite/$IISVDir"
$IISConfigPSPath = "IIS:\sites\$IISSite\$IISVDir"
$IISConfigSharedPSPathP = "IIS:\sites\$IISSite\$IISVDir\p"
$IISConfigSharedPSPathUnderscore = "IIS:\sites\$IISSite\$IISVDir\_"
} else {
$IISConfigLocation = "$IISSite"
$IISConfigPSPath = "IIS:\sites\$IISSite"
$IISConfigSharedPSPathP = "IIS:\sites\$IISSite\p"
$IISConfigSharedPSPathUnderscore = "IIS:\sites\$IISSite\_"
}
if (!$FastvueReporterUrl) {
if ($Server) {
# Localhost is still included when $Server is set as the script will be running on the server itself
$PossibleFastvueReporterUrls = @("http://localhost/$IISVDir", "http://127.0.0.1/$IISVDir", "http://${Server}/${IISVDir}");
$FastvueReporterUrl = "http://localhost/$IISVDir"
} else {
$PossibleFastvueReporterUrls = @("http://localhost/$IISVDir", "http://127.0.0.1/$IISVDir");
$FastvueReporterUrl = "http://localhost/$IISVDir"
}
} else {
$PossibleFastvueReporterUrls = @($FastvueReporterUrl);
}
# ------------------------------------------------------------------------------
# Download installer executable for specified product and version
# ------------------------------------------------------------------------------
if (!$InstallerExecutablePath -and $PerformInstall) {
$InstallerExecutablePath = "$env:TEMP\FastvueReporterSetup_${Product}_${ReleaseChannelSuffix}.exe"
Write-Host "- Downloading Installer"
$PerformDownload = $true
$UseExistingInstallerReason = ""
if (Test-Path $InstallerExecutablePath -PathType Leaf) {
$ExistingInstallerFile = Get-ChildItem $InstallerExecutablePath
$ExistingInstallerAgeLimit = [datetime]::Now.AddDays(-1)
if ($ExistingInstallerFile.LastWriteTime -gt $ExistingInstallerAgeLimit) {
$PerformDownload = $false
$UseExistingInstallerReason = "Downloaded $($ExistingInstallerFile.LastWriteTime)"
}
}
if ($PerformDownload) {
$oldProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
try {
Invoke-WebRequest -Uri $FastvueReporterInstallerDownloadUrl -OutFile $InstallerExecutablePath
} catch {
Write-Error "Failed to download installer: $_"
Exit 1
}
$ProgressPreference = $oldProgressPreference
} else {
Write-Host "- Using Existing Installer ($UseExistingInstallerReason)"
}
}
if ($Server -and !$InvokedFromRemote) {
# ------------------------------------------------------------------------------
# REMOTE MODE: Perform script operations on a remote system
# ------------------------------------------------------------------------------
if ($PerformUninstall) {
Write-Host "- Uninstalling from remote server $Server"
} elseif ($PerformInstall) {
Write-Host "- Installing to remote server $Server"
} else {
Write-Host "- Configuring on remote server $Server"
}
$ServerCredential = Resolve-Credential -Provided $ServerCredential -Username $ServerUsername -Password $ServerPassword -Ask $true -AskMessage "Enter credentials for remote session on server '$Server'"
if (!$ServerCredential) {
Write-Error "No credentials provided"
Exit 1
}
Write-Host "- Connecting to $Server"
$RemoteSession = New-PSSession -Port $ServerPort -Credential $ServerCredential $Server
if ($RemoteSession) {
Write-Host "- Connected to $Server"
Write-Host "- Copying files to remote session"
Invoke-Command -Session $RemoteSession -ScriptBlock {
New-Item -Path $using:TempPath -type directory -Force | Out-Null
}
$RemoteParameters = [hashtable]$PSBoundParameters
$RemoteParameters["InvokedFromRemote"] = $true
Copy-Item -ToSession $RemoteSession $ThisScriptPath -Destination "$TempPath\FastvueReporterInstall.ps1" -ErrorAction Stop
if ($PerformInstall) {
Copy-Item -ToSession $RemoteSession $InstallerExecutablePath -Destination "$TempPath\FastvueReporterSetup.exe" -ErrorAction Stop
$RemoteParameters["InstallerExecutablePath"] = "$TempPath\FastvueReporterSetup.exe"
}
if ($ConfigFile) {
Copy-Item -ToSession $RemoteSession $ConfigFile -Destination "$TempPath\FastvueReporter.conf" -ErrorAction Stop
$RemoteParameters["ConfigFile"] = "$TempPath\FastvueReporter.conf"
}
Write-Host "- Performing operations on remote session"
$RemoteInvokeResult = Invoke-Command -Session $RemoteSession -ScriptBlock {
& "$using:TempPath\FastvueReporterInstall.ps1" @using:RemoteParameters
if (!$?) {
Write-Error "Operation failed"
Break
}
return @{MachineName=$env:computername}
}
if ($RemoteInvokeResult) {
$ServerMachineName = $RemoteInvokeResult.MachineName
}
Write-Host "- Cleaning up"
Invoke-Command -Session $RemoteSession -ScriptBlock {
Remove-Item -Recurse -Path $using:TempPath -Force
}
Write-Host "- Closing remote session"
Remove-PSSession -Session $RemoteSession
} else {
Write-Error "Could not connect to $Server"
}
} else {
# ------------------------------------------------------------------------------
# LOCAL MODE: Perform script operations on local machine
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Install Fastvue Reporter if script is in Install mode
# ------------------------------------------------------------------------------
if ($PerformInstall) {
Write-Host "- Installing $ProductName"
$InstallerArgs = "/silent /verysilent"
if ($DataPath) {
$InstallerArgs += " /datapath=`"$DataPath`""
}
if ($IISSite) {
$InstallerArgs += " /iissite=`"$IISSite`""
}
if ($IISVDir) {
$InstallerArgs += " /iisvdir=`"$IISVDir`""
}
Start-Process $InstallerExecutablePath -Wait -ArgumentList $InstallerArgs
Write-Host "- $ProductName Installed!"
}
# ------------------------------------------------------------------------------
# Uninstall Fastvue Reporter if script is in Uninstall mode
# ------------------------------------------------------------------------------
if ($PerformUninstall) {
Write-Host "- Uninstalling $ProductName"
$RegUninstall = Get-Item -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
$RegUninstallEntries = $RegUninstall.GetSubKeyNames()
foreach ($UninstallEntry in $RegUninstallEntries) {
$UninstallEntryDisplayName = (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$UninstallEntry" -Name "DisplayName" -ErrorAction SilentlyContinue).DisplayName
if ($UninstallEntryDisplayName -eq $ProductName) {
$UninstallEntryCommand = (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$UninstallEntry" -Name "UninstallString").UninstallString
Start-Process $UninstallEntryCommand.Trim('`"') -Wait -ArgumentList "/silent"
Write-Host "- Uninstallation complete"
Exit 0
}
}
Write-Warning "- Could not find uninstall entry for '$ProductName', possibly not currently installed. Exiting."
Exit
}
# ------------------------------------------------------------------------------
# Configure Fastvue Reporter if script is in Configure mode
# ------------------------------------------------------------------------------
if ($PerformConfig) {
$ApiCredential = Resolve-Credential -Provided $ApiCredential -Username $ApiUsername -Password $ApiPassword
# ------------------------------------------------------------------------------
# Enable anonymous access in IIS if Auth should be configured but no API credentials have been specified
# ------------------------------------------------------------------------------
if ($null -ne $IISAuth -and $ConfigTarget -contains "Auth") {
if (!$ApiCredential) {
Write-Host "- Temporarily Enabling Anonymous Access For Configuration"
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/anonymousAuthentication" -Name "enabled" -Value "true" -PSPath "IIS:\" -Location $IISConfigLocation
Remove-WebConfigurationProperty -Filter "system.webServer/security/authorization" -PSPath $IISConfigPSPath -name .
Remove-WebConfigurationProperty -Filter "system.webServer/security/authorization" -PSPath $IISConfigSharedPSPathP -name .
Remove-WebConfigurationProperty -Filter "system.webServer/security/authorization" -PSPath $IISConfigSharedPSPathUnderscore -name .
Add-WebConfiguration -Filter "system.webServer/security/authorization" -Value @{accessType="Allow"; users="?"} -PSPath $IISConfigPSPath
Add-WebConfiguration -Filter "system.webServer/security/authorization" -Value @{accessType="Allow"; users="?"} -PSPath $IISConfigSharedPSPathP
Add-WebConfiguration -Filter "system.webServer/security/authorization" -Value @{accessType="Allow"; users="?"} -PSPath $IISConfigSharedPSPathUnderscore
}
}
# ------------------------------------------------------------------------------
# Verify that Fastvue Reporter is installed and its API is responding
# ------------------------------------------------------------------------------
Write-Host "- Checking Connection to $ProductName"
$waitResponsiveStart = Get-Date
$waitResponsiveDuration = 120
$oldErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"
$serviceResponsive = False
while (!$serviceResponsive) {
foreach ($PossibleUrl in $PossibleFastvueReporterUrls) {
$response = Invoke-RestMethod -Credential $ApiCredential -TimeoutSec 2 -Uri "$PossibleUrl/_/api?f=Service.Status"
$serviceResponsive = $?
if ($serviceResponsive) {
$FastvueReporterUrl = $PossibleUrl
write-Host " - Connected via $FastvueReporterUrl"
} else {
if ((New-TimeSpan -Start $waitResponsiveStart).TotalSeconds -gt $waitResponsiveDuration) {
$ErrorActionPreference = $oldErrorActionPreference
Write-Error "Unable to verify connection to $ProductName at the following URLs after $waitResponsiveDuration seconds. Please check the installation configuration and try again."
foreach ($url in $PossibleFastvueReporterUrls) {
Write-Host " - $url"
}
Exit 1
}
}
}
}
$ErrorActionPreference = $oldErrorActionPreference
# ------------------------------------------------------------------------------
# Begin configuration of Fastvue Reporter
# ------------------------------------------------------------------------------
Write-Host "- Configuring $ProductName"
# ------------------------------------------------------------------------------
# Configure Data Retention Policy
# ------------------------------------------------------------------------------
if ($RetentionEnabled -and $RetentionSize -and $ConfigTarget -contains "DataRetention") {
Write-Host "- Configuring Data Retention Policy"
$response = Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.General.SetRetentionPolicy" -Method Post -ContentType "application/json" -Body @"
{
"Enabled": $RetentionEnabled,
"Days": $RetentionDays,
"Size": $RetentionSize
}
"@
if ($response.Status -ne 0) {
Write-Error "Error configuring Data Retention Policy: ${response.Message}"
}
}
# ------------------------------------------------------------------------------
# Configure LDAP
# ------------------------------------------------------------------------------
if ($LdapHost -and $ConfigTarget -contains "LDAP") {
Write-Host "- Configuring LDAP Integration"
$existingLdapSources = Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.General.GetLdapSources"
$ldapSourceID = $existingLdapSources.Data[0].ID
$LdapCredential = Resolve-Credential -Provided $LdapCredential -Username $LdapUsername -Password $LdapPassword
$LdapCredentialExtract = Open-Credential -Credential $LdapCredential
$response = Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.General.SetLdapSource" -Method Post -ContentType "application/json" -Body @"
{
"Source": {
"Enabled": true,
"ID": "$ldapSourceID",
"Server": "$LdapHost",
"Port": $LdapPort,
"SSL": "$LdapSSL",
"Roots": ["$LdapSearchDN"],
"Username": "$($LdapCredentialExtract.Username)",
"Password": "$($LdapCredentialExtract.Password)"
}
}
"@
}
# ------------------------------------------------------------------------------
# Configure Email
# ------------------------------------------------------------------------------
if ($MailHost -and $ConfigTarget -contains "Mail") {
Write-Host "- Configuring Email Settings"
$MailCredential = Resolve-Credential -Provided $MailCredential -Username $MailUsername -Password $MailPassword
$MailCredentialExtract = Open-Credential -Credential $MailCredential
$response = Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.General.SetMail" -Method Post -ContentType "application/json" -Body @"
{
"Enabled": true,
"ID": "",
"Server": "$MailHost",
"Port": $MailPort,
"Secure": "$MailSSL",
"From": "$MailFrom",
"Username": "$($MailCredentialExtract.Username)",
"Password": "$($MailCredentialExtract.Password)"
}
"@
}
# ------------------------------------------------------------------------------
# Configure Syslog Source
# ------------------------------------------------------------------------------
if ($SyslogSourceHost -and $ConfigTarget -contains "Source") {
Write-Host "- Configuring Syslog Source"
$existingSources = Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Sources.GetSources" -Method Get
if (!($existingSources.Data | Where-Object { $_.SourceType -eq "$ProductSourceType" -and $_.SourceDescription -eq "${SyslogSourceHost}:${SyslogSourcePort}" })) {
$response = Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Sources.AddRoot" -Method Post -ContentType "application/json" -Body @"
{
"Type":"SonicWall",
"Options": {
"Host": "$SyslogSourceHost",
"Port": $SyslogSourcePort,
"HistoricalMode": "None"
}
}
"@
}
}
# ------------------------------------------------------------------------------
# Configure Productivity Ratings
# ------------------------------------------------------------------------------
if ($ProductivityUnacceptable -or $ProductivityUnproductive -or $ProductivityAcceptable -or $ProductivityProductive) {
if ($ConfigTarget -contains "Productivity") {
Write-Host "- Configuring Productivity Ratings"
$ModifiedProductivityUnacceptable = $(Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Aliases.GetAliasEntryValues&Alias=Productivity&Entry=Unacceptable").Data
$ModifiedProductivityUnproductive = $(Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Aliases.GetAliasEntryValues&Alias=Productivity&Entry=Unproductive").Data
$ModifiedProductivityAcceptable = $(Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Aliases.GetAliasEntryValues&Alias=Productivity&Entry=Acceptable").Data
$ModifiedProductivityProductive = $(Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Aliases.GetAliasEntryValues&Alias=Productivity&Entry=Productive").Data
$ModifiedProductivityUnassigned = $(Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Aliases.GetAliasEntryValues&Alias=Productivity&Entry=Unassigned").Data
$ProductivityUnacceptable = Resolve-Array $ProductivityUnacceptable
$ProductivityUnproductive = Resolve-Array $ProductivityUnproductive
$ProductivityAcceptable = Resolve-Array $ProductivityAcceptable
$ProductivityProductive = Resolve-Array $ProductivityProductive
function Merge-Productivity {
param (
[Array]$Target = $null,
$Categories = $null
)
$Output = @()
if ($Categories) {
foreach ($Category in $Categories) {
if ($ModifiedProductivityUnacceptable -contains $Category) {
$script:ModifiedProductivityUnacceptable = $ModifiedProductivityUnacceptable | Where-Object { $_ -ne $Category }
}
if ($ModifiedProductivityUnproductive -contains $Category) {
$script:ModifiedProductivityUnproductive = $ModifiedProductivityUnproductive | Where-Object { $_ -ne $Category }
}
if ($ModifiedProductivityAcceptable -contains $Category) {
$script:ModifiedProductivityAcceptable = $ModifiedProductivityAcceptable | Where-Object { $_ -ne $Category }
}
if ($ModifiedProductivityProductive -contains $Category) {
$script:ModifiedProductivityProductive = $ModifiedProductivityProductive | Where-Object { $_ -ne $Category }
}
if ($ModifiedProductivityUnassigned -contains $Category) {
$script:ModifiedProductivityUnassigned = $ModifiedProductivityUnassigned | Where-Object { $_ -ne $Category }
}
if (!($Output -contains $Category)) {
$Output += $Category
}
}
}
foreach ($TargetCategory in $Target) {
if (!($Output -contains $TargetCategory)) {
$Output += $TargetCategory
}
}
return $Output
}
$ModifiedProductivityUnacceptable = Merge-Productivity -Target $ModifiedProductivityUnacceptable -Categories $ProductivityUnacceptable
$ModifiedProductivityUnproductive = Merge-Productivity -Target $ModifiedProductivityUnproductive -Categories $ProductivityUnproductive
$ModifiedProductivityAcceptable = Merge-Productivity -Target $ModifiedProductivityAcceptable -Categories $ProductivityAcceptable
$ModifiedProductivityProductive = Merge-Productivity -Target $ModifiedProductivityProductive -Categories $ProductivityProductive
$ModifiedProductivityUnacceptable = $ModifiedProductivityUnacceptable | Sort-Object
$ModifiedProductivityUnproductive = $ModifiedProductivityUnproductive | Sort-Object
$ModifiedProductivityAcceptable = $ModifiedProductivityAcceptable | Sort-Object
$ModifiedProductivityProductive = $ModifiedProductivityProductive | Sort-Object
$ProductivityUnacceptableJson = Convert-Array-ToJSON $ModifiedProductivityUnacceptable
$ProductivityUnproductiveJson = Convert-Array-ToJSON $ModifiedProductivityUnproductive
$ProductivityAcceptableJson = Convert-Array-ToJSON $ModifiedProductivityAcceptable
$ProductivityProductiveJson = Convert-Array-ToJSON $ModifiedProductivityProductive
$ProductivityUnassignedJson = Convert-Array-ToJSON $ModifiedProductivityUnassigned
$response = Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Aliases.SetAliasEntries" -Method Post -ContentType "application/json" -Body @"
{
"Alias":"Productivity",
"Entries": [
{ "Name": "Productive", "Values": $ProductivityProductiveJson },
{ "Name": "Unproductive", "Values": $ProductivityUnproductiveJson },
{ "Name": "Acceptable", "Values": $ProductivityAcceptableJson },
{ "Name": "Unacceptable", "Values": $ProductivityUnacceptableJson },
{ "Name": "Unassigned", "Values": $ProductivityUnassignedJson }
]
}
"@
}
}
# ------------------------------------------------------------------------------
# Configure Proxy
# ------------------------------------------------------------------------------
if ($ProxyServer -and $ConfigTarget -contains "Proxy") {
Write-Host "- Configuring Proxy"
$ProxyCredential = Resolve-Credential -Provided $ProxyCredential -Username $ProxyUsername -Password $ProxyPassword
$ProxyCredentialExtract = Open-Credential -Credential $ProxyCredential
if ($ProxyCredentialExtract.Username) {
$ProxyAuthEnabled = $true
} else {
$ProxyAuthEnabled = $false
}
$response = Invoke-RestMethod -Credential $ApiCredential -Uri "$FastvueReporterUrl/_/api?f=Settings.Proxy.SetProxySettings" -Method Post -ContentType "application/json" -Body @"
{
"ProxyEnabled": "True",
"ProxyServer": "$ProxyServer",
"ProxyPort": $ProxyPort,
"ProxyIgnoreSSLErrors": "$ProxyIgnoreCertErrors",
"ProxyAuthEnabled": "$ProxyAuthEnabled",
"ProxyAuthUsername": "$($ProxyCredentialExtract.Username)",
"ProxyAuthPassword": "$($ProxyCredentialExtract.Password)",
"ProxyAuthDomain": "$ProxyAuthDomain"
}
"@
}
# ------------------------------------------------------------------------------
# Configure License Keys
# ------------------------------------------------------------------------------
if ($LicenseKey -and $ConfigTarget -contains "License") {
Write-Host "- Configuring License"
$Keys = Resolve-Array $LicenseKey
$SetKeys = @()
if ($LicenseKeyMode -eq "Add") {