Skip to content

Commit

Permalink
Some updates
Browse files Browse the repository at this point in the history
Change joshcooper powershell module to puppetlabs powershell module
Remove warning when set bindings
Add flag for choosing if we want to manage bindings without managing
sites
  • Loading branch information
ninja-2 committed Sep 3, 2014
1 parent d274d65 commit 4e20116
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ license 'MIT'
summary 'Module that will manage IIS for windows server 2008 and above. It will help maintain application pools, sites and virtual applications'
project_page 'https://github.com/opentable/puppet-iis'
dependency 'puppetlabs/stdlib', '>=3.0.0'
dependency 'joshcooper/powershell', '>=0.0.6'
dependency 'puppetlabs/powershell', '>=1.0.2'
26 changes: 17 additions & 9 deletions manifests/manage_binding.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
define iis::manage_binding($site_name, $protocol, $port, $host_header = '', $ip_address = '*', $certificate_thumbprint = '', $ensure = 'present') {
define iis::manage_binding($site_name, $protocol, $port, $host_header = '', $ip_address = '*', $certificate_thumbprint = '', $ensure = 'present', $only_manage_binding = false) {
include 'iis::param::powershell'

if ! ($protocol in [ 'http', 'https', 'net.tcp', 'net.pipe', 'netmsmq', 'msmq.formatname' ]) {
Expand All @@ -9,20 +9,28 @@
validate_string($site_name)
validate_re($site_name,['^(.)+$'], 'site_name must not be empty')
validate_re($ensure, '^(present|installed|absent|purged)$', 'ensure must be one of \'present\', \'installed\', \'absent\', \'purged\'')

validate_bool($only_manage_binding)
if ! ($ip_address == '*') {
validate_re($ip_address, ['^([0-9]){1,3}\.([0-9]){1,3}\.([0-9]){1,3}\.([0-9]){1,3}$'], "\"${ip_address}\" is not a valid ip address")
}

if ($ensure in ['present','installed']) {
exec { "CreateBinding-${title}":
path => "${iis::param::powershell::path};${::path}",
command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-WebBinding -Name \\\"${site_name}\\\" -Port ${port} -Protocol \\\"${protocol}\\\" -HostHeader \\\"${host_header}\\\" -IPAddress \\\"${ip_address}\\\"\"",
onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if (Get-WebBinding -Name \\\"${site_name}\\\" -Port ${port} -Protocol \\\"${protocol}\\\" -HostHeader \\\"${host_header}\\\" -IPAddress \\\"${ip_address}\\\" | Where-Object {\$_.bindingInformation -eq \\\"${ip_address}:${port}:${host_header}\\\"}) { exit 1 } else { exit 0 }\"",
logoutput => true,
require => Iis::Manage_site[$site_name],
if($only_manage_binding){
exec { "CreateBinding-${title}":
path => "${iis::param::powershell::path};${::path}",
command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-WebBinding -Name \\\"${site_name}\\\" -Port ${port} -Protocol \\\"${protocol}\\\" -HostHeader \\\"${host_header}\\\" -IPAddress \\\"${ip_address}\\\"\"",
onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if (Get-WebBinding -Name \\\"${site_name}\\\" -Port ${port} -Protocol \\\"${protocol}\\\" -HostHeader \\\"${host_header}\\\" -IPAddress \\\"${ip_address}\\\" | Where-Object {\$_.bindingInformation -eq \\\"${ip_address}:${port}:${host_header}\\\"}) { exit 1 } else { exit 0 }\"",
logoutput => true,
}
}else{
exec { "CreateBinding-${title}":
path => "${iis::param::powershell::path};${::path}",
command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-WebBinding -Name \\\"${site_name}\\\" -Port ${port} -Protocol \\\"${protocol}\\\" -HostHeader \\\"${host_header}\\\" -IPAddress \\\"${ip_address}\\\"\"",
onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if (Get-WebBinding -Name \\\"${site_name}\\\" -Port ${port} -Protocol \\\"${protocol}\\\" -HostHeader \\\"${host_header}\\\" -IPAddress \\\"${ip_address}\\\" | Where-Object {\$_.bindingInformation -eq \\\"${ip_address}:${port}:${host_header}\\\"}) { exit 1 } else { exit 0 }\"",
logoutput => true,
require => Iis::Manage_site[$site_name],
}
}

if ($protocol == 'https') {
validate_re($certificate_thumbprint, ['^(.)+$'], 'certificate_thumbprint required for https bindings')
if ($ip_address == '0.0.0.0') {
Expand Down
16 changes: 8 additions & 8 deletions templates/create-certificate-binding.ps1.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Import-Module WebAdministration

$site = Get-Website | Where-Object { $_.Name -eq "<%= site_name %>" }
$site = Get-Website | Where-Object { $_.Name -eq "<%= @site_name %>" }
$certsAttachedToSite = Get-ChildItem IIS:\SSLBindings | ? { $site | Select-Object { $_ -contains $_.Sites.Value }} | % { $_.Thumbprint }
$certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= certificate_thumbprint %>" }
$certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= @certificate_thumbprint %>" }

if((Test-Path IIS:\SslBindings\<%= ip_address %>!<%= port %>) -eq $false) {
if((Test-Path IIS:\SslBindings\<%= @ip_address %>!<%= @port %>) -eq $false) {
push-location IIS:\SslBindings
Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | New-Item <%= ip_address %>!<%= port %>
Get-Item Cert:\LocalMachine\My\<%= @certificate_thumbprint %> | New-Item <%= @ip_address %>!<%= @port %>
}
elseif (((Test-Path IIS:\SslBindings\<%= ip_address %>!<%= port %>) -eq $true) -and (($certificate -ne $null) -or ($certificate.Thumbprint -ne "<%= certificate_thumbprint %>"))) {
elseif (((Test-Path IIS:\SslBindings\<%= @ip_address %>!<%= @port %>) -eq $true) -and (($certificate -ne $null) -or ($certificate.Thumbprint -ne "<%= @certificate_thumbprint %>"))) {
push-location IIS:\SslBindings
Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | Set-Item <%= ip_address %>!<%= port %>
Get-Item Cert:\LocalMachine\My\<%= @certificate_thumbprint %> | Set-Item <%= @ip_address %>!<%= @port %>
foreach ($cert in $certificates) {
if(($cert -ne $null) -and ($cert.Thumbprint -ne "<%= certificate_thumbprint %>")) {
Get-Item Cert:\LocalMachine\My\$cert.Thumbprint | Remove-Item <%= ip_address %>!<%= port %>
if(($cert -ne $null) -and ($cert.Thumbprint -ne "<%= @certificate_thumbprint %>")) {
Get-Item Cert:\LocalMachine\My\$cert.Thumbprint | Remove-Item <%= @ip_address %>!<%= @port %>
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions templates/inspect-certificate-binding.ps1.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Import-Module WebAdministration

if((Test-Path IIS:\SslBindings\<%= ip_address %>!<%= port %>) -eq $false) {
$site = Get-Website | Where-Object { $_.Name -eq "<%= site_name %>" }
if((Test-Path IIS:\SslBindings\<%= @ip_address %>!<%= @port %>) -eq $false) {
$site = Get-Website | Where-Object { $_.Name -eq "<%= @site_name %>" }
$certsAttachedToSite = Get-ChildItem IIS:\SSLBindings | ? { $site | Select-Object { $_ -contains $_.Sites.Value }} | % { $_.Thumbprint }
$certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= certificate_thumbprint %>" }
$certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= @certificate_thumbprint %>" }
if ($certificate -ne $null ){
exit 1
}
Expand Down

0 comments on commit 4e20116

Please sign in to comment.