Skip to content

Commit

Permalink
feat(db): returned session transitions restricted to address of curre…
Browse files Browse the repository at this point in the history
…nt run and session list
  • Loading branch information
fkglr committed Nov 14, 2022
1 parent 278abf3 commit 2537d49
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/gallia/db/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def __init__(self, database: Path):
self.path = database
self.connection: aiosqlite.Connection | None = None
self.scan_run: int | None = None
self.target: str | None = None
self.discovery_run: int | None = None
self.meta: int | None = None
self.logger = get_logger("db")
Expand Down Expand Up @@ -238,6 +239,7 @@ async def insert_scan_run(self, target: str) -> None:
cursor = await self.connection.execute(query, (target, self.meta))

self.scan_run = cursor.lastrowid
self.target = target
await self.connection.commit()

async def insert_scan_run_properties_pre(
Expand Down Expand Up @@ -395,11 +397,36 @@ async def insert_session_transition(
parameters = (self.scan_run, destination, json.dumps(steps))
await self.connection.execute(query, parameters)

async def get_sessions(self) -> list[int]:
assert self.connection is not None, "Not connected to the database"
assert self.target is not None, "Scan run not yet created, target unknown"

query = (
"SELECT DISTINCT destination "
"FROM session_transition st, "
" scan_run sr, "
" address ad "
"WHERE st.run = sr.id AND sr.address = ad.id "
"AND ad.url = ?"
)
parameters = (self.target,)

cursor: aiosqlite.Cursor = await self.connection.execute(query, parameters)
return list(x[0] for x in await cursor.fetchall())

async def get_session_transition(self, destination: int) -> list[int] | None:
assert self.connection is not None, "Not connected to the database"
assert self.target is not None, "Scan run not yet created, target unknown"

query = "SELECT steps FROM session_transition WHERE destination = ?"
parameters = (destination,)
query = (
"SELECT steps "
"FROM session_transition st, "
" scan_run sr, "
" address ad "
"WHERE st.run = sr.id AND sr.address = ad.id "
"AND st.destination = ? AND ad.url = ?"
)
parameters = (destination, self.target)
cursor: aiosqlite.Cursor = await self.connection.execute(query, parameters)
row = await cursor.fetchone()

Expand Down

0 comments on commit 2537d49

Please sign in to comment.