This commit is contained in:
josemine 2015-02-17 12:41:13 +00:00
commit 28a0e11a43
2 changed files with 8 additions and 17 deletions

0
dev Normal file
View File

View File

@ -88,13 +88,10 @@ Traffic Legend:
# in the form of token: host:port # in the form of token: host:port
# Extract the token parameter from url # Extract the token parameter from url
args = parse_qs(urlparse(path)[4]) # 4 is the query from url token = urlparse(path)[4] # 4 is the query from url
if not token:
if not args.has_key('token') or not len(args['token']):
raise self.EClose("Token not present") raise self.EClose("Token not present")
token = args['token'][0].rstrip('\n')
# target_cfg can be a single config file or directory of # target_cfg can be a single config file or directory of
# config files # config files
if os.path.isdir(target_cfg): if os.path.isdir(target_cfg):
@ -103,18 +100,12 @@ Traffic Legend:
else: else:
cfg_files = [target_cfg] cfg_files = [target_cfg]
targets = {}
for f in cfg_files: for f in cfg_files:
for line in [l.strip() for l in file(f).readlines()]: for line in [l.strip() for l in open(f)]:
if line and not line.startswith('#'): if line and not line.startswith('#'):
ttoken, target = line.split(': ') ftoken, target = line.split(': ')
targets[ttoken] = target.strip() if ftoken == token:
return target.split(':')
self.vmsg("Target config: %s" % repr(targets))
if targets.has_key(token):
return targets[token].split(':')
else:
raise self.EClose("Token '%s' not found" % token) raise self.EClose("Token '%s' not found" % token)
def do_proxy(self, target): def do_proxy(self, target):