initial commit

This commit is contained in:
PC-Admin 2023-08-14 03:05:54 +08:00
parent fe3c76b5a1
commit c7d4e71b86
3 changed files with 57 additions and 3 deletions

View File

@ -1,5 +1,5 @@
# rdlist-transform
Some bash scripts to add double hashes to rdlist and to strip the room_ids.
These transformations will generate a "safer" version of rdlist that can be loaded into trusted redlight servers.
Some bash scripts to add double hashes to rdlist (rdlist_transform.sh) and to strip the room_ids from every file in rdlist (rdlist_strip.sh).
These transformations will generate a "safer" version of rdlist that can be loaded into trusted redlight servers.

20
rdlist_strip.sh Normal file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# Prompt user for rdlist location
echo "Enter the path to rdlist:"
read RDLIST
# Check and create blank JSON files
echo "{}" > "$RDLIST/dist/known_rooms.json"
echo "{}" > "$RDLIST/dist/memberships.json"
# Blank out the values of "room_id" in $RDLIST/dist/summaries.json
if [ -f "$RDLIST/dist/summaries.json" ]; then
jq -c 'map(if .room? and .room.room_id then .room.room_id = "" else . end)' "$RDLIST/dist/summaries.json" > "$RDLIST/dist/summaries.json.tmp"
mv "$RDLIST/dist/summaries.json.tmp" "$RDLIST/dist/summaries.json"
echo "Processed $RDLIST/dist/summaries.json and blanked room_id values."
else
echo "$RDLIST/dist/summaries.json not found!"
fi
echo "Script completed. The room_ids have been stripped from rdlist."

34
rdlist_transform.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Ask user for the JSON file location
echo "Enter the path to summaries.json:"
read JSON_FILE
# Check if file exists
if [ ! -f "$JSON_FILE" ]; then
echo "File not found!"
exit 1
fi
# Ask user for the output file location
echo "Enter the path where the output should be written:"
read OUTPUT_FILE
TMP_JSON="$JSON_FILE.tmp"
cp "$JSON_FILE" "$TMP_JSON"
# Process each report and update in TMP_JSON
jq --raw-output '.[] | select(.room? and .room.room_id) | .room.room_id' "$JSON_FILE" | while read -r room_id; do
# Double hash the room_id
HASHED_ID=$(echo -n "$room_id" | sha256sum -b | cut -d ' ' -f1 | xxd -r -p | sha256sum | cut -d ' ' -f1)
# Update hashed id in TMP_JSON inside 'room'
jq --arg room_id "$room_id" --arg hashed_id "$HASHED_ID" 'map(if .room? and .room.room_id == $room_id then .room += {"room_id_hash": $hashed_id} else . end)' "$TMP_JSON" > "$TMP_JSON.tmp" && mv "$TMP_JSON.tmp" "$TMP_JSON"
done
# For compact output
jq -c '.' "$TMP_JSON" > "$OUTPUT_FILE"
rm "$TMP_JSON"
echo "Processing complete. Modified JSON saved to $OUTPUT_FILE. The summaries.json file now has double hashes of the room_id in every report!"