Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

Code Block
### Return the result of the request
Function BasicHandlerCurl {
    Param($MyResult)
    $FiltredMyResult = ""
    foreach ($line in $MyResult) {
        if ($line.StartsWith("<")) {
            $FiltredMyResult += $line
        } elseif ($line.StartsWith(" ")) {
            $FiltredMyResult += $line
        }
    }
    [xml]$XmlResult = $FiltredMyResult
    if($XmlResult.root.status.http_code.contains("200")) {
        return 1
    } else {
        return "Error Code:<"+$XmlResult.root.status.app_status.app_status_entry.code+"> Param:<"+$XmlResult.root.status.app_status.app_status_entry.params+">"
    }
}
  
     
Code Block
 ### Return the result of the last action
function LookCompletionStatus {
    Param($MyNodeUrl, $MyPs)
    $url = "https://$MyNodeUrl/rest/sbaactionstatus"
    $timer = 0
    while($timer -lt 3600) {
       
Code Block
 
$Result = Invoke-RestMethod -Uri $url -Method GET -WebSession $MyPs
        if ((BasicHandler $Result) -ne 1) { return 0}
        [xml]$FinalResult= $Result.Substring(5)
        if ($FinalResult.root.sbaactionstatus.rt_Success -eq 1) {
            if ($FinalResult.root.sbaactionstatus.rt_PercentComplete -eq 100) { return 1 }
        } else {
            return $FinalResult.root.sbaactionstatus.rt_StatusText
        }
        sleep 10
        $timer += 10
        write-host "- "$FinalResult.root.sbaactionstatus.rt_PercentComplete"% "$FinalResult.root.sbaactionstatus.rt_StatusText
    }
    return "Timout out"
}
###################################
#### Main Code
###################################
  
$ActualStep = 0

Code Block
### 1. Log in with Powershell
$ActualStep = "1. Log in with Powershell"

### Allow self Sign Cert
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
Code Block



 public class IDontCarePolicy : ICertificatePolicy {
        public IDontCarePolicy() {}
        public bool CheckValidationResult(
            ServicePoint sPoint, X509Certificate cert,
            WebRequest wRequest, int certProb) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy
                                              
### Login
$BodyValue = "Username=restuser&Password=restpass"
  
$url = "https://$NodeUrl/rest/login"
$Result = Invoke-RestMethod -Uri $url -Method Post -Body $BodyValue -SessionVariable ps

### 2. Log in with Curl
$ActualStep = "2. Log in with Curl"

$login = ./curl.exe -k --data "Username=$NodeLogin&Password=$NodePassword" -i -v https://$NodeUrl/rest/login
$PHPSESSID = 0
foreach ($line in $login) {
    if ($line.contains("PHPSESSID=")) {
        $correctline = $line.split(";")
        $splitedline = $correctline.split("=")
        $PHPSESSID = $splitedline[1]
    }
}
Code Block
### 3. Update SbcComms
$ActualStep = "3. Update SbcComms"

$Result = ./curl.exe --cookie PHPSESSID=$PHPSESSID -k -i https://$NodeUrl/rest/sbaconfig?action=sbaupgrade -F sbaInstallFilename=@$SbcCommsFilePath
if ((BasicHandlerCurl $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandlerCurl $Result)
    return 0
}


### 4. Install the Latest Lync SBA Cumulative Update (CU)
$ActualStep = "4. Install the Latest Lync SBA Cumulative Update (CU)"

$Result = ./curl.exe --cookie PHPSESSID=$PHPSESSID -k -i https://$NodeUrl/rest/sbaconfig?action=sbaupgrade -F sbaInstallFilename=@$LyncCU 
if ((BasicHandlerCurl $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
Code Block

# We need to log again since we may timeout
### Login
$BodyValue = "Username=restuser&Password=restpass"  
$url = "https://$NodeUrl/rest/login"
$Result = Invoke-RestMethod -Uri $url -Method Post -Body $BodyValue -SessionVariable ps

# Check for the completion of the CU install
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandlerCurl $Result)
    return 0
}
# We need to log again since we may timeout
Code Block
### Log in with Curl
$login = ./curl.exe -k --data "Username=$NodeLogin&Password=$NodePassword" -i -v https://$NodeUrl/rest/login
$PHPSESSID = 0
foreach ($line in $login) {
    if ($line.contains("PHPSESSID=")) {
        $correctline = $line.split(";")
        $splitedline = $correctline.split("=")
        $PHPSESSID = $splitedline[1]
    }
}
Code Block


### 5. Install the Latest Sonus Windows Update pack
$ActualStep = "5. Install the Latest Sonus Windows Update pack"

$Result = ./curl.exe --cookie PHPSESSID=$PHPSESSID -k -i https://$NodeUrl/rest/sbaconfig?action=sbaupgrade -F sbaInstallFilename=@$WindowsUpdate 
if ((BasicHandlerCurl $Result) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandler $Result)
    return 0
}
if ((LookCompletionStatus $NodeUrl $ps) -ne 1) {
    write-host $ActualStep" Failed: "(BasicHandlerCurl $Result)
    return 0
}

while (1) {
    $url = "https://$NodeUrl/rest/sbaconfig"
    $ResultGeneral = Invoke-RestMethod -Uri $url -Method GET  -WebSession $ps

    if ((BasicHandler $ResultGeneral) -ne 1) {
        write-host $ActualStep" Failed: "(BasicHandler $ResultGeneral)
        return 0
    }

...