Пример #1
0
Файл: ksp.py Проект: nomada2/KSP
def _first_contact(request, device):
	# triggered actions:
	# - upload config, for debugging purposes (we can check the API urls config in the logs)
	# - update client API urls, customized for the particular client type
	# - upload snapshot -- it will include device serial and model for the kindles
	text = _FIRST_CONTACT \
				.replace('$_SERVER_URL_$', config.server_url(request)) \
				.replace('$_SERVERS_CONFIG_$', _servers_config(request, device))
	return bytes(text, 'UTF-8')
Пример #2
0
Файл: ksp.py Проект: nomada2/KSP
def _servers_config(request, device):
	is_kindle = device.is_kindle()
	server_url = config.server_url(request)
	def _url(x):
		# always drop the last / from the url
		# the kindle devices urls also need to include the service paths (FionaTodoListProxy, FionaCDEServiceEngine, etc)
		# the other clients seem to require urls without those paths
		return (server_url + x.strip('/')) if is_kindle else server_url[:-1]

	# we always need the todo and cde urls
	urls = [ '', 'url.todo=' + _url(TODO_PATH), 'url.cde=' + _url(CDE_PATH) ]

	if is_kindle:
		# cookie domains ensures we get the proper cookie and are able to identify the device
		urls.append('cookie.store.domains=.amazon.com,' + config.server_hostname)
		# we need these urls to intercept registration/deregistration calls,
		# so that we can update the client certificate
		urls.extend((
			'url.firs=' + _url(FIRS_PATH),
			'url.firs.unauth=' + _url(FIRS_PATH),
		))
	else:
		urls.append('url.firs=' + _url(FIRS_PATH))
		# not sure what this is for, but all non-kindle clients seem to have it
		urls.append('url.cde.nossl=' + _url(CDE_PATH))

	# all other clients queue up the logs upload commands
	if not features.allow_logs_upload:
		if is_kindle:
			ignore = config.server_url(request) + 'ksp/ignore'
			urls.extend((
				'url.messaging.post=' + ignore,
				'url.det=' + ignore,
				'url.det.unauth=' + ignore,
			))
		# else:
		# 	urls.extend((
		# 		'url.messaging.post=',
		# 		'url.det=',
		# 		'url.det.unauth=',
		# 	))

	urls.append('')
	return '\n'.join(urls)
Пример #3
0
def _consume_action_queue(request, device, x_items):
    was_updated = False
    while device.actions_queue:
        action = device.actions_queue.pop()
        # logging.debug("checking action %s", action)
        if list(qxml.filter(x_items, 'item', action=action[0],
                            type=action[1])):
            # logging.debug("action %s already found in %s, skipping", action, x_items)
            continue
        if action == 'SET_SCFG':
            _add_item(x_items,
                      'SET',
                      'SCFG',
                      key='KSP.set.scfg',
                      priority=100,
                      body=_servers_config(request, device))
            was_updated = True
        elif action == 'UPLOAD_SNAP':
            _add_item(x_items,
                      'UPLOAD',
                      'SNAP',
                      key='KSP.upload.snap',
                      priority=1000,
                      url=config.server_url(request) +
                      'FionaCDEServiceEngine/UploadSnapshot')
            was_updated = True
        # elif action == 'GET_NAMS':
        # 	_add_item(x_items, 'GET', 'NAMS', key = 'NameChange' if device.is_kindle() else 'AliasChange')
        # 	was_updated = True
        elif action == 'UPLOAD_SCFG':
            _add_item(x_items,
                      'UPLOAD',
                      'SCFG',
                      key='KSP.upload.scfg',
                      priority=50,
                      url=config.server_url(request) + 'ksp/scfg')
            was_updated = True
        elif type(action) == tuple and action[0] == 'ADD_COLLECTION':
            pass
        else:
            logging.warn("unknown action %s", action)
    return was_updated
Пример #4
0
def _consume_action_queue(request, device, x_items):
	was_updated = False
	while device.actions_queue:
		action = device.actions_queue.pop()
		# logging.debug("checking action %s", action)
		if list(qxml.filter(x_items, 'item', action = action[0], type = action[1])):
			# logging.debug("action %s already found in %s, skipping", action, x_items)
			continue
		if action == 'SET_SCFG':
			_add_item(x_items, 'SET', 'SCFG', key = 'KSP.set.scfg', priority = 100, body = _servers_config(request, device))
			was_updated = True
		elif action == 'UPLOAD_SNAP':
			_add_item(x_items, 'UPLOAD', 'SNAP', key = 'KSP.upload.snap', priority = 1000, url = config.server_url(request) + 'FionaCDEServiceEngine/UploadSnapshot')
			was_updated = True
		# elif action == 'GET_NAMS':
		# 	_add_item(x_items, 'GET', 'NAMS', key = 'NameChange' if device.is_kindle() else 'AliasChange')
		# 	was_updated = True
		elif action == 'UPLOAD_SCFG':
			_add_item(x_items, 'UPLOAD', 'SCFG', key = 'KSP.upload.scfg', priority = 50, url = config.server_url(request) + 'ksp/scfg')
			was_updated = True
		elif type(action) == tuple and action[0] == 'ADD_COLLECTION':
			pass
		else:
			logging.warn("unknown action %s", action)
	return was_updated
Пример #5
0
if __disable_procotol_matching:
	logging.warn("disabling protocol matching")
	__server_url_log = __server_url
else:
	__server_url_log = ('http(s)://' if config.server_certificate else 'http://') + __server_url_without_protocol

logging.info("server url [%s]", __server_url_log )

__amazon_hosts = "https://([-a-z7]*).amazon.com/"
logging.info("rewrite rule: %s => %s", __amazon_hosts, __server_url_log)
__amazon_hosts_re = re.compile(__amazon_hosts)
del __amazon_hosts

if config.server_certificate and not __disable_procotol_matching:
	config.server_url = lambda request: ('https://' if request.is_secure() else 'http://') + __server_url_without_protocol
	config.rewrite_rules = lambda request: { __amazon_hosts_re : config.server_url(request) }
else:
	config.server_url = lambda request: __server_url
	config.rewrite_rules = lambda request: { __amazon_hosts_re : __server_url }

del __protocol, __host_and_port, __path, __server_url_log


_loggers = {}
def logger(name, formatted = True, level = logging.NOTSET):
	log = _loggers.get(name)
	if not log:
		log = logging.getLogger(name)
		log.setLevel(level)
		_loggers[name] = log