Skip to content

Instantly share code, notes, and snippets.

@stevommmm
Created January 13, 2015 04:02
Show Gist options
  • Select an option

  • Save stevommmm/866320f6f91e6375efa3 to your computer and use it in GitHub Desktop.

Select an option

Save stevommmm/866320f6f91e6375efa3 to your computer and use it in GitHub Desktop.
def run(self):
self.conn.send('220 Welcome!\r\n')
while True:
if not isinstance(self.conn, ssl.SSLSocket): # Can't PEEK at ssl sockets
if self.conn.recv( 1, socket.MSG_PEEK ) == "\x16":
self.conn = ssl.wrap_socket(self.conn, certfile="cert.pem", server_side=True)
cmd=self.conn.recv(256)
if not cmd: break
else:
try:
func=getattr(self,cmd[:4].strip().upper())
func(cmd)
except Exception,e:
print 'ERROR:',e
traceback.print_exc()
self.conn.send('500 Sorry.\r\n')
# ... snip ...
def AUTH(self, cmd):
print repr(cmd)
if cmd.strip == "AUTH TLS":
self.conn.send('234 OK.\r\n')
else:
self.conn.send('504 Sorry.\r\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment