honeynet / ochi

https://ochi.mushmush.org
GNU General Public License v3.0
25 stars 16 forks source link

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

Closed glaslos closed 8 months ago

glaslos commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

You can just use make or copy the command from here

Tushar-kalsi commented 9 months ago

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

glaslos commented 9 months ago

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 commented 8 months ago

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 commented 8 months ago

Yes, this looks good!

Tushar-kalsi commented 8 months ago

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 .

glaslos commented 8 months ago

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!