Brak opisu

case_rfiles_routes.py 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # IRIS Source Code
  2. # Copyright (C) 2021 - Airbus CyberSecurity (SAS) - DFIR-IRIS Team
  3. # ir@cyberactionlab.net - contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from flask import Blueprint
  19. from flask import redirect
  20. from flask import render_template
  21. from flask import url_for
  22. from flask_wtf import FlaskForm
  23. from app.datamgmt.case.case_db import get_case
  24. from app.datamgmt.case.case_rfiles_db import get_case_evidence_comments_count
  25. from app.datamgmt.case.case_rfiles_db import get_rfile
  26. from app.datamgmt.manage.manage_attribute_db import get_default_custom_attributes
  27. from app.models.authorization import CaseAccessLevel
  28. from app.blueprints.access_controls import ac_case_requires
  29. from app.blueprints.responses import response_error
  30. case_rfiles_blueprint = Blueprint(
  31. 'case_rfiles',
  32. __name__,
  33. template_folder='templates'
  34. )
  35. @case_rfiles_blueprint.route('/case/evidences', methods=['GET'])
  36. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  37. def case_rfile(caseid, url_redir):
  38. if url_redir:
  39. return redirect(url_for('case_rfiles.case_rfile', cid=caseid, redirect=True))
  40. form = FlaskForm()
  41. case = get_case(caseid)
  42. return render_template("case_rfile.html", case=case, form=form)
  43. @case_rfiles_blueprint.route('/case/evidences/<int:cur_id>/modal', methods=['GET'])
  44. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  45. def case_edit_rfile_modal(cur_id, caseid, url_redir):
  46. if url_redir:
  47. return redirect(url_for('case_rfiles.case_rfile', cid=caseid, redirect=True))
  48. crf = get_rfile(cur_id, caseid)
  49. if not crf:
  50. return response_error("Invalid evidence ID for this case")
  51. comments_map = get_case_evidence_comments_count([cur_id])
  52. return render_template("modal_add_case_rfile.html", rfile=crf, attributes=crf.custom_attributes,
  53. comments_map=comments_map)
  54. @case_rfiles_blueprint.route('/case/evidences/add/modal', methods=['GET'])
  55. @ac_case_requires(CaseAccessLevel.full_access)
  56. def case_add_rfile_modal(caseid, url_redir):
  57. if url_redir:
  58. return redirect(url_for('case_rfiles.case_rfile', cid=caseid, redirect=True))
  59. return render_template("modal_add_case_rfile.html", rfile=None, attributes=get_default_custom_attributes('evidence'))
  60. @case_rfiles_blueprint.route('/case/evidences/<int:cur_id>/comments/modal', methods=['GET'])
  61. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  62. def case_comment_evidence_modal(cur_id, caseid, url_redir):
  63. if url_redir:
  64. return redirect(url_for('case_task.case_task', cid=caseid, redirect=True))
  65. evidence = get_rfile(cur_id, caseid=caseid)
  66. if not evidence:
  67. return response_error('Invalid evidence ID')
  68. return render_template("modal_conversation.html", element_id=cur_id, element_type='evidences',
  69. title=evidence.filename)