-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmammia.py
64 lines (52 loc) · 2.07 KB
/
mammia.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Mammatus, a DNS-centric HA platform
Dmytri Kleiner <[email protected]>, 2010
The "Petit-bourgeois Reformist" edition
Mammatus exploits the ubiquity of DNS fail-over to implement
hight availablity http service.
This implementation includes support for resolving the endpoint
IP as well as redirecting to a target domain, proxying and serving
local files.
This is selected by specifying resolve=self or resolve=endpoint in
the _mammatus TXT record for the subdomain.
endpoints can be forign or local.
USAGE:
sudo twistd -[n]y mammatus.tac
"""
from twisted.application import service, internet
from twisted.internet import reactor
from twisted.internet.task import deferLater
from twisted.web import server as web_server
from twisted.names import server as names_server, dns as names_dns
from controllers import dns, http
import model
#########
# Attach method called by tac
##
def expose(application):
def attachDnsController(dns_controller):
#########
# Mammatus is the giver of names, on TCP and UDP.
##
verbosity = 0
tcpFactory = names_server.DNSServerFactory(clients=[dns_controller], verbose=verbosity)
udpFactory = names_dns.DNSDatagramProtocol(tcpFactory)
tcpFactory.noisy = udpFactory.noisy = verbosity
dns_service = service.MultiService()
internet.TCPServer(53, tcpFactory).setServiceParent(dns_service)
internet.UDPServer(53, udpFactory).setServiceParent(dns_service)
dns_service.setServiceParent(application)
def attachHttpController(http_controller):
#########
# Mammatus feeds you, over HTTP.
##
httpFactory = web_server.Site(http_controller)
web_service = internet.TCPServer(80, httpFactory)
web_service.setServiceParent(application)
#########
# Expose Mammia
##
deferDnsController = deferLater(reactor, 0, dns.getController, model)
deferDnsController.addCallback(attachDnsController)
deferHttpController = deferLater(reactor, 0, http.getController, model)
deferHttpController.addCallback(attachHttpController)