· last year · Jun 25, 2024, 04:05 PM
1local component = require("component")
2local event = require("event")
3local internet = require("internet")
4
5local sen = component.motion_sensor
6
7-- Запрашиваем у пользователя ключи Pastebin API при запуске программы
8print("Enter your Pastebin API Key:")
9local pastebinKey = io.read()
10print("Enter your Pastebin User Key:")
11local userKey = io.read()
12
13print("Порог чувствительности: ", sen.getSensitivity())
14print("Отключить сигнализацию - любая клавиша")
15print("Завершить программу - Q")
16print()
17print("Список посетителей:")
18
19-- Функция для отправки данных на Pastebin
20local function pasteToPastebin(data, pastebinKey, userKey)
21 local pasteName = "Alert: Unauthorized Visitor"
22 local response = ""
23
24 local url = "https://pastebin.com/api/api_post.php"
25 local requestBody = "api_dev_key=" .. pastebinKey ..
26 "&api_user_key=" .. userKey ..
27 "&api_option=paste" ..
28 "&api_paste_code=" .. data
29
30 local handle, err = internet.request(url, requestBody)
31 if not handle then
32 return "Error: " .. (err or "unknown error")
33 end
34
35 for chunk in handle do
36 response = response .. chunk
37 end
38
39 return response
40end
41
42
43
44-- Основной цикл программы
45local name, n
46local q = true
47local quests = {}
48-- Вайтлист
49local whiteList = {"cloud", "LeShyj", "entity.Cat.name", "reload", "karnel"}
50
51while q do
52 local b = true
53 n, _, _, m, _, name = event.pull()
54 if n == "motion" then
55 for i = 1, #quests do
56 if quests[i] == name then
57 b = false
58 break
59 end
60 end
61 if b then
62 table.insert(quests, name)
63 print(name)
64 -- Проверяем, есть ли посетитель в вайтлисте и отправляем данные на Pastebin, если он не в вайтлисте
65 local unauthorized = true
66 for i = 1, #whiteList do
67 if whiteList[i] == name then
68 unauthorized = false
69 break
70 end
71 end
72 if unauthorized then
73 print("Unauthorized visitor detected: " .. name)
74 local pasteResponse = pasteToPastebin("Unauthorized visitor detected: " .. name, pastebinKey, userKey)
75 print("Data sent to Pastebin: " .. pasteResponse)
76 end
77 end
78 end
79 if n == "key_down" then
80 if m == 16 then
81 q = false
82 print("Программа завершена.")
83 end
84 end
85end
86
87
88