View | Details | Raw Unified | Return to bug 51996 | Differences between
and this patch

Collapse All | Expand All

(-)univention-appcenter-control.new (-18 / +7 lines)
 Lines 310-316    Link Here 
310
310
311
	def __init__(self):
311
	def __init__(self):
312
		super(SelfserviceAction, self).__init__()
312
		super(SelfserviceAction, self).__init__()
313
		self._cookiejar = None
313
		self._username = None
314
		self._password = None
314
315
315
	def setup_parser(self, parser):
316
	def setup_parser(self, parser):
316
		try:
317
		try:
 Lines 336-346    Link Here 
336
			raise Abort('Unrecoverable result: %r' % result)
337
			raise Abort('Unrecoverable result: %r' % result)
337
338
338
	def _login(self, args):
339
	def _login(self, args):
339
		username = self._get_username(args)
340
		self._username = self._get_username(args)
340
		password = self._get_password(args)
341
		self._password = self._get_password(args)
341
		self._cookiejar = NamedTemporaryFile()
342
		result = self.curl(args, 'auth', username=username, password=password)
343
		self._get_result(result)
344
		result = self.command(args, 'api')
342
		result = self.command(args, 'api')
345
		remote_api_level = self._get_result(result)
343
		remote_api_level = self._get_result(result)
346
		if remote_api_level != self.API_LEVEL:
344
		if remote_api_level != self.API_LEVEL:
 Lines 368-384    Link Here 
368
		if not args:
366
		if not args:
369
			args.extend(['-X', 'POST'])
367
			args.extend(['-X', 'POST'])
370
			args.extend(['-H', 'Content-Length: 0'])
368
			args.extend(['-H', 'Content-Length: 0'])
371
		umc_session_id = None
372
		with open(self._cookiejar.name) as cookie_file:
373
			# hopefully, cookie jar format does not change with different libcurl versions...
374
			for line in cookie_file:
375
				match = re.match(r'(.*)\t(.*)\t(.*)\t(.*)\t(.*)\tUMCSessionId\t(.*)', line)
376
				if match:
377
					umc_session_id = match.groups()[-1]
378
		if umc_session_id:
379
			args.extend(['-H', 'X-Xsrf-Protection: %s' % umc_session_id])
380
369
381
		args = ['curl', '--cookie', self._cookiejar.name, '--cookie-jar', self._cookiejar.name, '-H', 'X-Requested-With: XmlHttpRequest', '-H', 'Accept: application/json; q=1'] + args + [uri]
370
		args = ['curl', '--basic', '--user', '%s:%s' % (self._username, self._password), '-H', 'X-Requested-With: XmlHttpRequest', '-H', 'Accept: application/json; q=1'] + args + [uri]
382
		process = Popen(args, stdout=PIPE, stderr=PIPE)
371
		process = Popen(args, stdout=PIPE, stderr=PIPE)
383
		out, err = process.communicate()
372
		out, err = process.communicate()
384
		out, err = out.decode('UTF-8'), err.decode('UTF-8')
373
		out, err = out.decode('UTF-8'), err.decode('UTF-8')
 Lines 390-401    Link Here 
390
			raise Abort('Unrecoverable Response')
379
			raise Abort('Unrecoverable Response')
391
380
392
	def command(self, args, command, **kwargs):
381
	def command(self, args, command, **kwargs):
393
		if not self._cookiejar:
382
		if not self._username:
394
			self._login(args)
383
			self._login(args)
395
		return self.curl(args, 'command/appcenter-selfservice/%s' % command, _command=True, **kwargs)
384
		return self.curl(args, 'command/appcenter-selfservice/%s' % command, _command=True, **kwargs)
396
385
397
	def upload(self, args, **kwargs):
386
	def upload(self, args, **kwargs):
398
		if not self._cookiejar:
387
		if not self._username:
399
			self._login(args)
388
			self._login(args)
400
		return self.curl(args, 'upload/appcenter-selfservice/upload', **kwargs)
389
		return self.curl(args, 'upload/appcenter-selfservice/upload', **kwargs)
401
390

Return to bug 51996