Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-updating config via websocket | setting: automatically include limit in query for tags/services #189

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

findus
Copy link
Contributor

@findus findus commented Nov 12, 2024

Config option still missing

Websocket connection to update setting for all connected users on the fly
Introduces config endpoint that lets us configure settings on the fly and send it over instantly to all connected clients

@peace-maker not sure if https://www.youtube.com/watch?v=cDA3_5982h8 moment, but I tried.

#181

@findus findus marked this pull request as ready for review November 12, 2024 10:56
@peace-maker
Copy link
Collaborator

We try to make as much configurable during runtime without restarting pkappa2. So some config page and rest endpoints to change the config values would be good. You don't have to add the UI part yet to configure it.

The current way the ltime:-1h: expression is inserted into the search box when clicking on Help or All Streams confused me at first because the query isn't run yet. The All Streams page still shows all streams instead of only the ones from the last hour as shown in the search box. I'd expect the query to be applied. Can you try how it feels when actually including that constraint on the All Streams view?
The interaction when clearing the search box and submitting the empty query after having searched another query should be special. Right now the ltime expression is inserted right away again but the search is still the empty query. It should always be possible to send the empty query to get all streams (paginated of course).

I think it's useful to add it to the other tags too. When clicking on a tag like flag_in it should show the query like tag:flag_in ltime:-1h:.

We'll have to test if this is annoying or intuitive to use during a CTF.

@peace-maker peace-maker linked an issue Nov 17, 2024 that may be closed by this pull request
@findus
Copy link
Contributor Author

findus commented Nov 17, 2024

@peace-maker came up with a solution, now on result-view creation it gets checked if setting option is is enabled, if yes + query is empty the limit gets auto applied.

Also if any link is clicked in the sidebar the router sends an additional queryparam that indicates exactly that, then the limit also gets auto applied.

Opening links with already defined queries in url just are just getting placed as is.

Only remaining issue: searching with empty query not possible atm, limit always get applied every time now.

Copy link
Collaborator

@peace-maker peace-maker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you for working on this! The empty query could be allowed by not interacting with an manually entered empty query. So after clearing the searchbox and pressing enter, you wouldn't insert the time query part.

I think adding another websocket event to notify all clients of the changed config would be useful instead of polling, but that can be done later.

A note on the Settings page that changes are global and affect all users would hopefully avoid confusion on people trying to disable the autofill for themselves.

web/src/components/SearchBox.vue Show resolved Hide resolved
web/src/apiClient.ts Outdated Show resolved Hide resolved
cmd/pkappa2/main.go Outdated Show resolved Hide resolved
cmd/pkappa2/main.go Outdated Show resolved Hide resolved
cmd/pkappa2/main.go Outdated Show resolved Hide resolved
internal/index/manager/manager.go Outdated Show resolved Hide resolved
internal/index/manager/manager.go Outdated Show resolved Hide resolved
web/src/components/SearchBox.vue Outdated Show resolved Hide resolved
web/src/components/Settings.vue Outdated Show resolved Hide resolved
web/src/stores/index.ts Outdated Show resolved Hide resolved
@findus findus requested a review from peace-maker November 17, 2024 23:33
@peace-maker peace-maker added enhancement New feature or request javascript Pull requests that update Javascript code go Pull requests that update Go code labels Nov 18, 2024
Copy link
Collaborator

@peace-maker peace-maker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried running the code yet, so this is still just visual inspection. Looks good overall.

I had the idea of turning the config option into an arbitrary suffix to add to the query, so you can change the currently hardcoded "ltime:-1h:". I'm not sure it'd help usability though and this can be switched to that option when a different query was desired during a CTF. Just for future reference.

There are multiple linter warnings still yelling about.

cmd/pkappa2/main.go Outdated Show resolved Hide resolved
internal/index/manager/manager.go Outdated Show resolved Hide resolved
web/src/apiClient.ts Outdated Show resolved Hide resolved
web/src/components/Results.vue Outdated Show resolved Hide resolved
@findus findus requested a review from peace-maker November 19, 2024 10:22
@findus findus force-pushed the limit-auto-fill branch 6 times, most recently from 2c17232 to 57a7529 Compare November 20, 2024 09:55
@findus findus changed the title auto include limit in query auto-updating config via websocket | setting: automatically include limit in query for tags/services Nov 20, 2024
@findus findus mentioned this pull request Dec 2, 2024
@peace-maker
Copy link
Collaborator

I didn't notice a difference in query speed when appending ltime:-1h: to tag/service queries during saarctf. So I'm not sure this does anything in the current state :(

Maybe a suffix in the v-text-input which gets added to the query transparently could work? I'm not sure how that interacts with sharing links to query results. Would the ltime be in the query or would it be omitted since the config is global and it would be added again when loading the page? I'd like to make it very clear visually what query is actually run.
Or include it in the query in the link but strip it from the text field value using the parser if the config option is enabled? That could fail horribly for more complex queries using parentheses or negation and would need heavy testing. But it wouldn't rely on the state of the config value when clicking on links.

grafik

How should the submenu time limit buttons work together with the global auto append setting?
grafik

Copy link
Collaborator

@peace-maker peace-maker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the technical side this looks good now minus the remaining comments. But since the envisioned performance gain doesn't exist, it's a lot of code that doesn't improve the experience :(

@spq do you have ideas on how to implement appending the time limitation ltime to any query the user might do by default, without them having to remember to click a button or type it themselves?

@@ -353,6 +360,12 @@ watch(route, () => {
fetchStreams();
});

onBeforeMount(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config is only fetched when looking at query results once. It doesn't update when you start on the landing page and click on one of the tags, so this should be moved to Navigation.vue. That way clicking on Settings right away without searching for anything first updates the button state correctly.

@@ -28,6 +30,7 @@ export const useRootStore = defineStore("root", {
tags: null,
converters: null,
pcapOverIPEndpoints: null,
clientConfig: null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add the config defaults here instead of allowing null. This makes a bunch of null checks obsolete too and simplifies the code. It also allows the websocket update messages to work even when we didn't fetch the clientconfig REST endpoint yet.

@findus
Copy link
Contributor Author

findus commented Dec 3, 2024

@peace-maker

Right now the ltime query param only gets added to the links inside the navbar, so that should not clash with more complex queries.

Could we just repurpose the PR to something like: Boilerplate code for config functionality and remove the ltime feature from this branch?

c <- mgr.clientConfig
close(c)
}
res := <-c
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return <-res

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we name the "clientconfig" that way? why not config and open it up to store runtime controllable server-side config for later?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request go Pull requests that update Go code javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config option to search in last hour by default
3 participants