示例#1
0
    def __init__(self):
        # Load config dictionaries
        saved = self.__get_config_json()
        default = self.__get_bundle_json()

        # Extract version info
        saved_version = saved['config_version']
        default_version = default['config_version']

        # Get the latest version
        self.config_version: int = default_version

        # Assign json properties to the class instance
        self.__keys = [
            'port', 'log_level', 'start_minimized', 'block_telemetry',
            'use_webmaster', 'delete_cert_on_exit', 'platforms'
        ]

        for key in self.__keys:
            # Try saved value first, otherwise use default
            try:
                self.__setattr__(key, saved[key])
            except KeyError:
                self.__setattr__(key, default[key])

        # Save the new fields
        if saved_version < default_version:
            self.__save_config_file(default_version)

        # Update the log level since we now know the preference
        log.setLevel(getLevelName(self.log_level))
        log.debug(f'Setting log level to {self.log_level}')
示例#2
0
文件: cfg.py 项目: ASzc/nagoya
def mod_aconf(path):
    log.info("Editing {0}".format(path))
    a = aconf.ApacheHttpdConf()
    a.read_file(path)
    yield a
    log.debug("Writing to path {0}".format(path))
    a.write_file(path)
示例#3
0
    def intercept_entitlements(self, flow: HTTPFlow):
        if BaseAddon.host_and_path_match(
                flow,
                host=OriginAddon.api_host,
                path=r"^/ecommerce2/entitlements/\d+$"):  # Real DLC request
            self.patch_origin_client()

            log.info('Intercepted an Entitlements request from Origin ')

            # Get legit user entitlements
            try:
                entitlements: List = json.loads(
                    flow.response.text)['entitlements']
            except KeyError:
                entitlements = []

            # Inject our entitlements
            entitlements.extend(self.injected_entitlements)

            for e in entitlements:
                try:
                    log.debug(f"\t{e['___name']}")
                except KeyError:
                    log.debug(f"\t{e['entitlementTag']}")

            # Modify response
            flow.response.status_code = 200
            flow.response.reason = 'OK'
            flow.response.text = json.dumps({'entitlements': entitlements})

            flow.response.headers.add('X-Origin-CurrentTime', '1609452000')
            flow.response.headers.add('X-Origin-Signature', 'nonce')
示例#4
0
文件: billing.py 项目: cloudant/slapi
def _verify_order(quote_id, order_container):
    order_service = get_service('SoftLayer_Billing_Order_Quote', quote_id)
    log.debug("verifying order for quote %d", quote_id)
    verified_order_container = SoftLayerContainerProductOrder(
        order_service.verifyOrder(order_container._data))
    log.debug("verified order for quote %d", quote_id)
    return verified_order_container
示例#5
0
def _find_vlan(vlan_type, vlan_spec):
    """Return a single public or private vlan matching spec"""
    log.debug("looking up %s vlan %s", vlan_type, vlan_spec)
    vlan_object_mask = build_vlan_object_mask()
    if vlan_type == 'public':
        # Lookup Public VLAN
        vlans = list(
            get_public_vlans(parse_vlan_spec(vlan_spec), vlan_object_mask))
    elif vlan_type == 'private':
        # Lookup Public VLAN
        vlans = list(
            get_private_vlans(parse_vlan_spec(vlan_spec), vlan_object_mask))
    else:
        raise TypeError("Unknown vlan type: %s" % (vlan_type))

    if len(vlans) < 1:
        print error("No vlans found matching spec: %s" % (vlan_spec))
        sys.exit(1)

    if len(vlans) > 1:
        print error("More then one vlan found matching spec: %s. "
                    "Refusing to continue." % (vlan_spec))
        sys.exit(1)

    return vlans[0]
示例#6
0
def download_package(name, dest_file):
    yb = yum.YumBase()
    # YumBase will now load its stuff, which will output annoying startup messages I can't seem to suppress
    pkg = yb.pkgSack.returnNewestByName(name=name)[0]
    pkg_url = pkg._remote_url()
    log.debug("Found URL {0} for package {1}".format(pkg_url, name))
    _download(pkg_url, dest_file)
示例#7
0
def fetch_rpm_file(package, filepath):
    log.debug("Getting file {0} from rpm {1}".format(
        os.path.basename(filepath), package))
    extract_dir = "/tmp/" + package
    rpm_path = "/tmp/" + package + ".rpm"

    log.debug("Downloading")
    download_package(package, rpm_path)
    log.debug("Extracting")
    os.makedirs(extract_dir)

    # Run rpm2cpio into cpio. There is apparently no better way to do this.
    rpm2cpio_cmd = ["rpm2cpio", rpm_path]
    cpio_cmd = ["cpio", "-id"]
    rpm2cpio = subprocess.Popen(rpm2cpio_cmd, stdout=subprocess.PIPE)
    cpio = subprocess.Popen(cpio_cmd, cwd=extract_dir, stdin=rpm2cpio.stdout)
    rpm2cpio.stdout.close()  # Allows rpm2cpio to exit when cpio does
    for p, cmd in [(rpm2cpio, rpm2cpio_cmd), (cpio, cpio_cmd)]:
        code = p.wait()
        if not code == 0:
            raise CalledProcessError(code, cmd)

    extracted_paths = glob.glob(extract_dir + "/" + filepath)
    if len(extracted_paths) > 1:
        log.debug("filepath glob matched more than one file: {0}".format(
            extracted_paths))

    yield extracted_paths[0]

    log.debug("Removing temp files")
    shutil.rmtree(extract_dir)
    os.remove(rpm_path)
示例#8
0
文件: billing.py 项目: cloudant/slapi
def _place_order(quote_id, order_container):
    order_service = get_service('SoftLayer_Billing_Order_Quote', quote_id)
    log.debug("placing order for quote %d", quote_id)
    placed_order_container = SoftLayerContainerProductOrder(
        order_service.placeOrder(order_container._data))
    log.debug("placed order for quote %d", quote_id)
    return placed_order_container
示例#9
0
	def fetch_entitlements_if_necessary(self):
		log.debug('Fetching Origin entitlements')

		# Get the etag
		etag_path = get_data_path('origin-entitlements.etag')
		etag = ''
		if isfile(self.entitlements_path) and isfile(etag_path):
			with open(etag_path, mode='r') as file:
				etag = file.read()

		# Fetch entitlements if etag does not match
		url = 'https://raw.githubusercontent.com/acidicoala/public-entitlements/main/origin/v1/entitlements.json'

		try:
			response = requests.get(url, headers={'If-None-Match': etag}, timeout=10)
		except Exception as e:
			log.error(f"Failed to fetch origin entitlements. {str(e)}")
			return

		if response.status_code == 304:
			log.debug(f'Cached Origin entitlements have not changed')
			return

		if response.status_code != 200:
			log.error(f'Error while fetching entitlements: {response.status_code} - {response.text}')
			return

		try:
			index = 1000000
			entitlements: List[dict] = json.loads(response.text)
			for entitlement in entitlements:
				entitlement.update({
					"entitlementId": index,
					"lastModifiedDate": "2020-01-01T00:00Z",
					"entitlementSource": "ORIGIN-OIG",
					"grantDate": "2020-01-01T00:00:00Z",
					"suppressedBy": [],
					"version": 0,
					"isConsumable": False,
					"productCatalog": "OFB",
					"suppressedOffers": [],
					"originPermissions": "0",
					"useCount": 0,
					"projectId": "123456",
					"status": "ACTIVE"
				})
				index += 1
		except ValueError as e:
			log.error(f"Failed to decode entitlements from json. {str(e)}")
			return

		# Cache entitlements
		with open(self.entitlements_path, 'w') as f:
			f.write(json.dumps(entitlements, indent=4, ensure_ascii=False))

		# Cache etag
		with open(etag_path, 'w') as f:
			f.write(response.headers['etag'])

		log.info('Origin entitlements were successfully fetched and cached')
示例#10
0
文件: billing.py 项目: cloudant/slapi
def _find_vlan(vlan_type, vlan_spec):
    """Return a single public or private vlan matching spec"""
    log.debug("looking up %s vlan %s", vlan_type, vlan_spec)
    vlan_object_mask = build_vlan_object_mask()
    if vlan_type == 'public':
        # Lookup Public VLAN
        vlans = list(get_public_vlans(
            parse_vlan_spec(vlan_spec), vlan_object_mask))
    elif vlan_type == 'private':
        # Lookup Public VLAN
        vlans = list(get_private_vlans(
            parse_vlan_spec(vlan_spec), vlan_object_mask))
    else:
        raise TypeError("Unknown vlan type: %s" % (vlan_type))

    if len(vlans) < 1:
        print error("No vlans found matching spec: %s" % (vlan_spec))
        sys.exit(1)

    if len(vlans) > 1:
        print error("More then one vlan found matching spec: %s. "
                    "Refusing to continue." % (vlan_spec))
        sys.exit(1)

    return vlans[0]
示例#11
0
def mod_aconf(path):
    log.info("Editing {0}".format(path))
    a = aconf.ApacheHttpdConf()
    a.read_file(path)
    yield a
    log.debug("Writing to path {0}".format(path))
    a.write_file(path)
示例#12
0
文件: pkg.py 项目: ASzc/nagoya
def download_package(name, dest_file):
    yb = yum.YumBase()
    # YumBase will now load its stuff, which will output annoying startup messages I can't seem to suppress
    pkg = yb.pkgSack.returnNewestByName(name=name)[0]
    pkg_url = pkg._remote_url()
    log.debug("Found URL {0} for package {1}".format(pkg_url, name))
    _download(pkg_url, dest_file)
示例#13
0
    def fetch_entitlements_if_necessary(self):
        log.debug('Fetching origin entitlements')

        # Get the etag
        etag_path = get_data_path('origin-entitlements.etag')
        etag = ''
        if isfile(self.entitlements_path) and isfile(etag_path):
            with open(etag_path, mode='r') as file:
                etag = file.read()

        # Fetch entitlements if etag does not match
        url = 'https://raw.githubusercontent.com/acidicoala/origin-entitlements/master/entitlements.json'
        response = requests.get(url, headers={'If-None-Match': etag})

        if response.status_code == 304:
            log.debug(f'Cached Origin entitlements have not changed')
            return

        if response.status_code != 200:
            log.error(
                f'Error while fetching entitlements: {response.status_code} - {response.text}'
            )
            return

        # Cache entitlements
        with open(self.entitlements_path, 'w') as f:
            f.write(response.text)

        # Cache etag
        with open(etag_path, 'w') as f:
            f.write(response.headers['etag'])

        log.info('Origin entitlements were successfully fetched and cached')
示例#14
0
def _get_hardware_object_mask(properties):
    """Return an object mask for the given list of propeties"""
    default_mask = {'datacenter': {}, 'hardwareStatus': {}}
    object_mask = default_mask
    for prop in properties:
        log.debug("getting hardware object mask for %s", prop)
        if prop in ['processor', 'proc', 'cpu', 'cpus']:
            object_mask['processors'] = {}
        elif prop in ['drives', 'disks', 'disk']:
            object_mask['hardDrives'] = {}
        elif prop in ['memory', 'mem']:
            object_mask['memory'] = {}
        elif prop in ['raid']:
            object_mask['raidControllers'] = {}
        elif prop in ['nic', 'nics']:
            object_mask['networkComponents'] = {'primarySubnet': {'networkVlan': {'primaryRouter': {}, 'secondaryRouter': {}}}}
        elif prop in ['pwr', 'powersupply']:
            object_mask['powerSupply'] = {}
        elif prop in ['mobo', 'motherboard']:
            object_mask['motherboard'] = {}
        else:
            print error("Unknown hardware property: %s" % (prop))
            sys.exit(1)
    log.debug("hardware object mask: %s", object_mask)
    return object_mask
示例#15
0
    def read_entitlements_from_cache(self):
        log.debug('Reading origin entitlements from cache')

        with open(self.entitlements_path, mode='r') as file:
            self.injected_entitlements = json.loads(file.read())

        log.info('Origin entitlements were successfully read from file')
示例#16
0
def _verify_order(quote_id, order_container):
    order_service = get_service('SoftLayer_Billing_Order_Quote', quote_id)
    log.debug("verifying order for quote %d", quote_id)
    verified_order_container = SoftLayerContainerProductOrder(
        order_service.verifyOrder(order_container._data))
    log.debug("verified order for quote %d", quote_id)
    return verified_order_container
示例#17
0
文件: pkg.py 项目: ASzc/nagoya
def fetch_rpm_file(package, filepath):
    log.debug("Getting file {0} from rpm {1}".format(os.path.basename(filepath), package))
    extract_dir = "/tmp/" + package
    rpm_path = "/tmp/" + package + ".rpm"

    log.debug("Downloading")
    download_package(package, rpm_path)
    log.debug("Extracting")
    os.makedirs(extract_dir)

    # Run rpm2cpio into cpio. There is apparently no better way to do this.
    rpm2cpio_cmd = ["rpm2cpio", rpm_path]
    cpio_cmd = ["cpio", "-id"]
    rpm2cpio = subprocess.Popen(rpm2cpio_cmd, stdout=subprocess.PIPE)
    cpio = subprocess.Popen(cpio_cmd, cwd=extract_dir, stdin=rpm2cpio.stdout)
    rpm2cpio.stdout.close() # Allows rpm2cpio to exit when cpio does
    for p,cmd in [(rpm2cpio, rpm2cpio_cmd), (cpio, cpio_cmd)]:
        code = p.wait()
        if not code == 0:
            raise CalledProcessError(code, cmd)

    extracted_paths = glob.glob(extract_dir + "/" + filepath)
    if len(extracted_paths) > 1:
        log.debug("filepath glob matched more than one file: {0}".format(extracted_paths))

    yield extracted_paths[0]

    log.debug("Removing temp files")
    shutil.rmtree(extract_dir)
    os.remove(rpm_path)
示例#18
0
def _place_order(quote_id, order_container):
    order_service = get_service('SoftLayer_Billing_Order_Quote', quote_id)
    log.debug("placing order for quote %d", quote_id)
    placed_order_container = SoftLayerContainerProductOrder(
        order_service.placeOrder(order_container._data))
    log.debug("placed order for quote %d", quote_id)
    return placed_order_container
示例#19
0
def mod_between(path):
    mods = []
    yield mods
    log.debug("Applying {0} modifications to path {1}".format(len(mods), path))
    with mod_text(path) as lines:
        for lineno, line in enumerate(lines):
            for mod in mods:
                lines[lineno] = mod.process(line)
示例#20
0
def mod_text(path):
    log.info("Editing {0}".format(path))
    with open(path, "r") as f:
        lines = list(f.readlines())
    yield lines
    log.debug("Writing to path {0}".format(path))
    with open(path, "w") as f:
        f.write("".join(lines))
示例#21
0
文件: cfg.py 项目: ASzc/nagoya
def mod_between(path):
    mods = []
    yield mods
    log.debug("Applying {0} modifications to path {1}".format(len(mods), path))
    with mod_text(path) as lines:
        for lineno,line in enumerate(lines):
            for mod in mods:
                lines[lineno] = mod.process(line)
示例#22
0
def _get_quote_product_orders(quote_id, mask):  # pylint: disable-msg=C0103
    """Generator returning all product order containers for the given quote"""
    quote_service = get_service('SoftLayer_Billing_Order_Quote', quote_id)
    quote_service.set_object_mask(mask)
    log.debug("fetching order container for quote id %d", quote_id)
    quote_container = quote_service.getRecalculatedOrderContainer()
    for product_order_container in quote_container['orderContainers']:
        yield SoftLayerContainerProductOrder(product_order_container)
示例#23
0
文件: cfg.py 项目: ASzc/nagoya
def mod_text(path):
    log.info("Editing {0}".format(path))
    with open(path, "r") as f:
        lines = list(f.readlines())
    yield lines
    log.debug("Writing to path {0}".format(path))
    with open(path, "w") as f:
        f.write("".join(lines))
示例#24
0
文件: billing.py 项目: cloudant/slapi
def _get_quote_product_orders(quote_id, mask):  # pylint: disable-msg=C0103
    """Generator returning all product order containers for the given quote"""
    quote_service = get_service('SoftLayer_Billing_Order_Quote', quote_id)
    quote_service.set_object_mask(mask)
    log.debug("fetching order container for quote id %d", quote_id)
    quote_container = quote_service.getRecalculatedOrderContainer()
    for product_order_container in quote_container['orderContainers']:
        yield SoftLayerContainerProductOrder(product_order_container)
示例#25
0
	def patch_origin_client(self):
		origin = Client('Origin', 'Origin.exe', 'libeay32.dll', 'EVP_DigestVerifyFinal')
		eadesktop = Client('EA Desktop', 'EADesktop.exe', 'libcrypto-1_1-x64.dll', 'EVP_DigestVerifyFinal')

		client = origin

		try:
			client_process = Pymem(client.PROCESS_NAME)
		except ProcessNotFound:
			client = eadesktop
			try:
				client_process = Pymem(client.PROCESS_NAME)
			except ProcessNotFound:
				log.warning('Origin/EA Desktop process not found. Patching aborted')
				return

		if client_process.process_id == self.last_client_pid:
			log.debug(f'{client.NAME} client is already patched')
			return

		log.info(f'Patching {client.NAME} client')

		try:
			dll_module = next(m for m in client_process.list_modules() if m.name.lower() == client.DLL_NAME)
		except StopIteration:
			log.error(f'{client.DLL_NAME} is not loaded. Patching aborted')
			return

		# The rest should complete without issues in most cases.

		# Get the Export Address Table symbols
		# noinspection PyUnresolvedReferences
		dll_symbols = PE(dll_module.filename).DIRECTORY_ENTRY_EXPORT.symbols

		# Get the symbol of the EVP_DigestVerifyFinal function
		verify_func_symbol = next(s for s in dll_symbols if s.name.decode('ascii') == client.FUNCTION_NAME)

		# Calculate the final address in memory
		verify_func_addr = dll_module.lpBaseOfDll + verify_func_symbol.address

		# Instructions to patch. We return 1 to force successful response validation.
		patch_instructions = bytes([
			0x66, 0xB8, 0x01, 0,  # mov ax, 0x1
			0xC3  # ret
		])
		client_process.write_bytes(verify_func_addr, patch_instructions, len(patch_instructions))

		# Validate the written memory
		read_instructions = client_process.read_bytes(verify_func_addr, len(patch_instructions))

		if read_instructions != patch_instructions:
			log.error('Failed to patch the instruction memory')
			return

		# At this point we know that patching was successful

		self.last_client_pid = client_process.process_id
		log.info(f'Patching {client.NAME} was successful')
示例#26
0
文件: pkg.py 项目: ASzc/nagoya
def install(packages):
    if isinstance(packages, list):
        log.debug("Installing packages: {0}".format(packages))
        package_list = packages
    else:
        log.debug("Installing package: {0}".format(packages))
        package_list = [packages]

    subprocess.check_call(["yum", "-y", "install"] + package_list)
示例#27
0
文件: cfg.py 项目: ASzc/nagoya
def mod_ini(path):
    log.info("Editing {0}".format(path))
    with open(path, "r") as f:
        ini_data = iniparse.INIConfig(f)
    yield ini_data
    # Printing is the only way the library supports writing
    log.debug("Writing to path {0}".format(path))
    with open(path, "w") as f:
        print(ini_data, end="", file=f)
示例#28
0
def mod_ini(path):
    log.info("Editing {0}".format(path))
    with open(path, "r") as f:
        ini_data = iniparse.INIConfig(f)
    yield ini_data
    # Printing is the only way the library supports writing
    log.debug("Writing to path {0}".format(path))
    with open(path, "w") as f:
        print(ini_data, end="", file=f)
示例#29
0
def install(packages):
    if isinstance(packages, list):
        log.debug("Installing packages: {0}".format(packages))
        package_list = packages
    else:
        log.debug("Installing package: {0}".format(packages))
        package_list = [packages]

    subprocess.check_call(["yum", "-y", "install"] + package_list)
示例#30
0
文件: sql.py 项目: ASzc/nagoya
def commands(user, database):
    sql_commands = []
    yield sql_commands
    sql = ";\n".join(sql_commands)

    log.debug("Running {0} sql commands as user {1} against database {2}".format(len(sql_commands), user, database))
    cmd = ["psql", database, user, "-f"]
    p = multiprocessing.Process(target=_exec_with_tempfile_as, args=(user, cmd, sql))
    p.start()
    p.join()
    if not p.exitcode == 0:
        raise Exception("Running sql commands failed, see above trace")
示例#31
0
def install_cert():
    log.warning('Installing mitmproxy certificate...')

    # Init dummy config to generate the certificate
    ProxyConfig(Options())
    crtPath = Path.home().joinpath('.mitmproxy', 'mitmproxy-ca-cert.cer')
    log.debug(f'certificate path: "{crtPath}"')

    if error_code := subprocess.call(
            f'certutil -addstore -user Root "{crtPath}"', shell=True):
        log.error(
            f'Certificate could not be installed: {hex(error_code)} - {str(FormatMessage(error_code)).strip()}'
        )
        # noinspection PyProtectedMember,PyUnresolvedReferences
        os._exit(1)
示例#32
0
    def intercept_entitlements(self, flow: HTTPFlow):
        if BaseAddon.host_and_path_match(
                flow,
                host=OriginAddon.api_host,
                path=r"^/ecommerce2/entitlements/\d+$"):  # Real DLC request
            self.patch_origin_client()

            log.info('Intercepted an Entitlements request from Origin ')

            xml_mode = 'application/xml' in flow.response.headers[
                'content-type']
            # Get legit user entitlements
            if xml_mode:
                entitlements: List = xml2entitlements(flow.response.text)
            else:
                try:
                    entitlements: List = json.loads(
                        flow.response.text)['entitlements']
                except KeyError:
                    entitlements = []

            # Inject our entitlements
            entitlements.extend(self.injected_entitlements)

            # Filter out blacklisted DLCs
            blacklist = [
                game['id'] for game in config.platforms['origin']['blacklist']
            ]
            entitlements = [
                e for e in entitlements if e['entitlementTag'] not in blacklist
            ]

            for e in entitlements:
                try:
                    log.debug(f"\t{e['___name']}")
                except KeyError:
                    log.debug(f"\t{e['entitlementTag']}")

            # Modify response
            flow.response.status_code = 200
            flow.response.reason = 'OK'
            if xml_mode:
                flow.response.content = entitlements2xml(entitlements)
            else:
                flow.response.text = json.dumps({'entitlements': entitlements})

            flow.response.headers.add('X-Origin-CurrentTime', '1609452000')
            flow.response.headers.add('X-Origin-Signature', 'nonce')
示例#33
0
	def intercept_ownership(flow: HTTPFlow):
		if BaseAddon.host_and_path_match(
				flow,
				host=EpicAddon.api_host,
				path=r"^/epic/ecom/v1/platforms/EPIC/identities/\w+/ownership$"
		):
			log.info('Intercepted an Ownership request from Epic Games')

			url = urlparse(flow.request.url)
			params = parse_qs(url.query)['nsCatalogItemId']

			# Each nsCatalogItemId is formatted as '{namespace}:{item_id}'
			[log.debug(f'\t{param}') for param in params]

			def process_game(param: str):
				namespace, itemID = param.split(':')
				game = get_epic_game(namespace)
				blacklist = [dlc['id'] for dlc in game['blacklist']] if game is not None else []
				owned = True if game is None else itemID not in blacklist
				return {
					'namespace': namespace,
					'itemId': itemID,
					'owned': owned,
				}

			result = [process_game(param) for param in params]

			EpicAddon.modify_response(flow, result)
示例#34
0
	def intercept_entitlements(flow: HTTPFlow):
		if BaseAddon.host_and_path_match(
				flow, host=EpicAddon.ecom_host,
				path=r"^/ecommerceintegration/api/public/v2/identities/\w+/entitlements$"
		) or BaseAddon.host_and_path_match(
				flow, host=EpicAddon.api_host,
				path=r"^/epic/ecom/v1/identities/\w+/entitlements"
		):
			log.info('Intercepted an Entitlements request from Epic Games')

			url = urlparse(flow.request.url)
			sandbox_id = parse_qs(url.query)['sandboxId'][0]

			# Get the game in the config with namespace that matches the sandboxId
			game = get_epic_game(sandbox_id)

			try:
				# Get the entitlements from request params
				entitlementNames = parse_qs(url.query)['entitlementName']
			except KeyError:
				log.warning(
						'No entitlement names were provided, '
						'responding with entitlements defined in the config file'
				)

				# Get the game's entitlements
				entitlements = game['entitlements'] if game is not None and 'entitlements' in game else []

				# Map the list of objects to the list of string
				entitlementNames = [entitlement['id'] for entitlement in entitlements]

			[log.debug(f'\t{sandbox_id}:{entitlement}') for entitlement in entitlementNames]

			# Filter out blacklisted entitlements
			blacklist = [dlc['id'] for dlc in game['blacklist']] if game is not None and 'blacklist' in game else []
			entitlementNames = [e for e in entitlementNames if e not in blacklist]

			injected_entitlements: List[EpicEntitlement] = [{
				'id': entitlementName,  # Not true, but irrelevant
				'entitlementName': entitlementName,
				'namespace': sandbox_id,
				'catalogItemId': entitlementName,
				'entitlementType': "AUDIENCE",
				'grantDate': "2021-01-01T00:00:00.000Z",
				'consumable': False,
				'status': "ACTIVE",
				'useCount': 0,
				'entitlementSource': "LauncherWeb"
			} for entitlementName in entitlementNames]

			log.info(f'Injecting {len(injected_entitlements)} entitlements')

			original_entitlements: List[EpicEntitlement] = json.loads(flow.response.text)

			merged_entitlements = original_entitlements + injected_entitlements

			EpicAddon.modify_response(flow, merged_entitlements)
示例#35
0
    def intercept_products(self, flow: HTTPFlow):
        if BaseAddon.host_and_path_match(
                flow, host=self.api_host, path=r"^/ecommerce2/products$"
        ):  # Just for store page, no effect in game
            log.info('Intercepted a Products request from Origin')
            tree = ElementTree.fromstring(flow.response.text)

            for elem in tree.iter():
                if elem.tag == 'offer':
                    log.debug(f"\t{elem.attrib['offerId']}")
                elif elem.tag == 'isOwned':
                    elem.text = 'true'
                elif elem.tag == 'userCanPurchase':
                    elem.text = 'false'

            flow.response.status_code = 200
            flow.response.reason = "OK"
            flow.response.text = ElementTree.tostring(tree, encoding='unicode')
示例#36
0
	def block_playtime(flow: HTTPFlow):
		if config.block_playtime and flow.request.path.startswith('/library/api/public/playtime/'):
			original_playtime = json.loads(flow.request.text)
			flow.request.text = '{}'  # Just in case

			correlation_id = flow.request.headers.get('X-Epic-Correlation-ID')
			if m := re.match(r"UE4-(\w+)", correlation_id):
				device_id = m.group(1)
			else:
				device_id = '123456789abcdef01234567890abcdef'

			flow.response = HTTPResponse.make(204)
			flow.response.headers.add('x-epic-device-id', device_id)
			flow.response.headers.add('x-epic-correlation-id', correlation_id)
			flow.response.headers.add('x-envoy-upstream-service-time', '10')  # ?
			flow.response.headers.add('server', 'istio-envoy')

			log.info('Blocked playtime request from Epic Games')
			log.debug(f'\n{json.dumps(original_playtime, indent=4)}')
示例#37
0
def try_download_image(base_url, img_dir, save_dir, img, exts):
    log.add()
    res = False
    for i, ext in enumerate(exts):
        img_path = Path(img_dir) / f'{img}{ext}'
        img_url = urljoin(base_url, img_path.as_posix())
        file = save_dir / f'{img}{ext}'
        try:
            if not i:
                log.debug(f'Trying to save {img_url} as {file.as_posix()}')
            else:
                log.add().debug(f'Retrying with {ext}... ').sub()
            download_image(img_url, file)
            log.info(f'Saved {file.as_posix()}')
            res = True
        except HTTPError as e:
            log.add().debug(f'{str(e)}: {file.as_posix()}').sub()
    log.sub()
    return res
示例#38
0
    def startServer(self):
        app = tornado.web.Application(
            handlers=[(r"/msg", send_message.SendMessageHandler,
                       dict(initializer=None)),
                      (r"/test", send_message.IndexHandler)],
            template_path=os.path.join(os.path.dirname(__file__), "template"))

        http_server = tornado.httpserver.HTTPServer(app)
        http_server.bind(self.port)
        #MUST BY 1, for threading share data
        process_num = 5
        log.debug("Started Server, port={}".format(self.port))

        http_server.start(process_num if process_num > 0 else 1)
        log.debug("process_num:%s, current_pid:%d" %
                  (process_num, multiprocessing.current_process().pid))
        try:
            tornado.ioloop.IOLoop.instance().start()
        except Exception as e:
            sys.stderr.write("Exception: {}".format(e))
示例#39
0
def is_up(hostname, port, timeout=2):
    log.debug("Trying connect to {0}:{1}".format(hostname, port))
    try:
        _attempt(hostname, port, timeout)
        log.debug("Connected to {0}:{1}".format(hostname, port))
        return True
    except socket.error as e:
        log.debug("Failed to connect to {0}:{1}".format(hostname, port))
        return False
示例#40
0
	def intercept_entitlements(flow: HTTPFlow):
		if BaseAddon.host_and_path_match(
				flow,
				host=EpicAddon.ecom_host,
				path=r"^/ecommerceintegration/api/public/v2/identities/\w+/entitlements$"
		):
			log.info('Intercepted an Entitlements request from Epic Games')

			url = urlparse(flow.request.url)
			sandbox_id = parse_qs(url.query)['sandboxId'][0]

			try:
				# Get the entitlements from request params
				entitlementNames = parse_qs(url.query)['entitlementName']
			except KeyError:
				log.warning(
						'No entitlement names were provided, '
						'responding with entitlements defined in the config file'
				)

				# Get the game in the config with namespace that matches the sandboxId
				game = next((game for game in config.platforms['epic'] if game['namespace'] == sandbox_id), None)

				# Get the game's entitlements
				entitlements = game['entitlements'] if game is not None else []

				# Map the list of objects to the list of string
				entitlementNames = [entitlement['id'] for entitlement in entitlements]

			[log.debug(f'\t{sandbox_id}:{entitlement}') for entitlement in entitlementNames]

			result = [{
				'id': entitlementName,  # Not true, but irrelevant
				'entitlementName': entitlementName,
				'namespace': sandbox_id,
				'catalogItemId': entitlementName,
				'entitlementType': "AUDIENCE",
				'grantDate': "2021-01-01T00:00:00.000Z",
				'consumable': False,
				'status': "ACTIVE",
				'useCount': 0,
				'entitlementSource': "eos"
			} for entitlementName in entitlementNames]

			EpicAddon.modify_response(flow, result)
示例#41
0
文件: service.py 项目: cloudant/slapi
def get_objects(service_name, service_method_name, spec, mask):
    """Generator returning all objects for from a SoftLayer service"""
    account_service = get_service('SoftLayer_Account')
    account_service.set_object_mask(None)
    log.debug("fetching all objects from %s.%s", 'SoftLayer_Account_Service',
              service_method_name)
    objects = account_service.__getattr__(service_method_name)()
    log.debug("found %d objects, filter`ing with %s", len(objects), spec)
    for obj in filter(spec, objects):
        log.debug("fetching object id %d", obj['id'])
        service = get_service(service_name, obj['id'])
        service.set_object_mask(mask)
        yield service.getObject()
示例#42
0
文件: remote.py 项目: sbadakhc/nagoya
def wait_up(hostname, port, attempts=10, timeout=2, wait=2):
    log.debug("Trying {0} times to connect to {1}:{2}".format(attempts, hostname, port))
    attempt = 0
    while True:
        attempt += 1
        try:
            _attempt(hostname, port, timeout)
            log.debug("Connected to {0}:{1}".format(hostname, port))
            break
        except socket.error as e:
            log.debug("Connection to {0}:{1} failed (attempt {2}/{3}): {4}".format(hostname, port, attempt, attempts, e))
            if attempt >= attempts:
                # Python 2 has wierd exception stuff, just re-raise rather than wrap in AttemptsExhausted exception
                raise
            time.sleep(wait)
示例#43
0
	def intercept_ownership(flow: HTTPFlow):
		if BaseAddon.host_and_path_match(
				flow,
				host=EpicAddon.api_host,
				path=r"^/epic/ecom/v1/platforms/EPIC/identities/\w+/ownership$"
		):
			log.info('Intercepted an Ownership request from Epic Games')

			url = urlparse(flow.request.url)
			params = parse_qs(url.query)['nsCatalogItemId']

			# Each nsCatalogItemId is formatted as '{namespace}:{item_id}'
			[log.debug(f'\t{param}') for param in params]

			result = [{
				'namespace': param.split(':')[0],
				'itemId': param.split(':')[1],
				'owned': True
			} for param in params]

			EpicAddon.modify_response(flow, result)
示例#44
0
文件: demote.py 项目: ASzc/nagoya
def to_username(username):
    uid, gid = get_user_ids(username)
    log.debug("Creating function to demote to user {0}, uid {1}, gid {2}".format(username, uid, gid))
    return to_id(uid, gid)
示例#45
0
文件: system.py 项目: ASzc/nagoya
def chkconfig(name, state):
    log.debug("Service {0} to startup state {1}".format(name, state))
    subprocess.check_call(["chkconfig", name, target])
示例#46
0
文件: system.py 项目: ASzc/nagoya
def add_system_user(username):
    log.debug("Adding system user: {0}".format(username))
    subprocess.check_call(["useradd", "-r", username])
示例#47
0
文件: system.py 项目: ASzc/nagoya
def run_as(username, cmd):
    log.debug("Calling {0} as user {1}".format(username, cmd))
    subprocess.check_call(cmd, preexec_fn=util.demote.to_username(username))
示例#48
0
文件: system.py 项目: ASzc/nagoya
def service(name, target):
    log.debug("Service {0} to target {1}".format(name, target))
    subprocess.check_call(["service", name, target])
示例#49
0
文件: pkg.py 项目: ASzc/nagoya
def _download(url, file_path):
    log.debug("Downloading URL {0} to file {1}".format(url, file_path))
    # Python 2 urlopen is not closeable
    response = urlopen(url)
    with open(file_path, "wb") as out_file:
        shutil.copyfileobj(response, out_file)
示例#50
0
文件: pkg.py 项目: ASzc/nagoya
def update():
    log.debug("Updating all")
    subprocess.check_call(["yum", "-y", "update"])
示例#51
0
文件: pkg.py 项目: ASzc/nagoya
def clean():
    log.debug("Cleaning all")
    subprocess.check_call(["yum", "clean", "all"])
示例#52
0
 def runTimed(self, f, *args, **kwargs):
     log.debug("Starting new timed thread for function %s" % f)
     t = BroTimedThread(f, args, kwargs)
     self.threads.append(t)
     t.start()
     return t
示例#53
0
文件: billing.py 项目: cloudant/slapi
def orderquote(args):
    """Place an order from an existing quote

    Usage: slapi billing orderquote [options] <quote_spec> <hostname> <domain>

    Options:
        --network-public-vlan VLAN_SPEC
        --network-private-vlan VLAN_SPEC
        -h, --help
    """
    # Parse Quote Spec
    quote_spec = parse_quote_spec(args['<quote_spec>'])
    # TODO: Build Object Mask
    object_mask = None

    # Get Quotes
    quotelist = list(get_quotes(quote_spec, object_mask))
    if len(quotelist) < 1:
        print warning("No quotes found matching spec: %s." % (
            args['<quote_spec>']))
        sys.exit(1)
    if len(quotelist) > 1:
        print error("More then one quote matching spec: %s. "
                    "Refusing to continue." % args['<quote_spec>'])
        sys.exit(1)

    # Get Quote
    quote = quotelist[0]
    log.debug("found quote: %d, name: %s, key: %s", quote.id,
              quote.name,
              quote.key)

    # Get Orders Containers
    order_containers = list(_get_quote_product_orders(quote.id, None))
    if len(order_containers) < 0:
        print error("Quote %d contains no product orders." % (quote.id))
        sys.exit(1)
    if len(order_containers) > 1:
        print error("Quote %d contains more then one product orders."
                    "Refusing to continue." % (quote.id))
        sys.exit(1)
    order_container = order_containers[0]

    # Get VLAN information
    if args['--network-public-vlan']:
        public_vlan = _find_vlan('public', args['--network-public-vlan'])
    else:
        public_vlan = None
    if args['--network-private-vlan']:
        private_vlan = _find_vlan('private', args['--network-private-vlan'])
    else:
        private_vlan = None

    # Check public vlan location
    if public_vlan and \
            public_vlan.primary_router.datacenter.id != order_container.location.id:
        print error("Public VLAN %d does not appear to be in %s." % (
            public_vlan.vlan, order_container.location.name))
        sys.exit(1)

    # Check private vlan location
    if private_vlan and \
            private_vlan.primary_router.datacenter.id != order_container.location.id:
        print error("Private VLAN %d does not appear to be in %s." % (
            public_vlan.vlan, order_container.location.name))
        sys.exit(1)

    # Set order type
    order_container._data['complexType'] = \
        'SoftLayer_Container_Product_Order_Hardware_Server'

    # Get order hardware
    hardware = order_container._data['hardware'][0]

    # Update order information
    hardware['hostname'] = args['<hostname>']
    hardware['domain'] = args['<domain>']

    # Configure VLANs
    if public_vlan:
        hardware['primaryNetworkComponent']['networkVlanId'] = \
            public_vlan.id
    if private_vlan:
        hardware['primaryBackendNetworkComponent']['networkVlanId'] = \
            private_vlan.id

    # Verify order
    _verify_order(quote.id, order_container)

    # Print Order Information

    print colored("Quote:", fg='green', style='bright')
    print quote.format()

    server_name = ".".join([args['<hostname>'], args['<domain>']])
    print colored("Public VLAN:", fg='green', style='bright')
    if public_vlan:
        print public_vlan.format()
    else:
        print "Default"
    print colored("Private VLAN:", fg='green', style='bright')
    if private_vlan:
        print private_vlan.format()
    else:
        print "Default"

    print colored("Order:", fg='green', style='bright')
    print order_container.format()

    print critical("You are about to order a server: %s." % (server_name),
                   label="WARNING: ")
    print critical("Monthly Cost: %s %s, Setup Cost: %s %s" % (
        order_container.currency_type,
        order_container.post_tax_recurring_charge,
        order_container.currency_type,
        order_container.post_tax_setup_charge), label="WARNING: ")
    if confirm(colored("Are you sure you want to continue?",
                       fg='red',
                       style='bright')):
        # Place Order
        _place_order(quote.id, order_container)
        print colored("Order Placed", fg='green', style='bright')
        return
示例#54
0
文件: sql.py 项目: ASzc/nagoya
def init_db():
    new_env = os.environ.copy()
    new_env["PGDATA"] = "/var/lib/pgsql/data"
    log.debug("Calling initdb as user postgres with PGDATA={0}".format(new_env["PGDATA"]))
    subprocess.check_call(["initdb"], env=new_env, preexec_fn=util.demote.to_username("postgres"))
示例#55
0
文件: sql.py 项目: ASzc/nagoya
def exec_file(user, database, path):
    cmd = ["psql", database, user, "-f", path]
    log.debug("Running sql file {0} as user {1} against database {2}".format(path, user, database))
    subprocess.check_call(cmd, preexec_fn=util.demote.to_username(user))