Initial commit

This commit is contained in:
Steph 2020-01-27 15:53:46 +01:00
commit 7fa00cf4e4
2 changed files with 65 additions and 0 deletions

30
json.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
echo "content-type: text/plain"
echo "Access-Control-Allow-Origin: *"
echo ""
IFS=\& read -a fields <<<"$QUERY_STRING"
if [ -z "${fields[0]}" ]
then
echo '{"status":"error","message":"Please supply url as a query parameter"}'
exit 0
fi
KEY=$(echo -n ${fields[0]} | cut -d/ -f3- | cut -d? -f1 | sed 's:/*$::' | sha1sum | head -c -4)
if [ -z "${fields[1]}" ]
then
echo -n '{"status":"ok", "url":"'${fields[0]}'", "dates":'
echo -n '["'$(ls "./data/$KEY" | sed ':a;N;$!ba;s/\n/","/g')'"]'
echo "}"
else
VIEWS=$(cat "./data/$KEY/${fields[1]}" | wc -l)
UNIQUE=$(sort -u "./data/$KEY/${fields[1]}" | wc -l)
echo -n '{"status":"ok", "url":"'${fields[0]}'", "date":"'${fields[1]}'", "views":'$VIEWS', "unique":'$UNIQUE', "sessions":'
echo -n '["'$(sed ':a;N;$!ba;s/\n/","/g' ./data/$KEY/${fields[1]})'"]'
echo "}"
fi

35
pixel.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/sh
echo "Content-type: image/svg+xml"
echo "Cache-Control: no-store, no-cache, must-revalidate, max-age=0"
echo "Cache-Control: post-check=0, pre-check=0"
echo "Pragma: no-cache"
# Get an unique session id to start storing sessions.
# This is better than using the ip directly, as it
# changes for each browsing session. This way it is
# impossible to link past browsing activity
if [ -z "$HTTP_COOKIE" ]
then
SESSION_ID=$(echo "$(date) $REMOTE_ADDR" | sha1sum | head -c -4)
echo "Set-Cookie: $SESSION_ID; Path=/"
else
SESSION_ID=$HTTP_COOKIE
fi
# End of headers
echo ""
# Generate the key and date
KEY=$(echo -n $HTTP_REFERER | cut -d/ -f3- | cut -d? -f1 | sed 's:/*$::' | sha1sum | head -c -4)
UNIQUE=$(date '+%Y-%m-%d')
# store
echo $SESSION_ID >> "./data/$KEY/$UNIQUE" || (mkdir -p "./data/$KEY" && echo $SESSION_ID >> "./data/$KEY/$UNIQUE")
# reply
echo '<svg width="0" height="0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="" class=""></path><!-- Simple privacy minded analytics for the ~verse. https://tilde.team/~steph for more info --></svg>'
exit 0