Advertisement
Ewgeniy

Signalka

Jun 25th, 2024 (edited)
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.28 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local internet = require("internet")
  4. local tty = require("tty")
  5. local fs = require("filesystem")
  6. local json = require("json")
  7. local serial = require("serialization")
  8. local gpu = require("component").gpu
  9.  
  10. local sen = component.motion_sensor
  11. local oldback = gpu.getBackground()
  12. local oldfore = gpu.getForeground()
  13.  
  14. -- Запрашиваем у пользователя ключи Pastebin API при запуске программы
  15. --print("Enter your Pastebin API Key:")
  16. --local pastebinKey = io.read()
  17. --print("Enter your Pastebin User Key:")
  18. --local userKey = io.read()
  19.  
  20. -- Запрашиваем у пользователя данные для Telegram
  21. print("Enter your Telegram Bot Token:")
  22. local botToken = io.read()
  23. print("Enter your Telegram Chat ID:")
  24. local chatID = io.read()
  25.  
  26. sen.setSensitivity(0,1)
  27. tty.clear()
  28.  
  29. io.write([===[
  30.                  .-_; ;_-.
  31.                 / /     \ \
  32.                | |       | |
  33.                 \ \.---./ /
  34.             .-"~   .---.   ~"-.
  35.           ,`.-~/ .'`---`'. \~-.`,
  36.           '`   | | \(_)/ | |   `'
  37.           ,    \  \ | | /  /    ,
  38.           ;`'.,_\  `-'-'  /_,.'`;
  39.            '-._  _.-'^'-._  _.-'
  40.                ``         ``  
  41. ]===])
  42. print("Primitive tracking program v1.1")
  43. print("By HappyWindinkg")
  44. print("Sensitivity threshold: ", sen.getSensitivity())
  45. print()
  46. print("List of offenders:")
  47.  
  48. -- Функция для отправки данных на Pastebin
  49. local function pasteToPastebin(data, pastebinKey, userKey)
  50.   local pasteName = "Alert: Unauthorized Visitor"
  51.   local response = ""
  52.  
  53.   local url = "https://pastebin.com/api/api_post.php"
  54.   local requestBody = "api_dev_key=" .. pastebinKey ..
  55.                       "&api_user_key=" .. userKey ..
  56.                       "&api_option=paste" ..
  57.                       "&api_paste_code=" .. data
  58.  
  59.   local handle, err = internet.request(url, requestBody)
  60.   if not handle then
  61.     return "Error: " .. (err or "unknown error")
  62.   end
  63.  
  64.   for chunk in handle do
  65.     response = response .. chunk
  66.   end
  67.  
  68.   return response
  69. end
  70.  
  71. -- Функция для кодирования URL
  72. local function urlencode(str)
  73.    if (str) then
  74.       str = string.gsub (str, "\n", "\r\n")
  75.       str = string.gsub (str, "([^%w ])",
  76.          function (c) return string.format ("%%%02X", string.byte(c)) end)
  77.       str = string.gsub (str, " ", "+")
  78.    end
  79.    return str    
  80. end
  81.  
  82. -- Функция для отправки данных в Telegram
  83. local function telegramGET(chatid, text)
  84.     local result, reason = internet.request("https://api.telegram.org/bot" .. botToken .. "/sendMessage?chat_id=" .. chatID .. "&text=" .. urlencode(text))
  85.     local info = ""
  86.     if result then
  87.         for chunk in result do
  88.             info = info .. chunk
  89.         end
  90.         return info
  91.     else
  92.         return "Error: " .. (reason or "unknown error")
  93.     end
  94. end
  95.  
  96. -- Функция для записи никнеймов в файл
  97. local function saveToFile(filename, text)
  98.     local file, err = io.open(filename, "a")
  99.     if not file then
  100.         print("Error opening file: " .. (err or "unknown error"))
  101.         return
  102.     end
  103.     file:write(text .. "\n")
  104.     file:close()
  105. end
  106.  
  107. --(установить для своего часового пояса, -12 : +13, например: -2 или 6)
  108. local TIME_ZONE = 3  
  109.  
  110. --(не изменять!)
  111. local t_correction = TIME_ZONE * 3600
  112.  
  113. function os.dateRL(format)
  114.     if not fs.get("/").isReadOnly() then
  115.         local time = io.open("/tmp/.time", "w")
  116.         time:write()
  117.         time:close()
  118.         os.sleep(0.01)
  119.         local currentTime = fs.lastModified("/tmp/.time") / 1000
  120.         -- Добавляем 3 часа к текущему времени
  121.         currentTime = currentTime + 3 * 3600
  122.         return os.date(format, currentTime)
  123.     else
  124.         local currentTime = os.time()
  125.         -- Добавляем 3 часа к текущему времени
  126.         currentTime = currentTime + 3 * 3600
  127.         return os.date(format, currentTime)
  128.     end
  129. end
  130.  
  131.  
  132.  
  133. -- Основной цикл программы
  134. local name, n
  135. local q = true
  136. local quests = {}
  137. -- Вайтлист
  138. local whiteList = {"cloud", "LeShyj", "entity.Cat.name", "reload", "karnel"}
  139.  
  140. while q do
  141.   local b = true
  142.   n, _, _, m, _, name = event.pull()
  143.   if n == "motion" then
  144.     for i = 1, #quests do
  145.       if quests[i] == name then
  146.         b = false
  147.         break
  148.       end
  149.     end
  150.     if b then
  151.       table.insert(quests, name)
  152.       print(name)
  153.       -- Проверяем, есть ли посетитель в вайтлисте и отправляем данные на Pastebin, если он не в вайтлисте
  154.       local unauthorized = true
  155.       for i = 1, #whiteList do
  156.         if whiteList[i] == name then
  157.           unauthorized = false
  158.           break
  159.         end
  160.       end
  161.       if unauthorized then
  162.        local alertMessage = "Unauthorized visitor detected: " .. name .. " " .. os.dateRL("%x %X")
  163.     local alert2Message = "All the user details namely, IP Address, Nickname, Identification Number and Residence have been successfully sent [OK];"
  164.     local alertErrorMessage = "Something prevented the data from being sent [ERR];\nSaving a local copy of the file [OK];"
  165.         print(alertMessage)
  166.  
  167. --gpu.setForeground(0x00FF00)
  168.         --local pasteResponse = pasteToPastebin("Unauthorized visitor detected: " .. name .. " " .. os.dateRL("%x %X"), pastebinKey, userKey)
  169.         --print("Data sent to Pastebin: " .. alert2Message)
  170. --gpu.setForeground(oldfore)
  171.  
  172.  
  173.  local telegramSuccess, telegramResponse = pcall(telegramGET, chatID, alertMessage)
  174.         if telegramSuccess then
  175. gpu.setForeground(0x00FF00)
  176.           print("Data sent to Telegram: " .. alert2Message)
  177.         saveToFile("/home/1.txt", name .. " " .. os.dateRL("%x %X"))
  178. gpu.setForeground(oldfore)
  179. print(" ")
  180.       else
  181. gpu.setForeground(0xFF0000)
  182.           print("Error sending to Telegram: " .. alertErrorMessage)  
  183.         saveToFile("/home/1.txt", name .. " " .. os.dateRL("%x %X"))
  184. gpu.setForeground(oldfore)
  185. print(" ")
  186.       end
  187.     end
  188.   end
  189. end
  190.   if n == "key_down" then
  191.     if m == 16 then
  192.       q = false
  193.       print("The program has been successfully completed.")
  194.     end
  195.   end
  196. end
  197.  
  198.  
  199.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement