File: uhub-nmdc-redirector.py

package info (click to toggle)
uhub 0.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,624 kB
  • sloc: ansic: 19,102; xml: 607; perl: 463; sh: 403; python: 239; makefile: 9
file content (30 lines) | stat: -rwxr-xr-x 849 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
"""
A simple NMDC to ADC redirector service.
"""

import SocketServer

# The target hub we want to redirect clients to
redirect_uri = "adcs://adcs.uhub.org:1511"

# A message to be sent to users while they are being redirected.
message = "This hub has been permanently moved."

# The chat name of the message.
bot_name = "Redirector"

# The local address and port to bind the redirector to.
bind_addr = "0.0.0.0"
bind_port = 1411

class NmdcRedirector(SocketServer.BaseRequestHandler):

	def setup(self):
		self.request.sendall("<%(botname)s> %(message)s|$ForceMove %(address)s|" % { "address": redirect_uri, "botname": bot_name, "message": message })
		return False

if __name__ == "__main__":
	server = SocketServer.TCPServer((bind_addr, bind_port), NmdcRedirector)
	server.allow_reuse_address = True
	server.serve_forever()