Ei kuvausta

manage_case_templates_routes.py 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # IRIS Source Code
  2. # contact@dfir-iris.org
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 3 of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. from flask import Blueprint
  18. from flask import redirect
  19. from flask import render_template
  20. from flask import url_for
  21. from app.datamgmt.manage.manage_case_templates_db import get_case_template_by_id
  22. from app.forms import CaseTemplateForm
  23. from app.forms import AddAssetForm
  24. from app.models.models import CaseTemplate
  25. from app.models.authorization import Permissions
  26. from app.blueprints.access_controls import ac_requires
  27. from app.blueprints.responses import response_error
  28. manage_case_templates_blueprint = Blueprint('manage_case_templates',
  29. __name__,
  30. template_folder='templates')
  31. @manage_case_templates_blueprint.route('/manage/case-templates', methods=['GET'])
  32. @ac_requires(Permissions.case_templates_read)
  33. def manage_case_templates(caseid, url_redir):
  34. if url_redir:
  35. return redirect(url_for('manage_case_templates.manage_case_templates', cid=caseid))
  36. form = AddAssetForm()
  37. return render_template('manage_case_templates.html', form=form)
  38. @manage_case_templates_blueprint.route('/manage/case-templates/<int:cur_id>/modal', methods=['GET'])
  39. @ac_requires(Permissions.case_templates_read)
  40. def case_template_modal(cur_id, caseid, url_redir):
  41. """Get a case template
  42. Args:
  43. cur_id (int): case template id
  44. Returns:
  45. HTML Template: Case template modal
  46. """
  47. if url_redir:
  48. return redirect(url_for('manage_case_templates.manage_case_templates', cid=caseid))
  49. form = CaseTemplateForm()
  50. case_template = get_case_template_by_id(cur_id)
  51. if not case_template:
  52. return response_error(f"Invalid Case template ID {cur_id}")
  53. # Temporary : for now we build the full JSON form object based on case templates attributes
  54. # Next step : add more fields to the form
  55. case_template_dict = {
  56. "name": case_template.name,
  57. "display_name": case_template.display_name,
  58. "description": case_template.description,
  59. "author": case_template.author,
  60. "title_prefix": case_template.title_prefix,
  61. "summary": case_template.summary,
  62. "tags": case_template.tags,
  63. "tasks": case_template.tasks,
  64. "note_directories": case_template.note_directories,
  65. "classification": case_template.classification
  66. }
  67. form.case_template_json.data = case_template_dict
  68. return render_template("modal_case_template.html", form=form, case_template=case_template)
  69. @manage_case_templates_blueprint.route('/manage/case-templates/add/modal', methods=['GET'])
  70. @ac_requires(Permissions.case_templates_write, no_cid_required=True)
  71. def add_template_modal(caseid, url_redir):
  72. if url_redir:
  73. return redirect(url_for('manage_case_templates.manage_case_templates', cid=caseid))
  74. case_template = CaseTemplate()
  75. form = CaseTemplateForm()
  76. form.case_template_json.data = {
  77. "name": "Template name",
  78. "display_name": "Template Display Name",
  79. "description": "Template description",
  80. "author": "YOUR NAME",
  81. "classification": "known-template-classification",
  82. "title_prefix": "[PREFIX]",
  83. "summary": "Summary to be set",
  84. "tags": ["ransomware", "malware"],
  85. "tasks": [
  86. {
  87. "title": "Task 1",
  88. "description": "Task 1 description",
  89. "tags": ["tag1", "tag2"]
  90. }
  91. ],
  92. "note_directories": [
  93. {
  94. "title": "Note group 1",
  95. "notes": [
  96. {
  97. "title": "Note 1",
  98. "content": "Note 1 content"
  99. }
  100. ]
  101. }
  102. ]
  103. }
  104. return render_template("modal_case_template.html", form=form, case_template=case_template)
  105. @manage_case_templates_blueprint.route('/manage/case-templates/upload/modal', methods=['GET'])
  106. @ac_requires(Permissions.case_templates_write, no_cid_required=True)
  107. def upload_template_modal(caseid, url_redir):
  108. if url_redir:
  109. return redirect(url_for('manage_case_templates.manage_case_templates', cid=caseid))
  110. return render_template("modal_upload_case_template.html")