A shell script to make purging remote media files from a Matrix Synapse server easier.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

45 lines
929 B

#!/bin/bash
name="Remote Media Killer"
version=1.0.0
author="Joe"
license="GNU GPLv3"
UserInput() {
read -r -p "$(echo -e 'Domain:')" domain
read -r -p "$(echo -e 'Time:')" time
read -s -r -p "$(echo -e 'Token:')" token
}
ExecutePurge() {
echo 'Purging remote media, please wait.'
curl -X POST "https://$1/_synapse/admin/v1/purge_media_cache?before_ts=$2&access_token=$3" --data '{}'
}
UnixTimeMs() {
unix_time_ms="$(($(date -d "$1" +'%s') * 1000))"
}
DomainCheck() {
local result=$(perl -pe 's/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)/pass/g' <<< "$1")
if [ "$result" = "pass" ]; then
return 0;
else
echo -e '\nError: Not a valid domain.\n'
exit 1;
fi
}
EchoInfo() {
echo "$name $version - Licensed $license by $author"
}
main() {
EchoInfo;
UserInput;
DomainCheck "$domain";
UnixTimeMs "$time";
ExecutePurge "$domain" "$unix_time_ms" "$token"
}
main