if client.type == host.client_type.net then
client:send( "Password: " ..IAC..WILL..ECHO )
else
- -- no authentification needed on stdin
+ -- no authentication needed on stdin
client:switch_status( host.status.read )
end
end
password = config.password or "admin"
--[[ Launch vlm ]]
-vlm = vlc.vlm.new()
+vlm = vlc.vlm()
--[[ Commands ]]
function shutdown(client)
h:broadcast("Shutting down.\r\n")
vlc.msg.err("shutdown requested")
- vlc.quit()
+ vlc.misc.quit()
return true
end
function logout(client)
["logout"] = { func = logout, help = "logout" },
["lock"] = { func = lock, help = "lock the telnet prompt" },
["description"] = { func = print_text(description), help = "describe this module" },
- ["license"] = { func = print_text(vlc.license()), help = "print VLC's license message" },
+ ["license"] = { func = print_text(vlc.misc.license()), help = "print VLC's license message" },
["help"] = { func = help, help = "show this help", dovlm = true },
}
client.buffer = ""
if not commands[cmd] or not commands[cmd].func or commands[cmd].dovlm then
-- if it's not an interface specific command, it has to be a VLM command
- local message, vlc_err = vlc.vlm.execute_command( vlm, cmd )
+ local message, vlc_err = vlm:execute_command( cmd )
vlm_message_to_string( client, message )
if not commands[cmd] or not commands[cmd].func and not commands[cmd].dovlm then
if vlc_err ~= 0 then client:append( "Type `help' for help." ) end
end
--[[ The main loop ]]
-while not vlc.should_die() do
- h:accept()
- local w, r = h:select( 0.1 )
+while not vlc.misc.should_die() do
+ local w, r = h:accept_and_select()
-- Handle writes
for _, client in pairs(w) do
-- Handle reads
for _, client in pairs(r) do
- local str = client:recv(1000)
+ local str = string.gsub(client:recv(1000),"\r","\n")
local done = false
- if string.match(str,"\n$") then
- client.buffer = string.gsub(client.buffer..str,"\r?\n$","")
+
+ -- the telnet client program has leave
+ if not str then
+ client.buffer = "quit"
done = true
+
+ -- Caught a ^D
elseif client.buffer == ""
and ((client.type == host.client_type.stdio and str == "")
or (client.type == host.client_type.net and str == "\004")) then
- -- Caught a ^D
client.buffer = "quit"
done = true
+
+ -- '\n' found: a command was sent
+ elseif string.match(str,"\n") then
+ client.buffer = client.buffer .. str
+ done = true
+
+ -- The command is not finished yet
else
client.buffer = client.buffer .. str
end
+
+ -- Some cleaning for telnet
if client.type == host.client_type.net then
telnet_commands( client )
end
+
+ -- If a command must be parsed
if done then
- if client.status == host.status.password then
- if client.buffer == password then
- client:send( IAC..WONT..ECHO.."\r\nWelcome, Master\r\n" )
- client.buffer = ""
+ -- loop on all commands (might have more than one commands seperated by '\n'
+ local returned_values = ""
+ while not (client.buffer == "") do
+ -- pick the first command
+ local commands = ""
+ if string.find(client.buffer, "\n") then
+ commands = string.sub(client.buffer, string.find(client.buffer, "\n") + 1)
+ client.buffer = string.sub(client.buffer, 0, string.find(client.buffer, "\n") - 1)
+ end
+ local cmd = client.buffer
+
+ if client.status == host.status.password then
+ if client.buffer == password then
+ client:send( IAC..WONT..ECHO.."\r\nWelcome, Master\r\n" )
+ client.buffer = ""
+ client:switch_status( host.status.write )
+ else
+ client:send( "\r\nWrong password\r\nPassword: " )
+ client.buffer = ""
+ end
+ elseif client_command( client ) then
client:switch_status( host.status.write )
- else
- client:send( "\r\nWrong password\r\nPassword: " )
- client.buffer = ""
+ -- special case to exit the loop
+ if cmd == "quit" or cmd == "shutdown" then break end
end
- elseif client_command( client ) then
- client:switch_status( host.status.write )
+ returned_values = returned_values .. client.buffer
+ client.buffer = commands
end
+ vlc.msg.err("end of loop")
+ client.buffer = returned_values
end
end
end
--[[ Clean up ]]
-vlc.vlm.delete( vlm )
+vlm = nil