Update install.ps1

This commit is contained in:
FusionPBX
2017-12-31 01:47:59 -07:00
committed by GitHub
parent 2f13faa427
commit de03dc3932

View File

@@ -1,5 +1,5 @@
# FusionPBX Settings # FusionPBX Settings
$domain_name = "hostname" # hostname, ip_address or a custom value $domain_name = "hostname" # hostname, ip_address or a custom value
$system_username = "admin" # default username admin $system_username = "admin" # default username admin
$system_password = "random" # random or a custom value $system_password = "random" # random or a custom value
$system_branch = "master" # master, stable $system_branch = "master" # master, stable
@@ -14,347 +14,339 @@ $switch_version = "1.6" # *1.6.*
$database_password = "random" # random or a custom value $database_password = "random" # random or a custom value
#$database_backup = $false # true or false #$database_backup = $false # true or false
# Web server # General Settings
$php_version = 7 # PHP version 5 or 7 $cpu = "x64" # x64 or x86
$web_server = "IIS" # nginx or IIS $php_version = 7 # PHP version 5 or 7
$iis_identity = "LocalSystem" # localSystem or NetworkService $web_server = "IIS" # nginx or IIS
$iis_identity = "LocalSystem" # localSystem or NetworkService
# Download file to current folder using default or provided name. Return saved file name # Download file to current folder using default or provided name. Return saved file name
Function Get-File([string]$url, [string]$filename) { Function Get-File([string]$url, [string]$filename) {
#Get filename from path #Get filename from path
if ($filename.Length -eq 0) { if ($filename.Length -eq 0) {
$filename = Split-Path -Path $url -Leaf $filename = Split-Path -Path $url -Leaf
} }
#Download if local copy doesn't exist #Download if local copy doesn't exist
if (-not (Test-Path $filename)) { if (-not (Test-Path $filename)) {
Invoke-WebRequest $url -OutFile $filename Invoke-WebRequest $url -OutFile $filename
} }
return $filename return $filename
} }
# Get page with links, filter, and select latest version using pattern. Return file download URL. # Get page with links, filter, and select latest version using pattern. Return file download URL.
Function Get-Link([string]$url, [string]$pattern) { Function Get-Link([string]$url, [string]$pattern) {
$link = (Invoke-WebRequest $url).Links | Where-Object {$_.href -like $pattern} | Select-Object -Last 1 $link = (Invoke-WebRequest $url).Links | Where-Object {$_.href -like $pattern} | Select-Object -Last 1
Write-Host $link.href -ForegroundColor Gray Write-Host $link.href -ForegroundColor Gray
#Use System.URI to combine url parts #Use System.URI to combine url parts
$uri = New-Object -TypeName System.URI -ArgumentList ([System.URI]$url),($link.href) $uri = New-Object -TypeName System.URI -ArgumentList ([System.URI]$url),($link.href)
return $uri.AbsoluteUri return $uri.AbsoluteUri
}
Function Get-CPU() {
if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
Return "x86"
}
else {
Return "x64"
}
} }
Function Write-Log([string]$message) { Function Write-Log([string]$message) {
Add-Content -Path "install.log" -Value $message Add-Content -Path "install.log" -Value $message
Write-Host $message -ForegroundColor Cyan Write-Host $message -ForegroundColor Cyan
} }
Function New-Password([int32]$length) { Function New-Password([int32]$length) {
([char[]]([char]'A'..[char]'Z') + [char[]]([char]'a'..[char]'z') + 0..9 | Sort-Object {Get-Random})[0..$length] -join '' ([char[]]([char]'A'..[char]'Z') + [char[]]([char]'a'..[char]'z') + 0..9 | Sort-Object {Get-Random})[0..$length] -join ''
} }
Function Get-InstalledApp([string]$name) { Function Get-InstalledApp([string]$name) {
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object DisplayName -like $name | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate,UninstallString | Format-Table AutoSize Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object DisplayName -like $name | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate,UninstallString | Format-Table AutoSize
} }
#Download and install latest version on FreeSWITCH 1.6. #Download and install latest version on FreeSWITCH 1.6.
#Set it to auto start #Set it to auto start
Function Install-FreeSWITCH() { Function Install-FreeSWITCH() {
if (Get-CPU -eq "x86") { if ($cpu -eq "x86") {
$url = "http://files.freeswitch.org/windows/installer/x86/" $url = "http://files.freeswitch.org/windows/installer/x86/"
} }
else { else {
$url = "http://files.freeswitch.org/windows/installer/x64/" $url = "http://files.freeswitch.org/windows/installer/x64/"
} }
$link = Get-Link $url "*${switch_version}*" $link = Get-Link $url "*${switch_version}*"
Write-Host Download FreeSWITCH from $link -ForegroundColor Cyan Write-Host Download FreeSWITCH from $link -ForegroundColor Cyan
$filename = Get-File $link $filename = Get-File $link
Write-Host "Install Freeswitch" -ForegroundColor Cyan Write-Host "Install Freeswitch" -ForegroundColor Cyan
#Remove FreeSWITCH #Remove FreeSWITCH
Start-Process MsiExec.exe "/x {B004A325-1272-47E5-A415-A74E9FC99865} /passive /qb" -Wait Start-Process MsiExec.exe "/x {B004A325-1272-47E5-A415-A74E9FC99865} /passive /qb" -Wait
#Install new version #Install new version
Start-Process msiexec "/i $filename /passive /qb" -Wait Start-Process msiexec "/i $filename /passive /qb" -Wait
#Configure service to auto start #Configure service to auto start
Start-Process sc "config FreeSWITCH start= auto" -Wait -NoNewWindow Start-Process sc "config FreeSWITCH start= auto" -Wait -NoNewWindow
#Start-Service FreeSWITCH #Start-Service FreeSWITCH
#Set permissions to folder "c:\Program Files\FreeSWITCH" for PHP (IIS) #Set permissions to folder "c:\Program Files\FreeSWITCH" for PHP (IIS)
if ($iis_identity -ne "LocalSystem") { if ($iis_identity -ne "LocalSystem") {
Icacls "c:\Program Files\FreeSWITCH" /grant "NetworkService:(OI)(CI)M" Icacls "c:\Program Files\FreeSWITCH" /grant "NetworkService:(OI)(CI)M"
} }
#mod_lua.dll is missing from recent windows builds #mod_lua.dll is missing from recent windows builds
$lua = "C:\Program Files\FreeSWITCH\mod\mod_lua.dll" $lua = "C:\Program Files\FreeSWITCH\mod\mod_lua.dll"
if ( -not (Test-Path $lua) ) { if ( -not (Test-Path $lua) ) {
$cpu = Get-CPU Get-File "https://raw.github.com/sergey-mz/fusionpbx-install.sh/master/windows/resources/$cpu/mod_lua.dll"
Get-File "https://raw.github.com/sergey-mz/fusionpbx-install.sh/master/windows/resources/$cpu/mod_lua.dll" Copy-Item ".\mod_lua.dll" -Destination $lua
Copy-Item ".\mod_lua.dll" -Destination $lua }
}
} }
Function Install-7zip() { Function Install-7zip() {
if (-not (Test-Path "c:\Program Files\7-Zip\7z.exe")) { if (-not (Test-Path "c:\Program Files\7-Zip\7z.exe")) {
Write-Host "Downloading and Installing 7-Zip" -ForegroundColor Cyan Write-Host "Downloading and Installing 7-Zip" -ForegroundColor Cyan
if ($env:PROCESSOR_ARCHITECTURE -eq "x86") { if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
$zip7 = Get-File http://www.7-zip.org/a/7z1604.msi $zip7 = Get-File http://www.7-zip.org/a/7z1604.msi
} }
else { else {
$zip7 = Get-File http://www.7-zip.org/a/7z1604-x64.msi $zip7 = Get-File http://www.7-zip.org/a/7z1604-x64.msi
} }
Start-Process msiexec "/i $zip7 /passive /qb" -Wait Start-Process msiexec "/i $zip7 /passive /qb" -Wait
} }
} }
Function Expand-ZIP([string]$filename) { Function Expand-ZIP([string]$filename) {
#Extract archive #Extract archive
if ($PSVersionTable.PSVersion.Major -ge 5) { if ($PSVersionTable.PSVersion.Major -ge 5) {
Expand-Archive $filename -DestinationPath . Expand-Archive $filename -DestinationPath .
} }
elseif ( [System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") ) { elseif ( [System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") ) {
$path = Get-Location $path = Get-Location
[System.IO.Compression.ZipFile]::ExtractToDirectory("$path\$filename",$path) [System.IO.Compression.ZipFile]::ExtractToDirectory("$path\$filename",$path)
} }
else { else {
#Check if 7zip is installed and install it if needed #Check if 7zip is installed and install it if needed
Install-7zip Install-7zip
#Extract all files #Extract all files
Start-Process "c:\Program Files\7-Zip\7z.exe" "e -y $filename" Start-Process "c:\Program Files\7-Zip\7z.exe" "e -y $filename"
} }
} }
Function Install-PostgresODBC() { Function Install-PostgresODBC() {
$url = "https://ftp.postgresql.org/pub/odbc/versions/msi/" $url = "https://ftp.postgresql.org/pub/odbc/versions/msi/"
$link = Get-Link $url -pattern "*" + (Get-CPU) + "*" $link = Get-Link $url -pattern "*" + ($cpu) + "*"
Write-Host Download ODBC from $link -ForegroundColor Cyan Write-Host Download ODBC from $link -ForegroundColor Cyan
$filename = Get-File $link $filename = Get-File $link
Expand-ZIP $filename Expand-ZIP $filename
Write-Host Install postgresql-odbc Write-Host Install postgresql-odbc
$filename = Get-Item psqlodbc*.exe $filename = Get-Item psqlodbc*.exe
if ($filename) { if ($filename) {
Start-Process $filename -Wait Start-Process $filename -Wait
} }
$filename = Get-Item psqlodbc*.msi $filename = Get-Item psqlodbc*.msi
if ($filename) { if ($filename) {
Start-Process msiexec "/i $filename /passive /qb" -Wait Start-Process msiexec "/i $filename /passive /qb" -Wait
} }
if ((Get-Command Get-OdbcDsn -ErrorAction SilentlyContinue)) { if ((Get-Command Get-OdbcDsn -ErrorAction SilentlyContinue)) {
#Get or create DSN #Get or create DSN
$dsn = Get-OdbcDsn FusionPBX -ErrorAction SilentlyContinue $dsn = Get-OdbcDsn FusionPBX -ErrorAction SilentlyContinue
Remove-OdbcDsn FusionPBX -DsnType System Remove-OdbcDsn FusionPBX -DsnType System
if ($dsn.length -eq 0) { if ($dsn.length -eq 0) {
# Get ODBC Driver name # Get ODBC Driver name
$driver = (Get-OdbcDriver -Name "PostgreSQL Unicode*").Name $driver = (Get-OdbcDriver -Name "PostgreSQL Unicode*").Name
$dsn = Add-OdbcDsn -DsnType System -Name fusionpbx -DriverName $driver -SetPropertyValue "servername=localhost","port=5432","database=fusionpbx","GssAuthUseGSS=0" $dsn = Add-OdbcDsn -DsnType System -Name fusionpbx -DriverName $driver -SetPropertyValue "servername=localhost","port=5432","database=fusionpbx","GssAuthUseGSS=0"
} }
$dsn | Set-OdbcDsn -SetPropertyValue Username=postgres $dsn | Set-OdbcDsn -SetPropertyValue Username=postgres
$dsn | Set-OdbcDsn -SetPropertyValue password=$database_password $dsn | Set-OdbcDsn -SetPropertyValue password=$database_password
} }
else { else {
# Configure DSN with ODBC Administrator # Configure DSN with ODBC Administrator
Write-Host The ODBC Administrator window will open. -ForegroundColor Yellow Write-Host The ODBC Administrator window will open. -ForegroundColor Yellow
if (Get-CPU -eq "x86") { if ($cpu -eq "x86") {
$driver="PostgreSQL Unicode" } $driver="PostgreSQL Unicode"
else { }
$driver="PostgreSQL Unicode(x64)" } else {
#ODBCCONF.EXE /Lv dsn_log.txt CONFIGSYSDSN "$driver" "DSN=fusionpbx|server=localhost|port=5432|database=fusionpbx|Username=postgres|password=$database_password" $driver="PostgreSQL Unicode(x64)"
ODBCCONF.EXE /Lv dsn_log.txt CONFIGSYSDSN "$driver" "DSN=fusionpbx|server=localhost|port=5432|database=fusionpbx|Username=postgres|password=$database_password|GssAuthUseGSS=false" }
} #ODBCCONF.EXE /Lv dsn_log.txt CONFIGSYSDSN "$driver" "DSN=fusionpbx|server=localhost|port=5432|database=fusionpbx|Username=postgres|password=$database_password"
Start-Process odbcad32.exe -Wait ODBCCONF.EXE /Lv dsn_log.txt CONFIGSYSDSN "$driver" "DSN=fusionpbx|server=localhost|port=5432|database=fusionpbx|Username=postgres|password=$database_password|GssAuthUseGSS=false"
}
Start-Process odbcad32.exe -Wait
} }
Function Start-PSQL([string]$command) { Function Start-PSQL([string]$command) {
$location = Get-Location $location = Get-Location
Set-Location "C:\Program Files\PostgreSQL\10.1\bin" Set-Location "C:\Program Files\PostgreSQL\10.1\bin"
.\psql.exe --username=postgres -c "$command" .\psql.exe --username=postgres -c "$command"
Set-Location $location Set-Location $location
} }
Function Test-ODBC([string]$DSN,[string]$username,[string]$password) { Function Test-ODBC([string]$DSN,[string]$username,[string]$password) {
$connection_string = "DSN=$DSN;" $connection_string = "DSN=$DSN;"
if ($username) { if ($username) {
$connection_string += "username=$username;" $connection_string += "username=$username;"
} }
if ($password) { if ($password) {
$connection_string += "password=$password;" $connection_string += "password=$password;"
} }
$conn = New-Object System.Data.Odbc.OdbcConnection $conn = New-Object System.Data.Odbc.OdbcConnection
$conn.ConnectionString = $connection_string $conn.ConnectionString = $connection_string
$conn.open() $conn.open()
$result = ($conn.State -eq "Open") $result = ($conn.State -eq "Open")
if ($result) { if ($result) {
$conn.Close() $conn.Close()
} }
return $result return $result
} }
Function Start-ODBC([string]$query) { Function Start-ODBC([string]$query) {
$conn = New-Object System.Data.Odbc.OdbcConnection $conn = New-Object System.Data.Odbc.OdbcConnection
$conn.ConnectionString = "DSN=fusionpbx;username=fusionpbxadmin;password=despatch4u" $conn.ConnectionString = "DSN=fusionpbx;username=fusionpbxadmin;password=despatch4u"
$conn.open() $conn.open()
if ($conn.State -eq "Open") { if ($conn.State -eq "Open") {
$cmd = New-object System.Data.Odbc.OdbcCommand($query,$conn) $cmd = New-object System.Data.Odbc.OdbcCommand($query,$conn)
$cmd.ExecuteScalar() $cmd.ExecuteScalar()
$conn.Close() $conn.Close()
} }
} }
Start-ODBC "select username from v_users" Start-ODBC "select username from v_users"
Function Install-PostgreSQL() { Function Install-PostgreSQL() {
if (Get-InstalledApp "PostgreSQL*") { if (Get-InstalledApp "PostgreSQL*") {
Write-Host PostgreSQL is already installed Write-Host PostgreSQL is already installed
return return
} }
if ($env:PROCESSOR_ARCHITECTURE -eq "x86") { if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
$url = "https://get.enterprisedb.com/postgresql/postgresql-10.1-3-windows.exe" $url = "https://get.enterprisedb.com/postgresql/postgresql-10.1-3-windows.exe"
} }
else { else {
$url = "https://get.enterprisedb.com/postgresql/postgresql-10.1-3-windows-x64.exe" $url = "https://get.enterprisedb.com/postgresql/postgresql-10.1-3-windows-x64.exe"
} }
Write-Host Download PostgreSQL from $url -ForegroundColor Cyan Write-Host Download PostgreSQL from $url -ForegroundColor Cyan
$filename = Get-File $url $filename = Get-File $url
Write-Host Install Postgresql -ForegroundColor Cyan Write-Host Install Postgresql -ForegroundColor Cyan
Start-Process $filename "--mode unattended --superpassword $database_password" -Wait Start-Process $filename "--mode unattended --superpassword $database_password" -Wait
#Get-Service postgre* #Get-Service postgre*
Write-Host "Create the database and users" -ForegroundColor Cyan Write-Host "Create the database and users" -ForegroundColor Cyan
Start-PSQL "CREATE DATABASE fusionpbx;"; Start-PSQL "CREATE DATABASE fusionpbx;";
Start-PSQL "CREATE DATABASE freeswitch;"; Start-PSQL "CREATE DATABASE freeswitch;";
Start-PSQL "CREATE ROLE fusionpbx WITH SUPERUSER LOGIN PASSWORD '$database_password';" Start-PSQL "CREATE ROLE fusionpbx WITH SUPERUSER LOGIN PASSWORD '$database_password';"
Start-PSQL "CREATE ROLE freeswitch WITH SUPERUSER LOGIN PASSWORD '$database_password';" Start-PSQL "CREATE ROLE freeswitch WITH SUPERUSER LOGIN PASSWORD '$database_password';"
Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE fusionpbx to fusionpbx;" Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE fusionpbx to fusionpbx;"
Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE freeswitch to fusionpbx;" Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE freeswitch to fusionpbx;"
Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE freeswitch to freeswitch;" Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE freeswitch to freeswitch;"
} }
Function Install-Git(){ Function Install-Git(){
if ($env:PROCESSOR_ARCHITECTURE -eq "x86") { if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
Ω $url = "https://github.com/git-for-windows/git/releases/download/v2.15.1.windows.2/Git-2.15.1.2-32-bit.exe" $url = "https://github.com/git-for-windows/git/releases/download/v2.15.1.windows.2/Git-2.15.1.2-32-bit.exe"
} }
else { else {
$url = "https://github.com/git-for-windows/git/releases/download/v2.15.1.windows.2/Git-2.15.1.2-64-bit.exe" $url = "https://github.com/git-for-windows/git/releases/download/v2.15.1.windows.2/Git-2.15.1.2-64-bit.exe"
} }
Write-Host Download Git from $url -ForegroundColor Cyan Write-Host Download Git from $url -ForegroundColor Cyan
$filename = Get-File $url $filename = Get-File $url
Write-Host Install git -ForegroundColor Cyan Write-Host Install git -ForegroundColor Cyan
Start-Process $filename /quiet -Wait Start-Process $filename /quiet -Wait
Remove-Item $filename Remove-Item $filename
} }
Function Install-FusionPBX() { Function Install-FusionPBX() {
#Set directory #Set directory
if (-not (Test-Path $system_directory)) { if (-not (Test-Path $system_directory)) {
New-Item $system_directory -ItemType Directory New-Item $system_directory -ItemType Directory
} }
<# #Clean default files <# #Clean default files
if (Test-Path "$system_directory\iisstart.htm") { if (Test-Path "$system_directory\iisstart.htm") {
Get-ChildItem "$system_directory\*" -Recurse | Remove-Item -Force Get-ChildItem "$system_directory\*" -Recurse | Remove-Item -Force
} }
#> #>
#Clone FusionPBX GIT from Master or 4.2 #Clone FusionPBX GIT from Master or 4.2
if ($system_branch -eq "stable") { $branch = "4.2" } if ($system_branch -eq "stable") { $branch = "4.2" }
else { $branch = ""} else { $branch = ""}
Start-Process "C:\Program Files\Git\bin\git.exe" "clone $branch https://github.com/fusionpbx/fusionpbx.git $system_directory" -Wait Start-Process "C:\Program Files\Git\bin\git.exe" "clone $branch https://github.com/fusionpbx/fusionpbx.git $system_directory" -Wait
#Grant permissions to FusionPBX folder #Grant permissions to FusionPBX folder
if ($iis_identity -ne "LocalSystem") { if ($iis_identity -ne "LocalSystem") {
Icacls $system_directory /grant "${iis_identity}:(OI)(CI)M" Icacls $system_directory /grant "${iis_identity}:(OI)(CI)M"
} }
#Copy configuration #Copy configuration
Move-Item -Path "c:\Program Files\FreeSWITCH\conf" -Destination "c:\Program Files\FreeSWITCH\conf-orig" Move-Item -Path "c:\Program Files\FreeSWITCH\conf" -Destination "c:\Program Files\FreeSWITCH\conf-orig"
Copy-Item "$system_directory\resources\templates\conf" "c:\Program Files\FreeSWITCH" -recurse Copy-Item "$system_directory\resources\templates\conf" "c:\Program Files\FreeSWITCH" -recurse
#Update xml_cdr url, user and password
$filename = "C:\Program Files\FreeSWITCH\conf\autoload_configs\xml_cdr.conf.xml"
(Get-Content $filename) -replace "{v_http_protocol}","http" `
-replace "{domain_name}",$domain_name `
-replace "{v_project_path}","" `
-replace "{v_user}:{v_pass}",((New-Password 8) + ":" + (New-Password 8)) | Out-File $filename
#Update xml_cdr url, user and password
$filename = "C:\Program Files\FreeSWITCH\conf\autoload_configs\xml_cdr.conf.xml"
(Get-Content $filename) -replace "{v_http_protocol}","http" `
-replace "{domain_name}",$domain_name `
-replace "{v_project_path}","" `
-replace "{v_user}:{v_pass}",((New-Password 8) + ":" + (New-Password 8)) | Out-File $filename
} }
Function Install-IIS([string]$path) { Function Install-IIS([string]$path) {
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$iis = new-object Microsoft.Web.Administration.ServerManager $iis = new-object Microsoft.Web.Administration.ServerManager
#Create or set application pool #Create or set application pool
if (-not ($iis.ApplicationPools.Item("PHP"))) { if (-not ($iis.ApplicationPools.Item("PHP"))) {
$pool = $iis.ApplicationPools.Add("PHP") $pool = $iis.ApplicationPools.Add("PHP")
} }
$pool = $iis.ApplicationPools.Item("PHP") $pool = $iis.ApplicationPools.Item("PHP")
$pool.ProcessModel.IdentityType = "NetworkService" $pool.ProcessModel.IdentityType = "NetworkService"
$pool.ProcessModel.IdleTimeout = "00:30:00" $pool.ProcessModel.IdleTimeout = "00:30:00"
#Grant permissions to path #Grant permissions to path
if ($iis_identity -ne "LocalSystem") { if ($iis_identity -ne "LocalSystem") {
Icacls $path /grant "${iis_identity}:(OI)(CI)M" Icacls $path /grant "${iis_identity}:(OI)(CI)M"
} }
$site= $iis.Sites | Where-Object Bindings -Like "*:80:*" $site= $iis.Sites | Where-Object Bindings -Like "*:80:*"
#Get site #Get site
if ($site) { if ($site) {
$site.Name = "FusionPBX" $site.Name = "FusionPBX"
} }
elseif ($iis.sites.Item("FusionPBX")) { elseif ($iis.sites.Item("FusionPBX")) {
$site = $iis.Sites.Item("FusionPBX") $site = $iis.Sites.Item("FusionPBX")
} }
else { else {
$site = $iis.Sites.Add("FusionPBX",$path,80) $site = $iis.Sites.Add("FusionPBX",$path,80)
} }
#$site.Bindings | Format-Table protocol,EndPoint,Host,SslFlags -AutoSize #$site.Bindings | Format-Table protocol,EndPoint,Host,SslFlags -AutoSize
#$cert = (Get-ChildItem Path cert:\LocalMachine\My | Sort-Object NotAfter | Select-Object -Last 1).Thumbprint #$cert = (Get-ChildItem Path cert:\LocalMachine\My | Sort-Object NotAfter | Select-Object -Last 1).Thumbprint
#netsh http delete sslcert ipport=0.0.0.0:443 #netsh http delete sslcert ipport=0.0.0.0:443
#netsh http add sslcert ipport=0.0.0.0:443 certhash=$cert "appid={4dc3e181-e14b-4a21-b022-59fc669b0914}" #netsh http add sslcert ipport=0.0.0.0:443 certhash=$cert "appid={4dc3e181-e14b-4a21-b022-59fc669b0914}"
#netsh http show sslcert #netsh http show sslcert
#Set anonimous authentication to application pool identity #Set anonimous authentication to application pool identity
$config = $iis.GetApplicationHostConfiguration() $config = $iis.GetApplicationHostConfiguration()
$auth = $config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "FusionPBX/") $auth = $config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "FusionPBX/")
$auth.SetAttributeValue("userName","") $auth.SetAttributeValue("userName","")
#Set application pool #Set application pool
$app = $site.Applications | Where-Object -Property Path -eq '/' $app = $site.Applications | Where-Object -Property Path -eq '/'
$app.ApplicationPoolName = $pool.Name $app.ApplicationPoolName = $pool.Name
#Set physical path #Set physical path
$vd = $app.VirtualDirectories | Where-Object -Property Path -eq '/' $vd = $app.VirtualDirectories | Where-Object -Property Path -eq '/'
$vd.PhysicalPath = $path $vd.PhysicalPath = $path
#Save #Save
$iis.CommitChanges() $iis.CommitChanges()
} }
Function Start-WebPlatform() { Function Start-WebPlatform() {
if (-not (Test-Path "${env:ProgramFiles}\Microsoft\Web Platform Installer\WebPlatformInstaller.exe")) { if (-not (Test-Path "${env:ProgramFiles}\Microsoft\Web Platform Installer\WebPlatformInstaller.exe")) {
$filename = Get-File http://download.microsoft.com/download/F/4/2/F42AB12D-C935-4E65-9D98-4E56F9ACBC8E/wpilauncher.exe $filename = Get-File http://download.microsoft.com/download/F/4/2/F42AB12D-C935-4E65-9D98-4E56F9ACBC8E/wpilauncher.exe
Start-Process $filename -Wait Start-Process $filename -Wait
} }
else { else {
Start-Process "C:\Program Files\Microsoft\Web Platform Installer\WebPlatformInstaller.exe" -Wait Start-Process "C:\Program Files\Microsoft\Web Platform Installer\WebPlatformInstaller.exe" -Wait
} }
} }
Function Install-Nginx() { Function Install-Nginx() {
Write-Host Going to install NGINX Write-Host Going to install NGINX
$filename = Get-File http://nginx.org/download/nginx-1.12.1.zip $filename = Get-File http://nginx.org/download/nginx-1.12.1.zip
. "C:\Program Files\7-Zip\7z.exe" "e $filename -oc:\Nginx" . "C:\Program Files\7-Zip\7z.exe" "e $filename -oc:\Nginx"
# needed for php7.0 # needed for php7.0
$filename = Get-File https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe $filename = Get-File https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe
@@ -362,15 +354,14 @@ Function Install-Nginx() {
Write-Host Going to install PHP 7.0 Write-Host Going to install PHP 7.0
Get-File http://windows.php.net/downloads/releases/php-7.0.1-nts-Win32-VC14-x64.zip -OutFile php-7.0.1-nts-Win32-VC14-x64.zip Get-File http://windows.php.net/downloads/releases/php-7.0.1-nts-Win32-VC14-x64.zip -OutFile php-7.0.1-nts-Win32-VC14-x64.zip
$url = "http://windows.php.net/downloads/releases" $url = "http://windows.php.net/downloads/releases"
#php-7.0.1-nts-Win32-VC14-x64.zip #php-7.0.1-nts-Win32-VC14-x64.zip
$link = Get-Link $url "*php-7.0*x64*" $link = Get-Link $url "*php-7.0*x64*"
Write-Host Download PHP from $link -ForegroundColor Cyan Write-Host Download PHP from $link -ForegroundColor Cyan
$filename = Get-File $link $filename = Get-File $link
Start-Process "C:\Program Files\7-Zip\7z.exe" "e $filename" -Wait Start-Process "C:\Program Files\7-Zip\7z.exe" "e $filename" -Wait
Set-Location "C:/nginx"
Set-Location "C:/nginx"
} }
#[System.Environment]::OSVersion.Version.Major #[System.Environment]::OSVersion.Version.Major
@@ -386,33 +377,33 @@ Write-Host "This will install/update and configure FusionPBX, FreeSWITCH, Postgr
# Create folder and make it current # Create folder and make it current
if (-not (Test-Path "$env:PUBLIC\Downloads\FusionPBX")) { if (-not (Test-Path "$env:PUBLIC\Downloads\FusionPBX")) {
mkdir "$env:PUBLIC\Downloads\FusionPBX" mkdir "$env:PUBLIC\Downloads\FusionPBX"
} }
Set-Location "$env:PUBLIC\Downloads\FusionPBX" Set-Location "$env:PUBLIC\Downloads\FusionPBX"
#Required for FreeSWITCH #Required for FreeSWITCH
if ( ([System.Environment]::OSVersion.Version.Build -lt 9600) -and -not (Get-InstalledApp "FreeSWITCH*") -and -not (Get-HotFix -id KB2999226)) { if ( ([System.Environment]::OSVersion.Version.Build -lt 9600) -and -not (Get-InstalledApp "FreeSWITCH*") -and -not (Get-HotFix -id KB2999226)) {
Write-Host Install update KB2999226 Write-Host Install update KB2999226
Return Return
} }
#System Password #System Password
if ($system_password -eq 'random') { if ($system_password -eq 'random') {
$system_password = New-Password 20 $system_password = New-Password 20
} }
elseif ($system_password -eq '') { elseif ($system_password -eq '') {
$system_password = Read-Host -Prompt "Enter system password" $system_password = Read-Host -Prompt "Enter system password"
} }
#Database Password #Database Password
if ($env:PGPASSWORD) { if ($env:PGPASSWORD) {
$database_password = $env:PGPASSWORD $database_password = $env:PGPASSWORD
} }
if ($database_password -eq 'random') { if ($database_password -eq 'random') {
$database_password = New-Password 20 $database_password = New-Password 20
} }
elseif ($database_password -eq '') { elseif ($database_password -eq '') {
$database_password = Read-Host -Prompt "Enter database superuser (postgres) password" $database_password = Read-Host -Prompt "Enter database superuser (postgres) password"
} }
#Set DB password #Set DB password
$env:PGPASSWORD = "$database_password" $env:PGPASSWORD = "$database_password"
@@ -420,16 +411,16 @@ $env:PGPASSWORD = "$database_password"
#Set the domain name #Set the domain name
$cert = Get-ChildItem Path cert:\LocalMachine\My | Where-Object -Property Subject -Like "CN=${env:COMPUTERNAME}*" | Sort-Object NotAfter | Select-Object -Last 1 $cert = Get-ChildItem Path cert:\LocalMachine\My | Where-Object -Property Subject -Like "CN=${env:COMPUTERNAME}*" | Sort-Object NotAfter | Select-Object -Last 1
if ( $cert -and ($domain_name -eq "hostname") ) { if ( $cert -and ($domain_name -eq "hostname") ) {
$domain_name = $cert.Subject.Substring(3) $domain_name = $cert.Subject.Substring(3)
} }
elseif ($domain_name -eq "hostname") { elseif ($domain_name -eq "hostname") {
$domain_name = $env:COMPUTERNAME $domain_name = $env:COMPUTERNAME
#$dns = [System.Net.Dns]::GetHostByName(($env:computerName)) #$dns = [System.Net.Dns]::GetHostByName(($env:computerName))
#$domain_name = $dns.HostName #$domain_name = $dns.HostName
#$dns.addresslist.IPAddressToString #$dns.addresslist.IPAddressToString
} }
else { else {
$domain_name = [System.Net.Dns]::GetHostByName(($env:computerName)).AddressList.IPAddressToString $domain_name = [System.Net.Dns]::GetHostByName(($env:computerName)).AddressList.IPAddressToString
} }
Install-PostgreSQL Install-PostgreSQL
@@ -441,21 +432,21 @@ Install-Git
Install-FusionPBX Install-FusionPBX
if ($web_server -eq "IIS") { if ($web_server -eq "IIS") {
#Run IIS platform installer #Run IIS platform installer
Write-Host "Install PHP 7.1, PHP Manager for IIS and URL Rewrite using Web Platform Installer" -ForegroundColor Yellow Write-Host "Install PHP 7.1, PHP Manager for IIS and URL Rewrite using Web Platform Installer" -ForegroundColor Yellow
Start-WebPlatform Start-WebPlatform
#Run IIS manager and create FusionPBX app #Run IIS manager and create FusionPBX app
Write-Host "Create web site in IIS" -ForegroundColor Yellow Write-Host "Create web site in IIS" -ForegroundColor Yellow
Write-Host "Enable extensions php_pgsql and php_pdo_pgsql" in IIS -ForegroundColor Yellow Write-Host "Enable extensions php_pgsql and php_pdo_pgsql" in IIS -ForegroundColor Yellow
Write-Host "Use URL Rewrite to import rules from .htaccess file" -ForegroundColor Yellow Write-Host "Use URL Rewrite to import rules from .htaccess file" -ForegroundColor Yellow
Start-Process "${env:SystemRoot}\system32\inetsrv\InetMgr.exe" Start-Process "${env:SystemRoot}\system32\inetsrv\InetMgr.exe"
Install-IIS -path $system_directory -port 80 Install-IIS -path $system_directory -port 80
iisreset iisreset
#Remove current configuration #Remove current configuration
#Remove-Item c:\inetpub\FusionPBX\resources\config.php #Remove-Item c:\inetpub\FusionPBX\resources\config.php
} }
#Update schema #Update schema