fedipact.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/php
  2. <?php
  3. /*
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. define('N',"\n");
  16. require __DIR__.'/../lib/delinstbyid.php';
  17. $levs=['Debug', 'Info', 'Warning', 'Error'];
  18. $opts=[
  19. 'url'=>'https://fedipact.online/',
  20. 'ofpath'=>__DIR__.'/fedipact.list'
  21. ];
  22. $help='mustool.php
  23. DESCRIPTION
  24. fedipact.php downloads the list of Anti-Meta Fedi Pact signers from
  25. «'.$opts['url'].'», parses it, creates a machine readable signers list and
  26. saves it to «'.$opts['ofpath'].'».
  27. SYNOPSIS
  28. fedipact.php
  29. OPTIONS
  30. -h, --help
  31. Shows this help text and exits.
  32. This program comes with ABSOLUTELY NO WARRANTY; for details see the source.
  33. This is free software, and you are welcome to redistribute it under
  34. certain conditions; see <http://www.gnu.org/licenses/> for details.'.N;
  35. for ($i=1; $i<$argc; $i++) {
  36. if ($argv[$i]=='-h' || $argv[$i]=='--help') {
  37. echo($help);
  38. exit(0);
  39. } else {
  40. mexit('don’t know how to interpret «'.$argv[$i].'» (use «-h» to read help).'.N,1);
  41. }
  42. }
  43. $codoms=0;
  44. $ocont=@file($opts['ofpath'],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
  45. if (is_array($ocont))
  46. $codoms=count($ocont);
  47. $cont=@file($opts['url'],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
  48. if (is_array($cont)) {
  49. $doms=[];
  50. foreach ($cont as $line)
  51. if (preg_match('#<li>\s*🖤\s*[a-z0-9\.\-\_]+@([a-z0-9\.\-\_]+)\s*</li>#iu',$line,$matches)===1)
  52. if (!in_array($matches[1],$doms))
  53. $doms[]=mb_strtolower($matches[1]);
  54. $cdoms=count($doms);
  55. if ($cdoms>0) {
  56. sort($doms);
  57. $doms=implode(N,$doms);
  58. if (@file_put_contents($opts['ofpath'],$doms.N)===false)
  59. mexit('couldn’t save domain list into «'.$opts['ofpath'].'» :-('.N,3);
  60. else
  61. eecho('done saving '.$cdoms.' entries into «'.$opts['ofpath'].'» :-)'.N,1);
  62. } else {
  63. mexit('couldn’t find any domain in «'.$opts['url'].'» :-('.N,2);
  64. }
  65. } else {
  66. mexit('couldn’t open «'.$opts['url'].'».'.N,3);
  67. }
  68. exit(0);
  69. // functions
  70. function mexit($msg,$code) {
  71. global $link;
  72. if (isset($link) && $link!==false) mysqli_close($link);
  73. if ($code==0)
  74. eecho($msg,1);
  75. else
  76. eecho($msg,3);
  77. exit($code);
  78. }
  79. function eecho($msg,$lev=1) {
  80. global $levs;
  81. $time=microtime(false);
  82. $time=explode(' ',$time);
  83. $time=date('Y-m-d H:i:s',$time[1]).'.'.substr($time[0],2);
  84. $msg=$time.' '.$levs[$lev].': '.$msg;
  85. if ($lev<2)
  86. echo($msg);
  87. else
  88. fwrite(STDERR,$msg);
  89. }
  90. ?>