Esempio n. 1
0
def capture_foxyfeed(request):
    capture_name = "test1"
    save_request_object = True
    allow_overwrite = False
    capture_dir = os.path.join(os.path.dirname(__file__), "fixtures")

    logger = logging.getLogger("foxycart")
    logger.error(capture_dir)

    # print capture_dir

    if save_request_object:
        capture_file_path = os.path.join(capture_dir, capture_name + ".request")
        f = open(capture_file_path, "w")
        f.write(request.__repr__())
        f.close()
    if request.method == "POST" and "FoxyData" in request.POST:
        encrypted_file_path = os.path.join(capture_dir, capture_name + ".encrypted")
        plaintext_file_path = os.path.join(capture_dir, capture_name + ".plaintext")
        if not allow_overwrite:
            if os.path.exists(encrypted_file_path):
                return HttpResponseForbidden("Error: data already captured.")

        f = codecs.open(encrypted_file_path, encoding="utf-8", mode="w")
        data = request.POST["FoxyData"]
        f.write(data)
        f.close()
        f = codecs.open(plaintext_file_path, encoding="utf-8", mode="w")
        f.write(FoxyData.decrypt_str(urllib.unquote_plus(data), settings.FOXYCART_DATAFEED_KEY))
        return HttpResponse("foxy")

    return HttpResponseForbidden("Unauthorized request.")
Esempio n. 2
0
def capture_foxyfeed(request):
  capture_name = "test1"
  save_request_object = True
  allow_overwrite = False
  capture_dir =  os.path.join(os.path.dirname(__file__), "fixtures")
  if save_request_object:
    capture_file_path = os.path.join(capture_dir, capture_name + '.request')
    f = open(capture_file_path, 'w')
    f.write(request.__repr__())
    f.close()
  if request.method == 'POST' and 'FoxyData' in request.POST:
    encrypted_file_path = os.path.join(capture_dir, capture_name + '.encrypted')
    plaintext_file_path = os.path.join(capture_dir, capture_name + '.plaintext')
    if not allow_overwrite:
      if os.path.exists(encrypted_file_path):
          return HttpResponseForbidden('Error: data already captured.')

    f = codecs.open(encrypted_file_path, encoding='utf-8', mode="w")
    data = request.POST['FoxyData']
    f.write(data)
    f.close()
    f = codecs.open(plaintext_file_path, encoding='utf-8', mode="w")
    f.write(FoxyData.decrypt_str(urllib.unquote_plus(data), settings.FOXYCART_DATAFEED_KEY))
    return HttpResponse('foxy')
 
  return HttpResponseForbidden('Unauthorized request.')