-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSHServer.lua
More file actions
37 lines (31 loc) · 1012 Bytes
/
Copy pathSSHServer.lua
File metadata and controls
37 lines (31 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local event = require("event")
local shell = require("shell")
local component = require("component")
local function handleMessage(_, _, sender, port, _, message)
if port == 400 and message then
local handle = io.popen(tostring(message) .. " 2>&1")
local result = handle:read("*a")
handle:close()
if not result or result == "" then
result = "[Command executed with no output]"
end
print("\n--- Remote Command Received ---")
print("From: " .. sender)
print("Cmd: " .. tostring(message))
print("Output:\n" .. result)
print("-------------------------------")
os.sleep(1)
component.modem.broadcast(400, result)
end
end
function start()
if component.isAvailable("modem") then
component.modem.open(400)
event.listen("modem_message", handleMessage)
else
io.stderr:write("Error: No modem found!\n")
end
end
function stop()
event.ignore("modem_message", handleMessage)
end