Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kx1t authored Apr 26, 2024
2 parents 940c611 + 5c1f9eb commit ba5c295
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 302 deletions.
4 changes: 4 additions & 0 deletions README-Mastodon.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Once you have an account, please do the following:
![image](https://user-images.githubusercontent.com/15090643/208438462-b40cc847-f36c-4db7-bacb-54a68fae2cff.png)
![image](https://user-images.githubusercontent.com/15090643/208438987-3e1fd9c2-5ce9-46c0-92e9-20bb78f55a8c.png)

Note -- if you post lots of traffic to Mastodon, please consider adding an Automatic Post Deletion time of 1 week.
This will help manage storage costs for the operator of the Mastodon server!

## Configuring Planefence to use Mastodon

Please set the following parameters in your `planefence.config` file:
Expand All @@ -55,6 +58,7 @@ PF_MASTODON=ON
PA_MASTODON=ON
PA_MASTODON_VISIBILITY=unlisted
PF_MASTODON_VISIBILITY=unlisted
MASTODON_RETENTION_TIME=7
```

- Replace the values with the applicable server name and access token.
Expand Down
73 changes: 73 additions & 0 deletions rootfs/scripts/masto_expire.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/command/with-contenv bash
#shellcheck shell=bash disable=SC1091,SC2174
# -----------------------------------------------------------------------------------
# Copyright 2024 Ramon F. Kolb - licensed under the terms and conditions
# of GPLv3. The terms and conditions of this license are included with the Github
# distribution of this package, and are also available here:
# https://github.com/kx1t/docker-planefence/
#
# This package may incorporate other software and license terms.
# -----------------------------------------------------------------------------------

if [[ -f /usr/share/planefence/persist/planefence.config ]]; then source /usr/share/planefence/persist/planefence.config; fi

ACCESS_TOKEN=$MASTODON_ACCESS_TOKEN
INSTANCE_URL="https://$MASTODON_SERVER"

RETENTION_DAYS="${MASTODON_RETENTION_TIME}"

delete_toot() {
local toot_id="$1"
local result
if result="$(curl -s --fail -X DELETE -H "Authorization: Bearer $ACCESS_TOKEN" "$INSTANCE_URL/api/v1/statuses/$toot_id" 2>&1)"; then
echo "successfully deleted"
else
echo "error: $result"
fi
}

if [[ -z "$RETENTION_DAYS" ]]; then
echo "RETENTION_DAYS not set. Exiting."
exit 1
fi

unset toot_dates counter last_id
declare -A toot_dates

now="$(date +%s)"

masto_id="$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" "$INSTANCE_URL/api/v1/accounts/verify_credentials" | jq -r '.id')"

while : ; do
echo -n "Indexing Media IDs round $((++counter))"
toots="$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" "$INSTANCE_URL/api/v1/accounts/$masto_id/statuses?limit=40${last_id:+&max_id=}${last_id}")"
# shellcheck disable=SC2207
toot_ids=($(jq -r '.[] | .id' <<< "$toots" 2>/dev/null))
if (( ${#toot_ids[@]} == 0)); then
echo "No more toots, we are done!"
exit
fi
last_id="${toot_ids[-1]}"
echo " ${#toot_ids[@]} toots"
for t in "${toot_ids[@]}"; do
if [[ -z "${toot_dates[$t]}" ]]; then
toot_dates[$t]="$(date -d "$(jq -r 'map(select(.id == "'"$t"'"))[].created_at' <<< "$toots")" +%s)"
echo -n "$t --> $(date -d @"${toot_dates[$t]}") "
if (( (now - toot_dates[$t])/(60*60*24) > RETENTION_DAYS )); then
echo -n " expired (age: $(( (now - toot_dates[$t])/(60*60*24) )) days): "
if [[ "$1" == "delete" ]]; then
echo -n "deleting... "
delete_toot "$t";
else
echo "(not deleted)"
fi
else
echo " not expired (age: $(( (now
- toot_dates[$t])/(60*60*24) )) days)"
fi
else
echo "$t --> duplicate, we're done!"
exit
fi
done
done
2 changes: 2 additions & 0 deletions rootfs/usr/share/plane-alert/plane-alert.conf
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ set +a
MASTODON_ACCESS_TOKEN=
MASTODON_VISIBILITY=unlisted
MASTODON_NAME=
MASTODON_MAXIMGS=1
MASTODON_RETENTION_TIME=
ATTRIB="#adsb #planefence #planealert by kx1t - https://sdr-e.com/docker-planefence"
#

Expand Down
2 changes: 1 addition & 1 deletion rootfs/usr/share/plane-alert/plane-alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ then
do
fld="$(echo ${field[$i]}|xargs)"
ext="${fld: -3}"
if [[ " jpg png peg bmp gif " =~ " $ext " ]] && (( ${#mast_id[@]} < 4 ))
if [[ " jpg png peg bmp gif " =~ " $ext " ]] && (( ${#mast_id[@]} < MASTODON_MAXIMGS ))
then
rm -f "/tmp/planeimg.*"
[[ "$ext" == "peg" ]] && ext="jpeg" || true
Expand Down
29 changes: 12 additions & 17 deletions rootfs/usr/share/planefence/noise2fence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Feel free to make changes to the variables between these two lines. However, it is
# STRONGLY RECOMMENDED to RTFM! See README.md for explanation of what these do.
#
# shellcheck disable=SC1091
[[ -f "/usr/share/planefence/planefence.conf" ]] && source /usr/share/planefence/planefence.conf

CSVDIR=/usr/share/planefence/html
Expand All @@ -26,14 +27,14 @@ CSVTMP=/usr/share/planefence/persist/.internal/pf-noise-csv.tmp
NOISETMP=/usr/share/planefence/persist/.internal/pf-noise-data.tmp
LOGFILE=/tmp/noise2fence.log
VERBOSE=
VERSION=0.2-docker
VERSION=0.3-docker
# -----------------------------------------------------------------------------------
# Figure out if NOISECAPT is active or not. REMOTENOISE contains the URL of the NoiseCapt container/server
# and is configured via the $PF_NOISECAPT variable in the .env file.
# Only if REMOTENOISE contains a URL and this URL is reachable, we collect noise data
# Note that this doesn't check for the validity of the actual URL, just that we can reach it.
#replace wget with curl to save disk space --was [[ "x$REMOTENOISE" != "x" ]] && [[ "$(wget -q -O /dev/null $REMOTENOISE ; echo $?)" == "0" ]] && NOISECAPT=1 || NOISECAPT=0
[[ "x$REMOTENOISE" != "x" ]] && [[ "$(curl --fail -s -o /dev/null $REMOTENOISE ; echo $?)" == "0" ]] && NOISECAPT=1 || NOISECAPT=0
if [[ -n "$REMOTENOISE" ]] && curl --fail -s -o /dev/null "$REMOTENOISE"; then NOISECAPT=1; else NOISECAPT=0; fi

if [ "$NOISECAPT" != "1" ]
then
Expand Down Expand Up @@ -63,20 +64,19 @@ CSVFILE=$CSVNAMEBASE$NOISEDATE$CSVNAMEEXT


# replace wget by curl to save disk space. was: if [ "$(wget -q -O - $REMOTENOISE/${LOGNAMEBASE##*/}$NOISEDATE$LOGNAMEEXT > $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp ; echo $?)" != "0" ]
if [ "$(curl --fail -s $REMOTENOISE/${LOGNAMEBASE##*/}$NOISEDATE$LOGNAMEEXT > $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp ; echo $?)" != "0" ]
if ! curl --fail -s "$REMOTENOISE/${LOGNAMEBASE##*/}$NOISEDATE$LOGNAMEEXT" > "$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp"
then
echo "Can't reach $REMOTENOISE/${LOGNAMEBASE##*/}$NOISEDATE$LOGNAMEEXT ... exiting"
exit 1
fi

mv -f $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT
mv -f "$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp" "$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT"
LOG "Got $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT from $REMOTELOG"

NOISEFILE=$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT
NOISEFILE="$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT"

# make sure there's no stray TMP file around, so we can directly append
[ -f "$CSVTMP" ] && rm "$CSVTMP"
[ -f "$NOISETMP" ] && rm "$NOISETMP"
rm -f "$CSVTMP" "$NOISETMP"

#Now iterate through the CSVFILE:
LOG "------------------------------"
Expand All @@ -88,13 +88,13 @@ then
# Clean the $CSVFILE first
# cat "$CSVFILE" | tr -d '\r' >/tmp/noisetmp.tmp
# mv /tmp/noisetmp.tmp "$CSVFILE"
while read CSVLINE
while read -r CSVLINE
do
XX=$(echo -n $CSVLINE | tr -d '[:cntrl:]')
XX=$(echo -n "$CSVLINE" | tr -d '[:cntrl:]')
CSVLINE=$XX
unset RECORD
# Read the line, but first clean it up as it appears to have a newline in it
IFS="," read -aRECORD <<< "$CSVLINE"
IFS="," read -ra RECORD <<< "$CSVLINE"
LOG "${#RECORD[*]} records in the current line: (${RECORD[*]})"
# if there's no audio stored in the record
if [ "${#RECORD[*]}" -le "7" ]
Expand All @@ -115,7 +115,7 @@ then
(( NUMPOS=NUMPOS+1 ))
LOG "Start Position: $STARTPOS, Number of samples: $NUMPOS"
# Then put the corresponding noisecapt records into $NOISETMP.
tail --lines=+"$STARTPOS" $NOISEFILE | head --lines="$NUMPOS" > $NOISETMP
tail --lines=+"$STARTPOS" "$NOISEFILE" | head --lines="$NUMPOS" > $NOISETMP
#RECORD[6]="${RECORD[6]//[$'\t\r\n']}"
# Next is to figure out the data that we want to add to the PLANEFENCE record.
# $NOISEFILE and $NOISECAPT have the following format, with all audio values in dBFS:
Expand All @@ -133,12 +133,7 @@ then
fi
# Now write everything back to $CSVTMP, which we will then copy back over the old CSV file
( IFS=','; echo "${RECORD[*]}" >> "$CSVTMP" )
LOG "The record now contains $(IFS=','; echo ${RECORD[*]})"
#for i in {0..10}
#do
# printf "%s," "${RECORD[i]}" >> "$CSVTMP"
#done
# printf "%s\n" "${RECORD[11]}" >> "$CSVTMP"
LOG "The record now contains ${RECORD[*]}"
done < "$CSVFILE"

# Now, if there is a $CSVTMP file, we will overwrite $CSVFILE with it.
Expand Down
Loading

0 comments on commit ba5c295

Please sign in to comment.