def get_lcs_name(): date = vps_util.todaystr() if redis_shell.get(CM + ':lcsserial:date') == date: serial = redis_shell.incr(CM + ':lcsserial') else: pipe = redis_shell.pipeline() pipe.set(CM + ':lcsserial:date', date) pipe.set(CM + ':lcsserial', 1) pipe.execute() serial = 1 return 'fp-%s-%s-%03d' % (CM, date, serial)
def get_lcs_name(req): date = vps_util.todaystr() if redis_shell.get(CM + ':lcsserial:date') == date: serial = redis_shell.incr(CM + ':lcsserial') else: pipe = redis_shell.pipeline() pipe.set(CM + ':lcsserial:date', date) pipe.set(CM + ':lcsserial', 1) pipe.execute() serial = 1 type_prefix = 'obfs4' if 'obfs4_port' in req else 'https' return 'fp-%s-%s-%s-%03d' % (type_prefix, CM, date, serial)
def vpss_from_cm(cm): try: local_version = file(cm + '_vpss_version').read() except IOError: local_version = None remote_version = redis_shell.get(cm + ':vpss:version') if local_version == remote_version: return set(map(str.strip, file(cm + '_vpss'))) else: ret = redis_shell.lrange(cm + ':vpss', 0, -1) file(cm + '_vpss', 'w').write('\n'.join(ret)) file(cm + '_vpss_version', 'w').write(remote_version) return set(ret)
def vpss_from_cm(cm): try: local_version = file(cm + "_vpss_version").read() except IOError: local_version = None remote_version = redis_shell.get(cm + ":vpss:version") if local_version == remote_version: return set(map(str.strip, file(cm + "_vpss"))) else: ret = redis_shell.lrange(cm + ":vpss", 0, -1) file(cm + "_vpss", "w").write("\n".join(ret)) file(cm + "_vpss_version", "w").write(remote_version) return set(ret)
def vpss_from_cm(cm): try: local_version = file(cm + '_vpss_version').read() except IOError: local_version = None remote_version = redis_shell.get(cm + ':vpss:version') if local_version == remote_version: return set(map(str.strip, file(cm + '_vpss'))) else: ret = redis_shell.lrange(cm + ':vpss', 0, -1) file(cm + '_vpss', 'w').write('\n'.join(ret)) file(cm + '_vpss_version', 'w').write(remote_version) return set(ret)
def get_lcs_name(dc, redis_shell): if dc.startswith('vltok'): country = 'jp' elif dc.startswith('doams'): country = 'nl' else: assert False now = datetime.utcnow() date = "%d%02d%02d" % (now.year, now.month, now.day) if redis_shell.get(dc + ':lcsserial:date') == date: serial = redis_shell.incr(dc + ':lcsserial') else: pipe = redis_shell.pipeline() pipe.set(dc + ':lcsserial:date', date) pipe.set(dc + ':lcsserial', 1) pipe.execute() serial = 1 return 'fp-%s-%s-%03d' % (country, date, serial)
def get_lcs_name(dc, redis_shell): if dc.startswith('vltok'): country = 'jp' elif dc.startswith('doams'): country = 'nl' else: assert False now = datetime.utcnow() date = "%d%02d%02d" % (now.year, now.month, now.day) if redis_shell.get(dc + ':lcsserial:date') == date: serial = redis_shell.incr(dc + ':lcsserial') else: pipe = redis_shell.pipeline() pipe.set(dc + ':lcsserial:date', date) pipe.set(dc + ':lcsserial', 1) pipe.execute() serial = 1 return 'fp-%s-%s-%03d' % (country, date, serial)
def extract_opts(args, *names): ret = {} for name in names: try: args.remove('--' + name) ret[name] = True except ValueError: ret[name] = False return ret if __name__ == '__main__': args = sys.argv[:] opts = extract_opts(args, 'json', 'print-name-and-ip') region = None if len(args) == 1: region = rs.get('default-user-region') elif len(args) == 2: region = args[1] if not rs.sismember('user-regions', region): print "Usage: %s [--json] [--print-name-and-ip] [user-region]" % args[0] print "Where region must be one of 'sea' for Southeast Asia (currently, only China) 'ir' for Iran, or 'etc' (default) for anywhere else." print "Options (all default to false):" print " --json: output a format that can be directly read by genconfig." print " --print-name-and-ip: print name and ip of the new proxy, in addition to its config." sys.exit(1) ip, name, cfg = fetch(region) if opts['json']: cfg = tojson(cfg) if opts['print-name-and-ip']: print "\n%s (%s):\n" % (name, ip) print cfg
#!/usr/bin/env python import json import subprocess import yaml from alert import alert from redis_util import redis_shell prefix = 'fallbacks-to-check' try: local_version = file(prefix + '-version').read() except IOError: local_version = None remote_version = redis_shell.get('srvcount') if local_version != remote_version: suppress = redis_shell.smembers('checkfallbacks-suppress') json.dump([yaml.load(cfg).values()[0] for srv, cfg in redis_shell.hgetall('srv->cfg').iteritems() if srv not in suppress], file(prefix + '.json', 'w')) file(prefix + '-version', 'w').write(remote_version) cmd = subprocess.Popen("checkfallbacks -fallbacks %s.json -connections 20 | grep '\[failed fallback check\]'" % prefix, shell=True, stdout=subprocess.PIPE) errors = list(cmd.stdout) if errors: for error in errors: print error