forked from Shadow0ps/SpamassassinAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
133 lines (99 loc) · 5.42 KB
/
install.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
# Check and see if already installed
if((Test-Path -Path "C:\Program Files (x86)\SpamAssassin\" )){
$message = 'Warning'
$question = "A SpamAssassin installation has been detected already. If you continue all files (including settings) will be overwritten.
Are you sure you want to proceed?"
$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes'))
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No'))
$decision = $Host.UI.PromptForChoice($message, $question, $choices, 1)
if ($decision -eq 0) {
# Stop spamd if it exists
Stop-Service spamd -ErrorAction Ignore
# Delete spamd if it exists
$service = Get-WmiObject -Class Win32_Service -Filter "Name='spamd'"
if($service) {
$service.delete()
}
Remove-Item -Recurse -Force "C:\Program Files (x86)\SpamAssassin\"
schtasks.exe /delete /tn "SpamAssassin AutoUpdate" /F
} else {
Exit
}
}
# Download
Invoke-WebRequest http://www.jam-software.com/spamassassin/SpamAssassinForWindows-x86.zip -OutFile C:\Windows\Temp\SpamAssassinForWindows.zip
# Create directory if it doesn't exist
New-Item "C:\Program Files (x86)\SpamAssassin\" -type Directory
# Unzip
$shell = new-object -com shell.application
$zip = $shell.NameSpace(“C:\Windows\Temp\SpamAssassinForWindows.zip”)
foreach($item in $zip.items())
{
$shell.Namespace("C:\Program Files (x86)\SpamAssassin\").copyhere($item)
}
# Downloading srvany-ng
Invoke-WebRequest https://github.com/birkett/srvany-ng/releases/download/v1.0.0.0/srvany-ng_26-03-2015.zip -OutFile C:\Windows\Temp\srvany-ng.zip
# Unzip
Expand-Archive -LiteralPath C:\Windows\Temp\srvany-ng.zip -DestinationPath C:\Windows\Temp\srvany-ng
# Copy to system folder
Copy-Item "C:\Windows\Temp\srvany-ng\x86\srvany-ng.exe" -Destination "C:\Windows\System32\"
#TODO: Get latest version of default configs from the github repo
# Create the service
New-Service -BinaryPathName "C:\Windows\System32\srvany-ng.exe" -Name spamd -DisplayName "SpamAssassin Daemon"
New-Item -Path HKLM:\SYSTEM\CurrentControlSet\services\spamd -Name "Parameters"
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\services\spamd\Parameters -Name "Application" -PropertyType STRING -Value "C:\Program Files (x86)\SpamAssassin\spamd.exe"
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\services\spamd\Parameters -Name "AppDirectory" -PropertyType STRING -Value "C:\Program Files (x86)\SpamAssassin\"
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\services\spamd\Parameters -Name "AppParameters" -PropertyType STRING -Value "-x -l -s spamd.log"
# Create the system task to run the update script every night
schtasks.exe /create /tn "SpamAssassin AutoUpdate" /tr "'C:\Program Files (x86)\SpamAssassin\sa-update.bat'" /sc DAILY /st 02:00 /RU SYSTEM /RL HIGHEST /v1
schtasks.exe /run /tn "SpamAssassin AutoUpdate"
# wait about 30 seconds for the update to complete
Start-Sleep -Seconds 30
# Download the SpamAssassin config file
Invoke-WebRequest https://raw.githubusercontent.com/shubell/SpamassassinAgent/master/contrib/spamassassin/local.cf -OutFile "C:\Program Files (x86)\SpamAssassin\etc\spamassassin\local.cf"
# Start the spamd service
Start-Service spamd
# Now let's download and install Spamassasssin Transport Agent, Ask what version of exchange they are using
$Version = ""
[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 5 ){
Write-Host "Please select the version of Microsoft Exchange Server you are using..."
Write-host "1. 2016 Service Pack 0"
Write-host "2. 2013 Service Pack 1"
Write-host "3. 2010 Service pack 3"
Write-host "4. 2010 Service Pack 2"
Write-host "5. 2016 15.1.2507.6"
[Int]$xMenuChoiceA = read-host "Please enter an option 1 to 5..." }
Switch( $xMenuChoiceA ){
1{$version = "2016SP0"}
2{$version = "2013SP1"}
3{$version = "2010SP3"}
4{$version = "2010SP2"}
5{$version = "15.1.2507.6"}
default{Write-Host "Invalid Selection"}
}
# Create Directory to save to
New-Item "C:\CustomAgents\" -type Directory
# Create Data Directory
New-Item "C:\CustomAgents\SpamassassinAgentData" -type Directory
# Download the proper DLL
Invoke-WebRequest https://raw.githubusercontent.com/shubell/SpamassassinAgent/master/bin/$version/SpamassassinAgent.dll -OutFile "C:\CustomAgents\SpamassassinAgent.dll"
# Download the XML configuration
Invoke-WebRequest https://raw.githubusercontent.com/shubell/SpamassassinAgent/master/etc/SpamassassinConfig.xml -OutFile "C:\CustomAgents\SpamassassinAgentData\SpamassassinConfig.xml"
# Connect to the exchange Server
. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto
# Install the Transport Agent
Install-TransportAgent -Name "SpamAssassin Agent" -AssemblyPath C:\CustomAgents\SpamassassinAgent.dll -TransportAgentFactory SpamassassinAgent.SpamassassinAgentFactory
Enable-TransportAgent "Spamassassin Agent"
#Set-TransportAgent "Spamassassin Agent" -Priority 3
# Install Anti-Spam Functionality
#. 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\Install-AntiSpamAgents.ps1'
# Disable Existing Anti-Spam Functionality
#Set-ContentFilterConfig -Enable $false
#Set-SenderFilterConfig -Enable $false
#Set-SenderIDConfig -Enable $false
#Set-SenderReputationConfig -Enable $false
# Restart
Restart-Service MSExchangeTransport