diff --git a/web/clitools/fedipact.php b/web/clitools/fedipact.php new file mode 100755 index 0000000..d2cc615 --- /dev/null +++ b/web/clitools/fedipact.php @@ -0,0 +1,101 @@ +#!/usr/bin/php +. +*/ + +define('N',"\n"); +require __DIR__.'/../lib/delinstbyid.php'; +$levs=['Debug', 'Info', 'Warning', 'Error']; + +$opts=[ + 'url'=>'https://fedipact.online/', + 'ofpath'=>__DIR__.'/fedipact.list' +]; + +$help='mustool.php + DESCRIPTION + fedipact.php downloads the list of Anti-Meta Fedi Pact signers from + «'.$opts['url'].'», parses it, creates a machine readable signers list and + saves it to «'.$opts['ofpath'].'». + SYNOPSIS + fedipact.php + OPTIONS + -h, --help + Shows this help text and exits. + + This program comes with ABSOLUTELY NO WARRANTY; for details see the source. + This is free software, and you are welcome to redistribute it under + certain conditions; see for details.'.N; + +for ($i=1; $i<$argc; $i++) { + if ($argv[$i]=='-h' || $argv[$i]=='--help') { + echo($help); + exit(0); + } else { + mexit('don’t know how to interpret «'.$argv[$i].'» (use «-h» to read help).'.N,1); + } +} + +$cont=@file($opts['url'],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); +if (is_array($cont)) { + $domlist=[]; + foreach ($cont as $line) + if (preg_match('#
  • \s*🖤\s*[a-z0-9\.\-\_]+@([a-z0-9\.\-\_]+)\s*
  • #iu',$line,$matches)===1) + if (!in_array($matches[1],$domlist)) + $domlist[]=mb_strtolower($matches[1]); + $cdomlist=count($domlist); + if ($cdomlist>0) { + sort($domlist); + $domlist=implode(N,$domlist); + if (@file_put_contents($opts['ofpath'],$domlist.N)===false) + mexit('couldn’t save domain list into «'.$opts['ofpath'].'» :-('.N,3); + else + eecho('done saving '.$cdomlist.' entries into «'.$opts['ofpath'].'» :-)'.N,1); + } else { + mexit('couldn’t find any domain in «'.$opts['url'].'» :-('.N,2); + } +} else { + mexit('couldn’t open «'.$opts['url'].'».'.N,3); +} + +exit(0); + + +// functions + +function mexit($msg,$code) { + global $link; + if (isset($link) && $link!==false) mysqli_close($link); + if ($code==0) + eecho($msg,1); + else + eecho($msg,3); + exit($code); +} + +function eecho($msg,$lev=1) { + global $levs; + $time=microtime(false); + $time=explode(' ',$time); + $time=date('Y-m-d H:i:s',$time[1]).'.'.substr($time[0],2); + $msg=$time.' '.$levs[$lev].': '.$msg; + if ($lev<2) + echo($msg); + else + fwrite(STDERR,$msg); +} + +?>