Example #1
0
    def add_comment(self, id):
        if comments_enabled():
            f = File(get_or_404(current_user.files, _id=id))

            if current_user.has_permission('add_probable_name'):
                probable_name = request.form.get('probable_name')
            else:
                probable_name = None

            comment = request.form.get('comment')
            analysis_id = request.form.get('analysis')
            notify = request.form.get('notify')

            if comment:
                # If there is an analysis ID, make sure it is accessible
                if analysis_id:
                    get_or_404(current_user.analyses, _id=analysis_id)

                f.add_comment(current_user['_id'], comment, analysis_id, probable_name)
                if notify:
                    self.notify_new_comment(f, analysis_id, current_user['_id'], comment)

            else:
                flash('Comment should not be empty', 'danger')

        return redirect(request.referrer)
Example #2
0
    def add_comment(self, id):
        if comments_enabled():
            f = File(get_or_404(current_user.files, _id=id))

            if current_user.has_permission("add_probable_name"):
                probable_name = request.form.get("probable_name")
            else:
                probable_name = None

            comment = request.form.get("comment")
            analysis_id = request.form.get("analysis")
            notify = request.form.get("notify")

            if comment:
                # If there is an analysis ID, make sure it is accessible
                if analysis_id:
                    get_or_404(current_user.analyses, _id=analysis_id)

                f.add_comment(current_user["_id"], comment, analysis_id,
                              probable_name, notify)
            else:
                flash("Comment should not be empty", "danger")

        return redirect(request.referrer)
Example #3
0
    def post(self):
        """Create a new analysis.

        .. :quickref: Analysis; Create an analysis

        Launch a new analysis. You have to specify on which object this analysis
        will be made, by specifying one of:

        * ``file_id`` for an existing object
        * ``file`` for file uploads
        * ``url``
        * ``hash`` if VirusTotal sample retrieval is enabled.

        You should also supply all enabled analysis options with the name
        ``options[OPTION_NAME]``. For boolean options, any value different than
        ``0`` or ``False`` means the option is enabled.

        If the submitted object already exists (and ``file_id`` was not specified),
        the response will be a file object. When a new analysis was successfuly
        created, the analysis object will be returned, in the ``analysis`` field.

        If there was error in your submission, they will be returned in the
        ``errors`` field.

        **Example request**::

            headers = {
                'Accept': "application/json",
                'X-API-KEY': FAME_API_KEY
            }

            with open(filepath, 'rb') as f:
                params = {
                    'options[allow_internet_access]':  "on",
                    'options[analysis_time]': "300",
                    'groups': "cert"
                }

                files = {
                    'file': f
                }

                r = requests.post(ENDPOINT, data=params, files=files, headers=headers)

        :form string file_id: (optional) the id of the object on which this analysis should run.
        :form file file: (optional) file to analyze.
        :form string url: (optional) url to analyze.
        :form string hash: (optional) hash to analyze.
        :form string module: (optional) the name of the target module.
        :form string groups: a comma-separated list of groups that will have access to this analysis.
        :form string comment: comment to add to this object.
        :form string option[*]: value of each enabled option.
        """
        file_id = request.form.get('file_id')
        modules = filter(None, request.form.get('modules', '').split(','))
        groups = request.form.get('groups', '').split(',')
        comment = request.form.get('comment', '')

        options = get_options()
        if options is None:
            return validation_error()

        valid_submission = self._validate_form(groups, modules, options)
        if not valid_submission:
            return validation_error()

        if file_id is not None:
            f = File(get_or_404(current_user.files, _id=file_id))
            analysis = {
                'analysis':
                f.analyze(groups, current_user['_id'], modules, options)
            }
            return redirect(
                analysis,
                url_for('AnalysesView:get', id=analysis['analysis']['_id']))
        else:
            # When this is a new submission, validate the comment
            if not self._validate_comment(comment):
                return validation_error()

            f = self._get_object_to_analyze()
            if f is not None:
                f.add_owners(set(current_user['groups']) & set(groups))

                if comment:
                    f.add_comment(current_user['_id'], comment)

                if f.existing:
                    f.add_groups(groups)
                    flash(
                        "File already exists, so the analysis was not launched."
                    )

                    return redirect(clean_files(f),
                                    url_for('FilesView:get', id=f['_id']))
                else:
                    analysis = {
                        'analysis':
                        clean_analyses(
                            f.analyze(groups, current_user['_id'], modules,
                                      options))
                    }
                    analysis['analysis']['file'] = clean_files(f)

                    return redirect(
                        analysis,
                        url_for('AnalysesView:get',
                                id=analysis['analysis']['_id']))
            else:
                return render_template('analyses/new.html',
                                       options=dispatcher.options)