Advertisement
gdunc

List-Banned.ps1

Nov 3rd, 2020 (edited)
2,800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.   List-Banned.ps1 -file <file.json> [-delay <seconds>]
  3.   V. 20201115-1132
  4.  
  5.   Where: file.json = CTBRec config file, (usually ctbrec.json or server.json)
  6.          seconds   = Delay between each Web Request, (avoid possible error 503), valid range 0.1-90
  7.  
  8.   example: List-Banned.ps1 -file server.json
  9.            List-Banned.ps1 -file ctbrec.json -delay 3
  10.  
  11.   List models with pages that don't resolve, (error 404, etc), or CB models that are banned.
  12.  
  13.   Output will be to Model-Status.txt in the same dir as List-Banned.ps1.
  14.   File will be overwritten in consecutive runs.
  15.  
  16.   Prints a number and the model name as it progresses, will only consign HTTP error codes 4xx
  17.   to the output file + CB Banned rooms.
  18.   Output file will open after it's finished.
  19.  
  20.   Tested on PowerShell 7, Windows 10 and DietPi 6.33.3, (RasPi).
  21.  
  22.   *** NOTE: Only tested with a few models on CB because I only monitor 1-3 models there, so if
  23.             no-one tells me anything I'll assume it works on all sites.
  24. #>
  25.  
  26. param (
  27.     [Parameter(Mandatory=$true)][string]$file,
  28.     [ValidateRange(0.1,90)][decimal]$delay
  29. )
  30.  
  31. $httpErrors = @{
  32.   400 = 'Bad Request'
  33.   401 = 'Unauthorized'
  34.   402 = 'Payment Required'
  35.   403 = 'Forbidden'
  36.   404 = 'Not Found'
  37.   405 = 'Method Not Allowed'
  38.   406 = 'Not Acceptable'
  39.   407 = 'Proxy Authentication Required'
  40.   408 = 'Request Timeout'
  41.   409 = 'Conflict'
  42.   410 = 'Gone'
  43.   411 = 'Length Required'
  44.   412 = 'Precondition Failed'
  45.   413 = 'Payload Too Large'
  46.   414 = 'URI Too Long'
  47.   415 = 'Unsupported Media Type'
  48.   416 = 'Range Not Satisfiable'
  49.   417 = 'Expectation Failed'
  50.   418 = "I'm a teapot"
  51.   421 = 'Misdirected Request'
  52.   425 = 'Too Early'
  53.   426 = 'Upgrade Required'
  54.   428 = 'Precondition Required'
  55.   429 = 'Too Many Requests'
  56.   431 = 'Request Header Fields Too Large'
  57.   451 = 'Unavailable For Legal Reasons'
  58. }
  59.  
  60. function Test-Url ([string] $Url) {
  61.   $req = [system.Net.WebRequest]::Create($url)
  62.  
  63.   try {
  64.     $res = $req.GetResponse()
  65.   }
  66.   catch [System.Net.WebException] {
  67.     $res = $_.Exception.Response
  68.   }
  69.   return $res
  70. }
  71.  
  72. function Test-Models ([string] $infile) {
  73.   $json = (Get-Content $infile | ConvertFrom-Json)
  74.   for ($i = 0; $i -lt $json.models.Count; $i++) {
  75.     $statusCode = [int](Test-Url $json.models[$i].url).StatusCode
  76.     "$($i) - $($json.models[$i].name)"
  77.     if ($statusCode -gt 399 -and $statusCode -lt 500) {
  78.       "$($json.models[$i].name) - $($statusCode) - $($httpErrors[$statusCode])" | Out-File -FilePath Model-Status.txt -Append
  79.     } else {
  80.       if ($json.models[$i].type -match 'chaturbate') {
  81.         $data = Invoke-WebRequest -Uri $json.models[$i].url
  82.         if ($data -match 'This room has been banned') {
  83.           "$($json.models[$i].name) - Banned" | Out-File -FilePath Model-Status.txt -Append
  84.         }
  85.       }
  86.     }
  87.     if ($delay -gt 0) {
  88.       Start-Sleep -Seconds $delay
  89.     }
  90.   }
  91. }
  92.  
  93. if (Test-Path ./Model-Status.txt) {
  94.   Remove-Item ./Model-Status.txt -Force
  95. }
  96.  
  97. Get-Date -Format u | Out-File -FilePath Model-Status.txt
  98. Test-Models $file
  99. Invoke-Item .\Model-Status.txt
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement