Guest User

Untitled

a guest
May 4th, 2025
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | Cybersecurity | 0 0
  1.  
  2. $FilePath = ""
  3. $BotToken = ""
  4. $ChatID = ""
  5.  
  6.  
  7. # Переменные
  8. $LastAccessTime = (Get-Item $FilePath).LastAccessTime
  9. $LastWriteTime = (Get-Item $FilePath).LastWriteTime
  10. $FileExists = Test-Path $FilePath
  11.  
  12. # Основной цикл
  13. while ($true) {
  14. Start-Sleep -Seconds 5
  15.  
  16. $CurrentExists = Test-Path $FilePath
  17.  
  18. if ($CurrentExists) {
  19. $CurrentAccessTime = (Get-Item $FilePath).LastAccessTime
  20. $CurrentWriteTime = (Get-Item $FilePath).LastWriteTime
  21.  
  22. if ($CurrentAccessTime -ne $LastAccessTime) {
  23. $LastAccessTime = $CurrentAccessTime
  24. $msg = "File open: `"$FilePath`" в $CurrentAccessTime"
  25. Invoke-RestMethod -Uri "https://api.telegram.org/bot$BotToken/sendMessage" `
  26. -Method POST -Body @{
  27. chat_id = $ChatID
  28. text = $msg
  29. parse_mode = "Markdown"
  30. }
  31. }
  32.  
  33. if ($CurrentWriteTime -ne $LastWriteTime) {
  34. $LastWriteTime = $CurrentWriteTime
  35. $msg = "File modified: `"$FilePath`" в $CurrentWriteTime"
  36. Invoke-RestMethod -Uri "https://api.telegram.org/bot$BotToken/sendMessage" `
  37. -Method POST -Body @{
  38. chat_id = $ChatID
  39. text = $msg
  40. parse_mode = "Markdown"
  41. }
  42. }
  43. } elseif ($FileExists) {
  44. $FileExists = $false
  45. $msg = "File deleted: `"$FilePath`""
  46. Invoke-RestMethod -Uri "https://api.telegram.org/bot$BotToken/sendMessage" `
  47. -Method POST -Body @{
  48. chat_id = $ChatID
  49. text = $msg
  50. parse_mode = "Markdown"
  51. }
  52. } elseif (-not $FileExists -and $CurrentExists) {
  53. $FileExists = $true
  54. $LastAccessTime = (Get-Item $FilePath).LastAccessTime
  55. $LastWriteTime = (Get-Item $FilePath).LastWriteTime
  56. $msg = "File restored: `"$FilePath`""
  57. Invoke-RestMethod -Uri "https://api.telegram.org/bot$BotToken/sendMessage" `
  58. -Method POST -Body @{
  59. chat_id = $ChatID
  60. text = $msg
  61. parse_mode = "Markdown"
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment