add script to handle spam accounts

This commit is contained in:
Quentin Gibeaux 2021-07-29 14:08:31 +02:00 committed by root
parent 1deaa51956
commit cd33f21a32
3 changed files with 124 additions and 0 deletions

33
spam/generate_list_from_ip.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
if [ -z $1 ]; then
echo "Missing IP argument";
echo "Usage : ./$0 IP"
exit 1
fi
IP=$1
echo "Selecting accounts from IP $IP..."
psql -A -t -P pager=off mastodon-production -c "select account_id from users where host(last_sign_in_ip) like '$IP%';" > account_id_from_ip.txt
echo "Filtering accounts that are suspended..."
for id in `cat account_id_from_ip.txt`; do psql -A -t -P pager=off mastodon-production -c "select id from accounts where id='$id' and suspended_at is NULL;"; done > filtered_account_id_from_ip.txt
echo "Generating URL list..."
for id in `cat filtered_account_id_from_ip.txt`; do echo "https://pouet.chapril.org/admin/accounts/$id"; done > account_url_from_ip.txt
echo "Generating username list..."
for id in `cat filtered_account_id_from_ip.txt`; do psql -A -t -P pager=off mastodon-production -c "select username from accounts where id='$id';"; done > account_username_from_ip.txt
echo "Generating username string...";
for username in `cat account_username_from_ip.txt`; do echo -n "$username, "; done > account_username_from_ip_list.txt
echo -e "All done\n\n#################\n"
echo "accounts id in account_id_from_ip.txt"
echo "filtered accounts id in filtered_account_id_from_ip.txt"
echo "accounts url in account_url_from_ip.txt"
echo "username list in account_username_from_ip.txt"
echo "username string in account_username_from_ip_list.txt"

51
spam/notes Normal file
View File

@ -0,0 +1,51 @@
== Table accounts (110k lines)
username
locked
id
suspended_at
display_name
domain
== Table users (2k)
email
account_id
id
disabled
last_sign_in_ip
sign_up_ip
approved
== Divers
sql="\
SELECT count(*) AS ACCOUNTS,u.last_sign_in_ip AS IP from users as u INNER JOIN accounts as a ON a.id=u.account_id where a.suspended_at is not null group by u.last_sign_in_ip order by ACCOUNTS desc limit 10;
"
sql="\
SELECT (select count(*) from users uu where uu.last_sign_in_ip=u.last_sign_in_ip),distinct u.last_sign_in_ip from users u where u.last_sign_in_ip is not null;
"
sql="\
SELECT count(*),uu.last_sign_in_ip AS ACCOUNTS from users uu where uu.last_sign_in_ip in (SELECT u.last_sign_in_ip from users u where u.last_sign_in_ip is not null) group by uu.last_sign_in_ip order by ACCOUNTS desc;
"
sql="\
SELECT count(*) AS ACCOUNTS,(select count(*) from users uu where uu.last_sign),last_sign_in_ip as IP from users group by last_sign_in_ip order by ACCOUNTS desc;
"
sql="
select u.last_sign_in_ip,a.suspended_at,u.disabled from users u inner join accounts a on a.id=u.account_id where a.domain is null
"
sql="
select
u.last_sign_in_ip,
a.suspended_at,
(case when a.suspended_at is null then 1 else 0 end) as NOT_SUSPENDED,
u.disabled,
(case when u.disabled is false then 1 else 0 end) as NOT_DISABLED
from users u
inner join accounts a on
a.id=u.account_id
where
u.last_sign_in_ip is not null
"

40
spam/statsip Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
help()
{
echo "Usage: statsip [ result_line_number | -h ]"
}
if [ $# == 1 ]; then
if [ "$1" == "-h" ]; then
help
exit 0
else
limit="limit $1"
fi
else
limit=""
fi
sql="
select
count(*) AS ACCOUNTS,
sum(case when a.suspended_at is null then 1 else 0 end) as NOT_SUSPENDED,
sum(case when u.approved=false then 1 else 0 end) as WAITING_MODERATION,
case when family(u.last_sign_in_ip)=4 then host(u.last_sign_in_ip) else substring(host(u.last_sign_in_ip), '(([0-9a-f]{0,4}:){1,4})') end as IP
from users u
inner join accounts a on
a.id=u.account_id
where
u.last_sign_in_ip is not null
group by IP
order by ACCOUNTS desc
$limit
"
su - mastodon -c "psql -P pager=off mastodon-production -c \"$sql\" " | grep -v '[[:space:]]\+0[[:space:]]*|[[:space:]]*0'