-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathsetup.ps1
549 lines (416 loc) · 17.4 KB
/
setup.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
# This script sets up RAWeb on a Windows host.
#
# Note: RAWeb will be installed into the default IIS website.
# If you are already using the default website for other purposes, this script may interfere with your existing configuration.
#
# A full installation involves the following steps:
#
# - Install IIS and required components (Web-Server, Web-Asp-Net45, Web-Windows-Auth, Web-Http-Redirect, Web-Mgmt-Console)
# - Copy the RAWeb directory to the inetpub directory
# - Create the RAWeb virtual directory
# - Create the RAWeb application
# - Enable Windows Authentication on RAWeb\auth
# - Enable HTTPS on the Default Web Site
# - Create and install an SSL certificate#
#
# The script performs the following actions:
#
# 1. Performs checks to to see which components are already installed, and ensures the environment is suitable for installation.
# 2. Prompts the user if any input is required.
# 3. Determines which components need to be installed or configured.
# 4. Confirms the installation steps with the user.
# 5. Installs or configures the necessary components.
#
# Note:
#
# - If RAWeb and IIS are already installed, the script will prompt to perform the necessary steps to repair/configure RAWeb.
# - The script includes no uninstallation or rollback functionality.
# - The script will prompt the user for confirmation before performing certain actions, such as overwriting existing directories or enabling HTTPS.
# - If IIS installation or configuration requires a system restart, the script will prompt the user to restart the computer.
# - The script is intended for use on Windows 10/11 and Windows Server editions.
# VARIABLES
$debug = $false
$sitename = "Default Web Site"
$source_dir = "aspx\wwwroot"
$ScriptPath = Split-Path -Path $MyInvocation.MyCommand.Path
$is_admin = $null
$is_server = $null
$is_supportedwindows = $null
$is_home = $null
$is_iisinstalled = $null
$wwwroot = $null
$rawebinwwwroot = $null
$is_rawebinstallpath_exists = $null
$is_rawebrealfolder_exists = $null
$virtualdirectory = $null
$is_virtualdirectory_exists = $null
$virtualdirectorypath = $null
$is_virtualdirectoryrealfolder_exists = $null
$is_virtualdirectoryapplication = $null
$is_auth_enabled = $null
$is_httpsenabled = $null
$is_certificate = $null
$install_iis = $null
$install_copy_raweb = $null
$install_create_virtualdirectory = $null
$install_remove_virtualdirectory = $null
$install_create_application = $null
$install_remove_application = $null
$install_enable_auth = $null
$install_enable_https = $null
$install_create_certificate = $null
# CHECKS
# Is this script running as administrator?
$is_admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
# Is Windows 10/11 or Server?
$os = Get-WmiObject -Class Win32_OperatingSystem
$is_server = $os.Caption -like "*Server*"
$is_supportedwindows = $is_server -or $os.Version -like "10.*"
# Is Windows HOME edition?
$is_home = $os.Caption -like "*Home*"
# Does the source directory exist?
$is_sourceexist = Test-Path $ScriptPath\$source_dir
# Is IIS installed?
if ($is_server) {
$iis = Get-WindowsFeature -Name Web-Server
$is_iisinstalled = $iis.Installed
} else {
$iis = Get-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole
$is_iisinstalled = $iis.State -eq "Enabled"
}
# Does the RAWeb folder already exist in inetpub (the install location)?
$inetpub = "$env:SystemDrive\inetpub"
$rawebininetpub = "$inetpub\RAWeb"
$is_rawebinstallpath_exists = Test-Path $rawebininetpub
# Does a conflicting folder called RAWeb exist in wwwroot?
$wwwroot = "$env:SystemDrive\inetpub\wwwroot"
$rawebinwwwroot = "$wwwroot\RAWeb"
$is_rawebrealfolder_exists = Test-Path $rawebinwwwroot
# Some checks can't be completed if IIS is not installed yet.
# If IIS is already installed then perform the checks.
if ($is_iisinstalled) {
# Does RAWeb virtual directory already exist?
$virtualdirectory = Get-WebVirtualDirectory -Site $sitename -Name "RAWeb"
$is_virtualdirectory_exists = $null -ne $virtualdirectory
# If so, does physical directory for the virtual directory actually exist in the filesystem?
if ($is_virtualdirectory_exists) {
$virtualdirectorypath = $virtualdirectory.PhysicalPath
$is_virtualdirectoryrealfolder_exists = Test-Path $virtualdirectorypath
}
# Also, is the virtual directory converted to a be an IIS application?
$is_virtualdirectoryapplication = $null -ne (Get-WebApplication -Site $sitename -Name "RAWeb")
# Is authentication enabled?
if ($is_virtualdirectoryapplication) {
$windows_auth = Get-WebConfigurationProperty -Filter "/system.webServer/security/authentication/windowsAuthentication" -Location "$sitename/RAWeb/auth" -Name "enabled"
$anonymous_auth = Get-WebConfigurationProperty -Filter "/system.webServer/security/authentication/anonymousAuthentication" -Location "$sitename/RAWeb/auth" -Name "enabled"
$is_auth_enabled = $windows_auth -eq "True" -and $anonymous_auth -eq "False"
# Currently this only checks Windows and Anonymous auth. If any other kind of auth is enabled, this will be a problem.
}
# Is HTTPS enabled?
$binding = Get-WebBinding -Name $sitename -Protocol https -Port 443
$is_httpsenabled = $null -ne $binding
# If HTTPS is enabled, is a certificate bound to the HTTPS binding?
if ($is_httpsenabled) {
$cert = $binding.certificateHash
$is_certificate = $null -ne $cert
}
}
# WELCOME
Write-Host
Write-Host "+++ RAWeb Setup +++" -BackgroundColor Black -ForegroundColor Green
Write-Host
Write-Host "This script will enable IIS and install RAWeb on this computer."
Write-Host
if ($debug) {
Write-Host "Debugging information:"
Write-Host
Write-Host "OS: $($os.Caption)"
Write-Host "Is admin: $is_admin"
Write-Host "Is server: $is_server"
Write-Host "Is supported Windows: $is_supportedwindows"
Write-Host "Is home: $is_home"
Write-Host "Is IIS installed: $is_iisinstalled"
Write-Host "Install source directory exists: $is_sourceexist"
Write-Host "RAWeb install path exists: $is_rawebinstallpath_exists"
Write-Host "Conflicting RAWeb directory exists in wwwroot: $is_rawebrealfolder_exists"
Write-Host "RAWeb virtual directory exists: $is_virtualdirectory_exists"
Write-Host "RAWeb virtual directory real directory exists: $is_virtualdirectoryrealfolder_exists"
Write-Host "RAWeb virtual directory is an application: $is_virtualdirectoryapplication"
Write-Host "Authentication enabled: $is_auth_enabled"
Write-Host "HTTPS enabled: $is_httpsenabled"
Write-Host "Certificate bound to HTTPS binding: $is_certificate"
Write-Host
}
# VERIFY
# Is running as administrator?
if (-not $is_admin) {
Write-Host "This script must be run as an administrator."
Write-Host "Please run this script as an administrator and try again."
Write-Host
Exit
}
# Is Windows 10/11 or Server?
if (-not $is_supportedwindows) {
Write-Host "RAWeb is intended for use on Windows 10/11 and Windows Server."
Write-Host "Running on other versions of Windows may not work as expected."
Write-Host
Write-Host "Do you want to continue anyway?"
$continue = Read-Host -Prompt "(y/N)"
Write-Host
if ($continue -notlike "Y") {
Write-Host "Exiting."
Write-Host
Exit
}
}
# Is Windows a home edition?
if ($is_home) {
Write-Host "RAWeb is not intended for Windows Home editions."
Write-Host "Home editions do not support hosting Remote Desktop connections."
Write-Host "RAWeb can be manually installed, however, the Windows Authentication feature will not be available."
Write-Host "To enable Windows Authentication, install the ""Microsoft Windows IIS WebServer AddOn Package"" for your particular Windows version/update."
Write-Host "Exiting."
Write-Host
Exit
}
if (-not $is_sourceexist) {
Write-Host "The source directory cannot be found ($ScriptPath\$source_dir)."
Write-Host "Exiting."
Write-Host
Exit
}
# Does a conflicting folder called RAWeb already exist in wwwroot?
if ($is_rawebrealfolder_exists) {
Write-Host "A directory called RAWeb already exists in the root of the default web site."
Write-Host "This will need to be removed before continuing."
Write-Host
Write-Host "Please remove $rawebinwwwroot and try again."
Write-Host
}
# DETERMINE INSTALLATION STEPS
# IIS
$install_iis = $true
# RAWeb folder
if ($is_rawebinstallpath_exists) {
Write-Host "RAWeb directory already exists in inetpub."
Write-Host "Would you like to overwrite it with a fresh copy?"
Write-Host "Your existing RAWeb configuration will be lost."
Write-Host
$continue = Read-Host -Prompt "(y/N)"
Write-Host
if ($continue -like "Y") {
$install_copy_raweb = $true
}
} else {
$install_copy_raweb = $true
}
# RAWeb virtual directory
if ($is_virtualdirectory_exists) {
Write-Host "RAWeb virtual directory already exists in IIS."
Write-Host "Would you like to recreate it?"
Write-Host
$continue = Read-Host -Prompt "(y/N)"
Write-Host
if ($continue -notlike "Y") {
if (-not $is_virtualdirectoryapplication) {
$install_create_application = $true
}
} else {
if ($is_virtualdirectoryapplication) {
$install_remove_application = $true
}
$install_remove_virtualdirectory = $true
$install_create_virtualdirectory = $true
$install_create_application = $true
}
} else {
$install_create_virtualdirectory = $true
$install_create_application = $true
}
# Enable authentication
if (-not $is_auth_enabled) {
Write-Host "Authentication must be enabled to use the webfeed/workspace feature,"
Write-Host "but it will also require users to authenticate to the web interface."
Write-Host "Would you like to enable it?"
Write-Host
$continue = Read-Host -Prompt "(Y/n)"
Write-Host
if ($continue -notlike "N") {
$install_enable_auth = $true
}
}
# Enable HTTPS
if (-not $is_iisinstalled) {
$install_enable_https = $true
$install_create_certificate = $true
} else {
if (-not $is_httpsenabled) {
Write-Host "HTTPS is not enabled on the Default Web Site."
Write-Host "Would you like to enable HTTPS?"
Write-Host
$continue = Read-Host -Prompt "(Y/n)"
Write-Host
if ($continue -notlike "N") {
$install_enable_https = $true
$install_create_certificate = $true
}
} else {
if (-not $is_certificate) {
Write-Host "An SSL certificate is required use the webfeed/workspace feature."
Write-Host "Would you like to create and bind a self-signed certificate?"
Write-Host
$continue = Read-Host -Prompt "(Y/n)"
Write-Host
if ($continue -notlike "N") {
$install_create_certificate = $true
}
}
}
}
# CONFIRM
Write-Host "The following installation steps will be performed:"
Write-Host
if ($install_iis) {
Write-Host "-Verify all required IIS features are installed"
}
if ($install_copy_raweb) {
Write-Host "-Copy the RAWeb directory to the inetpub directory"
}
if ($install_remove_application) {
Write-Host "-Remove the existing RAWeb application"
}
if ($install_remove_virtualdirectory) {
Write-Host "-Remove the existing RAWeb virtual directory"
}
if ($install_create_virtualdirectory) {
Write-Host "-Create the RAWeb virtual directory"
}
if ($install_create_application) {
Write-Host "-Create the RAWeb application"
}
if ($install_enable_auth) {
Write-Host "-Enable Authentication"
}
if ($install_enable_https) {
Write-Host "-Enable HTTPS on the Default Web Site"
}
if ($install_create_certificate) {
Write-Host "-Create and install an SSL certificate"
}
Write-Host
Write-Host "Do you want to proceed with the installation?"
$continue = Read-Host -Prompt "(Y/n)"
Write-Host
if ($continue -like "N") {
Write-Host "Exiting."
Write-Host
Exit
}
# INSTALL
# Install IIS and required components
if ($install_iis) {
Write-Host "Installing IIS and required components..."
Write-Host
if ($is_server) {
$result = Install-WindowsFeature -Name Web-Server, Web-Asp-Net45, Web-Windows-Auth, Web-Http-Redirect, Web-Mgmt-Console
} else {
$result = Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole,IIS-WebServer,IIS-CommonHttpFeatures,IIS-HttpErrors,IIS-HttpRedirect,IIS-ApplicationDevelopment,IIS-Security,IIS-RequestFiltering,IIS-NetFxExtensibility45,IIS-HealthAndDiagnostics,IIS-HttpLogging,IIS-Performance,IIS-WebServerManagementTools,IIS-StaticContent,IIS-DefaultDocument,IIS-DirectoryBrowsing,IIS-ASPNET45,IIS-ISAPIExtensions,IIS-ISAPIFilter,IIS-HttpCompressionStatic,IIS-ManagementConsole,IIS-WindowsAuthentication,NetFx4-AdvSrvs,NetFx4Extended-ASPNET45
}
if (
((-not $is_server) -and $result.RestartNeeded) -or
($is_server -and $result.RestartNeeded -ne "No")
) {
Write-Host "A restart is required to complete the installation."
Write-Host
Write-Host "Press ENTER to restart now."
Read-Host
Restart-Computer
}
}
# Copy the RAWeb folder to the local inetpub/wwwroot directory
if ($install_copy_raweb) {
Write-Host "Copying the RAWeb directory to the inetpub directory..."
Write-Host
# Delete the RAWeb folder if it exists
if (Test-Path "$inetpub\RAWeb") {
Remove-Item -Path "$inetpub\RAWeb" -Force -Recurse | Out-Null
}
# Create the RAWeb folder
New-Item -Path "$inetpub" -Name "RAWeb" -ItemType "directory" | Out-Null
# Copy the folder structure
Copy-Item -Path "$ScriptPath\$source_dir\*" -Destination "$inetpub\RAWeb" -Recurse -Force | Out-Null
}
# Remove the RAWeb application
if ($install_remove_application) {
Write-Host "Removing the existing RAWeb application..."
Write-Host
Remove-WebApplication -Site $sitename -Name "RAWeb" | Out-Null
}
# Remove the RAWeb virtual directory
if ($install_remove_virtualdirectory) {
Write-Host "Removing the existing RAWeb virtual directory..."
Write-Host
#Remove-WebVirtualDirectory -Site $sitename -Name "RAWeb"
Remove-Item -Path "IIS:\Sites\$($sitename)\RAWeb" -Recurse -Force | Out-Null
}
# Create the RAWeb virtual directory
if ($install_create_virtualdirectory) {
Write-Host "Creating the RAWeb virtual directory..."
Write-Host
New-WebVirtualDirectory -Site $sitename -Name "RAWeb" -PhysicalPath $rawebininetpub | Out-Null
}
# Create the RAWeb application
if ($install_create_application) {
Write-Host "Creating the RAWeb application..."
Write-Host
New-WebApplication -Site $sitename -Name "RAWeb" -PhysicalPath $rawebininetpub | Out-Null
}
if ($install_enable_auth) {
Write-Host "Enabling Windows Authentication on RAWeb\auth..."
Write-Host
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/anonymousAuthentication" -Location "$sitename/RAWeb/auth" -Name "enabled" -Value "False" | Out-Null
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/windowsAuthentication" -Location "$sitename/RAWeb/auth" -Name "enabled" -Value "True" | Out-Null
}
# Enable HTTPS
if ($install_enable_https) {
Write-Host "Enabling HTTPS on the Default Web Site..."
Write-Host
New-WebBinding -Name $sitename -Protocol https -Port 443 | Out-Null
}
# Create and install an SSL certificate
if ($install_create_certificate) {
Write-Host "Creating a self-signed SSL certificate..."
Write-Host
$cert = New-SelfSignedCertificate -DnsName $env:COMPUTERNAME -CertStoreLocation "Cert:\LocalMachine\My"
$thumbprint = $cert.Thumbprint
Write-Host "Binding the SSL certificate to the Default Web Site..."
Write-Host
(Get-WebBinding -Name $sitename -Port 443 -Protocol "https").AddSslCertificate($thumbprint, "my") | Out-Null
}
Write-Host "RAWeb setup is complete." -BackgroundColor Black -ForegroundColor Green
Write-Host
if ($binding -or $install_enable_https) {
Write-Host "Web interface:"
Write-Host
Write-Host "https://$env:COMPUTERNAME/RAWeb"
Write-Host
if ($is_auth_enabled -or $install_enable_auth) {
Write-Host "Webfeed/Workspace URL:"
Write-Host
Write-Host "https://$env:COMPUTERNAME/RAWeb/webfeed.aspx"
Write-Host
Write-Host "If you wish to access via a different URL/domain, you will need to configure the appropriate DNS records and SSL certificate in IIS."
Write-Host
} else {
Write-Host "The webfeed feature will not be available until authentication is enabled."
Write-Host
}
} else {
Write-Host "Web interface:"
Write-Host
Write-Host "http://$env:COMPUTERNAME/RAWeb"
Write-Host
Write-Host "The webfeed feature will not be available until HTTPS is enabled on the Default Web Site."
Write-Host
}
# END