|
@@ -27,7 +27,8 @@ $opts=array(
|
|
|
'onlinecheck'=>true,
|
|
|
'timeout'=>5,
|
|
|
'biglistfp'=>null,
|
|
|
- 'prodlistfp'=>null
|
|
|
+ 'prodlistfp'=>null,
|
|
|
+ 'blacklists'=>array()
|
|
|
);
|
|
|
|
|
|
$help='DESCRIZIONE
|
|
@@ -64,13 +65,11 @@ OPZIONI
|
|
|
bloccate]
|
|
|
Ogni riga vuota o che cominci con il carattere «#» sarà ignorata.
|
|
|
Il formato del file delle istanze bloccate è questo: per ogni riga:
|
|
|
- |<uri della istanza bloccata>|<tipo di blocco>(Silenziata|Sospesa)|
|
|
|
- [riferimento al motivo del blocco.
|
|
|
- Le prime 4 righe del file saranno ignorate, così come le righe che non
|
|
|
- corrispondessero al formato di cui sopra.
|
|
|
- In futuro utilizzeremo un altro formato, per ora ci stiamo adeguando
|
|
|
- a quello impiegato da mastodon.bida.im per la sua lista di istanze
|
|
|
- bloccate.
|
|
|
+ |<uri della istanza bloccata>|<data del blocco>|<tipo di blocco>|
|
|
|
+ <motivazione pubblica del blocco>
|
|
|
+ Esempio di <data del blocco>: «2019-12-11 18:44:06.710862»
|
|
|
+ <tipo di blocco>: «0» per silenziata, «1» per sospesa, «2» per "solo
|
|
|
+ file media e rapporti".
|
|
|
-b, --biglistfp <file>
|
|
|
DEVE essere specificata.
|
|
|
Imposta il file da cui leggere le istanze già testate in passato
|
|
@@ -81,6 +80,13 @@ OPZIONI
|
|
|
Imposta il file da cui leggere (se esiste) e in cui scrivere i dati
|
|
|
relativi alle istanze corrispondenti ai criteri di selezione descritti
|
|
|
nel paragrafo «DESCRIZIONE».
|
|
|
+ -B, --blacklistfp
|
|
|
+ Imposta un eventuale file di istanze bloccate aggiuntivo. Per il
|
|
|
+ formato di questi file vedi sopra il paragrafo relativo nella
|
|
|
+ descrizione dell\'opzione «-s, --startinstancesfp». Questa opzione può
|
|
|
+ essere utilizzata più volte per specificare più file di istanze
|
|
|
+ bloccate. Nel file di configurazione è l\'unica opzione con un formato
|
|
|
+ particolare: «blacklistfp=file1[,file2[,file3[...]]].
|
|
|
-t, --timeout <secondi>
|
|
|
Imposta il timeout delle richieste http(s) in secondi.
|
|
|
DEFAULT: '.$opts['timeout'].' secondi.
|
|
@@ -158,15 +164,19 @@ if (!is_null($inifp)) {
|
|
|
$buf=@parse_ini_file($inifp);
|
|
|
if ($buf!==false) {
|
|
|
foreach ($buf as $key=>$val) {
|
|
|
- if (array_key_exists($key,$opts))
|
|
|
- $opts[$key]=$val;
|
|
|
- else
|
|
|
+ if (array_key_exists($key,$opts)) {
|
|
|
+ if ($key=='excludeafter') {
|
|
|
+ $opts['excludeafter']=tosec($val);
|
|
|
+ if ($opts['excludeafter']===false)
|
|
|
+ mexit('L’opzione «excludeafter» specificata in «'.$inifp.'» non è in un formato corretto (usa «-h» per vedere la guida).'.N,1);
|
|
|
+ } elseif ($key=='blacklists') {
|
|
|
+ $opts['blacklists']=explode(',',$val);
|
|
|
+ } else {
|
|
|
+ $opts[$key]=$val;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
echo('Attenzione: l’opzione «'.$key.'» in «'.$inifp.'» è sconosciuta e sarà ignorata.'.N);
|
|
|
- }
|
|
|
- if (array_key_exists('excludeafter',$opts)) {
|
|
|
- $opts['excludeafter']=tosec($opts['excludeafter']);
|
|
|
- if ($opts['excludeafter']===false)
|
|
|
- mexit('L’opzione «excludeafter» specificata in «'.$inifp.'» non è in un formato corretto (usa «-h» per vedere la guida).'.N,1);
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
mexit('Attenzione: non ho potuto leggere la configurazione dal file «'.$inifp.'».'.N,1);
|
|
@@ -216,6 +226,13 @@ for ($i=1; $i<$argc; $i++) {
|
|
|
$i++;
|
|
|
$opts['startinstancesfp']=$argv[$i];
|
|
|
break;
|
|
|
+ case '-B':
|
|
|
+ case '--blacklistfp':
|
|
|
+ if ($i+1>=$argc || $argv[$i+1]=='')
|
|
|
+ mexit('L’opzione «'.$argv[$i].'» richiede un parametro di tipo file (usa «-h» per vedere la guida).'.N,1);
|
|
|
+ $i++;
|
|
|
+ $opts['blacklists'][]=$argv[$i];
|
|
|
+ break;
|
|
|
case '-l':
|
|
|
case '--loadbiglist':
|
|
|
if ($i+1>=$argc || ($argv[$i+1]!='si' && $argv[$i+1]!='no'))
|
|
@@ -276,6 +293,27 @@ if ($opts['loadbiglist']) {
|
|
|
|
|
|
$blinstances=array();
|
|
|
|
|
|
+function loadblacklist($bluri) {
|
|
|
+ global $blinstances, $opts;
|
|
|
+ $context=stream_context_create(array('http'=>array('timeout'=>$opts['timeout'])));
|
|
|
+ $f=@fopen($bluri,'r',false,$context);
|
|
|
+ if ($f!==false) {
|
|
|
+ $i=0;
|
|
|
+ while (!feof($f)) {
|
|
|
+ $lin=fgets($f);
|
|
|
+//bsd.moe|2019-12-11 18:44:06.710862|1|https://mastodon.bida.im/@Ca_Gi/101270762003908554
|
|
|
+ if (preg_match('/^([^#\|]{1}[^\|]+)\|{1}([^\|]+)\|{1}([012]{1})\|{1}(.*)$/',$lin,$buf)===1 && !in_array($buf[1],$blinstances) ) {
|
|
|
+ $i++;
|
|
|
+ $blinstances[]=$buf[1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fclose($f);
|
|
|
+ echo('OK :-) (+'.$i.' istanze bloccate caricate; totale: '.count($blinstances).')'.N);
|
|
|
+ } else {
|
|
|
+ mexit('ERRORE :-('.N,1);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
if ($opts['onlinecheck']) {
|
|
|
|
|
|
$startinstances=array();
|
|
@@ -297,33 +335,23 @@ if ($opts['onlinecheck']) {
|
|
|
if (count($startinstances)<1)
|
|
|
mexit('Il file delle istanze di partenza «'.$opts['startinstancesfp'].'» non contiene alcuna voce, muoio.'.N,1);
|
|
|
|
|
|
- $context=stream_context_create(array('http'=>array('timeout'=>$opts['timeout'])));
|
|
|
-
|
|
|
foreach ($startinstances as $dom=>$bluri) {
|
|
|
if (!is_null($bluri)) {
|
|
|
echo('Recupero la lista delle istanze bloccate da «'.$dom.'» («'.$bluri.'») ... ');
|
|
|
- $f=@fopen($bluri,'r',false,$context);
|
|
|
- if ($f!==false) {
|
|
|
- // le prime 4 righe non ci interessano
|
|
|
- for ($i=0; $i<4; $i++)
|
|
|
- fgets($f);
|
|
|
- while (!feof($f)) {
|
|
|
- $lin=fgets($f);
|
|
|
- if (preg_match('/^\|([^\|]*)\|([^\|]*)\|([^\|]*)\|$/',$lin,$buf)===1)
|
|
|
- $blinstances[]=$buf[1];
|
|
|
- }
|
|
|
- fclose($f);
|
|
|
- echo('OK :-)'.N);
|
|
|
- } else {
|
|
|
- echo('ERRORE :-('.N);
|
|
|
- }
|
|
|
+ loadblacklist($bluri);
|
|
|
} else {
|
|
|
echo('NON recupero la lista delle istanze bloccate da «'.$dom.'»: la uri della stessa non è definita.'.N);
|
|
|
}
|
|
|
}
|
|
|
- ksort($blinstances);
|
|
|
+ foreach ($opts['blacklists'] as $bluri) {
|
|
|
+ echo('Carico le istanze bloccate dall\'URI «'.$bluri.'» ... ');
|
|
|
+ loadblacklist($bluri);
|
|
|
+ }
|
|
|
+ sort($blinstances);
|
|
|
echo(count($blinstances).' istanze bloccate.'.N);
|
|
|
|
|
|
+ $context=stream_context_create(array('http'=>array('timeout'=>$opts['timeout'])));
|
|
|
+
|
|
|
foreach ($startinstances as $dom=>$bluri) {
|
|
|
if (!array_key_exists($dom,$biglist))
|
|
|
$biglist[$dom]=null;
|
|
@@ -359,8 +387,25 @@ $newbiglist=array();
|
|
|
$i=0;
|
|
|
$biglistc=count($biglist);
|
|
|
foreach ($biglist as $dom=>$oinfo) {
|
|
|
+ $i++;
|
|
|
+ echo('~~~~~~'.N);
|
|
|
if ($opts['onlinecheck']) {
|
|
|
- echo('Recupero le informazioni su «'.$dom.'» ('.($i+1).'/'.$biglistc.' - '.round(100/$biglistc*$i).'%) ... ');
|
|
|
+
|
|
|
+ echo('Recupero le informazioni Nodeinfo su «'.$dom.'» ('.$i.'/'.$biglistc.' - '.round(100/$biglistc*$i).'%) ... ');
|
|
|
+ $buf=@file_get_contents('https://'.$dom.'/nodeinfo/2.0',false,$context);
|
|
|
+ if ($buf!==false) {
|
|
|
+ echo('OK :-)'.N);
|
|
|
+ $ninfo=json_decode($buf,true);
|
|
|
+ if (!is_null($ninfo) && array_key_exists('software',$ninfo) && array_key_exists('name',$ninfo['software'])) {
|
|
|
+ echo('Il software è '.$ninfo['software']['name'].'!'.N);
|
|
|
+ } else {
|
|
|
+ echo('Impossibile determinare il software!'.N);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ echo('ERRORE :-('.N);
|
|
|
+ }
|
|
|
+
|
|
|
+ echo('Recupero le informazioni API su «'.$dom.'» ('.$i.'/'.$biglistc.' - '.round(100/$biglistc*$i).'%) ... ');
|
|
|
$buf=@file_get_contents('https://'.$dom.'/api/v1/instance',false,$context);
|
|
|
if ($buf!==false) {
|
|
|
echo('OK :-)'.N);
|
|
@@ -386,19 +431,41 @@ foreach ($biglist as $dom=>$oinfo) {
|
|
|
}
|
|
|
$info=$oinfo;
|
|
|
}
|
|
|
- $i++;
|
|
|
} else {
|
|
|
$info=$oinfo;
|
|
|
}
|
|
|
- if (!is_null($info)
|
|
|
- && !in_array($dom,$blinstances)
|
|
|
- && array_key_exists('registrations',$info) && $info['registrations']==true
|
|
|
- && array_key_exists('stats',$info) && array_key_exists('user_count',$info['stats']) && $info['stats']['user_count']>10 && $info['stats']['user_count']<=30000
|
|
|
- && array_key_exists('domain_count',$info['stats']) && $info['stats']['domain_count']>=500
|
|
|
- && array_key_exists('status_count',$info['stats']) && $info['stats']['status_count']/$info['stats']['user_count']>=10
|
|
|
-/* && array_key_exists('contact_account',$info) && array_key_exists('created_at',$info['contact_account'])
|
|
|
- && time()-strtotime($info['contact_account']['created_at'])>=6*30*24*60*60*/
|
|
|
- ) {
|
|
|
+ $whynot=array();
|
|
|
+ if (in_array($dom,$blinstances))
|
|
|
+ $whynot[]='Istanza blacklistata';
|
|
|
+ if (array_key_exists('uri',$info)) {
|
|
|
+ if (!array_key_exists('registrations',$info))
|
|
|
+ $whynot[]='Stato delle registrazioni non disponibile';
|
|
|
+ elseif ($info['registrations']==false)
|
|
|
+ $whynot[]='Registrazioni chiuse';
|
|
|
+ if (!array_key_exists('stats',$info))
|
|
|
+ $whynot[]='Stats non disponibili';
|
|
|
+ elseif (!array_key_exists('user_count',$info['stats']))
|
|
|
+ $whynot[]='Numero utenti non disponibile';
|
|
|
+ elseif ($info['stats']['user_count']<10 || $info['stats']['user_count']>30000)
|
|
|
+ $whynot[]='Numero utenti ('.$info['stats']['user_count'].') non compreso tra 10 e 30000';
|
|
|
+ elseif (!array_key_exists('domain_count',$info['stats']))
|
|
|
+ $whynot[]='Numero istanze conosciute non disponibile';
|
|
|
+ elseif ($info['stats']['domain_count']<500)
|
|
|
+ $whynot[]='Numero istanze conosciute minore di 500';
|
|
|
+ elseif (!array_key_exists('status_count',$info['stats']))
|
|
|
+ $whynot[]='Numero di toots non disponibile';
|
|
|
+ elseif ($info['stats']['status_count']/$info['stats']['user_count']<10)
|
|
|
+ $whynot[]='Media dei toots per utente minore di 10';
|
|
|
+ if (!array_key_exists('contact_account',$info) || is_null($info['contact_account']))
|
|
|
+ $whynot[]='Informazioni sull\'account admin principale non disponibili';
|
|
|
+ elseif (!array_key_exists('created_at',$info['contact_account']))
|
|
|
+ $whynot[]='Data di creazione dell\'account admin principale non disponibile';
|
|
|
+ elseif (time()-strtotime($info['contact_account']['created_at'])<6*31*24*60*60)
|
|
|
+ $whynot[]='L\'account admin principale risulta esser stato creato meno di 6 mesi fa';
|
|
|
+ } elseif (!array_key_exists($dom,$prodlist)) {
|
|
|
+ $whynot[]='Info non disponibili, e l\'istanza non era già presente nella lista delle istanze occhei';
|
|
|
+ }
|
|
|
+ if (count($whynot)==0) {
|
|
|
if (array_key_exists($dom,$prodlist)) {
|
|
|
if (array_key_exists('short_description',$info) && (!array_key_exists('short_description',$prodlist[$dom]) || $prodlist[$dom]['short_description']!=$info['short_description'])) {
|
|
|
$info['short_description_changed']=true;
|
|
@@ -430,6 +497,7 @@ foreach ($biglist as $dom=>$oinfo) {
|
|
|
} else {
|
|
|
echo('«'.$dom.'» non era nella lista delle istanze occhei e NON CI È ENTRATA! :-('.N);
|
|
|
}
|
|
|
+ echo('Motivazioni: '.implode('; ',$whynot).'.'.N);
|
|
|
}
|
|
|
}
|
|
|
|