Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #179 from jjnicola/check-status-2
Browse files Browse the repository at this point in the history
[2.0] Check the existence and status of an scan_id
  • Loading branch information
bjoernricks authored Nov 8, 2019
2 parents fdbf434 + 30a3398 commit 4981808
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Set loglevel to debug for some message. [#159](https://github.com/greenbone/ospd/pull/159)
- Improve error handling when stop a scan. [#163](https://github.com/greenbone/ospd/pull/163)
- Check the existence and status of an scan_id. [#179](https://github.com/greenbone/ospd/pull/179)

### Fixed
- Fix set permission in unix socket. [#157](https://github.com/greenbone/ospd/pull/157)
Expand Down
24 changes: 21 additions & 3 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,15 @@ def handle_start_scan_command(self, scan_et):
scan_func = self.start_scan
scan_params = self.process_scan_params(params)

scan_id_aux = scan_id
scan_id = self.create_scan(
scan_id, scan_targets, scan_params, vt_selection
)
if not scan_id:
id_ = Element('id')
id_.text = scan_id_aux
return simple_response_str('start_scan', 100, 'Continue', id_)

scan_process = multiprocessing.Process(
target=scan_func, args=(scan_id, scan_targets, parallel)
)
Expand Down Expand Up @@ -1705,11 +1711,23 @@ def create_scan(self, scan_id, targets, options, vts):
@target: Target to scan.
@options: Miscellaneous scan options.
@return: New scan's ID.
@return: New scan's ID. None if the scan_id already exists and the
scan status is RUNNING or FINISHED.
"""
if self.scan_exists(scan_id):
logger.info("Scan %s exists. Resuming scan.", scan_id)
status = None
scan_exists = self.scan_exists(scan_id)
if scan_id and scan_exists:
status = self.get_scan_status(scan_id)

if scan_exists and status == ScanStatus.STOPPED:
logger.info("Scan %s exists. Resuming scan.", scan_id)
elif scan_exists and (
status == ScanStatus.RUNNING or status == ScanStatus.FINISHED
):
logger.info(
"Scan %s exists with status %s.", scan_id, status.name.lower()
)
return
return self.scan_collection.create_scan(scan_id, targets, options, vts)

def get_scan_options(self, scan_id):
Expand Down

0 comments on commit 4981808

Please sign in to comment.