1#!/usr/bin/env python
2"""
3A simple NMDC to ADC redirector service.
4"""
5
6import SocketServer
7
8# The target hub we want to redirect clients to
9redirect_uri = "adcs://adcs.uhub.org:1511"
10
11# A message to be sent to users while they are being redirected.
12message = "This hub has been permanently moved."
13
14# The chat name of the message.
15bot_name = "Redirector"
16
17# The local address and port to bind the redirector to.
18bind_addr = "0.0.0.0"
19bind_port = 1411
20
21class NmdcRedirector(SocketServer.BaseRequestHandler):
22
23	def setup(self):
24		self.request.sendall("<%(botname)s> %(message)s|$ForceMove %(address)s|" % { "address": redirect_uri, "botname": bot_name, "message": message })
25		return False
26
27if __name__ == "__main__":
28	server = SocketServer.TCPServer((bind_addr, bind_port), NmdcRedirector)
29	server.allow_reuse_address = True
30	server.serve_forever()
31