1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-19 01:37:39 +00:00

proxy apis over wireless

This commit is contained in:
kepler155c@gmail.com
2017-10-24 23:01:40 -04:00
parent 84b2b8ce63
commit 7fd93e8a8b
7 changed files with 63 additions and 13 deletions

34
sys/network/proxy.lua Normal file
View File

@@ -0,0 +1,34 @@
local Event = require('event')
local Socket = require('socket')
Event.addRoutine(function()
while true do
print('proxy: listening on port 188')
local socket = Socket.server(188)
print('proxy: connection from ' .. socket.dhost)
Event.addRoutine(function()
local api = socket:read(2)
if api then
local proxy = _G[api]
local methods = { }
for k,v in pairs(proxy) do
if type(v) == 'function' then
table.insert(methods, k)
end
end
socket:write(methods)
while true do
local data = socket:read()
if not data then
break
end
socket:write({ proxy[data.fn](unpack(data.args)) })
end
end
end)
end
end)

View File

@@ -2,9 +2,12 @@ local Event = require('event')
local Socket = require('socket')
local Util = require('util')
local function telnetHost(socket)
local multishell = _ENV.multishell
local os = _G.os
local term = _G.term
requireInjector(getfenv(1))
local function telnetHost(socket)
_G.requireInjector()
local Event = require('event')
@@ -14,7 +17,7 @@ local function telnetHost(socket)
local termInfo = socket:read(5)
if not termInfo then
printtError('read failed')
_G.printtError('read failed')
return
end
@@ -45,7 +48,7 @@ local function telnetHost(socket)
end
local shellThread = Event.addRoutine(function()
os.run(getfenv(1), 'sys/apps/shell')
os.run(_ENV, 'sys/apps/shell')
Event.exitPullEvents()
end)
@@ -67,7 +70,6 @@ local function telnetHost(socket)
end
Event.addRoutine(function()
print('telnet: listening on port 23')
while true do
local socket = Socket.server(23)
@@ -77,7 +79,6 @@ Event.addRoutine(function()
multishell.openTab({
fn = telnetHost,
args = { socket },
env = getfenv(1),
title = 'Telnet Client',
hidden = true,
})