Ejemplo n.º 1
0
def create_issue():
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    # see https://github.com/webcompat/webcompat.com/issues/688
    spamlist = ['facebook', 'fb.com']
    for spam in spamlist:
        if spam in form.get('url'):
            msg = (u'Anonymous reporting for Facebook.com is temporarily '
                   'disabled. Please see https://github.com/webcompat/we'
                   'bcompat.com/issues/688 for more details.')
            flash(msg, 'notimeout')
            return redirect(url_for('index'))
    form['ua_header'] = request.headers.get('User-Agent')
    # Do we have an image ready to be uploaded?
    image = request.files['image']
    if image:
        form['image_upload'] = json.loads(upload()[0])
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            return redirect(url_for('thanks',
                            number=response.get('number')))
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        return redirect(url_for('thanks', number=response.get('number')))
Ejemplo n.º 2
0
def index():
    '''Main view where people come to report issues.'''
    bug_form = IssueForm(request.form)
    # add browser and version to bug_form object data
    ua_header = request.headers.get('User-Agent')
    bug_form.browser.data = get_browser(ua_header)
    bug_form.os.data = get_os(ua_header)
    browser_name = get_browser_name(ua_header)
    # GET means you want to file a report.
    if request.method == 'GET':
        if g.user:
            get_user_info()
        return render_template('index.html',
                               form=bug_form,
                               browser=browser_name)
    # Form submission.
    elif request.method == 'POST' and bug_form.validate():
        # copy the form so we can add the full UA string to it.
        form = request.form.copy()
        form['ua_header'] = ua_header
        if form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(form)
                return redirect(
                    url_for('thanks', number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = form
                return redirect(url_for('login'))
        elif form.get('submit-type') == PROXY_REPORT:
            response = report_issue(form, proxy=True).json()
            return redirect(url_for('thanks', number=response.get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=bug_form)
Ejemplo n.º 3
0
def index():
    '''Main view where people come to report issues.'''
    bug_form = IssueForm(request.form)
    # add browser and version to bug_form object data
    ua_header = request.headers.get('User-Agent')
    bug_form.browser.data = get_browser(ua_header)
    bug_form.os.data = get_os(ua_header)
    browser_name = get_browser_name(ua_header)
    # GET means you want to file a report.
    if request.method == 'GET':
        if g.user:
            get_user_info()
        return render_template('index.html', form=bug_form,
                               browser=browser_name)
    # Form submission.
    elif request.method == 'POST' and bug_form.validate():
        # copy the form so we can add the full UA string to it.
        form = request.form.copy()
        form['ua_header'] = ua_header
        if form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(form)
                return redirect(url_for('thanks',
                                number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = form
                return redirect(url_for('login'))
        elif form.get('submit-type') == PROXY_REPORT:
            response = report_issue(form, proxy=True).json()
            return redirect(url_for('thanks', number=response.get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=bug_form)
Ejemplo n.º 4
0
def create_issue():
    """Creates a new issue.

    GET will return an HTML response for reporting issues
    POST will create a new issue
    """
    if request.method == 'GET':
        bug_form = get_form(request.headers.get('User-Agent'))
        if g.user:
            get_user_info()
        if request.args.get('src'):
            session['src'] = request.args.get('src')
        return render_template('new-issue.html', form=bug_form)
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    # see https://github.com/webcompat/webcompat.com/issues/1141
    # see https://github.com/webcompat/webcompat.com/issues/1237
    spamlist = ['qiangpiaoruanjian', 'cityweb.de']
    for spam in spamlist:
        if spam in form.get('url'):
            msg = (u'Anonymous reporting for domain {0} '
                   'is temporarily disabled. Please contact '
                   '[email protected] '
                   'for more details.').format(spam)
            flash(msg, 'notimeout')
            return redirect(url_for('index'))
    form['ua_header'] = request.headers.get('User-Agent')
    # Currently we support either a src GET param, or X-Reported-With header
    # to track where the report originated from.
    # See https://github.com/webcompat/webcompat.com/issues/1254 to track
    # supporting only the src param
    if session.get('src'):
        form['reported_with'] = session.pop('src')
    else:
        form['reported_with'] = request.headers.get('X-Reported-With', 'web')
    # Logging the ip and url for investigation
    log = app.logger
    log.setLevel(logging.INFO)
    log.info('{ip} {url}'.format(ip=request.remote_addr, url=form['url']))
    # form submission for 3 scenarios: authed, to be authed, anonymous
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            session['show_thanks'] = True
            return redirect(
                url_for('show_issue', number=response.get('number')))
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        session['show_thanks'] = True
        return redirect(url_for('show_issue', number=response.get('number')))
Ejemplo n.º 5
0
def create_issue():
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    form['ua_header'] = request.headers.get('User-Agent')
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            return thanks_page(request, response)
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        return thanks_page(request, response)
Ejemplo n.º 6
0
def file_issue():
    '''File an issue on behalf of the user that just gave us authorization.'''
    response = report_issue(session['form_data'])
    # Get rid of stashed form data
    session.pop('form_data', None)
    session['show_thanks'] = True
    return redirect(url_for('show_issue', number=response.get('number')))
Ejemplo n.º 7
0
def new_issue():
    '''Main view where people come to report issues.'''
    form = IssueForm(request.form)
    # add browser and version to form object data
    form.browser.data = get_browser_name(request.headers.get('User-Agent'))
    form.version.data = get_browser_version(request.headers.get('User-Agent'))
    # GET means you want to file a report.
    if request.method == 'GET':
        return render_template('index.html', form=form)
    # Form submission.
    elif request.method == 'POST' and form.validate():
        if request.form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(request.form)
                return redirect(
                    url_for('thanks', number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = request.form
                return redirect(url_for('login'))
        elif request.form.get('submit-type') == PROXY_REPORT:
            # `response` here is a Requests Response object, because
            # the proxy_report_issue crafts a manual request with Requests
            response = proxy_report_issue(request.form)
            return redirect(
                url_for('thanks', number=response.json().get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=form)
Ejemplo n.º 8
0
def file_issue():
    """File an issue on behalf of the user that just gave us authorization."""
    response = report_issue(session['form_data'])
    # Get rid of stashed form data
    session.pop('form_data', None)
    session['show_thanks'] = True
    return redirect(url_for('show_issue', number=response.get('number')))
Ejemplo n.º 9
0
def new_issue():
    '''Main view where people come to report issues.'''
    form = IssueForm(request.form)
    # add browser and version to form object data
    form.browser.data = get_browser_name(request.headers.get('User-Agent'))
    form.version.data = get_browser_version(request.headers.get('User-Agent'))
    # GET means you want to file a report.
    if request.method == 'GET':
        return render_template('index.html', form=form)
    # Form submission.
    elif request.method == 'POST' and form.validate():
        if request.form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(request.form)
                return redirect(url_for('thanks',
                                number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = request.form
                return redirect(url_for('login'))
        elif request.form.get('submit-type') == PROXY_REPORT:
            # `response` here is a Requests Response object, because
            # the proxy_report_issue crafts a manual request with Requests
            response = proxy_report_issue(request.form)
            return redirect(url_for('thanks',
                            number=response.json().get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=form)
Ejemplo n.º 10
0
def create_issue():
    """Creates a new issue.

    GET will return an HTML response for reporting issues
    POST will create a new issue
    """
    if request.method == 'GET':
        bug_form = get_form(request.headers.get('User-Agent'))
        if g.user:
            get_user_info()
        if request.args.get('src'):
            session['src'] = request.args.get('src')
        return render_template('new-issue.html', form=bug_form)
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    # see https://github.com/webcompat/webcompat.com/issues/1141
    # see https://github.com/webcompat/webcompat.com/issues/1237
    spamlist = ['qiangpiaoruanjian', 'cityweb.de']
    for spam in spamlist:
        if spam in form.get('url'):
            msg = (u'Anonymous reporting for domain {0} '
                   'is temporarily disabled. Please contact '
                   '[email protected] '
                   'for more details.').format(spam)
            flash(msg, 'notimeout')
            return redirect(url_for('index'))
    form['ua_header'] = request.headers.get('User-Agent')
    form['reported_with'] = session.pop('src', 'web')
    # Logging the ip and url for investigation
    log = app.logger
    log.setLevel(logging.INFO)
    log.info('{ip} {url}'.format(ip=request.remote_addr, url=form['url']))
    # form submission for 3 scenarios: authed, to be authed, anonymous
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            session['show_thanks'] = True
            return redirect(url_for('show_issue',
                                    number=response.get('number')))
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        session['show_thanks'] = True
        return redirect(url_for('show_issue', number=response.get('number')))
Ejemplo n.º 11
0
def create_issue():
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    form['ua_header'] = request.headers.get('User-Agent')
    # Do we have an image or screenshot ready to be uploaded?
    if ((request.files['image'] and request.files['image'].filename) or
       request.form.get('screenshot')):
        form['image_upload'] = json.loads(upload()[0])
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            return thanks_page(request, response)
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        return thanks_page(request, response)
Ejemplo n.º 12
0
def create_issue():
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    form['ua_header'] = request.headers.get('User-Agent')
    # Do we have an image or screenshot ready to be uploaded?
    if ((request.files['image'] and request.files['image'].filename)
            or request.form.get('screenshot')):
        form['image_upload'] = json.loads(upload()[0])
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            return thanks_page(request, response)
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        return thanks_page(request, response)
Ejemplo n.º 13
0
def create_issue():
    """Creates a new issue.

    GET will return an HTML response for reporting issues
    POST will create a new issue
    """
    if request.method == "GET":
        bug_form = get_form(request.headers.get("User-Agent"))
        if g.user:
            get_user_info()
        return render_template("new-issue.html", form=bug_form)
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    # see https://github.com/webcompat/webcompat.com/issues/1141
    spamlist = ["qiangpiaoruanjian"]
    for spam in spamlist:
        if spam in form.get("url"):
            msg = (
                u"Anonymous reporting for qiangpiaoruanjian.cn "
                "is temporarily disabled. Please see "
                "https://github.com/webcompat/webcompat.com/issues/1141 "
                "for more details."
            )
            flash(msg, "notimeout")
            return redirect(url_for("index"))
    form["ua_header"] = request.headers.get("User-Agent")
    # Store where the report originated from
    form["reported_with"] = request.headers.get("X-Reported-With", "web")
    # Logging the ip and url for investigation
    log = app.logger
    log.setLevel(logging.INFO)
    log.info("{ip} {url}".format(ip=request.remote_addr, url=form["url"]))
    # form submission for 3 scenarios: authed, to be authed, anonymous
    if form.get("submit-type") == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            return thanks_page(request, response)
        else:  # Stash form data into session, go do GitHub auth
            session["form_data"] = form
            return redirect(url_for("login"))
    elif form.get("submit-type") == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        return thanks_page(request, response)
Ejemplo n.º 14
0
def create_issue():
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    form['ua_header'] = request.headers.get('User-Agent')
    # Logging the ip and url for investigation
    log = app.logger
    log.setLevel(logging.INFO)
    log.info('{ip} {url}'.format(ip=request.remote_addr, url=form['url']))
    # form submission for 3 scenarios: authed, to be authed, anonymous
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            return thanks_page(request, response)
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        return thanks_page(request, response)
Ejemplo n.º 15
0
def create_issue():
    """Creates a new issue.

    GET will return an HTML response for reporting issues
    POST will create a new issue
    """
    if request.method == 'GET':
        bug_form = get_form(request.headers.get('User-Agent'))
        if g.user:
            get_user_info()
        return render_template('new-issue.html', form=bug_form)
    # copy the form so we can add the full UA string to it.
    form = request.form.copy()
    # see https://github.com/webcompat/webcompat.com/issues/1141
    spamlist = ['qiangpiaoruanjian']
    for spam in spamlist:
        if spam in form.get('url'):
            msg = (u'Anonymous reporting for qiangpiaoruanjian.cn '
                   'is temporarily disabled. Please see '
                   'https://github.com/webcompat/webcompat.com/issues/1141 '
                   'for more details.')
            flash(msg, 'notimeout')
            return redirect(url_for('index'))
    form['ua_header'] = request.headers.get('User-Agent')
    # Store where the report originated from
    form['reported_with'] = request.headers.get('X-Reported-With', 'web')
    # Logging the ip and url for investigation
    log = app.logger
    log.setLevel(logging.INFO)
    log.info('{ip} {url}'.format(ip=request.remote_addr, url=form['url']))
    # form submission for 3 scenarios: authed, to be authed, anonymous
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            return thanks_page(request, response)
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        return thanks_page(request, response)
Ejemplo n.º 16
0
def file_issue():
    """File an issue on behalf of the user that just gave us authorization."""
    form_data = session.get('form', None)
    if not session:
        abort(401)
    if session and (form_data is None):
        abort(403)
    json_response = report_issue(session['form'])
    # Get rid of stashed form data
    session.pop('form', None)
    session['show_thanks'] = True
    return redirect(url_for('show_issue', number=json_response.get('number')))
Ejemplo n.º 17
0
def file_issue():
    """File an issue on behalf of the user that just gave us authorization."""
    form_data = session.get('form', None)
    if not session:
        abort(401)
    if session and (form_data is None):
        abort(403)
    json_response = report_issue(session['form'])
    # Get rid of stashed form data
    session.pop('form', None)
    session['show_thanks'] = True
    return redirect(url_for('show_issue', number=json_response.get('number')))
Ejemplo n.º 18
0
def create_issue():
    """Create a new issue.

    GET will return an HTML response for reporting issues.
    POST will create a new issue.

    Any deceptive requests will be ended as a 400.
    See https://tools.ietf.org/html/rfc7231#section-6.5.1
    """
    # changing this from index to /issues/new to retire it,
    # and sending a 403 if anyone discovers this route
    abort(403)
    # Get the User-Agent
    user_agent = request.headers.get('User-Agent')
    # GET Requests
    if request.method == 'GET':
        bug_form = get_form(user_agent, request)
        # Note: `src` and `label` are special GET params that can pass
        # in extra information about a bug report. They're not part of the
        # HTML <form>, so we stick them in the session cookie so they survive
        # the scenario where the user decides to do authentication, and they
        # can then be passed on to form.py
        return render_template('new-issue.html', form=bug_form)
    # POST Requests
    if request.form:
        # Copy the form to add the full UA string.
        form = request.form.copy()
        if not is_valid_issue_form(form):
            abort(400)
    else:
        abort(400)
    # Feeding the form with request data
    form['ua_header'] = user_agent
    # form submission is anonymous!
    if form.get('submit_type') == PROXY_REPORT:
        response = report_issue(form, proxy=True)
        print('response: ', response.status_code)
        return redirect(url_for('thanks'))
    else:
        # if anything wrong, we assume it is a bad forged request
        abort(400)
Ejemplo n.º 19
0
def create_issue():
    """Create a new issue.

    GET will return an HTML response for reporting issues
    POST will create a new issue
    """
    if request.method == 'GET':
        bug_form = get_form(request.headers.get('User-Agent'))
        if g.user:
            get_user_info()
        # Note: `src` and `label` are special GET params that can pass
        # in extra information about a bug report. They're not part of the
        # HTML <form>, so we stick them in the session cookie so they survive
        # the scenario where the user decides to do authentication, and they
        # can then be passed on to form.py
        if request.args.get('src'):
            session['src'] = request.args.get('src')
        if request.args.get('label'):
            session['label'] = request.args.getlist('label')
        return render_template('new-issue.html', form=bug_form)
    # copy the form so we can add the full UA string to it.
    if request.form:
        form = request.form.copy()
        # To be legit the form needs a couple of parameters
        # if one essential is missing, it's a bad request
        must_parameters = set([
            'url', 'problem_category', 'description', 'os', 'browser',
            'username', 'submit-type'
        ])
        if not must_parameters.issubset(form.keys()):
            abort(400)
    else:
        # https://tools.ietf.org/html/rfc7231#section-6.5.1
        abort(400)
    # see https://github.com/webcompat/webcompat.com/issues/1141
    # see https://github.com/webcompat/webcompat.com/issues/1237
    # see https://github.com/webcompat/webcompat.com/issues/1627
    spamlist = ['qiangpiaoruanjian', 'cityweb.de', 'coco.fr']
    for spam in spamlist:
        if spam in form.get('url'):
            msg = (u'Anonymous reporting for domain {0} '
                   'is temporarily disabled. Please contact '
                   '[email protected] '
                   'for more details.').format(spam)
            flash(msg, 'notimeout')
            return redirect(url_for('index'))
    form['ua_header'] = request.headers.get('User-Agent')
    form['reported_with'] = session.pop('src', 'web')
    # Reminder: label is a list, if it exists
    form['extra_labels'] = session.pop('label', None)
    # Logging the ip and url for investigation
    log = app.logger
    log.setLevel(logging.INFO)
    log.info('{ip} {url}'.format(ip=request.remote_addr,
                                 url=form['url'].encode('utf-8')))
    # form submission for 3 scenarios: authed, to be authed, anonymous
    if form.get('submit-type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            response = report_issue(form)
            session['show_thanks'] = True
            return redirect(
                url_for('show_issue', number=response.get('number')))
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit-type') == PROXY_REPORT:
        response = report_issue(form, proxy=True).json()
        session['show_thanks'] = True
        return redirect(url_for('show_issue', number=response.get('number')))
    else:
        # if anything wrong, we assume it is a bad forged request
        abort(400)
Ejemplo n.º 20
0
def create_issue():
    """Create a new issue or prefill a form for submission.

    * HTTP GET with (optional) parameters
      * create a form with prefilled data.
      * parameters:
        * url: URL of the Web site
        * src: source of the request (web, addon, etc.)
        * label: controled list of labels
    * HTTP POST with a JSON payload
      * create a form with prefilled data
      * content-type is application/json
      * json may include:
        * title
        * User agent string
        * OS identification
        * labels list
        * type of bugs
        * short summary
        * full description
        * tested in another browser
        * body
    * HTTP POST with an attached form
      * submit a form to GitHub to create a new issue
      * form submit type:
        * authenticated: Github authentification
        * anonymous: handled by webcompat-bot

    Any deceptive requests will be ended as a 400.
    See https://tools.ietf.org/html/rfc7231#section-6.5.1
    """
    # Starting a logger
    log = app.logger
    log.setLevel(logging.INFO)
    if g.user:
        get_user_info()
    # We define which type of requests we are dealing with.
    request_type = form_type(request)
    # Form Prefill section
    if request_type == 'prefill':
        form_data = prepare_form(request)
        bug_form = get_form(form_data)
        session['extra_labels'] = form_data['extra_labels']
        return render_template('new-issue.html', form=bug_form)
    # Issue Creation section
    elif request_type == 'create':
        # Check if there is a form
        if not request.form:
            log.info('POST request without form.')
            abort(400)
        # Adding parameters to the form
        form = request.form.copy()
        extra_labels = session.pop('extra_labels', None)
        if extra_labels:
            form['extra_labels'] = extra_labels
        # Logging the ip and url for investigation
        log.info('{ip} {url}'.format(
            ip=request.remote_addr,
            url=form['url'].encode('utf-8')))
        # Checking blacklisted domains
        if is_blacklisted_domain(form['url']):
            msg = (u'Anonymous reporting for domain {0} '
                   'is temporarily disabled. Please contact '
                   '[email protected] '
                   'for more details.').format(form['url'])
            flash(msg, 'notimeout')
            return redirect(url_for('index'))
        # Check if the form is valid
        if not is_valid_issue_form(form):
            abort(400)
        # Anonymous reporting
        if form.get('submit_type') == PROXY_REPORT:
            json_response = report_issue(form, proxy=True)
            session['show_thanks'] = True
            return redirect(
                url_for('show_issue', number=json_response.get('number')))
        # Authenticated reporting
        if form.get('submit_type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                json_response = report_issue(form)
                session['show_thanks'] = True
                return redirect(url_for('show_issue',
                                        number=json_response.get('number')))
            else:
                # Stash form data into session, go do GitHub auth
                session['form'] = form
                return redirect(url_for('login'))
    else:
        abort(400)
Ejemplo n.º 21
0
def file_issue():
    """File an issue on behalf of the user that just gave us authorization."""
    response = report_issue(session["form_data"])
    # Get rid of stashed form data
    session.pop("form_data", None)
    return redirect(url_for("thanks", number=response.get("number")))
Ejemplo n.º 22
0
            contact_ready = get_contact_ready()
            needs_diagnosis = get_needs_diagnosis()
        else:
            user_issues = []
            contact_ready = proxy_get_contact_ready()
            needs_diagnosis = proxy_get_needs_diagnosis()
        return render_template('index.html',
                               form=bug_form,
                               user_issues=user_issues,
                               contact_ready=contact_ready,
                               needs_diagnosis=needs_diagnosis)
    # Form submission.
    elif request.method == 'POST' and bug_form.validate():
        if request.form.get('submit-type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                response = report_issue(request.form)
                return redirect(
                    url_for('thanks', number=response.get('number')))
            else:  # Stash form data into session, go do GitHub auth
                session['form_data'] = request.form
                return redirect(url_for('login'))
        elif request.form.get('submit-type') == PROXY_REPORT:
            # `response` here is a Requests Response object, because
            # the proxy_report_issue crafts a manual request with Requests
            response = proxy_report_issue(request.form)
            return redirect(url_for('thanks', number=response.get('number')))
    else:
        # Validation failed, re-render the form with the errors.
        return render_template('index.html', form=bug_form)

Ejemplo n.º 23
0
def create_issue():
    """Create a new issue or prefill a form for submission.

    * HTTP GET with (optional) parameters
      * create a form with prefilled data.
      * parameters:
        * url: URL of the Web site
        * src: source of the request (web, addon, etc.)
        * label: controled list of labels
    * HTTP POST with a JSON payload
      * create a form with prefilled data
      * content-type is application/json
      * json may include:
        * title
        * User agent string
        * OS identification
        * labels list
        * type of bugs
        * short summary
        * full description
        * tested in another browser
        * body
        * utm_ params for Google Analytics
    * HTTP POST with an attached form
      * submit a form to GitHub to create a new issue
      * form submit type:
        * authenticated: Github authentification
        * anonymous: handled by webcompat-bot

    Any deceptive requests will be ended as a 400.
    See https://tools.ietf.org/html/rfc7231#section-6.5.1
    """
    push('/css/dist/webcompat.min.css', **{'as': 'style', 'rel': 'preload'})
    push(bust_cache('/js/dist/webcompat.min.js'), **{
        'as': 'script',
        'rel': 'preload'
    })
    # Starting a logger
    log = app.logger
    log.setLevel(logging.INFO)
    if g.user:
        get_user_info()
    # We define which type of requests we are dealing with.
    request_type = form_type(request)
    # Form Prefill section
    if request_type == 'prefill':
        form_data = prepare_form(request)
        # XXXTemp Hack: if the user clicked on Report Site Issue from Release,
        # we want to redirect them somewhere else and forget all their data.
        # See https://bugzilla.mozilla.org/show_bug.cgi?id=1513541
        if form_data == 'release':
            return render_template('thanks.html')
        bug_form = get_form(form_data)
        session['extra_labels'] = form_data['extra_labels']
        source = form_data.pop('utm_source', None)
        campaign = form_data.pop('utm_campaign', None)
        return render_template('new-issue.html',
                               form=bug_form,
                               source=source,
                               campaign=campaign,
                               nonce=request.nonce)
    # Issue Creation section
    elif request_type == 'create':
        # Check if there is a form
        if not request.form:
            log.info('POST request without form.')
            abort(400)
        # Adding parameters to the form
        form = request.form.copy()
        extra_labels = session.pop('extra_labels', None)
        if extra_labels:
            form['extra_labels'] = extra_labels
        # Logging the ip and url for investigation
        log.info('{ip} {url}'.format(ip=request.remote_addr,
                                     url=form['url'].encode('utf-8')))
        # Check if the form is valid
        if not is_valid_issue_form(form):
            abort(400)
        if form.get('submit_type') == PROXY_REPORT:
            # Checking blacklisted domains
            domain = urlparse.urlsplit(form['url']).hostname
            if is_blacklisted_domain(domain):
                msg = app.config['IS_BLACKLISTED_DOMAIN'].format(form['url'])
                flash(msg, 'notimeout')
                return redirect(url_for('index'))
            # Anonymous reporting
            json_response = report_issue(form, proxy=True)
            session['show_thanks'] = True
            return redirect(
                url_for('show_issue', number=json_response.get('number')))
        # Authenticated reporting
        if form.get('submit_type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                json_response = report_issue(form)
                session['show_thanks'] = True
                return redirect(
                    url_for('show_issue', number=json_response.get('number')))
            else:
                # Stash form data into session, go do GitHub auth
                session['form'] = form
                return redirect(url_for('login'))
    else:
        abort(400)
Ejemplo n.º 24
0
def create_issue():
    """Create a new issue or prefill a form for submission.

    * HTTP GET with (optional) parameters
      * create a form with prefilled data.
      * parameters:
        * url: URL of the Web site
        * src: source of the request (web, addon, etc.)
        * label: controled list of labels
    * HTTP POST with a JSON payload
      * create a form with prefilled data
      * content-type is application/json
      * json may include:
        * title
        * User agent string
        * OS identification
        * labels list
        * type of bugs
        * short summary
        * full description
        * tested in another browser
        * body
        * utm_ params for Google Analytics
    * HTTP POST with an attached form
      * submit a form to GitHub to create a new issue
      * form submit type:
        * authenticated: Github authentification
        * anonymous: handled by webcompat-bot

    Any deceptive requests will be ended as a 400.
    See https://tools.ietf.org/html/rfc7231#section-6.5.1
    """
    push('/css/dist/webcompat.min.css', **{
        'as': 'style',
        'rel': 'preload'
    })
    push(bust_cache('/js/dist/webcompat.min.js'), **{
        'as': 'script',
        'rel': 'preload'
    })
    # Starting a logger
    log = app.logger
    log.setLevel(logging.INFO)
    if g.user:
        get_user_info()
    # We define which type of requests we are dealing with.
    request_type = form_type(request)
    # Form Prefill section
    if request_type == 'prefill':
        form_data = prepare_form(request)
        bug_form = get_form(form_data)
        session['extra_labels'] = form_data['extra_labels']
        source = form_data.pop('utm_source', None)
        campaign = form_data.pop('utm_campaign', None)
        return render_template('new-issue.html', form=bug_form, source=source,
                               campaign=campaign, nonce=request.nonce)
    # Issue Creation section
    elif request_type == 'create':
        # Check if there is a form
        if not request.form:
            log.info('POST request without form.')
            abort(400)
        # Adding parameters to the form
        form = request.form.copy()
        extra_labels = session.pop('extra_labels', None)
        if extra_labels:
            form['extra_labels'] = extra_labels
        # Logging the ip and url for investigation
        log.info('{ip} {url}'.format(
            ip=request.remote_addr,
            url=form['url'].encode('utf-8')))
        # Check if the form is valid
        if not is_valid_issue_form(form):
            abort(400)
        if form.get('submit_type') == PROXY_REPORT:
            # Checking blacklisted domains
            domain = urlparse.urlsplit(form['url']).hostname
            if is_blacklisted_domain(domain):
                msg = app.config['IS_BLACKLISTED_DOMAIN'].format(form['url'])
                flash(msg, 'notimeout')
                return redirect(url_for('index'))
            # Anonymous reporting
            json_response = report_issue(form, proxy=True)
            session['show_thanks'] = True
            return redirect(
                url_for('show_issue', number=json_response.get('number')))
        # Authenticated reporting
        if form.get('submit_type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                json_response = report_issue(form)
                session['show_thanks'] = True
                return redirect(url_for('show_issue',
                                        number=json_response.get('number')))
            else:
                # Stash form data into session, go do GitHub auth
                session['form'] = form
                return redirect(url_for('login'))
    else:
        abort(400)
Ejemplo n.º 25
0
def create_issue():
    """Create a new issue.

    GET will return an HTML response for reporting issues.
    POST will create a new issue.

    Any deceptive requests will be ended as a 400.
    See https://tools.ietf.org/html/rfc7231#section-6.5.1
    """
    # Starting a logger
    log = app.logger
    log.setLevel(logging.INFO)
    # Get the User-Agent
    user_agent = request.headers.get('User-Agent')
    # GET Requests
    if request.method == 'GET':
        bug_form = get_form(user_agent)
        if g.user:
            get_user_info()
        # Note: `src` and `label` are special GET params that can pass
        # in extra information about a bug report. They're not part of the
        # HTML <form>, so we stick them in the session cookie so they survive
        # the scenario where the user decides to do authentication, and they
        # can then be passed on to form.py
        if request.args.get('src'):
            session['src'] = request.args.get('src')
        if request.args.get('label'):
            session['label'] = request.args.getlist('label')
        return render_template('new-issue.html', form=bug_form)
    # POST Requests
    if request.form:
        # Copy the form to add the full UA string.
        form = request.form.copy()
        if not is_valid_issue_form(form):
            abort(400)
    else:
        log.info('POST request without form.')
        abort(400)
    # Logging the ip and url for investigation
    log.info('{ip} {url}'.format(
        ip=request.remote_addr,
        url=form['url'].encode('utf-8')))
    # Checking blacklisted domains
    if is_blacklisted_domain(form['url']):
        msg = (u'Anonymous reporting for domain {0} '
               'is temporarily disabled. Please contact '
               '[email protected] '
               'for more details.').format(form['url'])
        flash(msg, 'notimeout')
        return redirect(url_for('index'))
    # Feeding the form with request data
    form['ua_header'] = user_agent
    form['reported_with'] = session.pop('src', 'web')
    # Reminder: label is a list, if it exists
    form['extra_labels'] = session.pop('label', None)
    # form submission for 3 scenarios: authed, to be authed, anonymous
    if form.get('submit_type') == AUTH_REPORT:
        if g.user:  # If you're already authed, submit the bug.
            json_response = report_issue(form)
            session['show_thanks'] = True
            return redirect(url_for('show_issue',
                                    number=json_response.get('number')))
        else:  # Stash form data into session, go do GitHub auth
            session['form_data'] = form
            return redirect(url_for('login'))
    elif form.get('submit_type') == PROXY_REPORT:
        json_response = report_issue(form, proxy=True)
        session['show_thanks'] = True
        return redirect(url_for('show_issue',
                                number=json_response.get('number')))
    else:
        # if anything wrong, we assume it is a bad forged request
        abort(400)