Skip to content

Instantly share code, notes, and snippets.

@peterc
Created July 3, 2022 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterc/b37a92f180b5067aee8917d387f1487c to your computer and use it in GitHub Desktop.
Save peterc/b37a92f180b5067aee8917d387f1487c to your computer and use it in GitHub Desktop.
finger daemon
#!/usr/bin/env ruby
require 'eventmachine'
class FingerServer < EM::Connection
def receive_data(data)
data.strip!
if data =~ /\A\w+\z/ && data.length <= 100
puts "Got a request for user #{data}"
raise if data =~ /[^a-z+_]/i
raise if !data.class == String
raise if data.length > 100
if File.exist?("/home/#{data}/.plan")
fh = File.open("/home/#{data}/.plan", "r")
while (line = fh.gets) && line.strip !~ /\A\-{3,}\Z/
send_data(line)
end
fh.close
if File.exist?("/home/#{data}/.sig")
send_data(File.read("/home/#{data}/.sig").to_s)
end
send_data("\r\n\r\n")
else
send_data "No Plan."
end
else
send_data "No Plan."
end
close_connection_after_writing
#rescue
# close_connection_after_writing
end
end
EventMachine.run do
Signal.trap("INT") { EventMachine.stop }
Signal.trap("TERM") { EventMachine.stop }
puts "Starting finger daemon on port 7900"
EventMachine.start_server("0.0.0.0", 7900, FingerServer)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment