Пример #1
0
def handleRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYPE', '').startswith('application/x-www-form-urlencoded'):
        return showError('Unsupported request method', start_response)

    try:
        request_body_length = int(environ['CONTENT_LENGTH'])
    except:
        return showError('Invalid or missing Content-Length header', start_response)

    request_body = environ['wsgi.input'].read(request_body_length)
    params = {}
    for key, value in parse_qsl(request_body):
        params[key] = value.decode('utf-8')

    guid = params.get('guid', '').lower()
    if not re.match(r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$', guid):
        return showError('Invalid or missing report GUID', start_response)

    reportData = getReport(guid)

    if reportData == None:
        return showError('Report does not exist', start_response)

    secret = calculateReportSecret(guid)
    if params.get('secret', '') != secret and params.get('secret', '') != calculateReportSecret_compat(guid):
        return showError('Wrong secret value', start_response)

    reportData['status'] = params.get('status', '')
    if len(reportData['status']) > 1024:
        reportData['status'] = reportData['status'][:1024]

    oldusefulness = reportData.get('usefulness', '0')
    reportData['usefulness'] = params.get('usefulness', '0')
    if 'email' in reportData:
        updateUserUsefulness(getUserId(reportData['email']), reportData['usefulness'], oldusefulness)

    saveReport(guid, reportData)

    if params.get('notify', '') and 'email' in reportData:
        email = reportData['email']
        email = re.sub(r' at ', r'@', email)
        email = re.sub(r' dot ', r'.', email)
        if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email):
            sendUpdateNotification({
                'email': email,
                'url': get_config().get('reports', 'urlRoot') + guid,
                'status': reportData['status'],
            })

    newURL = get_config().get('reports', 'urlRoot') + guid
    newURL += '?updated=' + str(int(random.uniform(0, 10000)))
    newURL += '#secret=' + secret
    start_response('302 Found', [('Location', newURL.encode('utf-8'))])
    return []
Пример #2
0
def handleRequest(environ, start_response):
  setupStderr(environ['wsgi.errors'])

  if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYPE', '').startswith('application/x-www-form-urlencoded'):
    return showError('Unsupported request method', start_response)

  try:
    request_body_length = int(environ['CONTENT_LENGTH'])
  except:
    return showError('Invalid or missing Content-Length header', start_response)

  request_body = environ['wsgi.input'].read(request_body_length)
  params = {}
  for key, value in parse_qsl(request_body):
    params[key] = value.decode('utf-8')

  guid = params.get('guid', '').lower()
  if not re.match(r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$', guid):
    return showError('Invalid or missing report GUID', start_response)

  reportData = getReport(guid)    

  if reportData == None:
    return showError('Report does not exist', start_response)

  secret = calculateReportSecret(guid)
  if params.get('secret', '') != secret and params.get('secret', '') != calculateReportSecret_compat(guid):
    return showError('Wrong secret value', start_response)

  reportData['status'] = params.get('status', '')
  if len(reportData['status']) > 1024:
    reportData['status'] = reportData['status'][:1024]

  oldusefulness = reportData.get('usefulness', '0')
  reportData['usefulness'] = params.get('usefulness', '0')
  if ('email' in reportData):
    updateUserUsefulness(getUserId(reportData['email']), reportData['usefulness'], oldusefulness)

  saveReport(guid, reportData)

  if params.get('notify', '') and 'email' in reportData:
    email = reportData['email']
    email = re.sub(r' at ', r'@', email)
    email = re.sub(r' dot ', r'.', email)
    if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email):
      sendUpdateNotification({
        'email': email,
        'url': get_config().get('reports', 'urlRoot') + guid,
        'status': reportData['status'],
      })

  newURL = get_config().get('reports', 'urlRoot') + guid
  newURL += '?updated=' + str(int(random.uniform(0, 10000)))
  newURL += '#secret=' + secret
  start_response('302 Found', [('Location', newURL.encode('utf-8'))])
  return []
Пример #3
0
def handleRequest(environ, start_response):
    setupStderr(environ["wsgi.errors"])

    if environ["REQUEST_METHOD"].upper() != "POST" or not environ.get("CONTENT_TYPE", "").startswith(
        "application/x-www-form-urlencoded"
    ):
        return showError("Unsupported request method", start_response)

    try:
        request_body_length = int(environ["CONTENT_LENGTH"])
    except:
        return showError("Invalid or missing Content-Length header", start_response)

    request_body = environ["wsgi.input"].read(request_body_length)
    params = {}
    for key, value in parse_qsl(request_body):
        params[key] = value.decode("utf-8")

    guid = params.get("guid", "").lower()
    if not re.match(r"^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$", guid):
        return showError("Invalid or missing report GUID", start_response)

    reportData = getReport(guid)

    if reportData == None:
        return showError("Report does not exist", start_response)

    secret = calculateReportSecret(guid)
    if params.get("secret", "") != secret and params.get("secret", "") != calculateReportSecret_compat(guid):
        return showError("Wrong secret value", start_response)

    reportData["status"] = params.get("status", "")
    if len(reportData["status"]) > 1024:
        reportData["status"] = reportData["status"][:1024]

    oldusefulness = reportData.get("usefulness", "0")
    reportData["usefulness"] = params.get("usefulness", "0")
    if "email" in reportData:
        updateUserUsefulness(getUserId(reportData["email"]), reportData["usefulness"], oldusefulness)

    saveReport(guid, reportData)

    if params.get("notify", "") and "email" in reportData:
        email = reportData["email"]
        email = re.sub(r" at ", r"@", email)
        email = re.sub(r" dot ", r".", email)
        if re.match(r"^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+", email):
            sendUpdateNotification(
                {"email": email, "url": get_config().get("reports", "urlRoot") + guid, "status": reportData["status"]}
            )

    newURL = get_config().get("reports", "urlRoot") + guid
    newURL += "?updated=" + str(int(random.uniform(0, 10000)))
    newURL += "#secret=" + secret
    start_response("302 Found", [("Location", newURL.encode("utf-8"))])
    return []
Пример #4
0
def processReport(xmlFile):
    global reportData, tagStack

    guid = os.path.splitext(os.path.basename(xmlFile))[0]

    cursor = get_db().cursor()
    executeQuery(cursor, 'SELECT guid FROM #PFX#reports WHERE guid = %s', guid)
    report = cursor.fetchone()

    if report != None:
        os.remove(xmlFile)
        return

    source = open(xmlFile, 'rb')
    reportData = {
        'status': '',
        'usefulness': 0,
        'warnings': {},
        'requests': [],
        'filters': [],
        'subscriptions': [],
        'extensions': [],
        'errors': [],
        'time': time()
    }
    tagStack = []

    parser = ParserCreate()
    parser.StartElementHandler = processElementStart
    parser.EndElementHandler = processElementEnd
    parser.CharacterDataHandler = processText
    try:
        parser.ParseFile(source)
    except ExpatError as error:
        reportData['warnings'][
            '!parsing'] = 'Parsing error in the report: %s at line %i column %i' % (
                ErrorString(error.code), error.lineno, error.offset)

    source.seek(0)
    reportData['knownIssues'] = knownIssuesParser.findMatches(source, 'en-US')
    source.close()

    if 'screenshot' in reportData and not reportData['screenshot'].startswith(
            'data:image/'):
        del reportData['screenshot']
    if 'email' in reportData and reportData['email'].find(
            ' at ') < 0 and reportData['email'].find('@') < 0:
        del reportData['email']

    validateData(reportData)
    saveReport(guid, reportData, True)
    os.remove(xmlFile)
Пример #5
0
def handleRequest(environ, start_response, params):
    guid = params.get('guid', '').lower()
    if not re.match(GUID_REGEX, guid):
        return showError('Invalid or missing report GUID', start_response)

    reportData = getReport(guid)

    if reportData is None:
        return showError('Report does not exist', start_response)

    secret = calculateReportSecret(guid)
    if (params.get('secret', '') != secret and
            params.get('secret', '') != calculateReportSecret_compat(guid)):
        return showError('Wrong secret value', start_response)

    reportData['status'] = params.get('status', '')
    if len(reportData['status']) > 1024:
        reportData['status'] = reportData['status'][:1024]

    oldusefulness = reportData.get('usefulness', '0')
    reportData['usefulness'] = params.get('usefulness', '0')

    if 'email' in reportData:
        updateUserUsefulness(getUserId(reportData['email']),
                             reportData['usefulness'], oldusefulness)

    saveReport(guid, reportData)

    if params.get('notify', '') and 'email' in reportData:
        email = reportData['email']
        email = re.sub(r' at ', r'@', email)
        email = re.sub(r' dot ', r'.', email)
        if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email):
            sendUpdateNotification({
                'email':
                email,
                'url':
                get_config().get('reports', 'urlRoot') + guid,
                'status':
                reportData['status'],
            })

    newURL = get_config().get('reports', 'urlRoot') + guid
    newURL += '?updated=' + str(int(random.uniform(0, 10000)))
    newURL += '#secret=' + secret
    start_response('302 Found', [('Location', newURL.encode('utf-8'))])
    return []
Пример #6
0
def handleRequest(environ, start_response, params):
    guid = params.get('guid', '').lower()
    if not re.match(GUID_REGEX, guid):
        return showError('Invalid or missing report GUID', start_response)

    reportData = getReport(guid)

    if reportData is None:
        return showError('Report does not exist', start_response)

    secret = calculateReportSecret(guid)
    if (params.get('secret', '') != secret and
       params.get('secret', '') != calculateReportSecret_compat(guid)):
        return showError('Wrong secret value', start_response)

    reportData['status'] = params.get('status', '')
    if len(reportData['status']) > 1024:
        reportData['status'] = reportData['status'][:1024]

    oldusefulness = reportData.get('usefulness', '0')
    reportData['usefulness'] = params.get('usefulness', '0')

    if 'email' in reportData:
        updateUserUsefulness(getUserId(reportData['email']),
                             reportData['usefulness'], oldusefulness)

    saveReport(guid, reportData)

    if params.get('notify', '') and 'email' in reportData:
        email = reportData['email']
        email = re.sub(r' at ', r'@', email)
        email = re.sub(r' dot ', r'.', email)
        if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email):
            sendUpdateNotification({
                'email': email,
                'url': get_config().get('reports', 'urlRoot') + guid,
                'status': reportData['status'],
            })

    newURL = get_config().get('reports', 'urlRoot') + guid
    newURL += '?updated=' + str(int(random.uniform(0, 10000)))
    newURL += '#secret=' + secret
    start_response('302 Found', [('Location', newURL.encode('utf-8'))])
    return []
Пример #7
0
def processReport(xmlFile):
    global reportData, tagStack

    guid = os.path.splitext(os.path.basename(xmlFile))[0]

    cursor = get_db().cursor()
    executeQuery(cursor, 'SELECT guid FROM #PFX#reports WHERE guid = %s', guid)
    report = cursor.fetchone()

    if report != None:
        os.remove(xmlFile)
        return

    source = open(xmlFile, 'rb')
    reportData = {'status': '', 'usefulness': 0, 'warnings': {}, 'requests': [], 'filters': [], 'subscriptions': [], 'extensions': [], 'errors': [], 'time': time()}
    tagStack = []

    parser = ParserCreate()
    parser.StartElementHandler = processElementStart
    parser.EndElementHandler = processElementEnd
    parser.CharacterDataHandler = processText
    try:
        parser.ParseFile(source)
    except ExpatError as error:
        reportData['warnings']['!parsing'] = 'Parsing error in the report: %s at line %i column %i' % (ErrorString(error.code), error.lineno, error.offset)

    source.seek(0)
    reportData['knownIssues'] = knownIssuesParser.findMatches(source, 'en-US')
    source.close()

    if 'screenshot' in reportData and not reportData['screenshot'].startswith('data:image/'):
        del reportData['screenshot']
    if 'email' in reportData and reportData['email'].find(' at ') < 0 and reportData['email'].find('@') < 0:
        del reportData['email']

    validateData(reportData)
    saveReport(guid, reportData, True)
    os.remove(xmlFile)
Пример #8
0
def processReports():
    for report in getReports():
        guid = report.get('guid', None)
        reportData = getReport(guid)
        if 'screenshot' in reportData:
            saveReport(guid, reportData)
Пример #9
0
            '!parsing'] = 'Parsing error in the report: %s at line %i column %i' % (
                ErrorString(error.code), error.lineno, error.offset)

    source.seek(0)
    reportData['knownIssues'] = knownIssuesParser.findMatches(source, 'en-US')
    source.close()

    if 'screenshot' in reportData and not reportData['screenshot'].startswith(
            'data:image/'):
        del reportData['screenshot']
    if 'email' in reportData and reportData['email'].find(
            ' at ') < 0 and reportData['email'].find('@') < 0:
        del reportData['email']

    validateData(reportData)
    saveReport(guid, reportData, True)
    os.remove(xmlFile)


def processElementStart(name, attributes):
    global reportData, tagStack

    if name == 'report':
        reportData['type'] = attributes.get('type', 'unknown')
    elif name == 'adblock-plus':
        reportData['abp_version'] = attributes.get('version', 'unknown')
        if reportData['abp_version'] == '99.9':
            reportData['abp_version'] = 'development environment'
        reportData['abp_locale'] = attributes.get('locale', 'unknown')
    elif name == 'application':
        reportData['app_name'] = attributes.get('name', 'unknown')
Пример #10
0
def processReports():
    for report in getReports():
        guid = report.get('guid', None)
        reportData = getReport(guid)
        if 'screenshot' in reportData:
            saveReport(guid, reportData)
Пример #11
0
  try:
    parser.ParseFile(source)
  except ExpatError, error:
    reportData['warnings']['!parsing'] = 'Parsing error in the report: %s at line %i column %i' % (ErrorString(error.code), error.lineno, error.offset)

  source.seek(0)
  reportData['knownIssues'] = knownIssuesParser.findMatches(source, 'en-US')
  source.close()

  if 'screenshot' in reportData and not reportData['screenshot'].startswith('data:image/'):
    del reportData['screenshot']
  if 'email' in reportData and reportData['email'].find(' at ') < 0 and reportData['email'].find('@') < 0:
    del reportData['email']

  validateData(reportData)
  saveReport(guid, reportData, True)
  os.remove(xmlFile)

def processElementStart(name, attributes):
  global reportData, tagStack

  if name == 'report':
    reportData['type'] = attributes.get('type', 'unknown')
  elif name == 'adblock-plus':
    reportData['abp_version'] = attributes.get('version', 'unknown')
    if reportData['abp_version'] == '99.9':
      reportData['abp_version'] = 'development environment'
    reportData['abp_locale'] = attributes.get('locale', 'unknown')
  elif name == 'application':
    reportData['app_name'] = attributes.get('name', 'unknown')
    reportData['app_vendor'] = attributes.get('vendor', 'unknown')