Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from twisted.conch import telnet
  4. from twisted.internet import protocol, reactor
  5. from nevow.livepage import eol, set, js
  6. from cgi import escape
  7.  
  8. # if first chunk contains following sequence we send back rtclient\n
  9. # so they know it is ok to send html
  10. #HOWDY_SEQUENCE = "Welcome to Evennia!"
  11.  
  12. HTML_TOKEN = chr(240)
  13. JAVASCRIPT_TOKEN = chr(241)
  14. UNENCODED_TOKEN = chr(242)
  15. NO_AUTOCHUNK_TOKEN = chr(243)
  16. AUTOCHUNK_TOKEN = chr(244)
  17.  
  18. ENCODING_TOKENS = [HTML_TOKEN, JAVASCRIPT_TOKEN, UNENCODED_TOKEN, AUTOCHUNK_TOKEN, NO_AUTOCHUNK_TOKEN]
  19.  
  20. from random import randint
  21.  
  22. class ProxyTelnetClient(telnet.TelnetTransport):
  23. mode = 'WaitForUser'
  24. def connectionMade(self):
  25. pass
  26.  
  27. def gotClient(self):
  28. self.transport.write("ProxyKeyLogin %s\r\n" % self.client.key)
  29.  
  30. def dataReceived(self, chunk):
  31. """ data received FROM the MUD """
  32. self.client.transport.write(chunk)
  33.  
  34.  
  35. def telnet_WaitForUser(self, line):
  36. if line.startswith('Username: '):
  37. self.client.write(self.factory.username + '\r\n')
  38. return 'WaitForPassword'
  39.  
  40. def telnet_WaitForPassword(self, line):
  41. print "wfp"
  42. if line.startswith('Password: '):
  43. self.write(self.factory.password + '\r\n')
  44.  
  45. # Instead of this, you could do another state,
  46. # like "WaitForPrompt" or something.
  47. reactor.callLater(1, self.reboot)
  48. return 'Idling'
  49.  
  50. def telnet_Idling(self, line):
  51. print "idle"
  52. # La la la.
  53. pass
  54.  
  55. def reboot(self):
  56. self.write('reboot\r\n')
  57.  
  58. # This will make us lose our connection after the next
  59. # line is received. To lose it faster, use
  60. # self.transport.loseConnection() instead
  61. self.mode = 'Done'
  62.  
  63. def connectionLost(self, reason):
  64. #self.client.sendLine("Connection lost!!!")
  65. self.transport.loseConnection()
  66. if self.client.protocol:
  67. print "prepping another session"
  68. self.client.prep_session()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement