Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. #
  3. # Script to create files to import into MFT as variables for use in the Outgoing - Berwyn Death Report job.
  4. # Expects path to input file as first parameter.
  5. #
  6. #
  7. if(!($args[0].length -gt 0)) {
  8.     Write-Error "No input file"
  9.     exit;
  10. }
  11.  
  12. $LoginUsername = "login"
  13. $LoginPassword = "password"
  14.  
  15. $requiredSenderName = "sendername"
  16. $requiredCompanyName = "companyname"
  17. $requiredPhoneNumber = "phonenumber"
  18. $requiredEmailAddress = "email"
  19.  
  20. $userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
  21.  
  22. $loginURL = "https://login.url"
  23. $createTicketURL = "https://login.url/createTicket.html"
  24. $closeTicketURL = "https://login.url/closeTicket.html"
  25.  
  26. $proxyServer = "http://proxserver"
  27. $proxyPort = "8080"
  28.  
  29. [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
  30.  
  31. $loginParams = @{LoginUsername=$LoginUsername;
  32.                 LoginPassword=$LoginPassword;
  33.                 Action="Secure Login"}
  34. Invoke-WebRequest $loginURL -SessionVariable session -Body $loginParams -Method POST -TimeoutSec 120 -UserAgent $userAgent -Proxy $proxyServer":"$proxyPort -ProxyUseDefaultCredentials -OutFile loginResponse.html
  35.  
  36. $createTicketParams = @{FormInputMarker=1;
  37.                         requiredSenderName=$requiredSenderName;
  38.                         requiredCompanyName=$requiredCompanyName;
  39.                         requiredPhoneNumber=$requiredPhoneNumber;
  40.                         PhoneExtension="";
  41.                         FaxNumber="";
  42.                         requiredEmailAddress=$requiredEmailAddress;
  43.                         submit1="Select File to Send to Berwyn Group";}
  44. Invoke-WebRequest $createTicketURL -WebSession $session -Body $createTicketParams -Method POST -TimeoutSec 120 -UserAgent $userAgent -Proxy $proxyServer":"$proxyPort -ProxyUseDefaultCredentials -OutFile createTicketResponse.html
  45.  
  46. $ProgID = Get-Content createTicketResponse.html | Select-String 'ProgID=([0-9A-Z]*)' | % {"$($_.matches.groups[1])"}
  47. $TicketNumber = Get-Content createTicketResponse.html | Select-String '\(([0-9]+-[0-9]+)\)' | % {"$($_.matches.groups[1])"}
  48. $MgrWorkDirectory = Get-Content createTicketResponse.html | Select-String 'value="(DropOff[\(\)\-_0-9]*)"' | % {"$($_.matches.groups[1])"}
  49.  
  50. $uploadFileURL = "https://www.berwyngroup.com/db/UploadVerify.asp?ProgID=$ProgID"
  51.  
  52. $inputFile = Get-Content $args[0]
  53. $fileName = Split-Path $args[0] -leaf
  54.  
  55.  
  56. $encryptedFile = $inputFile
  57.  
  58. #Build multi-part message for file upload
  59. $boundary = "------"+[System.Guid]::NewGuid().ToString()
  60. $LF = "`n"
  61.  
  62. $uploadFileBody = (
  63.     "$boundary",
  64.     "Content-Disposition: form-data; name=`"MgrCustDirectory`"$LF",
  65.     $requiredCompanyName,
  66.     "$boundary",
  67.     "Content-Disposition: form-data; name=`"MgrWorkDirectory`"$LF",
  68.     $MgrWorkDirectory,
  69.     "$boundary",
  70.     "Content-Disposition: form-data; name=`"File1`"; filename=`"$fileName`"",
  71.     "Content-Type: text/plain$LF",
  72.     "filecontents",
  73.     "$boundary",
  74.     "Content-Disposition: form-data; name=`"requiredFileRecordCount`"$LF",
  75.     $inputFile.count,
  76.     "$boundary",
  77.     "Content-Disposition: form-data; name=`"FileInstructions`"$LF",
  78.     "",
  79.     "$boundary",
  80.     "Content-Disposition: form-data; name=`"Action`"$LF",
  81.     "Send File",
  82.     "$boundary--$LF"
  83.     ) -join $LF
  84.    
  85.     write-host $uploadFileBody;
  86.  
  87. 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
  88.  
  89. #Build multi-part message
  90. $boundary = "------"+[System.Guid]::NewGuid().ToString()
  91. $LF = "`n"
  92.  
  93. $exitBody = (
  94.     "$boundary",
  95.     "Content-Disposition: form-data; name=`"MgrCustDirectory`"$LF",
  96.     $requiredCompanyName,
  97.     "$boundary",
  98.     "Content-Disposition: form-data; name=`"MgrWorkDirectory`"$LF",
  99.     $MgrWorkDirectory,
  100.     "$boundary",
  101.     "Content-Disposition: form-data; name=`"Action`"$LF",
  102.     "Exit",
  103.     "$boundary--$LF"
  104.     ) -join $LF
  105.  
  106.     write-host $exitBody;
  107. 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
  108.  
  109. $MgrWorkDirectory | Out-File -Append WorkingDirectoryLog.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement