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

Commit

Permalink
Simplify start_scan and remove the recently added get_target() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed May 19, 2020
1 parent e0c2fbf commit 22a147f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
21 changes: 9 additions & 12 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,25 +505,21 @@ def handle_client_stream(self, stream: Stream) -> None:

stream.close()

def process_finished_hosts(self, scan_id: str, finished_hosts: str) -> None:
def process_finished_hosts(self, scan_id: str) -> None:
""" Process the finished hosts before launching the scans."""

finished_hosts = self.scan_collection.get_finished_hosts(scan_id)
if not finished_hosts:
return

exc_finished_hosts_list = target_str_to_list(finished_hosts)
self.scan_collection.set_host_finished(scan_id, exc_finished_hosts_list)

def start_scan(self, scan_id: str, target: Dict) -> None:
def start_scan(self, scan_id: str) -> None:
""" Starts the scan with scan_id. """
os.setsid()

if target is None or not target:
raise OspdCommandError('Erroneous target', 'start_scan')

logger.info("%s: Scan started.", scan_id)

self.process_finished_hosts(scan_id, target.get('finished_hosts'))
self.process_finished_hosts(scan_id)

try:
self.set_scan_status(scan_id, ScanStatus.RUNNING)
Expand Down Expand Up @@ -1188,11 +1184,12 @@ def run(self) -> None:
def start_pending_scans(self):
for scan_id in self.scan_collection.ids_iterator():
if self.get_scan_status(scan_id) == ScanStatus.PENDING:
scan_target = self.scan_collection.get_target(scan_id)

scan_func = self.start_scan
scan_process = create_process(
func=scan_func, args=(scan_id, scan_target)
)

print(scan_id)
scan_process = create_process(func=scan_func, args=(scan_id,))

self.scan_processes[scan_id] = scan_process
scan_process.start()
self.set_scan_status(scan_id, ScanStatus.INIT)
Expand Down
6 changes: 0 additions & 6 deletions ospd/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,6 @@ def get_target_options(self, scan_id: str) -> Dict[str, str]:
"""
return self.scans_table[scan_id]['target'].get('options')

def get_target(
self, scan_id: str
) -> Dict[str, Union[str, Dict[str, Union[str, Dict[str, str]]]]]:
""" Get the complete target info"""
return self.scans_table[scan_id].get('target')

def get_vts(self, scan_id: str) -> Dict[str, Union[Dict[str, str], List]]:
""" Get a scan's vts. """
scan_info = self.scans_table[scan_id]
Expand Down

0 comments on commit 22a147f

Please sign in to comment.