-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathumbracoPermissions.ps1
98 lines (88 loc) · 3.09 KB
/
umbracoPermissions.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
# Get Params #---------------
param([string]$folderName)
# Define Variables #---------------
$mode = "1" # Choose 1 (cli), 2 (grid picker), or 3 (full windows picker).
$appPoolAccount = ("IIS_IUSRS")
$websitesPath = ("C:\websites\")
$removalMode = $true
# Check for a path
if (([string]::IsNullOrEmpty($folderName)))
{
Switch ($mode) {
"1"
{
# 1. CLI Free text input
$folderName = Read-Host -Prompt 'Input website folder name'
}
"2"
{
# 2. GridView Picker
$folderName = @(Get-ChildItem $websitesPath | Out-GridView -Title 'Choose a folder' -PassThru)
Write-Output $folderName
}
"3"
{
# 3. GUI Picker
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{SelectedPath = $websitesPath}
[void]$FolderBrowser.ShowDialog()
$FolderBrowser.SelectedPath
}
}
}
# Build Path #---------------
if (([string]::IsNullOrEmpty($FolderBrowser.SelectedPath)))
{
$fullPhysicalPath = ($websitesPath + $folderName)
}
else
{
$fullPhysicalPath = $FolderBrowser.SelectedPath
}
# Misc ASCII #---------------
$finText = "
NEDONE DONED DO NE NEDONED
NEDONED EDONEDO DON NE NEDONED
NE ED ED DO DONE NE NE
NE ED ED DO DO EDONE NE
NE ED ED DO DO DONE NEDONE
NE ED ED DO DO ONE NE
NE ED ED DO DO NE NE
NE NED ED EDO DO NE NE
NEDONE DONED DO NE NEDONED
"
# Set Permissions #---------------
$readExecute = $appPoolAccount, "ReadAndExecute", "ContainerInherit, ObjectInherit", "None", "Allow"
$read = $appPoolAccount, "Read", "ContainerInherit, ObjectInherit", "None", "Allow"
$modify = $appPoolAccount, "Modify", "ContainerInherit, ObjectInherit", "None", "Allow"
$fileModify = $appPoolAccount, "Modify", "Allow"
$objects = @{}
$objects["app_browsers"] = $readExecute
$objects["app_code"] = $readExecute
$objects["app_data"] = $modify
$objects["bin"] = $read
$objects["views"] = $modify
$objects["config"] = $modify
$objects["css"] = $modify
$objects["data"] = $modify
$objects["masterpages"] = $modify
$objects["scripts"] = $modify
$objects["umbraco"] = $modify
$objects["usercontrols"] = $read
$objects["web.config"] = $fileModify
$objects["connectionStrings.secret.config"] = $fileModify
$objects["xslt"] = $modify
foreach ($key in $objects.Keys) {
$path = Join-Path $fullPhysicalPath $key
if (Test-Path $path) {
$acl = Get-ACL $path
if($removalMode) {
$acl.Access | Where-Object {$_.IdentityReference.Value -match $appPoolAccount} | Foreach-Object {$acl.RemoveAccessRule($_)} > $null
}
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($objects[$key])
$acl.AddAccessRule($rule)
Set-Acl $path $acl
Get-Acl $path | Format-List
}
}
Write-Output $finText