From efd6e1f99afa2cea5e3642fd22d40d37a505d90a Mon Sep 17 00:00:00 2001 From: stuppie Date: Sun, 15 Mar 2026 15:58:59 -0600 Subject: add migration 0009 --- ...p_portscanport_iplabel_mtr_portscan_and_more.py | 353 +++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 generalresearch/thl_django/migrations/0009_toolrun_mtrhop_portscanport_iplabel_mtr_portscan_and_more.py diff --git a/generalresearch/thl_django/migrations/0009_toolrun_mtrhop_portscanport_iplabel_mtr_portscan_and_more.py b/generalresearch/thl_django/migrations/0009_toolrun_mtrhop_portscanport_iplabel_mtr_portscan_and_more.py new file mode 100644 index 0000000..e19a353 --- /dev/null +++ b/generalresearch/thl_django/migrations/0009_toolrun_mtrhop_portscanport_iplabel_mtr_portscan_and_more.py @@ -0,0 +1,353 @@ +# Generated by Django 6.0 on 2026-03-15 20:17 + +import django.contrib.postgres.indexes +import django.db.models.deletion +import django.utils.timezone +from django.contrib.postgres.operations import CreateExtension + +import generalresearch.thl_django.fields +import uuid +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("thl_django", "0008_question_explanation_fragment_template_and_more"), + ] + + operations = [ + CreateExtension("btree_gist"), + migrations.CreateModel( + name="ToolRun", + fields=[ + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ("ip", models.GenericIPAddressField()), + ("scan_group_id", models.UUIDField(default=uuid.uuid4)), + ( + "tool_class", + models.CharField( + choices=[ + ("port_scan", "Port Scan"), + ("rdns", "Rdns"), + ("ping", "Ping"), + ("traceroute", "Traceroute"), + ], + max_length=32, + ), + ), + ("tool_name", models.CharField(max_length=64)), + ("tool_version", models.CharField(max_length=32, null=True)), + ("started_at", models.DateTimeField()), + ("finished_at", models.DateTimeField(null=True)), + ( + "status", + models.CharField( + choices=[ + ("success", "Success"), + ("failed", "Failed"), + ("timeout", "Timeout"), + ("error", "Error"), + ], + default="success", + max_length=16, + ), + ), + ("raw_command", models.TextField()), + ("config", models.JSONField(null=True)), + ], + options={ + "db_table": "network_toolrun", + }, + ), + migrations.CreateModel( + name="MTRHop", + fields=[ + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ("hop", models.PositiveSmallIntegerField()), + ("ip", models.GenericIPAddressField(null=True)), + ("domain", models.CharField(max_length=255, null=True)), + ("asn", models.PositiveIntegerField(null=True)), + ], + options={ + "db_table": "network_mtrhop", + }, + ), + migrations.CreateModel( + name="PortScanPort", + fields=[ + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ("protocol", models.PositiveSmallIntegerField(default=6)), + ("port", models.PositiveIntegerField(null=True)), + ("state", models.CharField(max_length=20)), + ("reason", models.CharField(max_length=32, null=True)), + ("reason_ttl", models.IntegerField(null=True)), + ("service_name", models.CharField(max_length=64, null=True)), + ], + options={ + "db_table": "network_portscanport", + }, + ), + migrations.CreateModel( + name="IPLabel", + fields=[ + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ("ip", generalresearch.thl_django.fields.CIDRField()), + ("labeled_at", models.DateTimeField(default=django.utils.timezone.now)), + ("created_at", models.DateTimeField(auto_now_add=True)), + ("label_kind", models.CharField(max_length=32)), + ("source", models.CharField(max_length=32)), + ("confidence", models.FloatField(default=1.0)), + ( + "provider", + models.CharField( + help_text="Proxy/VPN provider if known (e.g. geonode, brightdata)", + max_length=128, + null=True, + ), + ), + ("metadata", models.JSONField(null=True)), + ], + options={ + "db_table": "network_iplabel", + "indexes": [ + django.contrib.postgres.indexes.GistIndex( + fields=["ip"], name="network_ipl_ip_f564bf_gist" + ), + models.Index( + fields=["-labeled_at"], name="network_ipl_labeled_5f6661_idx" + ), + models.Index( + fields=["ip", "-labeled_at"], name="network_ipl_ip_5a7c2f_idx" + ), + models.Index( + fields=["label_kind"], name="network_ipl_label_k_772fd1_idx" + ), + ], + "constraints": [ + models.UniqueConstraint( + fields=("ip", "label_kind", "source", "labeled_at"), + name="unique_ip_label_event", + ) + ], + }, + ), + migrations.CreateModel( + name="MTR", + fields=[ + ( + "run", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + primary_key=True, + related_name="mtr", + serialize=False, + to="thl_django.toolrun", + ), + ), + ("ip", models.GenericIPAddressField()), + ("started_at", models.DateTimeField()), + ("scan_group_id", models.UUIDField()), + ("source_ip", models.GenericIPAddressField()), + ("facility_id", models.PositiveIntegerField()), + ("protocol", models.PositiveSmallIntegerField()), + ("port", models.PositiveIntegerField(null=True)), + ("parsed", models.JSONField()), + ], + options={ + "db_table": "network_mtr", + }, + ), + migrations.CreateModel( + name="PortScan", + fields=[ + ( + "run", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + primary_key=True, + related_name="port_scan", + serialize=False, + to="thl_django.toolrun", + ), + ), + ("ip", models.GenericIPAddressField()), + ("started_at", models.DateTimeField()), + ("scan_group_id", models.UUIDField()), + ("xml_version", models.CharField(max_length=8)), + ("host_state", models.CharField(max_length=16)), + ("host_state_reason", models.CharField(max_length=32)), + ("latency_ms", models.FloatField(null=True)), + ("distance", models.IntegerField(null=True)), + ("uptime_seconds", models.IntegerField(null=True)), + ("last_boot", models.DateTimeField(null=True)), + ("parsed", models.JSONField()), + ("open_tcp_ports", models.JSONField(default=list)), + ("open_udp_ports", models.JSONField(default=list)), + ], + options={ + "db_table": "network_portscan", + }, + ), + migrations.CreateModel( + name="RDNSResult", + fields=[ + ( + "run", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + primary_key=True, + related_name="rdns", + serialize=False, + to="thl_django.toolrun", + ), + ), + ("ip", models.GenericIPAddressField()), + ("started_at", models.DateTimeField()), + ("scan_group_id", models.UUIDField()), + ("primary_hostname", models.CharField(max_length=255, null=True)), + ("primary_domain", models.CharField(max_length=255, null=True)), + ("hostname_count", models.PositiveIntegerField(default=0)), + ("hostnames", models.JSONField(default=list)), + ], + options={ + "db_table": "network_rdnsresult", + }, + ), + migrations.AddIndex( + model_name="toolrun", + index=models.Index( + fields=["started_at"], name="network_too_started_98c8af_idx" + ), + ), + migrations.AddIndex( + model_name="toolrun", + index=models.Index( + fields=["scan_group_id"], name="network_too_scan_gr_9fd014_idx" + ), + ), + migrations.AddIndex( + model_name="toolrun", + index=models.Index( + fields=["ip", "-started_at"], name="network_too_ip_43bd05_idx" + ), + ), + migrations.AddField( + model_name="mtrhop", + name="mtr_run", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="hops", + to="thl_django.mtr", + ), + ), + migrations.AddIndex( + model_name="mtr", + index=models.Index( + fields=["ip", "-started_at"], name="network_mtr_ip_01f3ef_idx" + ), + ), + migrations.AddIndex( + model_name="mtr", + index=models.Index( + fields=["scan_group_id"], name="network_mtr_scan_gr_170b56_idx" + ), + ), + migrations.AddField( + model_name="portscanport", + name="port_scan", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="ports", + to="thl_django.portscan", + ), + ), + migrations.AddIndex( + model_name="portscan", + index=models.Index( + fields=["scan_group_id"], name="network_por_scan_gr_1d05b3_idx" + ), + ), + migrations.AddIndex( + model_name="portscan", + index=models.Index( + fields=["ip", "-started_at"], name="network_por_ip_578e34_idx" + ), + ), + migrations.AddIndex( + model_name="portscan", + index=django.contrib.postgres.indexes.GinIndex( + fields=["open_tcp_ports"], name="network_por_open_tc_46ffcb_gin" + ), + ), + migrations.AddIndex( + model_name="portscan", + index=django.contrib.postgres.indexes.GinIndex( + fields=["open_udp_ports"], name="network_por_open_ud_414f20_gin" + ), + ), + migrations.AddIndex( + model_name="rdnsresult", + index=models.Index( + fields=["ip", "-started_at"], name="network_rdn_ip_d0a43a_idx" + ), + ), + migrations.AddIndex( + model_name="rdnsresult", + index=models.Index( + fields=["scan_group_id"], name="network_rdn_scan_gr_3f23a8_idx" + ), + ), + migrations.AddIndex( + model_name="rdnsresult", + index=models.Index( + fields=["primary_hostname"], name="network_rdn_primary_39d0de_idx" + ), + ), + migrations.AddIndex( + model_name="rdnsresult", + index=models.Index( + fields=["primary_domain"], name="network_rdn_primary_ea0e8c_idx" + ), + ), + migrations.AddIndex( + model_name="mtrhop", + index=models.Index(fields=["ip"], name="network_mtr_ip_c73e13_idx"), + ), + migrations.AddIndex( + model_name="mtrhop", + index=models.Index(fields=["asn"], name="network_mtr_asn_b7fbf7_idx"), + ), + migrations.AddIndex( + model_name="mtrhop", + index=models.Index(fields=["domain"], name="network_mtr_domain_849ca4_idx"), + ), + migrations.AddConstraint( + model_name="mtrhop", + constraint=models.UniqueConstraint( + fields=("mtr_run", "hop"), name="unique_hop_per_run" + ), + ), + migrations.AddIndex( + model_name="portscanport", + index=models.Index( + fields=["port", "protocol", "state"], name="network_por_port_8d2c1c_idx" + ), + ), + migrations.AddIndex( + model_name="portscanport", + index=models.Index(fields=["state"], name="network_por_state_87f8b8_idx"), + ), + migrations.AddIndex( + model_name="portscanport", + index=models.Index( + fields=["service_name"], name="network_por_service_23a514_idx" + ), + ), + migrations.AddConstraint( + model_name="portscanport", + constraint=models.UniqueConstraint( + fields=("port_scan", "protocol", "port"), name="unique_port_per_scan" + ), + ), + ] -- cgit v1.2.3