3 from twisted
.web
.server
import Site
4 from twisted
.web
.resource
import Resource
5 from twisted
.web
.server
import NOT_DONE_YET
6 from twisted
.internet
import reactor
15 r
= ipaddress
.IPv4Address(input)
16 except AddressValueError
:
17 r
= ipaddress
.IPv6Address(input)
22 r
= ipaddress
.IPv4Network(input)
23 except NetworkValueError
:
24 r
= ipaddress
.IPv6Network(input)
34 max_batch_down: 262144
41 # instance data members
44 self
.pw
= cfg
.get(cs
, 'password')
48 for k
in ('max_batch_down','max_queue_time','max_request_time'):
49 req
= cfg
.getint(cs
, k
)
50 limit
= cfg
.getint('global',k
)
51 self
.cfg
[k
] = min(req
, limit
)
53 def process_arriving_data(d
):
60 network
= ipnetwork(cfg
.get('virtual','network'))
62 ourself
= cfg
.get('virtual','server')
63 except ConfigParser
.NoOptionError
:
64 ourself
= network
.hosts().next()
66 for cs
in cfg
.sections():
67 if not (':' in cs
or '.' in cs
): continue
70 raise ValueError('client %s not in network' % ci
)
72 raise ValueError('multiple client cfg sections for %s' % ci
)
73 clients
[ci
] = Client(ci
, cs
)
75 class FormPage(Resource
):
76 def render_POST(self
, request
):
77 # find client, update config, etc.
78 ci
= ipaddress(request
.args
['i'])
80 pw
= request
.args
['pw']
81 if pw
!= c
.pw
: raise ValueError('bad password')
84 for r
, w
in (('mbd', 'max_batch_down'),
85 ('mqt', 'max_queue_time'),
86 ('mrt', 'max_request_time')):
87 try: v
= request
.args
[r
]
88 except KeyError: continue
92 try: d
= request
.args
['d']
93 except KeyError: d
= ''
95 c
.process_arriving_data(d
)