finger.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """The Finger User Information Protocol (RFC 1288)"""
  4. from twisted.protocols import basic
  5. class Finger(basic.LineReceiver):
  6. def lineReceived(self, line):
  7. parts = line.split()
  8. if not parts:
  9. parts = [b'']
  10. if len(parts) == 1:
  11. slash_w = 0
  12. else:
  13. slash_w = 1
  14. user = parts[-1]
  15. if b'@' in user:
  16. hostPlace = user.rfind(b'@')
  17. user = user[:hostPlace]
  18. host = user[hostPlace+1:]
  19. return self.forwardQuery(slash_w, user, host)
  20. if user:
  21. return self.getUser(slash_w, user)
  22. else:
  23. return self.getDomain(slash_w)
  24. def _refuseMessage(self, message):
  25. self.transport.write(message + b"\n")
  26. self.transport.loseConnection()
  27. def forwardQuery(self, slash_w, user, host):
  28. self._refuseMessage(b'Finger forwarding service denied')
  29. def getDomain(self, slash_w):
  30. self._refuseMessage(b'Finger online list denied')
  31. def getUser(self, slash_w, user):
  32. self.transport.write(b'Login: ' + user + b'\n')
  33. self._refuseMessage(b'No such user')