Esempio n. 1
0
def submit_data(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    if environ['REQUEST_METHOD'].upper() != 'POST':
        return showError('Unsupported request method', start_response)

    params = parse_qs(environ.get('QUERY_STRING', ''))
    requestVersion = params.get('version', ['0'])[0]
    data = '{}'
    try:
        data_length = int(environ.get('CONTENT_LENGTH', '0'))
    except ValueError:
        data_length = 0
    if data_length != 0:
        data = environ['wsgi.input'].read(data_length)
    try:
        data = json.loads(data)
    except json.decoder.JSONDecodeError:
        return showError('Error while parsing JSON data.', start_response)

    db = _get_db()

    for domain, status in data.iteritems():
        process_domain(db, domain, status)

    db.commit()

    response_headers = [('Content-type', 'text/plain')]
    start_response('200 OK', response_headers)
    return []
Esempio n. 2
0
def handleRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')])
    if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get(
            'CONTENT_TYPE',
            '').startswith('application/x-www-form-urlencoded'):
        return 'Unsupported request method'

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

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

    if not 'name' in params or params['name'] == '':
        return 'No name entered'
    if not 'email' in params or params['email'] == '':
        return 'No email address entered'
    if not 'subject' in params or params['subject'] == '':
        return 'No subject entered'
    if not 'message' in params or params['message'] == '':
        return 'No message entered'

    if not re.match(r'^\w[\w.+!-]+@\w[\w.-]+\.[a-zA-Z]{2,6}$',
                    params['email']):
        return 'Invalid email address'

    params['time'] = datetime.datetime.now()
    sendMail(get_config().get('formmail', 'template'), params)
    return 'Message sent'
def submit_data(environ, start_response):
    setupStderr(environ["wsgi.errors"])

    if environ["REQUEST_METHOD"].upper() != "POST":
        return showError("Unsupported request method", start_response)

    params = parse_qs(environ.get("QUERY_STRING", ""))
    requestVersion = params.get("version", ["0"])[0]
    data = "{}"
    try:
        data_length = int(environ.get("CONTENT_LENGTH", "0"))
    except ValueError:
        data_length = 0
    if data_length != 0:
        data = environ["wsgi.input"].read(data_length)
    try:
        data = json.loads(data)
    except json.decoder.JSONDecodeError:
        return showError("Error while parsing JSON data.", start_response)

    db = _get_db()

    for domain, status in data.iteritems():
        process_domain(db, domain, status)

    db.commit()

    response_headers = [("Content-type", "text/plain")]
    start_response("200 OK", response_headers)
    return []
def handleRequest(environ, start_response):
  setupStderr(environ['wsgi.errors'])

  if not environ.get('HTTP_X_ADBLOCK_PLUS'):
    return showError('Please use Adblock Plus to submit crashes', start_response)

  if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYPE', '').startswith('text/xml'):
    return showError('Unsupported request method', start_response)

  params = parse_qs(environ.get('QUERY_STRING', ''))

  requestVersion = params.get('version', ['0'])[0]
  if requestVersion != '1':
    return showError('Unsupported request version', start_response)

  try:
    request_body_size = int(environ.get('CONTENT_LENGTH', 0))
  except (ValueError):
    return showError('No content', start_response)

  dir = get_config().get('crashes', 'dataPath')
  if not os.path.exists(dir):
    os.makedirs(dir)

  filename = None
  try:
    fd, filename = mkstemp('.xml.tmp', 'crash_', dir)
    file = os.fdopen(fd, 'wb')
    file.write(environ['wsgi.input'].read(request_body_size))
    file.close()
    os.rename(filename, os.path.splitext(filename)[0]);
  except Exception, e:
    if filename != None and os.path.isfile(filename):
      os.remove(filename)
    raise e
Esempio n. 5
0
def query_handler(environ, start_response):
  setupStderr(environ["wsgi.errors"])
  params = dict(parse_qsl(environ.get("QUERY_STRING", "")))

  try:
    db_connection = db.connect()
    try:
      results = db.query(db_connection, *query(**params), dict_result=True)
      total = db.query(db_connection, "SELECT FOUND_ROWS()")[0][0]
    finally:
      db_connection.close()
  except MySQLdb.Error:
    traceback.print_exc()
    return common.show_error("Failed to query database!", start_response,
                             "500 Database error")

  try:
    echo = int(params["echo"])
  except (ValueError, KeyError):
    echo = 0

  response_headers = [("Content-type", "application/json; charset=utf-8")]
  start_response("200 OK", response_headers)
  return [json.dumps({"results": results, "echo": echo,
                      "total": total, "count": len(results)},
                     ensure_ascii=False).encode("utf-8")]
Esempio n. 6
0
def query_handler(environ, start_response):
  setupStderr(environ["wsgi.errors"])
  params = dict(parse_qsl(environ.get("QUERY_STRING", "")))

  try:
    db_connection = db.connect()
    try:
      results = db.query(db_connection, *query(**params), dict_result=True)
      total = db.query(db_connection, "SELECT FOUND_ROWS()")[0][0]
    finally:
      db_connection.close()
  except MySQLdb.Error:
    traceback.print_exc()
    return common.show_error("Failed to query database!", start_response,
                             "500 Database error")

  try:
    echo = int(params["echo"])
  except (ValueError, KeyError):
    echo = 0

  response_headers = [("Content-type", "application/json; charset=utf-8")]
  start_response("200 OK", response_headers)
  return [json.dumps({"results": results, "echo": echo,
                      "total": total, "count": len(results)},
                     ensure_ascii=False).encode("utf-8")]
Esempio n. 7
0
def handleRequest(environ, start_response):
  setupStderr(environ['wsgi.errors'])

  start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')])
  if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYPE', '').startswith('application/x-www-form-urlencoded'):
    return 'Unsupported request method'

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

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

  if not 'name' in params or params['name'] == '':
    return 'No name entered'
  if not 'email' in params or params['email'] == '':
    return 'No email address entered'
  if not 'subject' in params or params['subject'] == '':
    return 'No subject entered'
  if not 'message' in params or params['message'] == '':
    return 'No message entered'

  if not re.match(r'^\w[\w.+!-]+@\w[\w.-]+\.[a-zA-Z]{2,6}$', params['email']):
    return 'Invalid email address'

  sendMail(get_config().get('formmail', 'template'), params)
  return 'Message sent'
Esempio n. 8
0
def submit_data(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    if environ['REQUEST_METHOD'].upper() != 'POST':
        return showError('Unsupported request method', start_response)

    params = parse_qs(environ.get('QUERY_STRING', ''))
    requestVersion = params.get('version', ['0'])[0]
    data = '{}'
    try:
        data_length = int(environ.get('CONTENT_LENGTH', '0'))
    except ValueError:
        data_length = 0
    if data_length != 0:
        data = environ['wsgi.input'].read(data_length)
    try:
        data = json.loads(data)
    except json.decoder.JSONDecodeError:
        return showError('Error while parsing JSON data.', start_response)

    db = _get_db()

    for domain, status in data.iteritems():
        process_domain(db, domain, status)

    db.commit()

    response_headers = [('Content-type', 'text/plain')]
    start_response('200 OK', response_headers)
    return []
def submit_data(environ, start_response):
  setupStderr(environ["wsgi.errors"])

  if environ["REQUEST_METHOD"].upper() != "POST":
    return showError("Unsupported request method", start_response)

  params = parse_qs(environ.get("QUERY_STRING", ""))
  requestVersion = params.get("version", ["0"])[0]
  data = "{}"
  try:
    data_length = int(environ.get("CONTENT_LENGTH", "0"))
  except ValueError:
    data_length = 0
  if data_length != 0:
    data = environ["wsgi.input"].read(data_length)
  try:
    data = json.loads(data)
  except json.decoder.JSONDecodeError:
    return showError("Error while parsing JSON data.", start_response)

  db = _get_db()

  for domain, status in data.iteritems():
    process_domain(db, domain, status)

  db.commit()

  response_headers = [("Content-type", "text/plain")]
  start_response("200 OK", response_headers)
  return []
Esempio n. 10
0
def hook(ui=None, repo=None, **kwargs):
    setupStderr()

    root = repo.root if repo != None else get_config().get('hg', 'auth_repository')
    result = generate_data(root)

    with open(get_config().get('hg', 'auth_file'), 'wb') as file:
        for s in result:
            file.write(s)
Esempio n. 11
0
def hook(ui=None, repo=None, **kwargs):
  setupStderr()

  root = repo.root if repo != None else get_config().get('hg', 'auth_repository')
  result = generate_data(root)

  with open(get_config().get('hg', 'auth_file'), 'wb') as file:
    for s in result:
      file.write(s)
Esempio n. 12
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 []
def handleRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    params = parse_qs(environ.get('QUERY_STRING', ''))

    id = params.get('id', [''])[0].lower()
    if not re.match(r'^[\da-f]{32}$', id):
        return showError('Invalid or missing ID', start_response)

    thisweek = getDigestSecret(id, date.today().isocalendar())
    prevweek = getDigestSecret(id, (date.today() -
                                    timedelta(weeks=1)).isocalendar())
    thisweek_compat = getDigestSecret_compat(id, date.today().isocalendar())
    prevweek_compat = getDigestSecret_compat(
        id, (date.today() - timedelta(weeks=1)).isocalendar())

    redirect = False
    secret = params.get('secret', [''])[0].lower()
    if secret:
        redirect = True
    else:
        try:
            cookies = Cookie.SimpleCookie(environ.get('HTTP_COOKIE', ''))
            secret = cookies[id].value
        except (Cookie.CookieError, KeyError):
            return showError('No digest secret', start_response)

    if secret != thisweek and secret != prevweek and secret != thisweek_compat and secret != prevweek_compat:
        return showError('Wrong secret', start_response)

    path = os.path.join(get_config().get('reports', 'digestPath'),
                        id + '.html')
    if not os.path.exists(path):
        return showError('Digest doesn\'t exist', start_response)

    cookies = Cookie.SimpleCookie()
    cookies[id] = secret
    cookies[id]['path'] = '/'
    cookies[id]['secure'] = True
    cookies[id]['httponly'] = True
    expiration = datetime.utcnow() + timedelta(weeks=2)
    cookies[id]['expires'] = expiration.strftime('%a, %d-%b-%Y %H:%M:%S GMT')
    if redirect:
        start_response('302 Found',
                       [('Location', '/digest?id=' + id),
                        ('Set-Cookie', cookies[id].OutputString())])
        return []
    else:
        start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8'),
                                  ('Set-Cookie', cookies[id].OutputString())])
        blockSize = 4096
        f = open(path)
        if 'wsgi.file_wrapper' in environ:
            return environ['wsgi.file_wrapper'](f, blockSize)
        else:
            return iter(lambda: f.read(blockSize), '')
Esempio n. 14
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 []
Esempio n. 15
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 []
Esempio n. 16
0
def submit(environ, start_response):
    setupStderr(environ["wsgi.errors"])
    config = get_config()

    # Check that this is a POST request
    if environ["REQUEST_METHOD"] != "POST":
        return common.show_error("Unsupported request method", start_response)

    # Parse the submitted JSON
    try:
        data = json.loads(environ["wsgi.input"].read(
            int(environ["CONTENT_LENGTH"])))
    except (KeyError, IOError, ValueError):
        return common.show_error("Error while parsing JSON data.",
                                 start_response)

    # Make sure the submitted data was contained within an object at least
    if not isinstance(data, dict):
        return common.show_error(
            "Error, data must be contained within an object.", start_response)

    # Log the data to a file
    log_dir = config.get("filterhitstats", "log_dir")
    try:
        log_file = log_filterhits(data, log_dir,
                                  environ.get("QUERY_STRING", ""))
    except (OSError, IOError):
        traceback.print_exc()
        return common.show_error("Failed to write data to log file!",
                                 start_response, "500 Logging error")

    # Update the geometrical_mean aggregations in the database
    interval = config.get("filterhitstats", "interval")
    try:
        db_connection = db.connect()
        try:
            db.write(db_connection, geometrical_mean.update(interval, data))
        finally:
            db_connection.close()
    except:
        # Updating the aggregations in the database failed for whatever reason,
        # log the details but continue to return 204 to the client to avoid the
        # re-transmission of data.
        processing_error_log = os.path.join(
            config.get("filterhitstats", "log_dir"), "processing-errors.log")
        with open(processing_error_log, "a+") as f:
            message = "Problem processing data file %s:\n%s" % (
                log_file, traceback.format_exc())
            print >> f, "[%s] %s" % (
                datetime.now().strftime("%d/%b/%Y:%H:%M:%S %z"), message)

    # Send back a 204 No Content
    start_response("204 No Content", [])
    return []
Esempio n. 17
0
def handleRequest(environ, start_response):
    setupStderr(environ["wsgi.errors"])

    params = parse_qs(environ.get("QUERY_STRING", ""))

    id = params.get("id", [""])[0].lower()
    if not re.match(r"^[\da-f]{32}$", id):
        return showError("Invalid or missing ID", start_response)

    thisweek = getDigestSecret(id, date.today().isocalendar())
    prevweek = getDigestSecret(id, (date.today() - timedelta(weeks=1)).isocalendar())
    thisweek_compat = getDigestSecret_compat(id, date.today().isocalendar())
    prevweek_compat = getDigestSecret_compat(id, (date.today() - timedelta(weeks=1)).isocalendar())

    redirect = False
    secret = params.get("secret", [""])[0].lower()
    if secret:
        redirect = True
    else:
        try:
            cookies = Cookie.SimpleCookie(environ.get("HTTP_COOKIE", ""))
            secret = cookies[id].value
        except (Cookie.CookieError, KeyError):
            return showError("No digest secret", start_response)

    if secret != thisweek and secret != prevweek and secret != thisweek_compat and secret != prevweek_compat:
        return showError("Wrong secret", start_response)

    path = os.path.join(get_config().get("reports", "digestPath"), id + ".html")
    if not os.path.exists(path):
        return showError("Digest doesn't exist", start_response)

    cookies = Cookie.SimpleCookie()
    cookies[id] = secret
    cookies[id]["path"] = "/"
    cookies[id]["secure"] = True
    cookies[id]["httponly"] = True
    expiration = datetime.utcnow() + timedelta(weeks=2)
    cookies[id]["expires"] = expiration.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
    if redirect:
        start_response("302 Found", [("Location", "/digest?id=" + id), ("Set-Cookie", cookies[id].OutputString())])
        return []
    else:
        start_response(
            "200 OK", [("Content-Type", "text/html; charset=utf-8"), ("Set-Cookie", cookies[id].OutputString())]
        )
        blockSize = 4096
        f = open(path)
        if "wsgi.file_wrapper" in environ:
            return environ["wsgi.file_wrapper"](f, blockSize)
        else:
            return iter(lambda: f.read(blockSize), "")
Esempio n. 18
0
def submit(environ, start_response):
  setupStderr(environ["wsgi.errors"])
  config = get_config()

  # Check that this is a POST request
  if environ["REQUEST_METHOD"] != "POST":
    return common.show_error("Unsupported request method", start_response)

  # Parse the submitted JSON
  try:
    data = json.loads(environ["wsgi.input"].read(int(environ["CONTENT_LENGTH"])))
  except (KeyError, IOError, ValueError):
    return common.show_error("Error while parsing JSON data.", start_response)

  # Make sure the submitted data was contained within an object at least
  if not isinstance(data, dict):
    return common.show_error("Error, data must be contained within an object.", start_response)

  # Log the data to a file
  log_dir = config.get("filterhitstats", "log_dir")
  try:
    log_file = log_filterhits(data, log_dir, environ.get("QUERY_STRING", ""))
  except (OSError, IOError):
    traceback.print_exc()
    return common.show_error("Failed to write data to log file!", start_response,
                             "500 Logging error")

  # Update the geometrical_mean aggregations in the database
  interval = config.get("filterhitstats", "interval")
  try:
    db_connection = db.connect()
    try:
      db.write(db_connection, geometrical_mean.update(interval, data))
    finally:
      db_connection.close()
  except:
    # Updating the aggregations in the database failed for whatever reason,
    # log the details but continue to return 204 to the client to avoid the
    # re-transmission of data.
    processing_error_log = os.path.join(config.get("filterhitstats", "log_dir"),
                                        "processing-errors.log")
    with open(processing_error_log, "a+") as f:
      message = "Problem processing data file %s:\n%s" % (
        log_file, traceback.format_exc()
      )
      print >> f, "[%s] %s" % (datetime.now().strftime("%d/%b/%Y:%H:%M:%S %z"), message)

  # Send back a 204 No Content
  start_response("204 No Content", [])
  return []
Esempio n. 19
0
def handleRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    params = parse_qs(environ.get('QUERY_STRING', ''))

    id = params.get('id', [''])[0].lower()
    if not re.match(r'^[\da-f]{32}$', id):
        return showError('Invalid or missing ID', start_response)

    thisweek = getDigestSecret(id, date.today().isocalendar())
    prevweek = getDigestSecret(id, (date.today() - timedelta(weeks=1)).isocalendar())
    thisweek_compat = getDigestSecret_compat(id, date.today().isocalendar())
    prevweek_compat = getDigestSecret_compat(id, (date.today() - timedelta(weeks=1)).isocalendar())

    redirect = False
    secret = params.get('secret', [''])[0].lower()
    if secret:
        redirect = True
    else:
        try:
            cookies = Cookie.SimpleCookie(environ.get('HTTP_COOKIE', ''))
            secret = cookies[id].value
        except (Cookie.CookieError, KeyError):
            return showError('No digest secret', start_response)

    if secret != thisweek and secret != prevweek and secret != thisweek_compat and secret != prevweek_compat:
        return showError('Wrong secret', start_response)

    path = os.path.join(get_config().get('reports', 'digestPath'), id + '.html')
    if not os.path.exists(path):
        return showError("Digest doesn't exist", start_response)

    cookies = Cookie.SimpleCookie()
    cookies[id] = secret
    cookies[id]['path'] = '/'
    cookies[id]['secure'] = True
    cookies[id]['httponly'] = True
    expiration = datetime.utcnow() + timedelta(weeks=2)
    cookies[id]['expires'] = expiration.strftime('%a, %d-%b-%Y %H:%M:%S GMT')
    if redirect:
        start_response('302 Found', [('Location', '/digest?id=' + id), ('Set-Cookie', cookies[id].OutputString())])
        return []
    else:
        start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8'), ('Set-Cookie', cookies[id].OutputString())])
        blockSize = 4096
        f = open(path)
        if 'wsgi.file_wrapper' in environ:
            return environ['wsgi.file_wrapper'](f, blockSize)
        else:
            return iter(lambda: f.read(blockSize), '')
Esempio n. 20
0
def handleSubscriptionFallbackRequest(environ, start_response):
  setupStderr(environ['wsgi.errors'])

  (redirects, gone)= getData()

  start_response('200 OK', [('Content-Type', 'text/plain')])

  url = None
  params = parse_qs(environ.get('QUERY_STRING', ''))
  if 'url' in params:
    url = params['url'][0]

  if url and url in gone:
    return ['410']
  elif url and url in redirects:
    return ['301 %s' % redirects[url]]

  return []
Esempio n. 21
0
def handleRequest(environ, start_response):
  setupStderr(environ['wsgi.errors'])

  params = parse_qs(environ.get('QUERY_STRING', ''))

  id = params.get('id', [''])[0].lower()
  if not re.match(r'^[\da-f]{32}$', id):
    return showError('Invalid or missing ID', start_response)

  user = getUser(id)
  if user == None:
    return showError('User not found', start_response)

  user['reportlist'] = getReportsForUser(id)

  template = get_template(get_config().get('reports', 'showUserTemplate'))
  start_response('200 OK', [('Content-Type', 'application/xhtml+xml; charset=utf-8')])
  return [template.render(user).encode('utf-8')]
Esempio n. 22
0
def handleSubscriptionFallbackRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    (redirects, gone) = getData()

    start_response('200 OK', [('Content-Type', 'text/plain')])

    url = None
    params = parse_qs(environ.get('QUERY_STRING', ''))
    if 'url' in params:
        url = params['url'][0]

    if url and url in gone:
        return ['410']
    elif url and url in redirects:
        return ['301 %s' % redirects[url]]

    return []
Esempio n. 23
0
def handleRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    params = parse_qs(environ.get('QUERY_STRING', ''))

    id = params.get('id', [''])[0].lower()
    if not re.match(r'^[\da-f]{32}$', id):
        return showError('Invalid or missing ID', start_response)

    user = getUser(id)
    if user == None:
        return showError('User not found', start_response)

    user['reportlist'] = getReportsForUser(id)

    template = get_template(get_config().get('reports', 'showUserTemplate'))
    start_response('200 OK',
                   [('Content-Type', 'application/xhtml+xml; charset=utf-8')])
    return [template.render(user).encode('utf-8')]
Esempio n. 24
0
def handleRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    if not environ.get('HTTP_X_ADBLOCK_PLUS'):
        return showError('Please use Adblock Plus to submit reports',
                         start_response)

    if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get(
            'CONTENT_TYPE', '').startswith('text/xml'):
        return showError('Unsupported request method', start_response)

    params = parse_qs(environ.get('QUERY_STRING', ''))

    requestVersion = params.get('version', ['0'])[0]
    if requestVersion != '1':
        return showError('Unsupported request version', start_response)

    guid = params.get('guid', [''])[0].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 GUID', start_response)

    path = os.path.join(get_config().get('reports', 'dataPath'), guid + '.xml')
    if os.path.exists(path) or os.path.exists(path + '.tmp'):
        return showError('Duplicate GUID', start_response)

    dir = os.path.dirname(path)
    if not os.path.exists(dir):
        os.makedirs(dir)
    try:
        file = open(path + '.tmp', 'wb')
        iter = dataIterator(environ['wsgi.input'], file)
        knownIssues = knownIssuesParser.findMatches(
            iter,
            params.get('lang', ['en-US'])[0])
        file.close()

        os.rename(path + '.tmp', path)
    except Exception, e:
        if os.path.isfile(path + '.tmp'):
            os.remove(path + '.tmp')
        raise e
Esempio n. 25
0
def handleRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    if not environ.get('HTTP_X_ADBLOCK_PLUS'):
        return showError('Please use Adblock Plus to submit crashes',
                         start_response)

    if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get(
            'CONTENT_TYPE', '').startswith('text/xml'):
        return showError('Unsupported request method', start_response)

    params = parse_qs(environ.get('QUERY_STRING', ''))

    requestVersion = params.get('version', ['0'])[0]
    if requestVersion != '1':
        return showError('Unsupported request version', start_response)

    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except ValueError:
        return showError('No content', start_response)

    dir = get_config().get('crashes', 'dataPath')
    if not os.path.exists(dir):
        os.makedirs(dir)

    filename = None
    try:
        fd, filename = mkstemp('.xml.tmp', 'crash_', dir)
        file = os.fdopen(fd, 'wb')
        file.write(environ['wsgi.input'].read(request_body_size))
        file.close()
        os.rename(filename, os.path.splitext(filename)[0])
    except Exception as e:
        if filename != None and os.path.isfile(filename):
            os.remove(filename)
        raise e

    start_response('200 Ok', [('Content-Type', 'text/plain; charset=utf-8')])
    return ['saved'.encode('utf-8')]
Esempio n. 26
0
def main():
  """
    main function for createNightlies.py
  """
  setupStderr()

  nightlyConfig = ConfigParser.SafeConfigParser()
  nightlyConfigFile = get_config().get('extensions', 'nightliesData')
  if os.path.exists(nightlyConfigFile):
    nightlyConfig.read(nightlyConfigFile)

  # build all extensions specified in the configuration file
  # and generate changelogs and documentations for each:
  data = None
  for repo in Configuration.getRepositoryConfigurations(nightlyConfig):
    build = None
    try:
      build = NightlyBuild(repo)
      if build.hasChanges():
        build.run()
    except Exception, ex:
      print >>sys.stderr, "The build for %s failed:" % repo
      traceback.print_exc()
def handleRequest(environ, start_response):
  setupStderr(environ['wsgi.errors'])

  if not environ.get('HTTP_X_ADBLOCK_PLUS'):
    return showError('Please use Adblock Plus to submit reports', start_response)

  if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYPE', '').startswith('text/xml'):
    return showError('Unsupported request method', start_response)

  params = parse_qs(environ.get('QUERY_STRING', ''))

  requestVersion = params.get('version', ['0'])[0]
  if requestVersion != '1':
    return showError('Unsupported request version', start_response)

  guid = params.get('guid', [''])[0].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 GUID', start_response)

  path = os.path.join(get_config().get('reports', 'dataPath'), guid + '.xml')
  if os.path.exists(path) or os.path.exists(path + '.tmp'):
    return showError('Duplicate GUID', start_response)

  dir = os.path.dirname(path)
  if not os.path.exists(dir):
    os.makedirs(dir)
  try:
    file = open(path + '.tmp', 'wb')
    iter = dataIterator(environ['wsgi.input'], file)
    knownIssues = knownIssuesParser.findMatches(iter, params.get('lang', ['en-US'])[0])
    file.close()

    os.rename(path + '.tmp', path);
  except Exception, e:
    if os.path.isfile(path + '.tmp'):
      os.remove(path + '.tmp')
    raise e
# Adblock Plus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>.

import os, subprocess
from sitescripts.utils import get_config, setupStderr
from sitescripts.subscriptions.bin.processTemplate import writeSubscriptions
from tempfile import mkdtemp
from shutil import rmtree

def updateRecommendations():
  repository = get_config().get('extensions', 'abp_repository')
  tempdir = mkdtemp(prefix='adblockplus')
  try:
    subprocess.check_call(['hg', 'clone', '-q', '-U', repository, tempdir])
    subprocess.check_call(['hg', 'up', '-q', '-R', tempdir, '-r', 'default'])
    writeSubscriptions('recommendations', os.path.join(tempdir, 'chrome', 'content', 'ui', 'subscriptions.xml'))
    if subprocess.check_output(['hg', 'stat', '-R', tempdir]) != '':
      subprocess.check_call(['hg', 'commit', '-q', '-R', tempdir, '-u', 'hgbot', '-m', 'Updated list of recommended subscriptions'])
      subprocess.check_call(['hg', 'push', '-q', '-R', tempdir])
  finally:
    rmtree(tempdir)

if __name__ == '__main__':
  setupStderr()
  updateRecommendations()
Esempio n. 29
0
        if path is None:
            keyPath = key
        else:
            keyPath = path + '.' + key

        if isinstance(data[key], dict):
            validateData(data[key], keyPath)
        elif isinstance(data[key], list):
            limit = lengthRestrictions.get(keyPath, lengthRestrictions['default_list'])
            if len(data[key]) > limit:
                data[key] = data[key][0:limit]
                reportData['warnings'][keyPath] = 'List %s exceeded length limit and was truncated' % keyPath
            for i in range(len(data[key])):
                if isinstance(data[key][i], dict):
                    validateData(data[key][i], keyPath)
                elif isinstance(data[key][i], basestring):
                    itemPath = keyPath + '.item'
                    limit = lengthRestrictions.get(itemPath, lengthRestrictions['default_string'])
                    if len(data[key][i]) > limit:
                        data[key][i] = data[key][i][0:limit] + u'\u2026'
                        reportData['warnings'][itemPath] = 'Field %s exceeded length limit and was truncated' % itemPath
        elif isinstance(data[key], basestring):
            limit = lengthRestrictions.get(keyPath, lengthRestrictions['default_string'])
            if len(data[key]) > limit:
                data[key] = data[key][0:limit] + u'\u2026'
                reportData['warnings'][keyPath] = 'Field %s exceeded length limit and was truncated' % keyPath

if __name__ == '__main__':
    setupStderr()
    scanReports(get_config().get('reports', 'dataPath'))