Upload files to "/"
This commit is contained in:
161
enterPairingCode.ps1
Normal file
161
enterPairingCode.ps1
Normal file
@@ -0,0 +1,161 @@
|
||||
param (
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$phNumber,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$instanceApiKey,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$instanceID,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]$debugtrue,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$instanceName
|
||||
)
|
||||
$phNumber = Read-Host ""
|
||||
Read-Host
|
||||
|
||||
$global:LDPlayerPath ="C:\Ldplayer\LDplayer9"
|
||||
$global:instanceNameglobal=$instanceName
|
||||
function logger($logMessage) {
|
||||
[int]$number = (get-content -path "$global:LDPlayerPath\index_count.txt")
|
||||
if($number -gt 21){ $number=0}
|
||||
$instanceList = Get-Content -Path "$global:LDPlayerPath\instanceList.txt"
|
||||
#$instanceNumber = $instanceList[$number]
|
||||
#$instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${instanceNumber}.config)
|
||||
#$convertedData = $instanceData | ConvertFrom-Json
|
||||
foreach ( $inst in $instanceList) {
|
||||
$instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config)
|
||||
$convertedData = $instanceData | ConvertFrom-Json
|
||||
$name = $convertedData."statusSettings.playerName"
|
||||
if ($global:instanceNameglobal -eq $name){
|
||||
$count = $inst
|
||||
break
|
||||
}
|
||||
}
|
||||
#if(-not $instanceName){$name = $convertedData."statusSettings.playerName"}
|
||||
#$count = $number+1
|
||||
|
||||
$scriptName = Split-Path -Leaf $PSCommandPath
|
||||
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
|
||||
$timestampedLogMessage = $timestamp + " ${global:instanceNameglobal} -instanceID: ${count} -${scriptName} -PID: ${PID}-:" + $logMessage
|
||||
#$timestampedLogMessage
|
||||
$logFilePath = "$global:LDPlayerPath\LDAutoLog.txt"
|
||||
$fs = New-Object System.IO.FileStream($logFilePath, [System.IO.FileMode]::Append, [System.IO.FileAccess]::Write, [System.IO.FileShare]::Read)
|
||||
$sw = New-Object System.IO.StreamWriter($fs)
|
||||
try {
|
||||
$sw.WriteLine($timestampedLogMessage)
|
||||
} finally {
|
||||
$sw.Close()
|
||||
$fs.Close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (-not $instanceApiKey) {
|
||||
$instanceApiKey = "4BC247F718F3-459C-9AFF-5D0A47306736"
|
||||
logger "this is the apikey $instanceApiKey"
|
||||
}
|
||||
|
||||
if ($instanceName -eq "") {
|
||||
logger "here"
|
||||
$instanceName = "PY-Expediente"
|
||||
logger "this is the instance Name: $instanceName"
|
||||
} else {logger "instance Name was provided: $instanceName"}
|
||||
|
||||
$pairingCode = $null
|
||||
$cnt = 0
|
||||
|
||||
while ($true) {
|
||||
if ($cnt -gt 3) {
|
||||
logger "Breaking loop due to too many retries: $cnt"
|
||||
break
|
||||
}
|
||||
|
||||
$invokeParamsCheck = @{
|
||||
Uri = "https://evo2.congregatio.info/instance/connectionState/${instanceName}"
|
||||
Method = 'Get'
|
||||
Headers = @{
|
||||
'apikey' = $instanceApiKey
|
||||
}
|
||||
}
|
||||
<# $referer = "https://evo2.congregatio.info/manager/instance/${instanceID}/dashboard"
|
||||
if($phNumber){
|
||||
$invokeParams = @{
|
||||
Uri = "https://evo2.congregatio.info/instance/connect/${instanceName}?number=$phNumber"
|
||||
Method = 'Get'
|
||||
Headers = @{
|
||||
'Accept' = 'application/json, text/plain, */*'
|
||||
'Accept-Encoding' = 'gzip, deflate, br, zstd'
|
||||
'Accept-Language' = 'en-US,en;q=0.9,pt;q=0.8'
|
||||
'Connection' = 'keep-alive'
|
||||
'Host' = 'evo2.congregatio.info'
|
||||
'If-None-Match' = 'W/"3566-dv/lW7LOD1QXVfUqIZqJkpLUNqg"'
|
||||
'Referer' = 'https://evo2.congregatio.info/manager/instance/be287e5d-66c6-4240-966a-94c1e7c9ed9a/dashboard'
|
||||
'User-Agent' = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
|
||||
'apikey' = $instanceApiKey
|
||||
}
|
||||
}
|
||||
} else { #>
|
||||
$invokeParams = @{
|
||||
Uri = "https://evo2.congregatio.info/instance/connect/${instanceName}?number=$phNumber"
|
||||
Method = 'Get'
|
||||
Headers = @{
|
||||
'Accept' = 'application/json, text/plain, */*'
|
||||
'Accept-Encoding' = 'gzip, deflate, br, zstd'
|
||||
'Accept-Language' = 'en-US,en;q=0.9,pt;q=0.8'
|
||||
'Connection' = 'keep-alive'
|
||||
'Host' = 'evo2.congregatio.info'
|
||||
'If-None-Match' = 'W/"3566-dv/lW7LOD1QXVfUqIZqJkpLUNqg"'
|
||||
'Referer' = 'https://evo2.congregatio.info/manager/instance/be287e5d-66c6-4240-966a-94c1e7c9ed9a/dashboard'
|
||||
'User-Agent' = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
|
||||
'apikey' = $instanceApiKey
|
||||
}
|
||||
}
|
||||
#}
|
||||
|
||||
$invokeParamsRestart = @{
|
||||
Uri = "https://evo2.congregatio.info/instance/logout/${instanceName}"
|
||||
Method = 'DELETE'
|
||||
Headers = @{
|
||||
'apikey' = $instanceApiKey
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$answerCheck = Invoke-RestMethod @invokeParamsCheck
|
||||
if ($answerCheck.instance.state -eq "open"){
|
||||
logger("instance is open, so not disconnecting")
|
||||
return
|
||||
}
|
||||
#Invoke-RestMethod @invokeParamsRestart
|
||||
|
||||
logger($invokeParams.Uri)
|
||||
logger($invokeParams.Headers.apikey)
|
||||
|
||||
$answer = Invoke-RestMethod @invokeParams 2>&1
|
||||
logger($answer)
|
||||
|
||||
$pairingCode = $answer.pairingCode
|
||||
logger($pairingCode)
|
||||
logger "Received pairing code: $pairingCode"
|
||||
if($pairingCode){break}
|
||||
else
|
||||
{
|
||||
logger "API request failed so restarting instance: $_"
|
||||
$answerRestart = Invoke-RestMethod @invokeParamsRestart
|
||||
logger($answerRestart)
|
||||
Start-Sleep -Seconds 3
|
||||
}
|
||||
$cnt += 1
|
||||
if($pairingCode){break}
|
||||
Write-Host "$cnt"
|
||||
}
|
||||
|
||||
logger "Final pairing code: $pairingCode"
|
||||
if($pairingCode) {& $global:LDPlayerPath\actions.ps1 -instanceIP "10.0.211.125" -action type, "$pairingCode"; Start-Sleep -Seconds 60}
|
||||
else {
|
||||
return $false
|
||||
}
|
||||
Reference in New Issue
Block a user