Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- #
- # Script to create files to import into MFT as variables for use in the Outgoing - Berwyn Death Report job.
- # Expects path to input file as first parameter.
- #
- #
- if(!($args[0].length -gt 0)) {
- Write-Error "No input file"
- exit;
- }
- $LoginUsername = "login"
- $LoginPassword = "password"
- $requiredSenderName = "sendername"
- $requiredCompanyName = "companyname"
- $requiredPhoneNumber = "phonenumber"
- $requiredEmailAddress = "email"
- $userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
- $loginURL = "https://login.url"
- $createTicketURL = "https://login.url/createTicket.html"
- $closeTicketURL = "https://login.url/closeTicket.html"
- $proxyServer = "http://proxserver"
- $proxyPort = "8080"
- [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
- $loginParams = @{LoginUsername=$LoginUsername;
- LoginPassword=$LoginPassword;
- Action="Secure Login"}
- Invoke-WebRequest $loginURL -SessionVariable session -Body $loginParams -Method POST -TimeoutSec 120 -UserAgent $userAgent -Proxy $proxyServer":"$proxyPort -ProxyUseDefaultCredentials -OutFile loginResponse.html
- $createTicketParams = @{FormInputMarker=1;
- requiredSenderName=$requiredSenderName;
- requiredCompanyName=$requiredCompanyName;
- requiredPhoneNumber=$requiredPhoneNumber;
- PhoneExtension="";
- FaxNumber="";
- requiredEmailAddress=$requiredEmailAddress;
- submit1="Select File to Send to Berwyn Group";}
- Invoke-WebRequest $createTicketURL -WebSession $session -Body $createTicketParams -Method POST -TimeoutSec 120 -UserAgent $userAgent -Proxy $proxyServer":"$proxyPort -ProxyUseDefaultCredentials -OutFile createTicketResponse.html
- $ProgID = Get-Content createTicketResponse.html | Select-String 'ProgID=([0-9A-Z]*)' | % {"$($_.matches.groups[1])"}
- $TicketNumber = Get-Content createTicketResponse.html | Select-String '\(([0-9]+-[0-9]+)\)' | % {"$($_.matches.groups[1])"}
- $MgrWorkDirectory = Get-Content createTicketResponse.html | Select-String 'value="(DropOff[\(\)\-_0-9]*)"' | % {"$($_.matches.groups[1])"}
- $uploadFileURL = "https://www.berwyngroup.com/db/UploadVerify.asp?ProgID=$ProgID"
- $inputFile = Get-Content $args[0]
- $fileName = Split-Path $args[0] -leaf
- $encryptedFile = $inputFile
- #Build multi-part message for file upload
- $boundary = "------"+[System.Guid]::NewGuid().ToString()
- $LF = "`n"
- $uploadFileBody = (
- "$boundary",
- "Content-Disposition: form-data; name=`"MgrCustDirectory`"$LF",
- $requiredCompanyName,
- "$boundary",
- "Content-Disposition: form-data; name=`"MgrWorkDirectory`"$LF",
- $MgrWorkDirectory,
- "$boundary",
- "Content-Disposition: form-data; name=`"File1`"; filename=`"$fileName`"",
- "Content-Type: text/plain$LF",
- "filecontents",
- "$boundary",
- "Content-Disposition: form-data; name=`"requiredFileRecordCount`"$LF",
- $inputFile.count,
- "$boundary",
- "Content-Disposition: form-data; name=`"FileInstructions`"$LF",
- "",
- "$boundary",
- "Content-Disposition: form-data; name=`"Action`"$LF",
- "Send File",
- "$boundary--$LF"
- ) -join $LF
- write-host $uploadFileBody;
- Invoke-WebRequest $uploadFileURL -WebSession $session -Body $uploadFileBody -Method POST -ContentType "multipart/form-data; boundary=`"$boundary`"" -TimeoutSec 300 -UserAgent $userAgent -Proxy $proxyServer":"$proxyPort -ProxyUseDefaultCredentials -OutFile uploadFileResponse.html
- #Build multi-part message
- $boundary = "------"+[System.Guid]::NewGuid().ToString()
- $LF = "`n"
- $exitBody = (
- "$boundary",
- "Content-Disposition: form-data; name=`"MgrCustDirectory`"$LF",
- $requiredCompanyName,
- "$boundary",
- "Content-Disposition: form-data; name=`"MgrWorkDirectory`"$LF",
- $MgrWorkDirectory,
- "$boundary",
- "Content-Disposition: form-data; name=`"Action`"$LF",
- "Exit",
- "$boundary--$LF"
- ) -join $LF
- write-host $exitBody;
- Invoke-WebRequest $closeTicketURL -WebSession $session -Body $exitBody -Method POST -ContentType "multipart/form-data; boundary=`"$boundary`"" -TimeoutSec 300 -UserAgent $userAgent -Proxy $proxyServer":"$proxyPort -ProxyUseDefaultCredentials -OutFile exitResponse.html
- $MgrWorkDirectory | Out-File -Append WorkingDirectoryLog.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement