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

Only return short version of sensor UUID in the websocket #96

Closed
glaslos opened this issue Oct 19, 2023 · 8 comments
Closed

Only return short version of sensor UUID in the websocket #96

glaslos opened this issue Oct 19, 2023 · 8 comments

Comments

@glaslos
Copy link
Member

glaslos commented Oct 19, 2023

Before publishing to the websockets, truncate the sensor UUID to only the first part until the first -.
Remove truncating from the front-end code.

@Tushar-kalsi
Copy link
Contributor

Hii @glaslos ,
I am exited to work on this issue .
Meanwhile if i run backend server locally what arguments do i need to pass with "go run server.go" to pass token middleware .

@glaslos
Copy link
Member Author

glaslos commented Oct 23, 2023

You can just use make or copy the command from here

@Tushar-kalsi
Copy link
Contributor

Can you check if my approach is correct to address this issue .

  • Intercept the msg variable from here .
  • Decode this msg []byte back to go object by taking reference of Event interface used in frontend .
  • Pull out sensorID from this object .
  • Alter it according to conditions.
  • Convert back into []byte.
  • Call cs.publish function .

@glaslos
Copy link
Member Author

glaslos commented Oct 24, 2023

Yes, that sound about right. Maybe try without defining the Event type too specific, maybe a map[string]interface{} does the trick here.

@Tushar-kalsi
Copy link
Contributor

Tushar-kalsi commented Oct 24, 2023

Please check if my snippet is correct and let me know how can i test this , i mean how these endpoints will be called when i run locally go server. afterward i will generate PR.

At line

I will put this below snippet in action :

`// Unmarshal the JSON message into a map
var data map[string]interface{}
if err := json.Unmarshal(msg, &data); err != nil {
http.Error(w, "Invalid JSON payload", http.StatusBadRequest)
return
}

// Check if "sensorID" key exists
if sensorID, ok := data["sensorID"].(string); ok {
	// Manipulate the "sensorID"
	sensorID = splitSensorID(sensorID)

	
	// Update the map with the new "sensorID" value
	data["sensorID"] = sensorID
}

// Marshal the map back to a JSON message
alteredMsg , err := json.Marshal(data)
if err != nil {
	http.Error(w, "Error processing JSON", http.StatusInternalServerError)
	return
}



cs.publish(alteredMsg) 

//Helper function which splits into two parts the sensorID by the hyphen
func splitSensorID(sensorID string) string {
parts := strings.Split(sensorID, "-")
if len(parts) > 0 {
return parts[0]
}
return sensorID // Return the original sensorID if there's no hyphen
}`

@glaslos
Copy link
Member Author

glaslos commented Oct 24, 2023

Yes, this looks good!

Tushar-kalsi added a commit to Tushar-kalsi/ochi that referenced this issue Oct 24, 2023
Fixed honeynet#96

Some changes in handler.go file in publishHandler function intersepted msg []byte object decode it , made changes as per requirnments .
@Tushar-kalsi
Copy link
Contributor

I was curious to know , why havn't we implemented Lint , and designed test cases for both Frontend and backend . Let me if maintainers are looking into this field . I would be happy to implement these .

Tushar-kalsi added a commit to Tushar-kalsi/ochi that referenced this issue Oct 25, 2023
…ckend

Removed .split ('-')[0] from front end code and already added this logic in backend
@glaslos
Copy link
Member Author

glaslos commented Oct 25, 2023

I will add linting in the GitHub actions in the future. Considering we are only a few people working in this at the moment, we didn't consider it a priority. Same for the testing, right now we do a lot of manual tests before we release. But feel free to add more tests!

Tushar-kalsi added a commit to Tushar-kalsi/ochi that referenced this issue Oct 25, 2023
I have made changes as per discussion please review .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants