Skip to content

Commit

Permalink
Merge pull request greenbone#182 from jjnicola/finished-excluded
Browse files Browse the repository at this point in the history
Remove from exclude_host list the hosts passed as finished too.
  • Loading branch information
bjoernricks committed Nov 14, 2019
2 parents 5ae9d12 + f2c0f32 commit 58cb0c7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- Fix set permission in unix socket. [#157](https://github.com/greenbone/ospd/pull/157)
- Fix VT filter. [#165](https://github.com/greenbone/ospd/pull/165)
- Remove from exclude_host list the hosts passed as finished too. [#183](https://github.com/greenbone/ospd/pull/183)

[2.0.1]: https://github.com/greenbone/ospd/compare/v2.0.0...ospd-2.0

Expand Down
38 changes: 34 additions & 4 deletions ospd/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def set_host_progress(self, scan_id, target, host, progress):
def set_host_finished(self, scan_id, target, host):
""" Add the host in a list of finished hosts """
finished_hosts = self.scans_table[scan_id]['finished_hosts']
finished_hosts[target].append(host)

if host not in finished_hosts[target]:
finished_hosts[target].append(host)

self.scans_table[scan_id]['finished_hosts'] = finished_hosts

def get_hosts_unfinished(self, scan_id):
Expand Down Expand Up @@ -284,15 +287,34 @@ def get_progress(self, scan_id):

return self.scans_table[scan_id]['progress']

def simplify_exclude_host_list(self, scan_id, target):
""" Remove from exclude_hosts the received hosts in the finished_hosts
list sent by the client.
The finished hosts are sent also as exclude hosts for backward
compatibility purposses.
"""

exc_hosts_list = target_str_to_list(
self.get_exclude_hosts(scan_id, target)
)

finished_hosts_list = target_str_to_list(
self.get_finished_hosts(scan_id, target)
)
if finished_hosts_list and exc_hosts_list:
for finished in finished_hosts_list:
if finished in exc_hosts_list:
exc_hosts_list.remove(finished)

return exc_hosts_list

def get_target_progress(self, scan_id, target):
""" Get a target's current progress value.
The value is calculated with the progress of each single host
in the target."""

total_hosts = len(target_str_to_list(target))
exc_hosts_list = target_str_to_list(
self.get_exclude_hosts(scan_id, target)
)
exc_hosts_list = self.simplify_exclude_host_list(scan_id, target)
exc_hosts = len(exc_hosts_list) if exc_hosts_list else 0
host_progresses = self.scans_table[scan_id]['target_progress'].get(
target
Expand Down Expand Up @@ -345,6 +367,14 @@ def get_exclude_hosts(self, scan_id, target):
if target == item[0]:
return item[3]

def get_finished_hosts(self, scan_id, target):
""" Get the finished host list sent by the client for a given target.
"""
if target:
for item in self.scans_table[scan_id]['targets']:
if target == item[0]:
return item[4]

def get_credentials(self, scan_id, target):
""" Get a scan's credential list. It return dictionary with
the corresponding credential for a given target.
Expand Down
3 changes: 3 additions & 0 deletions ospd/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ def target_str_to_list(target_str: str) -> Optional[List]:
""" Parses a targets string into a list of individual targets. """
new_list = list()

if not target_str:
return None

for target in target_str.split(','):

target = target.strip()
Expand Down

0 comments on commit 58cb0c7

Please sign in to comment.