this.updateParam((s) => s.config["flag_regex"] = v)}
error={this.state.flagRegexError}/>
- this.updateParam((s) => s.config.auth_required = v)}/>
+ this.updateParam((s) => s.config["auth_required"] = v)}/>
diff --git a/frontend/src/components/panels/ConnectionsPane.js b/frontend/src/components/panels/ConnectionsPane.js
index 23c6114..9418fad 100644
--- a/frontend/src/components/panels/ConnectionsPane.js
+++ b/frontend/src/components/panels/ConnectionsPane.js
@@ -178,7 +178,7 @@ class ConnectionsPane extends Component {
let firstConnection = this.state.firstConnection;
let lastConnection = this.state.lastConnection;
- if (additionalParams !== undefined && additionalParams.from !== undefined && additionalParams.to === undefined) {
+ if (additionalParams && additionalParams.from && !additionalParams.to) {
if (res.length > 0) {
if (!isInitial) {
res = res.slice(1);
@@ -194,7 +194,7 @@ class ConnectionsPane extends Component {
firstConnection = connections[0];
}
}
- } else if (additionalParams !== undefined && additionalParams.to !== undefined && additionalParams.from === undefined) {
+ } else if (additionalParams && additionalParams.to && !additionalParams.from) {
if (res.length > 0) {
connections = res.slice(0, res.length - 1).concat(this.state.connections);
firstConnection = connections[0];
@@ -215,12 +215,7 @@ class ConnectionsPane extends Component {
}
}
- this.setState({
- loading: false,
- connections: connections,
- firstConnection: firstConnection,
- lastConnection: lastConnection
- });
+ this.setState({loading: false, connections, firstConnection, lastConnection});
if (firstConnection != null && lastConnection != null) {
dispatcher.dispatch("connection_updates", {
diff --git a/frontend/src/components/panels/PcapsPane.js b/frontend/src/components/panels/PcapsPane.js
index 64e7804..ddc5948 100644
--- a/frontend/src/components/panels/PcapsPane.js
+++ b/frontend/src/components/panels/PcapsPane.js
@@ -181,15 +181,15 @@ class PcapsPane extends Component {
};
const uploadCurlCommand = createCurlCommand("/pcap/upload", "POST", null, {
- file: "@" + ((this.state.uploadSelectedFile != null && this.state.isUploadFileValid) ?
+ "file": "@" + ((this.state.uploadSelectedFile != null && this.state.isUploadFileValid) ?
this.state.uploadSelectedFile.name : "invalid.pcap"),
- flush_all: this.state.uploadFlushAll
+ "flush_all": this.state.uploadFlushAll
});
const fileCurlCommand = createCurlCommand("/pcap/file", "POST", {
- file: this.state.fileValue,
- flush_all: this.state.processFlushAll,
- delete_original_file: this.state.deleteOriginalFile
+ "file": this.state.fileValue,
+ "flush_all": this.state.processFlushAll,
+ "delete_original_file": this.state.deleteOriginalFile
});
return (
diff --git a/frontend/src/components/panels/RulesPane.js b/frontend/src/components/panels/RulesPane.js
index d872b47..0bbd407 100644
--- a/frontend/src/components/panels/RulesPane.js
+++ b/frontend/src/components/panels/RulesPane.js
@@ -142,23 +142,23 @@ class RulesPane extends Component {
this.setState({ruleColorError: "color is not hexcolor"});
valid = false;
}
- if (!validation.isValidPort(rule.filter.service_port)) {
+ if (!validation.isValidPort(rule.filter["service_port"])) {
this.setState({ruleServicePortError: "service_port > 65565"});
valid = false;
}
- if (!validation.isValidPort(rule.filter.client_port)) {
+ if (!validation.isValidPort(rule.filter["client_port"])) {
this.setState({ruleClientPortError: "client_port > 65565"});
valid = false;
}
- if (!validation.isValidAddress(rule.filter.client_address)) {
+ if (!validation.isValidAddress(rule.filter["client_address"])) {
this.setState({ruleClientAddressError: "client_address is not ip_address"});
valid = false;
}
- if (rule.filter.min_duration > rule.filter.max_duration) {
+ if (rule.filter["min_duration"] > rule.filter["max_duration"]) {
this.setState({ruleDurationError: "min_duration > max_dur."});
valid = false;
}
- if (rule.filter.min_bytes > rule.filter.max_bytes) {
+ if (rule.filter["min_bytes"] > rule.filter["max_bytes"]) {
this.setState({ruleBytesError: "min_bytes > max_bytes"});
valid = false;
}
@@ -175,9 +175,9 @@ class RulesPane extends Component {
const newPattern = _.cloneDeep(this.emptyPattern);
this.setState({
selectedRule: null,
- newRule: newRule,
+ newRule,
selectedPattern: null,
- newPattern: newPattern,
+ newPattern,
patternRegexFocused: false,
patternOccurrencesFocused: false,
ruleNameError: null,
@@ -210,9 +210,7 @@ class RulesPane extends Component {
const newPattern = _.cloneDeep(this.emptyPattern);
this.currentRule().patterns.push(pattern);
- this.setState({
- newPattern: newPattern
- });
+ this.setState({newPattern});
};
editPattern = (pattern) => {
@@ -237,7 +235,7 @@ class RulesPane extends Component {
valid = false;
this.setState({patternRegexFocused: true});
}
- if (pattern.min_occurrences > pattern.max_occurrences) {
+ if (pattern["min_occurrences"] > pattern["max_occurrences"]) {
valid = false;
this.setState({patternOccurrencesFocused: true});
}
@@ -273,25 +271,25 @@ class RulesPane extends Component {
this.setState({patternRegexFocused: pattern.regex === ""});
}}/>
- this.updateParam(() => pattern.flags.caseless = v)}/> |
- this.updateParam(() => pattern.flags.dot_all = v)}/> |
- this.updateParam(() => pattern.flags.multi_line = v)}/> |
- this.updateParam(() => pattern.flags.utf_8_mode = v)}/> |
- this.updateParam(() => pattern.flags.unicode_property = v)}/> |
+ this.updateParam(() => pattern.flags["caseless"] = v)}/> |
+ this.updateParam(() => pattern.flags["dot_all"] = v)}/> |
+ this.updateParam(() => pattern.flags["multi_line"] = v)}/> |
+ this.updateParam(() => pattern.flags["utf_8_mode"] = v)}/> |
+ this.updateParam(() => pattern.flags["unicode_property"] = v)}/> |
- this.updateParam(() => pattern.min_occurrences = v)}/>
+ onChange={(v) => this.updateParam(() => pattern["min_occurrences"] = v)}/>
|
- this.updateParam(() => pattern.max_occurrences = v)}/>
+ onChange={(v) => this.updateParam(() => pattern["max_occurrences"] = v)}/>
|
s", "s->c"]}
value={this.directions[pattern.direction]}
@@ -305,13 +303,13 @@ class RulesPane extends Component {
:
{p.regex} |
- {p.flags.caseless ? "yes" : "no"} |
- {p.flags.dot_all ? "yes" : "no"} |
- {p.flags.multi_line ? "yes" : "no"} |
- {p.flags.utf_8_mode ? "yes" : "no"} |
- {p.flags.unicode_property ? "yes" : "no"} |
- {p.min_occurrences} |
- {p.max_occurrences} |
+ {p.flags["caseless"] ? "yes" : "no"} |
+ {p.flags["dot_all"] ? "yes" : "no"} |
+ {p.flags["multi_line"] ? "yes" : "no"} |
+ {p.flags["utf_8_mode"] ? "yes" : "no"} |
+ {p.flags["unicode_property"] ? "yes" : "no"} |
+ {p["min_occurrences"]} |
+ {p["max_occurrences"]} |
{this.directions[p.direction]} |
{!isUpdate && this.editPattern(p)}/> | }
@@ -373,32 +371,32 @@ class RulesPane extends Component {
filters:
- this.updateParam((r) => r.filter.service_port = v)}
+ this.updateParam((r) => r.filter["service_port"] = v)}
min={0} max={65565} error={this.state.ruleServicePortError}
readonly={isUpdate}/>
- this.updateParam((r) => r.filter.client_port = v)}
+ this.updateParam((r) => r.filter["client_port"] = v)}
min={0} max={65565} error={this.state.ruleClientPortError}
readonly={isUpdate}/>
- this.updateParam((r) => r.filter.client_address = v)}/>
+ onChange={(v) => this.updateParam((r) => r.filter["client_address"] = v)}/>
- this.updateParam((r) => r.filter.min_duration = v)}/>
- this.updateParam((r) => r.filter["min_duration"] = v)}/>
+ this.updateParam((r) => r.filter.max_duration = v)}/>
- this.updateParam((r) => r.filter["max_duration"] = v)}/>
+ this.updateParam((r) => r.filter.min_bytes = v)}/>
- this.updateParam((r) => r.filter["min_bytes"] = v)}/>
+ this.updateParam((r) => r.filter.max_bytes = v)}/>
+ onChange={(v) => this.updateParam((r) => r.filter["max_bytes"] = v)}/>
diff --git a/frontend/src/components/panels/SearchPane.js b/frontend/src/components/panels/SearchPane.js
index d36e85e..776ebd0 100644
--- a/frontend/src/components/panels/SearchPane.js
+++ b/frontend/src/components/panels/SearchPane.js
@@ -70,20 +70,20 @@ class SearchPane extends Component {
loadSearches = () => {
backend.get("/api/searches")
- .then(res => this.setState({searches: res.json, searchesStatusCode: res.status}))
- .catch(res => this.setState({searchesStatusCode: res.status, searchesResponse: JSON.stringify(res.json)}));
+ .then((res) => this.setState({searches: res.json, searchesStatusCode: res.status}))
+ .catch((res) => this.setState({searchesStatusCode: res.status, searchesResponse: JSON.stringify(res.json)}));
};
performSearch = () => {
const options = this.state.currentSearchOptions;
this.setState({loading: true});
if (this.validateSearch(options)) {
- backend.post("/api/searches/perform", options).then(res => {
+ backend.post("/api/searches/perform", options).then((res) => {
this.reset();
this.setState({searchStatusCode: res.status, loading: false});
this.loadSearches();
this.viewSearch(res.json.id);
- }).catch(res => {
+ }).catch((res) => {
this.setState({
searchStatusCode: res.status, searchResponse: JSON.stringify(res.json),
loading: false
@@ -168,7 +168,7 @@ class SearchPane extends Component {
render() {
const options = this.state.currentSearchOptions;
- let searches = this.state.searches.map(s =>
+ let searches = this.state.searches.map((s) =>
{s.id.substring(0, 8)} |
{this.extractPattern(s["search_options"])} |
diff --git a/frontend/src/components/panels/StreamsPane.js b/frontend/src/components/panels/StreamsPane.js
index 41ab33d..1819fec 100644
--- a/frontend/src/components/panels/StreamsPane.js
+++ b/frontend/src/components/panels/StreamsPane.js
@@ -18,7 +18,7 @@
import DOMPurify from "dompurify";
import React, {Component} from "react";
import {Row} from "react-bootstrap";
-import ReactJson from "react-json-view"
+import ReactJson from "react-json-view";
import backend from "../../backend";
import log from "../../log";
import {downloadBlob, getHeaderValue} from "../../utils";
@@ -72,7 +72,7 @@ class StreamsPane extends Component {
setFormat = (format) => {
if (this.validFormats.includes(format)) {
- this.setState({format: format});
+ this.setState({format});
}
};
diff --git a/frontend/src/index.js b/frontend/src/index.js
index d00df88..62cb974 100644
--- a/frontend/src/index.js
+++ b/frontend/src/index.js
@@ -21,7 +21,6 @@ import ReactDOM from "react-dom";
import App from "./components/App";
import "./index.scss";
import notifications from "./notifications";
-import * as serviceWorker from "./serviceWorker";
notifications.createWebsocket();
@@ -31,5 +30,3 @@ ReactDOM.render(
// ,
document.getElementById("root")
);
-
-serviceWorker.unregister();
diff --git a/frontend/src/index.scss b/frontend/src/index.scss
index ea360be..1378d81 100644
--- a/frontend/src/index.scss
+++ b/frontend/src/index.scss
@@ -82,9 +82,11 @@ a {
0% {
opacity: 1;
}
+
50% {
opacity: 0.3;
}
+
100% {
opacity: 1;
}
diff --git a/frontend/src/log.js b/frontend/src/log.js
index 424e1b4..0afac47 100644
--- a/frontend/src/log.js
+++ b/frontend/src/log.js
@@ -16,9 +16,14 @@
*/
const log = {
- debug: (...obj) => console.info(...obj),
+ debug: (...obj) => isDevelopment() && console.info(...obj),
info: (...obj) => console.info(...obj),
+ warn: (...obj) => console.warn(...obj),
error: (...obj) => console.error(obj)
};
+function isDevelopment() {
+ return !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
+}
+
export default log;
diff --git a/frontend/src/serviceWorker.js b/frontend/src/serviceWorker.js
deleted file mode 100644
index a1f0ba8..0000000
--- a/frontend/src/serviceWorker.js
+++ /dev/null
@@ -1,141 +0,0 @@
-// This optional code is used to register a service worker.
-// register() is not called by default.
-
-// This lets the app load faster on subsequent visits in production, and gives
-// it offline capabilities. However, it also means that developers (and users)
-// will only see deployed updates on subsequent visits to a page, after all the
-// existing tabs open on the page have been closed, since previously cached
-// resources are updated in the background.
-
-// To learn more about the benefits of this model and instructions on how to
-// opt-in, read https://bit.ly/CRA-PWA
-
-const isLocalhost = Boolean(
- window.location.hostname === "localhost" ||
- // [::1] is the IPv6 localhost address.
- window.location.hostname === "[::1]" ||
- // 127.0.0.0/8 are considered localhost for IPv4.
- window.location.hostname.match(
- /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
- )
-);
-
-export function register(config) {
- if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
- // The URL constructor is available in all browsers that support SW.
- const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
- if (publicUrl.origin !== window.location.origin) {
- // Our service worker won't work if PUBLIC_URL is on a different origin
- // from what our page is served on. This might happen if a CDN is used to
- // serve assets; see https://github.com/facebook/create-react-app/issues/2374
- return;
- }
-
- window.addEventListener("load", () => {
- const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
-
- if (isLocalhost) {
- // This is running on localhost. Let's check if a service worker still exists or not.
- checkValidServiceWorker(swUrl, config);
-
- // Add some additional logging to localhost, pointing developers to the
- // service worker/PWA documentation.
- navigator.serviceWorker.ready.then(() => {
- console.log(
- "This web app is being served cache-first by a service " +
- "worker. To learn more, visit https://bit.ly/CRA-PWA"
- );
- });
- } else {
- // Is not localhost. Just register service worker
- registerValidSW(swUrl, config);
- }
- });
- }
-}
-
-function registerValidSW(swUrl, config) {
- navigator.serviceWorker
- .register(swUrl)
- .then((registration) => {
- registration.onupdatefound = () => {
- const installingWorker = registration.installing;
- if (installingWorker == null) {
- return;
- }
- installingWorker.onstatechange = () => {
- if (installingWorker.state === "installed") {
- if (navigator.serviceWorker.controller) {
- // At this point, the updated precached content has been fetched,
- // but the previous service worker will still serve the older
- // content until all client tabs are closed.
- console.log(
- "New content is available and will be used when all " +
- "tabs for this page are closed. See https://bit.ly/CRA-PWA."
- );
-
- // Execute callback
- if (config && config.onUpdate) {
- config.onUpdate(registration);
- }
- } else {
- // At this point, everything has been precached.
- // It's the perfect time to display a
- // "Content is cached for offline use." message.
- console.log("Content is cached for offline use.");
-
- // Execute callback
- if (config && config.onSuccess) {
- config.onSuccess(registration);
- }
- }
- }
- };
- };
- })
- .catch((error) => {
- console.error("Error during service worker registration:", error);
- });
-}
-
-function checkValidServiceWorker(swUrl, config) {
- // Check if the service worker can be found. If it can't reload the page.
- fetch(swUrl, {
- headers: {"Service-Worker": "script"},
- })
- .then((response) => {
- // Ensure service worker exists, and that we really are getting a JS file.
- const contentType = response.headers.get("content-type");
- if (
- response.status === 404 ||
- (contentType != null && contentType.indexOf("javascript") === -1)
- ) {
- // No service worker found. Probably a different app. Reload the page.
- navigator.serviceWorker.ready.then((registration) => {
- registration.unregister().then(() => {
- window.location.reload();
- });
- });
- } else {
- // Service worker found. Proceed as normal.
- registerValidSW(swUrl, config);
- }
- })
- .catch(() => {
- console.log(
- "No internet connection found. App is running in offline mode."
- );
- });
-}
-
-export function unregister() {
- if ("serviceWorker" in navigator) {
- navigator.serviceWorker.ready
- .then((registration) => {
- registration.unregister();
- })
- .catch((error) => {
- console.error(error.message);
- });
- }
-}
diff --git a/frontend/src/setupTests.js b/frontend/src/setupTests.js
deleted file mode 100644
index 9b1d6d0..0000000
--- a/frontend/src/setupTests.js
+++ /dev/null
@@ -1,5 +0,0 @@
-// jest-dom adds custom jest matchers for asserting on DOM nodes.
-// allows you to do things like:
-// expect(element).toHaveTextContent(/react/i)
-// learn more: https://github.com/testing-library/jest-dom
-import "@testing-library/jest-dom/extend-expect";
\ No newline at end of file
diff --git a/frontend/src/utils.js b/frontend/src/utils.js
index 0f0927e..445e576 100644
--- a/frontend/src/utils.js
+++ b/frontend/src/utils.js
@@ -133,7 +133,7 @@ export function getHeaderValue(request, key) {
if (request && request.headers) {
return request.headers[Object.keys(request.headers).find((k) => k.toLowerCase() === key.toLowerCase())];
}
- return undefined;
+ return null;
}
export function downloadBlob(blob, fileName) {
diff --git a/parsers/http_request_parser.go b/parsers/http_request_parser.go
index 56093c9..d7ed81c 100644
--- a/parsers/http_request_parser.go
+++ b/parsers/http_request_parser.go
@@ -28,7 +28,7 @@ import (
"strings"
)
-type HttpRequestMetadata struct {
+type HTTPRequestMetadata struct {
BasicMetadata
Method string `json:"method"`
URL string `json:"url"`
@@ -40,19 +40,19 @@ type HttpRequestMetadata struct {
FormData map[string]string `json:"form_data" binding:"omitempty"`
Body string `json:"body" binding:"omitempty"`
Trailer map[string]string `json:"trailer" binding:"omitempty"`
- Reproducers HttpRequestMetadataReproducers `json:"reproducers"`
+ Reproducers HTTPRequestMetadataReproducers `json:"reproducers"`
}
-type HttpRequestMetadataReproducers struct {
+type HTTPRequestMetadataReproducers struct {
CurlCommand string `json:"curl_command"`
RequestsCode string `json:"requests_code"`
FetchRequest string `json:"fetch_request"`
}
-type HttpRequestParser struct {
+type HTTPRequestParser struct {
}
-func (p HttpRequestParser) TryParse(content []byte) Metadata {
+func (p HTTPRequestParser) TryParse(content []byte) Metadata {
reader := bufio.NewReader(bytes.NewReader(content))
request, err := http.ReadRequest(reader)
if err != nil {
@@ -68,7 +68,7 @@ func (p HttpRequestParser) TryParse(content []byte) Metadata {
_ = request.Body.Close()
_ = request.ParseForm()
- return HttpRequestMetadata{
+ return HTTPRequestMetadata{
BasicMetadata: BasicMetadata{"http-request"},
Method: request.Method,
URL: request.URL.String(),
@@ -80,7 +80,7 @@ func (p HttpRequestParser) TryParse(content []byte) Metadata {
FormData: JoinArrayMap(request.Form),
Body: body,
Trailer: JoinArrayMap(request.Trailer),
- Reproducers: HttpRequestMetadataReproducers{
+ Reproducers: HTTPRequestMetadataReproducers{
CurlCommand: curlCommand(content),
RequestsCode: requestsCode(request, body),
FetchRequest: fetchRequest(request, body),
@@ -92,17 +92,17 @@ func curlCommand(content []byte) string {
// a new reader is required because all the body is read before and GetBody() doesn't works
reader := bufio.NewReader(bytes.NewReader(content))
request, _ := http.ReadRequest(reader)
- if command, err := http2curl.GetCurlCommand(request); err == nil {
+ command, err := http2curl.GetCurlCommand(request)
+ if err == nil {
return command.String()
- } else {
- return err.Error()
}
+ return err.Error()
}
func requestsCode(request *http.Request, body string) string {
var b strings.Builder
- headers := toJson(JoinArrayMap(request.Header))
- cookies := toJson(CookiesMap(request.Cookies()))
+ headers := toJSON(JoinArrayMap(request.Header))
+ cookies := toJSON(CookiesMap(request.Cookies()))
b.WriteString("import requests\n\nresponse = requests." + strings.ToLower(request.Method) + "(")
b.WriteString("\"" + request.URL.String() + "\"")
@@ -146,14 +146,14 @@ func fetchRequest(request *http.Request, body string) string {
data["method"] = request.Method
// TODO: mode
- if jsonData := toJson(data); jsonData != "" {
+ if jsonData := toJSON(data); jsonData != "" {
return "fetch(\"" + request.URL.String() + "\", " + jsonData + ");"
} else {
return "invalid-request"
}
}
-func toJson(obj interface{}) string {
+func toJSON(obj interface{}) string {
if buffer, err := json.MarshalIndent(obj, "", "\t"); err == nil {
return string(buffer)
} else {
diff --git a/parsers/http_response_parser.go b/parsers/http_response_parser.go
index e5ef1ac..e61fffd 100644
--- a/parsers/http_response_parser.go
+++ b/parsers/http_response_parser.go
@@ -26,7 +26,7 @@ import (
"net/http"
)
-type HttpResponseMetadata struct {
+type HTTPResponseMetadata struct {
BasicMetadata
Status string `json:"status"`
StatusCode int `json:"status_code"`
@@ -40,10 +40,10 @@ type HttpResponseMetadata struct {
Trailer map[string]string `json:"trailer" binding:"omitempty"`
}
-type HttpResponseParser struct {
+type HTTPResponseParser struct {
}
-func (p HttpResponseParser) TryParse(content []byte) Metadata {
+func (p HTTPResponseParser) TryParse(content []byte) Metadata {
reader := bufio.NewReader(bytes.NewReader(content))
response, err := http.ReadResponse(reader, nil)
if err != nil {
@@ -74,11 +74,11 @@ func (p HttpResponseParser) TryParse(content []byte) Metadata {
_ = response.Body.Close()
var location string
- if locationUrl, err := response.Location(); err == nil {
- location = locationUrl.String()
+ if locationURL, err := response.Location(); err == nil {
+ location = locationURL.String()
}
- return HttpResponseMetadata{
+ return HTTPResponseMetadata{
BasicMetadata: BasicMetadata{"http-response"},
Status: response.Status,
StatusCode: response.StatusCode,
diff --git a/parsers/parser.go b/parsers/parser.go
index a29b1ab..9aca3b6 100644
--- a/parsers/parser.go
+++ b/parsers/parser.go
@@ -30,8 +30,8 @@ type BasicMetadata struct {
}
var parsers = []Parser{ // order matter
- HttpRequestParser{},
- HttpResponseParser{},
+ HTTPRequestParser{},
+ HTTPResponseParser{},
}
func Parse(content []byte) Metadata {
diff --git a/pcap_importer_test.go b/pcap_importer_test.go
index 8940060..a47f2d9 100644
--- a/pcap_importer_test.go
+++ b/pcap_importer_test.go
@@ -127,6 +127,7 @@ func newTestPcapImporter(wrapper *TestStorageWrapper, serverAddress string) *Pca
mAssemblers: sync.Mutex{},
mSessions: sync.Mutex{},
serverNet: *ParseIPNet(serverAddress),
+ notificationController: NewNotificationController(nil),
}
}
diff --git a/rules_manager.go b/rules_manager.go
index 327e4ec..a6d969f 100644
--- a/rules_manager.go
+++ b/rules_manager.go
@@ -328,10 +328,10 @@ func (rm *rulesManagerImpl) validateAndAddRuleLocal(rule *Rule) error {
duplicatePatterns[regex] = true
}
- startId := len(rm.patterns)
+ startID := len(rm.patterns)
for id, pattern := range newPatterns {
rm.patterns = append(rm.patterns, pattern)
- rm.patternsIds[pattern.String()] = uint(startId + id)
+ rm.patternsIds[pattern.String()] = uint(startID + id)
}
rm.rules[rule.ID] = *rule
diff --git a/scripts/generate_ping.py b/scripts/generate_ping.py
index 73454c1..0c06a9e 100755
--- a/scripts/generate_ping.py
+++ b/scripts/generate_ping.py
@@ -28,7 +28,7 @@ if __name__ == "__main__":
port = 9999
n = 10000
-
+
if sys.argv[1] == "server":
# docker run -it --rm -p 9999:9999 -v "$PWD":/ping -w /ping python:3 python generate_ping.py server
with socketserver.TCPServer(("0.0.0.0", port), PongHandler) as server:
diff --git a/utils.go b/utils.go
index 639fd94..e721d78 100644
--- a/utils.go
+++ b/utils.go
@@ -57,12 +57,12 @@ func CustomRowID(payload uint64, timestamp time.Time) RowID {
binary.BigEndian.PutUint32(key[0:4], uint32(timestamp.Unix()))
binary.BigEndian.PutUint64(key[4:12], payload)
- if oid, err := primitive.ObjectIDFromHex(hex.EncodeToString(key[:])); err == nil {
+ oid, err := primitive.ObjectIDFromHex(hex.EncodeToString(key[:]))
+ if err == nil {
return oid
- } else {
- log.WithError(err).Warn("failed to create object id")
- return primitive.NewObjectID()
}
+ log.WithError(err).Warn("failed to create object id")
+ return primitive.NewObjectID()
}
func NewRowID() RowID {
--
cgit v1.2.3-70-g09d2
From 79b8b2fa3e8563c986da8baa3a761f2d4f0c6f47 Mon Sep 17 00:00:00 2001
From: Emiliano Ciavatta
Date: Fri, 16 Oct 2020 19:05:44 +0200
Subject: Minor improvements
---
application_router.go | 2 +-
frontend/src/components/App.js | 29 ++++++++-----
frontend/src/components/Header.js | 12 +++---
frontend/src/components/fields/InputField.js | 2 +-
frontend/src/components/objects/CopyLinkPopover.js | 4 +-
frontend/src/components/pages/ConfigurationPage.js | 12 ++++--
.../src/components/pages/ConfigurationPage.scss | 30 +++++++++----
frontend/src/components/pages/MainPage.js | 50 +++++++++++-----------
frontend/src/components/panels/ConnectionsPane.js | 4 +-
frontend/src/components/panels/SearchPane.js | 6 +--
rules_manager.go | 5 +++
11 files changed, 93 insertions(+), 63 deletions(-)
(limited to 'frontend/src/components/pages/ConfigurationPage.js')
diff --git a/application_router.go b/application_router.go
index 656b63e..4048dc5 100644
--- a/application_router.go
+++ b/application_router.go
@@ -39,7 +39,7 @@ func CreateApplicationRouter(applicationContext *ApplicationContext,
router.Use(static.Serve("/", static.LocalFile("./frontend/build", true)))
- for _, path := range []string{"/connections/:id", "/pcaps", "/rules", "/services", "/config"} {
+ for _, path := range []string{"/connections/:id", "/pcaps", "/rules", "/services", "/config", "/searches"} {
router.GET(path, func(c *gin.Context) {
c.File("./frontend/build/index.html")
})
diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js
index e12a99d..96083cd 100644
--- a/frontend/src/components/App.js
+++ b/frontend/src/components/App.js
@@ -16,6 +16,7 @@
*/
import React, {Component} from "react";
+import {BrowserRouter as Router} from "react-router-dom";
import dispatcher from "../dispatcher";
import Notifications from "./Notifications";
import ConfigurationPage from "./pages/ConfigurationPage";
@@ -27,15 +28,7 @@ class App extends Component {
state = {};
componentDidMount() {
- dispatcher.register("notifications", (payload) => {
- if (payload.event === "connected") {
- this.setState({
- connected: true,
- configured: payload.message["is_configured"],
- version: payload.message["version"]
- });
- }
- });
+ dispatcher.register("notifications", this.handleNotifications);
setInterval(() => {
if (document.title.endsWith("❚")) {
@@ -46,16 +39,30 @@ class App extends Component {
}, 500);
}
+ componentWillUnmount() {
+ dispatcher.unregister(this.handleNotifications);
+ }
+
+ handleNotifications = (payload) => {
+ if (payload.event === "connected") {
+ this.setState({
+ connected: true,
+ configured: payload.message["is_configured"],
+ version: payload.message["version"]
+ });
+ }
+ };
+
render() {
return (
- <>
+
{this.state.connected ?
(this.state.configured ? :
this.setState({configured: true})}/>) :
}
- >
+
);
}
}
diff --git a/frontend/src/components/Header.js b/frontend/src/components/Header.js
index ab16dd1..c46d768 100644
--- a/frontend/src/components/Header.js
+++ b/frontend/src/components/Header.js
@@ -27,6 +27,8 @@ import RulesConnectionsFilter from "./filters/RulesConnectionsFilter";
import StringConnectionsFilter from "./filters/StringConnectionsFilter";
import "./Header.scss";
+const classNames = require("classnames");
+
class Header extends Component {
componentDidMount() {
@@ -46,7 +48,7 @@ class Header extends Component {
return (
-
+
{
@@ -56,7 +58,7 @@ class Header extends Component {
-
+ {this.props.configured &&
+ }
-
+ {this.props.configured &&
@@ -89,7 +91,7 @@ class Header extends Component {
-
+ }
);
diff --git a/frontend/src/components/fields/InputField.js b/frontend/src/components/fields/InputField.js
index 823989d..e2ea020 100644
--- a/frontend/src/components/fields/InputField.js
+++ b/frontend/src/components/fields/InputField.js
@@ -75,7 +75,7 @@ class InputField extends Component {
aria-describedby={this.id} onChange={handler} {...inputProps}
readOnly={this.props.readonly}/>
- {type !== "file" && value !== "" &&
+ {type !== "file" && value !== "" && !this.props.readonly &&
handler(null)}>del
diff --git a/frontend/src/components/objects/CopyLinkPopover.js b/frontend/src/components/objects/CopyLinkPopover.js
index fa9266f..b951603 100644
--- a/frontend/src/components/objects/CopyLinkPopover.js
+++ b/frontend/src/components/objects/CopyLinkPopover.js
@@ -37,10 +37,10 @@ class CopyLinkPopover extends Component {
};
render() {
- const copyPopoverContent =
+ const copyPopoverContent =
{this.state.copiedMessage ? Copied! :
Click to copy}
-
+
;
return (
diff --git a/frontend/src/components/pages/ConfigurationPage.js b/frontend/src/components/pages/ConfigurationPage.js
index 4f0ce21..8f9b68b 100644
--- a/frontend/src/components/pages/ConfigurationPage.js
+++ b/frontend/src/components/pages/ConfigurationPage.js
@@ -25,8 +25,10 @@ import ButtonField from "../fields/ButtonField";
import CheckField from "../fields/CheckField";
import InputField from "../fields/InputField";
import TextField from "../fields/TextField";
+import Header from "../Header";
import LinkPopover from "../objects/LinkPopover";
import "../panels/common.scss";
+import "./common.scss";
import "./ConfigurationPage.scss";
class ConfigurationPage extends Component {
@@ -113,9 +115,13 @@ class ConfigurationPage extends Component {
);
return (
-
-
-
+
+
+
+
+
+
+
POST /setup
diff --git a/frontend/src/components/pages/ConfigurationPage.scss b/frontend/src/components/pages/ConfigurationPage.scss
index 4509865..4254547 100644
--- a/frontend/src/components/pages/ConfigurationPage.scss
+++ b/frontend/src/components/pages/ConfigurationPage.scss
@@ -1,18 +1,30 @@
@import "../../colors";
.configuration-page {
- display: flex;
- align-items: center;
- justify-content: center;
- height: 100%;
background-color: $color-primary-0;
- .pane {
- flex-basis: 900px;
- margin-bottom: 200px;
+ .header-title {
+ margin: 50px auto;
}
- .pane-container {
- padding-bottom: 1px;
+ .configuration-pane {
+ display: flex;
+ justify-content: center;
+ height: 100%;
+ padding-top: 100px;
+
+ .section-content {
+ background-color: $color-primary-3;
+ margin-top: 15px;
+ }
+
+ .section-table table {
+ background-color: red !important;
+ }
+
+ .section-footer {
+ background-color: $color-primary-3;
+ }
}
}
+
diff --git a/frontend/src/components/pages/MainPage.js b/frontend/src/components/pages/MainPage.js
index a542e3f..c4dcd20 100644
--- a/frontend/src/components/pages/MainPage.js
+++ b/frontend/src/components/pages/MainPage.js
@@ -16,7 +16,7 @@
*/
import React, {Component} from "react";
-import {BrowserRouter as Router, Route, Switch} from "react-router-dom";
+import {Route, Switch} from "react-router-dom";
import Filters from "../dialogs/Filters";
import Header from "../Header";
import Connections from "../panels/ConnectionsPane";
@@ -42,34 +42,32 @@ class MainPage extends Component {
return (
-
-
- this.setState({filterWindowOpen: true})}/>
-
-
-
-
- this.setState({selectedConnection: c})}/>
-
-
-
- }/>
- }/>
- }/>
- }/>
- }/>
- }/>
-
-
+
+ this.setState({filterWindowOpen: true})} configured={true}/>
+
- {modal}
+
+
+ this.setState({selectedConnection: c})}/>
-
-
-
+
+
+ }/>
+ }/>
+ }/>
+ }/>
+ }/>
+ }/>
+
-
+
+ {modal}
+
+
+
+
+
);
}
diff --git a/frontend/src/components/panels/ConnectionsPane.js b/frontend/src/components/panels/ConnectionsPane.js
index 457c249..6418b3e 100644
--- a/frontend/src/components/panels/ConnectionsPane.js
+++ b/frontend/src/components/panels/ConnectionsPane.js
@@ -226,11 +226,11 @@ class ConnectionsPane extends Component {
}
loadRules = async () => {
- return backend.get("/api/rules").then(res => this.setState({rules: res.json}));
+ return backend.get("/api/rules").then((res) => this.setState({rules: res.json}));
};
loadServices = async () => {
- return backend.get("/api/services").then(res => this.setState({services: res.json}));
+ return backend.get("/api/services").then((res) => this.setState({services: res.json}));
};
render() {
diff --git a/frontend/src/components/panels/SearchPane.js b/frontend/src/components/panels/SearchPane.js
index 4c9f229..4ef5632 100644
--- a/frontend/src/components/panels/SearchPane.js
+++ b/frontend/src/components/panels/SearchPane.js
@@ -236,13 +236,13 @@ class SearchPane extends Component {
})}
name="terms" min={3} inline allowNew={true}
readonly={regexOptionsModified || options["text_search"]["exact_phrase"]}
- onChange={(tags) => this.updateParam((s) => s["text_search"].terms = tags.map(t => t.name))}/>
- {
+ onChange={(tags) => this.updateParam((s) => s["text_search"].terms = tags.map((t) => t.name))}/>
+ {
return {name: t};
})}
name="excluded_terms" min={3} inline allowNew={true}
readonly={regexOptionsModified || options["text_search"]["exact_phrase"]}
- onChange={(tags) => this.updateParam((s) => s["text_search"]["excluded_terms"] = tags.map(t => t.name))}/>
+ onChange={(tags) => this.updateParam((s) => s["text_search"]["excluded_terms"] = tags.map((t) => t.name))}/>
or
diff --git a/rules_manager.go b/rules_manager.go
index a6d969f..5d6cded 100644
--- a/rules_manager.go
+++ b/rules_manager.go
@@ -24,6 +24,7 @@ import (
"github.com/flier/gohs/hyperscan"
"github.com/go-playground/validator/v10"
log "github.com/sirupsen/logrus"
+ "sort"
"sync"
"time"
)
@@ -213,6 +214,10 @@ func (rm *rulesManagerImpl) GetRules() []Rule {
rules = append(rules, rule)
}
+ sort.Slice(rules, func(i, j int) bool {
+ return rules[i].ID.Timestamp().Before(rules[j].ID.Timestamp())
+ })
+
return rules
}
--
cgit v1.2.3-70-g09d2
|