Пример #1
0
	def telnet_conn(self):

		self.server_conn = TelnetServer(
			port = self.port,
			address = '',
			on_connect = self.mon_connect,
			on_disconnect = self.mon_disconnect
		)

		# self.server_conn.on_connect = self.mon_connect
		# self.server_conn.on_disconnect = self.mon_disconnect

		sys.stdout.write("Running telnet service on port %d \n" % self.port)
		while (1):
			self.server_conn.poll()
			self.process_client()
Пример #2
0
class Mongrel(Server):

	def mon_connect(self, client):
		# TODO: Some log file append will be good
		print "++ Opened connection from %s \n" % client.addrport()
		# TODO: Broadcast function call should be here if any
		client_list.append(client)
		client.active = True
		client.send("Welcome to Mongrel v0.2. Your IP is %s \n" % client.addrport())
		client.send("Your terminal type is %s \n" % client.terminal_type)
		client.send(">>> ")
				
	def mon_disconnect(self, client):
		print "++ Closed connection from %s \n" % client.addrport()
		client.send("Bye, %s!" % client.addrport())
		client_list.remove(client)
		client.active = False

	def process_client(self):
		for client in client_list:
			if client.active and client.cmd_ready:
				self.chat(client)

	def chat(self, client):
		"""
		Log everything that the user writes
		"""
		msg = client.get_command()
		for guest in client_list:
			if guest != client:
				guest.send("%s: %s\n" % (client.addrport(), msg))
				guest.send(">>> ")
			else:
				guest.send("%s: %s\n" % (client.addrport(), msg))
				client.send(">>> ")
		cmd = msg.lower()
		# if cmd == 'cl':
		# Disconnect
		if cmd == 'bye':
			client.active = False

	def telnet_conn(self):

		self.server_conn = TelnetServer(
			port = self.port,
			address = '',
			on_connect = self.mon_connect,
			on_disconnect = self.mon_disconnect
		)

		# self.server_conn.on_connect = self.mon_connect
		# self.server_conn.on_disconnect = self.mon_disconnect

		sys.stdout.write("Running telnet service on port %d \n" % self.port)
		while (1):
			self.server_conn.poll()
			self.process_client()

	def run(self):
		self.telnet_conn()
		while True:
			time.sleep(1)