Няма описание

manage_assets_routes.py 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # IRIS Source Code
  2. # Copyright (C) 2024 - DFIR-IRIS
  3. # 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 request
  20. from werkzeug import Response
  21. from app.datamgmt.manage.manage_assets_db import get_filtered_assets
  22. from app.iris_engine.access_control.utils import ac_fast_check_current_user_has_case_access
  23. from app.models.authorization import CaseAccessLevel
  24. from app.schema.marshables import CaseAssetsSchema
  25. from app.blueprints.access_controls import ac_api_requires
  26. from app.blueprints.access_controls import ac_api_return_access_denied
  27. from app.blueprints.responses import response_success
  28. manage_assets_rest_blueprint = Blueprint('manage_assets_rest', __name__)
  29. @manage_assets_rest_blueprint.route('/manage/assets/filter', methods=['GET'])
  30. @ac_api_requires()
  31. def manage_assets_filter() -> Response:
  32. """Returns a list of assets, filtered by the given parameters."""
  33. page = request.args.get('page', 1, type=int)
  34. per_page = request.args.get('per_page', 10, type=int)
  35. order_by = request.args.get('order_by', 'name', type=str)
  36. sort_dir = request.args.get('sort_dir', 'asc', type=str)
  37. case_id = request.args.get('case_id', None, type=int)
  38. client_id = request.args.get('customer_id', None, type=int)
  39. asset_type_id = request.args.get('asset_type_id', None, type=int)
  40. asset_id = request.args.get('asset_id', None, type=int)
  41. asset_name = request.args.get('asset_name', None, type=str)
  42. asset_description = request.args.get('asset_description', None, type=str)
  43. asset_ip = request.args.get('asset_ip', None, type=str)
  44. draw = request.args.get('draw', None, type=int)
  45. if type(draw) is not int:
  46. draw = 1
  47. if case_id and ac_fast_check_current_user_has_case_access(case_id, [CaseAccessLevel.deny_all]):
  48. return ac_api_return_access_denied()
  49. filtered_assets = get_filtered_assets(case_id=case_id,
  50. client_id=client_id,
  51. asset_type_id=asset_type_id,
  52. asset_id=asset_id,
  53. asset_name=asset_name,
  54. asset_description=asset_description,
  55. asset_ip=asset_ip,
  56. page=page,
  57. per_page=per_page,
  58. sort_by=order_by,
  59. sort_dir=sort_dir)
  60. assets = {
  61. 'total': filtered_assets.total,
  62. 'assets': CaseAssetsSchema().dump(filtered_assets.items, many=True),
  63. 'last_page': filtered_assets.pages,
  64. 'current_page': filtered_assets.page,
  65. 'next_page': filtered_assets.next_num if filtered_assets.has_next else None,
  66. 'draw': draw
  67. }
  68. return response_success('', data=assets)