This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from GreatFruitOmsk/issue_210
Fix issue with IPv6 and blocking
- Loading branch information
Showing
6 changed files
with
94 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
backend/device_registry/migrations/0035_fix_missing_protocol_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Generated by Django 2.1.7 on 2019-05-27 10:29 | ||
|
||
from django.db import migrations | ||
|
||
from netaddr import IPAddress | ||
|
||
|
||
def fix_missing_protocol_version(apps, schema_editor): | ||
PortScan = apps.get_model('device_registry', 'PortScan') | ||
for instance in PortScan.objects.all(): | ||
# Fix `block_ports`. | ||
block_ports = instance.block_ports | ||
for record in block_ports: | ||
ipaddr = IPAddress(record[0]) | ||
# Check if it's IPv6 address or not. | ||
is_v6 = ipaddr.version == 6 | ||
if len(record) == 3: | ||
record.append(is_v6) | ||
# Fix `scan_info`. | ||
scan_info = instance.scan_info | ||
for record in scan_info: | ||
if 'ip_version' not in record: | ||
ipaddr = IPAddress(record['host']) | ||
record['ip_version'] = ipaddr.version | ||
# Fix `block_networks`. | ||
block_networks = instance.block_networks | ||
block_networks_list = [] | ||
for record in block_networks: | ||
if not isinstance(record, list): | ||
ipaddr = IPAddress(record) | ||
block_networks_list.append([record, ipaddr.version == 6]) | ||
else: | ||
block_networks_list.append(record) | ||
instance.block_networks = block_networks_list | ||
|
||
instance.save(update_fields=['block_ports', 'scan_info', 'block_networks']) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('device_registry', '0034_device_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(fix_missing_protocol_version), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters