1
- <#
1
+ <#
2
2
Created by: David Nahodyl, Blue Feather 10/8/2016
3
3
Contact: contact@bluefeathergroup.com
4
- Last Updated: 2/20 /2020
5
- Version: 2.0
4
+ Last Updated: 4/7 /2020
5
+ Version: 2.1
6
6
7
7
Need help? We can set this up to run on your server for you! Send an email to
8
8
contact@bluefeathergroup.com or give a call at (770) 765-6258
9
9
#>
10
10
11
11
<# Change the domain variable to the domain/subdomain for which you would like
12
- an SSL Certificate#>
12
+ an SSL Certificate#>
13
13
$domains = ' fms.mydomain.com' ;
14
14
15
15
<# You can also get a certificate for multiple host name. Uncomment the line below
16
16
and enter your domains in the array matching the example format if you'd like a
17
17
mult-domain certificate. Let's Encrypt will peform separate validation for each
18
18
of the domains, so be sure that your server is reachable at all of them before
19
19
attempting to get a certificate. #>
20
- # $domains = 'fms.mycompany .com,second.mycompany .com';
20
+ # $domains = 'fms.mydomain .com,subdomain.mydomain .com';
21
21
22
22
23
- <# Change the contact email address to your real email address so that Let's Encrypt
24
- can contact you if there are any problems #>
23
+ <# Change the contact email address to your real email address so that Let's Encrypt
24
+ can contact you if there are any problems #>
25
25
$email = ' test@mydomain.com'
26
26
27
27
<# Enter the path to your FileMaker Server directory, ending in a backslash \ #>
28
28
$fmsPath = ' C:\Program Files\FileMaker\FileMaker Server\'
29
29
30
- <# enter the path to le64.exe #>
31
- $le64Path = ' C:\Program Files\FileMaker\le64.exe'
30
+ <# Enter the path to le64.exe #>
31
+ $le64Path = ' C:\Program Files\FileMaker\SSL Renewal\ le64.exe'
32
32
33
33
<# Enable or disable test mode with a boolean 1 or 0. This is set true (1) by default for safety during initial testing but will need
34
34
# to be set to false (0) to get a real certificate.#>
35
35
$testMode = 1
36
36
37
+
38
+
37
39
<#
38
40
You should not need to edit anything below this point.
39
41
---------------------------------------------------------------------------------------------------#>
40
42
43
+ $outPath = $PSScriptRoot + ' \'
44
+ $logFile = $outPath + ' \SSL-Renewal.log'
45
+
46
+ <# Disable any already-running transcript #>
47
+ $ErrorActionPreference = " SilentlyContinue"
48
+ Stop-Transcript | out-null
49
+ $ErrorActionPreference = " Continue" # or "Stop"
50
+
51
+ <# Start the transcript #>
52
+ Start-Transcript - path $logFile
53
+
41
54
if ($domain -eq (' fms.mydomain.com' )){
42
55
Write-Output ' You must enter your real domain! The script will now exit.'
43
56
exit
@@ -107,10 +120,10 @@ Catch
107
120
</system.webServer>
108
121
</configuration>' | Out-File - FilePath $webConfigPath ;
109
122
110
- $keyPath = $fmsPath + ' CStore\serverKey .pem'
111
- $certPath = $fmsPath + ' CStore\crt .pem'
112
- $csrPath = $fmsPath + ' CStore\ domain.csr'
113
- $accountPath = $fmsPath + ' CStore\ account.key'
123
+ $keyPath = $outPath + ' key .pem'
124
+ $certPath = $outPath + ' certificate .pem'
125
+ $csrPath = $outPath + ' domain.csr'
126
+ $accountPath = $outPath + ' account.key'
114
127
115
128
116
129
@@ -129,20 +142,38 @@ if (-not $testMode)
129
142
<# check if the certificate succeeded and exit if there was a failure #>
130
143
if ($LASTEXITCODE -ne 0 )
131
144
{
132
- exit ;
145
+ <# Stop the transcript #>
146
+ Stop-Transcript
147
+ exit
133
148
}
134
149
135
150
136
151
<# cd to FMS directory to run fmsadmin commands #>
137
- cd $fmsPath ' \Database Server\' ;
152
+ cd $fmsPath ' \Database Server\'
138
153
139
- <# Install the certificate #>
140
- <# fmsadmin certificate import requires confirmation in 17, so put a '-y' in here to skip input. This won't do anything in earlier versions. #>
141
- .\fmsadmin certificate import $certPath - y;
142
154
143
- <# Append the intermediary certificate to support older FMS before 15 #>
144
- Add-Content $fmsPath ' CStore\serverCustom.pem' '
145
- -----BEGIN CERTIFICATE-----
155
+ $cstorePath = $fmsPath + ' CStore\'
156
+ $liveKeyPath = $cstorePath + ' serverKey.pem'
157
+ $oldKeyPath = $cstorePath + ' oldKey.pem'
158
+
159
+ Write-Output ' Comparing private key files'
160
+
161
+
162
+ $haveMovedKey = 0
163
+
164
+ if (Compare-Object - ReferenceObject $ (Get-Content $keyPath ) - DifferenceObject $ (Get-Content $liveKeyPath )){
165
+ Write-Output ' Key is different. Moving old key and replacing'
166
+ Move-Item - Path $liveKeyPath - Destination $oldKeyPath
167
+ $haveMovedKey = 1
168
+ } else {
169
+ Write-Output ' Keys are the same'
170
+ }
171
+
172
+
173
+
174
+ Write-Output writing out intermediary
175
+ $intermediaryPath = $outPath + ' intermediary.pem' ;
176
+ $intermediaryContents = ' -----BEGIN CERTIFICATE-----
146
177
MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
147
178
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
148
179
DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
@@ -170,12 +201,48 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
170
201
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
171
202
-----END CERTIFICATE-----'
172
203
204
+ Set-Content - Path $intermediaryPath - Value $intermediaryContents
205
+
206
+
207
+
208
+ Compare-Object $keyPath $liveKeyPath
209
+
210
+ Write-Output ' Attempting to install certificate to FileMaker Server'
211
+
212
+ <# Install the certificate #>
213
+ <# fmsadmin certificate import requires confirmation in 17, so put a '-y' in here to skip input. This won't do anything in earlier versions. #>
214
+ .\fmsadmin certificate import $certPath -- keyfile $keyPath -- intermediateCA $intermediaryPath - y;
215
+
216
+
217
+ <# Check and make sure the install succeeded #>
218
+ if ($LASTEXITCODE -ne 0 )
219
+ {
220
+ <# The certificate install failed #>
221
+ Write-Output ' fmsadmin certificate install command failed.'
222
+
223
+ <# Move the old private key back if there was a problem #>
224
+ if ($haveMovedKey ){
225
+ Write-Output ' Moving old key back to original location'
226
+ Move-Item - Path $oldKeyPath - Destination $liveKeyPath
227
+ }
228
+
229
+ Write-Output ' Exiting Script'
230
+ <# Stop the transcript #>
231
+ Stop-Transcript
232
+ exit ;
233
+ }
234
+
235
+ Write-Output ' FMS certificate import command completed'
236
+
173
237
<# Restart the FMS service #>
174
238
Write-Output ' Automatically Stopping FileMaker Server'
175
239
net stop ' FileMaker Server' ;
176
240
Write-Output ' Automatically Starting FileMaker Server'
177
241
net start ' FileMaker Server' ;
178
242
179
243
244
+ <# Stop the transcript #>
245
+ Stop-Transcript
246
+
180
247
<# All done! Exit. #>
181
- exit ;
248
+ exit ;
0 commit comments