protected network services

This commit is contained in:
kepler155c@gmail.com 2019-04-20 13:48:13 -04:00
parent 62a3bc1360
commit 7749e14cad
6 changed files with 83 additions and 54 deletions

View File

@ -14,14 +14,7 @@ local function getProxy(path)
return proxy
end
Event.addRoutine(function()
print('proxy: listening on port 188')
while true do
local socket = Socket.server(188)
print('proxy: connection from ' .. socket.dhost)
Event.addRoutine(function()
local function proxyConnection(socket)
local path = socket:read(2)
if path then
local api = getProxy(path)
@ -40,7 +33,6 @@ Event.addRoutine(function()
end
socket:write(methods)
local s, m = pcall(function()
while true do
local data = socket:read()
if not data then
@ -49,12 +41,24 @@ Event.addRoutine(function()
end
socket:write({ api[data[1]](table.unpack(data, 2)) })
end
end)
end
end
Event.addRoutine(function()
print('proxy: listening on port 188')
while true do
local socket = Socket.server(188)
print('proxy: connection from ' .. socket.dhost)
Event.addRoutine(function()
local s, m = pcall(proxyConnection, socket)
print('proxy: closing connection to ' .. socket.dhost)
socket:close()
if not s and m then
print('Proxy error')
_G.printError(m)
end
end
socket:close()
end)
end
end)

View File

@ -67,8 +67,13 @@ Event.addRoutine(function()
Event.addRoutine(function()
print('samba: connection from ' .. socket.dhost)
sambaConnection(socket)
local s, m = pcall(sambaConnection, socket)
print('samba: closing connection to ' .. socket.dhost)
socket:close()
if not s and m then
print('Samba error')
_G.printError(m)
end
end)
end
end)

View File

@ -106,8 +106,12 @@ Event.addRoutine(function()
Event.addRoutine(function()
print('snmp: connection from ' .. socket.dhost)
snmpConnection(socket)
local s, m = pcall(snmpConnection, socket)
print('snmp: closing connection to ' .. socket.dhost)
if not s and m then
print('snmp error')
_G.printError(m)
end
end)
end
end)

View File

@ -76,7 +76,11 @@ Event.addRoutine(function()
print('telnet: connection from ' .. socket.dhost)
Event.addRoutine(function()
telnetHost(socket)
local s, m = pcall(telnetHost, socket)
if not s and m then
print('Telnet error')
_G.printError(m)
end
end)
end
end)

View File

@ -4,14 +4,7 @@ local Security = require('security')
local Socket = require('socket')
local Util = require('util')
Event.addRoutine(function()
print('trust: listening on port 19')
while true do
local socket = Socket.server(19)
print('trust: connection from ' .. socket.dhost)
local function trustConnection(socket)
local data = socket:read(2)
if data then
local password = Security.getPassword()
@ -30,6 +23,21 @@ Event.addRoutine(function()
end
end
end
end
Event.addRoutine(function()
print('trust: listening on port 19')
while true do
local socket = Socket.server(19)
print('trust: connection from ' .. socket.dhost)
local s, m = pcall(trustConnection, socket)
socket:close()
if not s and m then
print('Trust error')
_G.printError(m)
end
end
end)

View File

@ -63,7 +63,11 @@ Event.addRoutine(function()
-- no new process - only 1 connection allowed
-- due to term size issues
vncHost(socket)
local s, m = pcall(vncHost, socket)
socket:close()
if not s and m then
print('vnc error')
_G.printError(m)
end
end
end)