mastodon-admintools/job-refuse-auto-subscription.php

70 lines
2.7 KiB
PHP

<?php
use Vazaha\Mastodon\Factories\ApiClientFactory;
require_once("bootstrap.php");
$factory = new ApiClientFactory();
$client = $factory->build()
->setBaseUri('https://'.$conf['instance']);
$client->setAccessToken($conf['token']);
$pending = $client->methods()->admin()->accounts()->v2('local','pending');
// pending is now a Vazaha\Mastodon\Results\Admin\AccountResult whose "items" are Vazaha\Mastodon\Models\Admin\AccountModel Objects
//print_r($pending);
$roles=[
0 => '_unknown_ ',
1 => 'hosting ',
3 => 'cdn ',
4 => 'land isp ',
5 => 'reserved ',
6 => 'mobile isp',
8 => 'commercial',
9 => 'government',
10 => 'university',
];
if (!($pending instanceof Vazaha\Mastodon\Results\Admin\AccountResult)) {
echo "Pending is not a AccountResult, weird\n";
print_r($pending);
exit();
}
// now scan all the results and refuse the one we want to refuse:
// if we have a account request with more than 20 character from any of those maps, we refuse the account request:
$refuse_map=[
"ru" => "абвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЭЮЯ",
"ar" => "ﺍﺎبﺏﺐﺒﺑتﺕﺖﺘﺗثﺙﺚﺜﺛجﺝﺞﺠﺟحﺡﺢﺤﺣخﺥﺦﺨﺧدﺩﺪذﺫﺬرﺭﺮزﺯﺰسﺱﺲﺴﺳشﺵﺶﺸﺷصﺹﺺﺼﺻضﺽﺾﻀﺿطﻁﻂﻄﻃظﻅﻆﻈﻇعﻉﻊﻌﻋغﻍﻎﻐﻏفﻑﻒﻔﻓقﻕﻖﻘﻗكﻙﻚﻜﻛلﻝﻞﻠﻟمﻡﻢﻤﻣنﻥﻦﻨﻧﻩﻪﻬوﻭﻮيﻱﻲﻴﻳآﺁﺂةﺓﺔىﻯﻰ"
];
foreach ($pending as $account) {
if ($account->invite_request=="Automated protocol deliverability probe") {
echo "Will REFUSE immediately this automated account: ".$account->username."\n";
$client->methods()->admin()->accounts()->reject($account->id);
} else {
echo "Pending account ".$account->username." ID ".$account->id."\n";
echo "Languager: ".$account->locale." Reason: ".$account->invite_request."\n";
echo "IP: ".$account->ip." (info: ".ipinfo($account->ip)."\n";
echo "\n";
}
// $client->methods()->admin()->accounts()->reject($account->id);
}
function ipinfo($ip) {
global $roles;
$res=json_decode(file_get_contents('https://waf1.octopuce.fr/ipinfo.php?ip='.$ip),true);
$s="";
$s .= "role: ".($roles[($res['role']??0)]??' ')." ";
$s .= "ip: $ip ";
$s .= "country: ".($res['country']??'unknown')." ";
$s .= "score: ".($res['score']??0)." ";
$s .= "prefix: ".($res['rdap']??'unknown')." ";
$s .= "isp: ".($res['isp']??'unknown')." ";
if (isset($res['whitelisted']) && $res['whitelisted']) $s .= "WHITELISTED! ";
return $s;
}