Add PCAP/PCAPNG import via POST /api/sessions/import

- pcap.py: parse_pcap (micro/nano, both byte orders) and parse_pcapng
  (SHB byte-order, IDB linktype + if_tsresol, EPB/SPB) readers that
  unwrap Ethernet/RAW/IPv4/NULL/SLL/SLL2 to UDP and extract GSMTAP-SIM
  packets (APDU->tpdu, ATR->atr, PPS->pps), with a heuristic fallback
- database: insert_messages bulk-insert helper
- server: import endpoint reads raw body, auto-detects format, skips
  non-GSMTAP packets; 400 'No GSMTAP data found in trace' (no session)
  when empty, else creates a 'pcap' session named after the file

Tests: 102 (pcap round-trip, pcapng, no-GSMTAP, endpoint 200/400).
This commit is contained in:
catarrh committed 2026-08-13 10:15:22 +03:00
1 parent 6b2bcefbac
commit dd34c25899
4 files changed
+453 -3

No files matched your search

+8
View File
@@ -134,6 +134,14 @@ class Database:
self._conn.commit()
return cur.lastrowid
def insert_messages(self, session_id, rows):
"""Bulk-insert messages; *rows* is an iterable of
(elapsed, msg_type, data, flags) tuples. Returns the last rowid."""
self._conn.executemany(
'INSERT INTO messages (session_id, elapsed, type, data, flags) VALUES (?,?,?,?,?)',
[(session_id, elapsed, msg_type, data, flags) for elapsed, msg_type, data, flags in rows])
self._conn.commit()
def get_message(self, msg_id):
row = self._conn.execute(
'SELECT id, session_id, elapsed, type, data, flags FROM messages WHERE id=?',